feat(server side png rendering): added timezone parameter for server side rendering, refactoring PR #7264

This commit is contained in:
Torkel Ödegaard
2017-01-31 07:48:10 +01:00
parent 830491fa66
commit 1a9aaa4138
4 changed files with 26 additions and 44 deletions

View File

@@ -69,15 +69,6 @@
</div>
</script>
<script type="text/ng-template" id="renderImageOptions.html">
<div class="gf-form-group">
<gf-form-switch class="gf-form"
label="Use browser time offset in image" label-class="width-18" switch-class="max-width-6"
checked="options.browserTimeOffset" on-change="buildUrl()">
</gf-form-switch>
</div>
</script>
<script type="text/ng-template" id="shareLink.html">
<div class="share-modal-header">
<div class="share-modal-big-icon">
@@ -100,7 +91,6 @@
</div>
</div>
</div>
<div ng-include src="'renderImageOptions.html'"></div>
<div class="gf-form" ng-show="modeSharePanel">
<a href="{{imageUrl}}" target="_blank"><i class="fa fa-camera"></i> Direct link rendered image</a>
</div>

View File

@@ -1,17 +1,18 @@
define(['angular',
'lodash',
'jquery',
'moment',
'require',
'app/core/config',
],
function (angular, _, $, require, config) {
function (angular, _, $, moment, require, config) {
'use strict';
var module = angular.module('grafana.controllers');
module.controller('ShareModalCtrl', function($scope, $rootScope, $location, $timeout, timeSrv, templateSrv, linkSrv) {
$scope.options = { forCurrent: true, includeTemplateVars: true, browserTimeOffset: false, theme: 'current' };
$scope.options = { forCurrent: true, includeTemplateVars: true, theme: 'current' };
$scope.editor = { index: $scope.tabIndex || 0};
$scope.init = function() {
@@ -83,13 +84,7 @@ function (angular, _, $, require, config) {
$scope.imageUrl = soloUrl.replace(config.appSubUrl + '/dashboard-solo/', config.appSubUrl + '/render/dashboard-solo/');
$scope.imageUrl += '&width=1000';
$scope.imageUrl += '&height=500';
if ($scope.options.browserTimeOffset) {
var offsetMinutes = new Date().getTimezoneOffset(); // Negative if ahead of UTC
var sign = offsetMinutes < 0 ? '+' : '-';
var hours = ('0' + Math.abs(offsetMinutes) / 60).slice(-2);
var minutes = ('0' + Math.abs(offsetMinutes) % 60).slice(-2);
$scope.imageUrl += '&timeOffset=' + encodeURIComponent(sign + hours + minutes);
}
$scope.imageUrl += '&tz=UTC' + encodeURIComponent(moment().format("Z"));
};
});