mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 17:36:33 +08:00
Add default settings to existing reports [SCI-5619][SCI-5672]
This commit is contained in:
parent
57c90a60c4
commit
b67f2a21f5
11 changed files with 39 additions and 30 deletions
|
@ -109,6 +109,7 @@ class ReportsController < ApplicationController
|
||||||
@edit = true
|
@edit = true
|
||||||
@templates = Extends::REPORT_TEMPLATES
|
@templates = Extends::REPORT_TEMPLATES
|
||||||
@repositories = Repository.accessible_by_teams(current_team).active.select(:id, :name)
|
@repositories = Repository.accessible_by_teams(current_team).active.select(:id, :name)
|
||||||
|
@report.settings = Report::DEFAULT_SETTINGS if @report.settings.blank?
|
||||||
|
|
||||||
@project_contents = {
|
@project_contents = {
|
||||||
experiments: @report.report_elements.where(type_of: 'experiment').pluck(:experiment_id),
|
experiments: @report.report_elements.where(type_of: 'experiment').pluck(:experiment_id),
|
||||||
|
|
|
@ -214,6 +214,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
Rails.logger.error e.message
|
Rails.logger.error e.message
|
||||||
|
'icon_small/missing.png'
|
||||||
end
|
end
|
||||||
|
|
||||||
def wopi_enabled?
|
def wopi_enabled?
|
||||||
|
|
|
@ -93,7 +93,6 @@ module ReportsHelper
|
||||||
element.element_references.each do |el_ref|
|
element.element_references.each do |el_ref|
|
||||||
locals[el_ref.class.name.underscore.to_sym] = el_ref
|
locals[el_ref.class.name.underscore.to_sym] = el_ref
|
||||||
end
|
end
|
||||||
locals[:order] = element.sort_order if type.in? ReportExtends::SORTED_ELEMENTS
|
|
||||||
end
|
end
|
||||||
|
|
||||||
(render partial: view, locals: locals).html_safe
|
(render partial: view, locals: locals).html_safe
|
||||||
|
@ -102,8 +101,9 @@ module ReportsHelper
|
||||||
# "Hack" to omit file preview URL because of WKHTML issues
|
# "Hack" to omit file preview URL because of WKHTML issues
|
||||||
def report_image_asset_url(asset)
|
def report_image_asset_url(asset)
|
||||||
preview = asset.inline? ? asset.large_preview : asset.medium_preview
|
preview = asset.inline? ? asset.large_preview : asset.medium_preview
|
||||||
image_tag(preview.processed
|
image_tag(preview.processed.service_url(expires_in: Constants::URL_LONG_EXPIRE_TIME))
|
||||||
.service_url(expires_in: Constants::URL_LONG_EXPIRE_TIME))
|
rescue ActiveStorage::FileNotFoundError
|
||||||
|
image_tag('icon_small/missing.png')
|
||||||
end
|
end
|
||||||
|
|
||||||
# "Hack" to load Glyphicons css directly from the CDN
|
# "Hack" to load Glyphicons css directly from the CDN
|
||||||
|
|
|
@ -20,9 +20,10 @@ module Reports
|
||||||
def perform(report, user)
|
def perform(report, user)
|
||||||
file = Tempfile.new(['report', '.pdf'], binmode: true)
|
file = Tempfile.new(['report', '.pdf'], binmode: true)
|
||||||
begin
|
begin
|
||||||
template_name = Extends::REPORT_TEMPLATES[report.settings[:template]&.to_sym]
|
template = Extends::REPORT_TEMPLATES[report.settings[:template]&.to_sym]
|
||||||
|
template ||= Extends::REPORT_TEMPLATES.values.first
|
||||||
|
|
||||||
raise StandardError, 'Report template not found!' if template_name.blank?
|
raise StandardError, 'Report template not found!' if template.blank?
|
||||||
|
|
||||||
ActionController::Renderer::RACK_KEY_TRANSLATION['warden'] ||= 'warden'
|
ActionController::Renderer::RACK_KEY_TRANSLATION['warden'] ||= 'warden'
|
||||||
proxy = Warden::Proxy.new({}, Warden::Manager.new({}))
|
proxy = Warden::Proxy.new({}, Warden::Manager.new({}))
|
||||||
|
@ -30,10 +31,10 @@ module Reports
|
||||||
renderer = ApplicationController.renderer.new(warden: proxy)
|
renderer = ApplicationController.renderer.new(warden: proxy)
|
||||||
|
|
||||||
file << renderer.render(
|
file << renderer.render(
|
||||||
pdf: 'report', header: { html: { template: "reports/templates/#{template_name}/header",
|
pdf: 'report', header: { html: { template: "reports/templates/#{template}/header",
|
||||||
locals: { report: report, user: user },
|
locals: { report: report, user: user },
|
||||||
layout: 'reports/footer_header.html.erb' } },
|
layout: 'reports/footer_header.html.erb' } },
|
||||||
footer: { html: { template: "reports/templates/#{template_name}/footer",
|
footer: { html: { template: "reports/templates/#{template}/footer",
|
||||||
locals: { report: report, user: user },
|
locals: { report: report, user: user },
|
||||||
layout: 'reports/footer_header.html.erb' } },
|
layout: 'reports/footer_header.html.erb' } },
|
||||||
assigns: { settings: report.settings },
|
assigns: { settings: report.settings },
|
||||||
|
@ -44,7 +45,7 @@ module Reports
|
||||||
|
|
||||||
file.rewind
|
file.rewind
|
||||||
|
|
||||||
file = prepend_title_page(file, template_name, report, renderer)
|
file = prepend_title_page(file, template, report, renderer)
|
||||||
|
|
||||||
file = append_result_asset_previews(report, file) if report.settings.dig(:task, :file_results_previews)
|
file = append_result_asset_previews(report, file) if report.settings.dig(:task, :file_results_previews)
|
||||||
|
|
||||||
|
@ -103,9 +104,8 @@ module Reports
|
||||||
merged_file
|
merged_file
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepend_title_page(file, template_name, report, renderer)
|
def prepend_title_page(file, template, report, renderer)
|
||||||
|
unless File.exist?(Rails.root.join('app', 'views', 'reports', 'templates', template, 'cover.html.erb'))
|
||||||
unless File.exists?(Rails.root.join('app', 'views', 'reports', 'templates', template_name, 'cover.html.erb'))
|
|
||||||
return file
|
return file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ module Reports
|
||||||
merged_file = Tempfile.new(['report', '.pdf'], binmode: true)
|
merged_file = Tempfile.new(['report', '.pdf'], binmode: true)
|
||||||
|
|
||||||
title_page << renderer.render(
|
title_page << renderer.render(
|
||||||
pdf: 'report', inline: renderer.render_to_string("reports/templates/#{template_name}/cover.html.erb",
|
pdf: 'report', inline: renderer.render_to_string("reports/templates/#{template}/cover.html.erb",
|
||||||
layout: false,
|
layout: false,
|
||||||
locals: { report: report, total_pages: total_pages.to_i }),
|
locals: { report: report, total_pages: total_pages.to_i }),
|
||||||
disable_javascript: false,
|
disable_javascript: false,
|
||||||
|
|
|
@ -20,12 +20,16 @@ module TinyMceImages
|
||||||
tiny_mce_assets.each do |tm_asset|
|
tiny_mce_assets.each do |tm_asset|
|
||||||
next unless tm_asset&.image&.attached?
|
next unless tm_asset&.image&.attached?
|
||||||
|
|
||||||
new_tm_asset_src =
|
begin
|
||||||
if base64_encoded_imgs
|
new_tm_asset_src =
|
||||||
tm_asset.convert_variant_to_base64(tm_asset.preview)
|
if base64_encoded_imgs
|
||||||
else
|
tm_asset.convert_variant_to_base64(tm_asset.preview)
|
||||||
tm_asset.preview.processed.service_url(expires_in: Constants::URL_LONG_EXPIRE_TIME)
|
else
|
||||||
end
|
tm_asset.preview.processed.service_url(expires_in: Constants::URL_LONG_EXPIRE_TIME)
|
||||||
|
end
|
||||||
|
rescue ActiveStorage::FileNotFoundError
|
||||||
|
next
|
||||||
|
end
|
||||||
html_description = Nokogiri::HTML(description)
|
html_description = Nokogiri::HTML(description)
|
||||||
tm_asset_to_update = html_description.css(
|
tm_asset_to_update = html_description.css(
|
||||||
"img[data-mce-token=\"#{Base62.encode(tm_asset.id)}\"]"
|
"img[data-mce-token=\"#{Base62.encode(tm_asset.id)}\"]"
|
||||||
|
|
|
@ -35,6 +35,7 @@ class Report < ApplicationRecord
|
||||||
dependent: :delete_all
|
dependent: :delete_all
|
||||||
|
|
||||||
DEFAULT_SETTINGS = {
|
DEFAULT_SETTINGS = {
|
||||||
|
template: 'scinote_template',
|
||||||
all_tasks: true,
|
all_tasks: true,
|
||||||
task: {
|
task: {
|
||||||
protocol: {
|
protocol: {
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
data-type="my_module_repository"
|
data-type="my_module_repository"
|
||||||
data-id='{ "my_module_id": <%= my_module.id %>, "repository_id": <%= repository.id %> }'
|
data-id='{ "my_module_id": <%= my_module.id %>, "repository_id": <%= repository.id %> }'
|
||||||
data-scroll-id="<%= "#{my_module.id}_#{repository.id}" %>"
|
data-scroll-id="<%= "#{my_module.id}_#{repository.id}" %>"
|
||||||
data-order="<%= order == :asc ? 'asc' : 'desc' %>"
|
|
||||||
data-name="<%= repository.name %>"
|
data-name="<%= repository.name %>"
|
||||||
data-icon-class="fas fa-list-alt">
|
data-icon-class="fas fa-list-alt">
|
||||||
<div class="report-element-header">
|
<div class="report-element-header">
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
<% if result.blank? and @result.present? then result = @result end %>
|
<% result ||= @result %>
|
||||||
<% if order.blank? and @order.present? then order = @order end %>
|
<% comments = result.result_comments.order(created_at: :desc) %>
|
||||||
<% comments = result.result_comments.order(created_at: order) %>
|
|
||||||
<% timestamp = Time.current + 1.year %>
|
<% timestamp = Time.current + 1.year %>
|
||||||
<% for_export_all = defined?(export_all) && export_all %>
|
<% for_export_all = defined?(export_all) && export_all %>
|
||||||
<div class="report-element report-comments-element report-result-comments-element" data-ts="<%= timestamp.to_i %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-type="result_comments" data-id='{ "result_id": <%= result.id %> }' data-scroll-id="<%= result.id %>" data-name="<%=t "projects.reports.elements.result_comments.sidebar_name" %>" data-icon-class="fas fa-comment">
|
<div class="report-element report-comments-element report-result-comments-element" data-ts="<%= timestamp.to_i %>" data-type="result_comments" data-id='{ "result_id": <%= result.id %> }' data-scroll-id="<%= result.id %>" data-name="<%=t "projects.reports.elements.result_comments.sidebar_name" %>" data-icon-class="fas fa-comment">
|
||||||
<div class="report-element-header">
|
<div class="report-element-header">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="pull-left comments-icon">
|
<div class="pull-left comments-icon">
|
||||||
|
|
|
@ -112,12 +112,6 @@ module ReportExtends
|
||||||
# path: app/helpers/reports_helpers.rb
|
# path: app/helpers/reports_helpers.rb
|
||||||
# method: render_report_element
|
# method: render_report_element
|
||||||
|
|
||||||
# adds :order local to listed elements views
|
|
||||||
# ADD REPORT ELEMENT TYPE WHICH YOU WANT TO PASS 'ORDER' LOCAL IN THE PARTIAL
|
|
||||||
SORTED_ELEMENTS = %w(my_module_activity
|
|
||||||
my_module_repository
|
|
||||||
step_comments
|
|
||||||
result_comments)
|
|
||||||
# sets local :my_module to the listed my_module child elements
|
# sets local :my_module to the listed my_module child elements
|
||||||
MY_MODULE_ELEMENTS = %w(my_module
|
MY_MODULE_ELEMENTS = %w(my_module
|
||||||
my_module_protocol
|
my_module_protocol
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddDefaultSettingsToOldReports < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
Report.find_each do |report|
|
||||||
|
report.update!(settings: Report::DEFAULT_SETTINGS)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -7233,6 +7233,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20210217114042'),
|
('20210217114042'),
|
||||||
('20210312185911'),
|
('20210312185911'),
|
||||||
('20210325152257'),
|
('20210325152257'),
|
||||||
('20210407143303');
|
('20210407143303'),
|
||||||
|
('20210506125657');
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue