Etemplate: Fix push add to an empty nextmatch would leave the 'No matches found' and throw errors for row actions

This commit is contained in:
nathangray 2020-10-09 10:15:17 -06:00
parent 23aea3b42e
commit 855d6defc9
4 changed files with 27 additions and 4 deletions

View File

@ -337,8 +337,13 @@ var et2_dataview_controller = /** @class */ (function () {
if (createdRow && _entry.row) { if (createdRow && _entry.row) {
this._grid.insertRow(_entry.idx, _entry.row); this._grid.insertRow(_entry.idx, _entry.row);
} }
// Remove 'No matches found' row
var row = jQuery(".egwGridView_empty", this._grid.innerTbody).remove();
if (row.length) {
this._selectionMgr.unregisterRow("", 0);
}
// Update index map only for push (autorefresh disabled) // Update index map only for push (autorefresh disabled)
if (this._indexMap[_entry.idx].uid !== _entry.uid) { if (this._indexMap[_entry.idx] && this._indexMap[_entry.idx].uid !== _entry.uid) {
var max = parseInt(Object.keys(this._indexMap).reduce(function (a, b) { return _this._indexMap[a] > _this._indexMap[b] ? a : b; })); var max = parseInt(Object.keys(this._indexMap).reduce(function (a, b) { return _this._indexMap[a] > _this._indexMap[b] ? a : b; }));
for (var idx = max; idx >= _entry.idx; idx--) { for (var idx = max; idx >= _entry.idx; idx--) {
var entry = this._indexMap[idx]; var entry = this._indexMap[idx];
@ -348,8 +353,8 @@ var et2_dataview_controller = /** @class */ (function () {
this._selectionMgr._registeredRows[entry.uid].idx = entry.idx; this._selectionMgr._registeredRows[entry.uid].idx = entry.idx;
} }
} }
this._indexMap[_entry.idx] = _entry;
} }
this._indexMap[_entry.idx] = _entry;
return this.hasData; return this.hasData;
}; };
/** /**

View File

@ -467,8 +467,15 @@ export class et2_dataview_controller
this._grid.insertRow(_entry.idx, _entry.row); this._grid.insertRow(_entry.idx, _entry.row);
} }
// Remove 'No matches found' row
var row = jQuery(".egwGridView_empty",this._grid.innerTbody).remove();
if(row.length)
{
this._selectionMgr.unregisterRow("", 0);
}
// Update index map only for push (autorefresh disabled) // Update index map only for push (autorefresh disabled)
if(this._indexMap[_entry.idx].uid !== _entry.uid) if(this._indexMap[_entry.idx] && this._indexMap[_entry.idx].uid !== _entry.uid)
{ {
let max = parseInt(Object.keys(this._indexMap).reduce((a, b) => this._indexMap[a] > this._indexMap[b] ? a : b)); let max = parseInt(Object.keys(this._indexMap).reduce((a, b) => this._indexMap[a] > this._indexMap[b] ? a : b));
for(let idx = max; idx >= _entry.idx; idx--) for(let idx = max; idx >= _entry.idx; idx--)
@ -481,8 +488,8 @@ export class et2_dataview_controller
this._selectionMgr._registeredRows[entry.uid].idx = entry.idx; this._selectionMgr._registeredRows[entry.uid].idx = entry.idx;
} }
} }
this._indexMap[_entry.idx] = _entry
} }
this._indexMap[_entry.idx] = _entry;
return this.hasData; return this.hasData;
} }

View File

@ -527,6 +527,7 @@ var et2_nextmatch = /** @class */ (function (_super) {
// This will remove the last row! // This will remove the last row!
// That's OK, because grid adds one in this.controller.deleteRow() // That's OK, because grid adds one in this.controller.deleteRow()
this.dataview.grid.setTotalCount(total); this.dataview.grid.setTotalCount(total);
this.controller._selectionMgr.setTotalCount(total);
// Re-enable automatic updating // Re-enable automatic updating
this.dataview.grid.doInvalidate = true; this.dataview.grid.doInvalidate = true;
this.dataview.grid.invalidate(); this.dataview.grid.invalidate();
@ -559,6 +560,7 @@ var et2_nextmatch = /** @class */ (function (_super) {
this.nm.controller.deleteRow(this.uid); this.nm.controller.deleteRow(this.uid);
// Adjust total rows, clean grid // Adjust total rows, clean grid
this.nm.controller._grid.setTotalCount(this.nm.controller._grid._total - _row_ids.length); this.nm.controller._grid.setTotalCount(this.nm.controller._grid._total - _row_ids.length);
this.controller._selectionMgr.setTotalCount(this.nm.controller._grid._total);
} }
}, { type: _type, nm: this_1, uid: uid_1, prefix: this_1.controller.dataStorePrefix }, [_row_ids]); }, { type: _type, nm: this_1, uid: uid_1, prefix: this_1.controller.dataStorePrefix }, [_row_ids]);
return { value: void 0 }; return { value: void 0 };
@ -622,6 +624,7 @@ var et2_nextmatch = /** @class */ (function (_super) {
} }
// Update does not need to increase row count, but refresh_add() adds it in // Update does not need to increase row count, but refresh_add() adds it in
this.controller._grid.setTotalCount(this.controller._grid.getTotalCount() - 1); this.controller._grid.setTotalCount(this.controller._grid.getTotalCount() - 1);
this.controller._selectionMgr.setTotalCount(this.controller._grid.getTotalCount());
return true; return true;
}; };
/** /**
@ -657,6 +660,7 @@ var et2_nextmatch = /** @class */ (function (_super) {
//if(stored?.timestamp >= time) return; //if(stored?.timestamp >= time) return;
// Increase displayed row count or we lose the last row when we add and the total is wrong // Increase displayed row count or we lose the last row when we add and the total is wrong
this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount() + 1); this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount() + 1);
this.nm.controller._selectionMgr.setTotalCount(this.nm.controller._grid.getTotalCount());
// Insert at the top of the list, or where app said // Insert at the top of the list, or where app said
var entry = this.nm.controller._selectionMgr._getRegisteredRowsEntry(this.uid); var entry = this.nm.controller._selectionMgr._getRegisteredRowsEntry(this.uid);
entry.idx = typeof this.index == "number" ? this.index : 0; entry.idx = typeof this.index == "number" ? this.index : 0;
@ -667,6 +671,7 @@ var et2_nextmatch = /** @class */ (function (_super) {
// Delete from internal references // Delete from internal references
this.nm.controller.deleteRow(this.uid); this.nm.controller.deleteRow(this.uid);
this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount() - 1); this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount() - 1);
this.nm.controller._selectionMgr.setTotalCount(this.nm.controller._grid.getTotalCount());
} }
this.nm.egw().dataUnregisterUID(this.uid, this.nm._push_add_callback, this); this.nm.egw().dataUnregisterUID(this.uid, this.nm._push_add_callback, this);
}; };

View File

@ -813,6 +813,8 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// This will remove the last row! // This will remove the last row!
// That's OK, because grid adds one in this.controller.deleteRow() // That's OK, because grid adds one in this.controller.deleteRow()
this.dataview.grid.setTotalCount(total); this.dataview.grid.setTotalCount(total);
this.controller._selectionMgr.setTotalCount(total);
// Re-enable automatic updating // Re-enable automatic updating
this.dataview.grid.doInvalidate = true; this.dataview.grid.doInvalidate = true;
this.dataview.grid.invalidate(); this.dataview.grid.invalidate();
@ -860,6 +862,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// Adjust total rows, clean grid // Adjust total rows, clean grid
this.nm.controller._grid.setTotalCount(this.nm.controller._grid._total- _row_ids.length); this.nm.controller._grid.setTotalCount(this.nm.controller._grid._total- _row_ids.length);
this.controller._selectionMgr.setTotalCount(this.nm.controller._grid._total);
} }
}, {type: _type, nm: this, uid: uid, prefix: this.controller.dataStorePrefix}, [_row_ids] }, {type: _type, nm: this, uid: uid, prefix: this.controller.dataStorePrefix}, [_row_ids]
); );
@ -923,6 +926,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
} }
// Update does not need to increase row count, but refresh_add() adds it in // Update does not need to increase row count, but refresh_add() adds it in
this.controller._grid.setTotalCount(this.controller._grid.getTotalCount()-1); this.controller._grid.setTotalCount(this.controller._grid.getTotalCount()-1);
this.controller._selectionMgr.setTotalCount(this.controller._grid.getTotalCount());
return true; return true;
} }
@ -969,6 +973,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// Increase displayed row count or we lose the last row when we add and the total is wrong // Increase displayed row count or we lose the last row when we add and the total is wrong
this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount()+1); this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount()+1);
this.nm.controller._selectionMgr.setTotalCount(this.nm.controller._grid.getTotalCount());
// Insert at the top of the list, or where app said // Insert at the top of the list, or where app said
var entry = this.nm.controller._selectionMgr._getRegisteredRowsEntry(this.uid); var entry = this.nm.controller._selectionMgr._getRegisteredRowsEntry(this.uid);
@ -981,6 +986,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2
// Delete from internal references // Delete from internal references
this.nm.controller.deleteRow(this.uid); this.nm.controller.deleteRow(this.uid);
this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount()-1); this.nm.controller._grid.setTotalCount(this.nm.controller._grid.getTotalCount()-1);
this.nm.controller._selectionMgr.setTotalCount(this.nm.controller._grid.getTotalCount());
} }
this.nm.egw().dataUnregisterUID(this.uid, this.nm._push_add_callback, this); this.nm.egw().dataUnregisterUID(this.uid, this.nm._push_add_callback, this);
} }