|
@@ -31,41 +31,59 @@ export class DashboardCtrl {
|
|
|
|
|
|
|
|
$scope.setupDashboard = function(data) {
|
|
$scope.setupDashboard = function(data) {
|
|
|
try {
|
|
try {
|
|
|
- var dashboard = dashboardSrv.create(data.dashboard, data.meta);
|
|
|
|
|
- dashboardSrv.setCurrent(dashboard);
|
|
|
|
|
|
|
+ $scope.setupDashboardInternal(data);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ $scope.onInitFailed(err, 'Dashboard init failed', true);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- // init services
|
|
|
|
|
- timeSrv.init(dashboard);
|
|
|
|
|
|
|
+ $scope.setupDashboardInternal = function(data) {
|
|
|
|
|
+ var dashboard = dashboardSrv.create(data.dashboard, data.meta);
|
|
|
|
|
+ dashboardSrv.setCurrent(dashboard);
|
|
|
|
|
|
|
|
- // template values service needs to initialize completely before
|
|
|
|
|
- // the rest of the dashboard can load
|
|
|
|
|
- templateValuesSrv.init(dashboard).finally(function() {
|
|
|
|
|
- dynamicDashboardSrv.init(dashboard);
|
|
|
|
|
|
|
+ // init services
|
|
|
|
|
+ timeSrv.init(dashboard);
|
|
|
|
|
|
|
|
- unsavedChangesSrv.init(dashboard, $scope);
|
|
|
|
|
|
|
+ // template values service needs to initialize completely before
|
|
|
|
|
+ // the rest of the dashboard can load
|
|
|
|
|
+ templateValuesSrv.init(dashboard)
|
|
|
|
|
+ // template values failes are non fatal
|
|
|
|
|
+ .catch($scope.onInitFailed.bind(this, 'Templating init failed', false))
|
|
|
|
|
+ // continue
|
|
|
|
|
+ .finally(function() {
|
|
|
|
|
+ dynamicDashboardSrv.init(dashboard);
|
|
|
|
|
+ unsavedChangesSrv.init(dashboard, $scope);
|
|
|
|
|
|
|
|
- $scope.dashboard = dashboard;
|
|
|
|
|
- $scope.dashboardMeta = dashboard.meta;
|
|
|
|
|
- $scope.dashboardViewState = dashboardViewStateSrv.create($scope);
|
|
|
|
|
|
|
+ $scope.dashboard = dashboard;
|
|
|
|
|
+ $scope.dashboardMeta = dashboard.meta;
|
|
|
|
|
+ $scope.dashboardViewState = dashboardViewStateSrv.create($scope);
|
|
|
|
|
|
|
|
- dashboardKeybindings.shortcuts($scope);
|
|
|
|
|
|
|
+ dashboardKeybindings.shortcuts($scope);
|
|
|
|
|
|
|
|
- $scope.updateSubmenuVisibility();
|
|
|
|
|
- $scope.setWindowTitleAndTheme();
|
|
|
|
|
|
|
+ $scope.updateSubmenuVisibility();
|
|
|
|
|
+ $scope.setWindowTitleAndTheme();
|
|
|
|
|
|
|
|
- $scope.appEvent("dashboard-initialized", $scope.dashboard);
|
|
|
|
|
- }).catch($scope.dashboardInitError.bind(this));
|
|
|
|
|
- } catch (err) {
|
|
|
|
|
- $scope.dashboardInitError(err);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $scope.appEvent("dashboard-initialized", $scope.dashboard);
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch($scope.onInitFailed.bind(this, 'Dashboard init failed', true));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- $scope.dashboardInitError = function(err) {
|
|
|
|
|
- console.log('Dashboard init failed', err);
|
|
|
|
|
|
|
+ $scope.onInitFailed = function(msg, fatal, err) {
|
|
|
|
|
+ console.log(msg, err);
|
|
|
|
|
+
|
|
|
if (err.data && err.data.message) {
|
|
if (err.data && err.data.message) {
|
|
|
err.message = err.data.message;
|
|
err.message = err.data.message;
|
|
|
|
|
+ } else if (!err.message) {
|
|
|
|
|
+ err = {message: err.toString()};
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $scope.appEvent("alert-error", [msg, err.message]);
|
|
|
|
|
+
|
|
|
|
|
+ // protect against recursive fallbacks
|
|
|
|
|
+ if (fatal && !$scope.loadedFallbackDashboard) {
|
|
|
|
|
+ $scope.loadedFallbackDashboard = true;
|
|
|
|
|
+ $scope.setupDashboard({dashboard: {title: 'Dashboard Init failed'}});
|
|
|
}
|
|
}
|
|
|
- $scope.appEvent("alert-error", ['Dashboard init failed', err.message]);
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
$scope.templateVariableUpdated = function() {
|
|
$scope.templateVariableUpdated = function() {
|