mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Add keepArrays option to flatten mixin, make table fields flatten correctly, closes #43
This commit is contained in:
parent
b469f140e2
commit
6c58b355f9
2 changed files with 19 additions and 5 deletions
|
@ -17,7 +17,7 @@ define(function (require) {
|
||||||
scope: {
|
scope: {
|
||||||
columns: '=',
|
columns: '=',
|
||||||
getSort: '=',
|
getSort: '=',
|
||||||
setSort: '='
|
setSort: '=',
|
||||||
},
|
},
|
||||||
template: headerHtml,
|
template: headerHtml,
|
||||||
controller: function ($scope) {
|
controller: function ($scope) {
|
||||||
|
@ -115,7 +115,10 @@ define(function (require) {
|
||||||
|
|
||||||
// itterate the columns and rows, rebuild the table's html
|
// itterate the columns and rows, rebuild the table's html
|
||||||
function render() {
|
function render() {
|
||||||
|
// Close all rows
|
||||||
|
opened = [];
|
||||||
|
|
||||||
|
// Clear the body
|
||||||
$body.empty();
|
$body.empty();
|
||||||
if (!$scope.rows || $scope.rows.length === 0) return;
|
if (!$scope.rows || $scope.rows.length === 0) return;
|
||||||
if (!$scope.columns || $scope.columns.length === 0) return;
|
if (!$scope.columns || $scope.columns.length === 0) return;
|
||||||
|
@ -140,7 +143,7 @@ define(function (require) {
|
||||||
function forEachRow(row, i, currentChunk) {
|
function forEachRow(row, i, currentChunk) {
|
||||||
var id = rowId(row);
|
var id = rowId(row);
|
||||||
var $summary = createSummaryRow(row, id);
|
var $summary = createSummaryRow(row, id);
|
||||||
var $details = createDetailsRow(row, id);
|
var $details = $('<tr></tr>');
|
||||||
// cursor is the end of current selection, so
|
// cursor is the end of current selection, so
|
||||||
// subtract the remaining queue size, then the
|
// subtract the remaining queue size, then the
|
||||||
// size of this chunk, and add the current i
|
// size of this chunk, and add the current i
|
||||||
|
@ -236,13 +239,23 @@ define(function (require) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
var topLevelDetails = '_index _type _id'.split(' ');
|
|
||||||
function createDetailsRow(row, id) {
|
function createDetailsRow(row, id) {
|
||||||
var $tr = $(document.createElement('tr'));
|
var $tr = $(document.createElement('tr'));
|
||||||
return appendDetailsToRow($tr, row, id);
|
return appendDetailsToRow($tr, row, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendDetailsToRow($tr, row, id) {
|
function appendDetailsToRow($tr, row, id) {
|
||||||
|
var topLevelDetails = ['_index', '_type', '_id'];
|
||||||
|
|
||||||
|
var rowFlat = _.flattenWith('.', row._source, true);
|
||||||
|
/*
|
||||||
|
_.each(topLevelDetails, function (field) {
|
||||||
|
rowFlat[field] = row[field];
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
console.log(rowFlat);
|
||||||
|
|
||||||
|
|
||||||
// we need a td to wrap the details table
|
// we need a td to wrap the details table
|
||||||
var containerTd = document.createElement('td');
|
var containerTd = document.createElement('td');
|
||||||
containerTd.setAttribute('colspan', $scope.columns.length);
|
containerTd.setAttribute('colspan', $scope.columns.length);
|
||||||
|
@ -265,7 +278,7 @@ define(function (require) {
|
||||||
|
|
||||||
// itterate each row and append it to the tbody
|
// itterate each row and append it to the tbody
|
||||||
// TODO: This doesn't work since _source is not flattened
|
// TODO: This doesn't work since _source is not flattened
|
||||||
_(row._source)
|
_(rowFlat)
|
||||||
.keys()
|
.keys()
|
||||||
.concat(topLevelDetails)
|
.concat(topLevelDetails)
|
||||||
.sort()
|
.sort()
|
||||||
|
|
|
@ -31,7 +31,8 @@ define(function (require) {
|
||||||
(function flattenObj(obj) {
|
(function flattenObj(obj) {
|
||||||
_.keys(obj).forEach(function (key) {
|
_.keys(obj).forEach(function (key) {
|
||||||
stack.push(key);
|
stack.push(key);
|
||||||
if (typeof obj[key] === 'object') flattenObj(obj[key]);
|
if (typeof keepArrays && _.isArray(obj[key])) flatObj[stack.join(dot)] = obj[key];
|
||||||
|
else if (typeof obj[key] === 'object') flattenObj(obj[key]);
|
||||||
else flatObj[stack.join(dot)] = obj[key];
|
else flatObj[stack.join(dot)] = obj[key];
|
||||||
stack.pop();
|
stack.pop();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue