dashLoadControllers.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. define([
  2. 'angular',
  3. 'lodash',
  4. 'kbn',
  5. 'moment',
  6. 'jquery',
  7. ],
  8. function (angular) {
  9. "use strict";
  10. var module = angular.module('grafana.routes');
  11. module.controller('LoadDashboardCtrl', function($scope, $routeParams, dashboardLoaderSrv, backendSrv) {
  12. if (!$routeParams.slug) {
  13. backendSrv.get('/api/dashboards/home').then(function(result) {
  14. var meta = result.meta;
  15. meta.canSave = meta.canShare = meta.canEdit = meta.canStar = false;
  16. $scope.initDashboard(result, $scope);
  17. });
  18. return;
  19. }
  20. dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug).then(function(result) {
  21. $scope.initDashboard(result, $scope);
  22. });
  23. });
  24. module.controller('DashFromImportCtrl', function($scope, $location, alertSrv) {
  25. if (!window.grafanaImportDashboard) {
  26. alertSrv.set('Not found', 'Cannot reload page with unsaved imported dashboard', 'warning', 7000);
  27. $location.path('');
  28. return;
  29. }
  30. $scope.initDashboard({
  31. meta: { canShare: false, canStar: false },
  32. dashboard: window.grafanaImportDashboard
  33. }, $scope);
  34. });
  35. module.controller('NewDashboardCtrl', function($scope) {
  36. $scope.initDashboard({
  37. meta: { canStar: false, canShare: false },
  38. dashboard: {
  39. title: "New dashboard",
  40. rows: [{ height: '250px', panels:[] }]
  41. },
  42. }, $scope);
  43. });
  44. });