2024-03-27 18:44:52 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module GlobalSearch
|
|
|
|
class ProjectFolderSerializer < ActiveModel::Serializer
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
attributes :id, :name, :code, :created_at, :team, :parent_folder, :archived, :url
|
|
|
|
|
|
|
|
def team
|
|
|
|
{
|
|
|
|
name: object.team.name,
|
2024-05-09 19:25:15 +08:00
|
|
|
url: dashboard_path(team: object.team)
|
2024-03-27 18:44:52 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_at
|
|
|
|
I18n.l(object.created_at, format: :full_date)
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
2024-05-09 19:25:15 +08:00
|
|
|
project_folder_path(object, team: object.team, view_mode: view_mode(object.archived?))
|
2024-03-27 18:44:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def parent_folder
|
|
|
|
if object.parent_folder_id?
|
2024-05-09 19:25:15 +08:00
|
|
|
archived = object.parent_folder.archived?
|
2024-03-27 18:44:52 +08:00
|
|
|
{
|
|
|
|
name: object.parent_folder.name,
|
2024-05-09 19:25:15 +08:00
|
|
|
url: project_folder_path(object.parent_folder.id, team: object.team, view_mode: view_mode(archived)),
|
|
|
|
archived: archived
|
2024-03-27 18:44:52 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2024-05-09 19:25:15 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def view_mode(archived)
|
|
|
|
archived ? 'archived' : 'active'
|
|
|
|
end
|
2024-03-27 18:44:52 +08:00
|
|
|
end
|
|
|
|
end
|