scinote-web/app/helpers/my_modules_helper.rb

74 lines
1.6 KiB
Ruby
Raw Normal View History

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)
assets=[]
assets += step.assets
assets += step.marvin_js_assets
assets.sort! { |a, b|
a[asset_date_sort_field(a)] <=> b[asset_date_sort_field(b)]
}
2016-02-12 23:52:43 +08:00
end
def az_ordered_assets_index(step, asset_id)
assets=[]
assets += step.assets
assets += step.marvin_js_assets
assets.sort! { |a, b|
(a[asset_name_sort_field(a)] || '').downcase <=> (b[asset_name_sort_field(b)] || '').downcase
}.pluck(:id).index(asset_id)
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?
action_name == "steps"
end
def is_results_page?
action_name == "results"
end
private
def asset_date_sort_field(el)
result = {
'Asset' => :file_updated_at,
'MarvinJsAsset' => :updated_at
}
result[el.class.name]
end
def asset_name_sort_field(el)
result = {
'Asset' => :file_file_name,
'MarvinJsAsset' => :name
}
result[el.class.name]
end
2016-02-12 23:52:43 +08:00
end