2023-11-10 20:34:36 +08:00
|
|
|
module Lists
|
|
|
|
class ProjectAndFolderSerializer < ActiveModel::Serializer
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
attributes :name, :code, :created_at, :archived_on, :users, :hidden, :urls, :folder
|
|
|
|
|
|
|
|
def folder
|
|
|
|
!project?
|
|
|
|
end
|
|
|
|
|
|
|
|
def code
|
|
|
|
object.code if project?
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_at
|
|
|
|
I18n.l(object.created_at, format: :full) if project?
|
|
|
|
end
|
|
|
|
|
|
|
|
def archived_on
|
|
|
|
I18n.l(object.archived_on, format: :full) if project? && object.archived_on
|
|
|
|
end
|
|
|
|
|
|
|
|
def hidden
|
|
|
|
object.hidden? if project?
|
|
|
|
end
|
|
|
|
|
|
|
|
def users
|
|
|
|
if project?
|
|
|
|
object.user_assignments.map do |ua|
|
|
|
|
{
|
|
|
|
avatar: avatar_path(ua.user, :icon_small),
|
|
|
|
full_name: ua.user_name_with_role
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def urls
|
|
|
|
{
|
|
|
|
show: project? ? project_path(object) : project_folder_path(object),
|
2023-11-24 18:08:28 +08:00
|
|
|
actions: actions_toolbar_projects_path(items: [{ id: object.id,
|
|
|
|
type: project? ? 'projects' : 'project_folders' }].to_json)
|
2023-11-10 20:34:36 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project?
|
2023-11-24 18:08:28 +08:00
|
|
|
object.instance_of?(Project)
|
2023-11-10 20:34:36 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|