From f04ee6fce8afe7741104e2c475a3e2467c03701d Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 12 Jul 2018 17:31:30 -0400 Subject: [PATCH] LP#1779158 Vandelay export form Signed-off-by: Bill Erickson --- .../app/staff/cat/vandelay/export.component.html | 118 ++++++++++++++++++++- .../src/app/staff/cat/vandelay/export.component.ts | 117 +++++++++++++++++++- .../app/staff/cat/vandelay/import.component.css | 27 ----- .../app/staff/cat/vandelay/import.component.html | 4 +- .../src/app/staff/cat/vandelay/import.component.ts | 5 +- .../app/staff/cat/vandelay/vandelay.component.html | 10 +- 6 files changed, 238 insertions(+), 43 deletions(-) delete mode 100644 Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.css diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/export.component.html b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/export.component.html index 944a368ac8..71f960f877 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/export.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/export.component.html @@ -1 +1,117 @@ -EXPORT +

Export Records

+ +
+
+
+
+ + + +
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ + +
+
+ +
+
+ +
+
+
+
+ + +
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/export.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/export.component.ts index 4f64a3ea5f..577da79bfd 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/export.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/export.component.ts @@ -1,14 +1,127 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, OnInit, ViewChild} from '@angular/core'; +import {NgbPanelChangeEvent} from '@ng-bootstrap/ng-bootstrap'; +import {HttpClient, HttpRequest, HttpEventType} from '@angular/common/http'; +import {HttpResponse, HttpErrorResponse} from '@angular/common/http'; +import {saveAs} from 'file-saver/FileSaver'; +import {AuthService} from '@eg/core/auth.service'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.component'; +import {VandelayService, VANDELAY_EXPORT_PATH} from './vandelay.service'; + @Component({ templateUrl: 'export.component.html' }) export class ExportComponent implements OnInit { - constructor() {} + recordSource: string; + fieldNumber: number; + selectedFile: File; + recordId: number; + bucketId: number; + recordType: string; + recordFormat: string; + recordEncoding: string; + includeHoldings: boolean; + isExporting: boolean; + + @ViewChild('fileSelector') private fileSelector; + @ViewChild('exportProgress') + private exportProgress: ProgressInlineComponent; + + constructor( + private http: HttpClient, + private toast: ToastService, + private auth: AuthService + ) { + this.recordType = 'biblio'; + this.recordFormat = 'USMARC'; + this.recordEncoding = 'UTF-8'; + this.includeHoldings = false; + } ngOnInit() { } + sourceChange($event: NgbPanelChangeEvent) { + this.recordSource = $event.panelId; + } + + fileSelected($event) { + this.selectedFile = $event.target.files[0]; + } + + hasNeededData(): boolean { + return Boolean( + this.selectedFile || this.recordId || this.bucketId + ); + } + + exportRecords() { + this.isExporting = true; + this.exportProgress.update({value: 0}); + + const formData: FormData = new FormData(); + + formData.append('ses', this.auth.token()); + formData.append('rectype', this.recordType); + formData.append('encoding', this.recordEncoding); + formData.append('format', this.recordFormat); + + if (this.includeHoldings) { + formData.append('holdings', '1'); + } + + switch (this.recordSource) { + + case 'csv': + formData.append('idcolumn', ''+this.fieldNumber); + formData.append('idfile', + this.selectedFile, this.selectedFile.name); + break; + + case 'record-id': + formData.append('id', ''+this.recordId); + break; + + case 'bucket-id': + formData.append('containerid', ''+this.bucketId); + break; + } + + this.sendExportRequest(formData); + } + + sendExportRequest(formData: FormData) { + + const fileName = `export.${this.recordType}.` + + `${this.recordEncoding}.${this.recordFormat}`; + + const req = new HttpRequest('POST', VANDELAY_EXPORT_PATH, + formData, {reportProgress: true, responseType: 'text'}); + + this.http.request(req).subscribe( + evt => { + console.log(evt); + if (evt.type === HttpEventType.DownloadProgress) { + // File size not reported by server in advance. + this.exportProgress.update({value: evt.loaded}); + + } else if (evt instanceof HttpResponse) { + + saveAs(new Blob([evt.body], + {type: 'application/octet-stream'}), fileName); + + this.isExporting = false; + } + }, + + (err: HttpErrorResponse) => { + console.error(err); + this.toast.danger(err.error); + this.isExporting = false; + } + ); + } } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.css b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.css deleted file mode 100644 index a6404125a6..0000000000 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.css +++ /dev/null @@ -1,27 +0,0 @@ - - -.import-form { - margin-right: 10px; - margin-left: 10px; - font-size: 95%; -} - -.import-form .row { - margin: 5px; - padding: 3px; -} - -.import-form .row:nth-child(even) { - background-color: rgba(0,0,0,.03); - border-top: 1px solid rgba(0,0,0,.125); - border-bottom: 1px solid rgba(0,0,0,.125); -} - -.import-form label { - font-weight: bold; -} - -.import-form input[type="checkbox"] { - /* BS adds a negative left margin */ - margin-left: 0px; -} 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 5e201045f7..2d4b150237 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,8 @@ -
-

MARC File Upload

+

MARC File Upload

+
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 035379ca67..6689e1a924 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 @@ -27,8 +27,7 @@ interface ImportOptions { } @Component({ - templateUrl: 'import.component.html', - styleUrls: ['import.component.css'] + templateUrl: 'import.component.html' }) export class ImportComponent implements OnInit, AfterViewInit, OnDestroy { @@ -346,7 +345,7 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy { (err: HttpErrorResponse) => { console.error(err); - this.toast.danger(err.error.error); + this.toast.danger(err.error); } )).toPromise(); } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.component.html b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.component.html index a5e896667c..410449136c 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.component.html @@ -1,14 +1,7 @@ - + -- 2.11.0