2017-12-20 05:33:33 -06:00
|
|
|
import config from 'app/core/config';
|
|
|
|
import coreModule from 'app/core/core_module';
|
2016-04-02 15:54:06 -05:00
|
|
|
|
|
|
|
export class PrefsControlCtrl {
|
|
|
|
prefs: any;
|
|
|
|
oldTheme: any;
|
|
|
|
prefsForm: any;
|
|
|
|
mode: string;
|
|
|
|
|
|
|
|
timezones: any = [
|
2017-12-20 05:33:33 -06:00
|
|
|
{ value: '', text: 'Default' },
|
|
|
|
{ value: 'browser', text: 'Local browser time' },
|
|
|
|
{ value: 'utc', text: 'UTC' },
|
2016-04-02 15:54:06 -05:00
|
|
|
];
|
2017-12-21 01:39:31 -06:00
|
|
|
themes: any = [{ value: '', text: 'Default' }, { value: 'dark', text: 'Dark' }, { value: 'light', text: 'Light' }];
|
2016-04-02 15:54:06 -05:00
|
|
|
|
2018-08-31 09:40:43 -05:00
|
|
|
/** @ngInject */
|
2017-12-19 09:06:54 -06:00
|
|
|
constructor(private backendSrv, private $location) {}
|
2016-04-02 15:54:06 -05:00
|
|
|
|
|
|
|
$onInit() {
|
|
|
|
return this.backendSrv.get(`/api/${this.mode}/preferences`).then(prefs => {
|
|
|
|
this.prefs = prefs;
|
|
|
|
this.oldTheme = prefs.theme;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
updatePrefs() {
|
2017-12-19 09:06:54 -06:00
|
|
|
if (!this.prefsForm.$valid) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-02 15:54:06 -05:00
|
|
|
|
2018-08-26 13:19:23 -05:00
|
|
|
const cmd = {
|
2016-04-02 15:54:06 -05:00
|
|
|
theme: this.prefs.theme,
|
|
|
|
timezone: this.prefs.timezone,
|
2017-12-20 05:33:33 -06:00
|
|
|
homeDashboardId: this.prefs.homeDashboardId,
|
2016-04-02 15:54:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
this.backendSrv.put(`/api/${this.mode}/preferences`, cmd).then(() => {
|
2016-04-03 08:05:43 -05:00
|
|
|
window.location.href = config.appSubUrl + this.$location.path();
|
2016-04-02 15:54:06 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-26 13:19:23 -05:00
|
|
|
const template = `
|
2016-04-15 18:56:39 -05:00
|
|
|
<form name="ctrl.prefsForm" class="section gf-form-group">
|
2017-12-01 06:49:15 -06:00
|
|
|
<h3 class="page-heading">Preferences</h3>
|
2016-04-02 15:54:06 -05:00
|
|
|
|
|
|
|
<div class="gf-form">
|
2017-10-11 04:17:42 -05:00
|
|
|
<span class="gf-form-label width-11">UI Theme</span>
|
2016-04-02 15:54:06 -05:00
|
|
|
<div class="gf-form-select-wrapper max-width-20">
|
|
|
|
<select class="gf-form-input" ng-model="ctrl.prefs.theme" ng-options="f.value as f.text for f in ctrl.themes"></select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="gf-form">
|
2017-10-11 04:17:42 -05:00
|
|
|
<span class="gf-form-label width-11">
|
2017-10-07 03:31:39 -05:00
|
|
|
Home Dashboard
|
|
|
|
<info-popover mode="right-normal">
|
|
|
|
Not finding dashboard you want? Star it first, then it should appear in this select box.
|
|
|
|
</info-popover>
|
|
|
|
</span>
|
|
|
|
<dashboard-selector class="gf-form-select-wrapper max-width-20" model="ctrl.prefs.homeDashboardId">
|
2016-04-02 15:54:06 -05:00
|
|
|
</dashboard-selector>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="gf-form">
|
2017-10-11 04:17:42 -05:00
|
|
|
<label class="gf-form-label width-11">Timezone</label>
|
2016-04-02 15:54:06 -05:00
|
|
|
<div class="gf-form-select-wrapper max-width-20">
|
|
|
|
<select class="gf-form-input" ng-model="ctrl.prefs.timezone" ng-options="f.value as f.text for f in ctrl.timezones"></select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="gf-form-button-row">
|
2017-08-20 14:16:40 -05:00
|
|
|
<button type="submit" class="btn btn-success" ng-click="ctrl.updatePrefs()">Save</button>
|
2016-04-02 15:54:06 -05:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
`;
|
|
|
|
|
|
|
|
export function prefsControlDirective() {
|
|
|
|
return {
|
2017-12-20 05:33:33 -06:00
|
|
|
restrict: 'E',
|
2016-04-02 15:54:06 -05:00
|
|
|
controller: PrefsControlCtrl,
|
|
|
|
bindToController: true,
|
2017-12-20 05:33:33 -06:00
|
|
|
controllerAs: 'ctrl',
|
2016-04-02 15:54:06 -05:00
|
|
|
template: template,
|
|
|
|
scope: {
|
2017-12-20 05:33:33 -06:00
|
|
|
mode: '@',
|
|
|
|
},
|
2016-04-02 15:54:06 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.directive('prefsControl', prefsControlDirective);
|