2024-03-29 16:27:33 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module GlobalSearch
|
|
|
|
class ResultSerializer < ActiveModel::Serializer
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
attributes :id, :name, :created_at, :updated_at, :team, :experiment, :my_module, :archived, :url
|
|
|
|
|
|
|
|
def team
|
|
|
|
{
|
|
|
|
name: object.my_module.experiment.project.team.name,
|
2024-05-09 19:25:15 +08:00
|
|
|
url: dashboard_path(team: object.team)
|
2024-03-29 16:27:33 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def experiment
|
2024-05-09 19:25:15 +08:00
|
|
|
archived = object.my_module.experiment.archived_branch?
|
2024-03-29 16:27:33 +08:00
|
|
|
{
|
|
|
|
name: object.my_module.experiment.name,
|
2024-05-09 19:25:15 +08:00
|
|
|
url: my_modules_experiment_path(object.my_module.experiment.id, view_mode: view_mode(archived)),
|
|
|
|
archived: archived
|
2024-03-29 16:27:33 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def my_module
|
2024-05-09 19:25:15 +08:00
|
|
|
archived = object.my_module.archived_branch?
|
2024-03-29 16:27:33 +08:00
|
|
|
{
|
|
|
|
name: object.my_module.name,
|
2024-05-09 19:25:15 +08:00
|
|
|
url: protocols_my_module_path(object.my_module.id, view_mode: view_mode(archived)),
|
|
|
|
archived: archived
|
2024-03-29 16:27:33 +08:00
|
|
|
}
|
|
|
|
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
|
2024-05-09 19:25:15 +08:00
|
|
|
my_module_results_path(my_module_id: object.my_module.id,
|
|
|
|
view_mode: view_mode(object.archived?))
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def view_mode(archived)
|
|
|
|
archived ? 'archived' : 'active'
|
2024-03-29 16:27:33 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|