///
import config from 'app/core/config';
import _ from 'lodash';
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; }
var 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();
});
}
}
var template = `
`;
export function prefsControlDirective() {
return {
restrict: 'E',
controller: PrefsControlCtrl,
bindToController: true,
controllerAs: 'ctrl',
template: template,
scope: {
mode: "@"
}
};
}
coreModule.directive('prefsControl', prefsControlDirective);