grafana/public/app/core/routes/dashboard_loaders.ts

61 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import coreModule from '../core_module';
export class LoadDashboardCtrl {
/** @ngInject */
constructor($scope, $routeParams, dashboardLoaderSrv, backendSrv, $location) {
2017-12-20 05:33:33 -06:00
$scope.appEvent('dashboard-fetch-start');
if (!$routeParams.slug) {
2017-12-20 05:33:33 -06:00
backendSrv.get('/api/dashboards/home').then(function(homeDash) {
if (homeDash.redirectUri) {
2017-12-20 05:33:33 -06:00
$location.path('dashboard/' + homeDash.redirectUri);
2016-03-17 03:38:18 -05:00
} else {
var meta = homeDash.meta;
meta.canSave = meta.canShare = meta.canStar = false;
$scope.initDashboard(homeDash, $scope);
2016-03-17 03:38:18 -05:00
}
});
return;
}
dashboardLoaderSrv
.loadDashboard($routeParams.type, $routeParams.slug)
.then(function(result) {
if ($routeParams.keepRows) {
result.meta.keepRows = true;
}
$scope.initDashboard(result, $scope);
});
}
}
export class NewDashboardCtrl {
/** @ngInject */
constructor($scope, $routeParams) {
$scope.initDashboard(
{
meta: {
canStar: false,
canShare: false,
isNew: true,
folderId: Number($routeParams.folderId),
},
dashboard: {
2017-12-20 05:33:33 -06:00
title: 'New dashboard',
panels: [
{
2017-12-20 05:33:33 -06:00
type: 'add-panel',
gridPos: { x: 0, y: 0, w: 12, h: 9 },
2017-12-20 05:33:33 -06:00
title: 'Panel Title',
},
],
2017-12-20 05:33:33 -06:00
},
},
$scope
);
}
}
2017-12-20 05:33:33 -06:00
coreModule.controller('LoadDashboardCtrl', LoadDashboardCtrl);
coreModule.controller('NewDashboardCtrl', NewDashboardCtrl);