Skip to content

Commit

Permalink
More print settings
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kastl <[email protected]>
  • Loading branch information
dkastl committed Dec 2, 2023
1 parent ad89469 commit c2fc7e9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/controllers/print_templates_pdfme_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def form
}
end

# Retrieve plugin settings
@plugin_settings = Setting.plugin_redmine_print_templates

# Pass the CSRF token to the view
@csrf_token = form_authenticity_token
end
Expand Down
30 changes: 28 additions & 2 deletions app/views/print_templates/_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,44 @@
<%= content_tag(:label, l(:print_templates_settings_general_placeholder_empty)) %>
<%= text_field_tag('settings[default_placeholder_empty]',
@settings['default_placeholder_empty'],
:size => 40) %>
:size => 50) %>
<br><%= content_tag(:small, l(:print_templates_settings_general_placeholder_note)) %>
</p>

</div>

<div class="box tabular settings">
<h3><%= l(:pdf_properties_print_templates_settings) %></h3>

<p>
<%= content_tag(:label, l(:print_templates_settings_general_pdf_author)) %>
<%= text_field_tag('settings[default_pdf_author]',
@settings['default_pdf_author'],
:size => 50) %>
</p>

<p>
<%= content_tag(:label, l(:print_templates_settings_general_pdf_producer)) %>
<%= text_field_tag('settings[default_pdf_producer]',
@settings['default_pdf_producer'],
:size => 50) %>
</p>

<p>
<%= content_tag(:label, l(:print_templates_settings_general_pdf_creator)) %>
<%= text_field_tag('settings[default_pdf_creator]',
@settings['default_pdf_creator'],
:size => 50, :readonly => true) %>
</p>

</div>

<div class="box tabular settings">
<h3><%= l(:print_templates_font_settings) %></h3>

<p>
<label for="font_name"><%= l(:label_print_template_font_name) %></label>
<input type="text" id="font_name" size="40">
<input type="text" id="font_name" size="50">
</p>
<p>
<label for="font_file"><%= l(:label_print_template_font_file) %></label>
Expand Down
1 change: 1 addition & 0 deletions app/views/print_templates_pdfme/form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<script type="text/javascript">
var issueData = <%= raw @issue_data %>;
var embeddedFonts = <%= raw @fonts.to_json %>;
var pluginSettings = <%= raw @plugin_settings.to_json %>;
</script>
</body>
</html>
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ en:
print_templates_settings_general_placeholder_empty: "Empty field placeholder text"
print_templates_settings_general_placeholder_note: "Enter text to display in empty fields, or leave this blank to keep fields empty."

pdf_properties_print_templates_settings: "PDF Properties"
print_templates_settings_general_pdf_author: "Author"
print_templates_settings_general_pdf_creator: "Creator"
print_templates_settings_general_pdf_producer: "Producer"

# javascript:
confirm_delete_font: "Are you sure you want to delete this font?"
error_uploading_font: "Error during font upload."
Expand Down
5 changes: 5 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ ja:
print_templates_settings_general_placeholder_empty: "Empty field placeholder text"
print_templates_settings_general_placeholder_note: "Enter text to display in empty fields, or leave this blank to keep fields empty."

pdf_properties_print_templates_settings: "PDF Properties"
print_templates_settings_general_pdf_author: "Author"
print_templates_settings_general_pdf_creator: "Creator"
print_templates_settings_general_pdf_producer: "Producer"

# javascript:
confirm_delete_font: "Are you sure you want to delete this font?"
error_uploading_font: "Error during font upload."
Expand Down
3 changes: 3 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
settings(
default: {
'default_placeholder_empty' => '',
'default_pdf_author' => ENV['PDF_AUTHOR'] || 'Redmine System',
'default_pdf_creator' => ENV['PDF_CREATOR'] || 'Redmine Print Plugin, powered by PDFme',
'default_pdf_producer' => ENV['PDF_PRODUCER'] || 'Redmine Print Plugin',
},
partial: 'print_templates/settings'
)
Expand Down
14 changes: 12 additions & 2 deletions src/form.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Template, BLANK_PDF, getDefaultFont } from '@pdfme/common';
import { Template, GeneratorOptions, BLANK_PDF, getDefaultFont } from '@pdfme/common';
import { Form } from '@pdfme/ui';
import { text, image, barcodes } from "@pdfme/schemas";
import { generate } from '@pdfme/generator';
Expand All @@ -10,6 +10,7 @@ interface FontData {

declare const embeddedFonts: FontData[];
declare const issueData: any;
declare const pluginSettings: any;

const urlParams = new URLSearchParams(window.location.search);
const issueId = urlParams.get('issue_id');
Expand Down Expand Up @@ -97,7 +98,16 @@ document.addEventListener("DOMContentLoaded", function() {
template: form.getTemplate(),
inputs: currentInputs,
plugins: { text, image, qrcode: barcodes.qrcode },
options: { font: availableFonts },
options: {
font: availableFonts,
author: pluginSettings.default_pdf_author || "",
creator: pluginSettings.default_pdf_creator || "",
keywords: [],
language: "en-US",
producer: pluginSettings.default_pdf_producer || "",
subject: "Redmine Issue Report",
title: `Issue #${issueId}: Feature Implementation`,
},
}).then((pdf) => {
const blob = new Blob([pdf.buffer], { type: 'application/pdf' });
const timestamp = new Date().toISOString().replace(/[-:.TZ]/g, '');
Expand Down

0 comments on commit c2fc7e9

Please sign in to comment.