From ef42506fea0baef55eecf697e82ea5b66eb061a5 Mon Sep 17 00:00:00 2001 From: Raruto Date: Tue, 25 Jul 2023 16:19:16 +0200 Subject: [PATCH] Add `src/app/eventbus.js` (common event emitters) --- src/app/constant.js | 9 ++++- src/app/eventbus.js | 34 +++++++++++++++++++ src/app/g3w-ol/constants.js | 11 ------ .../controls/basequerypolygoncontrol.js | 4 +-- src/app/g3w-ol/controls/interactioncontrol.js | 5 +-- src/app/g3w-ol/controls/querybboxcontrol.js | 4 +-- src/app/g3w-ol/projection/projections.js | 2 +- src/app/gui/catalog/vue/catalogeventhub.js | 8 ----- src/app/gui/relations/vue/relationeventbus.js | 6 ---- src/app/gui/sidebar/eventbus.js | 6 ---- src/components/Catalog.vue | 16 ++++----- src/components/CatalogLayerContextMenu.vue | 6 ++-- src/components/CatalogLayerLegend.vue | 6 ++-- src/components/CatalogLayersLegendItems.vue | 4 +-- src/components/CatalogTristateTree.vue | 20 +++++------ src/components/LayerOpacityPicker.vue | 6 ++-- src/components/Relation.vue | 4 +-- src/components/RelationsPage.vue | 4 +-- src/components/Sidebar.vue | 4 +-- src/components/SidebarItem.vue | 4 +-- src/store/map-controls.js | 2 +- 21 files changed, 88 insertions(+), 77 deletions(-) create mode 100644 src/app/eventbus.js delete mode 100644 src/app/g3w-ol/constants.js delete mode 100644 src/app/gui/catalog/vue/catalogeventhub.js delete mode 100644 src/app/gui/relations/vue/relationeventbus.js delete mode 100644 src/app/gui/sidebar/eventbus.js diff --git a/src/app/constant.js b/src/app/constant.js index a10121ded..96851a76a 100644 --- a/src/app/constant.js +++ b/src/app/constant.js @@ -611,9 +611,15 @@ export const LOCAL_ITEM_IDS = { /** * @since 3.8.0 */ - export const LOGO_GIS3W = 'images/logo_gis3w_156_85.png'; +/** + * List of Open Layers spatial methods used to find features + * + * @since 3.9.0 + */ +export const SPATIAL_METHODS = ['intersects', 'within']; + export default { APP_VERSION, API_BASE_URLS, @@ -637,6 +643,7 @@ export default { QUERY_POINT_TOLERANCE, SEARCH_ALLVALUE, SEARCH_RETURN_TYPES, + SPATIAL_METHODS, TIMEOUT, TOC_LAYERS_INIT_STATUS, TOC_THEMES_INIT_STATUS, diff --git a/src/app/eventbus.js b/src/app/eventbus.js new file mode 100644 index 000000000..f9dee8024 --- /dev/null +++ b/src/app/eventbus.js @@ -0,0 +1,34 @@ +/** + * @file common vue instances used to watch object changes or to emit events + * + * NB: node.js modules are singletons by default. + * + * @see https://medium.com/@lazlojuly/are-node-js-modules-singletons-764ae97519af + */ + +/** + * ORIGINAL SOURCE: src/app/g3w-ol/constants.js@3.8.6 + */ +export const VM = new Vue(); + +/** + * ORIGINAL SOURCE: src\app\gui\catalog\vue\catalogeventhub.js@3.8.6 + */ +export const CatalogEventBus = new Vue(); + +/** + * ORIGINAL SOURCE: src/app/gui/relations/vue/relationeventbus.js@3.8.6 + */ +export const RelationEventBus = new Vue(); + +/** + * ORIGINAL SOURCE: src/app/gui/sidebar/eventbus.js@3.8.6 + */ +export const SidebarEventBus = new Vue(); + +export default { + VM, + CatalogEventBus, + RelationEventBus, + SidebarEventBus, +}; diff --git a/src/app/g3w-ol/constants.js b/src/app/g3w-ol/constants.js deleted file mode 100644 index 024a5195c..000000000 --- a/src/app/g3w-ol/constants.js +++ /dev/null @@ -1,11 +0,0 @@ -//SPATIAL METHODS USED TO FIND FEATURES -export const SPATIALMETHODS = ['intersects', 'within']; - -/** - * MAIN VUE INSTANCE USED TO WATCH OBJECT CHANGES OR TO EMIT EVENTS - * - * NB: node.js modules are singletons by default. - * - * @see https://medium.com/@lazlojuly/are-node-js-modules-singletons-764ae97519af - */ -export const VM = new Vue(); diff --git a/src/app/g3w-ol/controls/basequerypolygoncontrol.js b/src/app/g3w-ol/controls/basequerypolygoncontrol.js index 9b1e80a42..d5bbf23df 100644 --- a/src/app/g3w-ol/controls/basequerypolygoncontrol.js +++ b/src/app/g3w-ol/controls/basequerypolygoncontrol.js @@ -2,7 +2,7 @@ * @file * @since v3.8 */ -import { SPATIALMETHODS } from 'g3w-ol/constants'; +import { SPATIAL_METHODS } from 'app/constant'; const InteractionControl = require('g3w-ol/controls/interactioncontrol'); const { merge } = require('core/utils/ol'); @@ -13,7 +13,7 @@ const VALIDGEOMETRIES = Geometry.getAllPolygonGeometryTypes(); const BaseQueryPolygonControl = function(options = {}) { const { - spatialMethod=SPATIALMETHODS[0], + spatialMethod=SPATIAL_METHODS[0], onSelectlayer, interactionClass } = options; diff --git a/src/app/g3w-ol/controls/interactioncontrol.js b/src/app/g3w-ol/controls/interactioncontrol.js index fa531967f..114fb2006 100644 --- a/src/app/g3w-ol/controls/interactioncontrol.js +++ b/src/app/g3w-ol/controls/interactioncontrol.js @@ -1,4 +1,5 @@ -import { VM, SPATIALMETHODS } from 'g3w-ol/constants'; +import { SPATIAL_METHODS } from 'app/constant'; +import { VM } from 'app/eventbus'; import GUI from 'services/gui'; import ControlsRegistry from 'store/map-controls' @@ -240,7 +241,7 @@ proto.createControlTool = function(toggledTool={}) { const method = this.getSpatialMethod(); this.toggledTool = { data() { - this.methods = SPATIALMETHODS; + this.methods = SPATIAL_METHODS; return { method } diff --git a/src/app/g3w-ol/controls/querybboxcontrol.js b/src/app/g3w-ol/controls/querybboxcontrol.js index 33d1fe16d..223492c5f 100644 --- a/src/app/g3w-ol/controls/querybboxcontrol.js +++ b/src/app/g3w-ol/controls/querybboxcontrol.js @@ -1,4 +1,4 @@ -import { SPATIALMETHODS } from 'g3w-ol/constants'; +import { SPATIAL_LMETHODS } from 'app/constant'; import GUI from 'services/gui'; import DataRouterService from 'services/data'; import ProjectsRegistry from 'store/projects'; @@ -24,7 +24,7 @@ const condition = { const QueryBBoxControl = function(options = {}) { const { - spatialMethod = SPATIALMETHODS[0] + spatialMethod = SPATIAL_METHODS[0] } = options; /** diff --git a/src/app/g3w-ol/projection/projections.js b/src/app/g3w-ol/projection/projections.js index 58a9bad5f..64e4398af 100644 --- a/src/app/g3w-ol/projection/projections.js +++ b/src/app/g3w-ol/projection/projections.js @@ -1,6 +1,6 @@ import { API_BASE_URLS } from 'constant'; -const Projection = require('./projection'); +const Projection = require('g3w-ol/projection/projection'); const { XHR } = require('core/utils/utils'); const {normalizeEpsg } = require('core/utils/geo'); diff --git a/src/app/gui/catalog/vue/catalogeventhub.js b/src/app/gui/catalog/vue/catalogeventhub.js deleted file mode 100644 index 5571295be..000000000 --- a/src/app/gui/catalog/vue/catalogeventhub.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * NB: node.js modules are singletons by default. - * - * @see https://medium.com/@lazlojuly/are-node-js-modules-singletons-764ae97519af - */ -const CatalogEventHub = new Vue(); - -export default CatalogEventHub; diff --git a/src/app/gui/relations/vue/relationeventbus.js b/src/app/gui/relations/vue/relationeventbus.js deleted file mode 100644 index a03a77035..000000000 --- a/src/app/gui/relations/vue/relationeventbus.js +++ /dev/null @@ -1,6 +0,0 @@ -/** - * NB: node.js modules are singletons by default. - * - * @see https://medium.com/@lazlojuly/are-node-js-modules-singletons-764ae97519af - */ -module.exports = new Vue(); \ No newline at end of file diff --git a/src/app/gui/sidebar/eventbus.js b/src/app/gui/sidebar/eventbus.js deleted file mode 100644 index d2ef851a3..000000000 --- a/src/app/gui/sidebar/eventbus.js +++ /dev/null @@ -1,6 +0,0 @@ -/** - * NB: node.js modules are singletons by default. - * - * @see https://medium.com/@lazlojuly/are-node-js-modules-singletons-764ae97519af - */ -export default new Vue(); \ No newline at end of file diff --git a/src/components/Catalog.vue b/src/components/Catalog.vue index ba907e0ab..1924690d8 100644 --- a/src/components/Catalog.vue +++ b/src/components/Catalog.vue @@ -123,7 +123,7 @@ diff --git a/src/components/SidebarItem.vue b/src/components/SidebarItem.vue index ea2212d9f..a0b337915 100644 --- a/src/components/SidebarItem.vue +++ b/src/components/SidebarItem.vue @@ -22,7 +22,7 @@