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']
recordType: string;
selectedQueue: ComboboxEntry; // freetext enabled
+ activeQueueId: number;
selectedBucket: number;
selectedBibSource: number;
selectedMatchSet: number;
// Upload in progress.
isUploading: boolean;
+ // True only after successful upload
+ uploadComplete: boolean;
+
// Upload / processsing session key
// Generated by the server
sessionKey: string;
private vandelay: VandelayService
) {
this.recordType = 'bib';
+ this.selectedBibSource = 2; // default to system local
this.attrDefs = {};
this.minQualityRatio = 0;
}
// Required form data varies depending on context.
confirmNeededData(): boolean {
- if (!this.selectedQueue) {
+ if (!this.selectedQueue || !this.selectedBibSource) {
return false;
}
return true;
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> {
uploadFile(): Promise<any> {
const formData: FormData = new FormData();
+ formData.append('ses', this.auth.token());
formData.append('marc_upload',
this.selectedFile, this.selectedFile.name);
)).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);
)).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);
+ }
}