From 69a57850c464a4f0aabe872eff9c92e0782426bd Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Tue, 13 Nov 2018 09:30:28 +0100 Subject: [PATCH] restore user profile preferences --- public/app/features/all.ts | 3 +- .../app/features/profile/PrefControlCtrl.ts | 92 +++++++++++++++++++ public/app/features/profile/all.ts | 3 + 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 public/app/features/profile/PrefControlCtrl.ts create mode 100644 public/app/features/profile/all.ts diff --git a/public/app/features/all.ts b/public/app/features/all.ts index ccdc7d7a820..b1283fdfd3e 100644 --- a/public/app/features/all.ts +++ b/public/app/features/all.ts @@ -10,5 +10,4 @@ import './alerting/NotificationsEditCtrl'; import './alerting/NotificationsListCtrl'; import './manage-dashboards'; import './teams/CreateTeamCtrl'; -import './profile/ProfileCtrl'; -import './profile/ChangePasswordCtrl'; +import './profile/all'; diff --git a/public/app/features/profile/PrefControlCtrl.ts b/public/app/features/profile/PrefControlCtrl.ts new file mode 100644 index 00000000000..74dde250eec --- /dev/null +++ b/public/app/features/profile/PrefControlCtrl.ts @@ -0,0 +1,92 @@ +import config from 'app/core/config'; +import coreModule from 'app/core/core_module'; + +export class PrefsControlCtrl { + prefs: any; + oldTheme: any; + prefsForm: any; + mode: string; + + timezones: any = [ + { value: '', text: 'Default' }, + { value: 'browser', text: 'Local browser time' }, + { value: 'utc', text: 'UTC' }, + ]; + themes: any = [{ value: '', text: 'Default' }, { value: 'dark', text: 'Dark' }, { value: 'light', text: 'Light' }]; + + /** @ngInject */ + constructor(private backendSrv, private $location) {} + + $onInit() { + return this.backendSrv.get(`/api/${this.mode}/preferences`).then(prefs => { + this.prefs = prefs; + this.oldTheme = prefs.theme; + }); + } + + updatePrefs() { + if (!this.prefsForm.$valid) { + return; + } + + const cmd = { + theme: this.prefs.theme, + timezone: this.prefs.timezone, + homeDashboardId: this.prefs.homeDashboardId, + }; + + this.backendSrv.put(`/api/${this.mode}/preferences`, cmd).then(() => { + window.location.href = config.appSubUrl + this.$location.path(); + }); + } +} + +const template = ` +
+

Preferences

+ +
+ UI Theme +
+ +
+
+ +
+ + Home Dashboard + + Not finding dashboard you want? Star it first, then it should appear in this select box. + + + + +
+ +
+ +
+ +
+
+ +
+ +
+
+`; + +export function prefsControlDirective() { + return { + restrict: 'E', + controller: PrefsControlCtrl, + bindToController: true, + controllerAs: 'ctrl', + template: template, + scope: { + mode: '@', + }, + }; +} + +coreModule.directive('prefsControl', prefsControlDirective); diff --git a/public/app/features/profile/all.ts b/public/app/features/profile/all.ts new file mode 100644 index 00000000000..6d462c08e6b --- /dev/null +++ b/public/app/features/profile/all.ts @@ -0,0 +1,3 @@ +import './ProfileCtrl'; +import './ChangePasswordCtrl'; +import './PrefControlCtrl';