Upload cover
This commit is contained in:
+34
-4
@@ -3,11 +3,41 @@
|
||||
<div class="overflow-y-scroll flex-1">
|
||||
|
||||
<div class="flex flex-row w-full gap-4">
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<img [src]="urlHelper.getCoverUrl(metadata.bookId, metadata?.coverUpdatedOn)" alt="Image" width="225"/>
|
||||
<p-button *ngIf="!metadata['coverLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['coverLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="warn"></p-button>
|
||||
|
||||
<div class="flex flex-col items-center gap-2 relative">
|
||||
|
||||
<img
|
||||
[src]="urlHelper.getCoverUrl(metadata.bookId, metadata?.coverUpdatedOn)"
|
||||
alt="Image"
|
||||
width="250"
|
||||
[ngClass]="{ 'brightness-50': isUploading }"
|
||||
class="transition-all duration-300 ease-in-out"/>
|
||||
|
||||
<p-progressSpinner
|
||||
*ngIf="isUploading"
|
||||
class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-10">
|
||||
</p-progressSpinner>
|
||||
|
||||
<div class="flex items-center gap-6">
|
||||
<p-fileupload
|
||||
[disabled]="metadata['coverLocked']"
|
||||
name="file"
|
||||
[url]="getUploadCoverUrl()"
|
||||
mode="basic"
|
||||
chooseIcon="pi pi-upload"
|
||||
accept="image/jpeg,image/png"
|
||||
maxFileSize="5000000"
|
||||
chooseLabel="Cover"
|
||||
(onUpload)="onUpload($event)"
|
||||
(onError)="onUploadError($event)"
|
||||
[auto]="true"
|
||||
(onBeforeUpload)="onBeforeSend()"></p-fileupload>
|
||||
|
||||
<p-button *ngIf="!metadata['coverLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="success"></p-button>
|
||||
<p-button *ngIf="metadata['coverLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="warn"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col flex-grow pl-2">
|
||||
|
||||
<!-- Title and Subtitle -->
|
||||
|
||||
+41
-2
@@ -6,11 +6,15 @@ import {Divider} from 'primeng/divider';
|
||||
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {Observable} from 'rxjs';
|
||||
import {BookMetadataCenterService} from '../book-metadata-center.service';
|
||||
import {AsyncPipe, NgIf} from '@angular/common';
|
||||
import {AsyncPipe, NgClass, NgIf} from '@angular/common';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {MetadataService} from '../../service/metadata.service';
|
||||
import {BookMetadata} from '../../../book/model/book.model';
|
||||
import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
import {FileUpload, FileUploadErrorEvent, FileUploadEvent} from 'primeng/fileupload';
|
||||
import {HttpResponse} from '@angular/common/http';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-editor',
|
||||
@@ -25,7 +29,10 @@ import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
FormsModule,
|
||||
AsyncPipe,
|
||||
NgIf,
|
||||
ReactiveFormsModule
|
||||
ReactiveFormsModule,
|
||||
FileUpload,
|
||||
ProgressSpinner,
|
||||
NgClass
|
||||
]
|
||||
})
|
||||
export class MetadataEditorComponent implements OnInit {
|
||||
@@ -33,11 +40,13 @@ export class MetadataEditorComponent implements OnInit {
|
||||
private metadataCenterService = inject(BookMetadataCenterService);
|
||||
private messageService = inject(MessageService);
|
||||
private metadataService = inject(MetadataService);
|
||||
private bookService = inject(BookService);
|
||||
protected urlHelper = inject(UrlHelperService);
|
||||
|
||||
bookMetadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$;
|
||||
metadataForm: FormGroup;
|
||||
currentBookId!: number;
|
||||
isUploading = false;
|
||||
|
||||
constructor() {
|
||||
this.metadataForm = new FormGroup({
|
||||
@@ -241,4 +250,34 @@ export class MetadataEditorComponent implements OnInit {
|
||||
closeDialog() {
|
||||
this.metadataCenterService.closeDialog(true);
|
||||
}
|
||||
|
||||
getUploadCoverUrl(): string {
|
||||
return this.metadataService.getUploadCoverUrl(this.currentBookId);
|
||||
}
|
||||
|
||||
onBeforeSend(): void {
|
||||
this.isUploading = true;
|
||||
}
|
||||
|
||||
onUpload(event: FileUploadEvent): void {
|
||||
const response: HttpResponse<any> = event.originalEvent as HttpResponse<any>;
|
||||
if (response && response.status === 200) {
|
||||
const bookMetadata: BookMetadata = response.body as BookMetadata;
|
||||
this.bookService.handleBookMetadataUpdate(this.currentBookId, bookMetadata);
|
||||
this.metadataCenterService.emit(bookMetadata);
|
||||
this.isUploading = false;
|
||||
} else {
|
||||
this.isUploading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error', summary: 'Upload Failed', detail: 'An error occurred while uploading the cover', life: 3000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onUploadError($event: FileUploadErrorEvent) {
|
||||
this.isUploading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error', summary: 'Upload Error', detail: 'An error occurred while uploading the cover', life: 3000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,20 +24,6 @@ export class MetadataService {
|
||||
return this.http.post<FetchedMetadata[]>(`${this.url}/${bookId}`, request);
|
||||
}
|
||||
|
||||
updatedMetadataFieldLock(bookId: number, field: string, isLocked: boolean): Observable<any> {
|
||||
const requestPayload = {
|
||||
bookId: bookId,
|
||||
field: field,
|
||||
isLocked: isLocked
|
||||
};
|
||||
return this.http.put<BookMetadata>(`${this.url}/lock`, requestPayload).pipe(
|
||||
map(updatedMetadata => {
|
||||
this.bookService.handleBookMetadataUpdate(bookId, updatedMetadata);
|
||||
return updatedMetadata;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
updateBookMetadata(bookId: number, bookMetadata: BookMetadata): Observable<BookMetadata> {
|
||||
return this.http.put<BookMetadata>(`${this.url}/${bookId}`, bookMetadata).pipe(
|
||||
map(updatedMetadata => {
|
||||
@@ -104,4 +90,8 @@ export class MetadataService {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getUploadCoverUrl(bookId: number): string {
|
||||
return this.url + '/' + bookId + "/upload-cover"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user