shareModalCtrl.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. define([
  2. 'angular',
  3. 'lodash',
  4. 'require',
  5. 'app/core/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, linkSrv) {
  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.timeRange();
  35. params.from = range.from.valueOf();
  36. params.to = range.to.valueOf();
  37. if ($scope.options.includeTemplateVars) {
  38. templateSrv.fillVariableValuesForUrl(params);
  39. }
  40. if (!$scope.options.forCurrent) {
  41. delete params.from;
  42. delete params.to;
  43. }
  44. if ($scope.options.theme !== 'current') {
  45. params.theme = $scope.options.theme;
  46. }
  47. if ($scope.modeSharePanel) {
  48. params.panelId = $scope.panel.id;
  49. params.fullscreen = true;
  50. } else {
  51. delete params.panelId;
  52. delete params.fullscreen;
  53. }
  54. $scope.shareUrl = linkSrv.addParamsToUrl(baseUrl, params);
  55. var soloUrl = $scope.shareUrl;
  56. soloUrl = soloUrl.replace('/dashboard/', '/dashboard-solo/');
  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. });