2017-12-21 04:56:45 -06:00
|
|
|
import coreModule from 'app/core/core_module';
|
2018-02-01 09:30:48 -06:00
|
|
|
import locationUtil from 'app/core/utils/location_util';
|
2015-03-02 15:24:01 -06:00
|
|
|
|
2017-10-26 06:26:03 -05:00
|
|
|
export class LoadDashboardCtrl {
|
|
|
|
/** @ngInject */
|
2018-02-01 09:30:48 -06:00
|
|
|
constructor($scope, $routeParams, dashboardLoaderSrv, backendSrv, $location, $browser) {
|
2017-12-20 05:33:33 -06:00
|
|
|
$scope.appEvent('dashboard-fetch-start');
|
2015-03-02 15:24:01 -06:00
|
|
|
|
2018-01-30 17:26:26 -06:00
|
|
|
if (!$routeParams.uid && !$routeParams.slug) {
|
2017-12-20 05:33:33 -06:00
|
|
|
backendSrv.get('/api/dashboards/home').then(function(homeDash) {
|
2016-03-20 05:52:19 -05:00
|
|
|
if (homeDash.redirectUri) {
|
2018-02-05 03:24:48 -06:00
|
|
|
$location.path(homeDash.redirectUri);
|
2016-03-17 03:38:18 -05:00
|
|
|
} else {
|
2016-03-20 05:52:19 -05:00
|
|
|
var meta = homeDash.meta;
|
|
|
|
meta.canSave = meta.canShare = meta.canStar = false;
|
|
|
|
$scope.initDashboard(homeDash, $scope);
|
2016-03-17 03:38:18 -05:00
|
|
|
}
|
2015-05-12 07:11:30 -05:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-30 17:26:26 -06:00
|
|
|
// if no uid, redirect to new route based on slug
|
2018-01-31 07:07:49 -06:00
|
|
|
if (!($routeParams.type === 'script' || $routeParams.type === 'snapshot') && !$routeParams.uid) {
|
2018-02-21 09:56:34 -06:00
|
|
|
backendSrv.getDashboardBySlug($routeParams.slug).then(res => {
|
2018-01-30 17:26:26 -06:00
|
|
|
if (res) {
|
2018-02-07 07:10:23 -06:00
|
|
|
$location.path(locationUtil.stripBaseFromUrl(res.meta.url)).replace();
|
2018-01-30 17:26:26 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug, $routeParams.uid).then(function(result) {
|
2018-02-05 03:31:53 -06:00
|
|
|
if (result.meta.url) {
|
|
|
|
const url = locationUtil.stripBaseFromUrl(result.meta.url);
|
2018-02-01 09:30:48 -06:00
|
|
|
|
2018-02-05 03:31:53 -06:00
|
|
|
if (url !== $location.path()) {
|
2018-08-13 08:41:15 -05:00
|
|
|
// replace url to not create additional history items and then return so that initDashboard below isn't executed multiple times.
|
2018-02-05 03:31:53 -06:00
|
|
|
$location.path(url).replace();
|
2018-08-13 08:41:15 -05:00
|
|
|
return;
|
2018-02-05 03:31:53 -06:00
|
|
|
}
|
2018-01-31 11:24:47 -06:00
|
|
|
}
|
|
|
|
|
2018-08-05 04:04:12 -05:00
|
|
|
if ($routeParams.autofitpanels) {
|
|
|
|
result.meta.autofitpanels = true;
|
2017-12-21 01:39:31 -06:00
|
|
|
}
|
2018-08-05 04:04:12 -05:00
|
|
|
|
2017-12-21 01:39:31 -06:00
|
|
|
$scope.initDashboard(result, $scope);
|
|
|
|
});
|
2017-10-26 06:26:03 -05:00
|
|
|
}
|
|
|
|
}
|
2015-03-02 15:24:01 -06:00
|
|
|
|
2017-10-26 06:26:03 -05:00
|
|
|
export class NewDashboardCtrl {
|
|
|
|
/** @ngInject */
|
2017-12-11 09:37:40 -06:00
|
|
|
constructor($scope, $routeParams) {
|
2017-12-19 09:06:54 -06:00
|
|
|
$scope.initDashboard(
|
|
|
|
{
|
2017-12-20 14:17:55 -06:00
|
|
|
meta: {
|
|
|
|
canStar: false,
|
|
|
|
canShare: false,
|
|
|
|
isNew: true,
|
|
|
|
folderId: Number($routeParams.folderId),
|
|
|
|
},
|
2017-12-19 09:06:54 -06:00
|
|
|
dashboard: {
|
2017-12-20 05:33:33 -06:00
|
|
|
title: 'New dashboard',
|
2017-12-19 09:06:54 -06:00
|
|
|
panels: [
|
|
|
|
{
|
2017-12-20 05:33:33 -06:00
|
|
|
type: 'add-panel',
|
2017-12-19 09:06:54 -06:00
|
|
|
gridPos: { x: 0, y: 0, w: 12, h: 9 },
|
2017-12-20 05:33:33 -06:00
|
|
|
title: 'Panel Title',
|
|
|
|
},
|
2017-12-19 09:06:54 -06:00
|
|
|
],
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2015-05-12 07:11:30 -05:00
|
|
|
},
|
2017-12-19 09:06:54 -06:00
|
|
|
$scope
|
|
|
|
);
|
2017-10-26 06:26:03 -05:00
|
|
|
}
|
|
|
|
}
|
2015-05-12 07:11:30 -05:00
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.controller('LoadDashboardCtrl', LoadDashboardCtrl);
|
|
|
|
coreModule.controller('NewDashboardCtrl', NewDashboardCtrl);
|