2013-01-26 12:10:28 +08:00
|
|
|
/*jshint globalstrict:true */
|
|
|
|
|
/*global angular:true */
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2013-01-29 03:28:12 +08:00
|
|
|
angular.module('kibana.controllers', [])
|
2013-07-11 01:22:01 +08:00
|
|
|
.controller('DashCtrl', function($scope, $rootScope, $http, $timeout, $route, ejsResource, eventBus, fields, dashboard) {
|
2013-01-26 12:10:28 +08:00
|
|
|
|
2013-02-14 05:51:56 +08:00
|
|
|
var _d = {
|
|
|
|
|
title: "",
|
|
|
|
|
editable: true,
|
|
|
|
|
rows: [],
|
2013-05-14 04:31:59 +08:00
|
|
|
last: null
|
2013-02-14 05:51:56 +08:00
|
|
|
}
|
2013-02-06 05:30:08 +08:00
|
|
|
|
2013-02-14 05:24:32 +08:00
|
|
|
$scope.init = function() {
|
2013-03-01 03:55:59 +08:00
|
|
|
|
2013-02-14 05:24:32 +08:00
|
|
|
$scope.config = config;
|
2013-04-06 01:08:00 +08:00
|
|
|
// Make underscore.js available to views
|
2013-02-14 05:24:32 +08:00
|
|
|
$scope._ = _;
|
2013-04-06 01:08:00 +08:00
|
|
|
|
2013-07-11 01:22:01 +08:00
|
|
|
$scope.dashboard = dashboard;
|
|
|
|
|
|
2013-04-06 01:08:00 +08:00
|
|
|
// Provide a global list of all see fields
|
|
|
|
|
$scope.fields = fields
|
2013-02-14 05:24:32 +08:00
|
|
|
$scope.reset_row();
|
2013-02-16 06:23:04 +08:00
|
|
|
$scope.clear_all_alerts();
|
2013-02-14 05:24:32 +08:00
|
|
|
|
|
|
|
|
var ejs = $scope.ejs = ejsResource(config.elasticsearch);
|
|
|
|
|
}
|
2013-02-02 05:16:55 +08:00
|
|
|
|
2013-07-11 01:22:01 +08:00
|
|
|
$scope.add_row = function(dash,row) {
|
|
|
|
|
dash.rows.push(row);
|
2013-02-14 05:24:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.reset_row = function() {
|
|
|
|
|
$scope.row = {
|
|
|
|
|
title: '',
|
|
|
|
|
height: '150px',
|
|
|
|
|
editable: true,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2013-04-11 07:48:48 +08:00
|
|
|
$scope.row_style = function(row) {
|
|
|
|
|
return { 'min-height': row.collapse ? '5px' : row.height }
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 06:23:04 +08:00
|
|
|
$scope.alert = function(title,text,severity,timeout) {
|
|
|
|
|
var alert = {
|
|
|
|
|
title: title,
|
|
|
|
|
text: text,
|
|
|
|
|
severity: severity || 'info',
|
|
|
|
|
};
|
|
|
|
|
$scope.global_alert.push(alert);
|
|
|
|
|
if (timeout > 0)
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.global_alert = _.without($scope.global_alert,alert)
|
|
|
|
|
}, timeout);
|
|
|
|
|
}
|
2013-02-14 05:24:32 +08:00
|
|
|
|
2013-02-16 06:23:04 +08:00
|
|
|
$scope.clear_alert = function(alert) {
|
|
|
|
|
$scope.global_alert = _.without($scope.global_alert,alert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.clear_all_alerts = function() {
|
|
|
|
|
$scope.global_alert = []
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-06 00:54:29 +08:00
|
|
|
$scope.edit_path = function(type) {
|
|
|
|
|
if(type)
|
|
|
|
|
return 'panels/'+type+'/editor.html';
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-06 03:11:47 +08:00
|
|
|
// This is whoafully incomplete, but will do for now
|
|
|
|
|
$scope.parse_error = function(data) {
|
2013-04-06 04:01:32 +08:00
|
|
|
var _error = data.match("nested: (.*?);")
|
|
|
|
|
return _.isNull(_error) ? data : _error[1];
|
2013-04-06 03:11:47 +08:00
|
|
|
}
|
|
|
|
|
|
2013-02-16 06:23:04 +08:00
|
|
|
$scope.init();
|
2013-02-14 05:24:32 +08:00
|
|
|
|
2013-02-13 07:25:39 +08:00
|
|
|
})
|
2013-02-16 06:23:04 +08:00
|
|
|
.controller('RowCtrl', function($scope, $rootScope, $timeout, ejsResource) {
|
2013-02-13 07:25:39 +08:00
|
|
|
|
2013-02-14 05:24:32 +08:00
|
|
|
var _d = {
|
|
|
|
|
title: "Row",
|
|
|
|
|
height: "150px",
|
|
|
|
|
collapse: false,
|
2013-03-09 01:04:38 +08:00
|
|
|
collapsable: true,
|
2013-02-14 05:24:32 +08:00
|
|
|
editable: true,
|
|
|
|
|
panels: [],
|
|
|
|
|
}
|
|
|
|
|
_.defaults($scope.row,_d)
|
|
|
|
|
|
|
|
|
|
|
2013-04-11 07:48:48 +08:00
|
|
|
$scope.init = function() {
|
2013-02-14 03:23:24 +08:00
|
|
|
$scope.reset_panel();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 07:25:39 +08:00
|
|
|
$scope.toggle_row = function(row) {
|
|
|
|
|
row.collapse = row.collapse ? false : true;
|
|
|
|
|
if (!row.collapse) {
|
|
|
|
|
$timeout(function() {
|
2013-04-11 07:48:48 +08:00
|
|
|
$scope.$broadcast('render')
|
2013-02-13 07:25:39 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-07 14:42:34 +08:00
|
|
|
// This can be overridden by individual panel
|
|
|
|
|
$scope.close_edit = function() {
|
|
|
|
|
$scope.$broadcast('render')
|
2013-02-14 23:37:03 +08:00
|
|
|
}
|
|
|
|
|
|
2013-02-14 03:23:24 +08:00
|
|
|
$scope.add_panel = function(row,panel) {
|
|
|
|
|
$scope.row.panels.push(panel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.reset_panel = function() {
|
|
|
|
|
$scope.panel = {
|
2013-04-11 07:48:48 +08:00
|
|
|
loading : false,
|
|
|
|
|
error : false,
|
|
|
|
|
span : 3,
|
2013-02-14 03:23:24 +08:00
|
|
|
editable: true,
|
2013-04-11 07:48:48 +08:00
|
|
|
group : ['default'],
|
2013-02-14 03:23:24 +08:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.init();
|
|
|
|
|
|
2013-01-26 12:10:28 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|