place holds continued
authorBill Erickson <berickxx@gmail.com>
Tue, 27 Nov 2018 16:35:01 +0000 (11:35 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 30 Nov 2018 16:34:20 +0000 (11:34 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html
Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts
Open-ILS/src/eg2/src/app/staff/share/hold.service.ts

index 2656c43..8e09a27 100644 (file)
     <div class="col-lg-1" i18n>Override</div>
   </div>
   <div class="row mt-1 ml-1 mr-1" *ngFor="let ctx of holdContexts">
-    <ng-container *ngIf="ctx.bibSummary">
+    <ng-container *ngIf="ctx.fleshedTarget">
       <div class="col-lg-1">
-        <ng-container *ngFor="let code of ctx.bibSummary.attributes.icon_format">
+        <ng-container *ngFor="let code of ctx.fleshedTarget.bibSummary.attributes.icon_format">
           <img class="pr-1" 
             alt="{{iconFormatLabel(code)}}"
             title="{{iconFormatLabel(code)}}"
         </ng-container>
       </div>
       <div class="col-lg-3">
-        <a routerLink="/staff/catalog/record/{{ctx.recordId}}">
-          {{ctx.bibSummary.display.title}}
+        <a routerLink="/staff/catalog/record/{{ctx.fleshedTarget.recordId}}">
+          {{ctx.fleshedTarget.bibSummary.display.title}}
         </a>
       </div>
-      <div class="col-lg-2">{{ctx.bibSummary.display.author}}</div>
+      <div class="col-lg-2">{{ctx.fleshedTarget.bibSummary.display.author}}</div>
       <div class="col-lg-2">
-        <ng-container *ngIf="ctx.volume; else anyValue">
-          {{ctx.volume.label()}}
+        <ng-container *ngIf="ctx.fleshedTarget.volume; else anyValue">
+          {{ctx.fleshedTarget.volume.label()}}
         </ng-container>
       </div>
       <div class="col-lg-1">
-        <ng-container *ngIf="ctx.copy; else anyValue">
-          {{ctx.copy.barcode()}}
+        <ng-container *ngIf="ctx.fleshedTarget.copy; else anyValue">
+          {{ctx.fleshedTarget.copy.barcode()}}
         </ng-container>
       </div>
       <div class="col-lg-2">
index 7da3aba..616060d 100644 (file)
@@ -13,17 +13,13 @@ import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.s
 import {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search-context';
 import {CatalogService} from '@eg/share/catalog/catalog.service';
 import {StaffCatalogService} from '../catalog.service';
-import {HoldService, HoldRequest} from '@eg/staff/share/hold.service';
+import {HoldService, HoldRequest, HoldRequestTarget} 
+    from '@eg/staff/share/hold.service';
 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
 
 class HoldContext {
-    recordId: number;
-    bibSummary: BibRecordSummary;
+    fleshedTarget: HoldRequestTarget;
     holdTarget: number;
-    volume: IdlObject;
-    copy: IdlObject;
-    part: IdlObject;
-    issuance: IdlObject;
     lastRequest: HoldRequest;
     canOverride?: boolean;
 }
@@ -97,7 +93,7 @@ export class HoldComponent implements OnInit {
             return ctx;
         });
 
-        this.findRecords();
+        this.getTargetMeta();
 
         this.org.settings('sms.enable').then(sets => {
             this.smsEnabled = sets['sms.enable']
@@ -117,74 +113,11 @@ export class HoldComponent implements OnInit {
     }
 
     // Load the bib, call number, copy, etc. data associated with each target.
-    findRecords() {
-        
-        switch (this.holdType) {
-
-            case 'T':
-                this.holdContexts.forEach(ctx => ctx.recordId = ctx.holdTarget);
-                this.getRecordSummaries();
-                break;
-
-            case 'V':
-                const volIds = this.holdContexts.map(ctx => ctx.holdTarget);
-                this.pcrud.search('acn', {id: volIds})
-                .subscribe(
-                    vol => {
-                        this.holdContexts.filter(
-                            ctx => ctx.holdTarget === vol.id()
-                        ).forEach(ctx => {
-                            ctx.volume = vol;
-                            ctx.recordId = vol.record();
-                        });
-                    },
-                    err => {},
-                    ()  => this.getRecordSummaries()
-                );
-                break;
-
-            case 'C':
-            case 'R':
-            case 'F':
-                const copyIds = this.holdContexts.map(ctx => ctx.holdTarget);
-                this.pcrud.search('acp', {id: copyIds}, 
-                    {flesh: 1, flesh_fields: {'acp': ['call_number']}
-                ).subscribe(
-                    copy => {
-                        this.holdContexts.filter(
-                            ctx => ctx.holdTarget === copy.id()
-                        ).forEach(ctx => {
-                            ctx.copy = copy;
-                            ctx.volume = copy.call_number();
-                            ctx.recordId = copy.call_number().record();
-                        });
-                    },
-                    err => {},
-                    ()  => this.getRecordSummaries()
-                )
-                break;
-
-            case 'I': // TODO
-                break;
-
-            case 'P': // TODO
-                break;
-        }
-    }
-
-    getRecordSummaries() {
-
-        const ids = this.holdContexts.map(ctx => ctx.recordId);
-
-        this.bib.getBibSummary(ids).subscribe(
-            sum => {
-                this.holdContexts.forEach(ctx => {
-                    if (ctx.recordId === sum.id) {
-                        ctx.bibSummary = sum;
-                    }
-                });
-            }
-        );
+    getTargetMeta() {
+        this.holdContexts.forEach(ctx => {
+            this.holds.getHoldTargetMeta(this.holdType, ctx.holdTarget)
+            .then(fleshedTarget => ctx.fleshedTarget = fleshedTarget);
+        });
     }
 
     holdForChanged() {
index 5651d59..a647e6f 100644 (file)
@@ -4,9 +4,13 @@
 import {Injectable, EventEmitter} from '@angular/core';
 import {Observable} from 'rxjs/Observable';
 import {map} from 'rxjs/operators/map';
+import {IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
+import {PcrudService} from '@eg/core/pcrud.service';
 import {EventService, EgEvent} from '@eg/core/event.service';
 import {AuthService} from '@eg/core/auth.service';
+import {BibRecordService, BibRecordSummary} 
+    from '@eg/share/catalog/bib-record.service';
 
 export interface HoldRequestResult {
     success: boolean;
@@ -27,18 +31,31 @@ export interface HoldRequest {
     smsCarrier?: string;
     thawDate?: string; // ISO date
     frozen?: boolean;
-    //holdableFormats?: {[id: number]: string[]};
+    holdableFormats?: {[id: number]: string[]};
     result?: HoldRequestResult
-    // ...
 };
 
+// A fleshed hold request target blob with whatever data is 
+// available for each hold type / target.
+export interface HoldRequestTarget {
+    metarecord?: IdlObject,
+    recordId?: number,
+    bibSummary?: BibRecordSummary,
+    part?: IdlObject,
+    volume?: IdlObject,
+    copy?: IdlObject,
+    issuance?: IdlObject
+}
+
 @Injectable()
 export class HoldService {
 
     constructor(
         private evt: EventService,
         private net: NetService,
-        private auth: AuthService
+        private pcrud: PcrudService,
+        private auth: AuthService,
+        private bib: BibRecordService,
     ) {}
 
     placeHold(request: HoldRequest): Observable<HoldRequest> {
@@ -56,8 +73,8 @@ export class HoldService {
                 thaw_date:      request.thawDate,
                 frozen:         request.frozen,
                 sms_notify:     request.notifySms,
-                sms_carrier:    request.smsCarrier
-                //holdable_formats_map: request.holdableFormats
+                sms_carrier:    request.smsCarrier,
+                holdable_formats_map: request.holdableFormats
             },
             [request.holdTarget]
         ).pipe(map(
@@ -91,5 +108,55 @@ export class HoldService {
             }
         ));
     }
+
+    addRecordSummary(target: HoldRequestTarget): Promise<HoldRequestTarget> {
+        return this.bib.getBibSummary(target.recordId).toPromise()
+        .then(sum => {
+            target.bibSummary = sum;
+            return target;
+        });
+    }
+
+    getHoldTargetMeta(holdType: string, 
+        holdTarget: number): Promise<HoldRequestTarget> {
+
+        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);
+                });
+        }
+    }
 }