shareModalCtrl.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. define(['angular',
  2. 'lodash',
  3. 'jquery',
  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, 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';
  21. }
  22. if (!$scope.dashboard.meta.isSnapshot) {
  23. $scope.tabs.push({title: 'Snapshot', src: 'shareSnapshot.html'});
  24. }
  25. if (!$scope.dashboard.meta.isSnapshot && !$scope.modeSharePanel) {
  26. $scope.tabs.push({title: 'Export', src: 'shareExport.html'});
  27. }
  28. $scope.buildUrl();
  29. };
  30. $scope.buildUrl = function() {
  31. var baseUrl = $location.absUrl();
  32. var queryStart = baseUrl.indexOf('?');
  33. if (queryStart !== -1) {
  34. baseUrl = baseUrl.substring(0, queryStart);
  35. }
  36. var params = angular.copy($location.search());
  37. var range = timeSrv.timeRange();
  38. params.from = range.from.valueOf();
  39. params.to = range.to.valueOf();
  40. if ($scope.options.includeTemplateVars) {
  41. templateSrv.fillVariableValuesForUrl(params);
  42. }
  43. if (!$scope.options.forCurrent) {
  44. delete params.from;
  45. delete params.to;
  46. }
  47. if ($scope.options.theme !== 'current') {
  48. params.theme = $scope.options.theme;
  49. }
  50. if ($scope.modeSharePanel) {
  51. params.panelId = $scope.panel.id;
  52. params.fullscreen = true;
  53. } else {
  54. delete params.panelId;
  55. delete params.fullscreen;
  56. }
  57. $scope.shareUrl = linkSrv.addParamsToUrl(baseUrl, params);
  58. var soloUrl = $scope.shareUrl;
  59. soloUrl = soloUrl.replace(config.appSubUrl + '/dashboard/', config.appSubUrl + '/dashboard-solo/');
  60. soloUrl = soloUrl.replace("&fullscreen", "").replace("&edit", "");
  61. $scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
  62. $scope.imageUrl = soloUrl.replace(config.appSubUrl + '/dashboard-solo/', config.appSubUrl + '/render/dashboard-solo/');
  63. $scope.imageUrl += '&width=1000';
  64. $scope.imageUrl += '&height=500';
  65. };
  66. });
  67. module.directive('clipboardButton',function() {
  68. return function(scope, elem) {
  69. require(['vendor/clipboard/dist/clipboard'], function(Clipboard) {
  70. scope.clipboard = new Clipboard(elem[0]);
  71. });
  72. scope.$on('$destroy', function() {
  73. if (scope.clipboard) {
  74. scope.clipboard.destroy();
  75. }
  76. });
  77. };
  78. });
  79. });