shareModalCtrl.js 3.3 KB

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