Mercurial > gemma
changeset 5310:660147046ddd zpg-exception
Client: Implement handling zpg-exception info in pdf
* Extend processing the "text" element of the pdf-template to check for the string "{zpg-exception}", and print the text after it only if the attribute "zpg-exception" set to true.
* Refactor one WFS-request and fit the affected functions to get these attribute, which is used to determine the displaying of zpg-exception info in pdf.
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Tue, 01 Jun 2021 09:33:03 +0200 |
parents | 3c876c65cc43 |
children | 72d3b8321ed0 |
files | client/src/components/Pdftool.vue client/src/lib/mixins.js client/src/store/bottlenecks.js |
diffstat | 3 files changed, 46 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue Fri May 28 13:43:27 2021 +0200 +++ b/client/src/components/Pdftool.vue Tue Jun 01 09:33:03 2021 +0200 @@ -270,7 +270,7 @@ this.form.paperSize = this.templateData.properties.paperSize; this.form.resolution = this.templateData.properties.resolution; }, - numberSoundingsVisible() { + getSoundingInfo() { return new Promise((resolve, reject) => { const map = this.openLayersMap(); const currentExtent = map.getView().calculateExtent(map.getSize()); @@ -280,7 +280,6 @@ featurePrefix: "gemma", featureTypes: ["sounding_results_areas_geoserver"], outputFormat: "application/json", - resultType: "hits", bbox: currentExtent, geometryName: "areas" }; @@ -310,14 +309,22 @@ }); }, download() { - this.numberSoundingsVisible() + this.getSoundingInfo() .then(response => { - const parser = new DOMParser(); - const responseXML = parser.parseFromString(response.data, "text/xml"); - const totalNumber = responseXML - .getElementsByTagName("wfs:FeatureCollection")[0] - .getAttribute("numberOfFeatures"); - this.generatePDF(totalNumber > 0); + let soundingInfo = {}; + if (this.selectedSurvey) { + soundingInfo = { + number: response.data.numberMatched || 0, + feature: + response.data.features.filter( + f => f.properties.data_info === this.selectedSurvey.data_info + )[0] || {} + }; + } else { + soundingInfo = { number: 0, feature: {} }; + } + this.$store.commit("bottlenecks/setSoundingInfo", soundingInfo); + this.generatePDF(soundingInfo); }) .catch(error => { console.log(error); @@ -332,7 +339,7 @@ }); }); }, - generatePDF(soundingsVisible) { + generatePDF(soundingInfo) { /** * In order to generate the image with the appropriate resolution * we have to temporaily scale the visible part of the map. @@ -367,7 +374,6 @@ this.pdf.width, this.pdf.height ); - if (this.templateData) { this.pdf.doc.setFont("linbiolinum", "normal"); let defaultFontSize = 11, @@ -386,7 +392,8 @@ e.width, e.fontSize || defaultFontSize, e.color || defaultTextColor, - e.text + e.text, + soundingInfo ); break; } @@ -436,7 +443,7 @@ e.rounding === 0 || e.rounding ? e.rounding : defaultRounding, e.color || defaultTextColor, e.brcolor || defaultBorderColor, - soundingsVisible + soundingInfo.number > 0 ); break; } @@ -446,7 +453,7 @@ e.offset || defaultOffset, e.rounding === 0 || e.rounding ? e.rounding : defaultRounding, e.brcolor || defaultBorderColor, - soundingsVisible + soundingInfo.number > 0 ); break; } @@ -496,7 +503,7 @@ let filename = "map"; if ( this.bottleneckForPrint && - (soundingsVisible || isBottlenckVisible()) + (soundingInfo.number > 0 || isBottlenckVisible()) ) { filename = `BN-${sanitize(this.bottleneckForPrint).replace( / /g, @@ -738,9 +745,9 @@ this.pdf.doc.setFontStyle("normal"); this.pdf.doc.text(size < 3 ? x1 - 0.5 : x1 - 1.3, y3 + 1, "N"); }, - addLegend(position, offset, rounding, brcolor, soundingsVisible) { + addLegend(position, offset, rounding, brcolor, hasSounding) { if ( - soundingsVisible && + hasSounding && this.bottleneckForPrint && this.selectedSurvey && this.openLayersMap() @@ -780,16 +787,9 @@ ); } }, - addBottleneckInfo( - position, - offset, - rounding, - color, - brcolor, - soundingsVisible - ) { + addBottleneckInfo(position, offset, rounding, color, brcolor, hasSounding) { if ( - soundingsVisible && + hasSounding && this.bottleneckForPrint && this.selectedSurvey && this.openLayersMap()
--- a/client/src/lib/mixins.js Fri May 28 13:43:27 2021 +0200 +++ b/client/src/lib/mixins.js Tue Jun 01 09:33:03 2021 +0200 @@ -165,7 +165,8 @@ export const pdfgen = { computed: { ...mapState("application", ["logoForPDF"]), - ...mapState("user", ["user"]) + ...mapState("user", ["user"]), + ...mapState("bottlenecks", ["soundingInfo"]) }, methods: { downloadImage(elementName, title) { @@ -455,6 +456,19 @@ if (text.includes("{user}")) { text = text.replace("{user}", this.user); } + if (text.includes("{zpg-exception}")) { + // Print the text followed by "zpg-exception" if this value set to true + if ( + this.soundingInfo && + this.soundingInfo.number > 0 && + this.soundingInfo.feature.properties.zpg_exception + ) { + text = text.replace("{zpg-exception}", ""); + // Otherwise nothing to print + } else { + text = ""; + } + } return text; }, addImage(url, format, position, offset, width, height) {
--- a/client/src/store/bottlenecks.js Fri May 28 13:43:27 2021 +0200 +++ b/client/src/store/bottlenecks.js Tue Jun 01 09:33:03 2021 +0200 @@ -25,7 +25,8 @@ surveys: [], selectedSurvey: null, surveysLoading: false, - bottleneckForPrint: null + bottleneckForPrint: null, + soundingInfo: null }; }; @@ -64,6 +65,9 @@ } }, mutations: { + setSoundingInfo: (state, data) => { + state.soundingInfo = data; + }, setBottleneckForPrint: (state, bottleneck) => { state.bottleneckForPrint = bottleneck; },