shareModalCtrl.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. define([
  2. 'angular',
  3. 'lodash',
  4. 'require',
  5. 'config',
  6. ],
  7. function (angular, _, require, config) {
  8. 'use strict';
  9. var module = angular.module('grafana.controllers');
  10. module.controller('ShareModalCtrl', function($scope, $rootScope, $location, $timeout, timeSrv, $element, templateSrv) {
  11. $scope.init = function() {
  12. $scope.editor = { index: 0 };
  13. $scope.options = { forCurrent: true, includeTemplateVars: true };
  14. $scope.modeSharePanel = $scope.panel ? true : false;
  15. $scope.tabs = [{title: 'Link', src: 'shareLink.html'}];
  16. if ($scope.modeSharePanel) {
  17. $scope.modalTitle = 'Share Panel';
  18. $scope.tabs.push({title: 'Embed', src: 'shareEmbed.html'});
  19. } else {
  20. $scope.modalTitle = 'Share Dashboard';
  21. }
  22. if (!$scope.dashboardMeta.isSnapshot) {
  23. $scope.tabs.push({title: 'Snapshot sharing', src: 'shareSnapshot.html'});
  24. }
  25. $scope.buildUrl();
  26. };
  27. $scope.buildUrl = function() {
  28. var baseUrl = $location.absUrl();
  29. var queryStart = baseUrl.indexOf('?');
  30. if (queryStart !== -1) {
  31. baseUrl = baseUrl.substring(0, queryStart);
  32. }
  33. var params = angular.copy($location.search());
  34. var range = timeSrv.timeRangeForUrl();
  35. params.from = range.from;
  36. params.to = range.to;
  37. if ($scope.options.includeTemplateVars) {
  38. _.each(templateSrv.variables, function(variable) {
  39. params['var-' + variable.name] = variable.current.text;
  40. });
  41. }
  42. else {
  43. _.each(templateSrv.variables, function(variable) {
  44. delete params['var-' + variable.name];
  45. });
  46. }
  47. if (!$scope.options.forCurrent) {
  48. delete params.from;
  49. delete params.to;
  50. }
  51. if ($scope.modeSharePanel) {
  52. params.panelId = $scope.panel.id;
  53. params.fullscreen = true;
  54. } else {
  55. delete params.panelId;
  56. delete params.fullscreen;
  57. }
  58. var paramsArray = [];
  59. _.each(params, function(value, key) {
  60. if (value === null) { return; }
  61. if (value === true) {
  62. paramsArray.push(key);
  63. } else {
  64. key += '=' + encodeURIComponent(value);
  65. paramsArray.push(key);
  66. }
  67. });
  68. var queryParams = "?" + paramsArray.join('&');
  69. $scope.shareUrl = baseUrl + queryParams;
  70. var soloUrl = $scope.shareUrl;
  71. soloUrl = soloUrl.replace('/dashboard/db/', '/dashboard/solo/db/');
  72. soloUrl = soloUrl.replace('/dashboard/snapshot/', '/dashboard/solo/snapshot/');
  73. $scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
  74. $scope.imageUrl = soloUrl.replace('/dashboard/', '/render/dashboard/');
  75. $scope.imageUrl += '&width=1000';
  76. $scope.imageUrl += '&height=500';
  77. };
  78. });
  79. module.directive('clipboardButton',function() {
  80. return function(scope, elem) {
  81. require(['ZeroClipboard'], function(ZeroClipboard) {
  82. ZeroClipboard.config({
  83. swfPath: config.appSubUrl + '/public/vendor/ZeroClipboard.swf'
  84. });
  85. new ZeroClipboard(elem[0]);
  86. });
  87. };
  88. });
  89. });