mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-04 19:53:19 +08:00
Handle step description with the new step_texts structure [SCI-6890] (#4176)
This commit is contained in:
parent
b880f6fc39
commit
800f856ab1
3 changed files with 24 additions and 7 deletions
|
@ -31,19 +31,29 @@ module Api
|
|||
def create
|
||||
raise PermissionError.new(Protocol, :create) unless can_manage_protocol_in_module?(@protocol)
|
||||
|
||||
step = @protocol.steps.create!(step_params.merge!(completed: false,
|
||||
user: current_user,
|
||||
position: @protocol.number_of_steps,
|
||||
last_modified_by_id: current_user.id))
|
||||
step = @protocol.steps.create!(
|
||||
step_params.except(:description)
|
||||
.merge!(completed: false,
|
||||
user: current_user,
|
||||
position: @protocol.number_of_steps,
|
||||
last_modified_by_id: current_user.id)
|
||||
)
|
||||
step.step_texts.create!(text: step_params[:description]) if step_params[:description]
|
||||
|
||||
render jsonapi: step, serializer: StepSerializer, status: :created
|
||||
end
|
||||
|
||||
def update
|
||||
@step.assign_attributes(
|
||||
step_params.merge!(last_modified_by_id: current_user.id)
|
||||
step_params.except(:description).merge!(last_modified_by_id: current_user.id)
|
||||
)
|
||||
|
||||
if step_params[:description]
|
||||
(@step.description_step_text || @step.step_texts.create!).update!(
|
||||
text: step_params[:description]
|
||||
)
|
||||
end
|
||||
|
||||
if @step.changed? && @step.save!
|
||||
if @step.saved_change_to_attribute?(:completed)
|
||||
completed_steps = @protocol.steps.where(completed: true).count
|
||||
|
|
|
@ -137,6 +137,10 @@ class Step < ApplicationRecord
|
|||
step_comments
|
||||
end
|
||||
|
||||
def description_step_text
|
||||
step_texts.order(created_at: :asc).first
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def move_in_protocol(direction)
|
||||
|
|
|
@ -15,18 +15,21 @@ module Api
|
|||
has_many :assets, serializer: AssetSerializer
|
||||
has_many :checklists, serializer: ChecklistSerializer
|
||||
has_many :tables, serializer: TableSerializer
|
||||
has_many :step_texts, serializer: StepTextSerializer
|
||||
has_many :step_comments, key: :comments, serializer: CommentSerializer
|
||||
|
||||
include TimestampableModel
|
||||
|
||||
def description
|
||||
return unless object.description_step_text
|
||||
|
||||
if instance_options[:rte_rendering]
|
||||
custom_auto_link(object.tinymce_render(:description),
|
||||
custom_auto_link(object.description_step_text.tinymce_render(:description),
|
||||
simple_format: false,
|
||||
tags: %w(img),
|
||||
team: instance_options[:team])
|
||||
else
|
||||
object.description
|
||||
object.description_step_text.text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue