comparison client/src/components/gauge/Waterlevel.vue @ 3249:d91c1200dc6b

client: diagram-template: cleanup code * remove unnecessary form.papersize data
author Fadi Abbud <fadi.abbud@intevation.de>
date Mon, 13 May 2019 16:16:55 +0200
parents 3159ee3bcb16
children fccb28813159
comparison
equal deleted inserted replaced
3248:3159ee3bcb16 3249:d91c1200dc6b
105 dimensions: null, 105 dimensions: null,
106 extent: null, 106 extent: null,
107 scale: null, 107 scale: null,
108 axes: null, 108 axes: null,
109 form: { 109 form: {
110 template: null, 110 template: null
111 form: null
112 }, 111 },
113 templates: [], 112 templates: [],
114 defaultTemplate: { 113 defaultTemplate: {
115 name: "Default", 114 name: "Default",
116 properties: { 115 properties: {
194 ? "GAUGE_HYDROLOGICALCONDITIONS" 193 ? "GAUGE_HYDROLOGICALCONDITIONS"
195 : "DEFAULT" 194 : "DEFAULT"
196 ); 195 );
197 }, 196 },
198 downloadPDF() { 197 downloadPDF() {
199 this.pdf.doc = new jsPDF("l", "mm", this.form.paperSize); 198 this.pdf.doc = new jsPDF(
200 this.pdf.width = this.form.paperSize === "a3" ? 420 : 297; 199 "l",
201 this.pdf.height = this.form.paperSize === "a3" ? 297 : 210; 200 "mm",
201 this.templateData.properties.paperSize
202 );
203 this.pdf.width =
204 this.templateData.properties.paperSize === "a3" ? 420 : 297;
205 this.pdf.height =
206 this.templateData.properties.paperSize === "a3" ? 297 : 210;
202 // check the template elements 207 // check the template elements
203 if (this.templateData) { 208 if (this.templateData) {
204 let defaultFontSize = 11, 209 let defaultFontSize = 11,
205 defaultColor = "black", 210 defaultColor = "black",
206 defaultWidth = 70, 211 defaultWidth = 70,
291 ); 296 );
292 }, 297 },
293 applyChange() { 298 applyChange() {
294 if (this.form.template.hasOwnProperty("properties")) { 299 if (this.form.template.hasOwnProperty("properties")) {
295 this.templateData = this.defaultTemplate; 300 this.templateData = this.defaultTemplate;
296 this.form.paperSize = this.defaultTemplate.properties.paperSize;
297 return; 301 return;
298 } 302 }
299 if (this.form.template) { 303 if (this.form.template) {
300 HTTP.get("/templates/diagram/" + this.form.template.name, { 304 HTTP.get("/templates/diagram/" + this.form.template.name, {
301 headers: { 305 headers: {
303 "Content-type": "text/xml; charset=UTF-8" 307 "Content-type": "text/xml; charset=UTF-8"
304 } 308 }
305 }) 309 })
306 .then(response => { 310 .then(response => {
307 this.templateData = response.data.template_data; 311 this.templateData = response.data.template_data;
308 this.form.paperSize = this.templateData.properties.paperSize;
309 }) 312 })
310 .catch(e => { 313 .catch(e => {
311 const { status, data } = e.response; 314 const { status, data } = e.response;
312 displayError({ 315 displayError({
313 title: this.$gettext("Backend Error"), 316 title: this.$gettext("Backend Error"),
349 ignoreDimensions: true 352 ignoreDimensions: true
350 }); 353 });
351 var imgData = canvas.toDataURL("image/png"); 354 var imgData = canvas.toDataURL("image/png");
352 // landscape format is used for both a3,a4 papersize 355 // landscape format is used for both a3,a4 papersize
353 if (!width) { 356 if (!width) {
354 width = this.form.paperSize === "a3" ? 380 : 290; 357 width = this.templateData.properties.paperSize === "a3" ? 380 : 290;
355 } 358 }
356 if (!height) { 359 if (!height) {
357 height = this.form.paperSize === "a3" ? 130 : 100; 360 height = this.templateData.properties.paperSize === "a3" ? 130 : 100;
358 } 361 }
359 if (["topright", "bottomright"].indexOf(position) !== -1) { 362 if (["topright", "bottomright"].indexOf(position) !== -1) {
360 x = this.pdf.width - offset.x - width; 363 x = this.pdf.width - offset.x - width;
361 } 364 }
362 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { 365 if (["bottomright", "bottomleft"].indexOf(position) !== -1) {