--- /dev/null
+<ng-template #dialogContent>
+ <div class="modal-header bg-info">
+ <h4 class="modal-title">
+ <span i18n>Upload Cover Image</span>
+ </h4>
+ <button type="button" class="close"
+ i18n-aria-label aria-label="Close" (click)="clearErrors(); close(false)">
+ <span aria-hidden="true">×</span>
+ </button>
+</div>
+<div class="modal-body">
+ <!--<form method="POST" enctype="multipart/form-data" action="/jacket-upload">
+ <input type="file" name="jacket_upload">
+ <input type="text" name="ses">
+ <input type="text" name="bib_record">
+ <input type="submit">
+ </form>-->
+ <input type="file" class="file-input" (change)="onFileSelected($event)" #fileUpload>
+ <div class="progress" *ngIf="uploading">
+ <div class="progress-bar progress-bar-striped active w-100"
+ role="progressbar" aria-valuenow="100"
+ aria-valuemin="0" aria-valuemax="100">
+ <span i18n>Uploading..</span>
+ </div>
+ </div>
+ <div style="margin-top: 20px" *ngIf="errorUploading">
+ <span *ngIf="errorAuthentication" class="alert alert-danger" i18n>Not authenticated. Expired login?</span>
+ <span *ngIf="errorAuthorization" class="alert alert-danger" i18n>Not authorized. Check your permissions.</span>
+ <span *ngIf="errorNotFound" class="alert alert-danger" i18n>Not found. Bib record deleted?</span>
+ <span *ngIf="errorCompressionConfig" class="alert alert-danger" i18n>Invalid global compression value. Talk to your system administrator.</span>
+ <span *ngIf="errorLocationConfig" class="alert alert-danger" i18n>Do not know where to upload files. Talk to your system administrator.</span>
+ <span *ngIf="errorWritingFile" class="alert alert-danger" i18n>Can not save uploaded file. Talk to your system administrator.</span>
+ <span *ngIf="errorSize" class="alert alert-danger" i18n>File size larger than configured limit. Check your library setting or try a smaller file.</span>
+ <span *ngIf="errorParsing" class="alert alert-danger" i18n>Error parsing the image. Is it a common image filetype?</span>
+ <span *ngIf="errorGeneric" class="alert alert-danger" i18n>Error uploading or processing file.</span>
+ </div>
+
+</div>
+<div class="modal-footer">
+ <button type="button" class="btn btn-success" [disabled]="uploading || noFile"
+ (click)="uploadJacketImage()" i18n>Upload Cover Image</button>
+</div>
+</ng-template>
--- /dev/null
+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;
+ }
+ }
+}