From 064788babfdd25024b15d730fcccad2389665f5d Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 29 Jun 2023 15:07:04 -0400 Subject: [PATCH] Bug 21246: Extend the 'Last patron' navigation feature to 'Last 10 patrons' This retains the "last patron" link, but extends it to add a dropdown containg the last 10 patrons. A future enhancement to control how many patrons to retain would complement this well. 1) Enable showLastPatron 2) Visit two patrons details pages 3) Note "Last patron" link displays and links to the last visited patron 4) Log out 5) Apply this patch 6) Log in 7) Visit the patron details page for a few patrons 8) Note the "Last patron" link behaves as is did previously 9) Note the split button has a pulldown with the other previous patrons 10) Verify that only the last 10 patrons are retained in the pulldown 11) Verify that if you visit a patron who is already in the list they get moved to the top of the list Signed-off-by: Sam Lau Signed-off-by: Tomas Cohen Arazi --- .../intranet-tmpl/prog/css/src/_header.scss | 11 +--- .../prog/en/includes/last-borrower.inc | 13 ++++- .../intranet-tmpl/prog/js/staff-global.js | 52 +++++++++++++------ 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/_header.scss b/koha-tmpl/intranet-tmpl/prog/css/src/_header.scss index 0007d2a5dd..946ce293d2 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/_header.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/_header.scss @@ -288,24 +288,15 @@ a.navbar-toggle { #lastborrower-window { display: none; - background-color: $background-color-primary; - box-shadow: 1px 1px 1px 0 #999; - color: #FFFFFF; - padding: .2em; - border-radius: 5px 5px 5px 5px; > * { padding: 0 .4em; } } -#lastborrower-remove { - cursor: pointer; - border-left: 1px solid #fff; -} - #lastborrowerlink { color: #FFFFFF; + background-color: $background-color-primary; } @media (max-width: 768px) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/last-borrower.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/last-borrower.inc index 61dec6b700..7bd739bb4e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/last-borrower.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/last-borrower.inc @@ -1,4 +1,13 @@
- -
+
+ Last patron + + +
diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index 86792041af..97267f3557 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -163,20 +163,43 @@ $(document).ready(function() { $("#catalog-search-dropdown a").toggleClass("catalog-search-dropdown-hover"); }); - if ( localStorage.getItem("lastborrowernumber") ){ - if( $("#hiddenborrowernumber").val() != localStorage.getItem("lastborrowernumber") ) { - $("#lastborrowerlink").show(); - $("#lastborrowerlink").prop("title", localStorage.getItem("lastborrowername") + " (" + localStorage.getItem("lastborrowercard") + ")"); - $("#lastborrowerlink").prop("href", "/cgi-bin/koha/circ/circulation.pl?borrowernumber=" + localStorage.getItem("lastborrowernumber")); - $("#lastborrower-window").css("display", "inline-flex"); + if ( localStorage.getItem("previousPatrons") || $("#hiddenborrowernumber").val() ){ + var previous_patrons = []; + if ( localStorage.getItem("previousPatrons") ) { + previous_patrons = JSON.parse(localStorage.getItem("previousPatrons")); } - } - if( !localStorage.getItem("lastborrowernumber") || ( $("#hiddenborrowernumber").val() != localStorage.getItem("lastborrowernumber") && localStorage.getItem("currentborrowernumber") != $("#hiddenborrowernumber").val())) { - if( $("#hiddenborrowernumber").val() ){ - localStorage.setItem("lastborrowernumber", $("#hiddenborrowernumber").val() ); - localStorage.setItem("lastborrowername", $("#hiddenborrowername").val() ); - localStorage.setItem("lastborrowercard", $("#hiddenborrowercard").val() ); + if ( $("#hiddenborrowernumber").val() ) { + // Remove this patron from the list if they are already there + previous_patrons = previous_patrons.filter(function (p) { + return p["borrowernumber"] != $("#hiddenborrowernumber").val(); + }); + + const previous_patron = { + "borrowernumber": $("#hiddenborrowernumber").val(), + "name": $("#hiddenborrowername").val(), + "card": $("#hiddenborrowercard").val() + }; + + previous_patrons.unshift( previous_patron ); + // Limit to last 10 patrons + if ( previous_patrons.length > 10 ) previous_patrons.pop(); + localStorage.setItem("previousPatrons", JSON.stringify(previous_patrons)); + } + + if ( previous_patrons.length ) { + let p = previous_patrons[0]; + $("#lastborrowerlink").show(); + $("#lastborrowerlink").prop("title", `${p["name"]} (${p["card"]})`); + $("#lastborrowerlink").prop("href", `/cgi-bin/koha/circ/circulation.pl?borrowernumber=${p["borrowernumber"]}`); + $("#lastborrower-window").css("display", "inline-flex"); + + previous_patrons.reverse(); + for ( i in previous_patrons ) { + p = previous_patrons[i]; + const el = `
  • ${p["name"]} (${p["card"]})
  • `; + $("#lastBorrowerList").prepend(el); + } } } @@ -224,10 +247,7 @@ $(document).ready(function() { }); function removeLastBorrower(){ - localStorage.removeItem("lastborrowernumber"); - localStorage.removeItem("lastborrowername"); - localStorage.removeItem("lastborrowercard"); - localStorage.removeItem("currentborrowernumber"); + localStorage.removeItem("previousPatrons"); } // http://jennifermadden.com/javascript/stringEnterKeyDetector.html