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)
|
2019-07-02 19:15:57 +08:00
|
|
|
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-07-02 19:15:57 +08:00
|
|
|
else { created_at: :desc }
|
|
|
|
end
|
|
|
|
|
2019-08-09 20:56:00 +08:00
|
|
|
step.assets.joins(file_attachment: :blob).order(sort)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2019-04-09 16:00:56 +08:00
|
|
|
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
|
2019-04-09 16:00:56 +08:00
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def number_of_samples(my_module)
|
|
|
|
my_module.samples.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def ordered_result_of(my_module)
|
|
|
|
my_module.results.where(archived: false).order(created_at: :desc)
|
|
|
|
end
|
|
|
|
|
2017-02-16 18:45:07 +08:00
|
|
|
def get_task_alert_color(my_module)
|
|
|
|
alert = ''
|
|
|
|
if !my_module.completed?
|
|
|
|
alert = ' alert-yellow' if my_module.is_one_day_prior?
|
|
|
|
alert = ' alert-red' if my_module.is_overdue?
|
|
|
|
elsif my_module.completed?
|
|
|
|
alert = ' alert-green'
|
|
|
|
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
|
|
|
|
end
|