shareModalCtrl.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.options = { forCurrent: true, includeTemplateVars: true, theme: 'current' };
  12. $scope.editor = { index: 0 };
  13. $scope.init = function() {
  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.options.theme !== 'current') {
  52. params.theme = $scope.options.theme;
  53. }
  54. if ($scope.modeSharePanel) {
  55. params.panelId = $scope.panel.id;
  56. params.fullscreen = true;
  57. } else {
  58. delete params.panelId;
  59. delete params.fullscreen;
  60. }
  61. var paramsArray = [];
  62. _.each(params, function(value, key) {
  63. if (value === null) { return; }
  64. if (value === true) {
  65. paramsArray.push(key);
  66. } else {
  67. key += '=' + encodeURIComponent(value);
  68. paramsArray.push(key);
  69. }
  70. });
  71. var queryParams = "?" + paramsArray.join('&');
  72. $scope.shareUrl = baseUrl + queryParams;
  73. var soloUrl = $scope.shareUrl;
  74. soloUrl = soloUrl.replace('/dashboard/db/', '/dashboard/solo/db/');
  75. soloUrl = soloUrl.replace('/dashboard/snapshot/', '/dashboard/solo/snapshot/');
  76. $scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
  77. $scope.imageUrl = soloUrl.replace('/dashboard/', '/render/dashboard/');
  78. $scope.imageUrl += '&width=1000';
  79. $scope.imageUrl += '&height=500';
  80. };
  81. });
  82. module.directive('clipboardButton',function() {
  83. return function(scope, elem) {
  84. require(['ZeroClipboard'], function(ZeroClipboard) {
  85. ZeroClipboard.config({
  86. swfPath: config.appSubUrl + '/public/vendor/ZeroClipboard.swf'
  87. });
  88. new ZeroClipboard(elem[0]);
  89. });
  90. };
  91. });
  92. });