Fix additional file uploader bugs and move formats to metadata header (#2816)
This commit is contained in:
+6
-13
@@ -30,22 +30,11 @@
|
||||
[disabled]="isUploading"
|
||||
></p-select>
|
||||
|
||||
<!-- Description Field -->
|
||||
<div class="description-field">
|
||||
<label for="description" class="description-label">{{ t('descriptionLabel') }}</label>
|
||||
<p-textarea
|
||||
[(ngModel)]="description"
|
||||
rows="3"
|
||||
[attr.placeholder]="t('descriptionPlaceholder')"
|
||||
class="full-width"
|
||||
[disabled]="isUploading"
|
||||
></p-textarea>
|
||||
</div>
|
||||
|
||||
<!-- File Upload -->
|
||||
<p-fileupload class="file-upload" name="file"
|
||||
[customUpload]="true"
|
||||
[multiple]="false"
|
||||
accept=".pdf,.epub,.cbz,.cbr,.cb7,.fb2,.mobi,.azw,.azw3,.m4b,.m4a,.mp3"
|
||||
(onSelect)="onFilesSelect($event)"
|
||||
(uploadHandler)="uploadFiles($event)"
|
||||
[disabled]="isUploading">
|
||||
@@ -133,7 +122,11 @@
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-cloud-upload empty-icon"></i>
|
||||
<p class="empty-text">{{ t('dragDropText') }}</p>
|
||||
<p class="empty-subtext" [innerHTML]="t('uploadForBook', { title: book.metadata?.title || t('thisBook') })"></p>
|
||||
<p class="empty-subtext">
|
||||
<span [innerHTML]="t('supportedFormats')"></span>
|
||||
<br/>
|
||||
{{ t('maxFileSize', { size: maxFileSizeDisplay }) }}
|
||||
</p>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-fileupload>
|
||||
|
||||
-11
@@ -40,17 +40,6 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.description-field {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.description-label {
|
||||
display: block;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.upload-header-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
+21
-20
@@ -1,19 +1,19 @@
|
||||
import { Component, OnInit, OnDestroy, ChangeDetectorRef, inject } from '@angular/core';
|
||||
import {ChangeDetectorRef, Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/dynamicdialog';
|
||||
import { Select } from 'primeng/select';
|
||||
import { Button } from 'primeng/button';
|
||||
import { FileSelectEvent, FileUpload, FileUploadHandlerEvent } from 'primeng/fileupload';
|
||||
import { Badge } from 'primeng/badge';
|
||||
import { Tooltip } from 'primeng/tooltip';
|
||||
import { Subject, takeUntil } from 'rxjs';
|
||||
import { BookFileService } from '../../service/book-file.service';
|
||||
import { AppSettingsService } from '../../../../shared/service/app-settings.service';
|
||||
import { Book, AdditionalFileType } from '../../model/book.model';
|
||||
import { MessageService } from 'primeng/api';
|
||||
import { filter, take } from 'rxjs/operators';
|
||||
import { TranslocoDirective, TranslocoService } from '@jsverse/transloco';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Button} from 'primeng/button';
|
||||
import {FileSelectEvent, FileUpload, FileUploadHandlerEvent} from 'primeng/fileupload';
|
||||
import {Badge} from 'primeng/badge';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {Subject} from 'rxjs';
|
||||
import {BookFileService} from '../../service/book-file.service';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {AdditionalFileType, Book} from '../../model/book.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
interface FileTypeOption {
|
||||
label: string;
|
||||
@@ -37,7 +37,7 @@ interface UploadingFile {
|
||||
Badge,
|
||||
Tooltip,
|
||||
TranslocoDirective
|
||||
],
|
||||
],
|
||||
templateUrl: './additional-file-uploader.component.html',
|
||||
styleUrls: ['./additional-file-uploader.component.scss']
|
||||
})
|
||||
@@ -47,9 +47,9 @@ export class AdditionalFileUploaderComponent implements OnInit, OnDestroy {
|
||||
book!: Book;
|
||||
files: UploadingFile[] = [];
|
||||
fileType: AdditionalFileType = AdditionalFileType.ALTERNATIVE_FORMAT;
|
||||
description: string = '';
|
||||
isUploading = false;
|
||||
maxFileSizeBytes?: number;
|
||||
maxFileSizeDisplay: string = '100 MB';
|
||||
|
||||
fileTypeOptions: FileTypeOption[] = [];
|
||||
|
||||
@@ -77,7 +77,9 @@ export class AdditionalFileUploaderComponent implements OnInit, OnDestroy {
|
||||
)
|
||||
.subscribe(settings => {
|
||||
if (settings) {
|
||||
this.maxFileSizeBytes = (settings.maxFileUploadSizeInMb || 100) * 1024 * 1024;
|
||||
const maxSizeMb = settings.maxFileUploadSizeInMb || 100;
|
||||
this.maxFileSizeBytes = maxSizeMb * 1024 * 1024;
|
||||
this.maxFileSizeDisplay = `${maxSizeMb} MB`;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -155,8 +157,7 @@ export class AdditionalFileUploaderComponent implements OnInit, OnDestroy {
|
||||
this.bookFileService.uploadAdditionalFile(
|
||||
this.book.id,
|
||||
uploadFile.file,
|
||||
this.fileType,
|
||||
this.description || undefined
|
||||
this.fileType
|
||||
).subscribe({
|
||||
next: () => {
|
||||
uploadFile.status = 'Uploaded';
|
||||
|
||||
@@ -136,7 +136,7 @@ export class BookFileService {
|
||||
);
|
||||
}
|
||||
|
||||
uploadAdditionalFile(bookId: number, file: File, fileType: AdditionalFileType, description?: string): Observable<AdditionalFile> {
|
||||
uploadAdditionalFile(bookId: number, file: File, fileType: AdditionalFileType): Observable<AdditionalFile> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
@@ -146,24 +146,21 @@ export class BookFileService {
|
||||
if (isBook) {
|
||||
const lower = (file?.name || '').toLowerCase();
|
||||
const ext = lower.includes('.') ? lower.substring(lower.lastIndexOf('.') + 1) : '';
|
||||
const bookType = ext === 'pdf'
|
||||
? 'PDF'
|
||||
: ext === 'epub'
|
||||
? 'EPUB'
|
||||
: (ext === 'cbz' || ext === 'cbr' || ext === 'cb7' || ext === 'cbt')
|
||||
? 'CBX'
|
||||
: (ext === 'm4b' || ext === 'm4a' || ext === 'mp3')
|
||||
? 'AUDIOBOOK'
|
||||
: null;
|
||||
const EXTENSION_TO_BOOK_TYPE: Record<string, string> = {
|
||||
pdf: 'PDF',
|
||||
epub: 'EPUB',
|
||||
cbz: 'CBX', cbr: 'CBX', cb7: 'CBX',
|
||||
mobi: 'MOBI',
|
||||
azw3: 'AZW3', azw: 'AZW3',
|
||||
fb2: 'FB2',
|
||||
m4b: 'AUDIOBOOK', m4a: 'AUDIOBOOK', mp3: 'AUDIOBOOK',
|
||||
};
|
||||
const bookType = EXTENSION_TO_BOOK_TYPE[ext] ?? null;
|
||||
|
||||
if (bookType) {
|
||||
formData.append('bookType', bookType);
|
||||
}
|
||||
}
|
||||
if (description) {
|
||||
formData.append('description', description);
|
||||
}
|
||||
|
||||
return this.http.post<AdditionalFile>(`${this.url}/${bookId}/files`, formData).pipe(
|
||||
tap((newFile) => {
|
||||
const currentState = this.bookStateService.getCurrentBookState();
|
||||
|
||||
+24
-24
@@ -128,6 +128,30 @@
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="formats-inline">
|
||||
@if (getDisplayFormat(book?.primaryFile); as displayFormat) {
|
||||
<span class="format-tag-wrapper primary-format" (click)="goToFileType(book?.primaryFile?.filePath)" [pTooltip]="book?.primaryFile?.fileName ?? ''" tooltipPosition="top">
|
||||
<app-tag size="3xs" variant="pill" [customBgColor]="getFileTypeBgColor(displayFormat)" customTextColor="#fff">
|
||||
{{ displayFormat }}
|
||||
</app-tag>
|
||||
<span class="format-badge">{{ t('primaryBadge') }}</span>
|
||||
</span>
|
||||
}
|
||||
@if (getDisplayFormat(book?.primaryFile) && getUniqueAlternativeFormats(book).length > 0) {
|
||||
<span class="format-pipe">|</span>
|
||||
}
|
||||
@for (formatExt of getUniqueAlternativeFormats(book); track formatExt) {
|
||||
<span class="format-tag-wrapper" (click)="goToFileType('.' + formatExt)" [pTooltip]="formatExt" tooltipPosition="top">
|
||||
<app-tag size="3xs" variant="pill" [customBgColor]="getFileTypeBgColor(formatExt)" customTextColor="#fff">
|
||||
{{ formatExt }}
|
||||
</app-tag>
|
||||
</span>
|
||||
}
|
||||
@if (!book?.primaryFile?.filePath && !book?.alternativeFormats?.length) {
|
||||
<app-tag size="3xs" variant="pill" [customBgColor]="'var(--book-type-physical-color)'" customTextColor="#fff">{{ t('physicalBadge') }}</app-tag>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ratings-section">
|
||||
@@ -371,30 +395,6 @@
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="metadata-item">
|
||||
<span class="metadata-key">{{ t('formatsLabel') }}</span>
|
||||
<span class="metadata-value-group format-tags">
|
||||
@if (getDisplayFormat(book?.primaryFile); as displayFormat) {
|
||||
<span class="format-tag-wrapper primary-format" (click)="goToFileType(book?.primaryFile?.filePath)" [pTooltip]="book?.primaryFile?.fileName ?? ''" tooltipPosition="top">
|
||||
<app-tag size="3xs" variant="pill" [customBgColor]="getFileTypeBgColor(displayFormat)" customTextColor="#fff">
|
||||
{{ displayFormat }}
|
||||
</app-tag>
|
||||
<span class="format-badge">{{ t('primaryBadge') }}</span>
|
||||
</span>
|
||||
}
|
||||
@for (formatExt of getUniqueAlternativeFormats(book); track formatExt) {
|
||||
<span class="format-tag-wrapper" (click)="goToFileType('.' + formatExt)" [pTooltip]="formatExt" tooltipPosition="top">
|
||||
<app-tag size="3xs" variant="pill" [customBgColor]="getFileTypeBgColor(formatExt)" customTextColor="#fff">
|
||||
{{ formatExt }}
|
||||
</app-tag>
|
||||
</span>
|
||||
}
|
||||
@if (!book?.primaryFile?.filePath && !book?.alternativeFormats?.length) {
|
||||
<app-tag size="3xs" variant="pill" [customBgColor]="'var(--book-type-physical-color)'" customTextColor="#fff">{{ t('physicalBadge') }}</app-tag>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="metadata-item">
|
||||
<span class="metadata-key">{{ t('bookloreProgressLabel') }}</span>
|
||||
<span class="metadata-value-group">
|
||||
|
||||
+23
-1
@@ -222,6 +222,27 @@
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.formats-inline {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.format-pipe {
|
||||
color: var(--text-color-secondary);
|
||||
font-weight: 300;
|
||||
font-size: 1rem;
|
||||
line-height: 1;
|
||||
user-select: none;
|
||||
|
||||
}
|
||||
|
||||
.author-separator {
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
@@ -437,6 +458,7 @@
|
||||
|
||||
.format-badge {
|
||||
display: none;
|
||||
align-items: center;
|
||||
font-size: 0.55rem;
|
||||
font-weight: 700;
|
||||
color: var(--primary-color);
|
||||
@@ -659,7 +681,7 @@
|
||||
}
|
||||
|
||||
.description-content.line-clamp-7 {
|
||||
max-height: 75px;
|
||||
max-height: 37px;
|
||||
}
|
||||
|
||||
.description-content:not(.line-clamp-7) {
|
||||
|
||||
Reference in New Issue
Block a user