Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add src/app/eventbus.js (common event emitters) #458

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/app/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions src/app/eventbus.js
Original file line number Diff line number Diff line change
@@ -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,
};
11 changes: 0 additions & 11 deletions src/app/g3w-ol/constants.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/g3w-ol/controls/basequerypolygoncontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -13,7 +13,7 @@ const VALIDGEOMETRIES = Geometry.getAllPolygonGeometryTypes();
const BaseQueryPolygonControl = function(options = {}) {

const {
spatialMethod=SPATIALMETHODS[0],
spatialMethod=SPATIAL_METHODS[0],
onSelectlayer,
interactionClass
} = options;
Expand Down
5 changes: 3 additions & 2 deletions src/app/g3w-ol/controls/interactioncontrol.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -240,7 +241,7 @@ proto.createControlTool = function(toggledTool={}) {
const method = this.getSpatialMethod();
this.toggledTool = {
data() {
this.methods = SPATIALMETHODS;
this.methods = SPATIAL_METHODS;
return {
method
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/g3w-ol/controls/querybboxcontrol.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -24,7 +24,7 @@ const condition = {
const QueryBBoxControl = function(options = {}) {

const {
spatialMethod = SPATIALMETHODS[0]
spatialMethod = SPATIAL_METHODS[0]
} = options;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/app/g3w-ol/projection/projections.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
8 changes: 0 additions & 8 deletions src/app/gui/catalog/vue/catalogeventhub.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/app/gui/relations/vue/relationeventbus.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/app/gui/sidebar/eventbus.js

This file was deleted.

16 changes: 8 additions & 8 deletions src/components/Catalog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

<script>
import { MAP_SETTINGS } from 'app/constant';
import CatalogEventHub from 'gui/catalog/vue/catalogeventhub';
import { CatalogEventBus as VM } from 'app/eventbus';
import ChangeMapThemesComponent from 'components/CatalogChangeMapThemes.vue';
import CatalogLayerContextMenu from 'components/CatalogLayerContextMenu.vue';
import CatalogLayersStoresRegistry from 'store/catalog-layers';
Expand Down Expand Up @@ -210,10 +210,10 @@ export default {
}
});
if ('tab' === this.legend.place) {
CatalogEventHub.$emit('layer-change-style');
VM.$emit('layer-change-style');
} else {
// get all layer tha changes style
changeStyleLayersId.forEach(layerId => { CatalogEventHub.$emit('layer-change-style', { layerId }); });
changeStyleLayersId.forEach(layerId => { VM.$emit('layer-change-style', { layerId }); });
}
},

Expand Down Expand Up @@ -289,7 +289,7 @@ export default {
/**
* @TODO add description
*/
CatalogEventHub.$on('unselectionlayer', (storeid, layerstree) => {
VM.$on('unselectionlayer', (storeid, layerstree) => {
if (layerstree.external) {
GUI.getService('queryresults').clearSelectionExtenalLayer(layerstree);
} else {
Expand All @@ -300,21 +300,21 @@ export default {
/**
* @TODO add description
*/
CatalogEventHub.$on('activefiltertokenlayer', async (storeid, layerstree) => {
VM.$on('activefiltertokenlayer', async (storeid, layerstree) => {
layerstree.filter.active = await CatalogLayersStoresRegistry.getLayersStore(storeid).getLayerById(layerstree.id).toggleFilterToken();
});

/**
* Handle visibilty change on legend item
*/
CatalogEventHub.$on('treenodevisible', layer => {
VM.$on('treenodevisible', layer => {
GUI.getService('map').emit('cataloglayervisible', layer);
});

/**
* Handle legend item select (single mouse click ?)
*/
CatalogEventHub.$on('treenodeselected', function (storeid, node) {
VM.$on('treenodeselected', function (storeid, node) {
let layer = CatalogLayersStoresRegistry.getLayersStore(storeid).getLayerById(node.id);
// emit signal of select layer from catalog
if (!layer.isSelected()) {
Expand All @@ -330,7 +330,7 @@ export default {
/**
* Handle temporary external layer add
*/
CatalogEventHub.$on('treenodeexternalselected', layer => {
VM.$on('treenodeexternalselected', layer => {
GUI
.getService('catalog')
.setSelectedExternalLayer({ layer, type: 'vector', selected: !layer.selected})
Expand Down
6 changes: 3 additions & 3 deletions src/components/CatalogLayerContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@

import LayerOpacityPicker from "components/LayerOpacityPicker.vue";

import CatalogEventHub from 'gui/catalog/vue/catalogeventhub';
import { CatalogEventBus as VM } from 'app/eventbus';
import CatalogLayersStoresRegistry from 'store/catalog-layers';
import ApplicationService from 'services/application';
import GUI from 'services/gui';
Expand Down Expand Up @@ -667,7 +667,7 @@
const layerId = this.layerMenu.layer.id;
const layer = CatalogLayersStoresRegistry.getLayerById(this.layerMenu.layer.id);
if (layer) {
CatalogEventHub.$emit('layer-change-style', {
VM.$emit('layer-change-style', {
layerId,
style: this.layerMenu.stylesMenu.style
});
Expand Down Expand Up @@ -778,7 +778,7 @@
},

created() {
CatalogEventHub.$on('showmenulayer', async (layerstree, evt) => {
VM.$on('showmenulayer', async (layerstree, evt) => {
this._hideMenu();
await this.$nextTick();
this.layerMenu.left = evt.x;
Expand Down
6 changes: 3 additions & 3 deletions src/components/CatalogLayerLegend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

<script>
import GUI from 'services/gui';
import CatalogEventHub from 'gui/catalog/vue/catalogeventhub';
import { CatalogEventBus as VM } from 'app/eventbus';
import CatalogLayersStoresRegistry from 'store/catalog-layers';
import ProjectsRegistry from 'store/projects';
import ClickMixin from 'mixins/click';
Expand Down Expand Up @@ -381,7 +381,7 @@
this.mapReady = false;

// listen layer change style event
CatalogEventHub.$on('layer-change-style', this.onChangeLayerLegendStyle);
VM.$on('layer-change-style', this.onChangeLayerLegendStyle);

// Get all legend graphics of a layer when start
// need to exclude wms source
Expand All @@ -392,7 +392,7 @@
},

beforeDestroy() {
CatalogEventHub.$off('layer-change-style', this.onChangeLayerLegendStyle);
VM.$off('layer-change-style', this.onChangeLayerLegendStyle);
},

}
Expand Down
4 changes: 2 additions & 2 deletions src/components/CatalogLayersLegendItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</template>

<script>
import CatalogEventHub from 'gui/catalog/vue/catalogeventhub';
import { CatalogEventBus as VM } from 'app/eventbus';
import CatalogLayersStoresRegistry from 'store/catalog-layers';
import ApplicationService from 'services/application';
import ProjectsRegistry from 'store/projects';
Expand Down Expand Up @@ -285,7 +285,7 @@ export default {
/**
* listen when layer has changed style
*/
CatalogEventHub.$on('layer-change-style', (options={}) => {
VM.$on('layer-change-style', (options={}) => {
this.getLegendSrc();
});
},
Expand Down
20 changes: 10 additions & 10 deletions src/components/CatalogTristateTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@

<script>
import LayerLegend from 'components/CatalogLayerLegend.vue';
import CatalogEventHub from 'gui/catalog/vue/catalogeventhub';
import { CatalogEventBus as VM } from 'app/eventbus';
import CatalogLayersStoresRegistry from 'store/catalog-layers';
import ClickMixin from 'mixins/click';
import GUI from 'services/gui';
Expand Down Expand Up @@ -437,7 +437,7 @@ export default {
* @TODO is it necessary to emit the `layer-change-style` event here?
*/
// if (visible && 'toc' === this.legendplace) {
// setTimeout(() => CatalogEventHub.$emit('layer-change-style', { layerId: id }));
// setTimeout(() => VM.$emit('layer-change-style', { layerId: id }));
// }
if (parentGroup.mutually_exclusive) {
parentGroup.nodes.forEach(node => node.checked = node.id === id);
Expand All @@ -449,17 +449,17 @@ export default {
} else {
layer.setVisible(false);
}
CatalogEventHub.$emit('treenodevisible', layer);
VM.$emit('treenodevisible', layer);
}

},

toggleFilterLayer() {
CatalogEventHub.$emit('activefiltertokenlayer', this.storeid, this.layerstree);
VM.$emit('activefiltertokenlayer', this.storeid, this.layerstree);
},

clearSelection() {
CatalogEventHub.$emit('unselectionlayer', this.storeid, this.layerstree);
VM.$emit('unselectionlayer', this.storeid, this.layerstree);
},

toggle() {
Expand All @@ -473,18 +473,18 @@ export default {
/**
* Select legend item
*
* @fires CatalogEventHub~treenodeexternalselected
* @fires CatalogEventHub~treenodeselected
* @fires CatalogEventBus~treenodeexternalselected
* @fires CatalogEventBus~treenodeselected
*/
select() {
// skip when `selected === undefined` (unselectable layer, eg. an external WMS layer)
if (undefined === this.layerstree.selected) {
return;
}
if (this.layerstree.external) {
CatalogEventHub.$emit('treenodeexternalselected', this.layerstree);
VM.$emit('treenodeexternalselected', this.layerstree);
} else if (!this.isGroup && !this.isTable) {
CatalogEventHub.$emit('treenodeselected', this.storeid, this.layerstree);
VM.$emit('treenodeselected', this.storeid, this.layerstree);
}
},

Expand Down Expand Up @@ -547,7 +547,7 @@ export default {
!this.isGroup &&
(this.layerstree.openattributetable || this.layerstree.downloadable || this.layerstree.geolayer || this.layerstree.external)
) {
CatalogEventHub.$emit('showmenulayer', layerstree, evt);
VM.$emit('showmenulayer', layerstree, evt);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/LayerOpacityPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<script>
import CatalogLayersStoresRegistry from 'store/catalog-layers';
import CatalogEventHub from 'gui/catalog/vue/catalogeventhub';
import { CatalogEventBus as VM } from 'app/eventbus';

export default {

Expand Down Expand Up @@ -77,7 +77,7 @@
/**
* @param {{ id:? string, value: number }}
*
* @fires CatalogEventHub~layer-change-opacity
* @fires CatalogEventBus~layer-change-opacity
*/
setLayerOpacity( { id = this.layer.id, value: opacity }) {
// skip if nothing has changed
Expand All @@ -87,7 +87,7 @@
this.layer.opacity = opacity;
const layer = CatalogLayersStoresRegistry.getLayerById(id);
if (layer) {
CatalogEventHub.$emit('layer-change-opacity', { layerId: id });
VM.$emit('layer-change-opacity', { layerId: id });
layer.change();
}
},
Expand Down
Loading