Commit c09cd4ba by jifwin

make load on scroll configurable and use debouce

parent a3019a97
...@@ -36,6 +36,7 @@ export class DashboardModel { ...@@ -36,6 +36,7 @@ export class DashboardModel {
meta: any; meta: any;
events: any; events: any;
editMode: boolean; editMode: boolean;
loadOnScroll: boolean;
constructor(data, meta?) { constructor(data, meta?) {
if (!data) { if (!data) {
...@@ -64,6 +65,7 @@ export class DashboardModel { ...@@ -64,6 +65,7 @@ export class DashboardModel {
this.version = data.version || 0; this.version = data.version || 0;
this.links = data.links || []; this.links = data.links || [];
this.gnetId = data.gnetId || null; this.gnetId = data.gnetId || null;
this.loadOnScroll = data.loadOnScroll || false;
this.rows = []; this.rows = [];
if (data.rows) { if (data.rows) {
......
...@@ -61,6 +61,12 @@ ...@@ -61,6 +61,12 @@
checked="dashboard.hideControls" checked="dashboard.hideControls"
label-class="width-11"> label-class="width-11">
</gf-form-switch> </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>
</div> </div>
......
...@@ -74,12 +74,13 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -74,12 +74,13 @@ class MetricsPanelCtrl extends PanelCtrl {
// ignore fetching data if another panel is in fullscreen // ignore fetching data if another panel is in fullscreen
if (this.otherPanelInFullscreenMode()) { return; } if (this.otherPanelInFullscreenMode()) { return; }
if (this.scope.ctrl.dashboard.loadOnScroll) {
if (!this.scope.$$childHead || (!this.scope.$$childHead.isVisible() && !this.isRenderGraph())) { if (!this.scope.$$childHead || (!this.scope.$$childHead.isVisible() && !this.isRenderGraph())) {
this.scope.$$childHead.needsRefresh = true; this.scope.$$childHead.needsRefresh = true;
return; return;
} }
this.scope.$$childHead.needsRefresh = false; this.scope.$$childHead.needsRefresh = false;
}
// if we have snapshot data use that // if we have snapshot data use that
if (this.panel.snapshotData) { if (this.panel.snapshotData) {
......
...@@ -184,7 +184,6 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) { ...@@ -184,7 +184,6 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) {
} }
}); });
var getDataPromise = null;
scope.needsRefresh = false; scope.needsRefresh = false;
scope.isVisible = function () { scope.isVisible = function () {
...@@ -192,16 +191,11 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) { ...@@ -192,16 +191,11 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) {
return (0 < position.top) && (position.top < window.innerHeight); return (0 < position.top) && (position.top < window.innerHeight);
}; };
$document.bind('scroll', function () { $document.bind('scroll', _.debounce(function () {
if (getDataPromise) { if (scope.ctrl.dashboard.loadOnScroll && scope.needsRefresh) {
$timeout.cancel(getDataPromise);
}
if (scope.needsRefresh) {
getDataPromise = $timeout(function () {
scope.ctrl.refresh(); 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