Forráskód Böngészése

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

Torkel Ödegaard 9 éve
szülő
commit
b30b78e442

+ 4 - 0
public/app/features/dashboard/dashboardCtrl.js

@@ -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');
     };

+ 10 - 2
public/app/features/dashboard/dashboardSrv.js

@@ -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;

+ 1 - 1
public/app/features/dashboard/partials/settings.html

@@ -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>

+ 2 - 2
public/app/features/dashboard/timepicker/timepicker.ts

@@ -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) {

+ 2 - 4
public/app/features/org/prefs_control.ts

@@ -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();
     });
   }
 

+ 1 - 1
public/app/plugins/panel/graph/graph.js

@@ -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,

+ 1 - 1
public/app/plugins/panel/table/module.ts

@@ -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));
     }

+ 2 - 2
public/app/plugins/panel/table/renderer.ts

@@ -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);