2019-09-17 19:02:38 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class StepSerializer < ActiveModel::Serializer
|
2020-07-02 23:03:29 +08:00
|
|
|
include ApplicationHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include InputSanitizeHelper
|
|
|
|
|
2019-09-17 19:02:38 +08:00
|
|
|
type :steps
|
2021-08-18 16:00:01 +08:00
|
|
|
attributes :id, :name, :description, :position, :completed
|
2020-07-02 23:03:29 +08:00
|
|
|
attribute :completed_on, if: -> { object.completed? }
|
2020-08-07 20:54:05 +08:00
|
|
|
belongs_to :user, serializer: UserSerializer
|
2019-09-17 19:02:38 +08:00
|
|
|
belongs_to :protocol, serializer: ProtocolSerializer
|
2019-09-19 22:12:15 +08:00
|
|
|
has_many :assets, serializer: AssetSerializer
|
2020-07-02 23:03:29 +08:00
|
|
|
has_many :checklists, serializer: ChecklistSerializer
|
|
|
|
has_many :tables, serializer: TableSerializer
|
2022-06-28 15:56:24 +08:00
|
|
|
has_many :step_texts, serializer: StepTextSerializer
|
2020-07-02 23:03:29 +08:00
|
|
|
has_many :step_comments, key: :comments, serializer: CommentSerializer
|
2022-07-12 16:13:47 +08:00
|
|
|
has_many :step_orderable_elements, key: :step_elements, serializer: StepOrderableElementSerializer
|
2019-09-17 19:02:38 +08:00
|
|
|
|
2021-08-18 16:00:01 +08:00
|
|
|
include TimestampableModel
|
|
|
|
|
2020-07-02 23:03:29 +08:00
|
|
|
def description
|
2022-06-28 15:56:24 +08:00
|
|
|
return unless object.description_step_text
|
|
|
|
|
2020-07-02 23:03:29 +08:00
|
|
|
if instance_options[:rte_rendering]
|
2022-06-28 15:56:24 +08:00
|
|
|
custom_auto_link(object.description_step_text.tinymce_render(:description),
|
2020-08-07 22:51:57 +08:00
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: instance_options[:team])
|
2020-07-02 23:03:29 +08:00
|
|
|
else
|
2022-06-28 15:56:24 +08:00
|
|
|
object.description_step_text.text
|
2020-07-02 23:03:29 +08:00
|
|
|
end
|
2019-09-17 19:02:38 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|