Skip to content

Commit

Permalink
Deprecate setters ProjectsRegistry~setCurrentProject(project) and `…
Browse files Browse the repository at this point in the history
…ProjectsRegistry~createProject(projectConfig)`

Start addressing: #67

As a result of: #150 we intend to bring the development environment ever closer to the production one.

Related to: #89, #292 and g3w-suite/g3w-suite-docker#79
  • Loading branch information
Raruto committed Feb 7, 2023
1 parent 69fcc81 commit 3460096
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 33 deletions.
3 changes: 3 additions & 0 deletions src/app/core/data/service.js
Original file line number Diff line number Diff line change
@@ -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();
}

Expand Down
3 changes: 3 additions & 0 deletions src/app/core/print/printservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
37 changes: 19 additions & 18 deletions src/app/gui/map/mapservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/app/gui/queryresults/queryresultsservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ function QueryResultsService() {
this.printService = new PrintService();
this._currentLayerIds = [];

/** @deprecated since v3.5 */
ProjectsRegistry.onafter('setCurrentProject', project => {
this._project = project;
this._setRelations(project);
this._setAtlasActions(project);
this.state.download_data = false;
this.plotLayerIds = [];
});

this.unlistenerlayeractionevents = [];
this._actions = {
'zoomto': QueryResultsService.zoomToElement,
Expand Down
5 changes: 4 additions & 1 deletion src/app/gui/wms/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/store/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
28 changes: 22 additions & 6 deletions src/store/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -40,6 +52,7 @@ function ProjectsRegistry() {
//set in first position (map)
MapLayersStoresRegistry.addLayersStore(projectLayersStore, 0);
}

};

this.state = {
Expand Down Expand Up @@ -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);
})
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3460096

Please sign in to comment.