grafana/src/app/features/dashboard/sharePanelCtrl.js

97 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-09-24 10:15:58 -05:00
define([
'angular',
'lodash',
'require',
2015-03-05 13:10:05 -06:00
'config',
2014-09-24 10:15:58 -05:00
],
2015-03-05 13:10:05 -06:00
function (angular, _, require, config) {
2014-09-24 10:15:58 -05:00
'use strict';
var module = angular.module('grafana.controllers');
module.controller('SharePanelCtrl', function($scope, $location, $timeout, timeSrv, $element, templateSrv) {
2014-09-24 10:15:58 -05:00
$scope.init = function() {
$scope.editor = { index: 0 };
2015-03-17 16:33:31 -05:00
$scope.options = {
forCurrent: true,
toPanel: $scope.panel ? true : false,
includeTemplateVars: true
};
$scope.buildUrl();
};
$scope.buildUrl = function() {
var baseUrl = $location.absUrl();
var queryStart = baseUrl.indexOf('?');
if (queryStart !== -1) {
baseUrl = baseUrl.substring(0, queryStart);
}
2014-09-24 10:15:58 -05:00
var params = angular.copy($location.search());
var range = timeSrv.timeRangeForUrl();
params.from = range.from;
params.to = range.to;
2015-03-17 16:33:31 -05:00
if ($scope.options.includeTemplateVars) {
_.each(templateSrv.variables, function(variable) {
params['var-' + variable.name] = variable.current.text;
});
}
else {
_.each(templateSrv.variables, function(variable) {
delete params['var-' + variable.name];
});
}
2015-03-17 16:33:31 -05:00
if (!$scope.options.forCurrent) {
delete params.from;
delete params.to;
2014-09-24 10:15:58 -05:00
}
2015-03-17 16:33:31 -05:00
if ($scope.options.toPanel) {
params.panelId = $scope.panel.id;
params.fullscreen = true;
} else {
delete params.panelId;
delete params.fullscreen;
2014-09-24 10:15:58 -05:00
}
var paramsArray = [];
_.each(params, function(value, key) {
if (value === null) { return; }
if (value === true) {
paramsArray.push(key);
} else {
key += '=' + encodeURIComponent(value);
paramsArray.push(key);
}
});
2014-09-24 10:15:58 -05:00
$scope.shareUrl = baseUrl + "?" + paramsArray.join('&');
$scope.imageUrl = $scope.shareUrl.replace('/dashboard/db/', '/render/dashboard/solo/');
$scope.imageUrl += '&width=1000';
$scope.imageUrl += '&height=500';
2014-09-24 10:15:58 -05:00
};
$scope.init();
});
module.directive('clipboardButton',function() {
return function(scope, elem) {
require(['ZeroClipboard'], function(ZeroClipboard) {
2015-03-05 13:10:05 -06:00
ZeroClipboard.config({
swfPath: config.appSubUrl + '/public/vendor/ZeroClipboard.swf'
2015-03-05 13:10:05 -06:00
});
new ZeroClipboard(elem[0]);
});
};
});
2014-09-24 10:15:58 -05:00
});