From: Llewellyn Marshall Date: Thu, 11 May 2023 20:07:26 +0000 (-0400) Subject: Replace perl/tt2 based circ history download with Javascript and a X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Flew%2Fcirc_history_csv_redo;p=working%2FEvergreen.git Replace perl/tt2 based circ history download with Javascript and a streaming API call to the Circ application. Added a download progress bar to the myOpac page (Bootstrap only). --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm index 6436f79e4d..f17af7df02 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm @@ -222,6 +222,147 @@ sub checkouts_by_user_opac { return $data; } +__PACKAGE__->register_method( + method => "circ_history_count", + api_name => "open-ils.circ.circ_history.count", + notes => q/ + Returns the number of archived circulations for a user + @param auth the auth token of the requestor + @param user_id the user to check + /); + +sub circ_history_count { + my( $self, $client, $auth, $user_id ) = @_; + + my $e = new_editor( authtoken => $auth ); + return $e->event unless $e->checkauth; + + my $user_id = (defined $user_id) ? $user_id : $e->requestor->id; + + if( $e->requestor->id ne $user_id ) { + return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); + } + + my $count = $e->json_query({ + select => { + auch => [{ + column => 'id', + transform => 'count', + aggregate => 1 + }] + }, + from => 'auch', + where => {'+auch' => {usr => $user_id}} + })->[0]->{id}; + + return $count; +} + +__PACKAGE__->register_method( + method => "circ_history_by_user", + api_name => "open-ils.circ.actor.user.circ_history", + stream => 1, + NOTES => <<" NOTES"); + Streams a list of circ history objects with the same + default flesh as MyOPAC's circ history page. + NOTES + +sub circ_history_by_user { + my ($self, $client, $auth, $user_id, $flesh, $limit, $offset) = @_; + + my $e = new_editor( authtoken => $auth ); + return $e->event unless $e->checkauth; + + my $user_id = (defined $user_id) ? $user_id : $e->requestor->id; + + if( $e->requestor->id ne $user_id ) { + return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); + } + + my %limits = (); + $limits{offset} = $offset if defined $offset; + $limits{limit} = $limit if defined $limit; + + my %flesh_ops = ( + flesh => 3, + flesh_fields => { + auch => ['target_copy','source_circ'], + acp => ['call_number','parts'], + acn => ['record','prefix','suffix'] + }, + ); + + $e->xact_begin; + my $circs = $e->search_action_user_circ_history( + [ + {usr => $user_id}, + { # order newest to oldest by default + order_by => {auch => 'xact_start DESC'}, + $flesh ? %flesh_ops : (), + %limits + } + ], + {substream => 1} + ); + $e->rollback; + + unless($flesh){ + for my $circ (@$circs) { + $client->respond( + { + circ => $circ + } + ); + } + return undef; + } + + $e->xact_begin; + my %unapi_cache = (); + for my $circ (@$circs) { + if ($circ->target_copy->call_number->id == -1) { + $client->respond( + { + circ => $circ, + marc_xml => undef # pre-cat copy, use the dummy title/author instead + } + ); + next; + } + my $bre_id = $circ->target_copy->call_number->record->id; + my $unapi; + if (exists $unapi_cache{$bre_id}) { + $unapi = $unapi_cache{$bre_id}; + } else { + my $result = $e->json_query({ + from => [ + 'unapi.bre', $bre_id, 'marcxml','record','{mra}', undef, undef, undef + ] + }); + if ($result) { + $unapi_cache{$bre_id} = $unapi = $result->[0]->{'unapi.bre'}; + } + } + if ($unapi) { + $client->respond( + { + circ => $circ, + marc_xml => $unapi + } + ); + } else { + $client->respond( + { + circ => $circ, + marc_xml => undef # failed, but try to go on + } + ); + } + } + $e->rollback; + + return undef; +} __PACKAGE__->register_method( method => "title_from_transaction", diff --git a/Open-ILS/src/templates-bootstrap/opac/myopac/circ_history.tt2 b/Open-ILS/src/templates-bootstrap/opac/myopac/circ_history.tt2 index e18bdf55eb..e3cd9f542b 100755 --- a/Open-ILS/src/templates-bootstrap/opac/myopac/circ_history.tt2 +++ b/Open-ILS/src/templates-bootstrap/opac/myopac/circ_history.tt2 @@ -1,5 +1,6 @@ [% PROCESS "opac/parts/header.tt2"; PROCESS "opac/parts/misc_util.tt2"; + PROCESS "opac/parts/myopac/circ_history_download.tt2"; PROCESS "opac/parts/myopac/column_sort_support.tt2"; WRAPPER "opac/parts/myopac/base.tt2"; myopac_page = "circ_history" @@ -215,15 +216,11 @@ -
-
- [%- INCLUDE "opac/parts/preserve_params.tt2" %] - [% IF ctx.circs.size > 0 %] - - - [% END %] -
-
+ +
+ [% END %] [% END %] diff --git a/Open-ILS/src/templates/opac/myopac/circ_history.tt2 b/Open-ILS/src/templates/opac/myopac/circ_history.tt2 index afef26a445..d7cfdd6808 100644 --- a/Open-ILS/src/templates/opac/myopac/circ_history.tt2 +++ b/Open-ILS/src/templates/opac/myopac/circ_history.tt2 @@ -1,5 +1,6 @@ [% PROCESS "opac/parts/header.tt2"; PROCESS "opac/parts/misc_util.tt2"; + PROCESS "opac/parts/myopac/circ_history_download.tt2"; PROCESS "opac/parts/myopac/column_sort_support.tt2"; WRAPPER "opac/parts/myopac/base.tt2"; myopac_page = "circs" @@ -46,15 +47,11 @@ [% IF no_next %] class='invisible' [% END %] >[% l('Next') %]
-
- [%- INCLUDE "opac/parts/preserve_params.tt2" %] [% IF ctx.circs.size > 0 %] - - + [% END %]
-
diff --git a/Open-ILS/src/templates/opac/parts/myopac/circ_history_download.tt2 b/Open-ILS/src/templates/opac/parts/myopac/circ_history_download.tt2 new file mode 100644 index 0000000000..92d393c950 --- /dev/null +++ b/Open-ILS/src/templates/opac/parts/myopac/circ_history_download.tt2 @@ -0,0 +1,147 @@ + + + + + + + + + \ No newline at end of file