grafana/src/app/controllers/dashboardCtrl.js

123 lines
3.1 KiB
JavaScript
Raw Normal View History

2013-09-13 15:52:13 -05:00
define([
'angular',
'jquery',
2013-09-13 15:52:13 -05:00
'config',
2014-08-07 07:35:19 -05:00
'lodash',
'services/all',
2013-09-13 15:52:13 -05:00
],
function (angular, $, config, _) {
2013-09-13 15:52:13 -05:00
"use strict";
var module = angular.module('grafana.controllers');
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) {
2014-06-08 07:40:44 -05:00
$scope.editor = { index: 0 };
$scope.panelNames = config.panels;
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');
});
});
$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;
$scope.dashboard = dashboardSrv.create(dashboardData);
2014-08-13 05:16:37 -05:00
$scope.dashboardViewState = dashboardViewStateSrv.create($scope);
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;
// 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);
};
$scope.isPanel = function(obj) {
if(!_.isNull(obj) && !_.isUndefined(obj) && !_.isUndefined(obj.type)) {
return true;
} else {
return false;
}
};
$scope.add_row = function(dash, row) {
2013-09-13 15:52:13 -05:00
dash.rows.push(row);
};
$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);
};
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();
});
});