2022-04-29 18:29:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StepTextSerializer < ActiveModel::Serializer
|
2022-06-03 17:52:10 +08:00
|
|
|
include Canaid::Helpers::PermissionsHelper
|
2022-05-03 21:15:49 +08:00
|
|
|
include Rails.application.routes.url_helpers
|
2022-05-10 19:28:09 +08:00
|
|
|
include ApplicationHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
2022-05-03 21:15:49 +08:00
|
|
|
|
2022-07-13 21:15:01 +08:00
|
|
|
attributes :id, :text, :urls, :text_view, :updated_at, :icon, :name, :placeholder
|
2022-05-10 19:28:09 +08:00
|
|
|
|
|
|
|
def updated_at
|
|
|
|
object.updated_at.to_i
|
|
|
|
end
|
|
|
|
|
2022-07-13 21:15:01 +08:00
|
|
|
def placeholder
|
|
|
|
I18n.t('protocols.steps.text.placeholder')
|
|
|
|
end
|
|
|
|
|
2022-05-10 19:28:09 +08:00
|
|
|
def text_view
|
|
|
|
@user = scope[:user]
|
|
|
|
custom_auto_link(object.tinymce_render('text'),
|
|
|
|
simple_format: false,
|
|
|
|
tags: %w(img),
|
|
|
|
team: object.step.protocol.team)
|
|
|
|
end
|
|
|
|
|
|
|
|
def text
|
|
|
|
sanitize_input(object.tinymce_render('text'))
|
|
|
|
end
|
2022-05-03 21:15:49 +08:00
|
|
|
|
2022-05-30 19:45:51 +08:00
|
|
|
def icon
|
|
|
|
'fa-font'
|
|
|
|
end
|
|
|
|
|
2022-05-03 21:15:49 +08:00
|
|
|
def urls
|
2022-06-07 18:10:10 +08:00
|
|
|
return {} if object.destroyed? || !can_manage_step?(scope[:user] || @instance_options[:user], object.step)
|
2022-05-03 21:15:49 +08:00
|
|
|
|
|
|
|
{
|
2022-05-10 19:28:09 +08:00
|
|
|
delete_url: step_text_path(object.step, object),
|
|
|
|
update_url: step_text_path(object.step, object)
|
2022-05-03 21:15:49 +08:00
|
|
|
}
|
|
|
|
end
|
2022-04-29 18:29:42 +08:00
|
|
|
end
|