Skip to content

Commit

Permalink
Merge pull request #2481 from simianhacker/fix/2183
Browse files Browse the repository at this point in the history
Closes #2183 - Add filters to table visualization
  • Loading branch information
spenceralger committed Jan 5, 2015
2 parents 6691a0b + 038743c commit 96c4de8
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/kibana/components/agg_table/agg_table.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<paginated-table
ng-if="formattedRows.length"
rows="formattedRows"
ng-if="rows.length"
rows="rows"
columns="formattedColumns"
per-page="perPage">

Expand Down
17 changes: 5 additions & 12 deletions src/kibana/components/agg_table/agg_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ define(function (require) {

function setFormattedColumns(table) {
$scope.formattedColumns = table.columns.map(function (col, i) {
var agg = $scope.table.aggConfig(col);
var field = agg.field();
var formattedColumn = {
title: col.title
title: col.title,
filterable: field && field.filterable && agg.schema.group === 'buckets'
};

var agg = $scope.table.aggConfig(col);
var last = i === (table.columns.length - 1);

if (last || (agg.schema.group === 'metrics')) {
Expand All @@ -98,16 +100,7 @@ define(function (require) {
}

function setFormattedRows(table) {
var formatters = table.columns.map(function (col) {
return table.fieldFormatter(col);
});

// format all row values
$scope.formattedRows = (table.rows).map(function (row) {
return row.map(function (cell, i) {
return formatters[i](cell);
});
});
$scope.rows = table.rows;

// update the csv file's title
self.csv.filename = (table.title() || 'table') + '.csv';
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/index_patterns/_field_formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ define(function (require) {

return formats;
};
});
});
3 changes: 2 additions & 1 deletion src/kibana/components/paginated_table/paginated_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'fa-sort': paginatedTable.sort.direction === null || paginatedTable.sort.columnName !== col.title
}">
</i>
<i ng-if="col.filterable" class="fa fa-search" ng-click="$event.stopPropagation()" tooltip="Click on a cell to filter"></i>
</th>
</tr>
</thead>
Expand All @@ -33,4 +34,4 @@
<!-- <paginate-controls></paginate-controls> -->
<div class="pagination-container" ng-transclude></div>

</paginate>
</paginate>
21 changes: 19 additions & 2 deletions src/kibana/components/state_management/app_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,42 @@ define(function (require) {
var _ = require('lodash');
var modules = require('modules');

function AppStateProvider(Private, $rootScope) {
function AppStateProvider(Private, $rootScope, getAppState) {
var State = Private(require('components/state_management/state'));

_(AppState).inherits(State);
function AppState(defaults) {
AppState.Super.call(this, '_a', defaults);
getAppState._set(this);
}

// if the url param is missing, write it back
AppState.prototype._persistAcrossApps = false;

// expose this as a factory as well
AppState.prototype.destroy = function () {
AppState.Super.prototype.destroy.call(this);
getAppState._set(null);
};

return AppState;
}

modules.get('kibana/global_state')
.factory('AppState', function (Private) {
return Private(AppStateProvider);
})
.service('getAppState', function () {
var currentAppState;

function get() {
return currentAppState;
}

get._set = function (current) {
currentAppState = current;
};

return get;
});

return AppStateProvider;
Expand Down
4 changes: 4 additions & 0 deletions src/kibana/components/vis/_agg_config_result.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ define(function (require) {
return this.aggConfig.createFilter(this.key);
};

AggConfigResult.prototype.toString = function () {
return this.aggConfig.fieldFormatter()(this.value);
};

return AggConfigResult;
});
27 changes: 25 additions & 2 deletions src/kibana/directives/rows.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ define(function (require) {
var $ = require('jquery');
var _ = require('lodash');
var module = require('modules').get('kibana');
var AggConfigResult = require('components/vis/_agg_config_result');

module.directive('kbnRows', function ($compile) {
module.directive('kbnRows', function ($compile, $rootScope, getAppState, Private) {
var filterBarClickHandler = Private(require('components/filter_bar/filter_bar_click_handler'));
return {
restrict: 'A',
link: function ($scope, $el, attr) {
Expand All @@ -14,6 +16,27 @@ define(function (require) {
// access to it here. This may become a problem with the switch to BigNumber
if (_.isNumeric(contents)) $cell.addClass('numeric-value');

var createAggConfigResultCell = function (aggConfigResult) {
var $cell = $(document.createElement('td'));
var $state = getAppState();
var clickHandler = filterBarClickHandler($state);
$cell.scope = $scope.$new();
$cell.addClass('cell-hover');
$cell.attr('ng-click', 'clickHandler()');
$cell.scope.clickHandler = function (negate) {
clickHandler({ point: { aggConfigResult: aggConfigResult } });
};
return $compile($cell)($cell.scope);
};


if (contents instanceof AggConfigResult) {
if (contents.type === 'bucket' && contents.aggConfig.field().filterable) {
$cell = createAggConfigResultCell(contents);
}
contents = contents.toString();
}

if (_.isObject(contents)) {
if (contents.scope) {
$cell.html($compile(contents.markup)(contents.scope));
Expand Down Expand Up @@ -68,4 +91,4 @@ define(function (require) {
}
};
});
});
});
5 changes: 3 additions & 2 deletions src/kibana/plugins/table_vis/table_vis_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ define(function (require) {

tableGroups = tabifyAggResponse(vis, resp, {
partialRows: params.showPartialRows,
minimalColumns: vis.isHierarchical() && !params.showMeticsAtAllLevels
minimalColumns: vis.isHierarchical() && !params.showMeticsAtAllLevels,
asAggConfigResults: true
});

hasSomeRows = tableGroups.tables.some(function haveRows(table) {
Expand All @@ -35,4 +36,4 @@ define(function (require) {
});
});

});
});
5 changes: 5 additions & 0 deletions src/kibana/styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,8 @@ style-compile {
}

@import '../components/filter_bar/filter_bar.less';

.cell-hover:hover {
background-color: @gray-lighter;
}

0 comments on commit 96c4de8

Please sign in to comment.