2024-04-03 06:55:09 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module GlobalSearch
|
|
|
|
class RepositoryRowSerializer < ActiveModel::Serializer
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
attributes :id, :name, :code, :created_at, :created_by, :team, :repository, :archived, :url
|
|
|
|
|
|
|
|
def team
|
2024-05-13 16:31:00 +08:00
|
|
|
team = object.repository.shared_with?(current_user.current_team) ? current_user.current_team : object.team
|
2024-04-03 06:55:09 +08:00
|
|
|
{
|
2024-05-13 16:31:00 +08:00
|
|
|
name: team.name,
|
|
|
|
url: dashboard_path(team: team)
|
2024-04-03 06:55:09 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_by
|
|
|
|
{
|
|
|
|
name: object.created_by.name,
|
|
|
|
avatar_url: avatar_path(object.created_by, :icon_small)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def created_at
|
|
|
|
I18n.l(object.created_at, format: :full_date)
|
|
|
|
end
|
|
|
|
|
|
|
|
def repository
|
2024-05-09 19:25:15 +08:00
|
|
|
archived = object.repository.archived
|
2024-04-03 06:55:09 +08:00
|
|
|
{
|
|
|
|
name: object.repository.name,
|
2024-05-09 19:25:15 +08:00
|
|
|
url: repository_path(object.repository, view_mode: archived ? 'archived' : 'active'),
|
|
|
|
archived: archived
|
2024-04-03 06:55:09 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
2024-05-09 19:25:15 +08:00
|
|
|
params = {
|
|
|
|
id: object.repository_id,
|
|
|
|
landing_page: true,
|
|
|
|
row_id: object.id
|
|
|
|
}
|
|
|
|
params[:archived] = true if object.archived
|
|
|
|
repository_path(params)
|
2024-04-03 06:55:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|