scinote-web/app/controllers/step_elements/checklists_controller.rb
artoscinote 23872f519b
Implement step element sorting modal [SCI-6849] (#4124)
* Implement step element sorting modal [SCI-6849]

* Implement step reordering modal [SCI-6850]

* Refactor reorderable items a bit [SCI-6850]
2022-05-30 13:45:51 +02:00

44 lines
1 KiB
Ruby

# frozen_string_literal: true
module StepElements
class ChecklistsController < BaseController
before_action :load_checklist, only: %i(update destroy)
def create
checklist = @step.checklists.build(
name: t('protocols.steps.checklist.default_name', position: @step.checklists.length + 1)
)
create_in_step!(@step, checklist)
render_step_orderable_element(checklist)
rescue ActiveRecord::RecordInvalid
head :unprocessable_entity
end
def update
@checklist.update!(checklist_params)
render json: @checklist, serializer: ChecklistSerializer
rescue ActiveRecord::RecordInvalid
head :unprocessable_entity
end
def destroy
if @checklist.destroy
head :ok
else
head :unprocessable_entity
end
end
private
def checklist_params
params.permit(:name, :text)
end
def load_checklist
@checklist = @step.checklists.find_by(id: params[:id])
return render_404 unless @checklist
end
end
end