From 5ca822a7d846f6bac25c3e62f2c3bd60c12c9ebf Mon Sep 17 00:00:00 2001 From: aignatov-bio <47317017+aignatov-bio@users.noreply.github.com> Date: Fri, 12 Jul 2019 11:38:48 +0200 Subject: [PATCH] Add archive lables and fix bright colors in RTE fields (#1923) --- app/services/reports/docx/draw_experiment.rb | 4 ++++ app/services/reports/docx/draw_my_module.rb | 4 ++++ app/services/reports/docx/private_methods.rb | 14 +++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/services/reports/docx/draw_experiment.rb b/app/services/reports/docx/draw_experiment.rb index a78156036..bf945c542 100644 --- a/app/services/reports/docx/draw_experiment.rb +++ b/app/services/reports/docx/draw_experiment.rb @@ -12,6 +12,10 @@ module DrawExperiment @docx.p do text I18n.t('projects.reports.elements.experiment.user_time', timestamp: I18n.l(experiment.created_at, format: :full)), color: color[:gray] + if experiment.archived? + text ' | ' + text I18n.t('search.index.archived'), color: color[:gray] + end text ' | ' link I18n.t('projects.reports.elements.all.scinote_link'), scinote_url + Rails.application.routes.url_helpers.canvas_experiment_path(experiment), diff --git a/app/services/reports/docx/draw_my_module.rb b/app/services/reports/docx/draw_my_module.rb index d8a5e8061..5f8b90d9f 100644 --- a/app/services/reports/docx/draw_my_module.rb +++ b/app/services/reports/docx/draw_my_module.rb @@ -23,6 +23,10 @@ module DrawMyModule text " #{I18n.t('my_modules.states.completed')} #{I18n.l(my_module.completed_on, format: :full)}", color: color[:gray] end + if my_module.archived? + text ' | ' + text I18n.t('search.index.archived'), color: color[:gray] + end text ' | ' link I18n.t('projects.reports.elements.all.scinote_link'), scinote_url + Rails.application.routes.url_helpers.protocols_my_module_path(my_module), diff --git a/app/services/reports/docx/private_methods.rb b/app/services/reports/docx/private_methods.rb index 392ee1714..4cc9d6bf9 100644 --- a/app/services/reports/docx/private_methods.rb +++ b/app/services/reports/docx/private_methods.rb @@ -142,7 +142,7 @@ module PrivateMethods value = style_el.split(':')[1].strip if style_el if key == 'text-align' result[:align] = value.to_sym - elsif key == 'color' + elsif key == 'color' && calculate_color_hsp(value) < 190 result[:color] = value.delete('#') end end @@ -276,4 +276,16 @@ module PrivateMethods image.open.path end end + + def calculate_color_hsp(color) + return 255 if color.length != 7 + + color = color.delete('#').scan(/.{1,2}/) + rgb = color.map(&:hex) + Math.sqrt( + 0.299 * (rgb[0]**2) + + 0.587 * (rgb[1]**2) + + 0.114 * (rgb[2]**2) + ) + end end