2013-09-13 15:52:13 -05:00
|
|
|
define([
|
|
|
|
'angular',
|
2013-12-29 04:46:36 -06:00
|
|
|
'jquery',
|
2013-09-13 15:52:13 -05:00
|
|
|
'config',
|
2014-08-07 07:35:19 -05:00
|
|
|
'lodash',
|
2013-09-13 15:52:13 -05:00
|
|
|
],
|
2015-02-04 04:35:19 -06:00
|
|
|
function (angular, $, config) {
|
2013-09-13 15:52:13 -05:00
|
|
|
"use strict";
|
|
|
|
|
2014-08-13 03:07:32 -05:00
|
|
|
var module = angular.module('grafana.controllers');
|
|
|
|
|
2014-08-16 01:55:05 -05:00
|
|
|
module.controller('DashboardCtrl', function(
|
2014-08-27 08:54:30 -05:00
|
|
|
$scope,
|
|
|
|
$rootScope,
|
|
|
|
dashboardKeybindings,
|
2014-08-27 09:29:48 -05:00
|
|
|
timeSrv,
|
2014-08-27 14:47:41 -05:00
|
|
|
templateValuesSrv,
|
2014-08-27 08:54:30 -05:00
|
|
|
dashboardSrv,
|
|
|
|
dashboardViewStateSrv,
|
2015-03-25 09:48:51 -05:00
|
|
|
contextSrv,
|
2014-08-27 08:54:30 -05:00
|
|
|
$timeout) {
|
2013-10-12 10:08:16 -05:00
|
|
|
|
2014-06-08 07:40:44 -05:00
|
|
|
$scope.editor = { index: 0 };
|
2015-03-28 11:53:52 -05:00
|
|
|
$scope.topNavPartial = 'app/features/dashboard/partials/dashboardTopNav.html';
|
2015-02-04 04:35:19 -06:00
|
|
|
$scope.panels = config.panels;
|
|
|
|
|
2014-08-23 13:23:33 -05:00
|
|
|
var resizeEventTimeout;
|
2014-02-11 02:03:21 -06:00
|
|
|
|
2015-02-02 04:32:00 -06:00
|
|
|
this.init = function(dashboard) {
|
2014-08-23 13:23:33 -05:00
|
|
|
$scope.reset_row();
|
|
|
|
$scope.registerWindowResizeEvent();
|
2014-09-24 03:51:20 -05:00
|
|
|
$scope.onAppEvent('show-json-editor', $scope.showJsonEditor);
|
2015-02-02 04:32:00 -06:00
|
|
|
$scope.setupDashboard(dashboard);
|
2014-08-23 13:23:33 -05:00
|
|
|
};
|
2014-08-20 15:34:51 -05:00
|
|
|
|
2015-03-14 14:29:41 -05:00
|
|
|
$scope.setupDashboard = function(data) {
|
2014-08-14 05:26:06 -05:00
|
|
|
$rootScope.performance.dashboardLoadStart = new Date().getTime();
|
|
|
|
$rootScope.performance.panelsInitialized = 0;
|
2014-09-06 11:05:54 -05:00
|
|
|
$rootScope.performance.panelsRendered = 0;
|
2014-08-14 05:15:46 -05:00
|
|
|
|
2015-03-14 14:29:41 -05:00
|
|
|
var dashboard = dashboardSrv.create(data.model);
|
2014-08-13 03:07:32 -05:00
|
|
|
|
2014-08-28 09:44:16 -05:00
|
|
|
// init services
|
2015-03-14 14:29:41 -05:00
|
|
|
timeSrv.init(dashboard);
|
2014-06-08 08:28:50 -05:00
|
|
|
|
2015-03-14 14:29:41 -05:00
|
|
|
// template values service needs to initialize completely before
|
|
|
|
// the rest of the dashboard can load
|
|
|
|
templateValuesSrv.init(dashboard).then(function() {
|
|
|
|
$scope.dashboard = dashboard;
|
|
|
|
$scope.dashboardViewState = dashboardViewStateSrv.create($scope);
|
2015-03-25 09:48:51 -05:00
|
|
|
$scope.initDashboardMeta(data.meta, $scope.dashboard);
|
2014-06-12 06:37:40 -05:00
|
|
|
|
2015-03-14 14:29:41 -05:00
|
|
|
dashboardKeybindings.shortcuts($scope);
|
2014-09-05 00:02:59 -05:00
|
|
|
|
2015-03-14 14:29:41 -05:00
|
|
|
$scope.updateSubmenuVisibility();
|
|
|
|
$scope.setWindowTitleAndTheme();
|
|
|
|
|
|
|
|
$scope.appEvent("dashboard-loaded", $scope.dashboard);
|
|
|
|
});
|
2013-12-29 04:46:36 -06:00
|
|
|
};
|
|
|
|
|
2015-03-28 15:04:38 -05:00
|
|
|
$scope.initDashboardMeta = function(meta) {
|
2015-03-25 09:48:51 -05:00
|
|
|
meta.canShare = true;
|
|
|
|
meta.canSave = true;
|
|
|
|
meta.canEdit = true;
|
|
|
|
meta.canStar = true;
|
|
|
|
|
|
|
|
if (contextSrv.hasRole('Viewer')) {
|
|
|
|
meta.canSave = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meta.isHome) {
|
|
|
|
meta.canShare = false;
|
|
|
|
meta.canStar = false;
|
|
|
|
meta.canSave = false;
|
|
|
|
meta.canEdit = false;
|
|
|
|
}
|
|
|
|
|
2015-03-28 15:04:38 -05:00
|
|
|
if (meta.isSnapshot) {
|
2015-03-28 11:53:52 -05:00
|
|
|
$scope.topNavPartial = 'app/features/dashboard/partials/snapshotTopNav.html';
|
2015-03-25 09:48:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.dashboardMeta = meta;
|
|
|
|
};
|
|
|
|
|
2015-02-20 05:20:10 -06:00
|
|
|
$scope.updateSubmenuVisibility = function() {
|
|
|
|
$scope.submenuEnabled = $scope.dashboard.hasTemplateVarsOrAnnotations();
|
|
|
|
};
|
|
|
|
|
2014-08-28 09:44:16 -05:00
|
|
|
$scope.setWindowTitleAndTheme = function() {
|
|
|
|
window.document.title = config.window_title_prefix + $scope.dashboard.title;
|
2013-09-26 17:42:43 -05:00
|
|
|
};
|
|
|
|
|
2015-02-22 01:09:58 -06:00
|
|
|
$scope.broadcastRefresh = function() {
|
|
|
|
$rootScope.$broadcast('refresh');
|
|
|
|
};
|
|
|
|
|
2014-05-25 14:03:53 -05:00
|
|
|
$scope.add_row = function(dash, row) {
|
2013-09-13 15:52:13 -05:00
|
|
|
dash.rows.push(row);
|
|
|
|
};
|
|
|
|
|
2014-06-06 11:30:15 -05:00
|
|
|
$scope.add_row_default = function() {
|
|
|
|
$scope.reset_row();
|
|
|
|
$scope.row.title = 'New row';
|
2014-06-07 14:00:05 -05:00
|
|
|
$scope.add_row($scope.dashboard, $scope.row);
|
2014-06-06 11:30:15 -05:00
|
|
|
};
|
|
|
|
|
2013-09-13 15:52:13 -05:00
|
|
|
$scope.reset_row = function() {
|
|
|
|
$scope.row = {
|
|
|
|
title: '',
|
2014-06-06 09:05:56 -05:00
|
|
|
height: '250px',
|
2013-09-13 15:52:13 -05:00
|
|
|
editable: true,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-10-14 15:57:33 -05:00
|
|
|
$scope.panelEditorPath = function(type) {
|
|
|
|
return 'app/' + config.panels[type].path + '/editor.html';
|
2013-09-13 15:52:13 -05:00
|
|
|
};
|
|
|
|
|
2014-10-14 15:57:33 -05:00
|
|
|
$scope.pulldownEditorPath = function(type) {
|
|
|
|
return 'app/panels/'+type+'/editor.html';
|
2014-09-09 04:35:29 -05:00
|
|
|
};
|
|
|
|
|
2014-09-03 04:15:01 -05:00
|
|
|
$scope.showJsonEditor = function(evt, options) {
|
|
|
|
var editScope = $rootScope.$new();
|
|
|
|
editScope.object = options.object;
|
|
|
|
editScope.updateHandler = options.updateHandler;
|
2014-09-24 09:26:39 -05:00
|
|
|
$scope.appEvent('show-dash-editor', { src: 'app/partials/edit_json.html', scope: editScope });
|
2014-09-03 04:15:01 -05:00
|
|
|
};
|
|
|
|
|
2014-10-09 19:30:23 -05:00
|
|
|
$scope.onDrop = function(panelId, row, dropTarget) {
|
|
|
|
var info = $scope.dashboard.getPanelInfoById(panelId);
|
|
|
|
if (dropTarget) {
|
|
|
|
var dropInfo = $scope.dashboard.getPanelInfoById(dropTarget.id);
|
|
|
|
dropInfo.row.panels[dropInfo.index] = info.panel;
|
|
|
|
info.row.panels[info.index] = dropTarget;
|
|
|
|
var dragSpan = info.panel.span;
|
|
|
|
info.panel.span = dropTarget.span;
|
|
|
|
dropTarget.span = dragSpan;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
info.row.panels.splice(info.index, 1);
|
|
|
|
info.panel.span = 12 - $scope.dashboard.rowSpan(row);
|
|
|
|
row.panels.push(info.panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
$rootScope.$broadcast('render');
|
|
|
|
};
|
|
|
|
|
2015-03-05 03:42:46 -06:00
|
|
|
$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');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-09-13 15:52:13 -05:00
|
|
|
});
|
2015-03-25 09:48:51 -05:00
|
|
|
|
2014-05-15 08:04:23 -05:00
|
|
|
});
|