From: Bill Erickson Date: Tue, 27 Nov 2018 17:47:13 +0000 (-0500) Subject: place holds cont. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=bba0c736e7f229453ca33f5f92b0616989c29a39;p=working%2FEvergreen.git place holds cont. Signed-off-by: Bill Erickson --- 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 8e09a274c9..7b6cae8880 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 @@ -183,9 +183,9 @@
Override
- +
- + {{iconFormatLabel(code)}}
-
{{ctx.fleshedTarget.bibSummary.display.author}}
+
{{ctx.holdMeta.bibSummary.display.author}}
- - {{ctx.fleshedTarget.volume.label()}} + + {{ctx.holdMeta.volume.label()}}
- - {{ctx.fleshedTarget.copy.barcode()}} + + {{ctx.holdMeta.copy.barcode()}}
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 616060de0c..5c59508c38 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 @@ -18,7 +18,7 @@ import {HoldService, HoldRequest, HoldRequestTarget} import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; class HoldContext { - fleshedTarget: HoldRequestTarget; + holdMeta: HoldRequestTarget; holdTarget: number; lastRequest: HoldRequest; canOverride?: boolean; @@ -46,7 +46,6 @@ export class HoldComponent implements OnInit { activeDate: string; holdContexts: HoldContext[]; - recordIds: number[]; recordSummaries: BibRecordSummary[]; currentUserBarcode: string; @@ -114,9 +113,10 @@ export class HoldComponent implements OnInit { // Load the bib, call number, copy, etc. data associated with each target. getTargetMeta() { - this.holdContexts.forEach(ctx => { - this.holds.getHoldTargetMeta(this.holdType, ctx.holdTarget) - .then(fleshedTarget => ctx.fleshedTarget = fleshedTarget); + this.holds.getHoldTargetMeta(this.holdType, this.holdTargets) + .subscribe(meta => { + this.holdContexts.filter(ctx => ctx.holdTarget === meta.target) + .forEach(ctx => ctx.holdMeta = meta); }); } diff --git a/Open-ILS/src/eg2/src/app/staff/share/hold.service.ts b/Open-ILS/src/eg2/src/app/staff/share/hold.service.ts index a647e6f28f..7f4b216136 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/hold.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/hold.service.ts @@ -4,6 +4,7 @@ import {Injectable, EventEmitter} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {map} from 'rxjs/operators/map'; +import {mergeMap} from 'rxjs/operators/mergeMap'; import {IdlObject} from '@eg/core/idl.service'; import {NetService} from '@eg/core/net.service'; import {PcrudService} from '@eg/core/pcrud.service'; @@ -12,12 +13,14 @@ import {AuthService} from '@eg/core/auth.service'; import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.service'; +// Response from a place-holds API call. export interface HoldRequestResult { success: boolean; holdId?: number; evt?: EgEvent; }; +// Values passed to the place-holds API call. export interface HoldRequest { holdType: string; holdTarget: number; @@ -35,16 +38,22 @@ export interface HoldRequest { result?: HoldRequestResult }; -// A fleshed hold request target blob with whatever data is -// available for each hold type / target. +// A fleshed hold request target object containing whatever data is +// available for each hold type / target. E.g. a TITLE hold will +// not have a value for 'volume', but a COPY hold will, since all +// copies have volumes. Every HoldRequestTarget will have a bibId and +// bibSummary. export interface HoldRequestTarget { - metarecord?: IdlObject, - recordId?: number, - bibSummary?: BibRecordSummary, - part?: IdlObject, - volume?: IdlObject, - copy?: IdlObject, - issuance?: IdlObject + target: number; + metarecord?: IdlObject; + bibrecord?: IdlObject; + bibId?: number; + bibSummary?: BibRecordSummary; + part?: IdlObject; + volume?: IdlObject; + copy?: IdlObject; + issuance?: IdlObject; + metarecord_filters?: any; } @Injectable() @@ -109,54 +118,24 @@ export class HoldService { )); } - addRecordSummary(target: HoldRequestTarget): Promise { - return this.bib.getBibSummary(target.recordId).toPromise() - .then(sum => { - target.bibSummary = sum; - return target; - }); - } + getHoldTargetMeta(holdType: string, holdTarget: number | number[], + orgId?: number): Observable { + + const targetIds = [].concat(holdTarget); - getHoldTargetMeta(holdType: string, - holdTarget: number): Promise { - - const target: HoldRequestTarget = {}; - - switch (holdType) { - - case 'M': // TODO - break; - - case 'T': - target.recordId = holdTarget; - return this.addRecordSummary(target); - - case 'P': // TODO - break; - - case 'V': - return this.pcrud.retrieve('acn', holdTarget).toPromise() - .then(vol => { - target.volume = vol; - target.recordId = vol.record(); - return this.addRecordSummary(target); - }); - - case 'I': // TODO - break; - - case 'C': - case 'R': - case 'F': - return this.pcrud.retrieve('acp', holdTarget, - {flesh: 1, flesh_fields: {'acp': ['call_number']}} - ).toPromise().then(copy => { - target.copy = copy; - target.volume = copy.call_number(); - target.recordId = copy.call_number().record(); - return this.addRecordSummary(target); - }); - } + return this.net.request( + 'open-ils.circ', + 'open-ils.circ.hold.get_metadata', + holdType, targetIds, orgId + ).pipe(mergeMap(meta => { + const target: HoldRequestTarget = meta; + target.bibId = target.bibrecord.id(); + return this.bib.getBibSummary(target.bibId) + .pipe(map(sum => { + target.bibSummary = sum; + return target; + })); + })); } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm index dcbe7dda4f..77868503f3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm @@ -3502,12 +3502,13 @@ sub find_hold_mvr { my $volume; my $issuance; my $part; + my $metarecord; my $no_mvr = $args->{suppress_mvr}; if( $hold->hold_type eq OILS_HOLD_TYPE_METARECORD ) { - my $mr = $e->retrieve_metabib_metarecord($hold->target) + $metarecord = $e->retrieve_metabib_metarecord($hold->target) or return $e->event; - $tid = $mr->master_record; + $tid = $metarecord->master_record; } elsif( $hold->hold_type eq OILS_HOLD_TYPE_TITLE ) { $tid = $hold->target; @@ -3553,7 +3554,8 @@ sub find_hold_mvr { # TODO return metarcord mvr for M holds my $title = $e->retrieve_biblio_record_entry($tid); - return ( ($no_mvr) ? undef : $U->record_to_mvr($title), $volume, $copy, $issuance, $part, $title ); + return ( ($no_mvr) ? undef : $U->record_to_mvr($title), + $volume, $copy, $issuance, $part, $title, $metarecord); } __PACKAGE__->register_method( @@ -4505,4 +4507,89 @@ sub copy_has_holds_count { return 0; } +__PACKAGE__->register_method( + method => "hold_metadata", + api_name => "open-ils.circ.hold.get_metadata", + authoritative => 1, + stream => 1, + signature => { + desc => q/ + Returns a stream of objects containing whatever bib, + volume, etc. data is available to the specific hold + type and target. + /, + params => [ + {desc => 'Hold Type', type => 'string'}, + {desc => 'Hold Target(s)', type => 'number or array'}, + {desc => 'Context org unit (optional)', type => 'number'} + ], + return => { + desc => q/ + Stream of hold metadata objects. + /, + type => 'object' + } + } +); + +sub hold_metadata { + my ($self, $client, $hold_type, $hold_targets, $org_id) = @_; + + $hold_targets = [$hold_targets] unless ref $hold_targets; + + my $e = new_editor(); + for my $target (@$hold_targets) { + + # create a dummy hold for find_hold_mvr + my $hold = Fieldmapper::action::hold_request->new; + $hold->hold_type($hold_type); + $hold->target($target); + + my (undef, $volume, $copy, $issuance, $part, $bre, $metarecord) = + find_hold_mvr($e, $hold, {suppress_mvr => 1}); + + $bre->clear_marc; # avoid bulk + + my $meta = { + target => $target, + copy => $copy, + volume => $volume, + issuance => $issuance, + part => $part, + bibrecord => $bre, + metarecord => $metarecord, + metarecord_filters => {} + }; + + # If this is a bib hold or metarecord hold, also return the + # available set of MR filters (AKA "Holdable Formats") for the + # hold. For bib holds these may be used to upgrade the hold + # from a bib to metarecord hold. + if ($hold_type eq 'T') { + my $map = $e->search_metabib_metarecord_source_map( + {source => $meta->{bibrecord}->id})->[0]; + + if ($map) { + $meta->{metarecord} = + $e->retrieve_metabib_metarecord($map->metarecord); + } + } + + if ($meta->{metarecord}) { + + my ($filters) = + $self->method_lookup('open-ils.circ.mmr.holds.filters') + ->run($meta->{metarecord}->id, $org_id); + + if ($filters) { + $meta->{metarecord_filters} = $filters->{metarecord}; + } + } + + $client->respond($meta); + } + + return undef; +} + 1;