add detach book file feature and fix attach not respecting move preference (#3024)
This commit is contained in:
+1
-1
@@ -51,7 +51,7 @@
|
||||
[dropdown]="true"
|
||||
[showClear]="true"
|
||||
[placeholder]="t('searchPlaceholder')"
|
||||
class="full-width"
|
||||
fluid
|
||||
[disabled]="isAttaching">
|
||||
<ng-template let-book pTemplate="item">
|
||||
<div class="book-suggestion">
|
||||
|
||||
+2
-1
@@ -9,7 +9,7 @@ import { filter, take } from 'rxjs/operators';
|
||||
import { BookService } from '../../service/book.service';
|
||||
import { BookFileService } from '../../service/book-file.service';
|
||||
import { Book } from '../../model/book.model';
|
||||
import { MessageService } from 'primeng/api';
|
||||
import {MessageService, PrimeTemplate} from 'primeng/api';
|
||||
import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/transloco';
|
||||
import { AppSettingsService } from '../../../../shared/service/app-settings.service';
|
||||
|
||||
@@ -23,6 +23,7 @@ import { AppSettingsService } from '../../../../shared/service/app-settings.serv
|
||||
Checkbox,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe,
|
||||
PrimeTemplate,
|
||||
],
|
||||
templateUrl: './book-file-attacher.component.html',
|
||||
styleUrls: ['./book-file-attacher.component.scss']
|
||||
|
||||
@@ -441,3 +441,8 @@ export interface DuplicateGroup {
|
||||
matchReason: string;
|
||||
books: Book[];
|
||||
}
|
||||
|
||||
export interface DetachBookFileResponse {
|
||||
sourceBook: Book;
|
||||
newBook: Book;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import {inject, Injectable} from '@angular/core';
|
||||
import {Observable, throwError} from 'rxjs';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {catchError, tap} from 'rxjs/operators';
|
||||
import {AdditionalFile, AdditionalFileType, Book, DuplicateDetectionRequest, DuplicateGroup} from '../model/book.model';
|
||||
import {AdditionalFile, AdditionalFileType, Book, DetachBookFileResponse, DuplicateDetectionRequest, DuplicateGroup} from '../model/book.model';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {FileDownloadService} from '../../../shared/service/file-download.service';
|
||||
@@ -208,6 +208,37 @@ export class BookFileService {
|
||||
this.fileDownloadService.downloadFile(downloadUrl, additionalFile?.fileName ?? 'file');
|
||||
}
|
||||
|
||||
detachBookFile(bookId: number, fileId: number, copyMetadata: boolean): Observable<DetachBookFileResponse> {
|
||||
return this.http.post<DetachBookFileResponse>(`${this.url}/${bookId}/files/${fileId}/detach`, { copyMetadata }).pipe(
|
||||
tap(response => {
|
||||
const currentState = this.bookStateService.getCurrentBookState();
|
||||
let updatedBooks = (currentState.books || []).map(book =>
|
||||
book.id === bookId ? response.sourceBook : book
|
||||
);
|
||||
updatedBooks = [...updatedBooks, response.newBook];
|
||||
|
||||
this.bookStateService.updateBookState({
|
||||
...currentState,
|
||||
books: updatedBooks
|
||||
});
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('metadata.viewer.toast.detachFileSuccessSummary'),
|
||||
detail: this.t.translate('metadata.viewer.toast.detachFileSuccessDetail')
|
||||
});
|
||||
}),
|
||||
catchError(error => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('metadata.viewer.toast.detachFileErrorSummary'),
|
||||
detail: error?.error?.message || error?.message || this.t.translate('metadata.viewer.toast.detachFileErrorDetail')
|
||||
});
|
||||
return throwError(() => error);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
findDuplicates(request: DuplicateDetectionRequest): Observable<DuplicateGroup[]> {
|
||||
return this.http.post<DuplicateGroup[]>(`${this.url}/duplicates`, request);
|
||||
}
|
||||
|
||||
+33
@@ -194,6 +194,17 @@
|
||||
tooltipPosition="top"
|
||||
(onClick)="download(book)">
|
||||
</p-button>
|
||||
@if (canDetach(book)) {
|
||||
<p-button
|
||||
icon="pi pi-external-link"
|
||||
size="small"
|
||||
text
|
||||
severity="warn"
|
||||
[pTooltip]="t('detachTooltip')"
|
||||
tooltipPosition="top"
|
||||
(onClick)="detachFile(book, book.primaryFile!.id, book.primaryFile!.fileName || 'file')">
|
||||
</p-button>
|
||||
}
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
@@ -271,6 +282,17 @@
|
||||
tooltipPosition="top"
|
||||
(onClick)="downloadAdditionalFile(book, format.id)">
|
||||
</p-button>
|
||||
@if (canDetach(book)) {
|
||||
<p-button
|
||||
icon="pi pi-external-link"
|
||||
size="small"
|
||||
text
|
||||
severity="warn"
|
||||
[pTooltip]="t('detachTooltip')"
|
||||
tooltipPosition="top"
|
||||
(onClick)="detachFile(book, format.id, format.fileName || 'file')">
|
||||
</p-button>
|
||||
}
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
@@ -307,6 +329,17 @@
|
||||
tooltipPosition="top"
|
||||
(onClick)="downloadAdditionalFile(book, file.id)">
|
||||
</p-button>
|
||||
@if (canDetach(book)) {
|
||||
<p-button
|
||||
icon="pi pi-external-link"
|
||||
size="small"
|
||||
text
|
||||
severity="warn"
|
||||
[pTooltip]="t('detachTooltip')"
|
||||
tooltipPosition="top"
|
||||
(onClick)="detachFile(book, file.id, file.fileName || 'file')">
|
||||
</p-button>
|
||||
}
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
|
||||
+18
@@ -47,6 +47,12 @@ export interface DeleteSupplementaryFileEvent {
|
||||
fileName: string;
|
||||
}
|
||||
|
||||
export interface DetachBookFileEvent {
|
||||
book: Book;
|
||||
fileId: number;
|
||||
fileName: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-tabs',
|
||||
standalone: true,
|
||||
@@ -84,6 +90,7 @@ export class MetadataTabsComponent {
|
||||
@Output() downloadAllFiles = new EventEmitter<DownloadAllFilesEvent>();
|
||||
@Output() deleteBookFile = new EventEmitter<DeleteBookFileEvent>();
|
||||
@Output() deleteSupplementaryFile = new EventEmitter<DeleteSupplementaryFileEvent>();
|
||||
@Output() detachBookFile = new EventEmitter<DetachBookFileEvent>();
|
||||
|
||||
get defaultTabValue(): string {
|
||||
return this.bookInSeries && this.bookInSeries.length > 1 ? 'series' : 'similar';
|
||||
@@ -114,6 +121,17 @@ export class MetadataTabsComponent {
|
||||
this.deleteSupplementaryFile.emit({ bookId, fileId, fileName });
|
||||
}
|
||||
|
||||
detachFile(book: Book, fileId: number, fileName: string): void {
|
||||
this.detachBookFile.emit({ book, fileId, fileName });
|
||||
}
|
||||
|
||||
canDetach(book: Book): boolean {
|
||||
const totalFiles = (book.primaryFile ? 1 : 0)
|
||||
+ (book.alternativeFormats?.length ?? 0)
|
||||
+ (book.supplementaryFiles?.length ?? 0);
|
||||
return totalFiles > 1;
|
||||
}
|
||||
|
||||
hasMultipleFiles(book: Book): boolean {
|
||||
const primaryCount = book.primaryFile ? 1 : 0;
|
||||
const altCount = book.alternativeFormats?.length ?? 0;
|
||||
|
||||
+35
-1
@@ -1012,8 +1012,42 @@
|
||||
(downloadFile)="onDownloadFile($event)"
|
||||
(downloadAllFiles)="onDownloadAllFiles($event)"
|
||||
(deleteBookFile)="onDeleteBookFile($event)"
|
||||
(deleteSupplementaryFile)="onDeleteSupplementaryFile($event)">
|
||||
(deleteSupplementaryFile)="onDeleteSupplementaryFile($event)"
|
||||
(detachBookFile)="onDetachBookFile($event)">
|
||||
</app-metadata-tabs>
|
||||
|
||||
<p-dialog
|
||||
[header]="t('confirm.detachFileHeader')"
|
||||
[(visible)]="showDetachDialog"
|
||||
[modal]="true"
|
||||
[closable]="true"
|
||||
[style]="{ width: '450px' }"
|
||||
[breakpoints]="{ '575px': '95vw' }">
|
||||
<div class="detach-dialog-content">
|
||||
<p>{{ t('confirm.detachFileMessage', { fileName: detachFileName }) }}</p>
|
||||
<div class="detach-dialog-option">
|
||||
<p-checkbox
|
||||
[(ngModel)]="detachCopyMetadata"
|
||||
[binary]="true"
|
||||
inputId="copyMetadata">
|
||||
</p-checkbox>
|
||||
<label for="copyMetadata">{{ t('confirm.detachFileCopyMetadata') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
<ng-template #footer>
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
severity="secondary"
|
||||
(onClick)="showDetachDialog = false">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="t('confirm.detachFileBtn')"
|
||||
severity="warn"
|
||||
icon="pi pi-external-link"
|
||||
(onClick)="confirmDetach()">
|
||||
</p-button>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="loading-state" *transloco="let t; prefix: 'metadata.viewer'">
|
||||
|
||||
+12
@@ -1184,3 +1184,15 @@
|
||||
font-size: 0.8rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.detach-dialog-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
|
||||
.detach-dialog-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
+22
-2
@@ -33,9 +33,11 @@ import {AGE_RATING_OPTIONS, CONTENT_RATING_LABELS, fileSizeRanges, matchScoreRan
|
||||
import {BookNavigationService} from '../../../../book/service/book-navigation.service';
|
||||
import {BookMetadataHostService} from '../../../../../shared/service/book-metadata-host.service';
|
||||
import {AppSettingsService} from '../../../../../shared/service/app-settings.service';
|
||||
import {DeleteBookFileEvent, DeleteSupplementaryFileEvent, DownloadAdditionalFileEvent, DownloadAllFilesEvent, DownloadEvent, MetadataTabsComponent, ReadEvent} from './metadata-tabs/metadata-tabs.component';
|
||||
import {DeleteBookFileEvent, DeleteSupplementaryFileEvent, DetachBookFileEvent, DownloadAdditionalFileEvent, DownloadAllFilesEvent, DownloadEvent, MetadataTabsComponent, ReadEvent} from './metadata-tabs/metadata-tabs.component';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
import {AuthorService} from '../../../../author-browser/service/author.service';
|
||||
import {Dialog} from 'primeng/dialog';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -43,7 +45,7 @@ import {AuthorService} from '../../../../author-browser/service/author.service';
|
||||
standalone: true,
|
||||
templateUrl: './metadata-viewer.component.html',
|
||||
styleUrl: './metadata-viewer.component.scss',
|
||||
imports: [Button, AsyncPipe, Rating, FormsModule, SplitButton, NgClass, Tooltip, DecimalPipe, ProgressBar, Menu, DatePicker, ProgressSpinner, TieredMenu, Image, TagComponent, MetadataTabsComponent, TranslocoDirective, TranslocoPipe]
|
||||
imports: [Button, AsyncPipe, Rating, FormsModule, SplitButton, NgClass, Tooltip, DecimalPipe, ProgressBar, Menu, DatePicker, ProgressSpinner, TieredMenu, Image, TagComponent, MetadataTabsComponent, TranslocoDirective, TranslocoPipe, Dialog, Checkbox]
|
||||
})
|
||||
export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChecked {
|
||||
@Input() book$!: Observable<Book | null>;
|
||||
@@ -85,6 +87,11 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec
|
||||
selectedReadStatus: ReadStatus = ReadStatus.UNREAD;
|
||||
isEditingDateFinished = false;
|
||||
editDateFinished: Date | null = null;
|
||||
showDetachDialog = false;
|
||||
detachCopyMetadata = true;
|
||||
private detachBookId = 0;
|
||||
private detachFileId = 0;
|
||||
detachFileName = '';
|
||||
|
||||
readStatusOptions: { value: ReadStatus, labelKey: string }[] = [
|
||||
{value: ReadStatus.UNREAD, labelKey: 'metadata.viewer.readStatusUnread'},
|
||||
@@ -537,6 +544,19 @@ export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChec
|
||||
this.deleteAdditionalFile(event.bookId, event.fileId, event.fileName);
|
||||
}
|
||||
|
||||
onDetachBookFile(event: DetachBookFileEvent): void {
|
||||
this.detachBookId = event.book.id;
|
||||
this.detachFileId = event.fileId;
|
||||
this.detachFileName = event.fileName;
|
||||
this.detachCopyMetadata = true;
|
||||
this.showDetachDialog = true;
|
||||
}
|
||||
|
||||
confirmDetach(): void {
|
||||
this.showDetachDialog = false;
|
||||
this.bookFileService.detachBookFile(this.detachBookId, this.detachFileId, this.detachCopyMetadata).subscribe();
|
||||
}
|
||||
|
||||
deleteAdditionalFile(bookId: number, fileId: number, fileName: string) {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('metadata.viewer.confirm.deleteSupplementaryMessage', { fileName }),
|
||||
|
||||
@@ -220,6 +220,7 @@
|
||||
"playTooltip": "Play",
|
||||
"downloadTooltip": "Download",
|
||||
"deleteTooltip": "Delete",
|
||||
"detachTooltip": "Detach",
|
||||
"downloadAllTooltip": "Download all files as a ZIP archive",
|
||||
"physicalBookHint": "You can upload a digital copy or add metadata manually."
|
||||
},
|
||||
@@ -355,6 +356,10 @@
|
||||
"deleteFormatSuccessDetail": "Book format \"{{ fileName }}\" deleted successfully",
|
||||
"deleteFormatErrorSummary": "Error",
|
||||
"deleteFormatErrorDetail": "Failed to delete book format: {{ error }}",
|
||||
"detachFileSuccessSummary": "File Detached",
|
||||
"detachFileSuccessDetail": "The file has been detached and a new book has been created.",
|
||||
"detachFileErrorSummary": "Detach Failed",
|
||||
"detachFileErrorDetail": "Failed to detach file.",
|
||||
"dateUpdatedSummary": "Date Updated",
|
||||
"dateUpdatedDetail": "Book finish date has been updated.",
|
||||
"dateUpdateFailedSummary": "Update Failed",
|
||||
@@ -372,6 +377,10 @@
|
||||
"deleteAltFormatMessage": "Are you sure you want to delete \"{{ fileName }}\"?\n\nThis file will be permanently removed from your filesystem.",
|
||||
"deleteAltFormatHeader": "Delete Book Format",
|
||||
"deleteFileBtn": "Delete File",
|
||||
"detachFileHeader": "Detach File",
|
||||
"detachFileMessage": "This will detach \"{{ fileName }}\" from this book and create a new standalone book for it. The file will not be deleted.",
|
||||
"detachFileCopyMetadata": "Copy metadata to new book",
|
||||
"detachFileBtn": "Detach",
|
||||
"deleteBookMessage": "Are you sure you want to delete \"{{ title }}\"?\n\nThis will permanently remove the book record from your library.\n\nThis action cannot be undone.",
|
||||
"deleteBookAllFilesMessage": "Are you sure you want to delete \"{{ title }}\"?\n\nThis will permanently remove the book record AND all associated files from your filesystem.\n\nThis action cannot be undone.",
|
||||
"deleteEverythingBtn": "Delete Everything"
|
||||
|
||||
@@ -220,6 +220,7 @@
|
||||
"playTooltip": "Reproducir",
|
||||
"downloadTooltip": "Descargar",
|
||||
"deleteTooltip": "Eliminar",
|
||||
"detachTooltip": "Separar",
|
||||
"downloadAllTooltip": "Descargar todos los archivos como archivo ZIP",
|
||||
"physicalBookHint": "Puede subir una copia digital o agregar metadatos manualmente."
|
||||
},
|
||||
@@ -355,6 +356,10 @@
|
||||
"deleteFormatSuccessDetail": "Formato de libro \"{{ fileName }}\" eliminado correctamente",
|
||||
"deleteFormatErrorSummary": "Error",
|
||||
"deleteFormatErrorDetail": "Error al eliminar formato de libro: {{ error }}",
|
||||
"detachFileSuccessSummary": "Archivo separado",
|
||||
"detachFileSuccessDetail": "El archivo se ha separado y se ha creado un nuevo libro.",
|
||||
"detachFileErrorSummary": "Error al separar",
|
||||
"detachFileErrorDetail": "No se pudo separar el archivo.",
|
||||
"dateUpdatedSummary": "Fecha actualizada",
|
||||
"dateUpdatedDetail": "La fecha de finalización del libro se ha actualizado.",
|
||||
"dateUpdateFailedSummary": "Actualización fallida",
|
||||
@@ -372,6 +377,10 @@
|
||||
"deleteAltFormatMessage": "¿Estás seguro de que deseas eliminar \"{{ fileName }}\"?\n\nEste archivo será eliminado permanentemente de tu sistema de archivos.",
|
||||
"deleteAltFormatHeader": "Eliminar formato del libro",
|
||||
"deleteFileBtn": "Eliminar archivo",
|
||||
"detachFileHeader": "Separar archivo",
|
||||
"detachFileMessage": "Esto separará \"{{ fileName }}\" de este libro y creará un nuevo libro independiente. El archivo no será eliminado.",
|
||||
"detachFileCopyMetadata": "Copiar metadatos al nuevo libro",
|
||||
"detachFileBtn": "Separar",
|
||||
"deleteBookMessage": "¿Estás seguro de que deseas eliminar \"{{ title }}\"?\n\nEsto eliminará permanentemente el registro del libro de tu biblioteca.\n\nEsta acción no se puede deshacer.",
|
||||
"deleteBookAllFilesMessage": "¿Estás seguro de que deseas eliminar \"{{ title }}\"?\n\nEsto eliminará permanentemente el registro del libro Y todos los archivos asociados de tu sistema de archivos.\n\nEsta acción no se puede deshacer.",
|
||||
"deleteEverythingBtn": "Eliminar todo"
|
||||
|
||||
Reference in New Issue
Block a user