scinote-web/app/serializers/result_text_serializer.rb

47 lines
1.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class ResultTextSerializer < ActiveModel::Serializer
include Canaid::Helpers::PermissionsHelper
include Rails.application.routes.url_helpers
include ApplicationHelper
include ActionView::Helpers::TextHelper
2023-08-11 20:48:20 +08:00
attributes :id, :text, :urls, :text_view, :icon, :placeholder, :name
def updated_at
object.updated_at.to_i
end
def placeholder
I18n.t('protocols.steps.text.placeholder')
end
def text_view
@user = scope[:user]
custom_auto_link(object.tinymce_render('text'),
simple_format: false,
tags: %w(img),
team: object.result.my_module.team)
end
def text
sanitize_input(object.tinymce_render('text'))
end
def icon
'fa-font'
end
def urls
result = object.result
return {} if object.destroyed? || !can_manage_result?(scope[:user] || @instance_options[:user], result)
{
duplicate_url: duplicate_my_module_result_text_path(result.my_module, result, object),
delete_url: my_module_result_text_path(result.my_module, result, object),
update_url: my_module_result_text_path(result.my_module, result, object)
}
end
end