sharePanelCtrl.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. define([
  2. 'angular',
  3. 'lodash'
  4. ],
  5. function (angular, _) {
  6. 'use strict';
  7. var module = angular.module('grafana.controllers');
  8. module.controller('SharePanelCtrl', function($scope, $location, $timeout, timeSrv, $element, templateSrv, $routeParams) {
  9. $scope.init = function() {
  10. $scope.editor = { index: 0 };
  11. $scope.forCurrent = true;
  12. $scope.toPanel = true;
  13. $scope.includeTemplateVars = true;
  14. $scope.buildUrl();
  15. };
  16. $scope.buildUrl = function() {
  17. var panelId = $scope.panel.id;
  18. var range = timeSrv.timeRange(false);
  19. var params = angular.copy($location.search());
  20. if (_.isString(range.to) && range.to.indexOf('now')) {
  21. range = timeSrv.timeRange();
  22. }
  23. params.from = range.from;
  24. params.to = range.to;
  25. if (_.isDate(params.from)) { params.from = params.from.getTime(); }
  26. if (_.isDate(params.to)) { params.to = params.to.getTime(); }
  27. if ($scope.includeTemplateVars) {
  28. _.each(templateSrv.variables, function(variable) {
  29. params['var-' + variable.name] = variable.current.text;
  30. });
  31. }
  32. else {
  33. _.each(templateSrv.variables, function(variable) {
  34. delete params['var-' + variable.name];
  35. });
  36. }
  37. if (!$scope.forCurrent) {
  38. delete params.from;
  39. delete params.to;
  40. }
  41. if ($scope.toPanel) {
  42. params.panelId = panelId;
  43. params.fullscreen = true;
  44. } else {
  45. delete params.panelId;
  46. delete params.fullscreen;
  47. }
  48. var paramsArray = [];
  49. _.each(params, function(value, key) {
  50. var str = key;
  51. if (value !== true) {
  52. str += '=' + encodeURIComponent(value);
  53. }
  54. paramsArray.push(str);
  55. });
  56. var baseUrl = 'http://localhost:3000';
  57. $scope.shareUrl = baseUrl + '/dashboard/db/' + $routeParams.id + "?" + paramsArray.join('&') ;
  58. paramsArray.push('width=1000');
  59. paramsArray.push('height=500');
  60. $scope.imageUrl = baseUrl + '/render/dashboard/solo/' + $routeParams.id + '?' + paramsArray.join('&') ;
  61. $timeout(function() {
  62. var input = $element.find('[data-share-panel-url]');
  63. input.focus();
  64. input.select();
  65. }, 10);
  66. };
  67. $scope.init();
  68. });
  69. });