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 = ''
|
2020-12-11 00:47:10 +08:00
|
|
|
if my_module.active? && !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
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|