LP#1779158 Angular vandelay more import form
authorBill Erickson <berickxx@gmail.com>
Sat, 30 Jun 2018 15:28:40 +0000 (11:28 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 11 Oct 2018 18:56:30 +0000 (14:56 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.html
Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts
Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts

index e8b65e4..b0a9ee6 100644 (file)
@@ -8,8 +8,7 @@
       <label class="font-weight-bold" i18n>Record Type</label>
     </div>
     <div class="col-lg-3">
-      <select class="form-control" [(ngModel)]="recordType" 
-        (change)="recordTypeChanged($event)">
+      <select class="form-control" [(ngModel)]="recordType">
         <option value='bib' i18n>Bibliographic Records</option>
         <option value='auth' i18n>Authority Records</option> 
         <option value='bib-acq' i18n>Acquisitions Records</option>
@@ -17,7 +16,7 @@
     </div>
   </div>
   <div class="row">
-    <div class="col-lg-3">
+    <div class="col-lg-3 pb-2">
       <label class="font-weight-bold" i18n>Create a New Upload Queue</label>
     </div>
     <div class="col-lg-3">
       <label class="font-weight-bold" i18n>or Add to an Existing Queue</label>
     </div>
     <div class="col-lg-3">
-      <eg-typeahead [entries]="queueEntries"></eg-typeahead>
+      <eg-typeahead [entries]="formatEntries('activeQueues')"></eg-typeahead>
+    </div>
+  </div>
+  <div class="row pb-2">
+    <div class="col-lg-3">
+      <label class="font-weight-bold" i18n>Record Match Set</label>
+    </div>
+    <div class="col-lg-3">
+      <eg-typeahead [entries]="formatEntries('matchSets')"></eg-typeahead>
+    </div>
+  </div>
+  <div class="row pb-2">
+    <div class="col-lg-3">
+      <label class="font-weight-bold" i18n>Holdings Import Profile</label>
+    </div>
+    <div class="col-lg-3"> <!-- TODO disable for authority -->
+      <eg-typeahead [entries]="formatEntries('importItemDefs')"></eg-typeahead>
+    </div>
+  </div>
+  <div class="row pb-2">
+    <div class="col-lg-3">
+      <label class="font-weight-bold" i18n>Select a Record Source</label>
+    </div>
+    <div class="col-lg-3">
+      <eg-typeahead [entries]="formatEntries('bibSources')"></eg-typeahead>
     </div>
   </div>
 </div>
index 7ae7ee3..4a7cb2e 100644 (file)
@@ -12,15 +12,18 @@ export class ImportComponent implements OnInit, AfterViewInit {
 
     recordType: string;
     newQueueName: string;
-    queueEntries: TypeaheadEntry[];
     allQueues: {[qtype: string]: IdlObject[]};
     activeQueues: {[qtype: string]: IdlObject[]}; 
     attrDefs: {[atype: string]: IdlObject[]};
     bibSources: IdlObject[];
     bibBuckets: IdlObject[];
+    itemImportAttrDefs: IdlObject[];
     matchSets: {[stype: string]: IdlObject[]};
     defaultMatchSet: string;
 
+    matchSetEntries: TypeaheadEntry[];
+    importItemDefEntries: TypeaheadEntry[];
+
     @ViewChild('progressDialog')
         private progressDialog: ProgressDialogComponent;
 
@@ -29,7 +32,6 @@ export class ImportComponent implements OnInit, AfterViewInit {
         private vandelay: VandelayService
     ) {
         this.recordType = 'bib';
-        this.queueEntries = [];
         this.attrDefs = {};
         this.matchSets = {};
         this.activeQueues = {};
@@ -40,16 +42,14 @@ export class ImportComponent implements OnInit, AfterViewInit {
     ngAfterViewInit() {
         // loading startup data changes our data in the midst of a
         // lifecycle hook.  Run after timeout.
-        setTimeout(() => this.loadStartupData());
-    }
-
-    // Display record-typ appropriate data when the record type changes
-    recordTypeChanged($event) {
-        //this.formatQueueSelector();
+        //setTimeout(() => this.loadStartupData());
+        this.loadStartupData();
     }
 
-    loadStartupData() {
-        this.progressDialog.open();
+    loadStartupData(): Promise<any>{
+        // Note displaying and manipulating a progress dialog inside
+        // the AfterViewInit cycle leads to errors because the child
+        // component is modifed after dirty checking.
 
         const promises = [
             this.vandelay.getAttrDefs('bib')
@@ -57,32 +57,51 @@ export class ImportComponent implements OnInit, AfterViewInit {
             this.vandelay.getAttrDefs('auth')
                 .then(defs => this.attrDefs.auth = defs),
             this.vandelay.getActiveQueues('bib')
-                .then(queues => {
-                    this.activeQueues.bib = queues;
-                    this.formatQueueSelector();
-                }),
+                .then(queues => this.activeQueues.bib = queues),
             this.vandelay.getActiveQueues('auth')
                 .then(queues => this.activeQueues.auth = queues),
-            this.vandelay.getMatchSets()
-                .then(sets => this.matchSets = sets),
+            this.vandelay.getMatchSets('bib')
+                .then(sets => this.matchSets.bib = sets),
+            this.vandelay.getMatchSets('auth')
+                .then(sets => this.matchSets.auth= sets),
             this.vandelay.getBibBuckets()
                 .then(bkts => this.bibBuckets = bkts),
             this.vandelay.getBibSources()
                 .then(srcs => this.bibSources = srcs),
+            this.vandelay.getItemImportDefs()
+                .then(defs => this.itemImportAttrDefs = defs),
             this.org.settings(['vandelay.default_match_set']).then(
                 s => this.defaultMatchSet = s['vandelay.default_match_set'])
         ];
 
-        this.progressDialog.update({value: 0, max: promises.length});
-        promises.forEach(p => p.then(() => this.progressDialog.increment()));
-        Promise.all(promises).then(() => this.progressDialog.close());
+        return Promise.all(promises);
     }
 
-    formatQueueSelector() {
-        const queues = this.activeQueues[this.recordType];
-        this.queueEntries = queues.map(q => {
-            return {id: q.id(), label: q.name()};
-        });
+    // Format typeahead data sets
+    formatEntries(etype: string): TypeaheadEntry[] {
+        const rtype = this.recordType;
+
+        switch (etype) {
+            case 'bibSources':
+                return (this.bibSources || []).map(s => {
+                    return {id: s.id(), label: s.source()};
+                });
+
+            case 'activeQueues':
+                return (this.activeQueues[rtype] || []).map(q => {
+                    return {id: q.id(), label: q.name()};
+                });
+
+            case 'matchSets':
+                return (this.matchSets[rtype] || []).map(s => { 
+                    return {id: s.id(), label: s.name()}; 
+                });
+
+            case 'importItemDefs':
+                return (this.itemImportAttrDefs || []).map(d => {
+                    return {id: d.id(), label: d.name()};
+                 });
+        }
     }
 }
 
index 4413326..e8d3e5f 100644 (file)
@@ -59,23 +59,19 @@ export class VandelayService {
     getActiveQueues(qtype: string): Promise<IdlObject[]> {
         if (this.activeQueues[qtype]) {
             return Promise.resolve(this.activeQueues[qtype]);
+        } else {
+            this.activeQueues[qtype] = [];
         }
 
         // could be a big list, invoke in streaming mode
-        const queues = [];
         const qt = (qtype === 'bib') ? qtype : 'authority';
         return this.net.request(
             'open-ils.vandelay',
             `open-ils.vandelay.${qt}_queue.owner.retrieve`,
             this.auth.token(), null, {complete: 'f'}
         ).pipe(tap(
-            queue => {
-                if (!this.activeQueues[qtype]) {
-                    this.activeQueues[qtype] = [];
-                }
-                this.activeQueues[qtype].push(queue);
-            }
-        )).toPromise().then(() => queues);
+            queue => this.activeQueues[qtype].push(queue)
+        )).toPromise().then(() => this.activeQueues[qtype]);
     }
 
     getBibSources(): Promise<IdlObject[]> {
@@ -98,28 +94,29 @@ export class VandelayService {
         }
 
         const owners = this.org.ancestors(this.auth.user().ws_ou(), true);
-        return this.pcrud.search('viiad', {owner: owners}, {atomic: true})
+        return this.pcrud.search('viiad', {owner: owners}, {}, {atomic: true})
         .toPromise().then(defs => {
             this.importItemAttrDefs = defs;
             return defs;
         });
     }
 
-    getMatchSets(): Promise<{[mtype:string]: IdlObject[]}> {
-        if (this.matchSets) {
-            return Promise.resolve(this.matchSets);
+    // todo: differentiate between biblio and authority a la queue api
+    getMatchSets(mtype: string): Promise<IdlObject[]> {
+        if (this.matchSets[mtype]) {
+            return Promise.resolve(this.matchSets[mtype]);
+        } else {
+            this.matchSets[mtype] = [];
         }
 
         const owners = this.org.ancestors(this.auth.user().ws_ou(), true);
-        return this.pcrud.search('vms', {owner: owners})
+        const mt = (mtype === 'bib') ? 'biblio' : 'authority';
+
+        return this.pcrud.search('vms', 
+            {owner: owners, mtype: mt}, {}, {atomic: true})
         .toPromise().then(sets => {
-            sets.forEach(s => {
-                if (!this.matchSets[s.mtype()]) {
-                    this.matchSets[s.mtype()] = [];
-                }
-                this.matchSets[s.mtype()].push(s);
-            });
-            return this.matchSets;
+            this.matchSets[mtype] = sets;
+            return sets;
         });
     }