Skip to content

Commit

Permalink
[agg_table] allow recursive rendering for passed in tableGroups
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer Alger committed Oct 27, 2014
1 parent 09a9adf commit 030abd7
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 78 deletions.
36 changes: 34 additions & 2 deletions src/kibana/components/agg_table/agg_table.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
<paginate list="formattedRows" per-page="pickPerPage" class="visualize-table">
<table ng-if="group && rows" class="table">
<tr ng-repeat-start="table in rows">
<th>
<span class="agg-table-table-header">{{ table.title }}</span>
</th>
</tr>
<tr ng-repeat-end>
<td>
<kbn-agg-table table="table" per-page="getPerPage()" level="nextLevel"></kbn-agg-table>
</td>
</tr>
</table>

<table ng-if="group && columns" class="table">
<tr>
<th ng-repeat="table in columns">
<span class="agg-table-table-header">{{ table.title }}</span>
</th>
</tr>
<tr>
<td ng-repeat="table in columns">
<kbn-agg-table table="table" per-page="getPerPage()" level="nextLevel"></kbn-agg-table>
</td>
</tr>
</table>

<paginate
ng-if="!group"

list="formattedRows"
per-page="getPerPage()"

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

Expand Down
36 changes: 28 additions & 8 deletions src/kibana/components/agg_table/agg_table.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
define(function (require) {
require('services/compile_recursive_directive');
require('css!components/agg_table/agg_table.css');

require('modules')
.get('kibana')
.directive('kbnAggTable', function ($filter, config, Private) {
.directive('kbnAggTable', function ($filter, config, Private, compileRecursiveDirective) {
var _ = require('lodash');
var saveAs = require('file_saver');

Expand All @@ -12,14 +15,22 @@ define(function (require) {
restrict: 'E',
template: require('text!components/agg_table/agg_table.html'),
scope: {
rows: '=',
columns: '=',
perPage: '=?'
tableOrGroup: '=table',
perPage: '=?',
level: '=?'
},
controllerAs: 'table',
compile: function ($el) {
// Use the compile function from the RecursionHelper,
// And return the linking function(s) which it returns
return compileRecursiveDirective.compile($el);
},
controller: function ($scope) {
var self = this;

$scope.level = $scope.level ? $scope.level + 1 : 1;
$scope.nextLevel = $scope.level + 1;

self.sort = null;
self.csv = {
showOptions: false,
Expand All @@ -45,7 +56,7 @@ define(function (require) {
return agg.params && agg.params.field;
}

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

Expand Down Expand Up @@ -116,15 +127,24 @@ define(function (require) {
};

$scope.$watchMulti([
'columns',
'rows',
'tableOrGroup',
'table.sort.asc',
'table.sort.field'
], function () {
if (!$scope.rows || !$scope.columns) {
$scope.rows = $scope.columns = $scope.group = null;

var tOrG = $scope.tableOrGroup;
if (!tOrG) return;

if (tOrG.tables) {
$scope.group = tOrG;
$scope[$scope.group.aggConfig.params.row ? 'rows' : 'columns'] = tOrG.tables;
return;
}

$scope.rows = tOrG.rows;
$scope.columns = tOrG.columns;

var formatters = $scope.columns.map(function (col) {
var field = colField(col);
return field ? field.format.convert : _.identity;
Expand Down
37 changes: 37 additions & 0 deletions src/kibana/components/agg_table/agg_table.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@import (reference) "lesshat.less";
@import (reference) "../../styles/theme/_variables.less";

agg-table {
.display(flex);
.flex(1, 1, auto);
.flex-direction(column);

.agg-table {
&-paginated-table {
.flex(1, 1, auto);
overflow: auto;

th i.fa-sort {
color: @gray-light;
}

.visualize-table-right,
td.numeric-value {
text-align: right;
}
}

&-controls {
.flex(0, 0, auto);
.display(flex);
.align-items(center);
margin: 10px 5px;

> paginate-controls {
.flex(1, 0, auto);
margin: 0;
padding: 0;
}
}
}
}
2 changes: 1 addition & 1 deletion src/kibana/components/visualize/spy/_table.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<kbn-agg-table rows="rows" columns="columns" per-page="perPage"></kbn-agg-table>
<kbn-agg-table table="table" per-page="perPage"></kbn-agg-table>
9 changes: 3 additions & 6 deletions src/kibana/components/visualize/spy/_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ define(function (require) {
'esResp'
], function () {
if (!$scope.vis || !$scope.esResp) {
$scope.rows = $scope.columns = null;
return;
$scope.table = null;
} else {
$scope.table = tabifyAggResponse($scope.vis, $scope.esResp, { canSplit: false });
}

var tabbed = tabifyAggResponse($scope.vis, $scope.esResp, { canSplit: false });
$scope.rows = tabbed.rows;
$scope.columns = tabbed.columns;
});
}
};
Expand Down
54 changes: 1 addition & 53 deletions src/kibana/components/visualize/visualize.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ visualize {

.visualize-chart {
.flex(1, 1);
overflow: hidden;
overflow: auto;

&.spy-visible {
margin-bottom: 10px;
Expand Down Expand Up @@ -93,58 +93,6 @@ visualize-spy {
height: auto;
}

// this is the default, double-arrow sort that is just a hint to the user that they can sort
.visualize-table {
.display(flex);
.flex(1, 1, auto);
.flex-direction(column);

&-paginated-table {
.flex(1, 1, auto);
overflow: auto;

th i.fa-sort {
color: @gray-light;
}

.visualize-table-right,
td.numeric-value {
text-align: right;
}
}

&-controls {
.flex(0, 0, auto);
.display(flex);
.align-items(center);
margin: 10px 5px;

> paginate-controls {
.flex(1, 0, auto);
margin: 0;
padding: 0;
}
}
}

.visualize-csv-options {
.form-control {
padding: 0px 6px;
height: auto;
}
label {
margin: 0 10px;
padding: 0;
font-weight: normal;
}
.visualize-csv-separator {
width: 1.5em;
}
button[type=submit] {
margin-left: 5px;
}
}

.visualize-spy-nav {
margin-top: 10px;
margin-bottom: 10px;
Expand Down
54 changes: 54 additions & 0 deletions src/kibana/services/compile_recursive_directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
define(function (require) {
var _ = require('lodash');

/**
* Angular can't render directives that render themselves recursively:
* http://stackoverflow.com/a/18609594/296172
*/

require('modules')
.get('kibana')
.service('compileRecursiveDirective', function ($compile) {
return {
/**
* Manually compiles the element, fixing the recursion loop.
* @param element
* @param [link] A post-link function, or an object with function(s) registered via pre and post properties.
* @returns An object containing the linking functions.
*/
compile: function (element, link) {
// Normalize the link parameter
if (_.isFunction(link)) {
link = {
post: link
};
}

// Break the recursion loop by removing the contents
var contents = element.contents().remove();
var compiledContents;
return {
pre: (link && link.pre) ? link.pre : null,
/**
* Compiles and re-adds the contents
*/
post: function (scope, element) {
// Compile the contents
if (!compiledContents) {
compiledContents = $compile(contents);
}
// Re-add the compiled contents to the element
compiledContents(scope, function (clone) {
element.append(clone);
});

// Call the post-linking function, if any
if (link && link.post) {
link.post.apply(null, arguments);
}
}
};
}
};
});
});
7 changes: 1 addition & 6 deletions src/kibana/styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@
// FontAwesome fills for glyphicons in bootstrap components
@import "./_glyphicons.less";

// Our CSS spinner
@import "./_spinner.less";

// Pagniation directive
@import "./_pagination.less";

// custom control style
@import "./_navbar.less";
@import "./_sidebar.less";
@import "./_truncate.less";
Expand Down Expand Up @@ -408,4 +403,4 @@ style-compile {
display: none;
}

@import '../components/filter_bar/filter_bar.less';
@import '../components/filter_bar/filter_bar.less';
2 changes: 1 addition & 1 deletion tasks/config/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
'<%= plugins %>/visualize/styles/main.less',
'<%= plugins %>/visualize/styles/visualization.less',
'<%= plugins %>/visualize/styles/main.less',
'<%= plugins %>/table_vis/styles/table_vis.less'
'<%= plugins %>/table_vis/table_vis.less'
],
expand: true,
ext: '.css',
Expand Down
3 changes: 2 additions & 1 deletion tasks/config/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = function (grunt) {
less: {
files: [
'<%= app %>/**/styles/**/*.less',
'<%= plugins %>/**/styles/**/*.less',
'<%= plugins %>/*/styles/**/*.less',
'<%= plugins %>/*/*.less',
'<%= app %>/**/components/**/*.less',
'<%= app %>/**/components/vislib/components/styles/**/*.less'
],
Expand Down

4 comments on commit 030abd7

@randavidovitz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you broke the code because you didn't include lesshat.less....
Really important to check before commit

@spalger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@randavidovitz can you clarify what's broken? I'm not having any issues.

@randavidovitz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first i got error on lesshat.less not found (i copied manually), than i got the following error:

Running "less:src" (less) task
File C:/Projects/Private/kibana_dev/src/kibana/components/agg_table/agg_table.css created.
File C:/Projects/Private/kibana_dev/src/kibana/components/agg_table/lesshat.csscreated.

FileError: '../bower_components/bootstrap/less/mixins.less' wasn't found in C:\Projects\Private\kibana_dev\src\kibana\styles_bootstrap.less on line 7, column 1:
6 // Mixins
7 @import "@{bs-less-dir}/mixins.less";
8
Warning: Error compiling C:/Projects/Private/kibana_dev/src/kibana/components/filter_bar/filter_bar.less Use --force to continue.

Aborted due to warnings.

Could it be that there are missing files ? (or am i missing some prereq)?

@spalger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, looks like you've renamed the bootstrap file from C:\Projects\Private\kibana_dev\src\kibana\styles\_bootstrap.less to C:\Projects\Private\kibana_dev\src\kibana\styles_bootstrap.less. If that is the case then the relative paths would need to be updated.

Maybe I could help better if you described what you're trying to accomplish.

If you're just trying to get the development environment setup, then you shouldn't have any problem. Maybe you should start over and copy paste the entire log of what happens into a gist. Here are the following steps I would try to run, using cygwin or something similar.

git co [email protected]:elasticsearch/kibana.git
cd kibana
npm install
bower install
grunt dev

Sorry you're having issues, none of the core developers use Windows, so the process may be a bit broken. Hopefully we can figure out the issue and document it for others :)

Please sign in to comment.