Skip to content

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

refactor duplicate code in custom styles view; add PDF demo generator

as-opb3d108e71c88
diff --git a/app/controllers/custom_styles_controller.rb b/app/controllers/custom_styles_controller.rb
index 96f2202801b..78ee35e5a30 100644
--- a/app/controllers/custom_styles_controller.rb
+++ b/app/controllers/custom_styles_controller.rb
@@ -184,6 +184,19 @@ class CustomStylesController < ApplicationController
redirect_to custom_style_path
end
+ def export_demo_pdf_download
+ result = ::Exports::PDF::DemoGenerator.new.export!
+ expires_in 0, public: false
+ send_data result.content,
+ filename: result.title,
+ type: "application/pdf",
+ disposition: "inline"
+ rescue StandardError => e
+ Rails.logger.error "Failed to generate demo PDF: #{e.message}"
+ flash[:error] = e.message
+ redirect_to custom_style_path
+ end
+
private
def theme_from_params
diff --git a/app/models/exports/pdf/demo_generator.rb b/app/models/exports/pdf/demo_generator.rb
new file mode 100644
index 00000000000..204449a70cf
--- /dev/null
+++ b/app/models/exports/pdf/demo_generator.rb
@@ -0,0 +1,149 @@
+# frozen_string_literal: true
+
+module Exports::PDF
+ class DemoPDFStyles
+ include MarkdownToPDF::Common
+ include MarkdownToPDF::StyleHelper
+ include Exports::PDF::Common::Styles
+ include Exports::PDF::Components::PageStyles
+ include Exports::PDF::Components::CoverStyles
+
+ def initialize
+ @styles = {
+ cover: {
+ hero: {
+ padding_top: 120,
+ title: {
+ max_height: 30,
+ spacing: 10,
+ font: "SpaceMono"
+ },
+ heading: {
+ spacing: 14,
+ styles: ["bold"],
+ size: 16
+ }
+ }
+ }
+ }
+ end
+ end
+
+ class DemoGenerator < ::Exports::Exporter
+ include Exports::PDF::Common::Common
+ include Exports::PDF::Common::Logo
+ include Exports::PDF::Components::Page
+ include Exports::PDF::Components::Cover
+ include Exports::PDF::Common::Attachments
+
+ attr_reader :pdf
+
+ def initialize
+ super(nil)
+ setup_page!
+ end
+
+ # This export is not tied to a particular AR model
+ self.model = NilClass
+
+ def self.key
+ :demo_pdf
+ end
+
+ def styles
+ @styles ||= DemoPDFStyles.new
+ end
+
+ def setup_page!
+ @pdf = get_pdf
+ configure_page_size!(:portrait)
+ pdf.title = heading
+ @page_count = 0
+ end
+
+ def export!
+ render_demo
+ success(pdf.render)
+ rescue StandardError => e
+ Rails.logger.error "Failed to generate demo PDF: #{e.message}:\n#{e.backtrace.join("\n")}"
+ error(I18n.t(:error_pdf_failed_to_export, error: e.message))
+ ensure
+ delete_all_resized_images
+ end
+
+ def heading
+ I18n.t("export.demo.heading")
+ end
+
+ def cover_page_heading
+ heading
+ end
+
+ def cover_page_title
+ Setting.app_title
+ end
+
+ def cover_page_dates
+ nil
+ end
+
+ def cover_page_subheading
+ nil
+ end
+
+ def footer_title
+ I18n.t("export.demo.footer",)
+ end
+
+ # Suggested filename
+ def title
+ "demo_#{Time.zone.now.strftime('%Y-%m-%d_%H-%M')}.pdf"
+ end
+
+ def with_images?
+ true
+ end
+
+ def header_footer_filter_pages
+ [2]
+ end
+
+ def render_demo
+ render_demo_page
+ pdf.start_new_page
+ render_demo_cover
+ write_logo!
+ write_footers!
+ end
+
+ def write_demo_text(text, size: 12, style: :normal)
+ pdf.text(text, style:, size:)
+ pdf.move_down 10
+ end
+
+ def render_demo_page
+ write_demo_text heading.to_s, size: 22, style: :bold
+ pdf.move_down 10
+
+ write_demo_text "Regular"
+ write_demo_text "Bold", style: :bold
+ write_demo_text "Italic", style: :italic
+ write_demo_text "Bold Italic", style: :bold_italic
+ pdf.move_down 10
+
+ write_demo_text(
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " \
+ "Vivamus lacinia odio vitae vestibulum vestibulum. " \
+ "Cras venenatis euismod malesuada.",
+ size: 11
+ )
+ end
+
+ def render_demo_cover
+ write_cover_logo
+ write_cover_hr
+ write_cover_hero
+ write_cover_footer
+ end
+ end
+end
diff --git a/app/views/custom_styles/_branding.html.erb b/app/views/custom_styles/_branding.html.erb
index 03c77b0ad98..4c38323d317 100644
--- a/app/views/custom_styles/_branding.html.erb
+++ b/app/views/custom_styles/_branding.html.erb
@@ -27,93 +27,41 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= 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_logo) %></legend>
- <% if @custom_style.id && @custom_style.logo.present? %>
- <div>
- <%# Don't use image_tag here due to asset host %>
- <%= tag("img", src: custom_style_logo_path(digest: @custom_style.digest, filename: @custom_style.logo_identifier), class: "custom-logo-preview") %>
- <%= link_to t(:button_delete),
- custom_style_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 :logo, required: true, class: "attachment_choose_file", size: "15" %>
- </div>
- </div>
- <div class="form--field-instructions">
- <%= t("text_custom_logo_instructions") %>
- </div>
- </div>
- </div>
- <%= styled_button_tag I18n.t(@custom_style.logo.present? ? :button_replace : :button_upload),
- class: "button #{@custom_style.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_favicon) %></legend>
+<%= render partial: "custom_styles/uploads/image", locals: { image:{
+ field: :logo,
+ label: I18n.t(:label_custom_logo),
+ present: @custom_style.id && @custom_style.logo.present?,
+ source: @custom_style.id && @custom_style.logo.present? ?
+ custom_style_logo_path(digest: @custom_style.digest, filename: @custom_style.logo_identifier) :
+ nil,
+ img_class: "custom-logo-preview",
+ accept: "image/*",
+ delete_path: custom_style_logo_delete_path,
+ instructions: I18n.t("text_custom_logo_instructions")
+} } %>
- <% if @custom_style.id && @custom_style.favicon.present? %>
- <div>
- <%= tag("img", src: custom_style_favicon_path(digest: @custom_style.digest, filename: @custom_style.favicon_identifier), class: "custom-favicon-preview") %>
- <%= link_to t(:button_delete),
- custom_style_favicon_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 :favicon, required: true, class: "attachment_choose_file", size: "15" %>
- </div>
- </div>
- <div class="form--field-instructions">
- <%= t("text_custom_favicon_instructions") %>
- </div>
- </div>
- </div>
- <%= styled_button_tag t(@custom_style.favicon.present? ? :button_replace : :button_upload), class: "button #{@custom_style.favicon.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_touch_icon) %></legend>
- <% if @custom_style.id && @custom_style.touch_icon.present? %>
- <div>
- <%= tag("img", src: custom_style_touch_icon_path(digest: @custom_style.digest, filename: @custom_style.touch_icon_identifier), class: "custom-touch-icon-preview") %>
- <%= link_to t(:button_delete),
- custom_style_touch_icon_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 :touch_icon, required: true, class: "attachment_choose_file", size: "15" %>
- </div>
- </div>
- <div class="form--field-instructions">
- <%= t("text_custom_touch_icon_instructions") %>
- </div>
- </div>
- </div>
- <%= styled_button_tag t(@custom_style.touch_icon.present? ? :button_replace : :button_upload), class: "button #{@custom_style.touch_icon.blank? ? '-with-icon icon-add' : ''}" %>
- </fieldset>
- </section>
-<% end %>
+<%= render partial: "custom_styles/uploads/image", locals: { image:{
+ field: :favicon,
+ label: I18n.t(:label_custom_favicon),
+ present: @custom_style.id && @custom_style.favicon.present?,
+ source: @custom_style.id && @custom_style.favicon.present? ?
+ custom_style_favicon_path(digest: @custom_style.digest, filename: @custom_style.favicon_identifier) :
+ nil,
+ img_class: "custom-favicon-preview",
+ accept: "image/*",
+ delete_path: custom_style_favicon_delete_path,
+ instructions: I18n.t("text_custom_favicon_instructions")
+} } %>
+
+<%= render partial: "custom_styles/uploads/image", locals: { image:{
+ field: :favicon,
+ label: I18n.t(:label_custom_touch_icon),
+ present: @custom_style.id && @custom_style.touch_icon.present?,
+ source: @custom_style.id && @custom_style.touch_icon.present? ?
+ custom_style_touch_icon_path(digest: @custom_style.digest, filename: @custom_style.touch_icon_identifier) :
+ nil,
+ img_class: "custom-touch-icon-preview",
+ accept: "image/*",
+ delete_path: custom_style_touch_icon_delete_path,
+ instructions: I18n.t("text_custom_touch_icon_instructions")
+} } %>
diff --git a/app/views/custom_styles/_pdf_export_font.html.erb b/app/views/custom_styles/_pdf_export_font.html.erb
index 3ec2fef9d22..1d652983002 100644
--- a/app/views/custom_styles/_pdf_export_font.html.erb
+++ b/app/views/custom_styles/_pdf_export_font.html.erb
@@ -29,30 +29,17 @@ See COPYRIGHT and LICENSE files for more details.
<p><%= I18n.t(:label_custom_export_font_instructions) %></p>
+<%=
+ render(Primer::Beta::Button.new(
+ target: "_blank",
+ data: { turbo: false },
+ tag: :a,
+ href: export_demo_pdf_download_custom_style_path
+ )) do |_c|
+ t("export.demo.button_text")
+ end
+%>
+
<% export_fonts_fields(@custom_style).each do |font| %>
- <%= 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"><%= font[:label] %></legend>
- <% if font[:present] %>
- <div>
- <span><%= font[:filename] %></span>
- <%= link_to t(:button_delete), font[: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 font[:field], required: true, class: "attachment_choose_file", accept: "font/ttf", size: "15" %>
- </div>
- </div>
- <div class="form--field-instructions"><%= font[:instructions] %></div>
- </div>
- </div>
- <%= styled_button_tag t(font[:present] ? :button_replace : :button_upload),
- class: "button #{font[:present] ? '' : '-with-icon icon-add'}" %>
- </fieldset>
- </section>
- <% end %>
+ <%= render partial: "custom_styles/uploads/font", locals: { font: } %>
<% end %>
diff --git a/app/views/custom_styles/_pdf_export_styles.html.erb b/app/views/custom_styles/_pdf_export_styles.html.erb
index cb527f8cde1..ee8e747e61c 100644
--- a/app/views/custom_styles/_pdf_export_styles.html.erb
+++ b/app/views/custom_styles/_pdf_export_styles.html.erb
@@ -27,67 +27,45 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<%= 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, accept: 'image/png, image/jpg', class: "attachment_choose_file", size: "15" %>
- </div>
- </div>
- <div class="form--field-instructions">
- <%= t("text_custom_export_logo_instructions") %>
- </div>
- </div>
- </div>
+<p><%= I18n.t("label_custom_export_images_instructions") %></p>
- <%= styled_button_tag t(@custom_style.export_logo.present? ? :button_replace : :button_upload), class: "button #{@custom_style.export_logo.blank? ? '-with-icon icon-add' : ''}" %>
+<%=
+ render(Primer::Beta::Button.new(
+ target: "_blank",
+ data: { turbo: false },
+ tag: :a,
+ href: export_demo_pdf_download_custom_style_path
+ )) do |_c|
+ t("export.demo.button_text")
+ end
+%>
- </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>
+<%= render partial: "custom_styles/uploads/image", locals: { image:{
+ field: :export_logo,
+ label: I18n.t(:label_custom_export_logo),
+ present: @custom_style.id && @custom_style.export_logo.present?,
+ source: @custom_style.id && @custom_style.export_logo.present? ?
+ custom_style_export_logo_path(digest: @custom_style.digest, filename: @custom_style.export_logo_identifier) :
+ nil,
+ img_class: "custom-export-logo-preview",
+ accept: "image/png, image/jpg",
+ delete_path: custom_style_export_logo_delete_path,
+ instructions: I18n.t("text_custom_export_logo_instructions")
+} } %>
+
+<%= render partial: "custom_styles/uploads/image", locals: { image:{
+ field: :export_cover,
+ label: I18n.t(:label_custom_export_cover),
+ present: @custom_style.id && @custom_style.export_cover.present?,
+ source: @custom_style.id && @custom_style.export_cover.present? ?
+ custom_style_export_cover_path(digest: @custom_style.digest, filename: @custom_style.export_cover_identifier) :
+ nil,
+ img_class: "custom-export-cover-preview",
+ accept: "image/png, image/jpg",
+ delete_path: custom_style_export_cover_delete_path,
+ instructions: I18n.t("text_custom_export_cover_instructions")
+} } %>
- <% 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, accept: 'image/png, image/jpg', class: "attachment_choose_file", size: "15" %>
- </div>
- </div>
- <div class="form--field-instructions">
- <%= t("text_custom_export_cover_instructions") %>
- </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' : ''}" %>
- </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">
@@ -97,17 +75,17 @@ See COPYRIGHT and LICENSE files for more details.
<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.presence || "" %>
+ <% design_color_hex = @custom_style.export_cover_text_color.presence %>
<%= icon_for_color(
Color.new(
- hexcode: design_color_hex
+ hexcode: design_color_hex || "#000"
),
data: { target: "#" + design_color_name }
) %>
</div>
<span class="form--text-field-container">
<%= styled_text_field_tag design_color_name,
- design_color_hex,
+ design_color_hex || "",
placeholder: "#000" %>
</span>
</span>
@@ -118,39 +96,31 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
</div>
</div>
- <button type="submit" class="button -hide-when-collapsed" data-test-selector="text-color-change"><%= I18n.t(:button_save) %></button>
+ <%=
+ render(Primer::Beta::Button.new(
+ type: :submit,
+ data: {
+ "test-selector": "text-color-change"
+ }
+ )) do |button|
+ I18n.t(:button_save)
+ end
+ %>
</fieldset>
</section>
<% end %>
-<% if OpenProject::FeatureDecisions.minutes_styling_meeting_pdf_active? %>
-<%= 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_footer) %></legend>
- <% if @custom_style.id && @custom_style.export_footer.present? %>
- <div>
- <%= tag("img", src: custom_style_export_footer_path(digest: @custom_style.digest, filename: @custom_style.export_footer_identifier), class: "custom-export-footer-preview") %>
- <%= link_to t(:button_delete),
- custom_style_export_footer_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_footer, required: true, accept: 'image/png, image/jpg', class: "attachment_choose_file", size: "15" %>
- </div>
- </div>
- <div class="form--field-instructions">
- <%= t("text_custom_export_footer_instructions") %>
- </div>
- </div>
- </div>
- <%= styled_button_tag t(@custom_style.export_footer.present? ? :button_replace : :button_upload), class: "button #{@custom_style.export_footer.blank? ? '-with-icon icon-add' : ''}" %>
- </fieldset>
- </section>
-<% end %>
+<% if OpenProject::FeatureDecisions.minutes_styling_meeting_pdf_active? %>
+ <%= render partial: "custom_styles/uploads/image", locals: { image:{
+ field: :export_footer,
+ label: I18n.t(:label_custom_export_footer),
+ present: @custom_style.id && @custom_style.export_footer.present?,
+ source: @custom_style.id && @custom_style.export_footer.present? ?
+ custom_style_export_footer_path(digest: @custom_style.digest, filename: @custom_style.export_footer_identifier) :
+ nil,
+ img_class: "custom-export-footer-preview",
+ accept: "image/png, image/jpg",
+ delete_path: custom_style_export_footer_delete_path,
+ instructions: I18n.t("text_custom_export_footer_instructions")
+ } } %>
<% end %>
diff --git a/app/views/custom_styles/uploads/_font.erb b/app/views/custom_styles/uploads/_font.erb
new file mode 100644
index 00000000000..3ba4d121f68
--- /dev/null
+++ b/app/views/custom_styles/uploads/_font.erb
@@ -0,0 +1,70 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) the OpenProject GmbH
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+Copyright (C) 2006-2013 Jean-Philippe Lang
+Copyright (C) 2010-2013 the ChiliProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<%= 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"><%= font[:label] %></legend>
+ <p class="form--field-instructions"><%= font[:instructions] %></p>
+ <% if font[:present] %>
+ <p>
+ <%= render(Primer::Beta::Octicon.new(icon: :file)) %>
+ <strong><%= font[:filename] %></strong></p>
+ <% 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 font[:field], required: true, class: "attachment_choose_file", accept: "font/ttf", size: "15" %>
+ </div>
+ </div>
+ </div>
+ </div>
+ <%=
+ render(Primer::Beta::Button.new(
+ type: :submit
+ )) do |button|
+ button.with_leading_visual_icon(icon: font[:present] ? :upload : :plus)
+ t(font[:present] ? :button_replace : :button_upload)
+ end
+ %>
+ <% if font[:present] %>
+ <%= render(Primer::Beta::Button.new(
+ tag: :a,
+ href: font[:delete_path],
+ data: { method: :delete }
+ )) do |button|
+ button.with_leading_visual_icon(icon: :trash)
+ t(:button_delete)
+ end
+ %>
+ <% end %>
+ </fieldset>
+ </section>
+<% end %>
diff --git a/app/views/custom_styles/uploads/_image.erb b/app/views/custom_styles/uploads/_image.erb
new file mode 100644
index 00000000000..80881843603
--- /dev/null
+++ b/app/views/custom_styles/uploads/_image.erb
@@ -0,0 +1,68 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) the OpenProject GmbH
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License version 3.
+
+OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+Copyright (C) 2006-2013 Jean-Philippe Lang
+Copyright (C) 2010-2013 the ChiliProject Team
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<%= 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"><%= image[:label] %></legend>
+ <p class="form--field-instructions"><%= image[:instructions] %></p>
+ <% if image[:present] %>
+ <%= tag("img", src: image[:source], class: image[:img_class]) %>
+ <% 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 image[:field], required: true, class: "attachment_choose_file", accept: image[:accept], size: "15" %>
+ </div>
+ </div>
+ </div>
+ </div>
+ <%=
+ render(Primer::Beta::Button.new(
+ type: :submit
+ )) do |button|
+ button.with_leading_visual_icon(icon: image[:present] ? :upload : :plus)
+ t(image[:present] ? :button_replace : :button_upload)
+ end
+ %>
+ <% if image[:present] %>
+ <%= render(Primer::Beta::Button.new(
+ tag: :a,
+ href: image[:delete_path],
+ data: { method: :delete }
+ )) do |button|
+ button.with_leading_visual_icon(icon: :trash)
+ t(:button_delete)
+ end
+ %>
+ <% end %>
+ </fieldset>
+ </section>
+<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 23b57ce5696..a9502ac965a 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2503,6 +2503,10 @@ en:
your_projects_export: "Projects are being exported"
succeeded: "Export completed"
failed: "An error has occurred while trying to export the work packages: %{message}"
+ demo:
+ heading: "Demo PDF"
+ footer: "Generated by OpenProject"
+ button_text: Generate Demo PDF
errors:
embedded_table_with_too_many_columns: "This embedded work package table could not fit on the page, please reduce the number of columns."
format:
@@ -4415,9 +4419,10 @@ en:
PDF exports will include a graphical element positioned to the left of the footer.
This image must be a PNG or JPEG file with approximately 200 pixels in width.
label_custom_export_font_instructions: >
- The following font files are used in your PDF exports.
- Upload and manage custom TrueType (.ttf) fonts for PDF exports. Ensure your license permits PDF embedding.
+ Upload and manage custom TrueType (.ttf) fonts used in your PDF exports.
For best results, use matching files from the same font family. If no font is provided, the default NotoSans font will be used.
+ label_custom_export_images_instructions: >
+ Upload and manage custom image files used in your PDF exports.
text_custom_export_font_regular_instructions: >
This is the font file for regular text. It needs to be in TTF format and is required.
text_custom_export_font_bold_instructions: >
diff --git a/config/routes.rb b/config/routes.rb
index cb2957b7d5b..08c6650f109 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -521,7 +521,9 @@ Rails.application.routes.draw do
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"
+ resource :custom_style, only: %i[update show create], path: "design" do
+ get :export_demo_pdf_download
+ end
resources :attribute_help_texts, only: %i(index new create edit update destroy)
diff --git a/frontend/src/global_styles/content/_custom_logo.sass b/frontend/src/global_styles/content/_custom_logo.sass
index 02830b6f187..566c90ee4fe 100644
--- a/frontend/src/global_styles/content/_custom_logo.sass
+++ b/frontend/src/global_styles/content/_custom_logo.sass
@@ -13,6 +13,9 @@ img.custom-logo-preview,
img.custom-export-logo-preview
height: 42px
+img.custom-export-footer-preview
+ max-width: 200px
+
img.custom-export-cover-preview
height: 100px