LPXXX Angular Volcopy
authorBill Erickson <berickxx@gmail.com>
Fri, 5 Jun 2020 21:49:31 +0000 (17:49 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 5 Jun 2020 21:49:31 +0000 (17:49 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
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

index a5f42a5..a8a74c7 100644 (file)
           <span *ngIf="copyIdx == 0">{{orgNode.target.shortname()}}</span>
         </div>
         <div class="p-1" [ngStyle]="{flex: flexAt(2)}">
-          <ng-container *ngIf="copyIdx == 0">
+          <ng-container *ngIf="copyIdx == 0 && volIdx == 0">
             <input type="number" class="form-control form-control-sm"
-              [required]="true"
+              [required]="true" min="0"
               [ngModel]="orgNode.children.length"
               (ngModelChange)="volCountChanged(orgNode, $event)"/>
           </ng-container>
         <div class="p-1" [ngStyle]="{flex: flexAt(7)}">
           <ng-container *ngIf="copyIdx == 0">
             <input type="number" class="form-control form-control-sm"
-              [required]="true"
+              [required]="true" min="0"
               [ngModel]="volNode.children.length"
               (ngModelChange)="copyCountChanged(volNode, $event)"/>
           </ng-container>
             Duplicate Barcode</div>
         </div>
         <div class="p-1" [ngStyle]="{flex: flexAt(9)}">
-          <input type="number" class="form-control form-control-sm"
+          <input type="number" min="0" class="form-control form-control-sm"
             [ngModel]="copyNode.target.copy_number()"
             (ngModelChange)="applyCopyValue(copyNode.target, 'copy_number', $event)"/>
         </div>
index ecef3b5..29692eb 100644 (file)
@@ -1,7 +1,7 @@
 import {Component, OnInit, AfterViewInit, ViewChild, Input, Renderer2} from '@angular/core';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
 import {tap} from 'rxjs/operators';
-import {IdlObject} from '@eg/core/idl.service';
+import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {OrgService} from '@eg/core/org.service';
 import {AuthService} from '@eg/core/auth.service';
 import {NetService} from '@eg/core/net.service';
@@ -43,8 +43,11 @@ export class VolEditComponent implements OnInit {
     autoBarcodeInProgress = false;
     useCheckdigit = false;
 
+    autoId = -1;
+
     constructor(
         private renderer: Renderer2,
+        private idl: IdlService,
         private pcrud: PcrudService,
         private net: NetService,
         private auth: AuthService,
@@ -54,7 +57,8 @@ export class VolEditComponent implements OnInit {
     ngOnInit() {
 
         this.fetchRecordVolLabels()
-        .then(_ => this.fetchBibParts());
+        .then(_ => this.fetchBibParts())
+        .then(_ => this.addStubCopies());
 
         // TODO: Filter these to only show org-scoped values
         // plus any values otherwise needed for the current
@@ -137,13 +141,90 @@ export class VolEditComponent implements OnInit {
     }
 
     volCountChanged(orgNode: HoldingsTreeNode, count: number) {
-        console.log('vol set set to ', count);
+        const diff = count - orgNode.children.length;
+        if (diff > 0) {
+            this.createVols(orgNode, diff);
+        } else if (diff < 0) {
+            this.deleteVols(orgNode, diff);
+        }
+    }
+
+    createStubVol(orgId: number): IdlObject {
+        // Volume creation should only be available as an option when
+        // working with a specific call bib record.
+        const recId = +this.context.getRecordIds()[0];
+
+        const vol = this.idl.create('acn');
+        vol.id(this.autoId--);
+        vol.isnew(true);
+        vol.record(recId);
+        vol.label(this.recordVolLabels[0] || '');
+        vol.owning_lib(orgId);
+
+        return vol;
+    }
+
+
+    createStubCopy(vol: IdlObject): IdlObject {
+
+        const copy = this.idl.create('acp');
+        copy.id(this.autoId--);
+        copy.isnew(true);
+        copy.circ_lib(vol.owning_lib());
+        copy.call_number(vol.id());
+        copy.deposit(0);
+        copy.price(0);
+        copy.deposit_amount(0);
+        copy.fine_level(2);     // Normal
+        copy.loan_duration(2);  // Normal
+        copy.location(1);       // Stacks
+        copy.circulate('t');
+        copy.holdable('t');
+        copy.opac_visible('t');
+        copy.ref('f');
+        copy.mint_condition('t');
+
+        // TODO: status / fast-add / defaults?
+
+        return copy;
     }
 
     copyCountChanged(volNode: HoldingsTreeNode, count: number) {
         console.log('vol set set to ', count);
     }
 
+    createVols(orgNode: HoldingsTreeNode, count: number) {
+        for (let i = 0; i < count; i++) {
+
+            // This will vivify the volNode if needed.
+            const vol = this.createStubVol(orgNode.target.id())
+
+            // Our context assumes copies are fleshed with volumes
+            const copy = this.createStubCopy(vol);
+            copy.call_number(vol);
+            this.context.findOrCreateCopyNode(copy);
+        }
+    }
+
+
+    deleteVols(orgNode: HoldingsTreeNode, count: number) {
+    }
+
+
+    // Empty volumes get a stub copy
+    addStubCopies() {
+
+        // TODO: timing issue -- all vols getting stubs
+        this.context.volNodes().forEach(volNode => {
+            if (volNode.children.length == 0) {
+                const vol = volNode.target;
+                const copy = this.createStubCopy(vol);
+                copy.call_number(vol);
+                this.context.findOrCreateCopyNode(copy);
+            }
+        });
+    }
+
     applyVolValue(vol: IdlObject, key: string, value: any) {
 
         if (value === null && (key === 'prefix' || key === 'suffix')) {
index 8a5999e..dd9173f 100644 (file)
@@ -89,7 +89,6 @@ export class VolCopyComponent implements OnInit {
         }
     }
 
-
     fetchCopies(copyIds: number | number[]): Promise<any> {
         const ids = [].concat(copyIds);
         return this.pcrud.search('acp', {id: ids}, COPY_FLESH)
@@ -116,7 +115,7 @@ export class VolCopyComponent implements OnInit {
         const ids = [].concat(recordIds);
 
         return this.pcrud.search('acn',
-            {record: ids, deleted: 'f'},
+            {record: ids, deleted: 'f', label: {'!=' : '##URI##'}},
             {}, {idlist: true, atomic: true}
         ).toPromise().then(volIds =>this.fetchVols(volIds));
     }
index aa07966..6a515d8 100644 (file)
@@ -137,21 +137,4 @@ export class VolCopyContext {
             o1.target.shortname() < o2.target.shortname() ? -1 : 1);
     }
 
-    // Sorted list of holdings tree nodes
-    /*
-    flattenHoldings(): HoldingsTreeNode[] {
-        this.sortHoldings();
-        let nodes: HoldingsTreeNode[] = [];
-
-        this.orgNodes().forEach(orgNode => {
-            nodes.push(orgNode);
-            orgNode.children.forEach(volNode => {
-                nodes.push(volNode);
-                nodes = nodes.concat(volNode.children);
-            });
-        });
-
-        return nodes;
-    }
-    */
 }