Skip to content

Commit

Permalink
[renderCounter] unify render counting login into directive
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Nov 23, 2016
1 parent 641f9af commit 0c084ac
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
search-source="savedObj.searchSource"
show-spy-panel="chrome.getVisible()"
ui-state="uiState"
render-counter
class="panel-content">
</visualize>

<doc-table ng-switch-when="search"
<doc-table
ng-switch-when="search"
search-source="savedObj.searchSource"
sorting="panel.sort"
columns="panel.columns"
render-counter
class="panel-content"
filter="filter">
</doc-table>
Expand Down
3 changes: 2 additions & 1 deletion src/core_plugins/kibana/public/discover/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ <h2>Searching</h2>
sorting="state.sort"
columns="state.columns"
infinite-scroll="true"
filter="filterQuery">
filter="filterQuery"
render-counter>
</doc-table>

<div ng-if="rows.length == opts.sampleSize" class="discover-table-footer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<div class="vis-editor-canvas" ng-class="{ embedded: !chrome.getVisible() }">
<visualize
vis="vis"
render-counter
ui-state="uiState"
show-spy-panel="chrome.getVisible()"
editable-vis="editableVis"
Expand Down
31 changes: 31 additions & 0 deletions src/ui/public/directives/render_counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import uiModules from 'ui/modules';

uiModules
.get('kibana')
.directive('renderCounter', () => ({
controller($scope, $element) {
let counter = 0;

const increment = () => {
counter += 1;
$element.attr('render-counter', counter);
};

const teardown = () => {
$element.off('renderComplete', increment);
};

const setup = () => {
$element.attr('render-counter', counter);
$element.on('renderComplete', increment);
$scope.$on('$destroy', teardown);
};

this.disable = () => {
$element.attr('render-counter', 'disabled');
teardown();
};

setup();
}
}));
2 changes: 1 addition & 1 deletion src/ui/public/doc_table/doc_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
<div ng-if="hits != null && !hits.length" class="table-vis-error">
<h2><i class="fa fa-meh-o"></i></h2>
<h4>No results found</h4>
</div>
</div>
6 changes: 0 additions & 6 deletions src/ui/public/doc_table/doc_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ uiModules.get('kibana')
$scope.limit += 50;
};

$el.attr('has-render-count', 'true');
$el.attr('render-count', '0');
$el.on('renderComplete', () => {
$el.attr('render-count', parseInt($el.attr('render-count'), 10) + 1);
});

// This exists to fix the problem of an empty initial column list not playing nice with watchCollection.
$scope.$watch('columns', function (columns) {
if (columns.length !== 0) return;
Expand Down
13 changes: 4 additions & 9 deletions src/ui/public/visualize/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ uiModules

return {
restrict: 'E',
require: '?renderCounter',
scope : {
showSpyPanel: '=?',
vis: '=',
Expand All @@ -34,7 +35,7 @@ uiModules
esResp: '=?',
},
template: visualizeTemplate,
link: function ($scope, $el, attr) {
link: function ($scope, $el, attr, renderCounter) {
const minVisChartHeight = 180;

if (_.isUndefined($scope.showSpyPanel)) {
Expand Down Expand Up @@ -72,14 +73,8 @@ uiModules
return legendPositionToVisContainerClassMap[$scope.vis.params.legendPosition];
};

if ($scope.vis.implementsRenderComplete()) {
$el.attr('has-render-count', 'true');
let renderCount = 0;
$el.on('renderComplete', () => {
$el.attr('render-count', ++renderCount);
});
} else {
$el.attr('has-render-count', 'false');
if (renderCounter && !$scope.vis.implementsRenderComplete()) {
renderCounter.disable();
}

$scope.spy = {};
Expand Down

0 comments on commit 0c084ac

Please sign in to comment.