Class: RailsOnboarding::Admin::FlowsController

Inherits:
BaseController show all
Defined in:
app/controllers/rails_onboarding/admin/flows_controller.rb

Overview

Admin flows controller Visual editor for creating and managing onboarding flows

Constant Summary

Constants inherited from BaseController

BaseController::DEFAULT_PER_PAGE, BaseController::MAX_PER_PAGE

Instance Method Summary collapse

Instance Method Details

#activateObject



81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/rails_onboarding/admin/flows_controller.rb', line 81

def activate
  RailsOnboarding::Flow.activate!(@flow)
  RailsOnboarding.configuration.clear_cache!
  flash[:notice] = "Flow '#{@flow.name}' is now active"
  redirect_to admin_flows_path
rescue StandardError => e
  logger.error "Error activating flow: #{e.message}"
  flash[:alert] = "Failed to activate flow"
  redirect_to admin_flows_path
end

#createObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/rails_onboarding/admin/flows_controller.rb', line 28

def create
  @flow = RailsOnboarding::Flow.new(flow_params)

  if @flow.save
    flash[:notice] = "Flow '#{@flow.name}' created successfully"
    redirect_to admin_flows_path
  else
    flash.now[:alert] = "Failed to create flow: #{@flow.errors.full_messages.join(', ')}"
    @available_icons = available_icons
    render :new
  end
end

#destroyObject



56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/rails_onboarding/admin/flows_controller.rb', line 56

def destroy
  if @flow.active?
    flash[:alert] = "Failed to delete flow. Cannot delete active flow."
  elsif @flow.destroy
    flash[:notice] = "Flow deleted successfully"
  else
    flash[:alert] = "Failed to delete flow."
  end
  redirect_to admin_flows_path
end

#duplicateObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/rails_onboarding/admin/flows_controller.rb', line 67

def duplicate
  new_flow = @flow.dup
  new_flow.name = "#{@flow.name} (Copy)"
  new_flow.active = false

  if new_flow.save
    flash[:notice] = "Flow duplicated successfully"
    redirect_to admin_flow_path(new_flow)
  else
    flash[:alert] = "Failed to duplicate flow"
    redirect_to admin_flows_path
  end
end

#editObject



41
42
43
# File 'app/controllers/rails_onboarding/admin/flows_controller.rb', line 41

def edit
  @available_icons = available_icons
end

#indexObject



10
11
12
13
14
15
16
# File 'app/controllers/rails_onboarding/admin/flows_controller.rb', line 10

def index
  @pagy, @flows = paginate(flows_collection)
  # Looked up independently of the page: the active flow is called out at the
  # top of the screen whether or not it falls on the page being viewed.
  @active_flow = RailsOnboarding::Flow.active.first
  @templates = available_templates
end

#newObject



23
24
25
26
# File 'app/controllers/rails_onboarding/admin/flows_controller.rb', line 23

def new
  @flow = RailsOnboarding::Flow.new(default_flow_structure)
  @available_icons = available_icons
end

#previewObject



92
93
94
95
# File 'app/controllers/rails_onboarding/admin/flows_controller.rb', line 92

def preview
  @steps = @flow.steps || []
  render layout: "rails_onboarding/application"
end

#showObject



18
19
20
21
# File 'app/controllers/rails_onboarding/admin/flows_controller.rb', line 18

def show
  @steps = @flow.steps || []
  @flow_stats = calculate_flow_stats(@flow)
end

#updateObject



45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/rails_onboarding/admin/flows_controller.rb', line 45

def update
  if @flow.update(flow_params)
    flash[:notice] = "Flow updated successfully"
    redirect_to admin_flow_path(@flow)
  else
    flash.now[:alert] = "Failed to update flow: #{@flow.errors.full_messages.join(', ')}"
    @available_icons = available_icons
    render :edit
  end
end