Commit c09cd4ba by jifwin

make load on scroll configurable and use debouce

parent a3019a97
......@@ -36,6 +36,7 @@ export class DashboardModel {
meta: any;
events: any;
editMode: boolean;
loadOnScroll: boolean;
constructor(data, meta?) {
if (!data) {
......@@ -64,6 +65,7 @@ export class DashboardModel {
this.version = data.version || 0;
this.links = data.links || [];
this.gnetId = data.gnetId || null;
this.loadOnScroll = data.loadOnScroll || false;
this.rows = [];
if (data.rows) {
......
......@@ -61,6 +61,12 @@
checked="dashboard.hideControls"
label-class="width-11">
</gf-form-switch>
<gf-form-switch class="gf-form"
label="Load on scroll"
tooltip="Load panels as they become visible"
checked="dashboard.loadOnScroll"
label-class="width-11">
</gf-form-switch>
</div>
</div>
......
......@@ -74,13 +74,14 @@ class MetricsPanelCtrl extends PanelCtrl {
// ignore fetching data if another panel is in fullscreen
if (this.otherPanelInFullscreenMode()) { return; }
if (!this.scope.$$childHead || (!this.scope.$$childHead.isVisible() && !this.isRenderGraph())) {
this.scope.$$childHead.needsRefresh = true;
return;
if (this.scope.ctrl.dashboard.loadOnScroll) {
if (!this.scope.$$childHead || (!this.scope.$$childHead.isVisible() && !this.isRenderGraph())) {
this.scope.$$childHead.needsRefresh = true;
return;
}
this.scope.$$childHead.needsRefresh = false;
}
this.scope.$$childHead.needsRefresh = false;
// if we have snapshot data use that
if (this.panel.snapshotData) {
this.updateTimeRange();
......
......@@ -184,7 +184,6 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) {
}
});
var getDataPromise = null;
scope.needsRefresh = false;
scope.isVisible = function () {
......@@ -192,16 +191,11 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) {
return (0 < position.top) && (position.top < window.innerHeight);
};
$document.bind('scroll', function () {
if (getDataPromise) {
$timeout.cancel(getDataPromise);
$document.bind('scroll', _.debounce(function () {
if (scope.ctrl.dashboard.loadOnScroll && scope.needsRefresh) {
scope.ctrl.refresh();
}
if (scope.needsRefresh) {
getDataPromise = $timeout(function () {
scope.ctrl.refresh();
}, 250);
}
});
}, 250));
}
};
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment