From: Galen Charlton Date: Fri, 12 Jul 2019 14:51:28 +0000 (-0400) Subject: LP#1777207: add duplicate row detection to prepend() X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=68893029f0d45460320ffcb780d3d34ba21cc1ef;p=working%2FEvergreen.git LP#1777207: add duplicate row detection to prepend() This patch ensures that if a visible grid item that might be added via prepend() would duplicate an existing row entry, a full collect() is done instead. This patch also converts a prepend() to a full collect() if sorting is in effect, so we cannot know whether the most recently added item should be displayed in the visible rows otherwise. Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/web/js/ui/default/staff/services/grid.js b/Open-ILS/web/js/ui/default/staff/services/grid.js index a12e47bb25..0d2ce9b677 100644 --- a/Open-ILS/web/js/ui/default/staff/services/grid.js +++ b/Open-ILS/web/js/ui/default/staff/services/grid.js @@ -1328,6 +1328,17 @@ angular.module('egGridMod', } grid.prepend = function(limit) { + var ran_into_duplicate = false; + var sort = grid.dataProvider.sort; + if (sort && sort.length) { + // if sorting is in effect, we have no + // have no way here of knowing which row + // was most recently added nor that it + // belongs on top of the visible set of rows, + // so we default to a full collect() + grid.collect(); + return; + } if (grid.offset > 0) { // if we're prepending, we're forcing the // offset back to zero to display the top @@ -1344,6 +1355,14 @@ angular.module('egGridMod', null, function(item) { if (item) { + var newIdx = grid.indexValue(item); + angular.forEach($scope.items, function(existing) { + if (grid.indexValue(existing) == newIdx) { + console.debug('egGrid.prepend(): refusing to add duplicate item ' + newIdx); + ran_into_duplicate = true; + return; + } + }); $scope.items.unshift(item); if (limit && $scope.items.length > limit) { // this accommodates the checkin grid that @@ -1363,6 +1382,9 @@ angular.module('egGridMod', console.debug('egGrid.prepend() complete'); grid.collecting = false; $scope.selected = angular.copy($scope.selected); + if (ran_into_duplicate) { + grid.collect(); + } }); }