shareSnapshotCtrl.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. define([
  2. 'angular',
  3. ],
  4. function (angular) {
  5. 'use strict';
  6. var module = angular.module('grafana.controllers');
  7. module.controller('ShareSnapshotCtrl', function($scope, $rootScope, $location, backendSrv, $timeout) {
  8. $scope.snapshot = {
  9. name: $scope.dashboard.title
  10. };
  11. $scope.createSnapshot = function(makePublic) {
  12. $scope.dashboard.snapshot = true;
  13. $scope.loading = true;
  14. $rootScope.$broadcast('refresh');
  15. $timeout(function() {
  16. var dash = angular.copy($scope.dashboard);
  17. dash.title = $scope.snapshot.name;
  18. var apiUrl = '/api/snapshots';
  19. if (makePublic) {
  20. apiUrl = 'http://snapshots.raintank.io/api/snapshots';
  21. }
  22. backendSrv.post(apiUrl, {dashboard: dash}).then(function(results) {
  23. $scope.loading = false;
  24. var baseUrl = $location.absUrl().replace($location.url(), "");
  25. if (makePublic) {
  26. baseUrl = 'http://snapshots.raintank.io';
  27. }
  28. $scope.snapshotUrl = baseUrl + '/dashboard/snapshots/' + results.key;
  29. }, function() {
  30. $scope.loading = false;
  31. });
  32. $scope.dashboard.snapshot = false;
  33. $scope.appEvent('dashboard-snapshot-cleanup');
  34. }, 2000);
  35. };
  36. });
  37. });