Skip to content

Commit

Permalink
Merge pull request #5516 from camptocamp/GSGMF-1215_submenu-on-theme-…
Browse files Browse the repository at this point in the history
…change

Remove layertree submenu when changing theme
  • Loading branch information
llienher committed Feb 13, 2020
2 parents 3a55c49 + 5b7613c commit 1860197
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
32 changes: 32 additions & 0 deletions contribs/gmf/src/layertree/TreeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ LayertreeTreeManager.prototype.handleThemesChange_ = function() {
* @return {boolean} True if the group has been added. False otherwise.
*/
LayertreeTreeManager.prototype.setFirstLevelGroups = function(firstLevelGroups) {
//Remove existing submenu if opened at theme refresh
this.parseTreeNodes(this.root);

this.root.children.length = 0;
this.ngeoStateManager_.deleteParam(PermalinkParam.TREE_GROUPS);
return this.addFirstLevelGroups(firstLevelGroups);
Expand Down Expand Up @@ -232,6 +235,35 @@ LayertreeTreeManager.prototype.setInitialFirstLevelGroups = function(firstGroups
this.initialLevelFirstGroups_ = firstGroups;
};

/**
* @param {import('gmf/themes.js').GmfGroup | import('gmf/themes.js').GmfLayer | import('gmf/themes.js').GmfRootNode} node Layer tree node to remove.
*/
LayertreeTreeManager.prototype.parseTreeNodes = function(node) {
if (node.children) {
/**
* @param {any} child
*/
node.children.forEach(child => {
this.parseTreeNodes(child);
});
}
if (node.popupId) {
this.removePopup_(node);
}
};


/**
* @param {import('gmf/themes.js').GmfGroup} node Layer tree node to remove.
* @private
*/
LayertreeTreeManager.prototype.removePopup_ = function(node) {
const popupId = node.popupId;
$(`#${popupId}`).remove();
delete node.popupId;
};


/**
* @param {array} array An array of groups.
* @param {number} old_index The old index before reorder (the current one).
Expand Down
33 changes: 2 additions & 31 deletions contribs/gmf/src/layertree/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,46 +805,17 @@ Controller.prototype.tagPopup = function(node) {
* @param {import('gmf/themes.js').GmfGroup} node Layer tree node to remove.
*/
Controller.prototype.removeNode = function(node) {
this.parseTreeNodes(node);
this.gmfTreeManager_.parseTreeNodes(node);
this.gmfTreeManager_.removeGroup(node);
};


Controller.prototype.removeAllNodes = function() {
this.parseTreeNodes(this.root);
this.gmfTreeManager_.parseTreeNodes(this.root);
this.gmfTreeManager_.removeAll();
};


/**
* @param {import('gmf/themes.js').GmfGroup | import('gmf/themes.js').GmfLayer | import('gmf/themes.js').GmfRootNode} node Layer tree node to remove.
*/
Controller.prototype.parseTreeNodes = function(node) {
if (node.children) {
/**
* @param {any} child
*/
node.children.forEach(child => {
this.parseTreeNodes(child);
});
}
if (node.popupId) {
this.removePopup_(node);
}
};


/**
* @param {import('gmf/themes.js').GmfGroup} node Layer tree node to remove.
* @private
*/
Controller.prototype.removePopup_ = function(node) {
const popupId = node.popupId;
$(`#${popupId}`).remove();
delete node.popupId;
};


/**
* @return {number} first level node count.
*/
Expand Down

0 comments on commit 1860197

Please sign in to comment.