Skip to content

Commit

Permalink
Add keepArrays option to flatten mixin, make table fields flatten cor…
Browse files Browse the repository at this point in the history
…rectly, closes #43
  • Loading branch information
Rashid Khan committed Apr 15, 2014
1 parent b403ec3 commit 846a6a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/kibana/directives/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define(function (require) {
scope: {
columns: '=',
getSort: '=',
setSort: '='
setSort: '=',
},
template: headerHtml,
controller: function ($scope) {
Expand Down Expand Up @@ -115,7 +115,10 @@ define(function (require) {

// itterate the columns and rows, rebuild the table's html
function render() {
// Close all rows
opened = [];

// Clear the body
$body.empty();
if (!$scope.rows || $scope.rows.length === 0) return;
if (!$scope.columns || $scope.columns.length === 0) return;
Expand All @@ -140,7 +143,7 @@ define(function (require) {
function forEachRow(row, i, currentChunk) {
var id = rowId(row);
var $summary = createSummaryRow(row, id);
var $details = createDetailsRow(row, id);
var $details = $('<tr></tr>');
// cursor is the end of current selection, so
// subtract the remaining queue size, then the
// size of this chunk, and add the current i
Expand Down Expand Up @@ -236,13 +239,23 @@ define(function (require) {
);
};

var topLevelDetails = '_index _type _id'.split(' ');
function createDetailsRow(row, id) {
var $tr = $(document.createElement('tr'));
return 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
var containerTd = document.createElement('td');
containerTd.setAttribute('colspan', $scope.columns.length);
Expand All @@ -265,7 +278,7 @@ define(function (require) {

// itterate each row and append it to the tbody
// TODO: This doesn't work since _source is not flattened
_(row._source)
_(rowFlat)
.keys()
.concat(topLevelDetails)
.sort()
Expand Down
3 changes: 2 additions & 1 deletion src/kibana/utils/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ define(function (require) {
(function flattenObj(obj) {
_.keys(obj).forEach(function (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];
stack.pop();
});
Expand Down

0 comments on commit 846a6a1

Please sign in to comment.