2022-08-04 16:51:30 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class LabelTemplateSerializer < ActiveModel::Serializer
|
2022-09-20 18:59:58 +08:00
|
|
|
include Canaid::Helpers::PermissionsHelper
|
2022-08-04 16:51:30 +08:00
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
2022-10-11 16:58:37 +08:00
|
|
|
attributes :name, :description, :language_type, :icon_url, :urls, :content, :type,
|
|
|
|
:default, :width_mm, :height_mm, :unit, :density
|
2022-08-04 16:51:30 +08:00
|
|
|
|
2022-08-08 16:06:00 +08:00
|
|
|
def icon_url
|
|
|
|
ActionController::Base.helpers.image_path("label_template_icons/#{object.icon}.svg")
|
|
|
|
end
|
|
|
|
|
2022-08-04 16:51:30 +08:00
|
|
|
def urls
|
2022-09-20 18:59:58 +08:00
|
|
|
return {} unless can_manage_label_templates?(object.team)
|
2022-08-04 16:51:30 +08:00
|
|
|
{
|
2022-08-16 16:16:40 +08:00
|
|
|
update: label_template_path(object),
|
2023-01-16 17:23:34 +08:00
|
|
|
fields: template_tags_label_templates_path(id: object.id)
|
2022-08-04 16:51:30 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|