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

pull/4513/head
Torkel Ödegaard 10 years ago
parent cab859a0e4
commit b30b78e442
  1. 4
      public/app/features/dashboard/dashboardCtrl.js
  2. 12
      public/app/features/dashboard/dashboardSrv.js
  3. 2
      public/app/features/dashboard/partials/settings.html
  4. 4
      public/app/features/dashboard/timepicker/timepicker.ts
  5. 4
      public/app/features/org/prefs_control.ts
  6. 2
      public/app/plugins/panel/graph/graph.js
  7. 2
      public/app/plugins/panel/table/module.ts
  8. 4
      public/app/plugins/panel/table/renderer.ts

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

@ -9,7 +9,7 @@ function (angular, $, _, moment) {
var module = angular.module('grafana.services'); var module = angular.module('grafana.services');
module.factory('dashboardSrv', function() { module.factory('dashboardSrv', function(contextSrv) {
function DashboardModel (data, meta) { function DashboardModel (data, meta) {
if (!data) { if (!data) {
@ -25,7 +25,7 @@ function (angular, $, _, moment) {
this.originalTitle = this.title; this.originalTitle = this.title;
this.tags = data.tags || []; this.tags = data.tags || [];
this.style = data.style || "dark"; this.style = data.style || "dark";
this.timezone = data.timezone || 'browser'; this.timezone = data.timezone || '';
this.editable = data.editable !== false; this.editable = data.editable !== false;
this.hideControls = data.hideControls || false; this.hideControls = data.hideControls || false;
this.sharedCrosshair = data.sharedCrosshair || 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) { p._updateSchema = function(old) {
var i, j, k; var i, j, k;
var oldVersion = this.schemaVersion; var oldVersion = this.schemaVersion;

@ -34,7 +34,7 @@
<div class="gf-form"> <div class="gf-form">
<label class="gf-form-label width-7">Timezone</label> <label class="gf-form-label width-7">Timezone</label>
<div class="gf-form-select-wrapper"> <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> </div>
</div> </div>

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

@ -2,7 +2,7 @@
import config from 'app/core/config'; import config from 'app/core/config';
import _ from 'lodash'; import _ from 'lodash';
import coreModule from '../../core/core_module'; import coreModule from 'app/core/core_module';
export class PrefsControlCtrl { export class PrefsControlCtrl {
prefs: any; prefs: any;
@ -42,9 +42,7 @@ export class PrefsControlCtrl {
}; };
this.backendSrv.put(`/api/${this.mode}/preferences`, cmd).then(() => { 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();
}
}); });
} }

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

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

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

Loading…
Cancel
Save