LP1889694 catalog record summary condensed WIP
authorBill Erickson <berickxx@gmail.com>
Fri, 31 Jul 2020 14:54:28 +0000 (10:54 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 31 Jul 2020 14:54:28 +0000 (10:54 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/catalog/bib-record.service.ts
Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts
Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm

index d29c4bd..e641a11 100644 (file)
@@ -33,7 +33,7 @@ export class BibRecordSummary {
     net: NetService;
     displayHighlights: {[name: string]: string | string[]} = {};
 
-    constructor(record: IdlObject, orgId: number, orgDepth: number) {
+    constructor(record: IdlObject, orgId: number, orgDepth?: number) {
         this.id = Number(record.id());
         this.record = record;
         this.orgId = orgId;
@@ -149,6 +149,27 @@ export class BibRecordService {
             .map(f => f.name);
     }
 
+    // newstyle
+    getBibSummaries(bibIds: number[],
+        orgId: number, isStaff?: boolean): Observable<BibRecordSummary> {
+
+        if (bibIds.length === 0) { return from([]); }
+
+        let method = 'open-ils.search.biblio.record.catalog_summary';
+        if (isStaff) { method += '.staff'; }
+
+        return this.net.request('open-ils.search', method, orgId, bibIds)
+        .pipe(map(bibSummary => {
+            const summary = new BibRecordSummary(bibSummary.record, orgId);
+            summary.net = this.net; // inject
+            summary.display = bibSummary.display;
+            summary.attributes = bibSummary.attributes;
+            summary.holdCount = bibSummary.hold_count;
+            summary.holdingsSummary = bibSummary.copy_counts;
+            return summary;
+        }));
+    }
+
     // Note when multiple IDs are provided, responses are emitted in order
     // of receipt, not necessarily in the requested ID order.
     getBibSummary(bibIds: number | number[],
index c80d0b2..2e7f164 100644 (file)
@@ -193,8 +193,8 @@ export class CatalogService {
             observable = this.bibService.getMetabibSummary(
                 ctx.currentResultIds(), ctx.searchOrg.id(), depth);
         } else {
-            observable = this.bibService.getBibSummary(
-                ctx.currentResultIds(), ctx.searchOrg.id(), depth);
+            observable = this.bibService.getBibSummaries(
+                ctx.currentResultIds(), ctx.searchOrg.id(), ctx.isStaff);
         }
 
         return observable.pipe(map(summary => {
index 8cb7f03..664d366 100644 (file)
@@ -43,7 +43,6 @@ export class ResultRecordComponent implements OnInit, OnDestroy {
 
     ngOnInit() {
         this.searchContext = this.staffCat.searchContext;
-        this.summary.getHoldCount();
         this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
 
         // Watch for basket changes caused by other components
index 50ed791..c84d4df 100644 (file)
@@ -100,8 +100,7 @@ export class ResultsComponent implements OnInit, OnDestroy {
             this.cat.search(this.searchContext)
             .then(ok => {
                 this.cat.fetchFacets(this.searchContext);
-                this.cat.fetchBibSummaries(this.searchContext)
-                .then(ok2 => this.fleshSearchResults());
+                this.cat.fetchBibSummaries(this.searchContext);
             });
         }
     }
@@ -125,14 +124,6 @@ export class ResultsComponent implements OnInit, OnDestroy {
         return false;
     }
 
-    fleshSearchResults(): void {
-        const records = this.searchContext.result.records;
-        if (!records || records.length === 0) { return; }
-
-        // Flesh the creator / editor fields with the user object.
-        this.bib.fleshBibUsers(records.map(r => r.record));
-    }
-
     searchIsDone(): boolean {
         return this.searchContext.searchState === CatalogSearchState.COMPLETE;
     }
index 159ecd7..3254c4f 100644 (file)
@@ -13,9 +13,6 @@ use Encode;
 
 use OpenSRF::Utils::Logger qw/:logger/;
 
-
-use OpenSRF::Utils::JSON;
-
 use Time::HiRes qw(time sleep);
 use OpenSRF::EX qw(:try);
 use Digest::MD5 qw(md5_hex);
@@ -2744,5 +2741,91 @@ sub mk_copy_query {
 }
 
 
+__PACKAGE__->register_method(
+    method    => 'catalog_record_summary',
+    api_name  => 'open-ils.search.biblio.record.catalog_summary',
+    stream    => 1,
+    max_bundle_count => 1,
+    signature => {
+        desc   => 'Stream of record data suitable for catalog display',
+        params => [
+            {desc => 'Context org unit ID', type => 'number'},
+            {desc => 'Array of Record IDs', type => 'array'}
+        ],
+        return => { 
+            desc => 'Stream of record summary objects'
+        }
+    }
+);
+
+__PACKAGE__->register_method(
+    method    => 'catalog_record_summary',
+    api_name  => 'open-ils.search.biblio.record.catalog_summary.staff',
+    stream    => 1,
+    max_bundle_count => 1,
+    signature => q/see open-ils.search.biblio.record.catalog_summary/
+);
+
+sub catalog_record_summary {
+    my ($self, $client, $org_id, $record_ids) = @_;
+
+    my $e = new_editor();
+
+    for my $rec_id (@$record_ids) {
+
+        my ($bre, $display, $attributes) = get_one_catalog_record($e, $rec_id);
+
+        my $copy_counts = 
+            record_id_to_copy_count($self, $client, $org_id, $rec_id);
+
+        my $hold_count = $U->simplereq(
+            'open-ils.circ',
+            'open-ils.circ.bre.holds.count', $rec_id);
+
+        $client->respond({
+            id => $rec_id,
+            record => $bre,
+            display => $display,
+            attributes => $attributes,
+            copy_counts => $copy_counts,
+            hold_count => $hold_count
+        });
+    }
+
+    return undef;
+}
+
+sub get_one_catalog_record {
+    my ($e, $rec_id) = @_;
+
+    my $bre = $e->retrieve_biblio_record_entry([$rec_id, {
+        flesh => 1,
+        flesh_fields => {
+            bre => [qw/compressed_display_entries mattrs creator editor/]
+        }
+    }]) or return ();
+
+    my $display = {};
+    $display->{$_->name} = OpenSRF::Utils::JSON->JSON2perl($_->value)
+        foreach @{$bre->compressed_display_entries};
+
+    # Create an object of 'mraf' attributes.
+    # Any attribute can be multi so dedupe and array-ify all of them.
+    my $attributes = {};
+    for my $attr (@{$bre->mattrs}) {
+        $attributes->{$attr->attr} = {} unless $attributes->{$attr->attr};
+        $attributes->{$attr->attr}->{$attr->value} = 1; # avoid dupes
+    }
+    $attributes->{$_} = [keys %{$attributes->{$_}}] for keys %$attributes;
+
+    # clear bulk
+    $bre->clear_marc;
+    $bre->clear_mattrs;
+    $bre->clear_compressed_display_entries;
+
+    return ($bre, $display, $attributes);
+}
+
+
 1;