From ac78c7d21bb736d6a3c6bfe1478c24da53b56081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Thu, 31 Jan 2019 07:39:17 +0100 Subject: [PATCH] Process Handsontable formulas in project HTML files in team export [SCI-2918] --- app/models/project.rb | 2 ++ app/models/team_zip_export.rb | 12 +++++++ app/views/team_zip_exports/report.html.erb | 37 +++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 73ffb8f4a..4e14304e7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -246,6 +246,8 @@ class Project < ApplicationRecord parsed_page_html = Nokogiri::HTML(page_html_string) parsed_html = parsed_page_html.at_css('#report-content') + # Style tables (mimick frontend processing) + tables = parsed_html.css('.hot-table-contents') .zip(parsed_html.css('.hot-table-container')) tables.each do |table_input, table_container| diff --git a/app/models/team_zip_export.rb b/app/models/team_zip_export.rb index 2ad9ea4ad..73bdb8286 100644 --- a/app/models/team_zip_export.rb +++ b/app/models/team_zip_export.rb @@ -129,6 +129,18 @@ class TeamZipExport < ZipExport ) file = FileUtils.touch("#{project_path}/#{html_name}").first File.open(file, 'wb') { |f| f.write(project_report_pdf) } + + # Add Handsontable and dependent JS files (mimick frontend formula + # processing). + required_js = %w(handsontable.full.min.js lodash.js numeral.js numeric.js + md5.js jstat.js formula.js parser.js ruleJS.js + handsontable.formula.js big.min.js) + required_js.each do |filename| + filepath = File.join(Rails.root, + "vendor/assets/javascripts/#{filename}/") + dest_folder = "#{project_path}/" + FileUtils.cp(filepath, dest_folder) + end end # Change current dir outside tmp_dir, since tmp_dir will be deleted diff --git a/app/views/team_zip_exports/report.html.erb b/app/views/team_zip_exports/report.html.erb index 0c40c95d7..2a8d3f81c 100644 --- a/app/views/team_zip_exports/report.html.erb +++ b/app/views/team_zip_exports/report.html.erb @@ -10,6 +10,41 @@ .force_encoding(Encoding::UTF_8) .html_safe %> + + + + + + + + + + + + + + + + + + <%= title %> @@ -17,4 +52,4 @@ <%= content.force_encoding(Encoding::UTF_8).html_safe %> - \ No newline at end of file +