From a2aafc889c35decc30a7ff3cc4e63b47cc6302da Mon Sep 17 00:00:00 2001 From: Dan Briem Date: Wed, 10 May 2023 15:04:27 +0000 Subject: [PATCH] LP#2009281 Recent patrons duplication issues Converts the user ID to a number to avoid duplicates caused by type mismatches. Removes duplicates before the ID is added or the array is trimmed to avoid prematurely removing IDs. To test: 1. Set "Number of Retrievable Recent Patrons" setting to 2 2. Open a patron record 3. Open a different patron record 4. Open Circulation->Retrieve Last Patron 5. Open Circulation->Retrieve Recent Patrons Note: both patrons are present without duplicates Signed-off-by: Dan Briem --- .../src/eg2/src/app/staff/circ/patron/patron.service.ts | 11 ++++------- .../web/js/ui/default/staff/services/patron_search.js | 15 +++++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.service.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.service.ts index 2b69f5967e..b4760029e4 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.service.ts @@ -112,16 +112,13 @@ export class PatronContextService { .then(num => { if (num) { this.maxRecentPatrons = num; } - const patrons: number[] = + let patrons: number[] = this.store.getLoginSessionItem('eg.circ.recent_patrons') || []; + // remove potential existing duplicates + patrons = patrons.filter(id => patronId !== id); patrons.splice(0, 0, patronId); // put this user at front - patrons.splice(this.maxRecentPatrons, 1); // remove excess - - // remove any other occurrences of this user, which may have been - // added before the most recent user. - const idx = patrons.indexOf(patronId, 1); - if (idx > 0) { patrons.splice(idx, 1); } + patrons.splice(this.maxRecentPatrons); // remove excess this.store.setLoginSessionItem('eg.circ.recent_patrons', patrons); }); diff --git a/Open-ILS/web/js/ui/default/staff/services/patron_search.js b/Open-ILS/web/js/ui/default/staff/services/patron_search.js index d2ebe6c3fa..798bd9db12 100644 --- a/Open-ILS/web/js/ui/default/staff/services/patron_search.js +++ b/Open-ILS/web/js/ui/default/staff/services/patron_search.js @@ -134,18 +134,21 @@ function($q , $timeout , $location , egCore, egUser , egConfirmDialog , $locale service.addRecentPatron = function(user_id) { if (service.maxRecentPatrons < 1) return; + // ensure ID is a number if pulled from route data + user_id = Number(user_id); + // no need to re-track same user if (service.current && service.current.id() == user_id) return; var patrons = egCore.hatch.getLoginSessionItem('eg.circ.recent_patrons') || []; - patrons.splice(0, 0, user_id); // put this user at front - patrons.splice(service.maxRecentPatrons, 1); // remove excess - // remove any other occurrences of this user, which may have been - // added before the most recent user. - var idx = patrons.indexOf(user_id, 1); - if (idx > 0) patrons.splice(idx, 1); + // remove potential existing duplicates + patrons = patrons.filter(function(id) { + return user_id !== id + }); + patrons.splice(0, 0, user_id); // put this user at front + patrons.splice(service.maxRecentPatrons); // remove excess egCore.hatch.setLoginSessionItem('eg.circ.recent_patrons', patrons); } -- 2.11.0