LPXXX Angular Volcopy
authorBill Erickson <berickxx@gmail.com>
Tue, 9 Jun 2020 21:22:08 +0000 (17:22 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 9 Jun 2020 21:22:08 +0000 (17:22 -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/volcopy.component.html
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts

index b1406ad..3f30820 100644 (file)
               spellcheck="false"
               [required]="true"
               [ngModel]="volNode.target.label()"
-              (onChange)="applyVolValue(volNode.target, 'label', $event)">
+              (change)="applyVolValue(volNode.target, 'label', $event.target.value)">
           </ng-container>
         </div>
         <div class="p-1" [ngStyle]="{flex: flexAt(6)}">
index 1c62cca..97256b1 100644 (file)
@@ -1,12 +1,10 @@
 <eg-staff-banner bannerText="Holdings Editor" i18n-bannerText></eg-staff-banner>
 
-<ng-container *ngIf="loading">
-  <div class="row">
-    <div class="col-lg-6 offset-lg-3">
-      <eg-progress-inline #loadingProgress></eg-progress-inline>
-    </div>
+<div class="row" [hidden]="!loading">
+  <div class="col-lg-6 offset-lg-3">
+    <eg-progress-inline #loadingProgress></eg-progress-inline>
   </div>
-</ng-container>
+</div>
 
 <ng-container *ngIf="!loading">
 
index f0916c4..6502392 100644 (file)
@@ -1,8 +1,11 @@
 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 {IdlObject, IdlService} from '@eg/core/idl.service';
+import {EventService} from '@eg/core/event.service';
 import {OrgService} from '@eg/core/org.service';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
 import {VolCopyContext} from './volcopy';
@@ -40,7 +43,11 @@ export class VolCopyComponent implements OnInit {
         private router: Router,
         private route: ActivatedRoute,
         private renderer: Renderer2,
+        private evt: EventService,
+        private idl: IdlService,
         private org: OrgService,
+        private net: NetService,
+        private auth: AuthService,
         private pcrud: PcrudService,
         private holdings: HoldingsService
     ) { }
@@ -128,6 +135,67 @@ export class VolCopyComponent implements OnInit {
             {}, {idlist: true, atomic: true}
         ).toPromise().then(volIds =>this.fetchVols(volIds));
     }
+
+
+    save() {
+        this.loadingProgress.reset();
+        this.loading = true;
+
+        // Volume update API wants volumes fleshed with copies, instead
+        // of the other way around, which is what we have here.
+        const volumes: IdlObject[] = [];
+
+        this.context.volNodes().forEach(volNode => {
+            const newVol = this.idl.clone(volNode.target);
+            const copies: IdlObject[] = [];
+
+            volNode.children.forEach(copyNode => {
+                const copy = copyNode.target;
+
+                if (copy.ischanged() || copy.isnew() || copy.isdeleted()) {
+                    const copyClone = this.idl.clone(copy);
+                    // De-flesh call number
+                    copyClone.call_number(copy.call_number().id());
+                    copies.push(copyClone);
+                }
+            });
+
+            newVol.copies(copies);
+
+            if (newVol.ischanged() || newVol.isnew() || copies.length > 0) {
+                volumes.push(newVol);
+            }
+        });
+
+        // TODO: deletedVols and deletedCopies
+
+        if (volumes.length > 0) {
+            this.saveApi(volumes);
+        }
+    }
+
+    saveApi(volumes: IdlObject[], override?: boolean) {
+
+        let method = 'open-ils.cat.asset.volume.fleshed.batch.update';
+        if (override) { method += '.override'; }
+
+        this.net.request('open-ils.cat',
+            method, this.auth.token(), volumes).toPromise()
+
+        .then(resp => {
+
+            const evt = this.evt.parse(resp);
+
+            // TODO: confirm / handle overrides
+
+            if (evt) {
+                alert(evt);
+                return;
+            }
+
+            return this.load();
+        });
+    }
 }
 
 
index c44a7f7..98c2eb6 100644 (file)
@@ -250,6 +250,8 @@ export class SandboxComponent implements OnInit {
             const query: any = new Array();
             query.push(base);
 
+            console.log(JSON.stringify(this.eventsDataSource.filters));
+
             Object.keys(this.eventsDataSource.filters).forEach(key => {
                 Object.keys(this.eventsDataSource.filters[key]).forEach(key2 => {
                     query.push(this.eventsDataSource.filters[key][key2]);