changeset 5340:ac1986c23889 extented-report

Merged default into extented-report branch.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 17 Jun 2021 20:48:24 +0200
parents 7365efe9f67d (current diff) d188baf44ed0 (diff)
children e434979f6ea6
files schema/gemma.sql schema/version.sql
diffstat 10 files changed, 106 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue	Thu Jun 17 14:36:01 2021 +0200
+++ b/client/src/components/Pdftool.vue	Thu Jun 17 20:48:24 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.date_info === this.selectedSurvey.date_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/components/identify/formatter.js	Thu Jun 17 14:36:01 2021 +0200
+++ b/client/src/components/identify/formatter.js	Thu Jun 17 20:48:24 2021 +0200
@@ -6,7 +6,11 @@
   all(p) {
     if (p.key === "objnam") p.key = app.$gettext("Name");
     if (p.key === "objname") p.key = app.$gettext("Name");
-    if (p.key === "staging_done" || p.key === "fa_critical")
+    if (
+      p.key === "staging_done" ||
+      p.key === "fa_critical" ||
+      p.key === "zpg_exception"
+    )
       p.val = p.val ? app.$gettext("yes") : app.$gettext("no");
     if (
       (p.key === "date_info" ||
@@ -20,7 +24,6 @@
     // remove certain props
     let propsToRemove = ["bbox"];
     if (propsToRemove.indexOf(p.key) !== -1) return null;
-
     return p;
   },
   bottlenecks_geoserver: {
@@ -121,6 +124,7 @@
       if (propsToRemove.indexOf(p.key) !== -1) return null;
       if (p.key === "surtyp") p.key = app.$gettext("Survey type");
       if (p.key === "bottleneck_id") p.key = app.$gettext("Bottleneck");
+      if (p.key === "zpg_exception") p.key = app.$gettext("ZPG exception");
       return p;
     }
   }
--- a/client/src/components/importconfiguration/types/Soundingresults.vue	Thu Jun 17 14:36:01 2021 +0200
+++ b/client/src/components/importconfiguration/types/Soundingresults.vue	Thu Jun 17 20:48:24 2021 +0200
@@ -469,11 +469,15 @@
     },
     depthReferenceOptions() {
       if (this.bottleneck) {
+        const bnProperties =this.bottleneck.properties;
         const referenceLevels = JSON.parse(
-          this.bottleneck.properties.reference_water_levels
-        );
+          bnProperties.reference_water_levels
+        )||{};
         const result = Object.keys(referenceLevels);
-        if (!referenceLevels["ZPG"]) result.push("ZPG"); // ZPG should always be available
+        const bottleneckBGorRO = bnProperties.responsible_country=="BG" || bnProperties.responsible_country=="RO";
+        const hasLDC = referenceLevels.hasOwnProperty("LDC");
+        const hasZPG = referenceLevels.hasOwnProperty("ZPG");
+        if (((hasLDC  && !hasZPG) || (!hasLDC && !hasZPG && bottleneckBGorRO)) ) result.push("ZPG");
         return result;
       }
       return [];
--- a/client/src/lib/mixins.js	Thu Jun 17 14:36:01 2021 +0200
+++ b/client/src/lib/mixins.js	Thu Jun 17 20:48:24 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	Thu Jun 17 14:36:01 2021 +0200
+++ b/client/src/store/bottlenecks.js	Thu Jun 17 20:48:24 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;
     },
--- a/pkg/imports/sr.go	Thu Jun 17 14:36:01 2021 +0200
+++ b/pkg/imports/sr.go	Thu Jun 17 20:48:24 2021 +0200
@@ -134,7 +134,8 @@
   date_info,
   depth_reference,
   area,
-  surtyp
+  surtyp,
+  zpg_exception
 ) SELECT
   bottleneck_id,
   $2::date,
@@ -145,7 +146,8 @@
     ELSE
       ST_MakeValid(ST_Transform(ST_GeomFromWKB($5, $6::integer), 4326))::geography
     END),
-  $7
+  $7,
+  $8
 FROM waterway.bottlenecks
 WHERE objnam = $1 AND validity @> CAST($2 AS timestamptz)
 RETURNING
@@ -207,6 +209,10 @@
   AND grwl.depth_reference like 'LDC%'
 `
 
+	selectZPGExceptionAllowedSQL = `
+SELECT rolname = 'sys_admin' OR country IN ('BG', 'RO')
+FROM users.list_users WHERE username = current_user`
+
 	reprojectPointsSingleBeamSQL = `
 SELECT
   ST_AsBinary(
@@ -294,6 +300,8 @@
 		xform = identityTransform
 	}
 
+	var zpgException bool
+
 	if m.DepthReference == "ZPG" {
 		feedback.Info("Found ZPG as reference system -> translating Z values to LDC")
 		var ldc float64
@@ -308,19 +316,29 @@
 		)
 		switch {
 		case err == sql.ErrNoRows:
-			return nil, errors.New("cannot load LDC value")
+			if err := conn.QueryRowContext(
+				ctx, selectZPGExceptionAllowedSQL).Scan(&zpgException); err != nil {
+				return nil, err
+			}
+			if !zpgException {
+				return nil, errors.New("cannot load LDC value")
+			}
+			feedback.Warn("Not LCD found, but ZPG exception granted")
+
 		case err != nil:
 			return nil, err
 		}
 
-		// LDC is cm. The data is in m.
-		ldc /= 100
-		xform = chainTransforms(
-			xform,
-			func(v mesh.Vertex) mesh.Vertex {
-				return mesh.Vertex{X: v.X, Y: v.Y, Z: v.Z + ldc}
-			})
-		m.DepthReference = depthReference
+		if !zpgException {
+			// LDC is cm. The data is in m.
+			ldc /= 100
+			xform = chainTransforms(
+				xform,
+				func(v mesh.Vertex) mesh.Vertex {
+					return mesh.Vertex{X: v.X, Y: v.Y, Z: v.Z + ldc}
+				})
+			m.DepthReference = depthReference
+		}
 	}
 
 	if err := m.Validate(ctx, conn); err != nil {
@@ -372,6 +390,7 @@
 		m,
 		xyz,
 		boundary,
+		zpgException,
 	)
 	if err != nil {
 		return nil, err
@@ -397,6 +416,7 @@
 	m *models.SoundingResultMeta,
 	xyz mesh.MultiPointZ,
 	boundary polygonSlice,
+	zpgException bool,
 ) (interface{}, error) {
 
 	if sr.singleBeam() {
@@ -626,6 +646,7 @@
 		clippingPolygonWKB,
 		epsg,
 		sr.surtype(),
+		zpgException,
 	).Scan(
 		&id,
 		&lat,
--- a/schema/default_sysconfig.sql	Thu Jun 17 14:36:01 2021 +0200
+++ b/schema/default_sysconfig.sql	Thu Jun 17 20:48:24 2021 +0200
@@ -213,7 +213,8 @@
             to_char(date_info, 'YYYY-MM-DD') AS date_info,
             height,
             areas,
-            surtyp
+            surtyp,
+            zpg_exception
         FROM waterway.sounding_results_iso_areas ia
             JOIN waterway.sounding_results sr ON sr.id = ia.sounding_result_id
     $$),
--- a/schema/gemma.sql	Thu Jun 17 14:36:01 2021 +0200
+++ b/schema/gemma.sql	Thu Jun 17 20:48:24 2021 +0200
@@ -800,6 +800,7 @@
         surtyp varchar REFERENCES survey_types,
         coverage varchar REFERENCES coverage_types,
         depth_reference varchar NOT NULL, -- REFERENCES depth_references,
+        zpg_exception bool NOT NULL DEFAULT FALSE, -- Found no LDC in ZPG case.
         octree_checksum varchar,
         octree_index bytea,
         mesh_checksum varchar,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schema/updates/1440/01.add_zpg_exception.sql	Thu Jun 17 20:48:24 2021 +0200
@@ -0,0 +1,1 @@
+ALTER TABLE waterway.sounding_results ADD COLUMN zpg_exception bool NOT NULL DEFAULT FALSE;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schema/updates/1441/01.extend_sounding_result_view.sql	Thu Jun 17 20:48:24 2021 +0200
@@ -0,0 +1,11 @@
+UPDATE sys_admin.published_services SET view_def = $$
+    SELECT bottleneck_id,
+        to_char(date_info, 'YYYY-MM-DD') AS date_info,
+        height,
+        areas,
+        surtyp,
+        zpg_exception
+    FROM waterway.sounding_results_iso_areas ia
+        JOIN waterway.sounding_results sr ON sr.id = ia.sounding_result_id
+$$
+  WHERE schema = 'waterway' AND name = 'sounding_results_areas_geoserver';