From: Bill Erickson Date: Mon, 2 Jul 2018 21:56:03 +0000 (-0400) Subject: LP#1779158 Ang vandelay import / import action X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d800db18026335e125818a545831aaaa3d219473;p=working%2FEvergreen.git LP#1779158 Ang vandelay import / import action Signed-off-by: Bill Erickson --- 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 9bfc50d36e..974a319d05 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 @@ -24,6 +24,7 @@
@@ -144,7 +145,7 @@
-
+
@@ -152,7 +153,7 @@
-
+
@@ -160,10 +161,16 @@
-
+
+
+
+ +
+
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 8f933ef0f6..19456ace8c 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 @@ -15,6 +15,18 @@ import {Subject} from 'rxjs/Subject'; const VAND_UPLOAD_URL = '/vandelay-upload'; +interface ImportOptions { + overlay_map?: any; + import_no_match?: boolean; + auto_overlay_exact?: boolean; + auto_overlay_best_match?: boolean; + auto_overlay_1match?: boolean; + opp_acq_copy_overlay?: boolean; + merge_profile?: any; + fall_through_merge_profile?: any; + strip_field_groups?: any; +} + @Component({ templateUrl: 'import.component.html', styleUrls: ['import.component.css'] @@ -23,6 +35,7 @@ export class ImportComponent implements OnInit, AfterViewInit { recordType: string; selectedQueue: ComboboxEntry; // freetext enabled + activeQueueId: number; selectedBucket: number; selectedBibSource: number; selectedMatchSet: number; @@ -47,6 +60,9 @@ export class ImportComponent implements OnInit, AfterViewInit { // Upload in progress. isUploading: boolean; + // True only after successful upload + uploadComplete: boolean; + // Upload / processsing session key // Generated by the server sessionKey: string; @@ -69,6 +85,7 @@ export class ImportComponent implements OnInit, AfterViewInit { private vandelay: VandelayService ) { this.recordType = 'bib'; + this.selectedBibSource = 2; // default to system local this.attrDefs = {}; this.minQualityRatio = 0; } @@ -146,7 +163,7 @@ export class ImportComponent implements OnInit, AfterViewInit { // Required form data varies depending on context. confirmNeededData(): boolean { - if (!this.selectedQueue) { + if (!this.selectedQueue || !this.selectedBibSource) { return false; } return true; @@ -162,29 +179,42 @@ export class ImportComponent implements OnInit, AfterViewInit { this.sessionKey = null; this.showProgress = true; this.isUploading = true; - this.uploadProgress.reset(); - this.enqueueProgress.update({value: 0, max: 1}); - this.importProgress.update({value: 0, max: 1}); - - let useQueueId; // find or create + this.uploadComplete = false; + this.resetProgressBars(); this.resolveQueue() .then( queueId => { - useQueueId = queueId; + this.activeQueueId = queueId; return this.uploadFile(); }, - err => { - this.isUploading = false; - } + err => Promise.reject('queue create failed') + ).then( + ok => this.processSpool(), + err => Promise.reject('process spool failed') ).then( - ok => this.processSpool(useQueueId), + ok => this.importRecords(), + err => Promise.reject('import records failed') + ).then( + ok => { + this.isUploading = false; + this.uploadComplete = true; + }, err => { + console.log('file upload failed: ', err); this.isUploading = false; + this.resetProgressBars(); + } ); } + resetProgressBars() { + this.uploadProgress.update({value: 0, max: 1}); + this.enqueueProgress.update({value: 0, max: 1}); + this.importProgress.update({value: 0, max: 1}); + } + // Extract selected queue ID or create a new queue when requested. resolveQueue(): Promise { @@ -208,6 +238,7 @@ export class ImportComponent implements OnInit, AfterViewInit { uploadFile(): Promise { const formData: FormData = new FormData(); + formData.append('ses', this.auth.token()); formData.append('marc_upload', this.selectedFile, this.selectedFile.name); @@ -239,14 +270,13 @@ export class ImportComponent implements OnInit, AfterViewInit { )).toPromise(); } - //processSpool(key, queueId, type, onload) { - processSpool(queueId: number): Promise { + processSpool(): Promise { const rtype = this.recordType === 'bib' ? 'bib' : 'authority'; const method = `open-ils.vandelay.${rtype}.process_spool`; return this.net.request( 'open-ils.vandelay', method, - this.auth.token(), this.sessionKey, queueId + this.auth.token(), this.sessionKey, this.activeQueueId ).pipe(tap( resp => { const e = this.evt.parse(resp); @@ -265,5 +295,61 @@ export class ImportComponent implements OnInit, AfterViewInit { )).toPromise(); } + importRecords(): Promise { + + // Confirm an import action was selected + if (this.importNonMatching + || this.mergeOnExact + || this.mergeOnSingleMatch + || this.mergeOnBestMatch) { + + return this.importRecordQueue() + } + + return Promise.resolve(); + } + + importRecordQueue(): Promise { + const method = `open-ils.vandelay.${this.recordType}_queue.import`; + const options: ImportOptions = this.compileImportOptions(); + + return this.net.request('open-ils.vandelay', + method, this.auth.token(), this.activeQueueId, options + ).pipe(tap( + resp => { + const e = this.evt.parse(resp); + if (e) { console.log(e); return; } + + this.importProgress.update( + {max: resp.total, value: resp.progress}); + }, + err => {}, + () => this.importProgress.update({max: 1, value: 1}) + )).toPromise(); + } + + // TODO + //importRecordList() {} + + compileImportOptions(): ImportOptions { + + const options: ImportOptions = { + overlay_map: null, // TODO + import_no_match: this.importNonMatching, + auto_overlay_exact: this.mergeOnExact, + auto_overlay_best_match: this.mergeOnBestMatch, + auto_overlay_1match: this.mergeOnSingleMatch, + opp_acq_copy_overlay: this.autoOverlayAcqCopies, + merge_profile: this.selectedMergeProfile, + fall_through_merge_profile: this.selectedFallThruMergeProfile, + strip_field_groups: null // TODO + }; + + return options; + } + + openQueue() { + console.log('opening queue ' + this.activeQueueId); + } } 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 99cc673575..d31eaa1f1d 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 @@ -198,19 +198,21 @@ export class VandelayService { let qType = 'acq'; } - return this.net.request( - 'open-ils.vandelay', method, - this.auth.token(), queueName, null, qType, - matchSet, importDefId, matchBucket - ).pipe(map(queue => { - const e = this.evt.parse(queue); - if (e) { - console.error(e); - return null; - } - return queue.id(); - })).toPromise(); + return new Promise((resolve, reject) => { + this.net.request( + 'open-ils.vandelay', method, + this.auth.token(), queueName, null, qType, + matchSet, importDefId, matchBucket + ).subscribe(queue => { + const e = this.evt.parse(queue); + if (e) { + alert(e); + reject(e); + } else { + resolve(queue.id()); + } + }); + }); } - }