Skip to content

Commit

Permalink
Merge pull request #4817 from camptocamp/GSGMF-858-flush_current_them…
Browse files Browse the repository at this point in the history
…e_on_login

In flush mode load current theme private groups on login
  • Loading branch information
arnaud-morvan authored Apr 16, 2019
2 parents aaa9f61 + 6e0a90a commit f09b85d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
21 changes: 2 additions & 19 deletions contribs/gmf/src/controllers/AbstractAppController.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import olStyleFill from 'ol/style/Fill.js';
import olStyleStroke from 'ol/style/Stroke.js';
import olStyleStyle from 'ol/style/Style.js';
import gmfThemeManager from 'gmf/theme/Manager.js';
import gmfThemeThemes from 'gmf/theme/Themes.js';

/**
* Application abstract controller.
Expand Down Expand Up @@ -191,7 +190,8 @@ const exports = function(config, $scope, $injector) {
this.gmfThemes_.loadThemes(roleId);

if (evt.type !== 'ready') {
this.updateCurrentTheme_(previousThemeName);
const themeName = this.permalink_.defaultThemeNameFromFunctionalities();
this.gmfThemeManager.updateCurrentTheme(themeName, previousThemeName);
}
this.setDefaultBackground_(null);
this.updateHasEditableLayers_();
Expand Down Expand Up @@ -737,23 +737,6 @@ exports.prototype.setDefaultBackground_ = function(theme) {
});
};

/**
* @param {string} fallbackThemeName fallback theme name.
* @private
*/
exports.prototype.updateCurrentTheme_ = function(fallbackThemeName) {
this.gmfThemes_.getThemesObject().then((themes) => {
const themeName = this.permalink_.defaultThemeNameFromFunctionalities();
if (themeName) {
const theme = gmfThemeThemes.findThemeByName(themes, /** @type {string} */ (themeName));
if (theme) {
this.gmfThemeManager.addTheme(theme, true);
}
} else {
this.gmfThemeManager.setThemeName(fallbackThemeName);
}
});
};

/**
* @protected
Expand Down
27 changes: 27 additions & 0 deletions contribs/gmf/src/theme/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,33 @@ exports.prototype.isLoading = function() {
return !this.gmfThemes_.loaded;
};


/**
* @param {string} themeName wanted theme name.
* @param {string} fallbackThemeName fallback theme name.
* @export
*/
exports.prototype.updateCurrentTheme = function(themeName, fallbackThemeName) {
this.gmfThemes_.getThemesObject().then((themes) => {
if (!themeName && this.modeFlush) {
// In flush mode load current theme private groups
const fallbackTheme = gmfThemeThemes.findThemeByName(themes, /** @type {string} */ (fallbackThemeName));
if (fallbackTheme) {
this.gmfTreeManager_.addFirstLevelGroups(fallbackTheme.children, false, false);
}
}
if (themeName) {
const theme = gmfThemeThemes.findThemeByName(themes, /** @type {string} */ (themeName));
if (theme) {
this.addTheme(theme, true);
}
} else {
this.setThemeName(fallbackThemeName);
}
});
};


/**
* @param {string} name The new theme name.
* @param {boolean=} opt_silent Don't emit a theme change event, default is false.
Expand Down

0 comments on commit f09b85d

Please sign in to comment.