feat(preferences): got timezone option to work on org and profile level, as well as dashboard

This commit is contained in:
Torkel Ödegaard
2016-04-03 06:05:43 -07:00
parent cab859a0e4
commit b30b78e442
8 changed files with 23 additions and 13 deletions

View File

@@ -134,6 +134,10 @@ function (angular, $, config, moment) {
});
};
$scope.timezoneChanged = function() {
$rootScope.$broadcast("refresh");
};
$scope.formatDate = function(date) {
return moment(date).format('MMM Do YYYY, h:mm:ss a');
};

View File

@@ -9,7 +9,7 @@ function (angular, $, _, moment) {
var module = angular.module('grafana.services');
module.factory('dashboardSrv', function() {
module.factory('dashboardSrv', function(contextSrv) {
function DashboardModel (data, meta) {
if (!data) {
@@ -25,7 +25,7 @@ function (angular, $, _, moment) {
this.originalTitle = this.title;
this.tags = data.tags || [];
this.style = data.style || "dark";
this.timezone = data.timezone || 'browser';
this.timezone = data.timezone || '';
this.editable = data.editable !== false;
this.hideControls = data.hideControls || false;
this.sharedCrosshair = data.sharedCrosshair || false;
@@ -208,6 +208,14 @@ function (angular, $, _, moment) {
});
};
p.isTimezoneUtc = function() {
return this.getTimezone() === 'utc';
};
p.getTimezone = function() {
return this.timezone ? this.timezone : contextSrv.user.timezone;
};
p._updateSchema = function(old) {
var i, j, k;
var oldVersion = this.schemaVersion;

View File

@@ -34,7 +34,7 @@
<div class="gf-form">
<label class="gf-form-label width-7">Timezone</label>
<div class="gf-form-select-wrapper">
<select ng-model="dashboard.timezone" class='gf-form-input' ng-options="f for f in ['browser','utc']"></select>
<select ng-model="dashboard.timezone" class='gf-form-input' ng-options="f.value as f.text for f in [{value: '', text: 'Default'}, {value: 'browser', text: 'Local browser time'},{value: 'utc', text: 'UTC'}]" ng-change="timezoneChanged()"></select>
</div>
</div>
</div>

View File

@@ -44,7 +44,7 @@ export class TimePickerCtrl {
var time = angular.copy(this.timeSrv.timeRange());
var timeRaw = angular.copy(this.timeSrv.timeRange(false));
if (this.dashboard.timezone === 'browser') {
if (!this.dashboard.isTimezoneUtc()) {
time.from.local();
time.to.local();
if (moment.isMoment(timeRaw.from)) {
@@ -125,7 +125,7 @@ export class TimePickerCtrl {
}
getAbsoluteMomentForTimezone(jsDate) {
return this.dashboard.timezone === 'browser' ? moment(jsDate) : moment(jsDate).utc();
return this.dashboard.isTimezoneUtc() ? moment(jsDate).utc() : moment(jsDate);
}
setRelativeFilter(timespan) {

View File

@@ -2,7 +2,7 @@
import config from 'app/core/config';
import _ from 'lodash';
import coreModule from '../../core/core_module';
import coreModule from 'app/core/core_module';
export class PrefsControlCtrl {
prefs: any;
@@ -42,9 +42,7 @@ export class PrefsControlCtrl {
};
this.backendSrv.put(`/api/${this.mode}/preferences`, cmd).then(() => {
if (this.oldTheme !== cmd.theme) {
window.location.href = config.appSubUrl + this.$location.path();
}
window.location.href = config.appSubUrl + this.$location.path();
});
}

View File

@@ -279,7 +279,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
var max = _.isUndefined(ctrl.range.to) ? null : ctrl.range.to.valueOf();
options.xaxis = {
timezone: dashboard.timezone,
timezone: dashboard.getTimezone(),
show: panel['x-axis'],
mode: "time",
min: min,

View File

@@ -155,7 +155,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
}
function appendTableRows(tbodyElem) {
var renderer = new TableRenderer(panel, data, ctrl.dashboard.timezone);
var renderer = new TableRenderer(panel, data, ctrl.dashboard.isTimezoneUtc());
tbodyElem.empty();
tbodyElem.html(renderer.render(ctrl.pageIndex));
}

View File

@@ -8,7 +8,7 @@ export class TableRenderer {
formaters: any[];
colorState: any;
constructor(private panel, private table, private timezone) {
constructor(private panel, private table, private isUtc) {
this.formaters = [];
this.colorState = {};
}
@@ -45,7 +45,7 @@ export class TableRenderer {
return v => {
if (_.isArray(v)) { v = v[0]; }
var date = moment(v);
if (this.timezone === 'utc') {
if (this.isUtc) {
date = date.utc();
}
return date.format(style.dateFormat);