From 29bfeb991c1e27a94085bf570c36426434aede5d Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Sat, 30 Jun 2018 11:28:40 -0400 Subject: [PATCH] LP#1779158 Angular vandelay more import form Signed-off-by: Bill Erickson --- .../app/staff/cat/vandelay/import.component.html | 31 ++++++++-- .../src/app/staff/cat/vandelay/import.component.ts | 67 ++++++++++++++-------- .../src/app/staff/cat/vandelay/vandelay.service.ts | 37 ++++++------ 3 files changed, 87 insertions(+), 48 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.html b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.html index e8b65e4e2c..b0a9ee6721 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.html @@ -8,8 +8,7 @@
- @@ -17,7 +16,7 @@
-
+
@@ -27,7 +26,31 @@
- + +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts index 7ae7ee3710..4a7cb2e0a6 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts @@ -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{ + // 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()}; + }); + } } } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts index 44133262ba..e8d3e5fcd2 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts @@ -59,23 +59,19 @@ export class VandelayService { getActiveQueues(qtype: string): Promise { 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 { @@ -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 { + 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; }); } -- 2.11.0