Mercurial > gemma
comparison client/src/components/Pdftool.vue @ 3840:387f239018c7
pdf_tool: retain default template, when custom template is uploaded
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 08 Jul 2019 14:11:19 +0200 |
parents | e8a950cf6c02 |
children | 7df9ef183985 |
comparison
equal
deleted
inserted
replaced
3839:03e8e6cc0b79 | 3840:387f239018c7 |
---|---|
106 import { getPointResolution } from "ol/proj"; | 106 import { getPointResolution } from "ol/proj"; |
107 import { HTTP } from "@/lib/http"; | 107 import { HTTP } from "@/lib/http"; |
108 import { displayError } from "@/lib/errors"; | 108 import { displayError } from "@/lib/errors"; |
109 import { pdfgen, templateLoader } from "@/lib/mixins"; | 109 import { pdfgen, templateLoader } from "@/lib/mixins"; |
110 | 110 |
111 var paperSizes = { | 111 const paperSizes = { |
112 // in millimeter, landscape [width, height] | 112 // in millimeter, landscape [width, height] |
113 a3: [420, 297], | 113 a3: [420, 297], |
114 a4: [297, 210] | 114 a4: [297, 210] |
115 }; | 115 }; |
116 | |
117 const DEFAULT_TEMPLATE = "Default"; | |
116 | 118 |
117 export default { | 119 export default { |
118 mixins: [pdfgen, templateLoader], | 120 mixins: [pdfgen, templateLoader], |
119 name: "pdftool", | 121 name: "pdftool", |
120 data() { | 122 data() { |
126 downloadType: "download", | 128 downloadType: "download", |
127 resolution: "80" | 129 resolution: "80" |
128 }, | 130 }, |
129 templates: [ | 131 templates: [ |
130 { | 132 { |
131 name: "Default", | 133 name: DEFAULT_TEMPLATE, |
132 properties: { | 134 properties: { |
133 format: "landscape", | 135 format: "landscape", |
134 paperSize: "a4", | 136 paperSize: "a4", |
135 resolution: "80" | 137 resolution: "80" |
136 }, | 138 }, |
148 fontSize: 8, | 150 fontSize: 8, |
149 text: this.$gettext("Generated by") + " " + "{user}, {date}" | 151 text: this.$gettext("Generated by") + " " + "{user}, {date}" |
150 }, | 152 }, |
151 { | 153 { |
152 type: "northarrow", | 154 type: "northarrow", |
153 position: "topright", | 155 position: "topleft", |
154 offset: { x: 6, y: 4 }, | 156 offset: { x: 6, y: 4 }, |
155 size: 2 | 157 size: 2 |
156 } | 158 } |
157 ] | 159 ] |
158 } | 160 } |
208 this.$store.commit("application/showPdfTool", false); | 210 this.$store.commit("application/showPdfTool", false); |
209 }, | 211 }, |
210 // When a template is chosen from the dropdown, its propoerties are | 212 // When a template is chosen from the dropdown, its propoerties are |
211 // applied to the rest of the form. | 213 // applied to the rest of the form. |
212 applyTemplateToForm() { | 214 applyTemplateToForm() { |
213 if (this.form.template) { | 215 if (this.form.template && this.form.template.name !== DEFAULT_TEMPLATE) { |
214 this.loadTemplates( | 216 this.loadTemplates( |
215 `/templates/${this.form.template.type}/${this.form.template.name}` | 217 `/templates/${this.form.template.type}/${this.form.template.name}` |
216 ) | 218 ) |
217 .then(response => { | 219 .then(response => { |
218 this.prepareImages(response.data.template_data.elements).then( | 220 this.prepareImages(response.data.template_data.elements).then( |
219 values => { | 221 values => { |
220 this.templateData = response.data.template_data; | |
221 values.forEach(v => { | 222 values.forEach(v => { |
222 response.data.template_data.elements[v.index].url = v.url; | 223 response.data.template_data.elements[v.index].url = v.url; |
223 }); | 224 }); |
224 this.form.format = this.templateData.properties.format; | 225 this.setTemplate(response.data.template_data); |
225 this.form.paperSize = this.templateData.properties.paperSize; | |
226 this.form.resolution = this.templateData.properties.resolution; | |
227 } | 226 } |
228 ); | 227 ); |
229 }) | 228 }) |
230 .catch(e => { | 229 .catch(e => { |
231 const { status, data } = e.response; | 230 const { status, data } = e.response; |
232 displayError({ | 231 displayError({ |
233 title: this.$gettext("Backend Error"), | 232 title: this.$gettext("Backend Error"), |
234 message: `${status}: ${data.message || data}` | 233 message: `${status}: ${data.message || data}` |
235 }); | 234 }); |
236 }); | 235 }); |
237 } | 236 } else { |
237 this.setTemplate(this.templates[0]); | |
238 } | |
239 }, | |
240 setTemplate(template) { | |
241 this.templateData = template; | |
242 this.form.format = this.templateData.properties.format; | |
243 this.form.paperSize = this.templateData.properties.paperSize; | |
244 this.form.resolution = this.templateData.properties.resolution; | |
238 }, | 245 }, |
239 download() { | 246 download() { |
240 // disable button while working on it | 247 // disable button while working on it |
241 this.readyToGenerate = false; | 248 this.readyToGenerate = false; |
242 | 249 |
801 "Content-type": "text/xml; charset=UTF-8" | 808 "Content-type": "text/xml; charset=UTF-8" |
802 } | 809 } |
803 }) | 810 }) |
804 .then(response => { | 811 .then(response => { |
805 if (response.data.length) { | 812 if (response.data.length) { |
806 this.templates = response.data; | 813 this.templates = [...this.templates, ...response.data]; |
807 this.form.template = this.templates[0]; | 814 this.form.template = this.templates[1]; |
808 this.applyTemplateToForm(); | 815 this.applyTemplateToForm(); |
809 } else { | 816 } else { |
810 this.form.template = this.templates[0]; | 817 this.form.template = this.templates[0]; |
811 this.templateData = this.form.template; | 818 this.templateData = this.form.template; |
812 } | 819 } |