shareModalCtrl.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: $scope.tabIndex || 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.dashboard.meta.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. soloUrl = soloUrl.replace("&fullscreen", "");
  58. $scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
  59. $scope.imageUrl = soloUrl.replace('/dashboard-solo/', '/render/dashboard-solo/');
  60. $scope.imageUrl += '&width=1000';
  61. $scope.imageUrl += '&height=500';
  62. };
  63. });
  64. module.directive('clipboardButton',function() {
  65. return function(scope, elem) {
  66. require(['vendor/zero_clipboard'], function(ZeroClipboard) {
  67. ZeroClipboard.config({
  68. swfPath: config.appSubUrl + '/public/vendor/zero_clipboard.swf'
  69. });
  70. new ZeroClipboard(elem[0]);
  71. });
  72. };
  73. });
  74. });