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
|
|
|
|
attributes :id, :name, :description, :position, :completed
|
2020-07-02 23:03:29 +08:00
|
|
|
attribute :completed_on, if: -> { object.completed? }
|
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
|
|
|
|
has_many :step_comments, key: :comments, serializer: CommentSerializer
|
2019-09-17 19:02:38 +08:00
|
|
|
|
2020-07-02 23:03:29 +08:00
|
|
|
def description
|
|
|
|
if instance_options[:rte_rendering]
|
|
|
|
custom_auto_link(object.tinymce_render(:description), simple_format: false, tags: %w(img))
|
|
|
|
else
|
|
|
|
object.description
|
|
|
|
end
|
2019-09-17 19:02:38 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|