From 03ec8d39303ebf403662df4a7f2a08a7bfbf9bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C5=BEe=20Fortun?= Date: Wed, 11 Dec 2024 14:23:22 +0100 Subject: [PATCH] Fix evaluated filters overwriting configuration --- .../components/PageBlocks/CalendarBase.vue | 5 +- .../components/PageBlocks/GeometryBase.vue | 89 +++++++++---------- .../src/components/PageBlocks/MetricBase.vue | 1 + 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/client/web/compose/src/components/PageBlocks/CalendarBase.vue b/client/web/compose/src/components/PageBlocks/CalendarBase.vue index d58ab50b96..1014250d8a 100644 --- a/client/web/compose/src/components/PageBlocks/CalendarBase.vue +++ b/client/web/compose/src/components/PageBlocks/CalendarBase.vue @@ -328,10 +328,7 @@ export default { case compose.PageBlockCalendar.feedResources.record: return this.findModuleByID({ namespace: this.namespace, moduleID: feed.options.moduleID }) .then(module => { - const ff = { - ...feed, - options: { ...feed.options }, - } + const ff = compose.PageBlockCalendar.makeFeed(feed) // Clone feed, so we don't modify the original // Interpolate prefilter variables if (ff.options.prefilter) { diff --git a/client/web/compose/src/components/PageBlocks/GeometryBase.vue b/client/web/compose/src/components/PageBlocks/GeometryBase.vue index cf8fc93ef2..10c1437940 100644 --- a/client/web/compose/src/components/PageBlocks/GeometryBase.vue +++ b/client/web/compose/src/components/PageBlocks/GeometryBase.vue @@ -190,51 +190,50 @@ export default { } Promise.all(this.options.feeds.filter(f => f.isValid()).map((feed, idx) => { - return this.findModuleByID({ namespace: this.namespace, moduleID: feed.options.moduleID }) - .then(module => { - const f = { ...feed } // Clone feed, so we dont modify the original - - // Interpolate prefilter variables - if (f.options.prefilter) { - f.options.prefilter = evaluatePrefilter(f.options.prefilter, { - record: this.record, - user: this.$auth.user || {}, - recordID: (this.record || {}).recordID || NoID, - ownerID: (this.record || {}).ownedBy || NoID, - userID: (this.$auth.user || {}).userID || NoID, - }) - } - - return compose.PageBlockGeometry.RecordFeed(this.$ComposeAPI, module, this.namespace, f, { cancelToken: this.cancelTokenSource.token }) - .then(records => { - const mapModuleField = module.fields.find(field => field.name === f.geometryField) - - if (!mapModuleField) return - - this.geometries[idx] = records.map(record => { - let geometry = record.values[f.geometryField] - let markers = [] - - if (mapModuleField.isMulti) { - geometry = geometry.map(value => this.parseGeometryField(value)) - markers = geometry - } else { - geometry = this.parseGeometryField(geometry) - markers = [geometry] - } - - return { - title: record.values[f.titleField], - geometry: f.displayPolygon ? geometry : [], - markers, - color: f.options.color, - displayMarker: f.displayMarker, - recordID: record.recordID, - moduleID: record.moduleID, - } - }).filter(g => g && g.markers.length) - }) - }) + return this.findModuleByID({ namespace: this.namespace, moduleID: feed.options.moduleID }).then(module => { + const f = compose.PageBlockGeometry.makeFeed(feed) // Clone feed, so we don't modify the original + + // Interpolate prefilter variables + if (f.options.prefilter) { + f.options.prefilter = evaluatePrefilter(f.options.prefilter, { + record: this.record, + user: this.$auth.user || {}, + recordID: (this.record || {}).recordID || NoID, + ownerID: (this.record || {}).ownedBy || NoID, + userID: (this.$auth.user || {}).userID || NoID, + }) + } + + return compose.PageBlockGeometry.RecordFeed(this.$ComposeAPI, module, this.namespace, f, { cancelToken: this.cancelTokenSource.token }) + .then(records => { + const mapModuleField = module.fields.find(field => field.name === f.geometryField) + + if (!mapModuleField) return + + this.geometries[idx] = records.map(record => { + let geometry = record.values[f.geometryField] + let markers = [] + + if (mapModuleField.isMulti) { + geometry = geometry.map(value => this.parseGeometryField(value)) + markers = geometry + } else { + geometry = this.parseGeometryField(geometry) + markers = [geometry] + } + + return { + title: record.values[f.titleField], + geometry: f.displayPolygon ? geometry : [], + markers, + color: f.options.color, + displayMarker: f.displayMarker, + recordID: record.recordID, + moduleID: record.moduleID, + } + }).filter(g => g && g.markers.length) + }) + }) })).finally(() => { setTimeout(() => { this.processing = false diff --git a/client/web/compose/src/components/PageBlocks/MetricBase.vue b/client/web/compose/src/components/PageBlocks/MetricBase.vue index 83991a17d8..1c892bf388 100644 --- a/client/web/compose/src/components/PageBlocks/MetricBase.vue +++ b/client/web/compose/src/components/PageBlocks/MetricBase.vue @@ -166,6 +166,7 @@ export default { if (m.moduleID) { // prepare a fresh metric with an evaluated prefilter const auxM = { ...m } + if (auxM.filter) { auxM.filter = evaluatePrefilter(auxM.filter, { record: this.record,