Replace arrow-based author reordering with CDK drag chips and persist author sort order (#3167) (#3175)

This commit is contained in:
ACX
2026-03-04 18:29:53 -07:00
committed by GitHub
parent 3bef84d102
commit 9c249fff1d
73 changed files with 901 additions and 304 deletions
@@ -182,19 +182,45 @@
<div class="meta-row field-{{field.controlName}}">
<label for="{{field.controlName}}" class="field-label">{{ field.label }}</label>
<div class="meta-fields">
<p-autoComplete
size="small"
formControlName="{{field.controlName}}"
[multiple]="true"
[typeahead]="false"
[dropdown]="false"
[forceSelection]="false"
class="dest full-width"
[ngClass]="{
'changed': isValueChanged(field.controlName),
}"
(onBlur)="onAutoCompleteBlur(field.controlName, $event)"
/>
@if (field.controlName === 'authors') {
<div class="author-chips-container dest full-width"
cdkDropList cdkDropListOrientation="mixed"
(cdkDropListDropped)="dropAuthor($event)"
[ngClass]="{ 'changed': isValueChanged('authors') }">
@for (author of metadataForm.get('authors')!.value; track $index) {
<span class="author-chip" [class.main-author]="$index === 0" cdkDrag>
@if ($index === 0) { <span class="main-author-badge">m</span> }
{{ author }}
<i class="pi pi-times author-chip-remove" (click)="removeAuthor($index)"></i>
</span>
}
<p-autoComplete
class="author-add-input"
[(ngModel)]="authorInputValue"
[ngModelOptions]="{ standalone: true }"
size="small"
[forceSelection]="false"
[dropdown]="false"
(onKeyUp)="onAuthorInputKeyUp($event)"
(onSelect)="onAuthorInputSelect($event)"
placeholder="Add author..."
/>
</div>
} @else {
<p-autoComplete
size="small"
formControlName="{{field.controlName}}"
[multiple]="true"
[typeahead]="false"
[dropdown]="false"
[forceSelection]="false"
class="dest full-width"
[ngClass]="{
'changed': isValueChanged(field.controlName),
}"
(onBlur)="onAutoCompleteBlur(field.controlName, $event)"
/>
}
<p-button
size="small"
[icon]="isValueSaved(field.controlName) ? 'pi pi-check' : (isValueChanged(field.controlName) || !fetchedMetadata[field.fetchedKey] ? 'pi pi-refresh' : 'pi pi-angle-left')"
@@ -406,19 +432,45 @@
<div class="meta-row field-{{field.controlName}}">
<label for="{{field.controlName}}" class="field-label field-label--fixed">{{ field.label }}</label>
<div class="field-input-row">
<p-autoComplete
size="small"
formControlName="{{field.controlName}}"
[multiple]="true"
[typeahead]="false"
[dropdown]="false"
[forceSelection]="false"
class="full-width"
[ngClass]="{
'changed': isValueChanged(field.controlName),
}"
(onBlur)="onAutoCompleteBlur(field.controlName, $event)"
/>
@if (field.controlName === 'authors') {
<div class="author-chips-container full-width"
cdkDropList cdkDropListOrientation="mixed"
(cdkDropListDropped)="dropAuthor($event)"
[ngClass]="{ 'changed': isValueChanged('authors') }">
@for (author of metadataForm.get('authors')!.value; track $index) {
<span class="author-chip" [class.main-author]="$index === 0" cdkDrag>
@if ($index === 0) { <span class="main-author-badge">m</span> }
{{ author }}
<i class="pi pi-times author-chip-remove" (click)="removeAuthor($index)"></i>
</span>
}
<p-autoComplete
class="author-add-input"
[(ngModel)]="authorInputValue"
[ngModelOptions]="{ standalone: true }"
size="small"
[forceSelection]="false"
[dropdown]="false"
(onKeyUp)="onAuthorInputKeyUp($event)"
(onSelect)="onAuthorInputSelect($event)"
placeholder="Add author..."
/>
</div>
} @else {
<p-autoComplete
size="small"
formControlName="{{field.controlName}}"
[multiple]="true"
[typeahead]="false"
[dropdown]="false"
[forceSelection]="false"
class="full-width"
[ngClass]="{
'changed': isValueChanged(field.controlName),
}"
(onBlur)="onAutoCompleteBlur(field.controlName, $event)"
/>
}
<p-button
size="small"
icon="pi pi-refresh"
@@ -410,3 +410,77 @@ textarea.changed,
}
}
}
.author-chips-container {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.375rem;
padding: 0.375rem;
min-height: 2.25rem;
border: 1px solid var(--p-inputtext-border-color);
border-radius: 6px;
background: var(--p-inputtext-background);
}
.author-add-input {
flex: 1 1 6rem;
min-width: 6rem;
::ng-deep input {
border: none !important;
background: transparent !important;
padding: 0.25rem;
box-shadow: none !important;
outline: none !important;
}
}
.author-chip {
display: inline-flex;
align-items: center;
gap: 0.25rem;
padding: 0.25rem 0.5rem;
border-radius: 1rem;
background: var(--p-chip-background);
color: var(--p-chip-color);
font-size: 0.875rem;
cursor: grab;
user-select: none;
}
.main-author-badge {
display: inline-flex;
align-items: center;
justify-content: center;
width: 1rem;
height: 1rem;
border-radius: 50%;
background: var(--p-primary-color);
color: var(--p-primary-contrast-color);
font-size: 0.6rem;
font-weight: 700;
flex-shrink: 0;
}
.author-chip-remove {
font-size: 0.65rem;
cursor: pointer;
opacity: 0.6;
padding: 0.15rem;
&:hover { opacity: 1; }
}
.cdk-drag-preview {
box-sizing: border-box;
border-radius: 1rem;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.cdk-drag-placeholder {
opacity: 0.4;
}
.cdk-drag-animating {
transition: transform 200ms ease;
}
@@ -13,6 +13,8 @@ import {AutoComplete} from 'primeng/autocomplete';
import {Image} from 'primeng/image';
import {LazyLoadImageModule} from 'ng-lazyload-image';
import {ConfirmationService} from 'primeng/api';
import {CdkDragDrop, CdkDropList, CdkDrag, moveItemInArray} from '@angular/cdk/drag-drop';
import {AutoCompleteSelectEvent} from 'primeng/autocomplete';
import {DatePicker} from 'primeng/datepicker';
import {ALL_METADATA_FIELDS, getArrayFields, getBottomFields, getTextareaFields, MetadataFieldConfig} from '../../../../shared/metadata';
import {MetadataUtilsService} from '../../../../shared/metadata';
@@ -35,6 +37,8 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
LazyLoadImageModule,
DatePicker,
TranslocoDirective,
CdkDropList,
CdkDrag,
],
templateUrl: './bookdrop-file-metadata-picker.component.html',
styleUrl: './bookdrop-file-metadata-picker.component.scss'
@@ -57,6 +61,8 @@ export class BookdropFileMetadataPickerComponent implements OnInit {
@Output() metadataCopied = new EventEmitter<boolean>();
authorInputValue = '';
private enabledProviderFields: MetadataProviderSpecificFields | null = null;
metadataFieldsTop: MetadataFieldConfig[] = ALL_METADATA_FIELDS.filter(f =>
@@ -135,6 +141,44 @@ export class BookdropFileMetadataPickerComponent implements OnInit {
}
}
dropAuthor(event: CdkDragDrop<string[]>) {
const authors = [...(this.metadataForm.get('authors')?.value ?? [])];
moveItemInArray(authors, event.previousIndex, event.currentIndex);
this.metadataForm.get('authors')?.setValue(authors);
this.metadataForm.get('authors')?.markAsDirty();
}
removeAuthor(index: number) {
const authors = [...(this.metadataForm.get('authors')?.value ?? [])];
authors.splice(index, 1);
this.metadataForm.get('authors')?.setValue(authors);
this.metadataForm.get('authors')?.markAsDirty();
}
onAuthorInputKeyUp(event: KeyboardEvent) {
if (event.key === 'Enter') {
const value = this.authorInputValue?.trim();
if (value) {
const authors = this.metadataForm.get('authors')?.value || [];
if (!authors.includes(value)) {
this.metadataForm.get('authors')?.setValue([...authors, value]);
this.metadataForm.get('authors')?.markAsDirty();
}
this.authorInputValue = '';
}
}
}
onAuthorInputSelect(event: AutoCompleteSelectEvent) {
const authors = (this.metadataForm.get('authors')?.value as string[]) || [];
const value = event.value as string;
if (!authors.includes(value)) {
this.metadataForm.get('authors')?.setValue([...authors, value]);
this.metadataForm.get('authors')?.markAsDirty();
}
setTimeout(() => this.authorInputValue = '');
}
onAutoCompleteBlur(fieldName: string, event: Event): void {
const target = event.target as HTMLInputElement;
const inputValue = target?.value?.trim();
@@ -210,19 +210,35 @@
<div class="field-row">
<div class="field-group authors-field">
<label for="authors">{{ t('authors') }} @if (isEmbeddable('authors', book)) { <i class="pi pi-file-export embeddable-indicator" [pTooltip]="t('writtenToFileTooltip')" tooltipPosition="top"></i> }</label>
<div class="field-with-lock">
<p-autoComplete
formControlName="authors"
[multiple]="true"
[fluid]="true"
[dropdown]="false"
[suggestions]="filteredAuthors"
[forceSelection]="false"
[showClear]="false"
(completeMethod)="filterAuthors($event)"
(onKeyUp)="onAutoCompleteKeyUp('authors', $event)"
(onSelect)="onAutoCompleteSelect('authors', $event)">
</p-autoComplete>
<div class="field-with-lock authors-lock-wrapper">
<div class="author-chips-container" [class.disabled]="metadataForm.get('authors')?.disabled"
cdkDropList cdkDropListOrientation="mixed"
[cdkDropListDisabled]="metadataForm.get('authors')?.disabled"
(cdkDropListDropped)="dropAuthor($event)">
@for (author of metadataForm.get('authors')!.value; track $index) {
<span class="author-chip" [class.main-author]="$first" cdkDrag>
@if ($first) { <span class="main-author-badge">m</span> }
{{ author }}
@if (!metadataForm.get('authors')?.disabled) {
<i class="pi pi-times author-chip-remove" (click)="removeAuthor($index)"></i>
}
</span>
}
@if (!metadataForm.get('authors')?.disabled) {
<p-autoComplete
class="author-add-input"
[(ngModel)]="authorInputValue"
[ngModelOptions]="{ standalone: true }"
[suggestions]="filteredAuthors"
[forceSelection]="false"
[dropdown]="false"
(completeMethod)="filterAuthors($event)"
(onKeyUp)="onAuthorInputKeyUp($event)"
(onSelect)="onAuthorInputSelect($event)"
placeholder="Add author..."
/>
}
</div>
@if (!book.metadata!['authorsLocked']) {
<p-button icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('authors')" severity="success"></p-button>
}
@@ -250,6 +250,92 @@ label {
}
}
.author-chips-container {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.375rem;
padding: 0.375rem;
min-height: 2.25rem;
border: 1px solid var(--p-inputtext-border-color);
border-radius: 6px;
background: var(--p-inputtext-background);
flex: 1;
min-width: 0;
&.disabled {
opacity: 0.6;
background: var(--p-inputtext-disabled-background);
cursor: default;
.author-chip {
cursor: default;
}
}
}
.author-add-input {
flex: 1 1 6rem;
min-width: 6rem;
::ng-deep input {
border: none !important;
background: transparent !important;
padding: 0.25rem;
box-shadow: none !important;
outline: none !important;
}
}
.author-chip {
display: inline-flex;
align-items: center;
gap: 0.25rem;
padding: 0.25rem 0.5rem;
border-radius: 1rem;
background: var(--p-chip-background);
color: var(--p-chip-color);
font-size: 0.875rem;
cursor: grab;
user-select: none;
}
.main-author-badge {
display: inline-flex;
align-items: center;
justify-content: center;
width: 1rem;
height: 1rem;
border-radius: 50%;
background: var(--p-primary-color);
color: var(--p-primary-contrast-color);
font-size: 0.6rem;
font-weight: 700;
flex-shrink: 0;
}
.author-chip-remove {
font-size: 0.65rem;
cursor: pointer;
opacity: 0.6;
padding: 0.15rem;
&:hover { opacity: 1; }
}
.cdk-drag-preview {
box-sizing: border-box;
border-radius: 1rem;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.cdk-drag-placeholder {
opacity: 0.4;
}
.cdk-drag-animating {
transition: transform 200ms ease;
}
.publisher-field {
@media (min-width: 768px) {
flex-basis: 35%;
@@ -33,6 +33,7 @@ import {UserService} from '../../../../settings/user-management/user.service';
import {AppSettingsService} from '../../../../../shared/service/app-settings.service';
import {MetadataProviderSpecificFields} from '../../../../../shared/model/app-settings.model';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
import {CdkDragDrop, CdkDropList, CdkDrag, moveItemInArray} from '@angular/cdk/drag-drop';
@Component({
selector: "app-metadata-editor",
@@ -56,6 +57,8 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
LazyLoadImageModule,
Select,
TranslocoDirective,
CdkDropList,
CdkDrag,
],
})
export class MetadataEditorComponent implements OnInit {
@@ -105,6 +108,7 @@ export class MetadataEditorComponent implements OnInit {
allSeries!: string[];
filteredCategories: string[] = [];
filteredAuthors: string[] = [];
authorInputValue = '';
filteredMoods: string[] = [];
filteredTags: string[] = [];
filteredPublishers: string[] = [];
@@ -162,6 +166,44 @@ export class MetadataEditorComponent implements OnInit {
);
}
dropAuthor(event: CdkDragDrop<string[]>) {
const authors = [...(this.metadataForm.get('authors')?.value ?? [])];
moveItemInArray(authors, event.previousIndex, event.currentIndex);
this.metadataForm.get('authors')?.setValue(authors);
this.metadataForm.get('authors')?.markAsDirty();
}
removeAuthor(index: number) {
const authors = [...(this.metadataForm.get('authors')?.value ?? [])];
authors.splice(index, 1);
this.metadataForm.get('authors')?.setValue(authors);
this.metadataForm.get('authors')?.markAsDirty();
}
onAuthorInputKeyUp(event: KeyboardEvent) {
if (event.key === 'Enter') {
const value = this.authorInputValue?.trim();
if (value) {
const authors = this.metadataForm.get('authors')?.value || [];
if (!authors.includes(value)) {
this.metadataForm.get('authors')?.setValue([...authors, value]);
this.metadataForm.get('authors')?.markAsDirty();
}
this.authorInputValue = '';
}
}
}
onAuthorInputSelect(event: AutoCompleteSelectEvent) {
const authors = (this.metadataForm.get('authors')?.value as string[]) || [];
const value = event.value as string;
if (!authors.includes(value)) {
this.metadataForm.get('authors')?.setValue([...authors, value]);
this.metadataForm.get('authors')?.markAsDirty();
}
setTimeout(() => this.authorInputValue = '');
}
filterMoods(event: { query: string }) {
const query = event.query.toLowerCase();
this.filteredMoods = this.allMoods.filter((mood) =>
@@ -392,7 +434,7 @@ export class MetadataEditorComponent implements OnInit {
this.metadataForm.patchValue({
title: metadata.title ?? null,
subtitle: metadata.subtitle ?? null,
authors: [...(metadata.authors ?? [])].sort(),
authors: [...(metadata.authors ?? [])],
categories: [...(metadata.categories ?? [])].sort(),
moods: [...(metadata.moods ?? [])].sort(),
tags: [...(metadata.tags ?? [])].sort(),
@@ -258,18 +258,49 @@
>
<i [class]="metadataForm.get(field.lockedKey)?.value ? 'pi pi-lock' : 'pi pi-lock-open'"></i>
</button>
<p-autoComplete
class="chips-input"
formControlName="{{field.controlName}}"
[multiple]="true"
[dropdown]="false"
[forceSelection]="false"
[showClear]="true"
[suggestions]="getFiltered(field.controlName)"
(completeMethod)="filterItems($event, field.controlName)"
(onKeyUp)="onAutoCompleteKeyUp(field.controlName, $event)"
(onSelect)="onAutoCompleteSelect(field.controlName, $event)"
/>
@if (field.controlName === 'authors') {
<div class="author-chips-container" [class.disabled]="metadataForm.get('authors')?.disabled"
cdkDropList cdkDropListOrientation="mixed"
[cdkDropListDisabled]="metadataForm.get('authors')?.disabled"
(cdkDropListDropped)="dropAuthor($event)">
@for (author of metadataForm.get('authors')!.value; track $index) {
<span class="author-chip" [class.main-author]="$index === 0" cdkDrag>
@if ($index === 0) { <span class="main-author-badge">m</span> }
{{ author }}
@if (!metadataForm.get('authors')?.disabled) {
<i class="pi pi-times author-chip-remove" (click)="removeAuthor($index)"></i>
}
</span>
}
@if (!metadataForm.get('authors')?.disabled) {
<p-autoComplete
class="author-add-input"
[(ngModel)]="authorInputValue"
[ngModelOptions]="{ standalone: true }"
[suggestions]="getFiltered('authors')"
[forceSelection]="false"
[dropdown]="false"
(completeMethod)="filterItems($event, 'authors')"
(onKeyUp)="onAuthorInputKeyUp($event)"
(onSelect)="onAuthorInputSelect($event)"
placeholder="Add author..."
/>
}
</div>
} @else {
<p-autoComplete
class="chips-input"
formControlName="{{field.controlName}}"
[multiple]="true"
[dropdown]="false"
[forceSelection]="false"
[showClear]="true"
[suggestions]="getFiltered(field.controlName)"
(completeMethod)="filterItems($event, field.controlName)"
(onKeyUp)="onAutoCompleteKeyUp(field.controlName, $event)"
(onSelect)="onAutoCompleteSelect(field.controlName, $event)"
/>
}
</div>
<button
@@ -630,3 +630,89 @@
font-weight: 600;
}
}
.author-chips-container {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.375rem;
padding: 0.375rem;
min-height: 2.25rem;
border: 1px solid var(--p-inputtext-border-color);
border-radius: 6px;
background: var(--p-inputtext-background);
flex: 1;
min-width: 0;
&.disabled {
opacity: 0.6;
background: var(--p-inputtext-disabled-background);
cursor: default;
.author-chip {
cursor: default;
}
}
}
.author-add-input {
flex: 1 1 6rem;
min-width: 6rem;
::ng-deep input {
border: none !important;
background: transparent !important;
padding: 0.25rem;
box-shadow: none !important;
outline: none !important;
}
}
.author-chip {
display: inline-flex;
align-items: center;
gap: 0.25rem;
padding: 0.25rem 0.5rem;
border-radius: 1rem;
background: var(--p-chip-background);
color: var(--p-chip-color);
font-size: 0.875rem;
cursor: grab;
user-select: none;
}
.main-author-badge {
display: inline-flex;
align-items: center;
justify-content: center;
width: 1rem;
height: 1rem;
border-radius: 50%;
background: var(--p-primary-color);
color: var(--p-primary-contrast-color);
font-size: 0.6rem;
font-weight: 700;
flex-shrink: 0;
}
.author-chip-remove {
font-size: 0.65rem;
cursor: pointer;
opacity: 0.6;
padding: 0.15rem;
&:hover { opacity: 1; }
}
.cdk-drag-preview {
box-sizing: border-box;
border-radius: 1rem;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.cdk-drag-placeholder {
opacity: 0.4;
}
.cdk-drag-animating {
transition: transform 200ms ease;
}
@@ -1,6 +1,7 @@
import {Component, DestroyRef, EventEmitter, inject, Input, OnInit, Output} from '@angular/core';
import {Book, BookMetadata, ComicMetadata, MetadataClearFlags, MetadataUpdateWrapper} from '../../../../book/model/book.model';
import {MessageService} from 'primeng/api';
import {CdkDragDrop, CdkDropList, CdkDrag, moveItemInArray} from '@angular/cdk/drag-drop';
import {Button} from 'primeng/button';
import {FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms';
import {InputText} from 'primeng/inputtext';
@@ -39,7 +40,9 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
Image,
LazyLoadImageModule,
Checkbox,
TranslocoDirective
TranslocoDirective,
CdkDropList,
CdkDrag,
]
})
export class MetadataPickerComponent implements OnInit {
@@ -68,6 +71,7 @@ export class MetadataPickerComponent implements OnInit {
private allItems: Record<string, string[]> = {};
filteredItems: Record<string, string[]> = {};
authorInputValue = '';
metadataForm!: FormGroup;
currentBookId!: number;
@@ -284,6 +288,44 @@ export class MetadataPickerComponent implements OnInit {
}
}
dropAuthor(event: CdkDragDrop<string[]>) {
const authors = [...(this.metadataForm.get('authors')?.value ?? [])];
moveItemInArray(authors, event.previousIndex, event.currentIndex);
this.metadataForm.get('authors')?.setValue(authors);
this.metadataForm.get('authors')?.markAsDirty();
}
removeAuthor(index: number) {
const authors = [...(this.metadataForm.get('authors')?.value ?? [])];
authors.splice(index, 1);
this.metadataForm.get('authors')?.setValue(authors);
this.metadataForm.get('authors')?.markAsDirty();
}
onAuthorInputKeyUp(event: KeyboardEvent) {
if (event.key === 'Enter') {
const value = this.authorInputValue?.trim();
if (value) {
const authors = this.metadataForm.get('authors')?.value || [];
if (!authors.includes(value)) {
this.metadataForm.get('authors')?.setValue([...authors, value]);
this.metadataForm.get('authors')?.markAsDirty();
}
this.authorInputValue = '';
}
}
}
onAuthorInputSelect(event: AutoCompleteSelectEvent) {
const authors = (this.metadataForm.get('authors')?.value as string[]) || [];
const value = event.value as string;
if (!authors.includes(value)) {
this.metadataForm.get('authors')?.setValue([...authors, value]);
this.metadataForm.get('authors')?.markAsDirty();
}
setTimeout(() => this.authorInputValue = '');
}
onSave(): void {
this.isSaving = true;
const updatedBookMetadata = this.buildMetadataWrapper(undefined);
@@ -120,8 +120,13 @@
</div>
<p class="authors">
@for (author of book?.metadata!.authors; track $index; let isLast = $last) {
<a class="author-link" (click)="goToAuthorBooks(author)">{{ author }}</a>
@for (author of book?.metadata!.authors; track $index; let isLast = $last; let isFirst = $first) {
@if (isFirst && book!.metadata!.authors!.length > 1) {
<a class="author-link" (click)="goToAuthorBooks(author)">{{ author }}</a>
<span class="first-author-badge">{{ t('firstAuthorBadge') }}</span>
} @else {
<a class="author-link" (click)="goToAuthorBooks(author)">{{ author }}</a>
}
@if (!isLast) {
<span class="author-separator">, </span>
}
@@ -222,6 +222,22 @@
text-decoration: underline;
}
.first-author-badge {
display: inline-flex;
align-items: center;
font-size: 0.55rem;
font-weight: 700;
color: #DAA520;
text-transform: uppercase;
letter-spacing: 0.3px;
margin-left: 0.25rem;
padding: 0.1rem 0.3rem;
border: 1px solid #DAA520;
border-radius: 3px;
line-height: 1;
vertical-align: middle;
}
.formats-inline {
display: flex;
align-items: center;