kibana-123
Version:
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic
57 lines (44 loc) • 1.86 kB
JavaScript
import AggResponseTabifyTabifyProvider from 'ui/agg_response/tabify/tabify';
import uiModules from 'ui/modules';
import { assign } from 'lodash';
// get the kibana/table_vis module, and make sure that it requires the "kibana" module if it
// didn't already
const module = uiModules.get('kibana/table_vis', ['kibana']);
// add a controller to tha module, which will transform the esResponse into a
// tabular format that we can pass to the table directive
module.controller('KbnTableVisController', function ($scope, $element, Private) {
const tabifyAggResponse = Private(AggResponseTabifyTabifyProvider);
var uiStateSort = ($scope.uiState) ? $scope.uiState.get('vis.params.sort') : {};
assign($scope.vis.params.sort, uiStateSort);
$scope.sort = $scope.vis.params.sort;
$scope.$watchCollection('sort', function (newSort) {
$scope.uiState.set('vis.params.sort', newSort);
});
/**
* Recreate the entire table when:
* - the underlying data changes (esResponse)
* - one of the view options changes (vis.params)
*/
$scope.$watchMulti(['esResponse', 'vis.params'], function ([resp]) {
let tableGroups = $scope.tableGroups = null;
let hasSomeRows = $scope.hasSomeRows = null;
if (resp) {
const vis = $scope.vis;
const params = vis.params;
tableGroups = tabifyAggResponse(vis, resp, {
partialRows: params.showPartialRows,
minimalColumns: vis.isHierarchical() && !params.showMeticsAtAllLevels,
asAggConfigResults: true
});
hasSomeRows = tableGroups.tables.some(function haveRows(table) {
if (table.tables) return table.tables.some(haveRows);
return table.rows.length > 0;
});
$element.trigger('renderComplete');
}
$scope.hasSomeRows = hasSomeRows;
if (hasSomeRows) {
$scope.tableGroups = tableGroups;
}
});
});