2013-07-21 05:56:59 +08:00
|
|
|
/*jshint globalstrict:true */
|
|
|
|
/*global angular:true */
|
2013-07-12 08:05:50 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
## query
|
|
|
|
|
|
|
|
An experimental panel for the query service
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
* label :: The label to stick over the field
|
|
|
|
* query :: A string or an array of querys. String if multi is off, array if it is on
|
|
|
|
This should be fixed, it should always be an array even if its only
|
|
|
|
one element
|
|
|
|
*/
|
|
|
|
|
2013-07-21 05:56:59 +08:00
|
|
|
'use strict';
|
|
|
|
|
2013-07-12 08:05:50 +08:00
|
|
|
angular.module('kibana.query', [])
|
2013-07-15 07:42:14 +08:00
|
|
|
.controller('query', function($scope, query, $rootScope) {
|
2013-07-12 08:05:50 +08:00
|
|
|
|
|
|
|
// Set and populate defaults
|
|
|
|
var _d = {
|
|
|
|
status : "Experimental",
|
|
|
|
label : "Search",
|
|
|
|
query : "*",
|
|
|
|
group : "default",
|
|
|
|
history : [],
|
|
|
|
remember: 10 // max: 100, angular strap can't take a variable for items param
|
2013-07-21 05:56:59 +08:00
|
|
|
};
|
2013-07-12 08:05:50 +08:00
|
|
|
_.defaults($scope.panel,_d);
|
|
|
|
|
|
|
|
$scope.queries = query;
|
|
|
|
|
|
|
|
$scope.init = function() {
|
2013-07-21 05:56:59 +08:00
|
|
|
};
|
2013-07-12 08:05:50 +08:00
|
|
|
|
|
|
|
$scope.refresh = function(query) {
|
2013-07-21 05:56:59 +08:00
|
|
|
$rootScope.$broadcast('refresh');
|
|
|
|
};
|
2013-07-12 08:05:50 +08:00
|
|
|
|
|
|
|
$scope.render = function(query) {
|
2013-07-21 05:56:59 +08:00
|
|
|
$rootScope.$broadcast('render');
|
|
|
|
};
|
2013-07-12 08:05:50 +08:00
|
|
|
|
|
|
|
$scope.add_query = function() {
|
2013-07-21 05:56:59 +08:00
|
|
|
if (_.isArray($scope.panel.query)) {
|
|
|
|
$scope.panel.query.push("");
|
|
|
|
} else {
|
|
|
|
$scope.panel.query = new Array($scope.panel.query);
|
|
|
|
$scope.panel.query.push("");
|
2013-07-12 08:05:50 +08:00
|
|
|
}
|
2013-07-21 05:56:59 +08:00
|
|
|
};
|
2013-07-12 08:05:50 +08:00
|
|
|
|
|
|
|
var update_history = function(query) {
|
|
|
|
if($scope.panel.remember > 0) {
|
2013-07-21 05:56:59 +08:00
|
|
|
$scope.panel.history = _.union(query.reverse(),$scope.panel.history);
|
|
|
|
var _length = $scope.panel.history.length;
|
2013-07-12 08:05:50 +08:00
|
|
|
if(_length > $scope.panel.remember) {
|
2013-07-21 05:56:59 +08:00
|
|
|
$scope.panel.history = $scope.panel.history.slice(0,$scope.panel.remember);
|
2013-07-12 08:05:50 +08:00
|
|
|
}
|
|
|
|
}
|
2013-07-21 05:56:59 +08:00
|
|
|
};
|
2013-07-12 08:05:50 +08:00
|
|
|
|
|
|
|
});
|