2024-03-29 15:34:13 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module GlobalSearch
|
|
|
|
class ExperimentSerializer < ActiveModel::Serializer
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
attributes :id, :name, :code, :created_at, :team, :project, :archived, :url
|
|
|
|
|
|
|
|
def team
|
|
|
|
{
|
|
|
|
name: object.project.team.name,
|
2024-05-09 19:25:15 +08:00
|
|
|
url: dashboard_path(team: object.team)
|
2024-03-29 15:34:13 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def project
|
2024-05-09 19:25:15 +08:00
|
|
|
archived = object.project.archived?
|
2024-03-29 15:34:13 +08:00
|
|
|
{
|
|
|
|
name: object.project.name,
|
2024-05-09 19:25:15 +08:00
|
|
|
url: project_experiments_path(project_id: object.project.id, view_mode: view_mode(archived)),
|
|
|
|
archived: archived
|
2024-03-29 15:34:13 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2024-05-09 19:25:15 +08:00
|
|
|
def archived
|
|
|
|
object.archived_branch?
|
|
|
|
end
|
|
|
|
|
2024-03-29 15:34:13 +08:00
|
|
|
def created_at
|
|
|
|
I18n.l(object.created_at, format: :full_date)
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
2024-05-09 19:25:15 +08:00
|
|
|
my_modules_experiment_path(object.id, view_mode: view_mode(archived))
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def view_mode(archived)
|
|
|
|
archived ? 'archived' : 'active'
|
2024-03-29 15:34:13 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|