Skip to content

Commit

Permalink
In flush mode reload current theme on login
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-morvan committed Apr 11, 2019
1 parent e8c5752 commit 8da1a9d
Show file tree
Hide file tree
Showing 2 changed files with 26 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
24 changes: 24 additions & 0 deletions contribs/gmf/src/theme/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ 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 we reload the current theme
themeName = fallbackThemeName;
}
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 8da1a9d

Please sign in to comment.