sharePanelCtrl.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. define([
  2. 'angular',
  3. 'lodash',
  4. 'require',
  5. 'config',
  6. ],
  7. function (angular, _, require, config) {
  8. 'use strict';
  9. var module = angular.module('grafana.controllers');
  10. module.controller('SharePanelCtrl', function($scope, $location, $timeout, timeSrv, $element, templateSrv) {
  11. $scope.init = function() {
  12. $scope.editor = { index: 0 };
  13. $scope.options = {
  14. forCurrent: true,
  15. toPanel: $scope.panel ? true : false,
  16. includeTemplateVars: true
  17. };
  18. $scope.buildUrl();
  19. };
  20. $scope.buildUrl = function() {
  21. var baseUrl = $location.absUrl();
  22. var queryStart = baseUrl.indexOf('?');
  23. if (queryStart !== -1) {
  24. baseUrl = baseUrl.substring(0, queryStart);
  25. }
  26. var params = angular.copy($location.search());
  27. var range = timeSrv.timeRangeForUrl();
  28. params.from = range.from;
  29. params.to = range.to;
  30. if ($scope.options.includeTemplateVars) {
  31. _.each(templateSrv.variables, function(variable) {
  32. params['var-' + variable.name] = variable.current.text;
  33. });
  34. }
  35. else {
  36. _.each(templateSrv.variables, function(variable) {
  37. delete params['var-' + variable.name];
  38. });
  39. }
  40. if (!$scope.options.forCurrent) {
  41. delete params.from;
  42. delete params.to;
  43. }
  44. if ($scope.options.toPanel) {
  45. params.panelId = $scope.panel.id;
  46. params.fullscreen = true;
  47. } else {
  48. delete params.panelId;
  49. delete params.fullscreen;
  50. }
  51. var paramsArray = [];
  52. _.each(params, function(value, key) {
  53. if (value === null) { return; }
  54. if (value === true) {
  55. paramsArray.push(key);
  56. } else {
  57. key += '=' + encodeURIComponent(value);
  58. paramsArray.push(key);
  59. }
  60. });
  61. $scope.shareUrl = baseUrl + "?" + paramsArray.join('&');
  62. $scope.soloUrl = $scope.shareUrl.replace('/dashboard/db/', '/dashboard/solo/');
  63. $scope.iframeHtml = '<iframe src="' + $scope.soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
  64. $scope.imageUrl = $scope.shareUrl.replace('/dashboard/db/', '/render/dashboard/solo/');
  65. $scope.imageUrl += '&width=1000';
  66. $scope.imageUrl += '&height=500';
  67. };
  68. $scope.init();
  69. });
  70. module.directive('clipboardButton',function() {
  71. return function(scope, elem) {
  72. require(['ZeroClipboard'], function(ZeroClipboard) {
  73. ZeroClipboard.config({
  74. swfPath: config.appSubUrl + '/public/vendor/ZeroClipboard.swf'
  75. });
  76. new ZeroClipboard(elem[0]);
  77. });
  78. };
  79. });
  80. });