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
|
|
|
|
has_many :step_comments, key: :comments, serializer: CommentSerializer
|
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
|
|
|
|
if instance_options[:rte_rendering]
|
2020-08-07 22:51:57 +08:00
|
|
|
custom_auto_link(object.tinymce_render(:description),
|
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: instance_options[:team])
|
2020-07-02 23:03:29 +08:00
|
|
|
else
|
|
|
|
object.description
|
|
|
|
end
|
2019-09-17 19:02:38 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|