place holds continued
authorBill Erickson <berickxx@gmail.com>
Mon, 19 Nov 2018 23:07:36 +0000 (18:07 -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

index f594ad0..b7857e5 100644 (file)
     <div class="col-lg-1" i18n>Barcode</div>
     <div class="col-lg-3" i18n>Holds Status</div>
   </div>
-  <div class="row mt-1 ml-1 mr-1" *ngFor="let rec of recordSummaries">
-    <div class="col-lg-3">
-      <a routerLink="/staff/catalog/record/{{rec.id}}">{{rec.display.title}}</a>
-    </div>
-    <div class="col-lg-2">{{rec.display.author}}</div>
-    <div class="col-lg-1">{{rec.record.tcn_value()}}</div>
-    <div class="col-lg-2">
-      <ng-container *ngIf="holdType == 'T'">
-        <span class="font-italic">ANY</span>
-      </ng-container>
-    </div>
-    <div class="col-lg-1">
-      <ng-container *ngIf="holdType == 'T' || holdType == 'V'">
-        <span class="font-italic">ANY</span>
-      </ng-container>
-    </div>
-    <div class="col-lg-3">
-      <div class="alert alert-info">Hold Pending</div>
-    </div>
+  <div class="row mt-1 ml-1 mr-1" *ngFor="let ctx of holdContexts">
+    <ng-container *ngIf="ctx.bibSummary">
+      <div class="col-lg-3">
+        <a routerLink="/staff/catalog/record/{{ctx.recordId}}">
+          {{ctx.bibSummary.display.title}}
+        </a>
+      </div>
+      <div class="col-lg-2">{{ctx.bibSummary.display.author}}</div>
+      <div class="col-lg-1">{{ctx.bibSummary.record.tcn_value()}}</div>
+      <div class="col-lg-2">
+        <ng-container *ngIf="holdType == 'T'">
+          <span class="font-italic">ANY</span>
+        </ng-container>
+      </div>
+      <div class="col-lg-1">
+        <ng-container *ngIf="holdType == 'T' || holdType == 'V'">
+          <span class="font-italic">ANY</span>
+        </ng-container>
+      </div>
+      <div class="col-lg-3">
+        <ng-container *ngIf="!ctx.lastRequest">
+          <div class="alert alert-info" i18n>Hold Pending</div>
+        </ng-container>
+        <ng-container *ngIf="ctx.lastRequest">
+          <ng-container *ngIf="ctx.lastRequest.result.success">
+            <div class="alert alert-success" i18n>Hold Succeeded</div>
+          </ng-container>
+          <ng-container *ngIf="!ctx.lastRequest.result.success">
+            <div class="alert alert-error">
+              {{ctx.lastRequest.result.last_event.toString()}}
+            </div>
+          </ng-container>
+        </ng-container>
+      </div>
+    </ng-container>
   </div>
 </div>
 
index 0a34270..ab77e31 100644 (file)
@@ -9,7 +9,14 @@ 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} from '@eg/staff/share/hold.service';
+import {HoldService, HoldRequest} from '@eg/staff/share/hold.service';
+
+class HoldContext {
+    recordId: number;
+    bibSummary: BibRecordSummary;
+    holdTarget: number;
+    lastRequest: HoldRequest;
+}
 
 @Component({
   templateUrl: 'hold.component.html'
@@ -29,6 +36,8 @@ export class HoldComponent implements OnInit {
     phoneValue: string;
     suspend: boolean;
     activeDate: string;
+
+    holdContexts: HoldContext[];
     recordIds: number[];
     recordSummaries: BibRecordSummary[];
 
@@ -47,8 +56,7 @@ export class HoldComponent implements OnInit {
         private staffCat: StaffCatalogService,
         private holds: HoldService
     ) {
-        this.recordIds = [];
-        this.recordSummaries = [];
+        this.holdContexts = [];
     }
 
     ngOnInit() {
@@ -60,9 +68,17 @@ export class HoldComponent implements OnInit {
             this.holdTargets = [this.holdTargets];
         }
 
+        this.holdTargets = this.holdTargets.map(t => Number(t));
         this.holdFor = 'patron';
         this.requestor = this.auth.user();
         this.pickupLib = this.auth.user().ws_ou();
+
+        this.holdContexts = this.holdTargets.map(target => {
+            const ctx = new HoldContext();
+            ctx.holdTarget = target;
+            return ctx;
+        });
+
         this.findRecords();
 
         setTimeout(() => // Focus barcode input
@@ -71,23 +87,30 @@ export class HoldComponent implements OnInit {
 
     findRecords() {
         if (this.holdType === 'T') {
-            this.recordIds = this.holdTargets;
+            this.holdContexts.forEach(ctx => ctx.recordId = ctx.holdTarget);
             this.getRecordSummaries();
         } else {
-            // TODO OTHER HOLD TYPES
+            // TODO BIB IDS FOR OTHER HOLD TYPES
         }
     }
 
     getRecordSummaries() {
-        this.bib.getBibSummary(this.recordIds).subscribe(
-            sum => this.recordSummaries.push(sum),
-            err => {},
-            ()  => {}
-        )
+
+        const ids = this.holdContexts.map(ctx => ctx.recordId);
+
+        this.bib.getBibSummary(ids).subscribe(
+            sum => {
+                this.holdContexts.forEach(ctx => {
+                    console.log(ctx.recordId, sum.id);
+                    if (ctx.recordId === sum.id) {
+                        ctx.bibSummary = sum;
+                    }
+                });
+            }
+        );
     }
 
     holdForChanged() {
-        console.log('placing hold for ' + this.holdFor);
 
         if (this.holdFor === 'patron') {
             if (this.userBarcode) {
@@ -209,6 +232,9 @@ export class HoldComponent implements OnInit {
 
         }).subscribe(request => {
             console.log('hold returned: ', request);
+            const ctx = this.holdContexts.filter(
+                ctx => ctx.holdTarget === request.holdTarget)[0];
+            ctx.lastRequest = request;
             this.placeHolds(idx + 1);
         });
     }