From 346009616895e59c36fcff4093807d1b54e514ef Mon Sep 17 00:00:00 2001 From: Raruto Date: Tue, 7 Feb 2023 16:19:07 +0100 Subject: [PATCH] Deprecate setters `ProjectsRegistry~setCurrentProject(project)` and `ProjectsRegistry~createProject(projectConfig)` Start addressing: https://github.com/g3w-suite/g3w-client/issues/67 As a result of: https://github.com/g3w-suite/g3w-client/pull/150 we intend to bring the development environment ever closer to the production one. Related to: https://github.com/g3w-suite/g3w-client/issues/89, https://github.com/g3w-suite/g3w-client/issues/292 and https://github.com/g3w-suite/g3w-suite-docker/pull/79 --- src/app/core/data/service.js | 3 ++ src/app/core/print/printservice.js | 3 ++ src/app/dev/index.js | 8 ++-- src/app/gui/map/mapservice.js | 37 ++++++++++--------- .../gui/queryresults/queryresultsservice.js | 2 + src/app/gui/wms/service.js | 5 ++- src/store/plugins.js | 6 +-- src/store/projects.js | 28 +++++++++++--- 8 files changed, 59 insertions(+), 33 deletions(-) diff --git a/src/app/core/data/service.js b/src/app/core/data/service.js index c2af22d54..fefe4e37f 100644 --- a/src/app/core/data/service.js +++ b/src/app/core/data/service.js @@ -1,7 +1,10 @@ import ProjectsRegistry from 'store/projects'; function BaseService(){ + + /** @deprecated since v3.5 */ ProjectsRegistry.onbefore('setCurrentProject' , project => this.project = project); + this.project = ProjectsRegistry.getCurrentProject(); } diff --git a/src/app/core/print/printservice.js b/src/app/core/print/printservice.js index cb521fe68..1b93900ef 100644 --- a/src/app/core/print/printservice.js +++ b/src/app/core/print/printservice.js @@ -120,7 +120,10 @@ const POST = function({url, params, mime_type}) { */ function PrintService(options = {}) { this._currentLayerStore = ProjectsRegistry.getCurrentProject().getLayersStore(); + + /** @deprecated since v3.5 */ ProjectsRegistry.onbefore('setCurrentProject', project=> this._currentLayerStore = project.getLayersStore()); + base(this); } diff --git a/src/app/dev/index.js b/src/app/dev/index.js index 0233b657b..48315be32 100644 --- a/src/app/dev/index.js +++ b/src/app/dev/index.js @@ -24,22 +24,22 @@ ApplicationService.once('initconfig', () => { }); }); -/** @deprecated */ +/** @deprecated since v3.5 */ if (createProject.before) { ProjectsRegistry.onbefore('createProject', (projectConfig) => createProject.before(projectConfig)); } -/** @deprecated */ +/** @deprecated since v3.5 */ if (createProject.after) { ProjectsRegistry.onafter('createProject', (projectConfig) => createProject.after(projectConfig)); } -/** @deprecated */ +/** @deprecated since v3.5 */ if (setCurrentProject.before) { ProjectsRegistry.onbefore('setCurrentProject', (project) => setCurrentProject.before(project)); } -/** @deprecated */ +/** @deprecated since v3.5 */ if (setCurrentProject.after) { ProjectsRegistry.onafter('setCurrentProject', (project) => setCurrentProject.after(project)); } diff --git a/src/app/gui/map/mapservice.js b/src/app/gui/map/mapservice.js index b91b552ba..b5837a30f 100644 --- a/src/app/gui/map/mapservice.js +++ b/src/app/gui/map/mapservice.js @@ -177,28 +177,29 @@ function MapService(options={}) { if (options.project) this.project = options.project; else { this.project = ProjectsRegistry.getCurrentProject(); - //on after setting current project - const keysetCurrentProject = ProjectsRegistry.onafter('setCurrentProject', project => { - this.removeLayers(); - this._removeListeners(); - // check if reload same project - const isSameProject = this.project.getId() === project.getId(); - this.project = project; - const changeProjectCallBack = () => { - this._resetView(); - this._setupAllLayers(); - this._checkMapControls(); - this.setUpMapOlEvents(); - this.setupCustomMapParamsToLegendUrl(); - }; - ApplicationService.isIframe() && changeProjectCallBack(); - isSameProject ? changeProjectCallBack() : this.getMap().once('change:size', changeProjectCallBack); - }); + + /** @deprecated since v3.5 */ this._keyEvents.g3wobject.push({ who: ProjectsRegistry, setter : 'setCurrentProject', - key: keysetCurrentProject + key: ProjectsRegistry.onafter('setCurrentProject', project => { // on after setting current project + this.removeLayers(); + this._removeListeners(); + // check if reload same project + const isSameProject = this.project.getId() === project.getId(); + this.project = project; + const changeProjectCallBack = () => { + this._resetView(); + this._setupAllLayers(); + this._checkMapControls(); + this.setUpMapOlEvents(); + this.setupCustomMapParamsToLegendUrl(); + }; + ApplicationService.isIframe() && changeProjectCallBack(); + isSameProject ? changeProjectCallBack() : this.getMap().once('change:size', changeProjectCallBack); + }) }); + } this._setupListeners(); this._marker = null; diff --git a/src/app/gui/queryresults/queryresultsservice.js b/src/app/gui/queryresults/queryresultsservice.js index b7cbdc1d4..20dd0d2ed 100644 --- a/src/app/gui/queryresults/queryresultsservice.js +++ b/src/app/gui/queryresults/queryresultsservice.js @@ -25,6 +25,7 @@ function QueryResultsService() { this.printService = new PrintService(); this._currentLayerIds = []; + /** @deprecated since v3.5 */ ProjectsRegistry.onafter('setCurrentProject', project => { this._project = project; this._setRelations(project); @@ -32,6 +33,7 @@ function QueryResultsService() { this.state.download_data = false; this.plotLayerIds = []; }); + this.unlistenerlayeractionevents = []; this._actions = { 'zoomto': QueryResultsService.zoomToElement, diff --git a/src/app/gui/wms/service.js b/src/app/gui/wms/service.js index abc043380..65949fdab 100644 --- a/src/app/gui/wms/service.js +++ b/src/app/gui/wms/service.js @@ -17,11 +17,14 @@ function Service(options={}){ }; this.loadClientWmsUrls() .then(urls => this.state.localwmsurls = urls); + + /** @deprecated since v3.5 */ ProjectsRegistry.onafter('setCurrentProject', async project => { this.projectId = project.getId(); this.state.adminwmsurls = project.wmsurls || []; this.state.localwmsurls = await this.loadClientWmsUrls(); - }) + }); + } const proto = Service.prototype; diff --git a/src/store/plugins.js b/src/store/plugins.js index f2e04c5cd..6e110c45f 100644 --- a/src/store/plugins.js +++ b/src/store/plugins.js @@ -27,10 +27,8 @@ function PluginsRegistry() { if (!this._plugins[plugin.name]) this._plugins[plugin.name] = plugin; } }; - /** - * CHECK IF STILL USEFUL. IT RELATED TO CHANGE MAP OLD BEHAVIOR (PREVIOUS VERSION 3.4). - * NOW WHEN CHANGE MAP IS TRIGGER, PAGE IS RELOADED. - */ + + /** @deprecated since v3.5 */ ProjectsRegistry.onafter('setCurrentProject', project =>{ this.gidProject = project.getGid(); }); diff --git a/src/store/projects.js b/src/store/projects.js index 34c13f89c..cd67009f4 100644 --- a/src/store/projects.js +++ b/src/store/projects.js @@ -22,10 +22,22 @@ function ProjectsRegistry() { this.initialized = false; this.projectType = null; this.overviewproject; + this.setters = { - createProject(projectConfig){ - //hook to get project config and modify it + + /** + * Hook mainly used to override current project configuration while developing locally. + * + * @deprecated since v3.5 + */ + createProject(projectConfig) { }, + + /** + * Prior to v3.4 a change map hook was always triggered, now the page is simply reloaded. + * + * @deprecated since v3.5 + */ setCurrentProject(project) { if (this.state.currentProject !== project) { CatalogLayersStoresRegistry.removeLayersStores(); @@ -40,6 +52,7 @@ function ProjectsRegistry() { //set in first position (map) MapLayersStoresRegistry.addLayersStore(projectLayersStore, 0); } + }; this.state = { @@ -76,9 +89,10 @@ proto.init = function(config={}) { map_theme }) .then(project => { - // set current project - this.setCurrentProject(project); + /** @deprecated since v3.5 */ + this.setCurrentProject(project); // set current project + this.initialized = true; d.resolve(project); }) @@ -188,8 +202,10 @@ proto.getProject = function(projectGid, options={ reload:false}) { // setupu project relations projectConfig.relations = this._setProjectRelations(projectConfig); this._projectConfigs[projectConfig.gid] = projectConfig; - // instance of Project - this.createProject(projectConfig); + + /** @deprecated since v3.5 */ + this.createProject(projectConfig); // instance of Project + const project = new Project(projectConfig); // add to project d.resolve(project);