From 41bc2fe71d61e90b7d203959deec6d2ff821ef2d Mon Sep 17 00:00:00 2001 From: nathangray Date: Fri, 2 Oct 2020 10:38:49 -0600 Subject: [PATCH] Etemplate: Fix editing entry so it no longer matched current filters would cause missing rows and incorrect total --- api/js/etemplate/et2_extension_nextmatch.js | 26 +++++++++-------- api/js/etemplate/et2_extension_nextmatch.ts | 29 ++++++++++++------- .../et2_extension_nextmatch_controller.js | 2 +- .../et2_extension_nextmatch_controller.ts | 2 +- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/api/js/etemplate/et2_extension_nextmatch.js b/api/js/etemplate/et2_extension_nextmatch.js index 8870408b1d..697160af2a 100644 --- a/api/js/etemplate/et2_extension_nextmatch.js +++ b/api/js/etemplate/et2_extension_nextmatch.js @@ -550,6 +550,12 @@ var et2_nextmatch = /** @class */ (function (_super) { this.type == et2_nextmatch.ADD ? this.nm.refresh_add(this.uid, this.type) : this.nm.refresh_update(this.uid); } + else if (this.type == et2_nextmatch.UPDATE) { + // Remove row from controller + this.nm.controller.deleteRow(this.uid); + // Adjust total rows, clean grid + this.nm.controller._grid.setTotalCount(this.nm.controller._grid._total - _row_ids.length); + } }, { type: _type, nm: this_1, uid: uid_1 }, [_row_ids]); return { value: void 0 }; } @@ -622,34 +628,30 @@ var et2_nextmatch = /** @class */ (function (_super) { */ et2_nextmatch.prototype.refresh_add = function (uid, type) { if (type === void 0) { type = et2_nextmatch.ADD; } - var _a, _b; var index = egw.preference("lazy-update") !== "exact" ? 0 : (this.is_sorted_by_modified() ? 0 : false); // No add, do a full refresh if (index === false) { return false; } - // Increase displayed row count or we lose the last row when we add - this.controller._grid.setTotalCount(this.controller._grid.getTotalCount() + 1); - // Insert at the top of the list, or where app said - var entry = this.controller._selectionMgr._getRegisteredRowsEntry(uid); - entry.idx = typeof index == "number" ? index : 0; - this.controller._insertDataRow(entry, true); - // Set "new entry" class - but it has to stay so register and re-add it after the data is there - (_b = (_a = entry.row) === null || _a === void 0 ? void 0 : _a.tr) === null || _b === void 0 ? void 0 : _b.addClass("new_entry"); var time = new Date().valueOf(); var callback = function (data) { - var _a; if (data) { if (data.class) { data.class += " new_entry"; } // Don't remove if new data has not arrived var stored = egw.dataGetUIDdata(uid); - if (((_a = stored) === null || _a === void 0 ? void 0 : _a.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 + this.controller._grid.setTotalCount(this.controller._grid.getTotalCount() + 1); + // Insert at the top of the list, or where app said + var entry = this.controller._selectionMgr._getRegisteredRowsEntry(uid); + entry.idx = typeof index == "number" ? index : 0; + this.controller._insertDataRow(entry, true); } else { + debugger; // Server didn't give us our row data // Delete from internal references this.controller.deleteRow(uid); diff --git a/api/js/etemplate/et2_extension_nextmatch.ts b/api/js/etemplate/et2_extension_nextmatch.ts index ec047d11c3..b62b2c00e9 100644 --- a/api/js/etemplate/et2_extension_nextmatch.ts +++ b/api/js/etemplate/et2_extension_nextmatch.ts @@ -849,6 +849,14 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2 this.type == et2_nextmatch.ADD ? this.nm.refresh_add(this.uid, this.type) : this.nm.refresh_update(this.uid); } + else if (this.type == et2_nextmatch.UPDATE) + { + // Remove row from controller + this.nm.controller.deleteRow(this.uid); + + // Adjust total rows, clean grid + this.nm.controller._grid.setTotalCount(this.nm.controller._grid._total- _row_ids.length); + } }, {type: _type, nm: this, uid: uid}, [_row_ids] ); return; @@ -932,16 +940,6 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2 return false; } - // Increase displayed row count or we lose the last row when we add - this.controller._grid.setTotalCount(this.controller._grid.getTotalCount()+1); - - // Insert at the top of the list, or where app said - var entry = this.controller._selectionMgr._getRegisteredRowsEntry(uid); - entry.idx = typeof index == "number" ? index : 0; - this.controller._insertDataRow(entry,true); - - // Set "new entry" class - but it has to stay so register and re-add it after the data is there - entry.row?.tr?.addClass("new_entry"); let time = new Date().valueOf(); let callback = function(data) { @@ -953,10 +951,19 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2 } // Don't remove if new data has not arrived let stored = egw.dataGetUIDdata(uid); - 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 + this.controller._grid.setTotalCount(this.controller._grid.getTotalCount()+1); + + // Insert at the top of the list, or where app said + var entry = this.controller._selectionMgr._getRegisteredRowsEntry(uid); + entry.idx = typeof index == "number" ? index : 0; + this.controller._insertDataRow(entry,true); } else { + debugger; // Server didn't give us our row data // Delete from internal references this.controller.deleteRow(uid); diff --git a/api/js/etemplate/et2_extension_nextmatch_controller.js b/api/js/etemplate/et2_extension_nextmatch_controller.js index 20b3fa95c6..6514adf381 100644 --- a/api/js/etemplate/et2_extension_nextmatch_controller.js +++ b/api/js/etemplate/et2_extension_nextmatch_controller.js @@ -159,7 +159,7 @@ var et2_nextmatch_controller = /** @class */ (function (_super) { * @param {string} uid */ et2_nextmatch_controller.prototype.deleteRow = function (uid) { - var entry = this._selectionMgr._getRegisteredRowsEntry(uid); + var entry = Object.values(this._indexMap).find(function (entry) { return entry.uid == uid; }); // Unselect this._selectionMgr.setSelected(uid, false); if (entry && entry.idx !== null) { diff --git a/api/js/etemplate/et2_extension_nextmatch_controller.ts b/api/js/etemplate/et2_extension_nextmatch_controller.ts index 8609e124b1..404f492ba1 100644 --- a/api/js/etemplate/et2_extension_nextmatch_controller.ts +++ b/api/js/etemplate/et2_extension_nextmatch_controller.ts @@ -185,7 +185,7 @@ export class et2_nextmatch_controller extends et2_dataview_controller implements */ deleteRow( uid) { - var entry = this._selectionMgr._getRegisteredRowsEntry(uid); + var entry = Object.values(this._indexMap).find(entry => entry.uid == uid); // Unselect this._selectionMgr.setSelected(uid,false);