mirror of https://github.com/portainer/portainer
fix(theme): apply theme without saving (#6695)
parent
e1df46b92b
commit
3c98bf9a79
|
@ -13,35 +13,27 @@ export default class ThemeSettingsController {
|
||||||
this.setTheme = this.setTheme.bind(this);
|
this.setTheme = this.setTheme.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Theme Settings Panel */
|
async setTheme(theme) {
|
||||||
async updateTheme() {
|
|
||||||
try {
|
try {
|
||||||
|
if (theme === 'auto' || !theme) {
|
||||||
|
this.ThemeManager.autoTheme();
|
||||||
|
} else {
|
||||||
|
this.ThemeManager.setTheme(theme);
|
||||||
|
}
|
||||||
|
this.state.userTheme = theme;
|
||||||
await this.UserService.updateUserTheme(this.state.userId, this.state.userTheme);
|
await this.UserService.updateUserTheme(this.state.userId, this.state.userTheme);
|
||||||
this.state.themeInProgress = false;
|
|
||||||
this.Notifications.success('Success', 'User theme successfully updated');
|
this.Notifications.success('Success', 'User theme successfully updated');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to update user theme');
|
this.Notifications.error('Failure', err, 'Unable to update user theme');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTheme(theme) {
|
|
||||||
if (theme === 'auto' || !theme) {
|
|
||||||
this.ThemeManager.autoTheme();
|
|
||||||
} else {
|
|
||||||
this.ThemeManager.setTheme(theme);
|
|
||||||
}
|
|
||||||
this.state.themeInProgress = true;
|
|
||||||
this.state.userTheme = theme;
|
|
||||||
}
|
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
return this.$async(async () => {
|
return this.$async(async () => {
|
||||||
this.state = {
|
this.state = {
|
||||||
userId: null,
|
userId: null,
|
||||||
userTheme: '',
|
userTheme: '',
|
||||||
initTheme: '',
|
|
||||||
defaultTheme: 'auto',
|
defaultTheme: 'auto',
|
||||||
themeInProgress: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.state.availableThemes = [
|
this.state.availableThemes = [
|
||||||
|
@ -55,16 +47,9 @@ export default class ThemeSettingsController {
|
||||||
this.state.userId = await this.Authentication.getUserDetails().ID;
|
this.state.userId = await this.Authentication.getUserDetails().ID;
|
||||||
const data = await this.UserService.user(this.state.userId);
|
const data = await this.UserService.user(this.state.userId);
|
||||||
this.state.userTheme = data.UserTheme || this.state.defaultTheme;
|
this.state.userTheme = data.UserTheme || this.state.defaultTheme;
|
||||||
this.state.initTheme = this.state.userTheme;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to get user details');
|
this.Notifications.error('Failure', err, 'Unable to get user details');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$onDestroy() {
|
|
||||||
if (this.state.themeInProgress) {
|
|
||||||
this.ThemeManager.setTheme(this.state.initTheme);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
<form class="theme-panel">
|
<form class="theme-panel">
|
||||||
<!-- Theme Selector-->
|
<!-- Theme Selector-->
|
||||||
<box-selector radio-name="'theme'" value="$ctrl.state.userTheme" options="$ctrl.state.availableThemes" on-change="($ctrl.setTheme)"></box-selector>
|
<box-selector radio-name="'theme'" value="$ctrl.state.userTheme" options="$ctrl.state.availableThemes" on-change="($ctrl.setTheme)"></box-selector>
|
||||||
<button ng-click="$ctrl.updateTheme()" class="btn btn-primary btn-sm">Update theme</button>
|
|
||||||
<!-- !Theme -->
|
<!-- !Theme -->
|
||||||
</form>
|
</form>
|
||||||
</rd-widget-body>
|
</rd-widget-body>
|
||||||
|
|
Loading…
Reference in New Issue