Mercurial > gemma
annotate client/src/lib/mixins.js @ 3963:feb53713bc2f diagram-cleanup
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Fri, 12 Jul 2019 15:14:16 +0200 |
parents | 3c468ed76daf |
children | afc7bca44df4 |
rev | line source |
---|---|
2738
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
2 * without warranty, see README.md and license for details. |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
3 * |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
4 * SPDX-License-Identifier: AGPL-3.0-or-later |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
5 * License-Filename: LICENSES/AGPL-3.0.txt |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
6 * |
3792
3878bc0c8e58
client: update attribution infos on lib/mixins.js
Bernhard Reiter <bernhard@intevation.de>
parents:
3790
diff
changeset
|
7 * Copyright (C) 2018, 2019 by via donau |
2738
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
8 * – Österreichische Wasserstraßen-Gesellschaft mbH |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
9 * Software engineering by Intevation GmbH |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
10 * |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
11 * Author(s): |
3792
3878bc0c8e58
client: update attribution infos on lib/mixins.js
Bernhard Reiter <bernhard@intevation.de>
parents:
3790
diff
changeset
|
12 * * Markus Kottländer <markus.kottlaender@intevation.de> |
3878bc0c8e58
client: update attribution infos on lib/mixins.js
Bernhard Reiter <bernhard@intevation.de>
parents:
3790
diff
changeset
|
13 * * Fadi Abbud <fadi.abbud@intevation.de> |
3878bc0c8e58
client: update attribution infos on lib/mixins.js
Bernhard Reiter <bernhard@intevation.de>
parents:
3790
diff
changeset
|
14 * * Bernhard Reiter <bernhard.reiter@intevation.de> |
2738
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
15 */ |
3796
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
16 import jsPDF from "jspdf-yworks"; |
3941
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
17 import svg2pdf from "svg2pdf.js"; |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
18 import locale2 from "locale2"; |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
19 import debounce from "debounce"; |
3406
1ba669cbbee6
client: pdf-template:(minor) add missed parameter for image element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3396
diff
changeset
|
20 import { mapState } from "vuex"; |
3802
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
21 import { HTTP } from "@/lib/http"; |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
22 import { displayError } from "@/lib/errors"; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
23 import { defaultDiagramTemplate } from "@/lib/DefaultDiagramTemplate"; |
3796
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
24 |
3180
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
25 export const sortTable = { |
2738
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
26 data() { |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
27 return { |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
28 sortColumn: "", |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
29 sortDirection: "ASC", |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
30 pageSize: 20, |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
31 page: 1 |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
32 }; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
33 }, |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
34 methods: { |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
35 sortTable(sorting) { |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
36 this.sortColumn = sorting.sortColumn; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
37 this.sortDirection = sorting.sortDirection; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
38 } |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
39 } |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
40 }; |
add2d47c2567
client: tables: implemented simple default sorting
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
41 |
3180
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
42 export const diagram = { |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
43 data() { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
44 return { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
45 resizeListenerFunction: null |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
46 }; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
47 }, |
3180
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
48 methods: { |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
49 getDimensions({ svgWidth, svgHeight, main, nav, DPI }) { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
50 const mainMargin = { |
3936
d859ec6cf2f0
Fairwayprofile enhanced
Thomas Junk <thomas.junk@intevation.de>
parents:
3919
diff
changeset
|
51 top: 20, |
d859ec6cf2f0
Fairwayprofile enhanced
Thomas Junk <thomas.junk@intevation.de>
parents:
3919
diff
changeset
|
52 right: 80, |
d859ec6cf2f0
Fairwayprofile enhanced
Thomas Junk <thomas.junk@intevation.de>
parents:
3919
diff
changeset
|
53 bottom: 60, |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
54 left: 80, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
55 ...main |
3936
d859ec6cf2f0
Fairwayprofile enhanced
Thomas Junk <thomas.junk@intevation.de>
parents:
3919
diff
changeset
|
56 }; |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
57 const navMargin = { |
3180
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
58 top: svgHeight - mainMargin.top - 65, |
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
59 right: 20, |
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
60 bottom: 30, |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
61 left: 80, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
62 ...nav |
3180
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
63 }; |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
64 if (DPI) { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
65 ["top", "right", "bottom", "left"].forEach(x => { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
66 mainMargin[x] = this.millimeter2pixels(mainMargin[x], DPI); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
67 navMargin[x] = this.millimeter2pixels(navMargin[x], DPI); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
68 }); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
69 } |
3478
afab8d87932c
mixin: assume when element not in DOM width and height are 0
Thomas Junk <thomas.junk@intevation.de>
parents:
3429
diff
changeset
|
70 const width = Number(svgWidth) - mainMargin.left - mainMargin.right; |
afab8d87932c
mixin: assume when element not in DOM width and height are 0
Thomas Junk <thomas.junk@intevation.de>
parents:
3429
diff
changeset
|
71 const mainHeight = Number(svgHeight) - mainMargin.top - mainMargin.bottom; |
afab8d87932c
mixin: assume when element not in DOM width and height are 0
Thomas Junk <thomas.junk@intevation.de>
parents:
3429
diff
changeset
|
72 const navHeight = Number(svgHeight) - navMargin.top - navMargin.bottom; |
3180
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
73 return { width, mainHeight, navHeight, mainMargin, navMargin }; |
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
74 } |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
75 }, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
76 created() { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
77 this.resizeListenerFunction = debounce(this.drawDiagram, 100); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
78 window.addEventListener("resize", this.resizeListenerFunction); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
79 }, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
80 mounted() { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
81 // Nasty but necessary if we don't want to use the updated hook to re-draw |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
82 // the diagram because this would re-draw it also for irrelevant reasons. |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
83 // In this case we need to wait for the child component (DiagramLegend) to |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
84 // render. According to the docs (https://vuejs.org/v2/api/#mounted) this |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
85 // should be possible with $nextTick() but it doesn't work because it does |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
86 // not guarantee that the DOM is not only updated but also re-painted on the |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
87 // screen. |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
88 setTimeout(this.drawDiagram, 150); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
89 }, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
90 destroyed() { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
91 window.removeEventListener("resize", this.resizeListenerFunction); |
3180
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
92 } |
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
93 }; |
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
94 |
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
95 export const pane = { |
3077
db890b71f070
client: panes: added paneId to mixin
Markus Kottlaender <markus@intevation.de>
parents:
3072
diff
changeset
|
96 computed: { |
db890b71f070
client: panes: added paneId to mixin
Markus Kottlaender <markus@intevation.de>
parents:
3072
diff
changeset
|
97 paneId() { |
db890b71f070
client: panes: added paneId to mixin
Markus Kottlaender <markus@intevation.de>
parents:
3072
diff
changeset
|
98 return this.$parent.pane.id; |
db890b71f070
client: panes: added paneId to mixin
Markus Kottlaender <markus@intevation.de>
parents:
3072
diff
changeset
|
99 } |
3072
0233845cadb7
client: improved splitscreen mechanis
Markus Kottlaender <markus@intevation.de>
parents:
2989
diff
changeset
|
100 } |
0233845cadb7
client: improved splitscreen mechanis
Markus Kottlaender <markus@intevation.de>
parents:
2989
diff
changeset
|
101 }; |
0233845cadb7
client: improved splitscreen mechanis
Markus Kottlaender <markus@intevation.de>
parents:
2989
diff
changeset
|
102 |
3802
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
103 export const templateLoader = { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
104 methods: { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
105 loadTemplates(url) { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
106 return new Promise((resolve, reject) => { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
107 HTTP.get(url, { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
108 headers: { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
109 "X-Gemma-Auth": localStorage.getItem("token"), |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
110 "Content-type": "text/xml; charset=UTF-8" |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
111 } |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
112 }) |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
113 .then(response => { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
114 resolve(response); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
115 }) |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
116 .catch(error => { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
117 reject(error); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
118 }); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
119 }); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
120 }, |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
121 prepareImages(elements) { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
122 /** |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
123 * In order to render the images from the template, we need to convert |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
124 * each image to dataURIs. Since this happens asynchronous, |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
125 * we need to wrap each image into its own promise and only after all are |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
126 * finished, we continue with the flow. |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
127 */ |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
128 return new Promise(resolve => { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
129 const imageElementLoaders = elements.reduce((o, n, i) => { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
130 if (n.type === "image") { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
131 o.push( |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
132 new Promise(resolve => { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
133 const image = new Image(); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
134 image.onload = function() { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
135 var canvas = document.createElement("canvas"); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
136 canvas.width = this.naturalWidth; // or 'width' if you want a special/scaled size |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
137 canvas.height = this.naturalHeight; // or 'height' if you want a special/scaled size |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
138 canvas.getContext("2d").drawImage(this, 0, 0); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
139 resolve({ |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
140 index: i, |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
141 url: canvas.toDataURL("image/png") |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
142 }); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
143 }; |
3881
7db6999962db
mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents:
3862
diff
changeset
|
144 let URL = n.URL; |
7db6999962db
mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents:
3862
diff
changeset
|
145 if (!URL) { |
7db6999962db
mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents:
3862
diff
changeset
|
146 URL = this.logoForPDF |
7db6999962db
mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents:
3862
diff
changeset
|
147 ? this.logoForPDF |
7db6999962db
mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents:
3862
diff
changeset
|
148 : "/img/gemma-logo-for-pdf.png"; |
7db6999962db
mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents:
3862
diff
changeset
|
149 } |
7db6999962db
mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents:
3862
diff
changeset
|
150 image.src = URL; |
3802
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
151 }) |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
152 ); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
153 } |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
154 return o; |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
155 }, []); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
156 Promise.all(imageElementLoaders).then(values => { |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
157 resolve(values); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
158 }); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
159 }); |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
160 } |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
161 } |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
162 }; |
e8a950cf6c02
Move Template loading and Imageprocessing to mixin
Thomas Junk <thomas.junk@intevation.de>
parents:
3801
diff
changeset
|
163 |
3180
429e28295902
available_fairway_depth: implement reactivity
Thomas Junk <thomas.junk@intevation.de>
parents:
3154
diff
changeset
|
164 export const pdfgen = { |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
165 data() { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
166 return { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
167 pdf: { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
168 doc: null, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
169 width: null, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
170 height: null |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
171 }, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
172 templates: [], |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
173 defaultTemplate: defaultDiagramTemplate, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
174 templateData: null, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
175 form: { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
176 template: null |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
177 } |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
178 }; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
179 }, |
3406
1ba669cbbee6
client: pdf-template:(minor) add missed parameter for image element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3396
diff
changeset
|
180 computed: { |
3408
a26c1d745fc3
client: pdf-template: fix display of user and move property to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3406
diff
changeset
|
181 ...mapState("application", ["logoForPDF"]), |
a26c1d745fc3
client: pdf-template: fix display of user and move property to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3406
diff
changeset
|
182 ...mapState("user", ["user"]) |
3406
1ba669cbbee6
client: pdf-template:(minor) add missed parameter for image element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3396
diff
changeset
|
183 }, |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
184 methods: { |
3941
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
185 addDiagram(position, offset, width, height) { |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
186 let x = offset.x, |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
187 y = offset.y; |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
188 const DPI = this.templateData.properties.resoltion || 80; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
189 const svgWidth = this.millimeter2pixels(width, DPI); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
190 const svgHeight = this.millimeter2pixels(height, DPI); |
3941
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
191 // draw the diagram in a separated html element to get the full size |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
192 const offScreen = document.querySelector("#offScreen"); |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
193 offScreen.style.width = `${svgWidth}px`; |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
194 offScreen.style.height = `${svgHeight}px`; |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
195 const layout = this.getPrintLayout(svgHeight); |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
196 this.renderTo({ |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
197 element: offScreen, |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
198 dimensions: this.getDimensions({ |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
199 svgWidth: svgWidth, |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
200 svgHeight: svgHeight, |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
201 ...layout, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
202 DPI: DPI |
3941
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
203 }) |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
204 }); |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
205 var svg = offScreen.querySelector("svg"); |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
206 if (["topright", "bottomright"].indexOf(position) !== -1) { |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
207 x = this.pdf.width - offset.x - width; |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
208 } |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
209 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
210 y = this.pdf.height - offset.y - height; |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
211 } |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
212 svg2pdf(svg, this.pdf.doc, { |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
213 xOffset: x, |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
214 yOffset: y, |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
215 scale: this.pixel2millimeter(1, DPI) |
3941
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
216 }); |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
217 offScreen.removeChild(svg); |
7b3935a8d9ee
refactor addDiagram to mixin and remove code duplication
Thomas Junk <thomas.junk@intevation.de>
parents:
3936
diff
changeset
|
218 }, |
3906
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
219 getPaperDimensions(format) { |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
220 const dims = { |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
221 A3: { |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
222 height: 297, |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
223 width: 420 |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
224 }, |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
225 A4: { |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
226 height: 210, |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
227 width: 297 |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
228 } |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
229 }; |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
230 return dims[format.toUpperCase()]; |
ec1d91fdd6a2
fairway_profile: print template edited and print mechanism improved
Thomas Junk <thomas.junk@intevation.de>
parents:
3886
diff
changeset
|
231 }, |
3886
9fa9a485c182
mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents:
3881
diff
changeset
|
232 millimeter2pixels(length, dpi) { |
9fa9a485c182
mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents:
3881
diff
changeset
|
233 return (dpi * length) / 25.4; |
9fa9a485c182
mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents:
3881
diff
changeset
|
234 }, |
9fa9a485c182
mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents:
3881
diff
changeset
|
235 pixel2millimeter(pixels, dpi) { |
9fa9a485c182
mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents:
3881
diff
changeset
|
236 return (pixels * 25.4) / dpi; |
9fa9a485c182
mixins: calculator for pixels2millimeter vice versa
Thomas Junk <thomas.junk@intevation.de>
parents:
3881
diff
changeset
|
237 }, |
3798
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
238 gaugeInfo(selectedGauge) { |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
239 // returns string with formatted gauge info |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
240 return ( |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
241 selectedGauge.properties.objname + |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
242 " (" + |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
243 selectedGauge.id |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
244 .split(".")[1] |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
245 .replace(/[()]/g, "") |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
246 .split(",")[3] + |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
247 ")" |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
248 ); |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
249 }, |
3796
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
250 generatePDF(params) { |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
251 // creates a new jsPDF object into this.pdf.doc |
3799
f4deb4aae485
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3798
diff
changeset
|
252 // will call functions that the calling context has to provide |
f4deb4aae485
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3798
diff
changeset
|
253 // as specified in the templateData |
3796
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
254 let templateData = params["templateData"]; |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
255 let diagramTitle = params["diagramTitle"]; |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
256 |
3799
f4deb4aae485
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3798
diff
changeset
|
257 this.pdf.doc = new jsPDF("l", "mm", templateData.properties.paperSize); |
3796
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
258 // pdf width and height in millimeter (landscape) |
3798
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
259 if (templateData.properties.paperSize === "a3") { |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
260 this.pdf.width = 420; |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
261 this.pdf.height = 297; |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
262 } else { |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
263 this.pdf.width = 297; |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
264 this.pdf.height = 210; |
e008197e2215
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3796
diff
changeset
|
265 } |
3796
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
266 // check the template elements |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
267 if (templateData) { |
3801
1399d31531f7
client: improve pdf generation to use linbiolinum font
Bernhard Reiter <bernhard@intevation.de>
parents:
3799
diff
changeset
|
268 this.pdf.doc.setFont("linbiolinum", "normal"); |
3796
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
269 let defaultFontSize = 11, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
270 defaultColor = "black", |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
271 defaultWidth = 70, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
272 defaultTextColor = "black", |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
273 defaultBorderColor = "white", |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
274 defaultBgColor = "white", |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
275 defaultRounding = 2, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
276 defaultPadding = 2, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
277 defaultOffset = { x: 0, y: 0 }; |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
278 templateData.elements.forEach(e => { |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
279 switch (e.type) { |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
280 case "diagram": { |
3807
876dc90c2825
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3802
diff
changeset
|
281 this.addDiagram( |
876dc90c2825
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3802
diff
changeset
|
282 e.position, |
876dc90c2825
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3802
diff
changeset
|
283 e.offset || defaultOffset, |
3943
3c468ed76daf
client:pdf-gen: correct default values of diagram size on pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3941
diff
changeset
|
284 // use default width,height if they are missing in template definition |
3c468ed76daf
client:pdf-gen: correct default values of diagram size on pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3941
diff
changeset
|
285 e.width || |
3c468ed76daf
client:pdf-gen: correct default values of diagram size on pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3941
diff
changeset
|
286 (this.templateData.properties.paperSize === "a3" ? 318 : 230), |
3c468ed76daf
client:pdf-gen: correct default values of diagram size on pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3941
diff
changeset
|
287 e.height || |
3c468ed76daf
client:pdf-gen: correct default values of diagram size on pdf
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3941
diff
changeset
|
288 (this.templateData.properties.paperSize === "a3" ? 104 : 110) |
3807
876dc90c2825
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3802
diff
changeset
|
289 ); |
3796
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
290 break; |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
291 } |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
292 case "diagramlegend": { |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
293 this.addDiagramLegend( |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
294 e.position, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
295 e.offset || defaultOffset, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
296 e.color || defaultColor |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
297 ); |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
298 break; |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
299 } |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
300 case "diagramtitle": { |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
301 this.addDiagramTitle( |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
302 e.position, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
303 e.offset || defaultOffset, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
304 e.fontsize || defaultFontSize, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
305 e.color || defaultColor, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
306 diagramTitle |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
307 ); |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
308 break; |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
309 } |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
310 case "text": { |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
311 this.addText( |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
312 e.position, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
313 e.offset || defaultOffset, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
314 e.width || defaultWidth, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
315 e.fontsize || defaultFontSize, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
316 e.color || defaultTextColor, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
317 e.text || "" |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
318 ); |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
319 break; |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
320 } |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
321 case "image": { |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
322 this.addImage( |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
323 e.url, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
324 e.format || "", |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
325 e.position, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
326 e.offset || defaultOffset, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
327 e.width || 90, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
328 e.height || 60 |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
329 ); |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
330 break; |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
331 } |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
332 case "box": { |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
333 this.addBox( |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
334 e.position, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
335 e.offset || defaultOffset, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
336 e.width || 90, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
337 e.height || 60, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
338 e.rounding === 0 || e.rounding ? e.rounding : defaultRounding, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
339 e.color || defaultBgColor, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
340 e.brcolor || defaultBorderColor |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
341 ); |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
342 break; |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
343 } |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
344 case "textbox": { |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
345 this.addTextBox( |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
346 e.position, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
347 e.offset || defaultOffset, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
348 e.width, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
349 e.height, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
350 e.rounding === 0 || e.rounding ? e.rounding : defaultRounding, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
351 e.padding || defaultPadding, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
352 e.fontsize || defaultFontSize, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
353 e.color || defaultTextColor, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
354 e.background || defaultBgColor, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
355 e.text || "", |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
356 e.brcolor || defaultBorderColor |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
357 ); |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
358 break; |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
359 } |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
360 } |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
361 }); |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
362 } |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
363 }, |
243316850889
client: improve pdf generation
Bernhard Reiter <bernhard@intevation.de>
parents:
3792
diff
changeset
|
364 // add text at specific coordinates and do line breaks |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
365 addText(position, offset, width, fontSize, color, text) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
366 text = this.replacePlaceholders(text); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
367 // split the incoming string to an array, each element is a string of |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
368 // words in a single line |
3396
169680c3698b
client: pdf-template: set font style for the text element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3350
diff
changeset
|
369 this.pdf.doc.setFontStyle("normal"); |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
370 this.pdf.doc.setTextColor(color); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
371 this.pdf.doc.setFontSize(fontSize); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
372 var textLines = this.pdf.doc.splitTextToSize(text, width); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
373 // x/y defaults to offset for topleft corner (normal x/y coordinates) |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
374 let x = offset.x; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
375 let y = offset.y; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
376 // if position is on the right, x needs to be calculate with pdf width and |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
377 // the size of the element |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
378 if (["topright", "bottomright"].indexOf(position) !== -1) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
379 x = this.pdf.width - offset.x - width; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
380 } |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
381 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
3919
2c9e96b02573
clinet: pdf-gen: improve addTextBox() function for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3906
diff
changeset
|
382 y = |
2c9e96b02573
clinet: pdf-gen: improve addTextBox() function for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3906
diff
changeset
|
383 this.pdf.height - |
2c9e96b02573
clinet: pdf-gen: improve addTextBox() function for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3906
diff
changeset
|
384 offset.y * 0.3 - |
2c9e96b02573
clinet: pdf-gen: improve addTextBox() function for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3906
diff
changeset
|
385 this.getTextHeight(textLines.length); |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
386 } |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
387 this.pdf.doc.text(textLines, x, y, { baseline: "hanging" }); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
388 }, |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
389 replacePlaceholders(text) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
390 if (text.includes("{date}")) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
391 text = text.replace("{date}", new Date().toLocaleString(locale2)); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
392 } |
3350
8da2f7b9a04b
client: diagram-template:remove unnecessary template properties and typo
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3344
diff
changeset
|
393 // get only day,month and year from the Date object |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
394 if (text.includes("{date-minor}")) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
395 var date = new Date(); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
396 var dt = |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
397 (date.getDate() < 10 ? "0" : "") + |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
398 date.getDate() + |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
399 "." + |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
400 (date.getMonth() + 1 < 10 ? "0" : "") + |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
401 (date.getMonth() + 1) + |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
402 "." + |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
403 date.getFullYear(); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
404 text = text.replace("{date-minor}", dt.toLocaleString(locale2)); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
405 } |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
406 if (text.includes("{user}")) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
407 text = text.replace("{user}", this.user); |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
408 } |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
409 return text; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
410 }, |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
411 addImage(url, format, position, offset, width, height) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
412 let x = offset.x; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
413 let y = offset.y; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
414 if (["topright", "bottomright"].indexOf(position) !== -1) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
415 x = this.pdf.width - offset.x - width; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
416 } |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
417 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
418 y = this.pdf.height - offset.y - height; |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
419 } |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
420 let image = new Image(); |
3881
7db6999962db
mixins: if image given with no explict URL load either configured logo or placeholder
Thomas Junk <thomas.junk@intevation.de>
parents:
3862
diff
changeset
|
421 image.src = url; |
3544
067ad32fba69
client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3500
diff
changeset
|
422 if (format === "") { |
067ad32fba69
client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3500
diff
changeset
|
423 let tmp = image.src.split("."); |
067ad32fba69
client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3500
diff
changeset
|
424 format = tmp[tmp.length - 1].toUpperCase(); |
067ad32fba69
client: diagram-template: improve values of template elements
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3500
diff
changeset
|
425 } |
3429
7bbab09cdf71
client: pdf-template:(minor) add missing parameter
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3408
diff
changeset
|
426 this.pdf.doc.addImage(image, format, x, y, width, height); |
3141
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
427 }, |
3293
76f643d20f19
clinet: pdf-gen: (cleanup) remove some pdf-functions from pdftool
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3285
diff
changeset
|
428 // add text at specific coordinates with a background box |
3141
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
429 addBox(position, offset, width, height, rounding, color, brcolor) { |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
430 // x/y defaults to offset for topleft corner (normal x/y coordinates) |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
431 let x = offset.x; |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
432 let y = offset.y; |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
433 |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
434 // if position is on the right, x needs to be calculate with pdf width and |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
435 // the size of the element |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
436 if (["topright", "bottomright"].indexOf(position) !== -1) { |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
437 x = this.pdf.width - offset.x - width; |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
438 } |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
439 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
440 y = this.pdf.height - offset.y - height; |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
441 } |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
442 this.addRoundedBox(x, y, width, height, color, rounding, brcolor); |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
443 }, |
3273
050e72ce5cf7
client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3235
diff
changeset
|
444 getTextHeight(numberOfLines) { |
3790
60977e18e227
client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents:
3788
diff
changeset
|
445 // Return estimated height in mm. |
60977e18e227
client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents:
3788
diff
changeset
|
446 |
60977e18e227
client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents:
3788
diff
changeset
|
447 // FontSize is given in desktop publishing points defined as 1/72 inch. |
60977e18e227
client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents:
3788
diff
changeset
|
448 // aka 25.4 / 72 mm |
60977e18e227
client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents:
3788
diff
changeset
|
449 let fontSize = this.pdf.doc.getFontSize(); |
60977e18e227
client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents:
3788
diff
changeset
|
450 let lineHeightFactor = 1.15; // default from jspdf-yworks 2.0.2 |
60977e18e227
client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents:
3788
diff
changeset
|
451 if (typeof this.pdf.doc.getLineHeightFactor !== "undefined") { |
60977e18e227
client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents:
3788
diff
changeset
|
452 lineHeightFactor = this.pdf.doc.getLineHeightFactor(); |
60977e18e227
client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents:
3788
diff
changeset
|
453 } |
60977e18e227
client: improve pdf generation getTextHeight()
Bernhard Reiter <bernhard@intevation.de>
parents:
3788
diff
changeset
|
454 return numberOfLines * fontSize * (25.4 / 72) * lineHeightFactor; |
3273
050e72ce5cf7
client: diagram-template: add template elements and get templates from backend(fairway avalibilty)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3235
diff
changeset
|
455 }, |
3285
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
456 // title for diagram |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
457 addDiagramTitle(position, offset, size, color, text) { |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
458 let x = offset.x, |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
459 y = offset.y; |
3336
db1dc197dc43
client: diagram-template: cleanup
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3293
diff
changeset
|
460 this.pdf.doc.setFontSize(size); |
3344
107de6def0c3
client: diagram-template: cleanup
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3336
diff
changeset
|
461 this.pdf.doc.setFontStyle("bold"); |
107de6def0c3
client: diagram-template: cleanup
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3336
diff
changeset
|
462 this.pdf.doc.setTextColor(color); |
3285
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
463 let width = |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
464 (this.pdf.doc.getStringUnitWidth(text) * size) / (72 / 25.6) + size / 2; |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
465 // if position is on the right, x needs to be calculate with pdf width and |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
466 // the size of the element |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
467 if (["topright", "bottomright"].indexOf(position) !== -1) { |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
468 x = this.pdf.width - offset.x - width; |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
469 } |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
470 if (["bottomright", "bottomleft"].indexOf(position) !== -1) { |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
471 y = this.pdf.height - offset.y - this.getTextHeight(1); |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
472 } |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
473 this.pdf.doc.text(text, x, y, { baseline: "hanging" }); |
aac1ca73e92a
client: diagram-template:(cleanup) move reusable pdf-functions to mixins.js
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3273
diff
changeset
|
474 }, |
3141
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
475 addRoundedBox(x, y, w, h, color, rounding, brcolor) { |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
476 this.pdf.doc.setDrawColor(brcolor); |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
477 this.pdf.doc.setFillColor(color); |
42324626f9e2
client: add box element for pdf-template (waterlevel)
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3137
diff
changeset
|
478 this.pdf.doc.roundedRect(x, y, w, h, rounding, rounding, "FD"); |
3154
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
479 }, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
480 addTextBox( |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
481 position, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
482 offset, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
483 width, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
484 height, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
485 rounding, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
486 padding, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
487 fontSize, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
488 color, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
489 background, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
490 text, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
491 brcolor |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
492 ) { |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
493 this.pdf.doc.setFontSize(fontSize); |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
494 text = this.replacePlaceholders(text); |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
495 |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
496 if (!width) { |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
497 width = this.pdf.doc.getTextWidth(text) + 2 * padding; |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
498 } |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
499 let textWidth = width - 2 * padding; |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
500 if (!height) { |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
501 let textLines = this.pdf.doc.splitTextToSize(text, textWidth); |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
502 height = this.getTextHeight(textLines.length) + 2 * padding; |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
503 } |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
504 this.addBox( |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
505 position, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
506 offset, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
507 width, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
508 height, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
509 rounding, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
510 background, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
511 brcolor |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
512 ); |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
513 this.addText( |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
514 position, |
3919
2c9e96b02573
clinet: pdf-gen: improve addTextBox() function for template
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3906
diff
changeset
|
515 { x: offset.x + padding, y: offset.y + padding * 2 }, |
3154
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
516 textWidth, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
517 fontSize, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
518 color, |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
519 text |
b6c10b30d6bd
client: pdf-gen: add one pdf-template element
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3145
diff
changeset
|
520 ); |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
521 }, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
522 applyChange() { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
523 if (this.form.template.hasOwnProperty("properties")) { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
524 this.templateData = this.defaultTemplate; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
525 return; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
526 } |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
527 if (this.form.template) { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
528 this.loadTemplates("/templates/diagram/" + this.form.template.name) |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
529 .then(response => { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
530 this.prepareImages(response.data.template_data.elements).then( |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
531 values => { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
532 values.forEach(v => { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
533 response.data.template_data.elements[v.index].url = v.url; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
534 }); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
535 this.templateData = response.data.template_data; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
536 } |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
537 ); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
538 }) |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
539 .catch(e => { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
540 const { status, data } = e.response; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
541 displayError({ |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
542 title: this.$gettext("Backend Error"), |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
543 message: `${status}: ${data.message || data}` |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
544 }); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
545 }); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
546 } |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
547 } |
3963
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
548 }, |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
549 mounted() { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
550 this.templates[0] = this.defaultTemplate; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
551 this.form.template = this.templates[0]; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
552 this.templateData = this.form.template; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
553 HTTP.get("/templates/diagram", { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
554 headers: { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
555 "X-Gemma-Auth": localStorage.getItem("token"), |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
556 "Content-type": "text/xml; charset=UTF-8" |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
557 } |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
558 }) |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
559 .then(response => { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
560 if (response.data.length) { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
561 this.templates = response.data; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
562 this.form.template = this.templates[0]; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
563 this.templates[this.templates.length] = this.defaultTemplate; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
564 this.applyChange(); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
565 } |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
566 }) |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
567 .catch(e => { |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
568 const { status, data } = e.response; |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
569 displayError({ |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
570 title: this.$gettext("Backend Error"), |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
571 message: `${status}: ${data.message || data}` |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
572 }); |
feb53713bc2f
client: moved duplicated code to mixins and unified code patterns in diagram components [WIP]
Markus Kottlaender <markus@intevation.de>
parents:
3943
diff
changeset
|
573 }); |
3137
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
574 } |
35c0da49eb89
client: pdf-gen: prepare pdf template for waterlevel diagram
Fadi Abbud <fadi.abbud@intevation.de>
parents:
3079
diff
changeset
|
575 }; |