grafana/public/app/features/dashboard/shareModalCtrl.js

101 lines
2.9 KiB
JavaScript
Raw Normal View History

2016-03-09 03:31:43 -06:00
define(['angular',
'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');
module.controller('ShareModalCtrl', function($scope, $rootScope, $location, $timeout, timeSrv, templateSrv, linkSrv) {
$scope.options = { forCurrent: true, includeTemplateVars: true, theme: 'current' };
$scope.editor = { index: $scope.tabIndex || 0};
2014-09-24 10:15:58 -05:00
$scope.init = function() {
$scope.modeSharePanel = $scope.panel ? true : false;
2015-03-29 07:30:03 -05:00
$scope.tabs = [{title: 'Link', src: 'shareLink.html'}];
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';
}
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
}
$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.timeRange();
params.from = range.from.valueOf();
params.to = range.to.valueOf();
2015-03-17 16:33:31 -05:00
if ($scope.options.includeTemplateVars) {
templateSrv.fillVariableValuesForUrl(params);
}
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
}
if ($scope.options.theme !== 'current') {
params.theme = $scope.options.theme;
}
if ($scope.modeSharePanel) {
params.panelId = $scope.panel.id;
params.fullscreen = true;
} else {
delete params.panelId;
delete params.fullscreen;
2014-09-24 10:15:58 -05:00
}
$scope.shareUrl = linkSrv.addParamsToUrl(baseUrl, params);
var soloUrl = $scope.shareUrl;
soloUrl = soloUrl.replace(config.appSubUrl + '/dashboard/', config.appSubUrl + '/dashboard-solo/');
soloUrl = soloUrl.replace("&fullscreen", "").replace("&edit", "");
$scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
$scope.imageUrl = soloUrl.replace(config.appSubUrl + '/dashboard-solo/', config.appSubUrl + '/render/dashboard-solo/');
$scope.imageUrl += '&width=1000';
$scope.imageUrl += '&height=500';
2014-09-24 10:15:58 -05: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
});
new ZeroClipboard(elem[0]);
});
};
});
2014-09-24 10:15:58 -05:00
});