Add doc_viewer directive

This commit is contained in:
Rashid Khan 2014-12-02 11:35:48 -07:00
parent e4de8274e1
commit 99a0b2ff31
2 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,42 @@
<div class="discover-table-details">
<ul class="nav nav-tabs discover-table-details-toggle">
<li ng-class="{active: mode == 'table'}"><a ng-click="mode='table'">Table</a></li>
<li ng-class="{active: mode == 'json'}"><a ng-click="mode='json'">JSON</a></li>
</ul>
<table class="table table-condensed" ng-show="mode == 'table'" bindonce>
<tbody>
<tr ng-repeat="field in fields" bindonce>
<td field-name="field"
field-type="mapping[field].type"
width="1%"
class="discover-table-details-field">
</td>
<td width="1%" class="discover-table-details-buttons" ng-show="filter">
<span bo-show="showFilters(mapping[field])">
<i ng-click="filter(doc, field, '+')" class="fa fa-search-plus"></i>
<i ng-click="filter(doc, field, '-')" class="fa fa-search-minus"></i>
</span>
<span bo-show="!showFilters(mapping[field])" tooltip="Unindexed fields can not be searched">
<i class="fa fa-search-plus text-muted"></i>
<i class="fa fa-search-minus text-muted"></i>
</span>
</td>
<td>
<i bo-show="!mapping[field] && !showArrayInObjectsWarning(doc, field)"
tooltip-placement="top"
tooltip="No cached mapping for this field. Refresh your mapping from the Settings > Indices page"
class="fa fa-warning text-color-warning ng-scope"></i>
<i bo-show="showArrayInObjectsWarning(doc, field)"
tooltip-placement="top"
tooltip="Objects in arrays are not well supported."
class="fa fa-warning text-color-warning ng-scope"></i>
<span class="discover-table-details-value" ng-bind-html="(formatted[field] || doc[field]) | highlight : hit.highlight[field] | trustAsHtml"></span>
</td>
</tr>
</tbody>
</table>
<pre ng-show="mode == 'json'">{{hit | json}}</pre>
</div>

View file

@ -0,0 +1,47 @@
define(function (require) {
var _ = require('lodash');
var html = require('text!components/doc_viewer/doc_viewer.html');
require('modules').get('kibana')
.directive('docViewer', function (config, courier) {
return {
restrict: 'E',
template: html,
transclude: true,
replace: true,
scope: {
hit: '=',
indexPattern: '=',
filter: '=?',
},
link: function ($scope, $el, attr) {
// If a field isn't in the mapping, use this
var defaultFormat = courier.indexPatterns.fieldFormats.defaultByType.string;
$scope.mode = 'table';
$scope.mapping = $scope.indexPattern.fields.byName;
$scope.flattened = $scope.indexPattern.flattenHit($scope.hit);
$scope.formatted = _.mapValues($scope.flattened, function (value, name) {
var formatter = $scope.mapping[name] ? $scope.mapping[name].format : defaultFormat;
return formatter.convert(value);
});
$scope.fields = _.keys($scope.flattened).sort();
$scope.showFilters = function (mapping) {
var validTypes = ['string', 'number', 'date', 'ip'];
if (!$scope.filter || !mapping || !mapping.indexed) return false;
return _.contains(validTypes, mapping.type);
};
$scope.showArrayInObjectsWarning = function (row, field) {
var value = $scope.flattened[field];
return _.isArray(value) && typeof value[0] === 'object';
};
}
};
});
});