From 7a8d5cabab965bbbc8603219eda374a6e0004a59 Mon Sep 17 00:00:00 2001 From: volterra79 Date: Thu, 21 Nov 2024 17:16:33 +0100 Subject: [PATCH] :bug: Fix show features/feature query results when layer is editable and check async editing config --- src/index.dev.js | 2 +- src/map/layers/layer.js | 1 + src/map/layers/tablelayer.js | 7 +++++-- src/services/gui.js | 4 ++-- src/services/map.js | 19 +++++++++++++++---- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/index.dev.js b/src/index.dev.js index 3f16b2d1a..d6a0ed0b6 100644 --- a/src/index.dev.js +++ b/src/index.dev.js @@ -201,5 +201,5 @@ g3wsdk.gui.GUI.once('ready', () => { }); }); -window.GUI = g3wsdk.gui.GUI, +window.GUI = g3wsdk.gui.GUI; window.localforage = localforage; \ No newline at end of file diff --git a/src/map/layers/layer.js b/src/map/layers/layer.js index 8433ff9e6..86c7e8e60 100644 --- a/src/map/layers/layer.js +++ b/src/map/layers/layer.js @@ -2016,6 +2016,7 @@ class Layer extends G3WObject { */ setEditingLayer(editingLayer) { this._editingLayer = editingLayer; + this.emit('set-editing-config', editingLayer.config.editing); } /** diff --git a/src/map/layers/tablelayer.js b/src/map/layers/tablelayer.js index c85aa9d73..18df96831 100644 --- a/src/map/layers/tablelayer.js +++ b/src/map/layers/tablelayer.js @@ -118,7 +118,8 @@ export class TableLayer extends Layer { await waitFor(() => window.g3wsdk.core.hasOwnProperty('editing'), TIMEOUT); // wait until "editing" plugin is loaded // add editing configurations - this.config.editing = { + + this.config.editing = { fields: vector.fields || [], format: vector.format, constraints, @@ -127,7 +128,9 @@ export class TableLayer extends Layer { style: vector.style, // get vector layer style geometrytype: vector.geometrytype, // whether is a vector layer, visible: (vector.editing || { visible: true }).visible, //@since 3.11.0 let know if layer should be editable directly (true) or through relation layer (false) - } + }; + + this.emit('set-editing-config', this.config.editing); if (vector.style) { // set vector layer color this.setColor(vector.style.color); diff --git a/src/services/gui.js b/src/services/gui.js index b8e96606c..f14f2d7bc 100644 --- a/src/services/gui.js +++ b/src/services/gui.js @@ -455,7 +455,7 @@ export default new (class GUI extends G3WObject { }); } - const show = !stop && 'function' === typeof output.condition ? output.condition(data) : false !== output.condition; + const show = !stop && 'function' === typeof output.condition ? await output.condition(data) : false !== output.condition; // check if data can be shown on query result content if (!stop && show) { @@ -463,7 +463,7 @@ export default new (class GUI extends G3WObject { } if (!stop && !show) { - this.pending_output = this.closeContent.bind(this); + this.pending_output = await this.closeContent(); } // call after is set with data diff --git a/src/services/map.js b/src/services/map.js index 3163dca6f..ad94d2cc2 100644 --- a/src/services/map.js +++ b/src/services/map.js @@ -1067,16 +1067,21 @@ class MapService extends G3WObject { return; } + const layer = this.project.getLayerById(layerId); + const { data = [] } = await DataRouterService.getData('search:fids', { inputs: { - layer: this.project.getLayerById(layerId), + layer, fids: [fid] }, outputs: { show: { loading: false, - condition({ data = [] } = {}) { - return data[0] && data[0].features.length > 0; + async condition({ data = [] } = {}) { + if (layer.isEditable() && undefined === layer.config.editing) { + await new Promise(resolve => layer.once('set-editing-config', resolve)); + } + return !!(data[0] && data[0].features.length > 0); } } } @@ -1118,7 +1123,13 @@ class MapService extends G3WObject { }, outputs: { show: { - loading: false + loading: false, + async condition({ data = [] } = {}) { + if (layer.isEditable() && undefined === layer.config.editing) { + await new Promise(resolve => layer.once('set-editing-config', resolve)); + } + return !!(data[0] && data[0].features.length > 0); + } } } });