dashboard_loaders.js 1.6 KB

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