2016-03-09 03:31:43 -06:00
|
|
|
define(['angular',
|
2015-03-05 09:52:32 -06:00
|
|
|
'lodash',
|
|
|
|
'require',
|
2015-10-30 08:19:02 -05:00
|
|
|
'app/core/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');
|
|
|
|
|
2016-09-22 04:32:27 -05:00
|
|
|
module.controller('ShareModalCtrl', function($scope, $rootScope, $location, $timeout, timeSrv, templateSrv, linkSrv) {
|
2015-05-08 03:56:54 -05:00
|
|
|
|
2015-04-02 02:21:38 -05:00
|
|
|
$scope.options = { forCurrent: true, includeTemplateVars: true, theme: 'current' };
|
2016-01-29 10:48:57 -06:00
|
|
|
$scope.editor = { index: $scope.tabIndex || 0};
|
2014-09-24 10:15:58 -05:00
|
|
|
|
|
|
|
$scope.init = function() {
|
2015-03-29 08:01:27 -05:00
|
|
|
$scope.modeSharePanel = $scope.panel ? true : false;
|
2014-09-30 07:42:59 -05:00
|
|
|
|
2015-03-29 07:30:03 -05:00
|
|
|
$scope.tabs = [{title: 'Link', src: 'shareLink.html'}];
|
|
|
|
|
2015-03-29 08:01:27 -05:00
|
|
|
if ($scope.modeSharePanel) {
|
2015-03-29 07:30:03 -05:00
|
|
|
$scope.modalTitle = 'Share Panel';
|
|
|
|
$scope.tabs.push({title: 'Embed', src: 'shareEmbed.html'});
|
|
|
|
} else {
|
2016-05-17 14:18:47 -05:00
|
|
|
$scope.modalTitle = 'Share';
|
2015-03-29 08:01:27 -05:00
|
|
|
}
|
|
|
|
|
2016-01-28 17:05:49 -06:00
|
|
|
if (!$scope.dashboard.meta.isSnapshot) {
|
2016-05-17 14:18:47 -05:00
|
|
|
$scope.tabs.push({title: 'Snapshot', src: 'shareSnapshot.html'});
|
|
|
|
}
|
|
|
|
|
2016-11-03 14:32:36 -05:00
|
|
|
if (!$scope.dashboard.meta.isSnapshot && !$scope.modeSharePanel) {
|
2016-05-17 14:18:47 -05:00
|
|
|
$scope.tabs.push({title: 'Export', src: 'shareExport.html'});
|
2015-03-29 07:30:03 -05:00
|
|
|
}
|
|
|
|
|
2014-09-30 07:42:59 -05:00
|
|
|
$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
|
|
|
|
2014-09-30 08:19:48 -05:00
|
|
|
var params = angular.copy($location.search());
|
2014-09-30 07:42:59 -05:00
|
|
|
|
2015-05-28 02:35:47 -05:00
|
|
|
var range = timeSrv.timeRange();
|
2015-09-22 00:32:47 -05:00
|
|
|
params.from = range.from.valueOf();
|
|
|
|
params.to = range.to.valueOf();
|
2014-09-30 07:42:59 -05:00
|
|
|
|
2015-03-17 16:33:31 -05:00
|
|
|
if ($scope.options.includeTemplateVars) {
|
2015-05-08 03:56:54 -05:00
|
|
|
templateSrv.fillVariableValuesForUrl(params);
|
2014-09-30 08:19:48 -05:00
|
|
|
}
|
|
|
|
|
2015-03-17 16:33:31 -05:00
|
|
|
if (!$scope.options.forCurrent) {
|
2014-09-30 07:42:59 -05:00
|
|
|
delete params.from;
|
|
|
|
delete params.to;
|
2014-09-24 10:15:58 -05:00
|
|
|
}
|
2014-09-30 07:42:59 -05:00
|
|
|
|
2015-04-02 02:21:38 -05:00
|
|
|
if ($scope.options.theme !== 'current') {
|
|
|
|
params.theme = $scope.options.theme;
|
|
|
|
}
|
|
|
|
|
2015-03-29 08:01:27 -05:00
|
|
|
if ($scope.modeSharePanel) {
|
2015-02-02 02:45:45 -06:00
|
|
|
params.panelId = $scope.panel.id;
|
2014-09-30 07:42:59 -05:00
|
|
|
params.fullscreen = true;
|
|
|
|
} else {
|
|
|
|
delete params.panelId;
|
|
|
|
delete params.fullscreen;
|
2014-09-24 10:15:58 -05:00
|
|
|
}
|
|
|
|
|
2015-05-08 03:56:54 -05:00
|
|
|
$scope.shareUrl = linkSrv.addParamsToUrl(baseUrl, params);
|
2015-03-05 09:52:32 -06:00
|
|
|
|
2015-03-25 09:48:51 -05:00
|
|
|
var soloUrl = $scope.shareUrl;
|
2016-05-20 01:31:27 -05:00
|
|
|
soloUrl = soloUrl.replace(config.appSubUrl + '/dashboard/', config.appSubUrl + '/dashboard-solo/');
|
2016-06-17 07:03:59 -05:00
|
|
|
soloUrl = soloUrl.replace("&fullscreen", "").replace("&edit", "");
|
2015-03-20 21:01:39 -05:00
|
|
|
|
2015-03-25 09:48:51 -05:00
|
|
|
$scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
|
|
|
|
|
2016-05-20 07:01:12 -05:00
|
|
|
$scope.imageUrl = soloUrl.replace(config.appSubUrl + '/dashboard-solo/', config.appSubUrl + '/render/dashboard-solo/');
|
2015-01-07 09:56:57 -06:00
|
|
|
$scope.imageUrl += '&width=1000';
|
|
|
|
$scope.imageUrl += '&height=500';
|
2014-09-24 10:15:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-03-05 09:52:32 -06:00
|
|
|
module.directive('clipboardButton',function() {
|
|
|
|
return function(scope, elem) {
|
2015-10-30 09:04:27 -05:00
|
|
|
require(['vendor/zero_clipboard'], function(ZeroClipboard) {
|
2015-03-05 13:10:05 -06:00
|
|
|
ZeroClipboard.config({
|
2015-10-30 09:04:27 -05:00
|
|
|
swfPath: config.appSubUrl + '/public/vendor/zero_clipboard.swf'
|
2015-03-05 13:10:05 -06:00
|
|
|
});
|
2015-03-05 09:52:32 -06:00
|
|
|
new ZeroClipboard(elem[0]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2014-09-24 10:15:58 -05:00
|
|
|
});
|