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',
|
2014-05-15 08:04:23 -05:00
|
|
|
'services/all',
|
2013-09-13 15:52:13 -05:00
|
|
|
],
|
2013-12-29 04:46:36 -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-13 05:16:37 -05:00
|
|
|
$scope, $rootScope, dashboardKeybindings,
|
|
|
|
filterSrv, dashboardSrv, dashboardViewStateSrv,
|
2014-08-20 15:34:51 -05:00
|
|
|
panelMoveSrv, timer, $timeout) {
|
2013-10-12 10:08:16 -05:00
|
|
|
|
2014-06-08 07:40:44 -05:00
|
|
|
$scope.editor = { index: 0 };
|
2014-08-06 03:39:27 -05:00
|
|
|
$scope.panelNames = config.panels;
|
2014-02-11 02:03:21 -06:00
|
|
|
|
2013-09-13 15:52:13 -05:00
|
|
|
$scope.init = function() {
|
2014-06-08 13:46:30 -05:00
|
|
|
$scope.availablePanels = config.panels;
|
2014-06-12 06:37:40 -05:00
|
|
|
$scope.onAppEvent('setup-dashboard', $scope.setupDashboard);
|
2014-08-20 15:34:51 -05:00
|
|
|
|
|
|
|
angular.element(window).bind('resize', function() {
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.$broadcast('render');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-08-23 03:43:37 -05:00
|
|
|
$scope.reset_row();
|
2014-06-08 08:28:50 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.setupDashboard = function(event, dashboardData) {
|
2014-06-08 13:46:30 -05:00
|
|
|
timer.cancel_all();
|
|
|
|
|
2014-08-14 05:26:06 -05:00
|
|
|
$rootScope.performance.dashboardLoadStart = new Date().getTime();
|
|
|
|
$rootScope.performance.panelsInitialized = 0;
|
|
|
|
$rootScope.performance.panelsRendered= 0;
|
2014-08-14 05:15:46 -05:00
|
|
|
|
2014-08-08 06:45:42 -05:00
|
|
|
$scope.dashboard = dashboardSrv.create(dashboardData);
|
2014-08-13 05:16:37 -05:00
|
|
|
$scope.dashboardViewState = dashboardViewStateSrv.create($scope);
|
2014-08-13 03:07:32 -05:00
|
|
|
|
2014-06-22 11:21:38 -05:00
|
|
|
$scope.grafana.style = $scope.dashboard.style;
|
|
|
|
|
2014-06-08 08:28:50 -05:00
|
|
|
$scope.filter = filterSrv;
|
|
|
|
$scope.filter.init($scope.dashboard);
|
|
|
|
|
|
|
|
var panelMove = panelMoveSrv.create($scope.dashboard);
|
|
|
|
|
|
|
|
$scope.panelMoveDrop = panelMove.onDrop;
|
|
|
|
$scope.panelMoveStart = panelMove.onStart;
|
|
|
|
$scope.panelMoveStop = panelMove.onStop;
|
|
|
|
$scope.panelMoveOver = panelMove.onOver;
|
|
|
|
$scope.panelMoveOut = panelMove.onOut;
|
|
|
|
|
2014-06-08 13:46:30 -05:00
|
|
|
window.document.title = 'Grafana - ' + $scope.dashboard.title;
|
|
|
|
|
2014-08-07 00:20:56 -05:00
|
|
|
// start auto refresh
|
|
|
|
if($scope.dashboard.refresh) {
|
|
|
|
$scope.dashboard.set_interval($scope.dashboard.refresh);
|
|
|
|
}
|
|
|
|
|
2014-06-12 06:37:40 -05:00
|
|
|
dashboardKeybindings.shortcuts($scope);
|
|
|
|
|
2014-06-08 08:28:50 -05:00
|
|
|
$scope.emitAppEvent("dashboard-loaded", $scope.dashboard);
|
2013-12-29 04:46:36 -06:00
|
|
|
};
|
|
|
|
|
2013-09-26 17:42:43 -05:00
|
|
|
$scope.isPanel = function(obj) {
|
|
|
|
if(!_.isNull(obj) && !_.isUndefined(obj) && !_.isUndefined(obj.type)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-11-07 15:25:24 -06:00
|
|
|
$scope.panel_path =function(type) {
|
2013-09-13 15:52:13 -05:00
|
|
|
if(type) {
|
2013-11-07 15:25:24 -06:00
|
|
|
return 'app/panels/'+type.replace(".","/");
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.edit_path = function(type) {
|
|
|
|
var p = $scope.panel_path(type);
|
|
|
|
if(p) {
|
|
|
|
return p+'/editor.html';
|
2013-09-13 15:52:13 -05:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.setEditorTabs = function(panelMeta) {
|
|
|
|
$scope.editorTabs = ['General','Panel'];
|
|
|
|
if(!_.isUndefined(panelMeta.editorTabs)) {
|
|
|
|
$scope.editorTabs = _.union($scope.editorTabs,_.pluck(panelMeta.editorTabs,'title'));
|
|
|
|
}
|
|
|
|
return $scope.editorTabs;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.init();
|
|
|
|
});
|
2014-05-15 08:04:23 -05:00
|
|
|
});
|