From 2a48625d9e75fc378470998692cdf67e68006158 Mon Sep 17 00:00:00 2001 From: Llewellyn Marshall Date: Wed, 17 Aug 2022 11:17:08 -0400 Subject: [PATCH] move next operating time into API call, use it from Angular hold placing page to set active date. --- .../src/app/staff/catalog/hold/hold.component.html | 13 +++-- .../src/app/staff/catalog/hold/hold.component.ts | 12 +++++ .../src/perlmods/lib/OpenILS/Application/Actor.pm | 60 ++++++++++++++++++++++ .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 40 ++------------- 4 files changed, 87 insertions(+), 38 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html index df4130e3bb..27078afc1b 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html @@ -90,7 +90,7 @@
-
@@ -102,12 +102,19 @@ -
+
+
+ + +
+
+
+ (onChangeAsIso)="activeDateSelected($event)" [disabled]="!suspend && !suspendTilOpen">
diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts index e24075f25b..27c81cb9a9 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts @@ -64,6 +64,7 @@ export class HoldComponent implements OnInit { notifySms: boolean; smsValue: string; suspend: boolean; + suspendTilOpen: boolean; activeDateStr: string; activeDateYmd: string; activeDate: Date; @@ -419,6 +420,7 @@ export class HoldComponent implements OnInit { this.activeDate = null; this.activeDateStr = null; this.suspend = false; + this.suspendTilOpen = false; if (this.smsCbox) { this.smsCbox.selectedId = null; } // Avoid clearing the barcode in cases where the form is @@ -702,6 +704,16 @@ export class HoldComponent implements OnInit { goBack() { history.back(); } + + nextOpenTime(){ + this.net.request('open-ils.actor', + 'open-ils.actor.org_unit.next_operating_hour',this.pickupLib + ).subscribe(resp => { + console.log(resp); + this.activeDateSelected(resp); + }); + } + } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 4298f2837d..acec076188 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -1474,6 +1474,66 @@ sub get_my_org_path { } __PACKAGE__->register_method( + method => "get_next_operating_hour", + api_name => "open-ils.actor.org_unit.next_operating_hour", + signature => { + params => [ + {type => 'number', desc => 'Context Organizational Unit ID'}, + {type => 'string', desc => 'Date string to start from (optional)'} + ], + return => { desc => 'An ISO8601 formatted date string of the next time the context org unit is operating.'} + } +); + +sub get_next_operating_hour { + my( $self, $client, $org_id, $start_time_str ) = @_; + my $e = new_editor(); + my $start_time; + if(defined($start_time_str)){ + $start_time = DateTime::Format::ISO8601->parse_datetime($start_time_str); + } + else{ + # default to current time if none defined + $start_time = DateTime::Format::ISO8601->new(); + } + my $h = $e->search_actor_hours_of_operation({id => $org_id})->[0]; + my $found = 0; + # look for thaw date up to 1 week in future + for(my $dow = 0;!$found && $dow < 6;$dow++){ + if($dow){ + # need to check another day + # set to first moment of tomorrow + $start_time->add(days => 1); + $start_time->set(hour => 0,minute => 0, second=> 0); + } + my $day_of_week = $start_time->wday; + my $open_time_st = $h->{'dow_'.$day_of_week.'_open'}; + my $close_time_st = $h->{'dow_'.$day_of_week.'_close'}; + # library closed, check back tomorrow + next if($open_time_st eq '00:00:00' and $close_time_st eq '00:00:00'); + my @open_times = split(':',$open_time_st); + my @close_times = split(':',$close_time_st); + # create open/close datetimes based on current thaw date + my $open_time = $start_time->clone->set(hour => @open_times[0],minute => @open_times[1],second => @open_times[2]); + my $close_time = $start_time->clone->set(hour => @open_times[0],minute => @open_times[1],second => @open_times[2]); + if($start_time->is_between($open_time,$close_time)){ + # we found a good time, end loop + $found = 1; + } + else if(DateTime->compare($thaw_dt,$close_time) <= 0){ + # our start is before opening time + # set start to opening time + $start_time->set(hour => $open_times[0],minute => $open_times[1]) + $found = 1; + } + # start falls after closing time, check tomorrow + } + # error, library is never operating + return $e->event unless $found; + return DateTime::Format::ISO8601->format_datetime($start_time); +} + +__PACKAGE__->register_method( method => "retrieve_coordinates", api_name => "open-ils.actor.geo.retrieve_coordinates", signature => { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index e6fe3239e3..a4d7249a0b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1550,41 +1550,11 @@ sub load_place_hold { } elsif ($cgi->param('hold_suspend') =~ /p/) { eval { - #start thaw date at current time - my $thaw_dt = DateTime::Format::ISO8601->new(); - my $thaw_found = 0; - my $h = $e->search_actor_hours_of_operation({id => $cgi->param('pickup_lib') || $self->ctx->{search_ou}})->[0]; - #look for thaw date up to 1 week in future - for(my $dow = 0;!$thaw_found && $dow < 6;$dow++){ - if($dow){ - # need to check another day - # set to first moment of tomorrow - $thaw_dt->add(days => 1); - $thaw_dt->set(hour => 0,minute => 0, second=> 0); - } - my $day_of_week = $thaw_dt->wday; - my $open_time_st = $h->{'dow_'.$day_of_week.'_open'}; - my $close_time_st = $h->{'dow_'.$day_of_week.'_close'}; - # library closed, check back tomorrow - next if($open_time_st eq '00:00:00' and $close_time_st eq '00:00:00'); - my @open_times = split(':',$open_time_st); - my @close_times = split(':',$close_time_st); - # create open/close datetimes based on current thaw date - my $open_time = $thaw_dt->clone->set(hour => @open_times[0],minute => @open_times[1],second => @open_times[2]); - my $close_time = $thaw_dt->clone->set(hour => @open_times[0],minute => @open_times[1],second => @open_times[2]); - if($thaw_dt->is_between($open_time,$close_time)){ - # we found a good time, end loop - $thaw_found = 1; - } - else if(DateTime->compare($thaw_dt,$close_time) <= 0){ - # our thaw date is before opening time - # set thaw date to opening time - $thaw_found->set(hour => $open_times[0],minute => $open_times[1]) - $thaw_found = 1; - } - # thaw date falls after closing time, check tomorrow - } - $ctx->{thaw_date} = $thaw_dt->ymd; + my $thaw_date_str = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.org_unit.next_operating_hour', $cgi->param('pickup_lib') || $self->ctx->{search_ou}); + my $thaw_dt = DateTime::Format::ISO8601->parse_datetime($thaw_date_str); + $ctx->{thaw_date} = $thaw_dt->ymd; $ctx->{frozen} = 1; }; if ($@) { -- 2.11.0