LPXXX Angular Volcopy
authorBill Erickson <berickxx@gmail.com>
Fri, 5 Jun 2020 15:30:13 +0000 (11:30 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 5 Jun 2020 15:30:13 +0000 (11:30 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/routing.module.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.html
Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.ts
Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.service.ts

index 368c30a..fb4f44d 100644 (file)
@@ -6,6 +6,12 @@ const routes: Routes = [{
     path: 'edit/item/:copy_id',
     component: VolCopyComponent
   }, {
+    path: 'edit/callnumber/:vol_id',
+    component: VolCopyComponent
+  }, {
+    path: 'edit/record/:record_id',
+    component: VolCopyComponent
+  }, {
     path: 'edit/session/:session',
     component: VolCopyComponent
   /*
index 4ff4529..115aaf3 100644 (file)
     <ng-container *ngFor="let copyNode of volNode.children; let copyIdx = index">
       <div class="row d-flex mt-1">
         <div class="p-1" [ngStyle]="{flex: flexAt(1)}">
-          <span *ngIf="volIdx == 0">{{orgNode.target.shortname()}}</span>
+          <span *ngIf="copyIdx == 0">{{orgNode.target.shortname()}}</span>
         </div>
         <div class="p-1" [ngStyle]="{flex: flexAt(2)}">
-          <ng-container *ngIf="volIdx == 0">
+          <ng-container *ngIf="copyIdx == 0">
             <input type="number" class="form-control form-control-sm"
               [required]="true"
               [ngModel]="orgNode.children.length"
             (ngModelChange)="applyCopyValue(copyNode.target, 'copy_number', $event)"/>
         </div>
         <div class="p-1" [ngStyle]="{flex: flexAt(10)}">
+          <ng-container *ngIf="!recordHasParts(volNode.target.record())">
+            <label i18n>N/A</label>
+          </ng-container>
+          <ng-container *ngIf="recordHasParts(volNode.target.record())">
             <eg-combobox 
+              [disabled]="bibParts[volNode.target.record()].length == 0"
               [startId]="copyNode.target.parts()[0] ? copyNode.target.parts()[0].id() : null"
               [smallFormControl]="true"
               (onChange)="copyPartChanged(copyNode, $event)">
                 [entryId]="part.id()" [entryLabel]="part.label()">
               </eg-combobox-entry>
             </eg-combobox>
+          </ng-container>
         </div>
       </div>
     </ng-container>
index 684b5a9..2d58cc7 100644 (file)
@@ -82,6 +82,10 @@ export class VolEditComponent implements OnInit {
         );
     }
 
+    recordHasParts(bibId: number): boolean {
+        return this.bibParts[bibId] && this.bibParts[bibId].length > 0;
+    }
+
     flexAt(column: number): number {
         return this.flexSettings[column];
     }
index 623075f..cb4c8dc 100644 (file)
@@ -1,12 +1,13 @@
 import {Component, OnInit, AfterViewInit, ViewChild, Renderer2} from '@angular/core';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {tap} from 'rxjs/operators';
 import {IdlObject} from '@eg/core/idl.service';
 import {OrgService} from '@eg/core/org.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
 import {VolCopyContext} from './volcopy';
 
-const copy_FLESH = {
+const COPY_FLESH = {
     flesh: 1,
     flesh_fields: {
         acp: ['call_number', 'location', 'parts']
@@ -23,7 +24,10 @@ export class VolCopyComponent implements OnInit {
     // Note in multi-record mode this value will be unset.
     recordId: number;
 
-    // Load the editor for a specific copy by ID.
+    // Load specific call number by ID.
+    volId: number;
+
+    // Load specific copy by ID.
     copyId: number;
 
     session: string;
@@ -47,15 +51,11 @@ export class VolCopyComponent implements OnInit {
     }
 
     negotiateRoute(params: ParamMap) {
-        const copyId = +params.get('copy_id');
-        if (copyId) {
-            if (copyId !== this.copyId) {
-                this.copyId = copyId;
-                this.load();
-            }
-        } else {
-            this.copyId = null;
-        }
+        this.recordId = +params.get('record_id') || null;
+        this.volId    = +params.get('vol_id')    || null;
+        this.copyId   = +params.get('copy_id')   || null;
+        this.session  =  params.get('session')   || null;
+        this.load();
     }
 
     load() {
@@ -66,22 +66,58 @@ export class VolCopyComponent implements OnInit {
         .then(_ => this.holdings.fetchCallNumberPrefixes())
         .then(_ => this.holdings.fetchCallNumberSuffixes())
         .then(_ => this.context.sortHoldings())
+        .then(_ => this.setRecordId())
         .then(_ => this.loading = false);
     }
 
+    setRecordId() {
+        if (!this.recordId) {
+            this.recordId = this.context.getRecordId();
+        }
+    }
+
     fetchHoldings(): Promise<any> {
         if (this.copyId) {
-            return this.fetchCopy();
+            return this.fetchCopies(this.copyId);
+        } else if (this.volId) {
+            return this.fetchVols(this.volId);
+        } else if (this.recordId) {
+            return this.fetchRecords(this.recordId);
         }
     }
 
 
-    fetchCopy(): Promise<any> {
-        return this.pcrud.retrieve('acp', this.copyId, copy_FLESH)
-        .toPromise().then(copy => {
-            this.recordId = copy.call_number().record();
-            this.context.findOrCreateCopyNode(copy);
-        });
+    fetchCopies(copyIds: number | number[]): Promise<any> {
+        const ids = [].concat(copyIds);
+        return this.pcrud.search('acp', {id: ids}, COPY_FLESH)
+        .pipe(tap(copy => this.context.findOrCreateCopyNode(copy)))
+        .toPromise();
+    }
+
+    // Fetch call numbers and copies by call number ids.
+    fetchVols(volIds?: number | number[]): Promise<any> {
+        const ids = [].concat(volIds);
+
+        return this.pcrud.search('acn', {id: ids})
+        .pipe(tap(vol => this.context.findOrCreateVolNode(vol)))
+        .pipe(tap(vol => {
+             return this.pcrud.search('acp',
+                {call_number: ids, deleted: 'f'}, COPY_FLESH
+            ).pipe(tap(copy => this.context.findOrCreateCopyNode(copy))
+            ).toPromise();
+        })).toPromise();
+    }
+
+    // Fetch call numbers and copies by record ids.
+    fetchRecords(recordIds: number | number[]): Promise<any> {
+        const ids = [].concat(recordIds);
+
+        return this.pcrud.search('acn',
+            {record: ids, deleted: 'f'},
+            {}, {idlist: true, atomic: true}
+        ).toPromise().then(volIds =>this.fetchVols(volIds));
     }
 }
 
+
+
index 4d5f799..0f1ad56 100644 (file)
@@ -32,6 +32,24 @@ export class VolCopyContext {
         return this.holdings.root.children;
     }
 
+    // If the holdings in question all link to a single bib
+    // record, return the ID of said record.  Otherwise null.
+    getRecordId(): number {
+        let id = null;
+        let nope = false;
+        this.orgNodes().forEach(orgNode => {
+            orgNode.children.forEach(volNode => {
+                if (id === null) {
+                    id = volNode.target.record();
+                } else if (id !== volNode.target.record()) {
+                    nope = true;
+                }
+            })
+        });
+
+        return nope ? null : id;
+    }
+
     // Adds an org unit node; unsorted.
     findOrCreateOrgNode(orgId: number): HoldingsTreeNode {
 
@@ -50,7 +68,7 @@ export class VolCopyContext {
         return node;
     }
 
-    findOrCreateCallNumNode(vol: IdlObject): HoldingsTreeNode {
+    findOrCreateVolNode(vol: IdlObject): HoldingsTreeNode {
         const orgId = vol.owning_lib();
         const orgNode = this.findOrCreateOrgNode(orgId);
 
@@ -72,7 +90,7 @@ export class VolCopyContext {
 
     findOrCreateCopyNode(copy: IdlObject): HoldingsTreeNode {
 
-        const volNode = this.findOrCreateCallNumNode(copy.call_number());
+        const volNode = this.findOrCreateVolNode(copy.call_number());
 
         const existing = volNode.children.filter(
             c => c.target.id() === copy.id())[0];
index b4f6e27..6b42543 100644 (file)
@@ -89,7 +89,6 @@ export class HoldingsService {
         .toPromise().then(prefixes => {
             this.callNumberPrefixes = prefixes.sort(
                 (c1, c2) => c1.label_sortkey() < c2.label_sortkey() ? -1 : 1);
-            console.log('H1', this.callNumberPrefixes);
             return this.callNumberPrefixes;
         });
     }