Class: RiddlerAdmin::StepsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- RiddlerAdmin::StepsController
- Defined in:
- app/controllers/riddler_admin/steps_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /steps.
-
#destroy ⇒ Object
DELETE /steps/1.
-
#edit ⇒ Object
GET /steps/1/edit.
-
#index ⇒ Object
GET /steps.
-
#internal_preview ⇒ Object
Should always comes from the admin tool.
-
#new ⇒ Object
GET /steps/new.
-
#preview ⇒ Object
POST /steps/1/preview.
-
#show ⇒ Object
GET /steps/1.
- #sort ⇒ Object
- #toggle ⇒ Object
-
#update ⇒ Object
PATCH/PUT /steps/1.
Methods inherited from ApplicationController
#riddler_current_user, #riddler_user_can_approve?, #riddler_user_can_deploy?
Instance Method Details
#create ⇒ Object
POST /steps
80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 80 def create @step = @step_class.new(step_params) if @step.save redirect_to @step, notice: "Step was successfully created." else render :new end end |
#destroy ⇒ Object
DELETE /steps/1
100 101 102 103 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 100 def destroy @step.destroy redirect_to steps_url, notice: "Step was successfully destroyed." end |
#edit ⇒ Object
GET /steps/1/edit
31 32 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 31 def edit end |
#index ⇒ Object
GET /steps
9 10 11 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 9 def index @steps = Step.all end |
#internal_preview ⇒ Object
Should always comes from the admin tool
35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 35 def internal_preview @preview_context = ::RiddlerAdmin::PreviewContext.find_by_id params["pctx_id"] if @preview_context.nil? render(status: 400, json: {message: "Invalid pctx_id"}) and return end @use_case = ::Riddler::UseCases::AdminPreviewStep.new @step.definition_hash, preview_context_data: @preview_context.data @preview_hash = @use_case.process end |
#new ⇒ Object
GET /steps/new
20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 20 def new hash = {} if step = Step.find_by_id(params["step_id"]) hash[:stepable] = step end @step = @step_class.new hash end |
#preview ⇒ Object
POST /steps/1/preview
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 59 def preview if @step.preview_enabled request_headers = PreviewContext.convert_headers request.headers.to_h definition = @step.definition_hash use_case = ::Riddler::UseCases::PreviewStep.new definition, params: params.to_unsafe_h, headers: request_headers render json: use_case.process else render json: {status: "disabled"} end end |
#show ⇒ Object
GET /steps/1
14 15 16 17 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 14 def show @step_definition = @step.definition_hash @preview_contexts = ::RiddlerAdmin::PreviewContext.all end |
#sort ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 47 def sort step_order = params.fetch "step_order" step_order.each_with_index do |step_id, index| step = Step.find_by_id step_id step.update_attribute :position, index+1 end head :no_content end |
#toggle ⇒ Object
74 75 76 77 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 74 def toggle @step.update_attributes(preview_enabled: !@step.preview_enabled) redirect_to @step end |
#update ⇒ Object
PATCH/PUT /steps/1
91 92 93 94 95 96 97 |
# File 'app/controllers/riddler_admin/steps_controller.rb', line 91 def update if @step.update(step_params) redirect_to @step, notice: "Step was successfully updated." else render :edit end end |