Fix up caching, clearing and filtering, so we cache what we need and clear only what we have to when filtering

Selection still needs work.
This commit is contained in:
Nathan Gray 2014-01-21 15:21:42 +00:00
parent 58e13743fc
commit 4d997bf7c8
6 changed files with 40 additions and 12 deletions

View File

@ -292,7 +292,7 @@ class etemplate_widget_nextmatch extends etemplate_widget
$value['start'] = (int)$queriedRange['start']; $value['start'] = (int)$queriedRange['start'];
$value['num_rows'] = (int)$queriedRange['num_rows']; $value['num_rows'] = (int)$queriedRange['num_rows'];
if($value['num_rows'] == 0) $value['num_rows'] = 20; if($value['num_rows'] == 0) $value['num_rows'] = self::INITIAL_ROWS;
// if app supports parent_id / hierarchy ($value['parent_id'] not empty), set parent_id as filter // if app supports parent_id / hierarchy ($value['parent_id'] not empty), set parent_id as filter
if (($parent_id = $value['parent_id'])) if (($parent_id = $value['parent_id']))
{ {

View File

@ -135,14 +135,22 @@ var et2_dataview_controller = Class.extend({
// TODO: Actually stuff here should be done if the server responds that // TODO: Actually stuff here should be done if the server responds that
// there at all were some changes (needs implementation of "refresh") // there at all were some changes (needs implementation of "refresh")
// Tell the grid not to try and update itself while we do this
this._grid.doInvalidate = false;
if(clear) if(clear)
{ {
this._grid.clear.apply(this._grid,[]); // Scroll to top
this._grid.makeIndexVisible(0);
this._grid.clear();
// Clear the map
this._indexMap = {}
// Clear the queue
this._queue = {};
} }
// Remove all rows which are outside the view range // Remove all rows which are outside the view range
this._grid.cleanup(); this._grid.cleanup();
// ---------
// Get the currently visible range from the grid // Get the currently visible range from the grid
var range = this._grid.getIndexRange(); var range = this._grid.getIndexRange();
@ -357,7 +365,7 @@ var et2_dataview_controller = Class.extend({
// Insert the row into the table -- the same row must never be inserted // Insert the row into the table -- the same row must never be inserted
// twice into the grid, so this function only executes the following // twice into the grid, so this function only executes the following
// code only if it is a newly created row. // code only if it is a newly created row.
if (createdRow) if (createdRow && _entry.row)
{ {
this._grid.insertRow(_entry.idx, _entry.row); this._grid.insertRow(_entry.idx, _entry.row);
} }
@ -421,6 +429,7 @@ var et2_dataview_controller = Class.extend({
if (this._queueTimer === null && !_isUpdate) if (this._queueTimer === null && !_isUpdate)
{ {
var self = this; var self = this;
egw.debug('log', 'Dataview queue: ', _range);
this._queueTimer = window.setTimeout(function () { this._queueTimer = window.setTimeout(function () {
self._flushQueue(false); self._flushQueue(false);
}, ET2_DATAVIEW_FETCH_TIMEOUT); }, ET2_DATAVIEW_FETCH_TIMEOUT);
@ -508,8 +517,12 @@ var et2_dataview_controller = Class.extend({
fetchList.push({ fetchList.push({
"start": 0, "count": 0 "start": 0, "count": 0
}); });
// Disable grid invalidate, or it might request again before we're done
this._grid.doInvalidate = false;
} }
egw.debug("log", "Dataview flush", fetchList);
// Execute all queries // Execute all queries
for (var i = 0; i < fetchList.length; i++) for (var i = 0; i < fetchList.length; i++)
{ {
@ -825,9 +838,15 @@ var et2_dataview_controller = Class.extend({
this.self._selectionMgr.unregisterRow("",0,row.get(0)); this.self._selectionMgr.unregisterRow("",0,row.get(0));
} }
// Now it's OK to invalidate, if it wasn't before
this.self._grid.doInvalidate = true;
// Update the total element count in the grid // Update the total element count in the grid
this.self._grid.setTotalCount(_response.total); this.self._grid.setTotalCount(_response.total);
this.self._selectionMgr.setTotalCount(_response.total); this.self._selectionMgr.setTotalCount(_response.total);
// Schedule an invalidate, in case total is the same
this.self._grid.invalidate();
}, },
/** /**

View File

@ -152,7 +152,6 @@ var et2_dataview_selectionManager = Class.extend(
if (!_noDelete if (!_noDelete
&& this._registeredRows[_uid].state === EGW_AO_STATE_NORMAL) && this._registeredRows[_uid].state === EGW_AO_STATE_NORMAL)
{ {
delete this._indexMap[this._registeredRows[_uid].idx];
delete this._registeredRows[_uid]; delete this._registeredRows[_uid];
} }

View File

@ -89,6 +89,9 @@ var et2_dataview_grid = et2_dataview_container.extend(et2_dataview_IViewRange,
this._invalidateCallback = null; this._invalidateCallback = null;
this._invalidateContext = null; this._invalidateContext = null;
// Flag for stopping invalidate while working
this.doInvalidate = true;
// _map contains a mapping between the grid indices and the elements // _map contains a mapping between the grid indices and the elements
// associated to it. The first element in the array always refers to the // associated to it. The first element in the array always refers to the
// element starting at index zero (being a spacer if the grid currently // element starting at index zero (being a spacer if the grid currently
@ -483,9 +486,15 @@ var et2_dataview_grid = et2_dataview_container.extend(et2_dataview_IViewRange,
window.clearTimeout(this._invalidateTimeout); window.clearTimeout(this._invalidateTimeout);
} }
if(!this.doInvalidate)
{
return;
}
var self = this; var self = this;
var _super = this._super; var _super = this._super;
this._invalidateTimeout = window.setTimeout(function() { this._invalidateTimeout = window.setTimeout(function() {
egw.debug("log","Dataview grid timed invalidate");
// Clear the "_avgHeight" // Clear the "_avgHeight"
self._avgHeight = false; self._avgHeight = false;
self._avgCount = false; self._avgCount = false;
@ -775,7 +784,9 @@ var et2_dataview_grid = et2_dataview_container.extend(et2_dataview_IViewRange,
var vtop = Math.max(0, vcr_top); var vtop = Math.max(0, vcr_top);
var idxStart = Math.floor( var idxStart = Math.floor(
Math.min(cidx + ccnt - 1, Math.min(cidx + ccnt - 1,
cidx + (vtop - elemRange.top) / avg)); cidx + (vtop - elemRange.top) / avg,
this._total
));
// Calculate the end index -- prevent vtop from getting // Calculate the end index -- prevent vtop from getting
// negative (and so idxEnd being smaller than cidx) and // negative (and so idxEnd being smaller than cidx) and
@ -784,7 +795,9 @@ var et2_dataview_grid = et2_dataview_container.extend(et2_dataview_IViewRange,
var vbot = Math.max(0, vcr_bot); var vbot = Math.max(0, vcr_bot);
var idxEnd = Math.ceil( var idxEnd = Math.ceil(
Math.min(cidx + ccnt - 1, Math.min(cidx + ccnt - 1,
cidx + (vbot - elemRange.top) / avg)); cidx + (vbot - elemRange.top) / avg,
this._total
));
// Initial resize while the grid is hidden will give NaN // Initial resize while the grid is hidden will give NaN
// This is an important optimisation, as it is involved in not // This is an important optimisation, as it is involved in not
@ -802,6 +815,7 @@ var et2_dataview_grid = et2_dataview_container.extend(et2_dataview_IViewRange,
if (this._callback) if (this._callback)
{ {
var self = this; var self = this;
egw.debug("log","Dataview grid flag for update: ", {start:idxStart,end:idxEnd});
window.setTimeout(function() { window.setTimeout(function() {
// If row template changes, self._callback might disappear // If row template changes, self._callback might disappear
if(typeof self._callback != "undefined") if(typeof self._callback != "undefined")

View File

@ -400,9 +400,6 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput],
} }
}, this.activeFilters.col_filter, et2_INextmatchHeader); }, this.activeFilters.col_filter, et2_INextmatchHeader);
// Explicitly the total count to zero, we're going to get some new info
this.controller._grid.setTotalCount(0);
// Trigger an update // Trigger an update
this.controller.update(true); this.controller.update(true);
}, },

View File

@ -692,7 +692,6 @@ ul.et2_vfs {
background-color: #FFFE36; background-color: #FFFE36;
border: 1px solid #E1E16D; border: 1px solid #E1E16D;
color: #000000; color: #000000;
display: none;
font-size: 11px; font-size: 11px;
height: 15px; height: 15px;
padding: 4px 10px; padding: 4px 10px;