refactor(frontend): rename booklore-ui to frontend
- Frontend path: - rename the tracked Angular app tree from `booklore-ui/` to `frontend/` - preserve file contents during the move so this commit stays focused on the path change itself - Frontend docs: - update the moved frontend README and contribution guide where they refer to the renamed folder - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
+382
@@ -0,0 +1,382 @@
|
||||
<div class="bulk-update-container">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-pencil header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">Bulk Edit Metadata</h2>
|
||||
<p class="panel-description">{{ books.length }} book{{ books.length !== 1 ? 's' : '' }} selected</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[rounded]="true"
|
||||
[text]="true"
|
||||
severity="secondary"
|
||||
(click)="ref.close()"
|
||||
class="close-button">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-content">
|
||||
@if (loading) {
|
||||
<div class="loading-overlay">
|
||||
<p-progressSpinner></p-progressSpinner>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="info-box">
|
||||
<div class="info-header">
|
||||
<p class="info-title">
|
||||
Editing {{ books.length }} Book{{ books.length !== 1 ? 's' : '' }}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
(click)="showBookList = !showBookList"
|
||||
class="toggle-list-btn">
|
||||
{{ showBookList ? 'Hide' : 'Show' }} Titles
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (showBookList) {
|
||||
<div class="book-list-panel">
|
||||
<ul class="book-list">
|
||||
@for (book of books; track book) {
|
||||
<li>{{ book.metadata?.title || 'Untitled Book' }}</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="warning-text">
|
||||
<i class="pi pi-exclamation-triangle warning-icon"></i>
|
||||
Checking <strong>Clear</strong> will remove that field's metadata from <strong>all selected books</strong>.
|
||||
</div>
|
||||
|
||||
<form [formGroup]="metadataForm" (ngSubmit)="onSubmit()" (keydown)="onFormKeydown($event)" class="bulk-form">
|
||||
|
||||
<div class="form-row">
|
||||
<!-- Authors -->
|
||||
<div class="field-group field-group--wide">
|
||||
<label for="authors" class="field-label-row">
|
||||
<span class="field-label-text">
|
||||
Author(s)
|
||||
<i class="pi pi-info-circle info-icon"
|
||||
pTooltip="Enter multiple authors. Press Enter after typing each name."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer"></i>
|
||||
</span>
|
||||
<div class="clear-checkbox">
|
||||
<p-checkbox [(ngModel)]="clearFields.authors" [ngModelOptions]="{standalone: true}" (onChange)="onFieldClearToggle('authors')" binary="true" inputId="clearAuthors"/>
|
||||
<label for="clearAuthors" class="clear-label">Clear</label>
|
||||
</div>
|
||||
</label>
|
||||
<p-autoComplete
|
||||
class="full-width"
|
||||
id="authors"
|
||||
formControlName="authors"
|
||||
[disabled]="clearFields.authors"
|
||||
[multiple]="true"
|
||||
[dropdown]="false"
|
||||
[forceSelection]="false"
|
||||
[suggestions]="filteredAuthors"
|
||||
(completeMethod)="filterAuthors($event)"
|
||||
(onKeyUp)="onAutoCompleteKeyUp('authors', $event)"
|
||||
(onSelect)="onAutoCompleteSelect('authors', $event)">
|
||||
</p-autoComplete>
|
||||
</div>
|
||||
|
||||
<!-- Language -->
|
||||
<div class="field-group field-group--narrow">
|
||||
<label for="language" class="field-label-row">
|
||||
<span>Language</span>
|
||||
<div class="clear-checkbox">
|
||||
<p-checkbox [(ngModel)]="clearFields.language" [ngModelOptions]="{standalone: true}"
|
||||
(onChange)="onFieldClearToggle('language')" binary="true" inputId="clearLanguage"/>
|
||||
<label for="clearLanguage" class="clear-label">Clear</label>
|
||||
</div>
|
||||
</label>
|
||||
<input pInputText id="language" formControlName="language" [disabled]="clearFields.language" class="full-width"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<!-- Publisher -->
|
||||
<div class="field-group field-group--wide">
|
||||
<label for="publisher" class="field-label-row">
|
||||
<span>Publisher</span>
|
||||
<div class="clear-checkbox">
|
||||
<p-checkbox [(ngModel)]="clearFields.publisher" [ngModelOptions]="{standalone: true}"
|
||||
(onChange)="onFieldClearToggle('publisher')" binary="true" inputId="clearPublisher"/>
|
||||
<label for="clearPublisher" class="clear-label">Clear</label>
|
||||
</div>
|
||||
</label>
|
||||
<p-autoComplete
|
||||
class="full-width"
|
||||
inputStyleClass="full-width"
|
||||
formControlName="publisher"
|
||||
inputId="publisher"
|
||||
[disabled]="clearFields.publisher"
|
||||
[multiple]="false"
|
||||
[dropdown]="false"
|
||||
[showClear]="true"
|
||||
[forceSelection]="false"
|
||||
[suggestions]="filteredPublishers"
|
||||
(completeMethod)="filterPublishers($event)">
|
||||
</p-autoComplete>
|
||||
</div>
|
||||
|
||||
<!-- Published Date -->
|
||||
<div class="field-group field-group--narrow">
|
||||
<label for="publishedDate" class="field-label-row">
|
||||
<span>Published Date</span>
|
||||
<div class="clear-checkbox">
|
||||
<p-checkbox [(ngModel)]="clearFields.publishedDate" [ngModelOptions]="{standalone: true}"
|
||||
(onChange)="onFieldClearToggle('publishedDate')" binary="true" inputId="clearPublishedDate"/>
|
||||
<label for="clearPublishedDate" class="clear-label">Clear</label>
|
||||
</div>
|
||||
</label>
|
||||
<p-datepicker
|
||||
class="full-width datepicker-min-width"
|
||||
formControlName="publishedDate"
|
||||
inputId="publishedDate"
|
||||
dataType="string"
|
||||
dateFormat="yy-mm-dd"
|
||||
[disabled]="clearFields.publishedDate"
|
||||
[keepInvalid]="true"
|
||||
[showIcon]="true"
|
||||
[iconDisplay]="'input'"
|
||||
fluid="true"
|
||||
appendTo="body">
|
||||
</p-datepicker>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<!-- Series Name -->
|
||||
<div class="field-group field-group--wide">
|
||||
<label for="seriesName" class="field-label-row">
|
||||
<span>Series Name</span>
|
||||
<div class="clear-checkbox">
|
||||
<p-checkbox [(ngModel)]="clearFields.seriesName" [ngModelOptions]="{standalone: true}"
|
||||
(onChange)="onFieldClearToggle('seriesName')" binary="true" inputId="clearSeriesName"/>
|
||||
<label for="clearSeriesName" class="clear-label">Clear</label>
|
||||
</div>
|
||||
</label>
|
||||
<p-autoComplete
|
||||
class="full-width"
|
||||
inputStyleClass="full-width"
|
||||
formControlName="seriesName"
|
||||
inputId="seriesName"
|
||||
[disabled]="clearFields.seriesName"
|
||||
[multiple]="false"
|
||||
[dropdown]="false"
|
||||
[showClear]="true"
|
||||
[forceSelection]="false"
|
||||
[suggestions]="filteredSeries"
|
||||
(completeMethod)="filterSeries($event)">
|
||||
</p-autoComplete>
|
||||
</div>
|
||||
|
||||
<!-- Series Total -->
|
||||
<div class="field-group field-group--narrow">
|
||||
<label for="seriesTotal" class="field-label-row">
|
||||
<span class="field-label-text">
|
||||
Total Books
|
||||
<i class="pi pi-info-circle info-icon"
|
||||
pTooltip="Total number of books in the series."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer"></i>
|
||||
</span>
|
||||
<div class="clear-checkbox">
|
||||
<p-checkbox [(ngModel)]="clearFields.seriesTotal" [ngModelOptions]="{standalone: true}"
|
||||
(onChange)="onFieldClearToggle('seriesTotal')" binary="true" inputId="clearSeriesTotal"/>
|
||||
<label for="clearSeriesTotal" class="clear-label">Clear</label>
|
||||
</div>
|
||||
</label>
|
||||
<input pInputText id="seriesTotal" type="number" min="1" formControlName="seriesTotal"
|
||||
[disabled]="clearFields.seriesTotal" class="full-width"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Genres -->
|
||||
<div class="field-group">
|
||||
<label for="genres" class="field-label-row">
|
||||
<span class="field-label-text">
|
||||
Genre(s)
|
||||
<i class="pi pi-info-circle info-icon"
|
||||
pTooltip="Enter multiple genres. Press Enter after typing each genre."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer"></i>
|
||||
</span>
|
||||
<div class="clear-checkbox">
|
||||
<p-checkbox [(ngModel)]="clearFields.genres" [ngModelOptions]="{standalone: true}"
|
||||
(onChange)="onFieldClearToggle('genres')" binary="true" inputId="clearGenres"/>
|
||||
<label for="clearGenres" class="clear-label">Clear</label>
|
||||
</div>
|
||||
</label>
|
||||
<p-autoComplete
|
||||
class="full-width"
|
||||
id="genres"
|
||||
formControlName="genres"
|
||||
[disabled]="clearFields.genres"
|
||||
[multiple]="true"
|
||||
[dropdown]="false"
|
||||
[forceSelection]="false"
|
||||
[suggestions]="filteredGenres"
|
||||
(completeMethod)="filterGenres($event)"
|
||||
(onKeyUp)="onAutoCompleteKeyUp('genres', $event)"
|
||||
(onSelect)="onAutoCompleteSelect('genres', $event)">
|
||||
</p-autoComplete>
|
||||
|
||||
<div class="merge-option">
|
||||
<p-checkbox
|
||||
inputId="mergeCategories"
|
||||
name="mergeCategories"
|
||||
[(ngModel)]="mergeCategories"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
binary="true"
|
||||
/>
|
||||
<label for="mergeCategories" class="clear-label">
|
||||
Keep existing genres and add new ones (uncheck to remove all existing genres)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Moods -->
|
||||
<div class="field-group">
|
||||
<label for="moods" class="field-label-row">
|
||||
<span class="field-label-text">
|
||||
Mood(s)
|
||||
<i class="pi pi-info-circle info-icon"
|
||||
pTooltip="Enter multiple moods. Press Enter after typing each mood."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer"></i>
|
||||
</span>
|
||||
<div class="clear-checkbox">
|
||||
<p-checkbox [(ngModel)]="clearFields.moods" [ngModelOptions]="{standalone: true}"
|
||||
(onChange)="onFieldClearToggle('moods')" binary="true" inputId="clearMoods"/>
|
||||
<label for="clearMoods" class="clear-label">Clear</label>
|
||||
</div>
|
||||
</label>
|
||||
<p-autoComplete
|
||||
class="full-width"
|
||||
id="moods"
|
||||
formControlName="moods"
|
||||
[disabled]="clearFields.moods"
|
||||
[multiple]="true"
|
||||
[dropdown]="false"
|
||||
[forceSelection]="false"
|
||||
[suggestions]="filteredMoods"
|
||||
(completeMethod)="filterMoods($event)"
|
||||
(onKeyUp)="onAutoCompleteKeyUp('moods', $event)"
|
||||
(onSelect)="onAutoCompleteSelect('moods', $event)">
|
||||
</p-autoComplete>
|
||||
|
||||
<div class="merge-option">
|
||||
<p-checkbox
|
||||
inputId="mergeMoods"
|
||||
name="mergeMoods"
|
||||
[(ngModel)]="mergeMoods"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
binary="true"
|
||||
/>
|
||||
<label for="mergeMoods" class="clear-label">
|
||||
Keep existing moods and add new ones (uncheck to remove all existing moods)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tags -->
|
||||
<div class="field-group">
|
||||
<label for="tags" class="field-label-row">
|
||||
<span class="field-label-text">
|
||||
Tag(s)
|
||||
<i class="pi pi-info-circle info-icon"
|
||||
pTooltip="Enter multiple tags. Press Enter after typing each tag."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer"></i>
|
||||
</span>
|
||||
<div class="clear-checkbox">
|
||||
<p-checkbox [(ngModel)]="clearFields.tags" [ngModelOptions]="{standalone: true}"
|
||||
(onChange)="onFieldClearToggle('tags')" binary="true" inputId="clearTags"/>
|
||||
<label for="clearTags" class="clear-label">Clear</label>
|
||||
</div>
|
||||
</label>
|
||||
<p-autoComplete
|
||||
class="full-width"
|
||||
id="tags"
|
||||
formControlName="tags"
|
||||
[disabled]="clearFields.tags"
|
||||
[multiple]="true"
|
||||
[dropdown]="false"
|
||||
[forceSelection]="false"
|
||||
[suggestions]="filteredTags"
|
||||
(completeMethod)="filterTags($event)"
|
||||
(onKeyUp)="onAutoCompleteKeyUp('tags', $event)"
|
||||
(onSelect)="onAutoCompleteSelect('tags', $event)">
|
||||
</p-autoComplete>
|
||||
|
||||
<div class="merge-option">
|
||||
<p-checkbox
|
||||
inputId="mergeTags"
|
||||
name="mergeTags"
|
||||
[(ngModel)]="mergeTags"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
binary="true"
|
||||
/>
|
||||
<label for="mergeTags" class="clear-label">
|
||||
Keep existing tags and add new ones (uncheck to remove all existing tags)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Cover Image Upload Section -->
|
||||
<div class="cover-section">
|
||||
<label class="cover-label">
|
||||
<i class="pi pi-image"></i>
|
||||
Cover Image
|
||||
</label>
|
||||
<p class="cover-description">
|
||||
Upload an image to set as the cover for all selected books.
|
||||
</p>
|
||||
<div class="cover-actions">
|
||||
@if (selectedCoverFile) {
|
||||
<div class="cover-file-info">
|
||||
<i class="pi pi-file-image"></i>
|
||||
<span>{{ selectedCoverFile.name }}</span>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
[text]="true"
|
||||
size="small"
|
||||
severity="danger"
|
||||
(onClick)="clearCoverFile()"
|
||||
pTooltip="Remove file"
|
||||
tooltipPosition="top">
|
||||
</p-button>
|
||||
</div>
|
||||
} @else {
|
||||
<input
|
||||
type="file"
|
||||
#coverFileInput
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
(change)="onCoverFileSelect($event)"
|
||||
class="file-input-hidden">
|
||||
<p-button
|
||||
icon="pi pi-upload"
|
||||
label="Select Image"
|
||||
[outlined]="true"
|
||||
size="small"
|
||||
severity="info"
|
||||
(onClick)="coverFileInput.click()">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-submit">
|
||||
<p-button type="submit" label="Apply to Selected" [disabled]="loading"/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.bulk-update-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
border-radius: 0 0 10px 10px;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.loading-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 50;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.info-box {
|
||||
padding: 1rem;
|
||||
border: 1px solid #374151;
|
||||
border-radius: 0.375rem;
|
||||
margin-bottom: 1rem;
|
||||
background: #111827;
|
||||
color: #e5e7eb;
|
||||
}
|
||||
|
||||
.info-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.info-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.toggle-list-btn {
|
||||
font-size: 0.875rem;
|
||||
color: #38bdf8;
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.book-list-panel {
|
||||
max-height: 12rem;
|
||||
overflow-y: auto;
|
||||
border-top: 1px solid #374151;
|
||||
padding-top: 0.5rem;
|
||||
padding-left: 0.25rem;
|
||||
font-size: 0.875rem;
|
||||
color: #d1d5db;
|
||||
}
|
||||
|
||||
.book-list {
|
||||
list-style-type: disc;
|
||||
padding-left: 1.25rem;
|
||||
|
||||
li + li {
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.warning-text {
|
||||
padding: 0 1rem;
|
||||
font-size: 0.875rem;
|
||||
color: #eab308;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.warning-icon {
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
|
||||
.bulk-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1.75rem;
|
||||
}
|
||||
|
||||
.field-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
&--wide {
|
||||
width: 100%;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
flex-basis: 80%;
|
||||
}
|
||||
}
|
||||
|
||||
&--narrow {
|
||||
@media (min-width: 768px) {
|
||||
flex-basis: 20%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.field-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.field-label-text {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.info-icon {
|
||||
color: #0284c7;
|
||||
}
|
||||
|
||||
.clear-checkbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.clear-label {
|
||||
font-size: 0.875rem;
|
||||
color: #d1d5db;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.datepicker-min-width {
|
||||
@media (min-width: 768px) {
|
||||
min-width: 9rem;
|
||||
}
|
||||
}
|
||||
|
||||
.merge-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.cover-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
border: 1px solid #374151;
|
||||
border-radius: 0.375rem;
|
||||
padding: 1rem;
|
||||
background: #111827;
|
||||
}
|
||||
|
||||
.cover-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.cover-description {
|
||||
font-size: 0.875rem;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.cover-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.cover-file-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
color: #d1d5db;
|
||||
}
|
||||
|
||||
.file-input-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.form-submit {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
::ng-deep .p-inputchips {
|
||||
width: 100%;
|
||||
}
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
import {Component, computed, effect, inject, Injector, OnInit} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {DatePicker} from 'primeng/datepicker';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {BookMetadataManageService} from '../../../book/service/book-metadata-manage.service';
|
||||
import {Book, BulkMetadataUpdateRequest} from '../../../book/model/book.model';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {AutoComplete} from 'primeng/autocomplete';
|
||||
import {AutoCompleteSelectEvent} from 'primeng/autocomplete';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bulk-metadata-update-component',
|
||||
standalone: true,
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
InputText,
|
||||
Button,
|
||||
Tooltip,
|
||||
DatePicker,
|
||||
Checkbox,
|
||||
ProgressSpinner,
|
||||
AutoComplete
|
||||
],
|
||||
providers: [MessageService],
|
||||
templateUrl: './bulk-metadata-update-component.html',
|
||||
styleUrl: './bulk-metadata-update-component.scss'
|
||||
})
|
||||
export class BulkMetadataUpdateComponent implements OnInit {
|
||||
metadataForm!: FormGroup;
|
||||
bookIds: number[] = [];
|
||||
books: Book[] = [];
|
||||
showBookList = true;
|
||||
mergeCategories = true;
|
||||
mergeMoods = true;
|
||||
mergeTags = true;
|
||||
loading = false;
|
||||
selectedCoverFile: File | null = null;
|
||||
|
||||
clearFields = {
|
||||
authors: false,
|
||||
publisher: false,
|
||||
language: false,
|
||||
seriesName: false,
|
||||
seriesTotal: false,
|
||||
publishedDate: false,
|
||||
genres: false,
|
||||
moods: false,
|
||||
tags: false,
|
||||
};
|
||||
|
||||
private readonly config = inject(DynamicDialogConfig);
|
||||
readonly ref = inject(DynamicDialogRef);
|
||||
private readonly fb = inject(FormBuilder);
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly bookMetadataManageService = inject(BookMetadataManageService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly injector = inject(Injector);
|
||||
private readonly uniqueMetadata = computed(() => this.bookService.uniqueMetadata());
|
||||
|
||||
get allAuthors(): string[] { return this.uniqueMetadata().authors; }
|
||||
get allGenres(): string[] { return this.uniqueMetadata().categories; }
|
||||
get allMoods(): string[] { return this.uniqueMetadata().moods; }
|
||||
get allTags(): string[] { return this.uniqueMetadata().tags; }
|
||||
get allPublishers(): string[] { return this.uniqueMetadata().publishers; }
|
||||
get allSeries(): string[] { return this.uniqueMetadata().series; }
|
||||
filteredGenres: string[] = [];
|
||||
filteredAuthors: string[] = [];
|
||||
filteredMoods: string[] = [];
|
||||
filteredTags: string[] = [];
|
||||
filteredPublishers: string[] = [];
|
||||
filteredSeries: string[] = [];
|
||||
|
||||
filterGenres(event: { query: string }) {
|
||||
const query = event.query.toLowerCase();
|
||||
this.filteredGenres = this.allGenres.filter((cat) =>
|
||||
cat.toLowerCase().includes(query)
|
||||
);
|
||||
}
|
||||
|
||||
filterAuthors(event: { query: string }) {
|
||||
const query = event.query.toLowerCase();
|
||||
this.filteredAuthors = this.allAuthors.filter((author) =>
|
||||
author.toLowerCase().includes(query)
|
||||
);
|
||||
}
|
||||
|
||||
filterMoods(event: { query: string }) {
|
||||
const query = event.query.toLowerCase();
|
||||
this.filteredMoods = this.allMoods.filter((mood) =>
|
||||
mood.toLowerCase().includes(query)
|
||||
);
|
||||
}
|
||||
|
||||
filterTags(event: { query: string }) {
|
||||
const query = event.query.toLowerCase();
|
||||
this.filteredTags = this.allTags.filter((tag) =>
|
||||
tag.toLowerCase().includes(query)
|
||||
);
|
||||
}
|
||||
|
||||
filterPublishers(event: { query: string }) {
|
||||
const query = event.query.toLowerCase();
|
||||
this.filteredPublishers = this.allPublishers.filter((publisher) =>
|
||||
publisher.toLowerCase().includes(query)
|
||||
);
|
||||
}
|
||||
|
||||
filterSeries(event: { query: string }) {
|
||||
const query = event.query.toLowerCase();
|
||||
this.filteredSeries = this.allSeries.filter((seriesName) =>
|
||||
seriesName.toLowerCase().includes(query)
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookIds = this.config.data?.bookIds ?? [];
|
||||
this.books = this.bookService.getBooksByIds(this.bookIds);
|
||||
|
||||
this.metadataForm = this.fb.group({
|
||||
authors: [],
|
||||
publisher: [''],
|
||||
language: [''],
|
||||
seriesName: [''],
|
||||
seriesTotal: [''],
|
||||
publishedDate: [null],
|
||||
genres: [],
|
||||
moods: [],
|
||||
tags: []
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
this.books = this.bookService.books().filter(book => this.bookIds.includes(book.id));
|
||||
}, {injector: this.injector});
|
||||
}
|
||||
|
||||
onFieldClearToggle(field: keyof typeof this.clearFields): void {
|
||||
const control = this.metadataForm.get(field);
|
||||
if (!control) return;
|
||||
|
||||
if (this.clearFields[field]) {
|
||||
control.disable();
|
||||
control.setValue(null);
|
||||
} else {
|
||||
control.enable();
|
||||
}
|
||||
}
|
||||
|
||||
onAutoCompleteSelect(fieldName: string, event: AutoCompleteSelectEvent) {
|
||||
const values = (this.metadataForm.get(fieldName)?.value as string[]) || [];
|
||||
if (!values.includes(event.value as string)) {
|
||||
this.metadataForm.get(fieldName)?.setValue([...values, event.value as string]);
|
||||
}
|
||||
(event.originalEvent.target as HTMLInputElement).value = "";
|
||||
}
|
||||
|
||||
onAutoCompleteKeyUp(fieldName: string, event: KeyboardEvent) {
|
||||
if (event.key === "Enter") {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const value = input.value?.trim();
|
||||
if (value) {
|
||||
const values = this.metadataForm.get(fieldName)?.value || [];
|
||||
if (!values.includes(value)) {
|
||||
this.metadataForm.get(fieldName)?.setValue([...values, value]);
|
||||
}
|
||||
input.value = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onFormKeydown(event: KeyboardEvent): void {
|
||||
if (event.key === 'Enter') {
|
||||
if ((event.target as HTMLElement)?.tagName === 'BUTTON' &&
|
||||
(event.target as HTMLButtonElement)?.type === 'submit') {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
onSubmit(): void {
|
||||
if (!this.metadataForm.valid) return;
|
||||
|
||||
const formValue = this.metadataForm.value;
|
||||
|
||||
const payload: BulkMetadataUpdateRequest = {
|
||||
bookIds: this.bookIds,
|
||||
|
||||
authors: this.clearFields.authors ? [] : (formValue.authors?.length ? formValue.authors : undefined),
|
||||
clearAuthors: this.clearFields.authors,
|
||||
|
||||
publisher: this.clearFields.publisher ? '' : (formValue.publisher?.trim() || undefined),
|
||||
clearPublisher: this.clearFields.publisher,
|
||||
|
||||
language: this.clearFields.language ? '' : (formValue.language?.trim() || undefined),
|
||||
clearLanguage: this.clearFields.language,
|
||||
|
||||
seriesName: this.clearFields.seriesName ? '' : (formValue.seriesName?.trim() || undefined),
|
||||
clearSeriesName: this.clearFields.seriesName,
|
||||
|
||||
seriesTotal: this.clearFields.seriesTotal ? null : (formValue.seriesTotal || undefined),
|
||||
clearSeriesTotal: this.clearFields.seriesTotal,
|
||||
|
||||
publishedDate: this.clearFields.publishedDate
|
||||
? null
|
||||
: (formValue.publishedDate ? new Date(formValue.publishedDate).toISOString().split('T')[0] : undefined),
|
||||
clearPublishedDate: this.clearFields.publishedDate,
|
||||
|
||||
genres: this.clearFields.genres ? [] : (formValue.genres?.length ? formValue.genres : undefined),
|
||||
clearGenres: this.clearFields.genres,
|
||||
|
||||
moods: this.clearFields.moods ? [] : (formValue.moods?.length ? formValue.moods : undefined),
|
||||
clearMoods: this.clearFields.moods,
|
||||
|
||||
tags: this.clearFields.tags ? [] : (formValue.tags?.length ? formValue.tags : undefined),
|
||||
clearTags: this.clearFields.tags,
|
||||
|
||||
mergeCategories: this.mergeCategories,
|
||||
mergeMoods: this.mergeMoods,
|
||||
mergeTags: this.mergeTags
|
||||
};
|
||||
|
||||
this.loading = true;
|
||||
this.bookMetadataManageService.updateBooksMetadata(payload).subscribe({
|
||||
next: () => {
|
||||
if (this.selectedCoverFile) {
|
||||
this.bookMetadataManageService.bulkUploadCover(this.bookIds, this.selectedCoverFile).subscribe({
|
||||
next: () => {
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Metadata & Cover Updated',
|
||||
detail: 'Books updated and cover upload started. Refresh the page when complete.'
|
||||
});
|
||||
this.ref.close(true);
|
||||
},
|
||||
error: err => {
|
||||
console.error('Bulk cover upload failed:', err);
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'Partial Success',
|
||||
detail: 'Metadata updated but cover upload failed'
|
||||
});
|
||||
this.ref.close(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Metadata Updated',
|
||||
detail: 'Books updated successfully'
|
||||
});
|
||||
this.ref.close(true);
|
||||
}
|
||||
},
|
||||
error: err => {
|
||||
console.error('Bulk metadata update failed:', err);
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Update Failed',
|
||||
detail: 'An error occurred while updating book metadata'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onCoverFileSelect(event: Event): void {
|
||||
const input = event.target as HTMLInputElement;
|
||||
if (input.files && input.files.length > 0) {
|
||||
this.selectedCoverFile = input.files[0];
|
||||
}
|
||||
}
|
||||
|
||||
clearCoverFile(): void {
|
||||
this.selectedCoverFile = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user