2024-03-27 19:41:30 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module GlobalSearch
|
|
|
|
class LabelTemplateSerializer < ActiveModel::Serializer
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
attributes :id, :name, :format, :created_at, :updated_at, :created_by, :team, :url
|
|
|
|
|
|
|
|
def team
|
|
|
|
{
|
|
|
|
name: object.team.name,
|
2024-05-09 19:25:15 +08:00
|
|
|
url: dashboard_path(team: object.team)
|
2024-03-27 19:41:30 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_by
|
|
|
|
{
|
2024-04-18 21:45:34 +08:00
|
|
|
name: object.type == 'FluicsLabelTemplate' ? object.created_by_user : object.created_by&.name,
|
2024-03-27 19:41:30 +08:00
|
|
|
avatar_url: object.created_by ? avatar_path(object.created_by, :icon_small) : nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def format
|
|
|
|
object.label_format
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_at
|
|
|
|
I18n.l(object.created_at, format: :full_date)
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated_at
|
|
|
|
I18n.l(object.updated_at, format: :full_date)
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
|
|
|
label_template_path(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|