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 <samalau@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Kyle Hall 2023-06-29 15:07:04 -04:00 committed by Tomas Cohen Arazi
parent fe21bbad2a
commit 064788babf
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
3 changed files with 48 additions and 28 deletions

View file

@ -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) {

View file

@ -1,4 +1,13 @@
<div id="lastborrower-window">
<div id="lastborrower-ref" class="lastborrower"><a id="lastborrowerlink" href="" title=""><i class="fa fa-arrow-right"></i> Last patron</a></div>
<div id="lastborrower-remove" class="lastborrower"><i class="fa fa-times"></i></div>
<div class="btn-group">
<a class="btn btn-default navbar-btn lastborrower" id="lastborrowerlink" href="#" title=""><i class="fa fa-arrow-right"></i> Last patron</a>
<button type="button" data-toggle="dropdown" class="btn btn-default navbar-btn dropdown-toggle" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul id="lastBorrowerList" class="dropdown-menu">
<li role="separator" class="divider"></li>
<li><a id="lastborrower-remove" class="lastborrower" href="#">Clear list</a></li>
</ul>
</div>
</div>

View file

@ -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 = `<li><a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=${p["borrowernumber"]}">${p["name"]} (${p["card"]})</a></li>`;
$("#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