2023-11-09 23:58:20 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Lists
|
|
|
|
class LabelTemplateSerializer < ActiveModel::Serializer
|
|
|
|
include Canaid::Helpers::PermissionsHelper
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
attributes :name, :language_type, :urls, :type,
|
2023-12-05 03:59:16 +08:00
|
|
|
:default, :format, :modified_by, :created_by,
|
2024-04-02 21:24:41 +08:00
|
|
|
:created_at, :updated_at, :id, :icon_url, :description,
|
|
|
|
:width_mm, :height_mm, :unit, :density
|
2023-11-09 23:58:20 +08:00
|
|
|
|
|
|
|
def icon_url
|
|
|
|
ActionController::Base.helpers.image_tag(
|
|
|
|
"label_template_icons/#{object.icon}.svg",
|
|
|
|
class: 'label-template-icon'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
delegate :modified_by, to: :object
|
|
|
|
|
|
|
|
def format
|
|
|
|
object.label_format
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_by
|
|
|
|
object.created_by_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_at
|
|
|
|
I18n.l(object.created_at, format: :full)
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated_at
|
|
|
|
I18n.l(object.updated_at, format: :full)
|
|
|
|
end
|
|
|
|
|
|
|
|
def urls
|
2024-04-01 20:38:35 +08:00
|
|
|
return {} unless can_view_label_templates?(object.team)
|
2023-11-09 23:58:20 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
show: label_template_path(object)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|