From: Jason Etheridge Date: Fri, 3 Sep 2021 15:25:14 +0000 (-0400) Subject: lp1787968 jacket_upload: UI X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=135cfa2ee3c7570c95d947cdce6796e0299ee2be;p=working%2FEvergreen.git lp1787968 jacket_upload: UI Signed-off-by: Jason Etheridge Signed-off-by: Michele Morgan --- diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts index 2108000a22..3222d87c03 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts @@ -22,6 +22,7 @@ import {HoldComponent} from './hold/hold.component'; import {PartsComponent} from './record/parts.component'; import {NotesComponent} from './record/notes.component'; import {AddToCarouselDialogComponent} from './record/add-to-carousel-dialog.component'; +import {UploadJacketImageDialogComponent} from './record/upload-jacket-image-dialog.component'; import {PartMergeDialogComponent} from './record/part-merge-dialog.component'; import {BrowseComponent} from './browse.component'; import {BrowseResultsComponent} from './browse/results.component'; @@ -33,6 +34,7 @@ import {SearchTemplatesComponent} from './search-templates.component'; import {MarcEditModule} from '@eg/staff/share/marc-edit/marc-edit.module'; import {PreferencesComponent} from './prefs.component'; import {BrowsePagerComponent} from './result/browse-pager.component'; +import {HttpClientModule} from '@angular/common/http'; @NgModule({ declarations: [ @@ -51,6 +53,7 @@ import {BrowsePagerComponent} from './result/browse-pager.component'; PartsComponent, NotesComponent, AddToCarouselDialogComponent, + UploadJacketImageDialogComponent, PartMergeDialogComponent, BrowseComponent, BrowseResultsComponent, @@ -70,7 +73,8 @@ import {BrowsePagerComponent} from './result/browse-pager.component'; HoldingsModule, BookingModule, PatronModule, - MarcEditModule + MarcEditModule, + HttpClientModule ], providers: [ StaffCatalogService diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/actions.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/record/actions.component.html index 8634f820b9..0b13009491 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/actions.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/actions.component.html @@ -16,6 +16,9 @@ + + +
@@ -91,6 +94,9 @@ + View/Place Orders diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/upload-jacket-image-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/record/upload-jacket-image-dialog.component.html new file mode 100644 index 0000000000..1c7612d707 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/upload-jacket-image-dialog.component.html @@ -0,0 +1,43 @@ + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/upload-jacket-image-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/record/upload-jacket-image-dialog.component.ts new file mode 100644 index 0000000000..d02911e952 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/upload-jacket-image-dialog.component.ts @@ -0,0 +1,138 @@ +import {Component, Input, OnInit, ViewChild} from '@angular/core'; +import {FormControl} from '@angular/forms'; +import {takeLast, finalize} from 'rxjs/operators'; +import {DialogComponent} from '@eg/share/dialog/dialog.component'; +import {AuthService} from '@eg/core/auth.service'; +import {NetService} from '@eg/core/net.service'; +import {EventService} from '@eg/core/event.service'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; +import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; +import {StringComponent} from '@eg/share/string/string.component'; +import {HttpClient, HttpResponse, HttpErrorResponse, HttpEventType} from '@angular/common/http'; + +@Component({ + selector: 'upload-jacket-image-dialog', + templateUrl: './upload-jacket-image-dialog.component.html' +}) + + +export class UploadJacketImageDialogComponent extends DialogComponent implements OnInit { + + // ID of bib record for jacket image + @Input() recordId: number; + + uploading: boolean; + noFile: boolean; + errorUploading: boolean; + errorAuthentication: boolean; + errorAuthorization: boolean; + errorCompressionConfig: boolean; + errorNotFound: boolean; + errorLocationConfig: boolean; + errorWritingFile: boolean; + errorSize: boolean; + errorParsing: boolean; + errorGeneric: boolean; + + private fileEvent: any; + + constructor( + private modal: NgbModal, + private auth: AuthService, + private evt: EventService, + private net: NetService, + private toast: ToastService, + private http: HttpClient + ) { + super(modal); + } + + clearErrors() { + this.errorAuthentication = false; + this.errorAuthorization = false; + this.errorCompressionConfig = false; + this.errorNotFound = false; + this.errorLocationConfig = false; + this.errorWritingFile = false; + this.errorSize = false; + this.errorParsing = false; + this.errorGeneric = false; + this.errorUploading = false; + } + + ngOnInit() { + this.uploading = false; + this.noFile = true; + this.clearErrors(); + } + + onFileSelected(event) { + console.debug('onFileSelected',event); + this.fileEvent = event; + const file:File = this.fileEvent.target.files[0]; + if (file) { + this.noFile = false; + } else { + this.noFile = true; + } + } + + uploadJacketImage() { + const file:File = this.fileEvent.target.files[0]; + if (file) { + this.uploading = true; + this.clearErrors(); + const formData = new FormData(); + formData.append("jacket_upload", file); + formData.append("ses", this.auth.token()); + formData.append("bib_record", this.recordId.toString()); + + const upload$ = this.http.post("/jacket-upload", formData, { + reportProgress: true, + observe: 'events' + }); + + upload$.subscribe( + x => { + console.debug('Jacket upload: ' , x); + if (x instanceof HttpResponse) { + console.debug('yay',x.body); + if (x.body != '1') { + this.uploading = false; + this.errorUploading = true; + } + switch(x.body) { + case "session not found": this.errorAuthentication = true; break; + case "permission denied": this.errorAuthorization = true; break; + case "invalid compression level": this.errorCompressionConfig = true; break; + case "bib not found": this.errorNotFound = true; break; + case "jacket location not configured": this.errorLocationConfig = true; break; + case "unable to open file for writing": this.errorWritingFile = true; break; + case "file too large": this.errorSize = true; break; + case "parse error": this.errorParsing = true; break; + case "upload error": this.errorGeneric = true; break; + default: this.errorGeneric = true; break; + } + } + }, + err => { + this.uploading = false; + this.errorUploading = true; + this.errorGeneric = true; + console.error('jacket upload error: ' , err); + }, + () => this.refreshPage() + ); + } + } + + refreshPage() { + if (this.errorUploading) { + console.debug('no refresh page due to error'); + } else { + console.debug('refresh page'); + location.href = location.href; + } + } +}