|
|
@@ -1,16 +1,11 @@
|
|
|
-// Libaries
|
|
|
-import { StoreState } from 'app/types';
|
|
|
-import { ThunkAction } from 'redux-thunk';
|
|
|
-
|
|
|
// Services & Utils
|
|
|
-import { getBackendSrv } from 'app/core/services/backend_srv';
|
|
|
import { createErrorNotification } from 'app/core/copy/appNotification';
|
|
|
|
|
|
// Actions
|
|
|
import { updateLocation } from 'app/core/actions';
|
|
|
import { notifyApp } from 'app/core/actions';
|
|
|
import locationUtil from 'app/core/utils/location_util';
|
|
|
-import { setDashboardLoadingState, ThunkResult } from './actions';
|
|
|
+import { setDashboardLoadingState, ThunkResult, setDashboardModel } from './actions';
|
|
|
|
|
|
// Types
|
|
|
import { DashboardLoadingState } from 'app/types/dashboard';
|
|
|
@@ -30,41 +25,58 @@ export function initDashboard({ injector, scope, urlUid, urlSlug, urlType }: Ini
|
|
|
|
|
|
dispatch(setDashboardLoadingState(DashboardLoadingState.Fetching));
|
|
|
|
|
|
+ let dashDTO = null;
|
|
|
+
|
|
|
try {
|
|
|
// fetch dashboard from api
|
|
|
- const dashDTO = await loaderSrv.loadDashboard(urlType, urlSlug, urlUid);
|
|
|
- // set initializing state
|
|
|
- dispatch(setDashboardLoadingState(DashboardLoadingState.Initializing));
|
|
|
- // create model
|
|
|
- const dashboard = new DashboardModel(dashDTO.dashboard, dashDTO.meta);
|
|
|
- // init services
|
|
|
+ dashDTO = await loaderSrv.loadDashboard(urlType, urlSlug, urlUid);
|
|
|
+ } catch (err) {
|
|
|
+ dispatch(setDashboardLoadingState(DashboardLoadingState.Error));
|
|
|
+ console.log(err);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- injector.get('timeSrv').init(dashboard);
|
|
|
- injector.get('annotationsSrv').init(dashboard);
|
|
|
+ // set initializing state
|
|
|
+ dispatch(setDashboardLoadingState(DashboardLoadingState.Initializing));
|
|
|
|
|
|
- // template values service needs to initialize completely before
|
|
|
- // the rest of the dashboard can load
|
|
|
- injector.get('variableSrv').init(dashboard)
|
|
|
- .catch(err => {
|
|
|
- dispatch(notifyApp(createErrorNotification('Templating init failed')));
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
+ // create model
|
|
|
+ let dashboard: DashboardModel;
|
|
|
+ try {
|
|
|
+ dashboard = new DashboardModel(dashDTO.dashboard, dashDTO.meta);
|
|
|
+ } catch (err) {
|
|
|
+ dispatch(setDashboardLoadingState(DashboardLoadingState.Error));
|
|
|
+ console.log(err);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- dashboard.processRepeats();
|
|
|
- dashboard.updateSubmenuVisibility();
|
|
|
- dashboard.autoFitPanels(window.innerHeight);
|
|
|
+ // init services
|
|
|
+ injector.get('timeSrv').init(dashboard);
|
|
|
+ injector.get('annotationsSrv').init(dashboard);
|
|
|
|
|
|
- injector.get('unsavedChangesSrv').init(dashboard, scope);
|
|
|
+ // template values service needs to initialize completely before
|
|
|
+ // the rest of the dashboard can load
|
|
|
+ try {
|
|
|
+ await injector.get('variableSrv').init(dashboard);
|
|
|
+ } catch (err) {
|
|
|
+ dispatch(notifyApp(createErrorNotification('Templating init failed', err.toString())));
|
|
|
+ console.log(err);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ dashboard.processRepeats();
|
|
|
+ dashboard.updateSubmenuVisibility();
|
|
|
+ dashboard.autoFitPanels(window.innerHeight);
|
|
|
+
|
|
|
+ injector.get('unsavedChangesSrv').init(dashboard, scope);
|
|
|
|
|
|
- scope.dashboard = dashboard;
|
|
|
- injector.get('dashboardViewStateSrv').create(scope);
|
|
|
- injector.get('keybindingSrv').setupDashboardBindings(scope, dashboard);
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- dispatch(setDashboardLoadingState(DashboardLoadingState.Error));
|
|
|
- });
|
|
|
+ scope.dashboard = dashboard;
|
|
|
+ injector.get('dashboardViewStateSrv').create(scope);
|
|
|
+ injector.get('keybindingSrv').setupDashboardBindings(scope, dashboard);
|
|
|
} catch (err) {
|
|
|
- dispatch(setDashboardLoadingState(DashboardLoadingState.Error));
|
|
|
+ dispatch(notifyApp(createErrorNotification('Dashboard init failed', err.toString())));
|
|
|
+ console.log(err);
|
|
|
}
|
|
|
+
|
|
|
+ dispatch(setDashboardModel(dashboard));
|
|
|
};
|
|
|
}
|