From a6fa0dcdd5927cc84c634d678e0d6a0a2f1e3506 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 28 Feb 2024 05:26:25 +0000 Subject: [PATCH] Bug 36188: Sort lists by items.dateaccessioned in the staff client When a list is sorted by dateaccessioned it should be ordered descending by default. This is to ensure the newest items are displayed first. Test plan: 1. Apply patches and restart services 2. Go to the Lists module and create a new list 3. Set the 'Sort this list by' dropdown = 'Date accessioned' 4. Add several barcodes to the list belonging to items with a range of different items.dateaccessioned dates 5. Observe the list records are ordered by the 'Date accessioned' column: - Records with the newest dateaccessioned values displayed first. - The items.dateaccessioned value for each title item record is listed in this column. 6. Switch to order dateaccessioned ascending by clicking on the 'Date accessioned' column label - records with the oldest dateaccessioned should be displayed first. 7. Edit the list. Change the 'Sort this list by' dropdown to 'Title' 8. Notice the list records are ordered by the 'Title' column in an ascending order - A-Z alphabetically. Sponsored-By: The Treasury, New Zealand --- .../prog/en/modules/virtualshelves/shelves.tt | 25 +++++++++++++++++++ .../virtualshelves/tables/shelves_results.tt | 2 +- virtualshelves/shelves.pl | 16 +++++++++--- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt index b80a7fbe69d..44656985502 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -315,6 +315,14 @@ [% END %] Call number + [% IF sortfield == 'dateaccessioned' %] + + [% ELSE %] + + [% END %] + Date accessioned + + [% FOREACH itemsloo IN itemsloop %] @@ -383,6 +391,17 @@ [% END # /FOREACH item %] + + + [% END #/FOREACH itemsloo %] @@ -452,6 +471,11 @@ [% ELSE %] [% END %] + [% IF shelf.sortfield == "dateaccessioned" %] + + [% ELSE %] + + [% END %]
  • @@ -526,6 +550,7 @@ + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt index a25ee522592..ecd6e3687f7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt @@ -20,7 +20,7 @@ "dt_owner": "[% d.firstname | html | $To %] [% d.surname | html | $To %]", "dt_sortby": - [% IF d.sortby == "author" %]"Author"[% ELSIF d.sortby == "copyrightdate" %]"Year"[% ELSIF d.sortby == "itemcallnumber" %]"Call number"[% ELSIF d.sortby == "dateadded" %]"Date added"[% ELSE %]"Title"[% END %], + [% IF d.sortby == "author" %]"Author"[% ELSIF d.sortby == "copyrightdate" %]"Year"[% ELSIF d.sortby == "itemcallnumber" %]"Call number"[% ELSIF d.sortby == "dateadded" %]"Date added"[% ELSIF d.sortby == "dateaccessioned" %]"Date accessioned"[% ELSE %]"Title"[% END %], "dt_created_on": "[% d.created_on | $KohaDates %]", "dt_modification_time": diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index a4a6e41ec71..2269d053986 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -113,7 +113,7 @@ if ( $op eq 'add_form' ) { if ( $shelf ) { $op = $referer; my $sortfield = $query->param('sortfield'); - $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded ); + $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded dateaccessioned ); if ( $shelf->can_be_managed( $loggedinuser ) ) { $shelf->shelfname( scalar $query->param('shelfname') ); $shelf->sortfield( $sortfield ); @@ -268,9 +268,16 @@ if ( $op eq 'view' ) { if ( $shelf ) { if ( $shelf->can_be_viewed( $loggedinuser ) ) { my $sortfield = $query->param('sortfield') || $shelf->sortfield || 'title'; # Passed in sorting overrides default sorting - $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded ); - my $direction = $query->param('direction') || 'asc'; - $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc'; + $sortfield = 'title' unless grep { $_ eq $sortfield } qw( title author copyrightdate itemcallnumber dateadded dateaccessioned ); + + # If sorting by dateaccessioned set direction to descending by default + my $direction = $query->param('direction'); + if ( $sortfield eq 'dateaccessioned' and $direction ne 'asc' and $direction ne 'desc' ) { + $direction = 'desc'; + } elsif ( $direction ne 'asc' and $direction ne 'desc' ) { + $direction = 'asc'; + } + my ( $rows, $page ); unless ( $query->param('print') ) { $rows = C4::Context->preference('numSearchResults') || 20; @@ -314,6 +321,7 @@ if ( $op eq 'view' ) { $this_item->{part_name} = $biblio->part_name; $this_item->{author} = $biblio->author; $this_item->{dateadded} = $content->dateadded; + $this_item->{dateaccessioned} = $biblio->items->get_column("dateaccessioned"); $this_item->{imageurl} = $itemtype ? C4::Koha::getitemtypeimagelocation( 'intranet', $itemtype->imageurl ) : q{}; $this_item->{description} = $itemtype ? $itemtype->description : q{}; #FIXME Should this be translated_description ? $this_item->{notforloan} = $itemtype->notforloan if $itemtype; -- 2.20.1