From 030dafc0a7c9bdc6677afe87fa69615068acb4c0 Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 25 Aug 2020 15:57:20 -0600 Subject: [PATCH] Etemplate: Fix some nm / push bugs - Handling for sub-grids - Fix some index issues in selectionMgr causing rows to jump around --- api/js/etemplate/et2_dataview_controller.js | 4 +++ api/js/etemplate/et2_dataview_controller.ts | 5 +++ api/js/etemplate/et2_extension_nextmatch.js | 32 ++++++++++++++++++- api/js/etemplate/et2_extension_nextmatch.ts | 8 ++++- .../et2_extension_nextmatch_controller.js | 10 +++--- .../et2_extension_nextmatch_controller.ts | 12 ++++--- 6 files changed, 61 insertions(+), 10 deletions(-) diff --git a/api/js/etemplate/et2_dataview_controller.js b/api/js/etemplate/et2_dataview_controller.js index 380c5d4068..84ee37d425 100644 --- a/api/js/etemplate/et2_dataview_controller.js +++ b/api/js/etemplate/et2_dataview_controller.js @@ -354,8 +354,12 @@ var et2_dataview_controller = /** @class */ (function () { if (this._disable_autorefresh && 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; })); for (var idx = max; idx >= _entry.idx; idx--) { + var entry = this._indexMap[idx]; this._indexMap[idx].idx = idx + 1; this._indexMap[this._indexMap[idx].idx] = this._indexMap[idx]; + if (this._selectionMgr && this._selectionMgr._registeredRows[entry.uid]) { + this._selectionMgr._registeredRows[entry.uid].idx = entry.idx; + } } this._indexMap[_entry.idx] = _entry; } diff --git a/api/js/etemplate/et2_dataview_controller.ts b/api/js/etemplate/et2_dataview_controller.ts index 65e70155a0..8e92858b7a 100644 --- a/api/js/etemplate/et2_dataview_controller.ts +++ b/api/js/etemplate/et2_dataview_controller.ts @@ -491,8 +491,13 @@ export class et2_dataview_controller 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--) { + let entry = this._indexMap[idx]; this._indexMap[idx].idx = idx+1; this._indexMap[this._indexMap[idx].idx] = this._indexMap[idx]; + if(this._selectionMgr && this._selectionMgr._registeredRows[entry.uid]) + { + this._selectionMgr._registeredRows[entry.uid].idx = entry.idx; + } } this._indexMap[_entry.idx] = _entry } diff --git a/api/js/etemplate/et2_extension_nextmatch.js b/api/js/etemplate/et2_extension_nextmatch.js index 9b9b4f9f9e..cf5d356355 100644 --- a/api/js/etemplate/et2_extension_nextmatch.js +++ b/api/js/etemplate/et2_extension_nextmatch.js @@ -572,6 +572,10 @@ var et2_nextmatch = /** @class */ (function (_super) { // Need to delete first as there's a good chance indexes will change in an unknown way // and we can't always find it by UID after due to duplication this.controller.deleteRow(uid); + // Trigger controller to remove from internals so we can ask for new data + this.egw().dataStoreUID(uid, null); + // Stop caring about this ID + this.egw().dataDeleteUID(uid); // Pretend it's a new row, let app tell us where it goes and we'll mark it as new if (!this.refresh_add(uid, et2_nextmatch.UPDATE)) { // App did not want the row, or doesn't know where it goes but we've already removed it... @@ -598,7 +602,7 @@ var et2_nextmatch = /** @class */ (function (_super) { // workaround for datagrid deleting the last row, see ticket #48204 // if we only have a couple of rows, do a full refresh instead if (this.controller.getTotalCount() < 15 && type != et2_nextmatch.UPDATE) { - return false; + // return false; } // No add, do a full refresh if (index === false) { @@ -651,6 +655,32 @@ var et2_nextmatch = /** @class */ (function (_super) { } return { ids: [], all: false }; }; + /** + * Log some debug information about internal values + */ + et2_nextmatch.prototype.spillYourGuts = function () { + var guts = function (controller) { + console.log("Controller:", controller); + console.log("Controller indexMap:", controller._indexMap); + console.log("Grid:", controller._grid); + console.log("Selection Manager:", controller._selectionMgr); + console.log("Selection registered rows:", controller._selectionMgr._registeredRows); + if (controller && controller._children.length > 0) { + console.groupCollapsed("Sub-grids"); + var child_index = 0; + for (var _i = 0, _a = controller._children; _i < _a.length; _i++) { + var child = _a[_i]; + console.groupCollapsed("Child " + (++child_index)); + guts(child); + console.groupEnd(); + } + console.groupEnd(); + } + }; + console.group("Nextmatch internals"); + guts(this.controller); + console.groupEnd(); + }; /** * Event handler for when the selection changes * diff --git a/api/js/etemplate/et2_extension_nextmatch.ts b/api/js/etemplate/et2_extension_nextmatch.ts index a77c529ffe..f2f99bd636 100644 --- a/api/js/etemplate/et2_extension_nextmatch.ts +++ b/api/js/etemplate/et2_extension_nextmatch.ts @@ -865,6 +865,12 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2 // and we can't always find it by UID after due to duplication this.controller.deleteRow(uid); + // Trigger controller to remove from internals so we can ask for new data + this.egw().dataStoreUID(uid,null); + + // Stop caring about this ID + this.egw().dataDeleteUID(uid); + // Pretend it's a new row, let app tell us where it goes and we'll mark it as new if(!this.refresh_add(uid, et2_nextmatch.UPDATE)) { @@ -896,7 +902,7 @@ export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable, et2 // if we only have a couple of rows, do a full refresh instead if (this.controller.getTotalCount() < 15 && type != et2_nextmatch.UPDATE) { - return false; + // return false; } // No add, do a full refresh diff --git a/api/js/etemplate/et2_extension_nextmatch_controller.js b/api/js/etemplate/et2_extension_nextmatch_controller.js index fe8309dd00..20b3fa95c6 100644 --- a/api/js/etemplate/et2_extension_nextmatch_controller.js +++ b/api/js/etemplate/et2_extension_nextmatch_controller.js @@ -163,13 +163,10 @@ var et2_nextmatch_controller = /** @class */ (function (_super) { // Unselect this._selectionMgr.setSelected(uid, false); if (entry && entry.idx !== null) { + this._selectionMgr.unregisterRow(uid, entry.tr); // This will remove the row, but add an empty to the end. // That's OK, because it will be removed when we update the row count this._grid.deleteRow(entry.idx); - // Trigger controller to remove from internals - this.egw.dataStoreUID(uid, null); - // Stop caring about this ID - this.egw.dataDeleteUID(uid); // Remove from internal map delete this._indexMap[entry.idx]; // Update the indices of all elements after the current one @@ -183,6 +180,7 @@ var et2_nextmatch_controller = /** @class */ (function (_super) { reg.idx = entry.idx; if (reg.ao && reg.ao._index) reg.ao._index = entry.idx; + this._selectionMgr._registeredRows[entry.uid].idx = reg.idx; } } // Remove last one, it was moved to mapIndex-1 before increment @@ -190,6 +188,10 @@ var et2_nextmatch_controller = /** @class */ (function (_super) { // Not needed, they share by reference // this._selectionMgr.setIndexMap(this._indexMap); } + for (var _i = 0, _a = this._children; _i < _a.length; _i++) { + var child = _a[_i]; + child.deleteRow(uid); + } }; /** -- PRIVATE FUNCTIONS -- **/ /** diff --git a/api/js/etemplate/et2_extension_nextmatch_controller.ts b/api/js/etemplate/et2_extension_nextmatch_controller.ts index 36c884ec01..8609e124b1 100644 --- a/api/js/etemplate/et2_extension_nextmatch_controller.ts +++ b/api/js/etemplate/et2_extension_nextmatch_controller.ts @@ -192,14 +192,12 @@ export class et2_nextmatch_controller extends et2_dataview_controller implements if(entry && entry.idx !== null) { + this._selectionMgr.unregisterRow(uid, entry.tr); // This will remove the row, but add an empty to the end. // That's OK, because it will be removed when we update the row count this._grid.deleteRow(entry.idx); - // Trigger controller to remove from internals - this.egw.dataStoreUID(uid,null); - // Stop caring about this ID - this.egw.dataDeleteUID(uid); + // Remove from internal map delete this._indexMap[entry.idx]; @@ -216,6 +214,7 @@ export class et2_nextmatch_controller extends et2_dataview_controller implements var reg = this._selectionMgr._getRegisteredRowsEntry(entry.uid); reg.idx = entry.idx; if(reg.ao && reg.ao._index) reg.ao._index = entry.idx; + this._selectionMgr._registeredRows[entry.uid].idx = reg.idx; } } // Remove last one, it was moved to mapIndex-1 before increment @@ -224,6 +223,11 @@ export class et2_nextmatch_controller extends et2_dataview_controller implements // Not needed, they share by reference // this._selectionMgr.setIndexMap(this._indexMap); } + + for(let child of this._children) + { + child.deleteRow(uid); + } } /** -- PRIVATE FUNCTIONS -- **/