mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 01:44:34 +08:00
ab5cb19d6e
* Add step activities, fix checklists [SCI-6852] * Linter fix [SCI-6852]
52 lines
1.3 KiB
Ruby
52 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module StepElements
|
|
class TextsController < BaseController
|
|
before_action :load_step_text, only: %i(update destroy)
|
|
|
|
def create
|
|
step_text = @step.step_texts.build
|
|
|
|
ActiveRecord::Base.transaction do
|
|
create_in_step!(@step, step_text)
|
|
log_step_activity(:text_added, { text_name: step_text.name })
|
|
end
|
|
|
|
render_step_orderable_element(step_text)
|
|
rescue ActiveRecord::RecordInvalid
|
|
head :unprocessable_entity
|
|
end
|
|
|
|
def update
|
|
ActiveRecord::Base.transaction do
|
|
@step_text.update!(step_text_params)
|
|
TinyMceAsset.update_images(@step_text, params[:tiny_mce_images], current_user)
|
|
log_step_activity(:text_edited, { text_name: @step_text.name })
|
|
end
|
|
|
|
render json: @step_text, serializer: StepTextSerializer
|
|
rescue ActiveRecord::RecordInvalid
|
|
head :unprocessable_entity
|
|
end
|
|
|
|
def destroy
|
|
if @step_text.destroy
|
|
log_step_activity(:text_deleted, { text_name: @step_text.name })
|
|
head :ok
|
|
else
|
|
head :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def step_text_params
|
|
params.require(:step_text).permit(:text)
|
|
end
|
|
|
|
def load_step_text
|
|
@step_text = @step.step_texts.find_by(id: params[:id])
|
|
return render_404 unless @step_text
|
|
end
|
|
end
|
|
end
|