|
|
@@ -1,146 +1,148 @@
|
|
|
import config from 'app/core/config';
|
|
|
-import angular from 'angular';
|
|
|
|
|
|
import coreModule from 'app/core/core_module';
|
|
|
+import {PanelContainer} from './dashgrid/PanelContainer';
|
|
|
+import {DashboardModel} from './model';
|
|
|
+import {PanelModel} from './PanelModel';
|
|
|
|
|
|
-export class DashboardCtrl {
|
|
|
+export class DashboardCtrl implements PanelContainer {
|
|
|
+ dashboard: DashboardModel;
|
|
|
+ dashboardViewState: any;
|
|
|
+ loadedFallbackDashboard: boolean;
|
|
|
|
|
|
/** @ngInject */
|
|
|
constructor(
|
|
|
private $scope,
|
|
|
- $rootScope,
|
|
|
- keybindingSrv,
|
|
|
- timeSrv,
|
|
|
- variableSrv,
|
|
|
- alertingSrv,
|
|
|
- dashboardSrv,
|
|
|
- unsavedChangesSrv,
|
|
|
- dynamicDashboardSrv,
|
|
|
- dashboardViewStateSrv,
|
|
|
- panelLoader,
|
|
|
- contextSrv,
|
|
|
- alertSrv,
|
|
|
- $timeout) {
|
|
|
-
|
|
|
- $scope.editor = { index: 0 };
|
|
|
-
|
|
|
- var resizeEventTimeout;
|
|
|
-
|
|
|
- $scope.setupDashboard = function(data) {
|
|
|
- try {
|
|
|
- $scope.setupDashboardInternal(data);
|
|
|
- } catch (err) {
|
|
|
- $scope.onInitFailed(err, 'Dashboard init failed', true);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- $scope.setupDashboardInternal = function(data) {
|
|
|
- var dashboard = dashboardSrv.create(data.dashboard, data.meta);
|
|
|
- dashboardSrv.setCurrent(dashboard);
|
|
|
-
|
|
|
- // init services
|
|
|
- timeSrv.init(dashboard);
|
|
|
- alertingSrv.init(dashboard, data.alerts);
|
|
|
-
|
|
|
- // template values service needs to initialize completely before
|
|
|
- // the rest of the dashboard can load
|
|
|
- variableSrv.init(dashboard)
|
|
|
- // template values failes are non fatal
|
|
|
- .catch($scope.onInitFailed.bind(this, 'Templating init failed', false))
|
|
|
- // continue
|
|
|
- .finally(function() {
|
|
|
- dynamicDashboardSrv.init(dashboard);
|
|
|
- dynamicDashboardSrv.process();
|
|
|
-
|
|
|
- unsavedChangesSrv.init(dashboard, $scope);
|
|
|
-
|
|
|
- $scope.dashboard = dashboard;
|
|
|
- $scope.dashboardMeta = dashboard.meta;
|
|
|
- $scope.dashboardViewState = dashboardViewStateSrv.create($scope);
|
|
|
-
|
|
|
- keybindingSrv.setupDashboardBindings($scope, dashboard);
|
|
|
-
|
|
|
- $scope.dashboard.updateSubmenuVisibility();
|
|
|
- $scope.setWindowTitleAndTheme();
|
|
|
-
|
|
|
- $scope.appEvent("dashboard-initialized", $scope.dashboard);
|
|
|
- })
|
|
|
- .catch($scope.onInitFailed.bind(this, 'Dashboard init failed', true));
|
|
|
- };
|
|
|
-
|
|
|
- $scope.onInitFailed = function(msg, fatal, err) {
|
|
|
- console.log(msg, err);
|
|
|
-
|
|
|
- if (err.data && 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.templateVariableUpdated = function() {
|
|
|
- dynamicDashboardSrv.process();
|
|
|
- };
|
|
|
-
|
|
|
- $scope.setWindowTitleAndTheme = function() {
|
|
|
- window.document.title = config.window_title_prefix + $scope.dashboard.title;
|
|
|
- };
|
|
|
-
|
|
|
- $scope.broadcastRefresh = function() {
|
|
|
- $rootScope.$broadcast('refresh');
|
|
|
- };
|
|
|
-
|
|
|
- $scope.addRowDefault = function() {
|
|
|
- $scope.dashboard.addEmptyRow();
|
|
|
- };
|
|
|
-
|
|
|
- $scope.showJsonEditor = function(evt, options) {
|
|
|
- var editScope = $rootScope.$new();
|
|
|
- editScope.object = options.object;
|
|
|
- editScope.updateHandler = options.updateHandler;
|
|
|
- $scope.appEvent('show-dash-editor', { src: 'public/app/partials/edit_json.html', scope: editScope });
|
|
|
- };
|
|
|
-
|
|
|
- $scope.registerWindowResizeEvent = function() {
|
|
|
- angular.element(window).bind('resize', function() {
|
|
|
- $timeout.cancel(resizeEventTimeout);
|
|
|
- resizeEventTimeout = $timeout(function() { $scope.$broadcast('render'); }, 200);
|
|
|
- });
|
|
|
-
|
|
|
- $scope.$on('$destroy', function() {
|
|
|
- angular.element(window).unbind('resize');
|
|
|
- $scope.dashboard.destroy();
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
- $scope.timezoneChanged = function() {
|
|
|
- $rootScope.$broadcast("refresh");
|
|
|
- };
|
|
|
-
|
|
|
- $scope.onFolderChange = function(folder) {
|
|
|
- $scope.dashboard.folderId = folder.id;
|
|
|
- $scope.dashboard.meta.folderId = folder.id;
|
|
|
- $scope.dashboard.meta.folderTitle= folder.title;
|
|
|
- };
|
|
|
-
|
|
|
- $scope.getPanelLoader = function() {
|
|
|
- return panelLoader;
|
|
|
- };
|
|
|
+ private $rootScope,
|
|
|
+ private keybindingSrv,
|
|
|
+ private timeSrv,
|
|
|
+ private variableSrv,
|
|
|
+ private alertingSrv,
|
|
|
+ private dashboardSrv,
|
|
|
+ private unsavedChangesSrv,
|
|
|
+ private dynamicDashboardSrv,
|
|
|
+ private dashboardViewStateSrv,
|
|
|
+ private panelLoader) {
|
|
|
+ // temp hack due to way dashboards are loaded
|
|
|
+ // can't use controllerAs on route yet
|
|
|
+ $scope.ctrl = this;
|
|
|
+
|
|
|
+ // funcs called from React component bindings and needs this binding
|
|
|
+ this.getPanelContainer = this.getPanelContainer.bind(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ setupDashboard(data) {
|
|
|
+ try {
|
|
|
+ this.setupDashboardInternal(data);
|
|
|
+ } catch (err) {
|
|
|
+ this.onInitFailed(err, 'Dashboard init failed', true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ setupDashboardInternal(data) {
|
|
|
+ const dashboard = this.dashboardSrv.create(data.dashboard, data.meta);
|
|
|
+ this.dashboardSrv.setCurrent(dashboard);
|
|
|
+
|
|
|
+ // init services
|
|
|
+ this.timeSrv.init(dashboard);
|
|
|
+ this.alertingSrv.init(dashboard, data.alerts);
|
|
|
+
|
|
|
+ // template values service needs to initialize completely before
|
|
|
+ // the rest of the dashboard can load
|
|
|
+ this.variableSrv.init(dashboard)
|
|
|
+ // template values failes are non fatal
|
|
|
+ .catch(this.onInitFailed.bind(this, 'Templating init failed', false))
|
|
|
+ // continue
|
|
|
+ .finally(() => {
|
|
|
+ this.dashboard = dashboard;
|
|
|
+
|
|
|
+ this.dynamicDashboardSrv.init(dashboard);
|
|
|
+ this.dynamicDashboardSrv.process();
|
|
|
+
|
|
|
+ this.unsavedChangesSrv.init(dashboard, this.$scope);
|
|
|
+
|
|
|
+ // TODO refactor ViewStateSrv
|
|
|
+ this.$scope.dashboard = dashboard;
|
|
|
+ this.dashboardViewState = this.dashboardViewStateSrv.create(this.$scope);
|
|
|
+
|
|
|
+ this.keybindingSrv.setupDashboardBindings(this.$scope, dashboard);
|
|
|
+
|
|
|
+ this.dashboard.updateSubmenuVisibility();
|
|
|
+ this.setWindowTitleAndTheme();
|
|
|
+
|
|
|
+ this.$scope.appEvent("dashboard-initialized", dashboard);
|
|
|
+ })
|
|
|
+ .catch(this.onInitFailed.bind(this, 'Dashboard init failed', true));
|
|
|
+ }
|
|
|
+
|
|
|
+ onInitFailed(msg, fatal, err) {
|
|
|
+ console.log(msg, err);
|
|
|
+
|
|
|
+ if (err.data && err.data.message) {
|
|
|
+ err.message = err.data.message;
|
|
|
+ } else if (!err.message) {
|
|
|
+ err = {message: err.toString()};
|
|
|
+ }
|
|
|
+
|
|
|
+ this.$scope.appEvent("alert-error", [msg, err.message]);
|
|
|
+
|
|
|
+ // protect against recursive fallbacks
|
|
|
+ if (fatal && !this.loadedFallbackDashboard) {
|
|
|
+ this.loadedFallbackDashboard = true;
|
|
|
+ this.setupDashboard({dashboard: {title: 'Dashboard Init failed'}});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ templateVariableUpdated() {
|
|
|
+ this.dynamicDashboardSrv.process();
|
|
|
+ }
|
|
|
+
|
|
|
+ setWindowTitleAndTheme() {
|
|
|
+ window.document.title = config.window_title_prefix + this.dashboard.title;
|
|
|
+ }
|
|
|
+
|
|
|
+ showJsonEditor(evt, options) {
|
|
|
+ var editScope = this.$rootScope.$new();
|
|
|
+ editScope.object = options.object;
|
|
|
+ editScope.updateHandler = options.updateHandler;
|
|
|
+ this.$scope.appEvent('show-dash-editor', { src: 'public/app/partials/edit_json.html', scope: editScope });
|
|
|
+ }
|
|
|
+
|
|
|
+ getDashboard() {
|
|
|
+ return this.dashboard;
|
|
|
+ }
|
|
|
+
|
|
|
+ getPanelLoader() {
|
|
|
+ return this.panelLoader;
|
|
|
+ }
|
|
|
+
|
|
|
+ getPanels() {
|
|
|
+ return this.dashboard.panels;
|
|
|
+ }
|
|
|
+
|
|
|
+ panelPossitionUpdated(panel: PanelModel) {
|
|
|
+ console.log('panel pos updated', panel);
|
|
|
+ }
|
|
|
+
|
|
|
+ timezoneChanged() {
|
|
|
+ this.$rootScope.$broadcast("refresh");
|
|
|
+ }
|
|
|
+
|
|
|
+ onFolderChange(folder) {
|
|
|
+ this.dashboard.folderId = folder.id;
|
|
|
+ this.dashboard.meta.folderId = folder.id;
|
|
|
+ this.dashboard.meta.folderTitle= folder.title;
|
|
|
+ }
|
|
|
+
|
|
|
+ getPanelContainer() {
|
|
|
+ console.log('DashboardCtrl:getPanelContainer()');
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
init(dashboard) {
|
|
|
this.$scope.onAppEvent('show-json-editor', this.$scope.showJsonEditor);
|
|
|
this.$scope.onAppEvent('template-variable-value-updated', this.$scope.templateVariableUpdated);
|
|
|
- this.$scope.setupDashboard(dashboard);
|
|
|
- this.$scope.registerWindowResizeEvent();
|
|
|
+ this.setupDashboard(dashboard);
|
|
|
}
|
|
|
}
|
|
|
|