2017-12-20 05:33:33 -06:00
|
|
|
import angular from 'angular';
|
|
|
|
import moment from 'moment';
|
|
|
|
import config from 'app/core/config';
|
2014-09-24 10:15:58 -05:00
|
|
|
|
2017-11-24 05:59:36 -06:00
|
|
|
export class ShareModalCtrl {
|
|
|
|
/** @ngInject */
|
2017-12-21 01:39:31 -06:00
|
|
|
constructor($scope, $rootScope, $location, $timeout, timeSrv, templateSrv, linkSrv) {
|
2017-12-19 09:06:54 -06:00
|
|
|
$scope.options = {
|
|
|
|
forCurrent: true,
|
|
|
|
includeTemplateVars: true,
|
2017-12-20 05:33:33 -06:00
|
|
|
theme: 'current',
|
2017-12-19 09:06:54 -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
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
$scope.tabs = [{ title: 'Link', src: 'shareLink.html' }];
|
2015-03-29 07:30:03 -05:00
|
|
|
|
2015-03-29 08:01:27 -05:00
|
|
|
if ($scope.modeSharePanel) {
|
2017-12-20 05:33:33 -06:00
|
|
|
$scope.modalTitle = 'Share Panel';
|
|
|
|
$scope.tabs.push({ title: 'Embed', src: 'shareEmbed.html' });
|
2015-03-29 07:30:03 -05:00
|
|
|
} else {
|
2017-12-20 05:33:33 -06: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) {
|
2017-12-20 05:33:33 -06:00
|
|
|
$scope.tabs.push({ title: 'Snapshot', src: 'shareSnapshot.html' });
|
2016-05-17 14:18:47 -05:00
|
|
|
}
|
|
|
|
|
2016-11-03 14:32:36 -05:00
|
|
|
if (!$scope.dashboard.meta.isSnapshot && !$scope.modeSharePanel) {
|
2017-12-20 05:33:33 -06: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();
|
2017-12-20 05:33:33 -06:00
|
|
|
var queryStart = baseUrl.indexOf('?');
|
2014-09-30 07:42:59 -05:00
|
|
|
|
|
|
|
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();
|
2017-02-22 06:56:04 -06:00
|
|
|
params.orgId = config.bootData.user.orgId;
|
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
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
if ($scope.options.theme !== 'current') {
|
2015-04-02 02:21:38 -05:00
|
|
|
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
|
|
|
|
2018-01-31 07:07:49 -06:00
|
|
|
var soloUrl = baseUrl.replace(config.appSubUrl + '/dashboard/', config.appSubUrl + '/dashboard-solo/');
|
|
|
|
soloUrl = soloUrl.replace(config.appSubUrl + '/d/', config.appSubUrl + '/d-solo/');
|
2017-03-13 03:31:59 -05:00
|
|
|
delete params.fullscreen;
|
|
|
|
delete params.edit;
|
|
|
|
soloUrl = linkSrv.addParamsToUrl(soloUrl, params);
|
2015-03-20 21:01:39 -05:00
|
|
|
|
2017-12-21 01:39:31 -06:00
|
|
|
$scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
|
2017-12-19 09:06:54 -06:00
|
|
|
|
2018-01-31 07:07:49 -06:00
|
|
|
$scope.imageUrl = soloUrl.replace(
|
|
|
|
config.appSubUrl + '/dashboard-solo/',
|
|
|
|
config.appSubUrl + '/render/dashboard-solo/'
|
|
|
|
);
|
|
|
|
$scope.imageUrl = $scope.imageUrl.replace(config.appSubUrl + '/d-solo/', config.appSubUrl + '/render/d-solo/');
|
2017-12-20 05:33:33 -06:00
|
|
|
$scope.imageUrl += '&width=1000';
|
|
|
|
$scope.imageUrl += '&height=500';
|
|
|
|
$scope.imageUrl += '&tz=UTC' + encodeURIComponent(moment().format('Z'));
|
2014-09-24 10:15:58 -05:00
|
|
|
};
|
|
|
|
|
2017-05-20 07:52:28 -05:00
|
|
|
$scope.getShareUrl = function() {
|
|
|
|
return $scope.shareUrl;
|
|
|
|
};
|
2017-11-24 05:59:36 -06:00
|
|
|
}
|
|
|
|
}
|
2017-05-20 07:52:28 -05:00
|
|
|
|
2017-12-21 01:39:31 -06:00
|
|
|
angular.module('grafana.controllers').controller('ShareModalCtrl', ShareModalCtrl);
|