Commit 86408301 by Rashid Khan

Added close button, related fields to micropanel

parent 985099e9
......@@ -6,10 +6,6 @@
color: #000;
}
#upload {
display: inline-block;
}
.odd {
background-color: #f9f9f9;
}
......
......@@ -30,18 +30,6 @@ function has_field(obj,field) {
}
}
// Retuns a sorted array with duplicates removed
function array_unique(arr) {
var sorted_arr = arr.sort();
var results = [];
for (var i = 0; i <= arr.length - 1; i++) {
if (sorted_arr[i + 1] != sorted_arr[i]) {
results.push(sorted_arr[i]);
}
}
return results
}
function get_objids_with_field(json,field) {
var objid_array = [];
for (hit in json.hits.hits) {
......@@ -75,15 +63,14 @@ function get_objids_with_field_value(json,field,value) {
return objid_array;
}
function get_related_fields(json,field) {
function get_related_fields(docs,field) {
var field_array = []
for (hit in json.hits.hits) {
var obj_fields = get_object_fields(json.hits.hits[hit])
if (_.inArray(obj_fields,field) >= 0) {
field_array.push.apply(field_array,obj_fields);
}
}
var counts = count_values_in_array(field_array);
_.each(docs, function(doc) {
var keys = _.keys(doc)
if(_.contains(keys,field))
field_array = field_array.concat(keys)
})
var counts = _.countBy(_.without(field_array,field),function(field){return field;});
return counts;
}
......@@ -100,7 +87,8 @@ function recurse_field_dots(object,field) {
return value;
}
// Probably useless now
// Probably useless now, leaving for cases where you might not want
// a flat dot notated data structure
function get_field_value(object,field,opt) {
var value = recurse_field_dots(object['_source'],field);
......@@ -130,23 +118,13 @@ function get_field_value(object,field,opt) {
return (value != null) ? value.toString() : '';
}
// Returns a big flat array of all values for a field
function get_all_values_for_field(docs,field) {
var field_array = [];
_.each(docs, function(doc,k) {
var value = doc[field] || ""
if(typeof value === 'object' && value != null) {
field_array.push.apply(field_array,value);
} else {
field_array.push(value);
}
})
return field_array;
}
function top_field_values(docs,field,count) {
var counts = _.countBy(get_all_values_for_field(docs,field),function(field){return field;});
return _.pairs(counts).sort(function(a, b) {return a[1] - b[1]}).reverse().slice(0,count)
var counts = _.countBy(_.pluck(docs,field),function(field){
return _.isUndefined(field) ? '' : field;
});
return _.pairs(counts).sort(function(a, b) {
return a[1] - b[1]
}).reverse().slice(0,count)
}
function add_to_query(original,field,value) {
......
<div>
<a class="close" ng-click="dismiss()" href="">×</a>
<div ng-show='panel.load.local'>
<h5>Local File</h5>
<form>
......
<div>
<a class="close" ng-click="dismiss()" href="">×</a>
<div ng-show="panel.save.default || panel.save.local">
<h5>Locally</h5>
<form>
......
......@@ -3,7 +3,7 @@
Micro Analysis of {{micropanel.field}}
<i class="pointer icon-search" ng-click="build_search('_exists_',micropanel.field);dismiss();"></i>
<i class="pointer icon-ban-circle" ng-click="build_search('_missing_',micropanel.field);dismiss();"></i>
<br><small>{{micropanel.count}} events on this page</small>
</h4>
<table style="width:500px" class='table table-bordered table-striped table-condensed'>
<thead>
......@@ -22,3 +22,4 @@
</tr>
</tbody>
</table>
<span ng-repeat='(field,count) in micropanel.related'><a ng-click="toggle_field(field)">{{field}}</a> ({{Math.round((count / micropanel.count) * 100)}}%),</span>
\ No newline at end of file
<kibana-panel ng-controller='fields'>
<ul class="unstyled" style="height:{{row.height}};overflow-y:auto;overflow-x:hidden;">
<ul class="unstyled" style="height:{{row.height}};overflow-y:auto;overflow-x:hidden;" ng-class="{'inline': panel.arrange == 'horizontal'}">
<li ng-style="panel.style" ng-repeat="field in fields" >
<i class="pointer" ng-class="{'icon-check': _.indexOf(active,field)>-1,'icon-check-empty': _.indexOf(active,field)<0}" ng-click="toggle_field(field)"></i>
<a data-unique="1" bs-popover="'panels/fields/micropanel.html'" ng-click="toggle_micropanel(field)" ng-class="{label: _.indexOf(active,field)>-1}">{{field}}</a>
<a data-unique="1" bs-popover="'panels/fields/micropanel.html'" data-placement="{{panel.micropanel_position}}" ng-click="toggle_micropanel(field)" ng-class="{label: _.indexOf(active,field)>-1}">{{field}}</a>
</li>
</ul>
</kibana-panel>
\ No newline at end of file
angular.module('kibana.fields', [])
.controller('fields', function($scope, eventBus) {
.controller('fields', function($scope, eventBus, $timeout) {
var _id = _.uniqueId();
......@@ -7,14 +7,17 @@ angular.module('kibana.fields', [])
var _d = {
group : "default",
style : {},
arrange : 'vertical',
micropanel_position : 'right',
}
_.defaults($scope.panel,_d);
$scope.init = function() {
$scope.Math = Math;
$scope.fields = [];
eventBus.register($scope,'fields', function(event, fields) {
$scope.panel.sort = _.clone(fields.sort);
$scope.fields = _.union(fields.all,$scope.fields);
$scope.fields = fields.all,
$scope.active = _.clone(fields.active);
});
eventBus.register($scope,'table_documents', function(event, docs) {
......@@ -23,10 +26,22 @@ angular.module('kibana.fields', [])
});
}
$scope.reload_list = function () {
var temp = _.clone($scope.fields);
$scope.fields = []
$timeout(function(){
$scope.fields = temp;
},10)
}
$scope.toggle_micropanel = function(field) {
$scope.micropanel = {
field: field,
values : top_field_values($scope.docs,field,10)
values : top_field_values($scope.docs,field,10),
related : get_related_fields($scope.docs,field),
count: _.countBy($scope.docs,function(doc){
return _.contains(_.keys(doc),field)})['true'],
}
}
......
<div class="row-fluid" ng-controller="hits">
<div class="row-fluid">
<div class="span9">
<form class="input-append">
<h6>Query</h6>
......
<kibana-panel ng-controller='stringquery'>
<form class="input-append" style="margin-bottom:0px; width:100%; white-space:nowrap;">
<label><small>{{panel.label}}</small></label>
<input type="text" ng-model="panel.query" style="width:90%">
<button type="submit" class="btn" ng-click="send_query(panel.query)"><i class="icon-search"></i></button>
<input type="text" ng-model="panel.query" style="width:85%">
<button type="submit" class="btn btn-info" ng-click="send_query(panel.query)"><i class="icon-search"></i></button>
<button type="submit" class="btn btn-danger" ng-click="panel.query='';send_query(panel.query)"><i class="icon-ban-circle"></i></button>
</form>
</kibana-panel>
\ No newline at end of file
......@@ -102,10 +102,9 @@ angular.module('kibana.table', [])
}
$scope.panel.error = false;
$scope.hits = results.hits.total;
$scope.data = []
_.each(results.hits.hits, function(v,k) {
$scope.data.push(flatten_json(v['_source']))
})
$scope.data = _.map(results.hits.hits, function(hit) {
return flatten_json(hit['_source']);
});
$scope.all_fields = get_all_fields(results);
broadcast_results();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment