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

Reorder private groups #5093

Merged
merged 1 commit into from
Aug 30, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions contribs/gmf/src/layertree/TreeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ export function LayertreeTreeManager($timeout, $injector, gettextCatalog, ngeoLa
*/
this.ngeoStateManager_ = ngeoStateManager;

/**
* @type {Array.<import('gmf/themes.js').GmfGroup>|undefined}
* @private
*/
this.initialLevelFirstGroups_ = undefined;

/**
* A reference to the OGC servers loaded by the theme service.
* @type {import('gmf/themes.js').GmfOgcServers|null}
Expand Down Expand Up @@ -196,6 +202,22 @@ LayertreeTreeManager.prototype.addFirstLevelGroups = function(firstLevelGroups,
return groupNotAdded.length === 0;
};

/**
* @param {Array.<import('gmf/themes.js').GmfGroup>} firstGroups The groups we add to the layertree
*/
LayertreeTreeManager.prototype.setItintialFirstLevelGroups = function(firstGroups) {
this.initialLevelFirstGroups_ = firstGroups;
};

/**
* @param {array} array An array of groups.
* @param {number} old_index The old index before reorder (the current one).
* @param {number} new_index The new index after reorder.
* @private
*/
LayertreeTreeManager.prototype.reorderChild_ = function(array, old_index, new_index) {
array.splice(new_index, 0, array.splice(old_index, 1)[0]);
};

/**
* Update the application state with the list of first level groups in the tree
Expand Down Expand Up @@ -257,7 +279,20 @@ LayertreeTreeManager.prototype.addFirstLevelGroup_ = function(group) {
// Add each first-level-groups.
this.groupsToAddInThisDigestLoop_.forEach((grp) => {
this.root.children.unshift(grp);

// We reorder the groups now as it has to be done before the permalink to be updated
// initialFirstGroups_ is only defined for user change theme loading
if (this.initialLevelFirstGroups_ !== undefined) {
this.root.children.forEach((group, old_index) => {
const new_index = this.initialLevelFirstGroups_.findIndex(
firstLevelGroup => firstLevelGroup.id === group.id);
if (new_index !== -1 && new_index !== old_index) {
this.reorderChild_(this.root.children, old_index, new_index);
}
});
}
});
this.initialLevelFirstGroups_ = undefined;
//Update the permalink
this.updateTreeGroupsState_(this.root.children);
// Reset the groups and the promise state. Don't reset the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
ng-click="$ctrl.removeDataSource(dataSource)">
<span class="fa fa-trash"></span>
</a>
</span>
</span>
</div>
</li>
</ul>
1 change: 1 addition & 0 deletions contribs/gmf/src/theme/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ ThemeManagerService.prototype.updateCurrentTheme = function(themeName, fallbackT
// In flush mode load current theme private groups
const fallbackTheme = findThemeByName(themes, fallbackThemeName);
if (fallbackTheme) {
this.gmfTreeManager_.setItintialFirstLevelGroups(fallbackTheme.children);
this.gmfTreeManager_.addFirstLevelGroups(fallbackTheme.children, false, opt_silent);
}
}
Expand Down