Mercurial > gemma
diff client/src/components/Pdftool.vue @ 2247:e6fba449aa3c
merged pdf-export in default
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Wed, 13 Feb 2019 16:41:00 +0100 |
parents | c3cc21dee75d |
children | ce6fd3d4a3a2 |
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue Wed Feb 13 16:13:44 2019 +0100 +++ b/client/src/components/Pdftool.vue Wed Feb 13 16:41:00 2019 +0100 @@ -57,35 +57,18 @@ </select> </div> </div> - <!-- - <small class="d-block my-2"> - <input - type="radio" - id="pdfexport-downloadtype-download" - value="download" - v-model="form.downloadType" - selected - /> - <label for="pdfexport-downloadtype-download" class="ml-1 mr-2"> - <translate>Download</translate> - </label> - <input - type="radio" - id="pdfexport-downloadtype-open" - value="open" - v-model="form.downloadType" - /> - <label for="pdfexport-downloadtype-open" class="ml-1"> - <translate>Open in new window</translate> - </label> - </small> - --> <button @click="download" type="button" :disabled="!readyToGenerate" class="btn btn-sm btn-info d-block w-100 mt-2" > + <font-awesome-icon + v-if="!readyToGenerate" + class="mr-1" + icon="spinner" + spin + /> <translate>Generate PDF</translate> </button> </div> @@ -114,6 +97,8 @@ import "@/lib/font-linbiolinum.js"; import { getPointResolution } from "ol/proj.js"; import locale2 from "locale2"; +import { HTTP } from "../lib/http"; +import { displayError } from "@/lib/errors.js"; var paperSizes = { // in millimeter, landscape [width, height] @@ -132,6 +117,7 @@ downloadType: "download", resolution: "80" }, + templateData: null, pdf: { doc: null, width: null, @@ -153,14 +139,28 @@ // applied to the rest of the form. applyTemplateToForm() { if (this.form.template) { - this.form.format = this.form.template.properties.format; - this.form.paperSize = this.form.template.properties.paperSize; - this.form.resolution = this.form.template.properties.resolution; + HTTP.get("/templates/print/" + this.form.template.name, { + headers: { + "X-Gemma-Auth": localStorage.getItem("token"), + "Content-type": "text/xml; charset=UTF-8" + } + }) + .then(response => { + this.templateData = response.data.template_data; + this.form.format = this.templateData.properties.format; + this.form.paperSize = this.templateData.properties.paperSize; + this.form.resolution = this.templateData.properties.resolution; + }) + .catch(e => { + const { status, data } = e.response; + displayError({ + title: "Backend Error", + message: `${status}: ${data.message || data}` + }); + }); } }, download() { - let template = this.form.template; - // disable button while working on it this.readyToGenerate = false; @@ -237,15 +237,15 @@ this.pdf.height ); - if (template) { + if (this.templateData) { this.pdf.doc.setFont("linbiolinum", "normal"); let defaultFontSize = 11, - defaultRounding = 0, + defaultRounding = 2, defaultTextColor = "black", defaultBgColor = "white", defaultPadding = 3, defaultOffset = { x: 0, y: 0 }; - template.elements.forEach(e => { + this.templateData.elements.forEach(e => { switch (e.type) { case "text": { this.addText( @@ -673,7 +673,7 @@ this.getLayerByName("Bottleneck isolines").isVisible ) { let width = 54; - let height = 13; + let height = 17; let padding = 3; // x/y defaults to offset for topleft corner (normal x/y coordinates) @@ -704,11 +704,13 @@ this.pdf.doc.setFontStyle("bold"); this.pdf.doc.text(x + padding + w, y + padding, str); + let survey = this.selectedSurvey; + str = this.$gettext("Survey date") + ": "; w = this.pdf.doc.getTextWidth(str); this.pdf.doc.setFontStyle("italic"); this.pdf.doc.text(x + padding, y + padding + 3, str); - str = this.selectedSurvey.date_info; + str = survey.date_info; this.pdf.doc.setFontStyle("normal"); this.pdf.doc.text(x + padding + w, y + padding + 3, str); @@ -716,9 +718,22 @@ w = this.pdf.doc.getTextWidth(str); this.pdf.doc.setFontStyle("italic"); this.pdf.doc.text(x + padding, y + padding + 6, str); - str = this.selectedSurvey.gauge_objname; + str = survey.gauge_objname; this.pdf.doc.setFontStyle("normal"); this.pdf.doc.text(x + padding + w, y + padding + 6, str); + + str = this.$gettext("Depth relativ to") + ": "; + w = this.pdf.doc.getTextWidth(str); + this.pdf.doc.setFontStyle("italic"); + this.pdf.doc.text(x + padding, y + padding + 9, str); + this.pdf.doc.setFontStyle("normal"); + str = survey.depth_reference + " = "; + if (survey.hasOwnProperty("waterlevel_value")) { + str += survey.waterlevel_value + " cm"; + } else { + str += "?"; + } + this.pdf.doc.text(x + padding + w, y + padding + 9, str); } }, replacePlaceholders(text) { @@ -741,6 +756,7 @@ mounted() { this.$store.dispatch("application/loadPdfTemplates").then(() => { this.form.template = this.pdfTemplates[0]; + this.applyTemplateToForm(); }); } };