Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #719 #731

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/panels/table/module.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</div>
</div>
<div style="{{panel.overflow}}:{{panel.height || row.height}};" ng-class="{'span9':panel.field_list,'span12':!panel.field_list}" class="table-doc-table">
<i class="pull-left icon-chevron-sign-right pointer" ng-click="panel.field_list = !panel.field_list" bs-tooltip="'Show field list'" ng-show="!panel.field_list"></i>
<i class="pull-left icon-chevron-sign-right pointer" ng-click="compute_fields(panel.field_list = !panel.field_list)" bs-tooltip="'Show field list'" ng-show="!panel.field_list"></i>
<div class="row-fluid" ng-show="panel.paging">
<div class="span1 offset1" style="text-align:right">
<i ng-click="panel.offset = 0" ng-show="panel.offset > 0" class='icon-circle-arrow-left pointer'></i>
Expand Down Expand Up @@ -64,7 +64,7 @@
<tbody ng-repeat="event in data| slice:panel.offset:panel.offset+panel.size" ng-class-odd="'odd'">
<tr ng-click="toggle_details(event)" class="pointer">
<td ng-show="panel.fields.length<1">{{event._source|stringify|tableTruncate:panel.trimFactor:1}}</td>
<td ng-show="panel.fields.length>0" ng-repeat="field in panel.fields" ng-bind-html-unsafe="(event.kibana.highlight[field]||event.kibana._source[field]) |tableHighlight | tableTruncate:panel.trimFactor:panel.fields.length"></td>
<td ng-show="panel.fields.length>0" ng-repeat="field in panel.fields" ng-bind-html-unsafe="field | fromSources: event.kibana.highlight:event.kibana._source |tableHighlight | tableTruncate:panel.trimFactor:panel.fields.length"></td>
</tr>
<tr ng-show="event.kibana.details">
<td colspan={{panel.fields.length}} ng-switch="event.kibana.view">
Expand Down
86 changes: 72 additions & 14 deletions src/app/panels/table/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ function (angular, app, _, kbn, moment) {
$scope.get_data();
};


$scope.toggle_field = function(field) {
if (_.indexOf($scope.panel.fields,field) > -1) {
$scope.panel.fields = _.without($scope.panel.fields,field);
Expand Down Expand Up @@ -202,7 +203,34 @@ function (angular, app, _, kbn, moment) {
filterSrv.set({type:'exists',field:field,mandate:mandate});
};

$scope.get_data = function(segment,query_id) {
$scope.compute_fields = function(state) {
$scope.panelMeta.loading = true;

var cb = function(results) {
$scope.panelMeta.loading = false;

// Check for error and abort if found
if(!(_.isUndefined(results.error))) {
$scope.panel.error = $scope.parse_error(results.error);
return;
}
$scope.update_current_fields(results.hits.hits);
// thank you, good bye
};

$scope.do_search($scope.segment, $scope.query_id, cb);

return state;
};

$scope.update_current_fields = function(hits) {
_.each(hits, function(hit) {
$scope.current_fields = $scope.current_fields.concat(_.keys(kbn.flatten_json(hit._source)));
});
$scope.current_fields = _.uniq($scope.current_fields);
};

$scope.do_search = function(segment, query_id, cb) {
var
_segment,
request,
Expand Down Expand Up @@ -248,12 +276,15 @@ function (angular, app, _, kbn, moment) {
$scope.populate_modal(request);

results = request.doSearch();
results.then(cb);
};


// Populate scope when we have results
results.then(function(results) {
$scope.get_data = function(segment, query_id) {
var cb = function(results) {
$scope.panelMeta.loading = false;

if(_segment === 0) {
if($scope.segment === 0) {
$scope.hits = 0;
$scope.data = [];
$scope.current_fields = [];
Expand All @@ -268,6 +299,10 @@ function (angular, app, _, kbn, moment) {

// Check that we're still on the same query, if not stop
if($scope.query_id === query_id) {
// Update field list immediately if visible
if($scope.panel.field_list && $scope.current_fields !== []) {
$scope.update_current_fields(results.hits.hits);
}

// This is exceptionally expensive, especially on events with a large number of fields
$scope.data = $scope.data.concat(_.map(results.hits.hits, function(hit) {
Expand All @@ -277,17 +312,13 @@ function (angular, app, _, kbn, moment) {

// _source is kind of a lie here, never display it, only select values from it
_h.kibana = {
_source : _.extend(kbn.flatten_json(hit._source),_p),
_source : _.extend(hit._source,_p),
highlight : kbn.flatten_json(hit.highlight||{})
};

// Kind of cheating with the _.map here, but this is faster than kbn.get_all_fields
$scope.current_fields = $scope.current_fields.concat(_.keys(_h.kibana._source));

return _h;
}));

$scope.current_fields = _.uniq($scope.current_fields);
$scope.hits += results.hits.total;

// Sort the data
Expand Down Expand Up @@ -316,11 +347,13 @@ function (angular, app, _, kbn, moment) {
// Otherwise, only get size*pages results then stop querying
if (($scope.data.length < $scope.panel.size*$scope.panel.pages ||
!((_.contains(filterSrv.timeField(),$scope.panel.sort[0])) && $scope.panel.sort[1] === 'desc')) &&
_segment+1 < dashboard.indices.length) {
$scope.get_data(_segment+1,$scope.query_id);
$scope.segment+1 < dashboard.indices.length) {
$scope.get_data($scope.segment+1,$scope.query_id);
}

});
};

$scope.do_search(segment, query_id, cb);
};

$scope.populate_modal = function(request) {
Expand Down Expand Up @@ -361,6 +394,33 @@ function (angular, app, _, kbn, moment) {

});

module.filter('fromSources', function() {
return function(fieldName, source1, source2) {
var findField = function(segments, into) {
var where = into;
var found = true;
var segment;

for(var seg in segments ) {
segment = segments[seg];
if(where[segment]) {
where = where[segment];
} else {
found = false;
break;
}
}
if(found) {
return where;
}
return null;
};
var segments = fieldName.split(/\./);

return findField(segments, source1) || findField(segments, source2);
};
});

// This also escapes some xml sequences
module.filter('tableHighlight', function() {
return function(text) {
Expand All @@ -386,8 +446,6 @@ function (angular, app, _, kbn, moment) {
};
});



module.filter('tableJson', function() {
var json;
return function(text,prettyLevel) {
Expand Down