dashboard_loaders.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import coreModule from '../core_module';
  2. export class LoadDashboardCtrl {
  3. /** @ngInject */
  4. constructor($scope, $routeParams, dashboardLoaderSrv, backendSrv, $location) {
  5. $scope.appEvent('dashboard-fetch-start');
  6. if (!$routeParams.slug) {
  7. backendSrv.get('/api/dashboards/home').then(function(homeDash) {
  8. if (homeDash.redirectUri) {
  9. $location.path('dashboard/' + homeDash.redirectUri);
  10. } else {
  11. var meta = homeDash.meta;
  12. meta.canSave = meta.canShare = meta.canStar = false;
  13. $scope.initDashboard(homeDash, $scope);
  14. }
  15. });
  16. return;
  17. }
  18. dashboardLoaderSrv
  19. .loadDashboard($routeParams.type, $routeParams.slug)
  20. .then(function(result) {
  21. if ($routeParams.keepRows) {
  22. result.meta.keepRows = true;
  23. }
  24. $scope.initDashboard(result, $scope);
  25. });
  26. }
  27. }
  28. export class NewDashboardCtrl {
  29. /** @ngInject */
  30. constructor($scope, $routeParams) {
  31. $scope.initDashboard(
  32. {
  33. meta: { canStar: false, canShare: false, isNew: true },
  34. dashboard: {
  35. title: 'New dashboard',
  36. panels: [
  37. {
  38. type: 'add-panel',
  39. gridPos: { x: 0, y: 0, w: 12, h: 9 },
  40. title: 'Panel Title',
  41. },
  42. ],
  43. folderId: Number($routeParams.folderId),
  44. },
  45. },
  46. $scope
  47. );
  48. }
  49. }
  50. coreModule.controller('LoadDashboardCtrl', LoadDashboardCtrl);
  51. coreModule.controller('NewDashboardCtrl', NewDashboardCtrl);