2019-04-29 01:11:41 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
module MyModulesHelper
|
|
|
|
def ordered_step_of(my_module)
|
2016-07-21 19:11:15 +08:00
|
|
|
my_module.protocol.steps.order(:position)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def ordered_checklist_items(checklist)
|
|
|
|
checklist.checklist_items.order(:position)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ordered_assets(step)
|
2019-06-11 16:08:33 +08:00
|
|
|
view_state = step.current_view_state(current_user)
|
|
|
|
sort = case view_state.state.dig('assets', 'sort')
|
|
|
|
when 'old' then { created_at: :asc }
|
2019-08-09 20:56:00 +08:00
|
|
|
when 'atoz' then { 'active_storage_blobs.filename': :asc }
|
|
|
|
when 'ztoa' then { 'active_storage_blobs.filename': :desc }
|
2019-06-11 16:08:33 +08:00
|
|
|
else { created_at: :desc }
|
|
|
|
end
|
|
|
|
|
2019-08-09 20:56:00 +08:00
|
|
|
step.assets.joins(file_attachment: :blob).order(sort)
|
2019-04-09 16:00:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def az_ordered_assets_index(step, asset_id)
|
2019-07-09 16:28:15 +08:00
|
|
|
step.assets
|
|
|
|
.joins(file_attachment: :blob)
|
|
|
|
.order(Arel.sql('LOWER(active_storage_blobs.filename)'))
|
|
|
|
.pluck(:id)
|
2019-08-09 21:17:19 +08:00
|
|
|
.index(asset_id) || 0
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2017-02-16 18:45:07 +08:00
|
|
|
def get_task_alert_color(my_module)
|
|
|
|
alert = ''
|
2023-01-13 17:18:35 +08:00
|
|
|
if !my_module.archived_branch? && !my_module.completed?
|
2017-02-16 18:45:07 +08:00
|
|
|
alert = ' alert-yellow' if my_module.is_one_day_prior?
|
|
|
|
alert = ' alert-red' if my_module.is_overdue?
|
|
|
|
end
|
|
|
|
alert
|
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def is_steps_page?
|
2019-04-29 01:11:41 +08:00
|
|
|
action_name == 'steps'
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_results_page?
|
2019-04-29 01:11:41 +08:00
|
|
|
action_name == 'results'
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
2020-05-08 17:56:29 +08:00
|
|
|
|
2020-05-14 16:57:43 +08:00
|
|
|
def grouped_by_prj_exp(my_modules)
|
|
|
|
ungrouped_tasks = my_modules.joins(experiment: :project)
|
|
|
|
.select('experiments.name as experiment_name,
|
|
|
|
experiments.archived as experiment_archived,
|
|
|
|
projects.name as project_name,
|
|
|
|
projects.archived as project_archived,
|
|
|
|
my_modules.*')
|
|
|
|
ungrouped_tasks.group_by { |i| [i[:project_name], i[:experiment_name]] }.map do |group, tasks|
|
|
|
|
{
|
|
|
|
project_name: group[0],
|
|
|
|
project_archived: tasks[0]&.project_archived,
|
|
|
|
experiment_name: group[1],
|
|
|
|
experiment_archived: tasks[0]&.experiment_archived,
|
|
|
|
tasks: tasks
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-12 22:26:44 +08:00
|
|
|
def assigned_repository_full_view_table_path(my_module, repository)
|
|
|
|
if repository.is_a?(RepositorySnapshot)
|
2020-05-13 18:58:31 +08:00
|
|
|
return full_view_table_my_module_repository_snapshot_path(my_module, repository)
|
2020-05-08 17:56:29 +08:00
|
|
|
end
|
2020-05-12 22:26:44 +08:00
|
|
|
|
|
|
|
full_view_table_my_module_repository_path(my_module, repository)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2020-05-12 22:26:44 +08:00
|
|
|
def assigned_repository_simple_view_index_path(my_module, repository)
|
2020-05-13 18:58:31 +08:00
|
|
|
return index_dt_my_module_repository_snapshot_path(my_module, repository) if repository.is_a?(RepositorySnapshot)
|
2020-05-12 22:26:44 +08:00
|
|
|
|
|
|
|
index_dt_my_module_repository_path(my_module, repository)
|
|
|
|
end
|
|
|
|
|
|
|
|
def assigned_repository_simple_view_footer_label(repository)
|
|
|
|
if repository.is_a?(RepositorySnapshot)
|
|
|
|
return t('my_modules.repository.snapshots.simple_view.snapshot_bottom_label',
|
2020-05-26 21:59:49 +08:00
|
|
|
date_time: l(repository.created_at, format: :full))
|
2020-05-12 22:26:44 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
t('my_modules.repository.snapshots.simple_view.live_bottom_label')
|
2020-05-08 17:56:29 +08:00
|
|
|
end
|
2020-05-22 21:10:21 +08:00
|
|
|
|
|
|
|
def assigned_repository_simple_view_name_column_id(repository)
|
|
|
|
repository.is_a?(RepositorySnapshot) ? 2 : 3
|
|
|
|
end
|
2021-01-12 22:15:57 +08:00
|
|
|
|
|
|
|
def my_module_archived_on(my_module)
|
|
|
|
if my_module.archived?
|
|
|
|
my_module.archived_on
|
|
|
|
elsif my_module.experiment.archived?
|
|
|
|
my_module.experiment.archived_on
|
|
|
|
elsif my_module.experiment.project.archived?
|
|
|
|
my_module.experiment.project.archived_on
|
|
|
|
end
|
|
|
|
end
|
2022-12-02 18:01:40 +08:00
|
|
|
|
|
|
|
def my_module_due_status(my_module, datetime = DateTime.current)
|
2023-01-13 17:18:35 +08:00
|
|
|
return if my_module.archived_branch? || my_module.completed?
|
|
|
|
|
2022-12-02 18:01:40 +08:00
|
|
|
if my_module.is_overdue?(datetime)
|
|
|
|
I18n.t('my_modules.details.overdue')
|
|
|
|
elsif my_module.is_one_day_prior?(datetime)
|
|
|
|
I18n.t('my_modules.details.due_soon')
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
2023-09-19 21:37:01 +08:00
|
|
|
|
2023-09-27 15:36:23 +08:00
|
|
|
def serialize_assigned_my_module_value(my_module)
|
2023-09-19 21:37:01 +08:00
|
|
|
[
|
2023-09-27 15:36:23 +08:00
|
|
|
serialize_assigned_my_module_team_data(my_module.team),
|
|
|
|
serialize_assigned_my_module_project_data(my_module.project),
|
|
|
|
serialize_assigned_my_module_experiment_data(my_module.experiment),
|
|
|
|
serialize_assigned_my_module_data(my_module)
|
2023-09-25 14:29:54 +08:00
|
|
|
]
|
2023-09-19 21:37:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-09-27 15:36:23 +08:00
|
|
|
def serialize_assigned_my_module_team_data(team)
|
2023-09-19 21:37:01 +08:00
|
|
|
{
|
2023-09-25 14:29:54 +08:00
|
|
|
type: team.class.name.underscore,
|
2023-09-19 21:37:01 +08:00
|
|
|
value: team.name,
|
|
|
|
url: projects_path(team: team.id),
|
|
|
|
archived: false
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-09-27 15:36:23 +08:00
|
|
|
def serialize_assigned_my_module_project_data(project)
|
|
|
|
archived = project.archived?
|
2023-09-19 21:37:01 +08:00
|
|
|
{
|
2023-09-25 14:29:54 +08:00
|
|
|
type: project.class.name.underscore,
|
2023-09-19 21:37:01 +08:00
|
|
|
value: project.name,
|
2023-12-07 03:53:11 +08:00
|
|
|
url: experiments_path(project_id: project, view_mode: archived ? 'archived' : 'active'),
|
2023-09-27 15:36:23 +08:00
|
|
|
archived: archived
|
2023-09-19 21:37:01 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-09-27 15:36:23 +08:00
|
|
|
def serialize_assigned_my_module_experiment_data(experiment)
|
|
|
|
archived = experiment.archived_branch?
|
2023-09-19 21:37:01 +08:00
|
|
|
{
|
2023-09-25 14:29:54 +08:00
|
|
|
type: experiment.class.name.underscore,
|
2023-09-19 21:37:01 +08:00
|
|
|
value: experiment.name,
|
2023-09-27 15:36:23 +08:00
|
|
|
url: archived ? module_archive_experiment_path(experiment) : my_modules_experiment_path(experiment),
|
|
|
|
archived: archived
|
2023-09-19 21:37:01 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-09-27 15:36:23 +08:00
|
|
|
def serialize_assigned_my_module_data(my_module)
|
2023-09-19 21:37:01 +08:00
|
|
|
{
|
2023-09-25 14:29:54 +08:00
|
|
|
type: my_module.class.name.underscore,
|
2023-09-19 21:37:01 +08:00
|
|
|
value: my_module.name,
|
2023-09-27 15:36:23 +08:00
|
|
|
url: protocols_my_module_path(my_module, view_mode: my_module.archived_branch? ? 'archived' : 'active'),
|
2023-09-19 21:37:01 +08:00
|
|
|
archived: my_module.archived_branch?
|
|
|
|
}
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|