LP#1779158 Ang vandelay import / import action
authorBill Erickson <berickxx@gmail.com>
Mon, 2 Jul 2018 21:56:03 +0000 (17:56 -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 9bfc50d..974a319 100644 (file)
@@ -24,6 +24,7 @@
     <div class="col-lg-3">
       <eg-combobox [entries]="formatEntries('bibSources')" 
         (onChange)="selectedBibSource=$event.id"
+        [startId]="selectedBibSource"
         placeholder="Record Source..." i18n-placeholder>
       </eg-combobox>
     </div>
     <div class="col-lg-3">
       <label i18n>Upload Progress</label>
     </div>
-    <div class="col-lg-3">
+    <div class="col-lg-6">
       <eg-progress-inline #uploadProgress></eg-progress-inline>
     </div>
   </div>
     <div class="col-lg-3">
       <label i18n>Enqueue Progress</label>
     </div>
-    <div class="col-lg-3">
+    <div class="col-lg-6">
       <eg-progress-inline #enqueueProgress></eg-progress-inline>
     </div>
   </div>
     <div class="col-lg-3">
       <label i18n>Import Progress</label>
     </div>
-    <div class="col-lg-3">
+    <div class="col-lg-6">
       <eg-progress-inline #importProgress></eg-progress-inline>
     </div>
   </div>
+  <div class="row" [hidden]="!uploadComplete">
+    <div class="col-lg-6 offset-lg-3">
+      <button class="btn btn-info btn-lg btn-block font-weight-bold"
+        (click)="openQueue()" i18n>Go To Queue</button>
+    </div>
+  </div>
 </div>
 
 
index 8f933ef..19456ac 100644 (file)
@@ -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<number> {
 
@@ -208,6 +238,7 @@ export class ImportComponent implements OnInit, AfterViewInit {
     uploadFile(): Promise<any> {
         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<any> {
+    processSpool():  Promise<any> {
         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<any> {
+
+        // Confirm an import action was selected
+        if (this.importNonMatching
+            || this.mergeOnExact
+            || this.mergeOnSingleMatch
+            || this.mergeOnBestMatch) {
+
+            return this.importRecordQueue()
+        }
+
+        return Promise.resolve();
+    }
+
+    importRecordQueue(): Promise<any> {
+        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);
+    }
 }
 
index 99cc673..d31eaa1 100644 (file)
@@ -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());
+                }
+            });
+        });
     }
-
 }