2019-09-12 15:02:45 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
module ReportsHelper
|
2018-09-20 13:05:52 +08:00
|
|
|
include StringUtility
|
2021-10-01 20:18:40 +08:00
|
|
|
include Canaid::Helpers::PermissionsHelper
|
2018-09-20 13:05:52 +08:00
|
|
|
|
2017-03-08 21:14:03 +08:00
|
|
|
def render_report_element(element, provided_locals = nil)
|
2021-10-01 20:18:40 +08:00
|
|
|
case element.type_of
|
|
|
|
when 'experiment'
|
2023-03-22 17:51:45 +08:00
|
|
|
return unless can_read_experiment?(element.experiment)
|
2021-10-01 20:18:40 +08:00
|
|
|
when 'my_module'
|
2023-03-22 17:51:45 +08:00
|
|
|
return unless can_read_my_module?(element.my_module)
|
2021-10-01 20:18:40 +08:00
|
|
|
end
|
|
|
|
|
2018-10-12 04:35:03 +08:00
|
|
|
# Determine partial
|
2023-07-11 15:20:29 +08:00
|
|
|
view = "reports/elements/#{element.type_of}_element"
|
2018-10-12 04:35:03 +08:00
|
|
|
|
|
|
|
# Set locals
|
|
|
|
locals = provided_locals.nil? ? {} : provided_locals.clone
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2018-10-12 04:35:03 +08:00
|
|
|
children_html = ''.html_safe
|
2017-03-08 21:14:03 +08:00
|
|
|
# First, recursively render element's children
|
2021-06-10 16:59:34 +08:00
|
|
|
if element.children.active.present?
|
|
|
|
element.children.active.each do |child|
|
|
|
|
children_html.safe_concat render_report_element(child, provided_locals)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
2021-06-17 22:23:27 +08:00
|
|
|
locals[:report_element] = element
|
2017-03-08 21:14:03 +08:00
|
|
|
locals[:children] = children_html
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2023-07-12 21:42:34 +08:00
|
|
|
render partial: view, locals: locals, formats: :html
|
2017-03-08 21:14:03 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2017-03-08 21:14:03 +08:00
|
|
|
# "Hack" to omit file preview URL because of WKHTML issues
|
2019-10-17 19:30:14 +08:00
|
|
|
def report_image_asset_url(asset)
|
2020-10-28 23:32:22 +08:00
|
|
|
preview = asset.inline? ? asset.large_preview : asset.medium_preview
|
2023-07-12 21:42:34 +08:00
|
|
|
image_tag(preview.processed.url(expires_in: Constants::URL_LONG_EXPIRE_TIME))
|
2021-05-06 23:33:58 +08:00
|
|
|
rescue ActiveStorage::FileNotFoundError
|
2023-06-15 21:12:51 +08:00
|
|
|
image_tag('icon_small/missing.svg')
|
2021-08-30 20:18:31 +08:00
|
|
|
rescue StandardError => e
|
|
|
|
Rails.logger.error e.message
|
|
|
|
tag.i(I18n.t('projects.reports.index.generation.file_preview_generation_error'))
|
2017-03-08 21:14:03 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2021-06-17 22:23:27 +08:00
|
|
|
def assigned_repository_or_snapshot(my_module, repository)
|
2021-06-18 16:33:31 +08:00
|
|
|
if repository.is_a?(RepositorySnapshot)
|
|
|
|
return my_module.repository_snapshots.find_by(parent_id: repository.parent_id, selected: true)
|
|
|
|
end
|
2021-06-17 22:23:27 +08:00
|
|
|
|
2021-06-18 16:33:31 +08:00
|
|
|
return nil unless my_module.assigned_repositories.exists?(id: repository.id)
|
2021-06-17 22:23:27 +08:00
|
|
|
|
2021-06-18 16:33:31 +08:00
|
|
|
selected_snapshot = repository.repository_snapshots.find_by(my_module: my_module, selected: true)
|
|
|
|
selected_snapshot || repository
|
2020-05-22 01:25:28 +08:00
|
|
|
end
|
|
|
|
|
2017-05-05 15:45:18 +08:00
|
|
|
def step_status_label(step)
|
|
|
|
if step.completed
|
|
|
|
style = 'success'
|
|
|
|
text = t('protocols.steps.completed')
|
|
|
|
else
|
|
|
|
style = 'default'
|
|
|
|
text = t('protocols.steps.uncompleted')
|
|
|
|
end
|
2020-07-23 20:24:30 +08:00
|
|
|
"<span class=\"label step-label-#{style}\">[#{text}]</span>".html_safe
|
2017-05-05 15:45:18 +08:00
|
|
|
end
|
2017-06-22 22:40:50 +08:00
|
|
|
|
2023-11-03 20:19:46 +08:00
|
|
|
def font_awesome_links
|
|
|
|
[{ url: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/fontawesome.min.css' },
|
|
|
|
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/regular.min.css' },
|
|
|
|
{ url: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/solid.min.css' }]
|
2021-06-18 21:01:16 +08:00
|
|
|
end
|
|
|
|
|
2021-04-27 16:15:48 +08:00
|
|
|
def filter_steps_for_report(steps, settings)
|
|
|
|
include_completed_steps = settings.dig('task', 'protocol', 'completed_steps')
|
|
|
|
include_uncompleted_steps = settings.dig('task', 'protocol', 'uncompleted_steps')
|
|
|
|
if include_completed_steps && include_uncompleted_steps
|
|
|
|
steps
|
|
|
|
elsif include_completed_steps
|
|
|
|
steps.where(completed: true)
|
|
|
|
elsif include_uncompleted_steps
|
|
|
|
steps.where(completed: false)
|
|
|
|
else
|
|
|
|
steps.none
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def order_results_for_report(results, order)
|
|
|
|
case order
|
|
|
|
when 'atoz'
|
|
|
|
results.order(name: :asc)
|
|
|
|
when 'ztoa'
|
|
|
|
results.order(name: :desc)
|
|
|
|
when 'new'
|
2022-12-02 00:13:26 +08:00
|
|
|
results.order(created_at: :desc)
|
|
|
|
when 'old_updated'
|
|
|
|
results.order(updated_at: :asc)
|
|
|
|
when 'new_updated'
|
2021-04-27 16:15:48 +08:00
|
|
|
results.order(updated_at: :desc)
|
|
|
|
else
|
2022-12-02 00:13:26 +08:00
|
|
|
results.order(created_at: :asc)
|
2021-04-27 16:15:48 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-19 16:17:44 +08:00
|
|
|
def report_experiment_descriptions(report)
|
2021-04-27 16:15:48 +08:00
|
|
|
report.report_elements.experiment.map do |experiment_element|
|
2021-04-28 20:37:16 +08:00
|
|
|
experiment_element.experiment.description
|
|
|
|
end
|
2021-04-19 16:17:44 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def assigned_to_report_repository_items(report, repository_name)
|
|
|
|
repository = Repository.accessible_by_teams(report.team).where(name: repository_name).take
|
|
|
|
return RepositoryRow.none if repository.blank?
|
|
|
|
|
2021-05-04 18:49:38 +08:00
|
|
|
my_modules = MyModule.joins(:experiment)
|
|
|
|
.where(experiment: { project: report.project })
|
2021-04-19 16:17:44 +08:00
|
|
|
.where(id: report.report_elements.my_module.select(:my_module_id))
|
|
|
|
repository.repository_rows.joins(:my_modules).where(my_modules: my_modules)
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|