shareModalCtrl.js 2.7 KB

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