From 2765d177014c812a614e4ed237a0c126b9be087a Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Mon, 6 Nov 2023 18:34:30 +0000 Subject: [PATCH 1/6] add location syncFields method --- lib/location/decorate.mjs | 58 ++++++++++++++------------- lib/ui/locations/entries/geometry.mjs | 15 +++++-- lib/ui/locations/entries/pin.mjs | 3 +- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/lib/location/decorate.mjs b/lib/location/decorate.mjs index ce0bb7da9..997828f44 100644 --- a/lib/location/decorate.mjs +++ b/lib/location/decorate.mjs @@ -7,6 +7,7 @@ export default location => { removeCallbacks: [], trash, update, + syncFields, mvt_cache, updateCallbacks: [], }) @@ -64,42 +65,23 @@ async function update() { }); await this.mvt_cache() - - let dependents = this.infoj - .filter(entry => typeof entry.newValue !== 'undefined') - .filter(entry => entry.dependents && entry.dependents.length) - .map(entry => entry.dependents) - .flat() - this.infoj + // Update entry.values with newValues. + // Return dependents from updated entries. + const dependents = this.infoj .filter(entry => typeof entry.newValue !== 'undefined') - .forEach(entry => { + .map(entry => { entry.value = entry.newValue; delete entry.newValue; + return entry.dependents }) - - if (dependents.length) { - - const response = await mapp.utils.xhr( - `${this.layer.mapview.host}/api/location/get?` + - mapp.utils.paramString({ - locale: this.layer.mapview.locale.key, - layer: this.layer.key, - table: this.table, - id: this.id, - fields: [...new Set(dependents)].join(), - }) - ); - - this.infoj - .filter(entry => typeof response[entry.field] !== 'undefined') - .forEach(entry => { - entry.value = response[entry.field]; - }) + .flat() + .filter(dependents => dependents !== undefined) - } + // sync dependent fields + if (dependents.length) await this.syncFields([...new Set(dependents)]) // Reload layer. this.layer.reload() @@ -107,6 +89,26 @@ async function update() { this.updateCallbacks?.forEach(fn => typeof fn === 'function' && fn(this)) } +async function syncFields(fields) { + + const response = await mapp.utils.xhr( + `${this.layer.mapview.host}/api/location/get?` + + mapp.utils.paramString({ + locale: this.layer.mapview.locale.key, + layer: this.layer.key, + table: this.table, + id: this.id, + fields: fields.join(), + }) + ); + + this.infoj + .filter(entry => typeof response[entry.field] !== 'undefined') + .forEach(entry => { + entry.value = response[entry.field]; + }) +} + function flyTo (maxZoom) { const sourceVector = new ol.source.Vector(); diff --git a/lib/ui/locations/entries/geometry.mjs b/lib/ui/locations/entries/geometry.mjs index e0f81c381..1ab69e897 100644 --- a/lib/ui/locations/entries/geometry.mjs +++ b/lib/ui/locations/entries/geometry.mjs @@ -108,7 +108,7 @@ export default entry => { entry.value = null - postUpdate(entry) + update(entry) } }}>Delete Geometry`) @@ -213,7 +213,7 @@ function modify(e, entry) { // Assign feature geometry as new value. entry.value = feature.geometry - postUpdate(entry) + update(entry) return; } @@ -237,7 +237,7 @@ function draw(entry, list) { // Assign feature geometry as new value. entry.value = feature.geometry - postUpdate(entry) + update(entry) } Object.keys(entry.draw).forEach(key => { @@ -249,7 +249,7 @@ function draw(entry, list) { } -async function postUpdate(entry) { +async function update(entry) { if (entry.L) { @@ -275,6 +275,13 @@ async function postUpdate(entry) { body: JSON.stringify({ [entry.field]: entry.value }), }) + if (entry.dependents) { + await entry.location.syncFields(entry.dependents) + // entry.location.viewEntries.remove() + // entry.location.view?.classList.remove('disabled') + // entry.location.viewEntries = entry.location.view.appendChild(mapp.ui.locations.infoj(entry.location)) + } + if (entry.location.layer.geom === entry.field) { // Reload the layer if the layers geom field has been updated. diff --git a/lib/ui/locations/entries/pin.mjs b/lib/ui/locations/entries/pin.mjs index d1899da5e..920735a3c 100644 --- a/lib/ui/locations/entries/pin.mjs +++ b/lib/ui/locations/entries/pin.mjs @@ -1,6 +1,7 @@ export default entry => { - entry.srid = entry.srid || entry.location.layer.srid + // Assign srid from location.layer if not implicit. + entry.srid ??= entry.location.layer.srid // Remove existing pin layer entry.location.layer.mapview.Map.removeLayer(entry.L) From 0976c8f430182c813dc73eb13db521c590f2c1dc Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Tue, 7 Nov 2023 11:28:16 +0000 Subject: [PATCH 2/6] geometry update; numeric input format --- lib/ui/locations/entries/geometry.mjs | 16 ++------- lib/ui/locations/entries/numeric.mjs | 49 ++++++++++----------------- 2 files changed, 21 insertions(+), 44 deletions(-) diff --git a/lib/ui/locations/entries/geometry.mjs b/lib/ui/locations/entries/geometry.mjs index 1ab69e897..7d15607de 100644 --- a/lib/ui/locations/entries/geometry.mjs +++ b/lib/ui/locations/entries/geometry.mjs @@ -22,7 +22,7 @@ export default entry => { entry.mapview = entry.location.layer.mapview // Assign entry.style to location.style - entry.style = {...entry.location?.style, ...entry.style} + entry.style = { ...entry.location?.style, ...entry.style } // Create ol style from entry.style if not yet defined. entry.Style ??= mapp.utils.style(entry.style) @@ -81,10 +81,8 @@ export default entry => { list.push(modifyBtn) } - } - // Push modify button into list. entry.value && entry.edit?.delete && list.push(mapp.utils.html`