OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#49684] Text color for cover page overlay of pdf export
as-opf09eaae3567c
diff --git a/app/controllers/custom_styles_controller.rb b/app/controllers/custom_styles_controller.rbindex ecbb2d23f0f..2132070279f 100644--- a/app/controllers/custom_styles_controller.rb+++ b/app/controllers/custom_styles_controller.rb@@ -65,6 +65,22 @@ class CustomStylesController < ApplicationControllerendend+ def update_export_cover_text_color+ color = params[:export_cover_text_color]++ @custom_style = CustomStyle.current+ if @custom_style.nil?+ return render_404+ end++ color_hexcode_regex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/+ if !color.nil? && color.match(color_hexcode_regex)+ @custom_style.export_cover_text_color = color+ @custom_style.save+ end+ redirect_to custom_style_path+ end+def logo_downloadfile_download(:logo_path)end@@ -163,6 +179,7 @@ class CustomStylesController < ApplicationControllerparams.require(:custom_style).permit(:logo, :remove_logo,:export_logo, :remove_export_logo,:export_cover, :remove_export_cover,+ :export_cover_text_color,:favicon, :remove_favicon,:touch_icon, :remove_touch_icon)enddiff --git a/app/models/work_package/pdf_export/cover.rb b/app/models/work_package/pdf_export/cover.rbindex 09818c1078f..3df517d55d6 100644--- a/app/models/work_package/pdf_export/cover.rb+++ b/app/models/work_package/pdf_export/cover.rb@@ -60,41 +60,69 @@ module WorkPackage::PDFExport::Cover)end+ def cover_text_color+ @cover_text_color ||= validate_cover_text_color+ end++ def validate_cover_text_color+ return nil if CustomStyle.current.blank?++ color = CustomStyle.current.export_cover_text_color+ return nil if color.blank?++ # pdf hex colors are defined without leading hash+ color = color.sub('#', '')+ # prawn does not support short notation like #000+ color = color + color if color.size == 3+ color+ end+def write_hero_title(top, width)- text_style = styles.cover_hero_title- formatted_text_box_measured(- [text_style.merge({ text: project.name, size: nil, leading: nil })],- size: text_style[:size], leading: text_style[:leading],- at: [0, top], width:, height: styles.cover_hero_title_max_height, overflow: :shrink_to_fit+ write_hero_text(+ top:, width:,+ text: project.name,+ text_style: styles.cover_hero_title,+ height: styles.cover_hero_title_max_height) + styles.cover_hero_title_spacingenddef write_hero_heading(top, width)- max_title_height = available_title_height(top)- text_style = styles.cover_hero_heading- formatted_text_box_measured(- [text_style.merge({ text: heading, size: nil, leading: nil })],- size: text_style[:size], leading: text_style[:leading],- at: [0, top], width:, height: max_title_height, overflow: :shrink_to_fit+ write_hero_text(+ top:, width:,+ text: heading,+ text_style: styles.cover_hero_heading,+ height: available_title_height(top)) + styles.cover_hero_heading_spacingenddef write_hero_subheading(top, width)- text_style = styles.cover_hero_subheading- pdf.formatted_text_box(- [text_style.merge({ text: User.current.name, size: nil, leading: nil })],+ write_hero_text(+ top:, width:,+ text: User.current.name,+ text_style: styles.cover_hero_subheading,+ height: styles.cover_hero_subheading_max_height+ )+ end++ def write_hero_text(top:, width:, text:, text_style:, height:)+ formatted_text = text_style.merge({ text:, size: nil, leading: nil })+ formatted_text[:color] = cover_text_color if cover_text_color.present?+ formatted_text_box_measured(+ [formatted_text],size: text_style[:size], leading: text_style[:leading],- at: [0, top], width:, height: styles.cover_hero_subheading_max_height, overflow: :shrink_to_fit+ at: [0, top], width:, height:, overflow: :shrink_to_fit)enddef write_cover_footer+ text_style = styles.cover_footer+ text_style[:color] = cover_text_color if cover_text_color.present?draw_text_multiline_left(text: footer_date,max_left: pdf.bounds.width / 2,max_lines: 1,top: pdf.bounds.bottom - styles.cover_footer_offset,- text_style: styles.cover_footer+ text_style:)enddiff --git a/app/views/custom_styles/show.html.erb b/app/views/custom_styles/show.html.erbindex 890dbc7541c..6e2e0c1e741 100644--- a/app/views/custom_styles/show.html.erb+++ b/app/views/custom_styles/show.html.erb@@ -155,73 +155,115 @@ See COPYRIGHT and LICENSE files for more details.</section><% end %>-<%= form_for @custom_style, url: custom_style_path, html: { multipart: true, class: "form -vertical" } do |f| %>- <section class="form--section">- <fieldset class="form--fieldset">- <legend class="form--fieldset-legend"><%= I18n.t(:label_custom_export_logo) %></legend>-- <% if @custom_style.id && @custom_style.export_logo.present? %>- <div>- <%= tag('img', src: custom_style_export_logo_path(digest: @custom_style.digest, filename: @custom_style.export_logo_identifier), class: 'custom-export-logo-preview') %>- <%= link_to t(:button_delete),- custom_style_export_logo_delete_path,- method: :delete,- class: 'icon icon-delete confirm-form-submit' %>- </div>- <% end %>-- <div class="grid-block">- <div class="form--field -required">- <div class="attachment_field form--field-container -vertical -shrink">- <div class="form--file-container">- <%= f.file_field :export_logo, required: true, class: "attachment_choose_file", size: "15" %>- </div>+<% custom_export_expanded = @custom_style.id && (@custom_style.export_logo.present? || @custom_style.export_cover.present? || @custom_style.export_cover_text_color.present?) %>+<collapsible-section-augment initially-expanded="<%= custom_export_expanded %>"+ section-title="<%= I18n.t(:label_custom_pdf_export_settings) %>">+</collapsible-section-augment>+<div class="collapsible-section-augment--body" hidden>++ <%= form_for @custom_style, url: custom_style_path, html: { multipart: true, class: "form -vertical" } do |f| %>+ <section class="form--section">+ <fieldset class="form--fieldset">+ <legend class="form--fieldset-legend"><%= I18n.t(:label_custom_export_logo) %></legend>++ <% if @custom_style.id && @custom_style.export_logo.present? %>+ <div>+ <%= tag('img', src: custom_style_export_logo_path(digest: @custom_style.digest, filename: @custom_style.export_logo_identifier), class: 'custom-export-logo-preview') %>+ <%= link_to t(:button_delete),+ custom_style_export_logo_delete_path,+ method: :delete,+ class: 'icon icon-delete confirm-form-submit' %></div>- <div class="form--field-instructions">- <%= t('text_custom_export_logo_instructions') %>+ <% end %>++ <div class="grid-block">+ <div class="form--field -required">+ <div class="attachment_field form--field-container -vertical -shrink">+ <div class="form--file-container">+ <%= f.file_field :export_logo, required: true, class: "attachment_choose_file", size: "15" %>+ </div>+ </div>+ <div class="form--field-instructions">+ <%= t('text_custom_export_logo_instructions') %>+ </div></div></div>- </div>- <%= styled_button_tag t(@custom_style.export_logo.present? ? :button_replace : :button_upload), class: "button #{@custom_style.export_logo.blank? ? '-with-icon icon-add' : ''}" %>+ <%= styled_button_tag t(@custom_style.export_logo.present? ? :button_replace : :button_upload), class: "button #{@custom_style.export_logo.blank? ? '-with-icon icon-add' : ''}" %>- </fieldset>- </section>-<% end %>--<%= form_for @custom_style, url: custom_style_path, html: { multipart: true, class: "form -vertical" } do |f| %>- <section class="form--section">- <fieldset class="form--fieldset">- <legend class="form--fieldset-legend"><%= I18n.t(:label_custom_export_cover) %></legend>+ </fieldset>+ </section>+ <% end %>- <% if @custom_style.id && @custom_style.export_cover.present? %>- <div>- <%= tag('img', src: custom_style_export_cover_path(digest: @custom_style.digest, filename: @custom_style.export_cover_identifier), class: 'custom-export-cover-preview') %>- <%= link_to t(:button_delete),- custom_style_export_cover_delete_path,- method: :delete,- class: 'icon icon-delete confirm-form-submit' %>+ <%= form_for @custom_style, url: custom_style_path, html: { multipart: true, class: "form -vertical" } do |f| %>+ <section class="form--section">+ <fieldset class="form--fieldset">+ <legend class="form--fieldset-legend"><%= I18n.t(:label_custom_export_cover) %></legend>++ <% if @custom_style.id && @custom_style.export_cover.present? %>+ <div>+ <%= tag('img', src: custom_style_export_cover_path(digest: @custom_style.digest, filename: @custom_style.export_cover_identifier), class: 'custom-export-cover-preview') %>+ <%= link_to t(:button_delete),+ custom_style_export_cover_delete_path,+ method: :delete,+ class: 'icon icon-delete confirm-form-submit' %>+ </div>+ <% end %>++ <div class="grid-block">+ <div class="form--field -required">+ <div class="attachment_field form--field-container -vertical -shrink">+ <div class="form--file-container">+ <%= f.file_field :export_cover, required: true, class: "attachment_choose_file", size: "15" %>+ </div>+ </div>+ <div class="form--field-instructions">+ <%= t('text_custom_export_cover_instructions') %>+ </div>+ </div></div>- <% end %>- <div class="grid-block">- <div class="form--field -required">- <div class="attachment_field form--field-container -vertical -shrink">- <div class="form--file-container">- <%= f.file_field :export_cover, required: true, class: "attachment_choose_file", size: "15" %>+ <%= styled_button_tag t(@custom_style.export_cover.present? ? :button_replace : :button_upload), class: "button #{@custom_style.export_cover.blank? ? '-with-icon icon-add' : ''}" %>++ </fieldset>+ </section>+ <% end %>++ <%= form_tag update_custom_style_export_cover_text_color_path, html: { multipart: true, class: "form -vertical" } do |f| %>+ <section class="form--section">+ <fieldset class="form--fieldset">+ <legend class="form--fieldset-legend"><%= I18n.t(:label_custom_export_cover_overlay) %></legend>+ <div class="form--field">+ <label class="form--label"><%= I18n.t(:label_custom_export_cover_text_color) %>:</label>+ <span class="form--field-container">+ <div class="form--field-affix">+ <% design_color_name = 'export_cover_text_color' %>+ <% design_color_hex = @custom_style.export_cover_text_color.present? ? @custom_style.export_cover_text_color : '' %>+ <%= icon_for_color(OpenStruct.new(variable: design_color_name,+ hexcode: design_color_hex),+ data: { target: "#" + design_color_name }) %></div>- </div>+ <span class="form--text-field-container">+ <%= styled_text_field_tag design_color_name,+ design_color_hex,+ placeholder: '#000'+ %>+ </span>+ </span><div class="form--field-instructions">- <%= t('text_custom_export_cover_instructions') %>+ <% instruction_key = "admin.custom_styles.instructions.#{design_color_name}" %>+ <% if I18n.exists?(instruction_key, :en) %>+ <%= I18n.t(instruction_key) %>+ <% end %></div></div>- </div>- <%= styled_button_tag t(@custom_style.export_cover.present? ? :button_replace : :button_upload), class: "button #{@custom_style.export_cover.blank? ? '-with-icon icon-add' : ''}" %>+ <button type="submit" class="button -hide-when-collapsed"><%= I18n.t(:button_save) %></button>- </fieldset>- </section>-<% end %>+ </fieldset>+ </section>+ <% end %>+</div><%= form_tag update_design_colors_path, method: :post, class: "form" do %><section class="form--section">diff --git a/config/locales/en.yml b/config/locales/en.ymlindex a5679d3e201..79d8953bb8b 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1880,6 +1880,9 @@ en:label_custom_logo: "Custom logo"label_custom_export_logo: "Custom export logo"label_custom_export_cover: "Custom export cover background"+ label_custom_export_cover_overlay: "Custom export cover background overlay"+ label_custom_export_cover_text_color: "Text color"+ label_custom_pdf_export_settings: "Custom PDF export settings"label_custom_favicon: "Custom favicon"label_custom_touch_icon: "Custom touch icon"label_logout: "Sign out"@@ -2908,8 +2911,7 @@ en:A black or colored logo on transparent or white background is recommended.text_custom_export_cover_instructions: >This is the image that appears in the background of a cover page in your PDF exports.- It needs to be a PNG or JPEG image file with the image's dimensions about 800px width by 550px height.- A light image must be used to make the overlaid black text legible.+ It needs to be an about 800px width by 500px height sized PNG or JPEG image file.text_custom_favicon_instructions: >This is the tiny icon that appears in your browser window/tab next to thepage's title.diff --git a/config/routes.rb b/config/routes.rbindex ba484fd490a..2e31eb0f1dc 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -362,6 +362,9 @@ OpenProject::Application.routes.draw doget 'design/upsale' => 'custom_styles#upsale', as: 'custom_style_upsale'post 'design/colors' => 'custom_styles#update_colors', as: 'update_design_colors'post 'design/themes' => 'custom_styles#update_themes', as: 'update_design_themes'+ post 'design/export_cover_text_color' => 'custom_styles#update_export_cover_text_color',+ as: 'update_custom_style_export_cover_text_color'+resource :custom_style, only: %i[update show create], path: 'design'resources :attribute_help_texts, only: %i(index new create edit update destroy) dodiff --git a/db/migrate/20230905126002_add_export_cover_to_custom_style.rb b/db/migrate/20230905126002_add_export_cover_to_custom_style.rbindex 7a4cd85ad05..16e8c511739 100644--- a/db/migrate/20230905126002_add_export_cover_to_custom_style.rb+++ b/db/migrate/20230905126002_add_export_cover_to_custom_style.rb@@ -4,5 +4,9 @@ class AddExportCoverToCustomStyle < ActiveRecord::Migration[7.0]:export_cover,:string,default: nil+ add_column :custom_styles,+ :export_cover_text_color,+ :string,+ default: nilendenddiff --git a/spec/controllers/custom_styles_controller_spec.rb b/spec/controllers/custom_styles_controller_spec.rbindex 3b0b86d07fe..163344da61e 100644--- a/spec/controllers/custom_styles_controller_spec.rb+++ b/spec/controllers/custom_styles_controller_spec.rb@@ -465,6 +465,58 @@ RSpec.describe CustomStylesController doendend+ describe "#update_export_cover_text_color", with_ee: %i[define_custom_style] do+ let(:params) do+ { export_cover_text_color: "#990000" }+ end++ context 'if CustomStyle exists' do+ let(:custom_style) { CustomStyle.new }++ before do+ allow(CustomStyle).to receive(:current).and_return(custom_style)+ allow(custom_style).to receive(:export_cover_text_color).and_call_original+ end++ context 'with valid parameter' do+ before do+ post :update_export_cover_text_color, params:+ end++ it "saves the color" do+ expect(custom_style.export_cover_text_color).to eq("#990000")+ expect(response).to redirect_to action: :show+ end+ end++ context 'with invalid parameter' do+ let(:params) do+ { export_cover_text_color: "red" } # we only accept hexcodes+ end++ before do+ post :update_export_cover_text_color, params:+ end++ it "ignores the parameter" do+ expect(custom_style.export_cover_text_color).to be_nil+ expect(response).to redirect_to action: :show+ end+ end+ end++ context 'if CustomStyle does not exist' do+ before do+ allow(CustomStyle).to receive(:current).and_return(nil)+ post :update_export_cover_text_color, params:+ end++ it 'renders 404' do+ expect(response).to have_http_status :not_found+ end+ end+ end+describe "#update_colors", with_ee: %i[define_custom_style] dolet(:params) do{