Commit 46da951a authored by Dietmar Maurer's avatar Dietmar Maurer

automatically scroll to end of log

parent 9ece39fb
......@@ -3,6 +3,8 @@ Ext.define('PVE.grig.LogView', {
alias: ['widget.pveLogView'],
scrollToEnd: true,
initComponent : function() {
var me = this;
......@@ -22,26 +24,101 @@ Ext.define('PVE.grig.LogView', {
}
});
var scrollEndMarker = false;
var autoscroll = true;
var scrollToEndFn = function() {
var vertScroller = me.getVerticalScroller();
if (!(vertScroller && vertScroller.scrollEl)) {
return;
}
var vertScrollerEl = vertScroller.scrollEl;
var vertScrollerElDom = vertScrollerEl.dom;
var maxDown = vertScrollerElDom.scrollHeight -
vertScrollerElDom.clientHeight -
vertScrollerElDom.scrollTop;
scrollEndMarker = (maxDown <= 0);
if (me.scrollToEnd && scrollEndMarker) {
autoscroll = true;
}
if (!autoscroll) {
return;
}
vertScroller.scrollByDeltaY(maxDown);
// invalidate last page by removing last entry from cache
store.prefetchData.removeAtKey(store.totalCount - 1);
store.guaranteeRange(store.totalCount - store.pageSize,
store.totalCount - 1);
};
var onScroll = function() {
var scroller = this;
if (me.scrollToEnd && scrollEndMarker) {
autoscroll = false;
}
};
Ext.apply(me, {
store: store,
features: [ {ftype: 'selectable'}],
stateful: false,
verticalScrollerType: 'paginggridscroller',
loadMask: true,
invalidateScrollerOnRefresh: false,
viewConfig: {
loadMask: false,
trackOver: false,
stripeRows: false
},
hideHeaders: true,
columns: [
{ header: "Text", dataIndex: 't', flex: 1 }
]
],
listeners: {
'scrollershow': function(scroller, orientation) {
if (orientation !== 'vertical') {
return;
}
scroller.on('afterrender', function() {
me.mon(scroller.scrollEl, 'scroll', onScroll, scroller);
});
},
'scrollerhide': function(scroller, orientation) {
if (orientation !== 'vertical') {
return;
}
autoscroll = false;
},
}
});
me.callParent();
var load_task = new Ext.util.DelayedTask();
var run_load_task = function() {
if (!store.totalCount) {
store.guaranteeRange(0, store.pageSize - 1);
} else {
scrollToEndFn();
}
load_task.delay(1000, run_load_task);
};
if (me.scrollToEnd) {
run_load_task();
} else {
store.guaranteeRange(0, store.pageSize - 1);
}
me.on('destroy', function() {
load_task.cancel();
});
}
});
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