Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into feature/tilemap
Browse files Browse the repository at this point in the history
Conflicts:
	test/unit/index.html
  • Loading branch information
Juan Thomassie committed Nov 6, 2014
2 parents b5e31c9 + 9332dfe commit bad9149
Show file tree
Hide file tree
Showing 70 changed files with 2,183 additions and 460 deletions.
6 changes: 4 additions & 2 deletions src/kibana/components/agg_response/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ define(function (require) {
chartData.columns = chartColumns;
}

if (!bucket) return;

var row = new Array(chartColumns.length);
rowStack.forEach(function (val, i) {
row[i] = val;
Expand Down Expand Up @@ -134,7 +136,7 @@ define(function (require) {
rowStack.pop();
});
} else {
writeRow(chartData, bucket);
writeRow(chartData);
}
break;
}
Expand Down Expand Up @@ -227,4 +229,4 @@ define(function (require) {
return chartData;
};
};
});
});
3 changes: 2 additions & 1 deletion src/kibana/components/agg_response/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ define(function (require) {
return function NormalizeChartDataFactory(Private) {
return {
flat: Private(require('components/agg_response/flat')),
hierarchical: Private(require('components/agg_response/hierarchical/build_hierarchical_data'))
hierarchical: Private(require('components/agg_response/hierarchical/build_hierarchical_data')),
tabify: Private(require('components/agg_response/tabify/tabify'))
};
};
});
16 changes: 13 additions & 3 deletions src/kibana/components/agg_response/tabify/_buckets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ define(function (require) {
function Buckets(aggResp) {
aggResp = aggResp || false;
this.buckets = aggResp.buckets || [];
this.length = this.buckets.length;
this.objectMode = _.isPlainObject(this.buckets);

if (this.objectMode) {
this._keys = _.keys(this.buckets);
this.length = this._keys.length;
} else {
this.length = this.buckets.length;
}
}

Buckets.prototype.forEach = function (fn) {
var buckets = this.buckets;

if (this.objectMode) {
_.forOwn(this.buckets, fn);
this._keys.forEach(function (key) {
fn(buckets[key], key);
});
} else {
this.buckets.forEach(function (bucket) {
buckets.forEach(function (bucket) {
fn(bucket, bucket.key);
});
}
Expand Down
37 changes: 30 additions & 7 deletions src/kibana/components/agg_response/tabify/_response_writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ define(function (require) {
* @param {any} key - the bucketKey that this table relates to
* @return {Table/TableGroup} table - the created table
*/
TabbedAggResponseWriter.prototype.table = function (group, agg, key) {
TabbedAggResponseWriter.prototype._table = function (group, agg, key) {
var Class = (group) ? TableGroup : Table;
var table = new Class();

if (group) {
table.aggConfig = agg;
table.key = key;
table.title = agg.makeLabel() + ': ' + key;
table.title = agg.makeLabel() + ': ' + (table.fieldFormat()(key));
}

var parent = this.splitStack[0];
Expand Down Expand Up @@ -68,15 +68,13 @@ define(function (require) {
throw new Error('attempted to split when splitting is disabled');
}

_.pull(self.columns, _.find(self.columns, function (col) {
return col.aggConfig === agg;
}));
self._removeAggFromColumns(agg);

buckets.forEach(function (bucket, key) {
// find the existing split that we should extend
var TableGroup = _.find(self.splitStack[0].tables, { aggConfig: agg, key: key });
// create the split if it doesn't exist yet
if (!TableGroup) TableGroup = self.table(true, agg, key);
if (!TableGroup) TableGroup = self._table(true, agg, key);

// push the split onto the stack so that it will receive written tables
self.splitStack.unshift(TableGroup);
Expand All @@ -87,6 +85,28 @@ define(function (require) {
});
};

TabbedAggResponseWriter.prototype._removeAggFromColumns = function (agg) {
var i = _.findIndex(this.columns, function (col) {
return col.aggConfig === agg;
});

// we must have already removed this column
if (i === -1) return;

this.columns.splice(i, 1);

if (!this.vis.isHierarchical()) return;

// hierarchical vis creats additional columns for each bucket
// we will remove those too
var mCol = this.columns.splice(i, 1).pop();
var mI = _.findIndex(this.aggStack, function (agg) {
return agg === mCol.aggConfig;
});

if (mI > -1) this.aggStack.splice(mI, 1);
};

/**
* Push a value into the row, then run a block. Once the block is
* complete the value is pulled from the stack.
Expand Down Expand Up @@ -119,10 +139,11 @@ define(function (require) {
}

var split = this.splitStack[0];
var table = split.tables[0] || this.table(false);
var table = split.tables[0] || this._table(false);

while (cells.length < this.columns.length) cells.push('');
table.rows.push(cells);
return table;
};

/**
Expand All @@ -147,6 +168,8 @@ define(function (require) {
if (this.canSplit) return this.root;

var table = this.root.tables[0];
if (!table) return;

delete table.$parent;
return table;
};
Expand Down
11 changes: 11 additions & 0 deletions src/kibana/components/agg_response/tabify/_table_group.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
define(function (require) {
return function TableGroupProvider() {
var _ = require('lodash');

/**
* Simple object that wraps multiple tables. It contains information about the aggConfig
* and bucket that created this group and a list of the tables within it.
Expand All @@ -11,6 +13,15 @@ define(function (require) {
this.tables = [];
}

TableGroup.prototype.field = function () {
return this.aggConfig && this.aggConfig.params && this.aggConfig.params.field;
};

TableGroup.prototype.fieldFormat = function () {
var field = this.field();
return field ? field.format.convert : _.identity;
};

return TableGroup;
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ define(function (require) {
}
break;
case 'metrics':
write.cell(aggResp ? metricValue(aggResp) : bucketCount(bucket), function () {
var value = (agg.type.name === 'count') ? bucketCount(bucket) : metricValue(aggResp);
write.cell(value, function () {
if (!write.aggStack.length) {
// row complete
write.row();
Expand Down
6 changes: 3 additions & 3 deletions src/kibana/components/agg_table/agg_table.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<paginate
ng-if="!group"
ng-if="formattedRows.length"

list="formattedRows"
per-page="aggTable.getPerPage()"
per-page-prop="perPage"

class="agg-table">
<div class="agg-table-paginated">
Expand All @@ -25,7 +25,7 @@
</th>
</tr>
</thead>
<tbody kbn-rows="page" kbn-rows-min="aggTable.getPerPage()"></tbody>
<tbody kbn-rows="page" kbn-rows-min="perPage"></tbody>
</table>
</div>

Expand Down
34 changes: 16 additions & 18 deletions src/kibana/components/agg_table/agg_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define(function (require) {
var _ = require('lodash');
var saveAs = require('file_saver');

var tabifyAggResponse = Private(require('components/agg_response/tabify/tabify_agg_response'));
var tabifyAggResponse = Private(require('components/agg_response/tabify/tabify'));
var orderBy = $filter('orderBy');

return {
Expand All @@ -29,15 +29,10 @@ define(function (require) {

self.sort = null;
self.csv = {
showOptions: false,
separator: config.get('csv:separator'),
quoteValues: config.get('csv:quoteValues')
};

self.getPerPage = function () {
return $scope.perPage || Infinity;
};

self.getColumnClass = function (col, $first, $last) {
var cls = [];
var agg = $scope.table.aggConfig(col);
Expand All @@ -62,33 +57,35 @@ define(function (require) {
} else if (self.sort.asc) {
self.sort.asc = false;
} else {
delete self.sort;
self.sort = null;
}

if (self.sort && !self.sort.getter) {
var colI = $scope.table.columns.indexOf(self.sort.col);
self.sort.getter = function (row) {
return row[colI];
};
if (colI === -1) delete self.sort;
if (colI === -1) self.sort = null;
}
};

self.exportAsCsv = function () {
self.csv.showOptions = false;
saveAs(new Blob(self.toCsv(), { type: 'text/plain' }), self.csv.filename);
};

var text = '';
self.toCsv = function () {
var rows = $scope.table.rows;
var columns = $scope.table.columns;
var nonAlphaNumRE = /[^a-zA-Z0-9]/;
var allDoubleQuoteRE = /"/g;
var escape = function (val) {

function escape(val) {
val = String(val);
if (self.csv.quoteValues && nonAlphaNumRE.test(val)) {
val = '"' + val.replace(allDoubleQuoteRE, '""') + '"';
}
return val;
};
}

// escape each cell in each row
var csvRows = rows.map(function (row, i) {
Expand All @@ -100,17 +97,15 @@ define(function (require) {
return escape(col.title);
}));

var blob = new Blob(csvRows.map(function (row) {
return csvRows.map(function (row) {
return row.join(self.csv.separator) + '\r\n';
}), { type: 'text/plain' });

saveAs(blob, ($scope.table.title() || 'table') + '.csv');
}).join('');
};

$scope.$watchMulti([
'table',
'aggTable.sort.asc',
'aggTable.sort.field'
'aggTable.sort.col'
], function () {
var table = $scope.table;

Expand All @@ -125,7 +120,7 @@ define(function (require) {

// sort the row values, not formatted
if (self.sort) {
$scope.formattedRows = orderBy(table.rows, self.sort.getter, self.sort.asc);
$scope.formattedRows = orderBy(table.rows, self.sort.getter, !self.sort.asc);
} else {
$scope.formattedRows = null;
}
Expand All @@ -136,6 +131,9 @@ define(function (require) {
return formatters[i](cell);
});
});

// update the csv file's title
self.csv.filename = (table.title() || 'table') + '.csv';
});
}
};
Expand Down
12 changes: 6 additions & 6 deletions src/kibana/components/agg_table/agg_table_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<thead ng-repeat-start="table in rows">
<tr>
<th ng-if="table.tables">
<span class="agg-table-table-header">{{ table.title }}</span>
<span class="agg-table-group-header">{{ table.title }}</span>
</th>
</tr>
</thead>
<tbody ng-repeat-end>
<tr>
<td>
<kbn-agg-table-group ng-if="table.tables" group="table"></kbn-agg-table-group>
<kbn-agg-table ng-if="table.rows" table="table"></kbn-agg-table>
<kbn-agg-table-group ng-if="table.tables" group="table" per-page="perPage"></kbn-agg-table-group>
<kbn-agg-table ng-if="table.rows" table="table" per-page="perPage"></kbn-agg-table>
</td>
</tr>
</tbody>
Expand All @@ -20,15 +20,15 @@
<thead>
<tr>
<th ng-repeat="table in columns" ng-if="table.tables">
<span class="agg-table-table-header">{{ table.title }}</span>
<span class="agg-table-group-header">{{ table.title }}</span>
</th>
</tr>
</thead>
<tbody>
<tr>
<td ng-repeat="table in columns">
<kbn-agg-table-group ng-if="table.tables" group="table"></kbn-agg-table-group>
<kbn-agg-table ng-if="table.rows" table="table"></kbn-agg-table>
<kbn-agg-table-group ng-if="table.tables" group="table" per-page="perPage"></kbn-agg-table-group>
<kbn-agg-table ng-if="table.rows" table="table" per-page="perPage"></kbn-agg-table>
</td>
</tr>
</tbody>
Expand Down
13 changes: 5 additions & 8 deletions src/kibana/components/agg_table/agg_table_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ define(function (require) {
restrict: 'E',
template: require('text!components/agg_table/agg_table_group.html'),
scope: {
group: '='
group: '=',
perPage: '=?'
},
compile: function ($el) {
// Use the compile function from the RecursionHelper,
// And return the linking function(s) which it returns
return compileRecursiveDirective.compile($el, {
post: function ($scope) {
$scope.$watch('group', function (group) {
if (group && !group.tables.length) {
group = null;
}
// clear the previous "state"
$scope.rows = $scope.columns = false;

if (!group) {
$scope.rows = $scope.columns = false;
return;
}
if (!group || !group.tables.length) return;

var firstTable = group.tables[0];
var params = firstTable.aggConfig && firstTable.aggConfig.params;
Expand Down
Loading

0 comments on commit bad9149

Please sign in to comment.