2018-09-07 15:19:20 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class ProtocolSerializer < ActiveModel::Serializer
|
2020-08-07 16:51:57 +02:00
|
|
|
include ApplicationHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include InputSanitizeHelper
|
|
|
|
|
2018-09-07 15:19:20 +02:00
|
|
|
type :protocols
|
2018-10-07 11:29:56 +02:00
|
|
|
attributes :id, :name, :authors, :description, :protocol_type
|
|
|
|
has_many :protocol_keywords,
|
2018-10-07 13:28:29 +02:00
|
|
|
key: :keywords,
|
|
|
|
serializer: ProtocolKeywordSerializer,
|
|
|
|
class_name: 'ProtocolKeyword',
|
2021-07-23 11:56:28 +02:00
|
|
|
unless: -> { object.protocol_keywords.blank? }
|
2019-09-17 13:02:38 +02:00
|
|
|
has_many :steps, serializer: StepSerializer, if: -> { object.steps.any? }
|
|
|
|
belongs_to :parent, serializer: ProtocolSerializer, if: -> { object.parent.present? }
|
2020-08-07 16:51:57 +02:00
|
|
|
|
2021-08-18 10:00:01 +02:00
|
|
|
include TimestampableModel
|
|
|
|
|
2020-08-07 16:51:57 +02:00
|
|
|
def description
|
|
|
|
if instance_options[:rte_rendering]
|
|
|
|
custom_auto_link(object.tinymce_render(:description),
|
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: instance_options[:team])
|
|
|
|
else
|
|
|
|
object.description
|
|
|
|
end
|
|
|
|
end
|
2018-09-07 15:19:20 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|