feat(sort): replace compound sort options with atomic fields and multi-sort support (#2686)
* fix(sidebar): replace routerLinkActive with getter-based route matching to prevent stale highlights * feat(sort): replace compound sort options with atomic fields and add 6 new sort criteria
This commit is contained in:
@@ -231,6 +231,13 @@ export const ALL_FILTER_OPTIONS: { label: string; value: VisibleFilterType }[] =
|
||||
{label: 'Comic Creator', value: 'comicCreator'}
|
||||
];
|
||||
|
||||
export const DEFAULT_VISIBLE_SORT_FIELDS: string[] = [
|
||||
'title', 'seriesName', 'fileName', 'filePath',
|
||||
'author', 'authorSurnameVorname', 'seriesNumber',
|
||||
'lastReadTime', 'personalRating', 'addedOn',
|
||||
'fileSizeKb', 'locked', 'publisher', 'publishedDate', 'pageCount', 'random'
|
||||
];
|
||||
|
||||
export interface UserSettings {
|
||||
perBookSetting: PerBookSetting;
|
||||
pdfReaderSetting: PdfReaderSetting;
|
||||
@@ -243,6 +250,7 @@ export interface UserSettings {
|
||||
sidebarMagicShelfSorting: SidebarMagicShelfSorting;
|
||||
filterMode: BookFilterMode;
|
||||
visibleFilters?: VisibleFilterType[];
|
||||
visibleSortFields?: string[];
|
||||
metadataCenterViewMode: 'route' | 'dialog';
|
||||
enableSeriesView: boolean;
|
||||
entityViewPreferences: EntityViewPreferences;
|
||||
|
||||
+60
-36
@@ -26,31 +26,41 @@
|
||||
|
||||
<div class="multi-sort-editor">
|
||||
<label class="multi-sort-label">{{ t('sortOrderLabel') }}</label>
|
||||
<app-multi-sort-popover
|
||||
[sortCriteria]="globalSortAsOptions"
|
||||
[availableSortOptions]="allSortAsOptions"
|
||||
(criteriaChange)="onGlobalSortCriteriaChange($event)">
|
||||
</app-multi-sort-popover>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-header-standalone">
|
||||
<label class="setting-label">{{ t('visibleSortFields') }}</label>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('visibleSortFieldsDesc') }}
|
||||
<span class="sort-field-count">({{ sortFieldSelectionCountText }})</span>
|
||||
</p>
|
||||
<div class="sort-field-order-editor">
|
||||
<div
|
||||
class="sort-criteria-list"
|
||||
#sortFieldList
|
||||
class="sort-field-order-list"
|
||||
cdkDropList
|
||||
[cdkDropListData]="sortCriteria"
|
||||
(cdkDropListDropped)="onSortCriteriaDrop($event)">
|
||||
@for (criterion of sortCriteria; track criterion.field; let i = $index) {
|
||||
<div class="sort-criterion-row" cdkDrag>
|
||||
<div class="criterion-drag-handle" cdkDragHandle>
|
||||
[cdkDropListData]="visibleSortFields"
|
||||
(cdkDropListDropped)="onSortFieldDrop($event)">
|
||||
@for (f of visibleSortFields; track f; let i = $index) {
|
||||
<div class="sort-field-order-row" cdkDrag>
|
||||
<div class="sort-field-drag-handle" cdkDragHandle>
|
||||
<i class="pi pi-bars"></i>
|
||||
</div>
|
||||
<span class="criterion-rank">{{ i + 1 }}.</span>
|
||||
<span class="criterion-label">{{ getSortLabel(criterion.field) }}</span>
|
||||
<span class="sort-field-rank">{{ i + 1 }}.</span>
|
||||
<span class="sort-field-label">{{ getSortFieldLabel(f) }}</span>
|
||||
<button
|
||||
type="button"
|
||||
class="direction-toggle-btn"
|
||||
(click)="toggleSortDirection(i)"
|
||||
[pTooltip]="criterion.direction === 'ASC' ? t('ascending') : t('descending')"
|
||||
tooltipPosition="top">
|
||||
<i [class]="criterion.direction === 'ASC' ? 'pi pi-arrow-up' : 'pi pi-arrow-down'"></i>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="remove-criterion-btn"
|
||||
(click)="removeSortCriterion(i)"
|
||||
[disabled]="sortCriteria.length === 1"
|
||||
class="remove-sort-field-btn"
|
||||
(click)="removeSortField(i)"
|
||||
[disabled]="visibleSortFields.length <= minSortFields"
|
||||
[pTooltip]="t('remove')"
|
||||
tooltipPosition="top">
|
||||
<i class="pi pi-times"></i>
|
||||
@@ -58,21 +68,29 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (availableSortFields.length > 0) {
|
||||
<div class="add-sort-row">
|
||||
<div class="sort-field-actions-row">
|
||||
@if (availableSortFieldsToAdd.length > 0 && visibleSortFields.length < maxSortFields) {
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="availableSortFields"
|
||||
[(ngModel)]="selectedAddField"
|
||||
[options]="availableSortFieldsToAdd"
|
||||
[(ngModel)]="selectedAddSortField"
|
||||
optionLabel="label"
|
||||
optionValue="field"
|
||||
optionValue="value"
|
||||
[placeholder]="t('addSortField')"
|
||||
[style]="{ width: '200px' }"
|
||||
appendTo="body"
|
||||
(onChange)="addSortCriterion()">
|
||||
(onChange)="addSortField()">
|
||||
</p-select>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
<button
|
||||
type="button"
|
||||
class="reset-sort-fields-btn"
|
||||
(click)="resetSortFieldsToDefaults()"
|
||||
[pTooltip]="t('resetToDefaults')"
|
||||
tooltipPosition="top">
|
||||
<i class="pi pi-refresh"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -101,8 +119,7 @@
|
||||
<tr>
|
||||
<th style="min-width: 150px; max-width: 220px;">{{ t('tableType') }}</th>
|
||||
<th style="min-width: 220px; max-width: 280px;">{{ t('tableName') }}</th>
|
||||
<th style="min-width: 190px; max-width: 250px;">{{ t('tableSortBy') }}</th>
|
||||
<th style="min-width: 125px;">{{ t('tableDirection') }}</th>
|
||||
<th style="min-width: 160px;">{{ t('tableSortConfig') }}</th>
|
||||
<th style="min-width: 125px;">{{ t('tableViewMode') }}</th>
|
||||
<th style="width: 75px; text-align: center;">{{ t('tableActions') }}</th>
|
||||
</tr>
|
||||
@@ -124,13 +141,20 @@
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<p-select size="small" [options]="sortOptions" optionLabel="label" optionValue="field"
|
||||
[(ngModel)]="override.sort" [style]="{'width': '100%'}" appendTo="body"></p-select>
|
||||
</td>
|
||||
<td>
|
||||
<p-select size="small" [options]="sortDirectionOptions" [(ngModel)]="override.sortDir"
|
||||
optionLabel="label" optionValue="value"
|
||||
[style]="{'width': '100%'}" appendTo="body"></p-select>
|
||||
<p-button
|
||||
[label]="t('editSort')"
|
||||
icon="pi pi-sort"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
(onClick)="overrideSortPop.toggle($event)">
|
||||
</p-button>
|
||||
<p-popover #overrideSortPop [dismissable]="true" appendTo="body">
|
||||
<app-multi-sort-popover
|
||||
[sortCriteria]="override.sortCriteriaAsOptions"
|
||||
[availableSortOptions]="allSortAsOptions"
|
||||
(criteriaChange)="onOverrideSortCriteriaChange(rowIndex, $event)">
|
||||
</app-multi-sort-popover>
|
||||
</p-popover>
|
||||
</td>
|
||||
<td>
|
||||
<p-select size="small" [options]="viewModeOptions" [(ngModel)]="override.view"
|
||||
|
||||
+49
-20
@@ -59,7 +59,6 @@
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
// Multi-sort editor styles
|
||||
.multi-sort-editor {
|
||||
margin-top: 1rem;
|
||||
padding-top: 1rem;
|
||||
@@ -74,15 +73,28 @@
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.sort-criteria-list {
|
||||
// Visible sort fields editor styles
|
||||
.sort-field-count {
|
||||
font-weight: 500;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
.sort-field-order-editor {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.sort-field-order-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
min-height: 40px;
|
||||
max-height: 320px;
|
||||
max-width: 350px;
|
||||
overflow-y: auto;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.sort-criterion-row {
|
||||
.sort-field-order-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
@@ -102,7 +114,7 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
padding: 0.35rem 0.75rem;
|
||||
background-color: var(--card-background);
|
||||
border: 1px solid var(--primary-color);
|
||||
border-radius: 6px;
|
||||
@@ -117,11 +129,11 @@
|
||||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.sort-criteria-list.cdk-drop-list-dragging .sort-criterion-row:not(.cdk-drag-placeholder) {
|
||||
.sort-field-order-list.cdk-drop-list-dragging .sort-field-order-row:not(.cdk-drag-placeholder) {
|
||||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.criterion-drag-handle {
|
||||
.sort-field-drag-handle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@@ -137,20 +149,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
.criterion-rank {
|
||||
.sort-field-rank {
|
||||
font-weight: 600;
|
||||
color: var(--primary-color);
|
||||
min-width: 1.5rem;
|
||||
min-width: 1.75rem;
|
||||
}
|
||||
|
||||
.criterion-label {
|
||||
.sort-field-label {
|
||||
flex: 1;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.direction-toggle-btn,
|
||||
.remove-criterion-btn {
|
||||
.remove-sort-field-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@@ -160,6 +171,7 @@
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background-color: transparent;
|
||||
color: var(--p-red-500);
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease;
|
||||
|
||||
@@ -177,15 +189,32 @@
|
||||
}
|
||||
}
|
||||
|
||||
.direction-toggle-btn {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.remove-criterion-btn {
|
||||
color: var(--p-red-500);
|
||||
}
|
||||
|
||||
.add-sort-row {
|
||||
.sort-field-actions-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.reset-sort-fields-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 1.75rem;
|
||||
height: 1.75rem;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background-color: transparent;
|
||||
color: var(--text-secondary-color);
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease, color 0.15s ease;
|
||||
|
||||
i {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: var(--ground-background);
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
+127
-50
@@ -1,10 +1,10 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, ElementRef, inject, OnDestroy, OnInit, viewChild} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Select} from 'primeng/select';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {SortCriterion, User, UserService} from '../../user-management/user.service';
|
||||
import {DEFAULT_VISIBLE_SORT_FIELDS, SortCriterion, User, UserService} from '../../user-management/user.service';
|
||||
import {LibraryService} from '../../../book/service/library.service';
|
||||
import {ShelfService} from '../../../book/service/shelf.service';
|
||||
import {MagicShelfService} from '../../../magic-shelf/service/magic-shelf.service';
|
||||
@@ -14,8 +14,11 @@ import {ToastModule} from 'primeng/toast';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {filter, take, takeUntil} from 'rxjs/operators';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {CdkDrag, CdkDragDrop, CdkDragHandle, CdkDropList, moveItemInArray} from '@angular/cdk/drag-drop';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {SortDirection, SortOption} from '../../../book/model/sort.model';
|
||||
import {MultiSortPopoverComponent} from '../../../book/components/book-browser/sorting/multi-sort-popover/multi-sort-popover.component';
|
||||
import {Popover} from 'primeng/popover';
|
||||
import {CdkDrag, CdkDragDrop, CdkDragHandle, CdkDropList, moveItemInArray} from '@angular/cdk/drag-drop';
|
||||
|
||||
@Component({
|
||||
selector: 'app-view-preferences',
|
||||
@@ -28,10 +31,12 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
ToastModule,
|
||||
Tooltip,
|
||||
ToggleSwitch,
|
||||
TranslocoDirective,
|
||||
MultiSortPopoverComponent,
|
||||
Popover,
|
||||
CdkDropList,
|
||||
CdkDrag,
|
||||
CdkDragHandle,
|
||||
TranslocoDirective
|
||||
CdkDragHandle
|
||||
],
|
||||
templateUrl: './view-preferences.component.html',
|
||||
styleUrl: './view-preferences.component.scss'
|
||||
@@ -41,12 +46,12 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
|
||||
sortOptions: {label: string; field: string; translationKey: string}[] = [
|
||||
{label: 'Title', field: 'title', translationKey: 'sortTitle'},
|
||||
{label: 'Title + Series', field: 'titleSeries', translationKey: 'sortTitleSeries'},
|
||||
{label: 'File Name', field: 'fileName', translationKey: 'sortFileName'},
|
||||
{label: 'File Path', field: 'filePath', translationKey: 'sortFilePath'},
|
||||
{label: 'Author', field: 'author', translationKey: 'sortAuthor'},
|
||||
{label: 'Author (Surname)', field: 'authorSurnameVorname', translationKey: 'sortAuthorSurname'},
|
||||
{label: 'Author + Series', field: 'authorSeries', translationKey: 'sortAuthorSeries'},
|
||||
{label: 'Series Name', field: 'seriesName', translationKey: 'sortSeriesName'},
|
||||
{label: 'Series Number', field: 'seriesNumber', translationKey: 'sortSeriesNumber'},
|
||||
{label: 'Last Read', field: 'lastReadTime', translationKey: 'sortLastRead'},
|
||||
{label: 'Personal Rating', field: 'personalRating', translationKey: 'sortPersonalRating'},
|
||||
{label: 'Added On', field: 'addedOn', translationKey: 'sortAddedOn'},
|
||||
@@ -54,6 +59,10 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
{label: 'Locked', field: 'locked', translationKey: 'sortLocked'},
|
||||
{label: 'Publisher', field: 'publisher', translationKey: 'sortPublisher'},
|
||||
{label: 'Published Date', field: 'publishedDate', translationKey: 'sortPublishedDate'},
|
||||
{label: 'Read Status', field: 'readStatus', translationKey: 'sortReadStatus'},
|
||||
{label: 'Date Finished', field: 'dateFinished', translationKey: 'sortDateFinished'},
|
||||
{label: 'Reading Progress', field: 'readingProgress', translationKey: 'sortReadingProgress'},
|
||||
{label: 'Book Type', field: 'bookType', translationKey: 'sortBookType'},
|
||||
{label: 'Amazon Rating', field: 'amazonRating', translationKey: 'sortAmazonRating'},
|
||||
{label: 'Amazon #', field: 'amazonReviewCount', translationKey: 'sortAmazonCount'},
|
||||
{label: 'Goodreads Rating', field: 'goodreadsRating', translationKey: 'sortGoodreadsRating'},
|
||||
@@ -71,11 +80,6 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
{label: 'Magic Shelf', value: 'MAGIC_SHELF', translationKey: 'entityMagicShelf'}
|
||||
];
|
||||
|
||||
sortDirectionOptions: {label: string; value: string; translationKey: string}[] = [
|
||||
{label: 'Ascending', value: 'ASC', translationKey: 'ascending'},
|
||||
{label: 'Descending', value: 'DESC', translationKey: 'descending'}
|
||||
];
|
||||
|
||||
viewModeOptions: {label: string; value: string; translationKey: string}[] = [
|
||||
{label: 'Grid', value: 'GRID', translationKey: 'viewGrid'},
|
||||
{label: 'Table', value: 'TABLE', translationKey: 'viewTable'}
|
||||
@@ -90,13 +94,26 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
selectedView: 'GRID' | 'TABLE' = 'GRID';
|
||||
autoSaveMetadata: boolean = false;
|
||||
sortCriteria: SortCriterion[] = [];
|
||||
selectedAddField: string | null = null;
|
||||
|
||||
// SortOption[] versions for the multi-sort-popover component
|
||||
globalSortAsOptions: SortOption[] = [];
|
||||
allSortAsOptions: SortOption[] = [];
|
||||
|
||||
// Visible sort fields configuration
|
||||
visibleSortFields: string[] = [];
|
||||
selectedAddSortField: string | null = null;
|
||||
readonly minSortFields = 3;
|
||||
readonly maxSortFields = 27;
|
||||
|
||||
private readonly sortFieldList = viewChild<ElementRef<HTMLElement>>('sortFieldList');
|
||||
|
||||
overrides: {
|
||||
entityType: 'LIBRARY' | 'SHELF' | 'MAGIC_SHELF';
|
||||
library: number;
|
||||
sort: string;
|
||||
sortDir: 'ASC' | 'DESC';
|
||||
sortCriteria: SortCriterion[];
|
||||
sortCriteriaAsOptions: SortOption[];
|
||||
view: 'GRID' | 'TABLE';
|
||||
}[] = [];
|
||||
|
||||
@@ -134,13 +151,32 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
this.sortCriteria = [{field: this.selectedSort, direction: this.selectedSortDir}];
|
||||
}
|
||||
|
||||
this.overrides = (prefs?.overrides ?? []).map(o => ({
|
||||
entityType: o.entityType,
|
||||
library: o.entityId,
|
||||
sort: o.preferences.sortKey,
|
||||
sortDir: o.preferences.sortDir ?? 'ASC',
|
||||
view: o.preferences.view ?? 'GRID'
|
||||
// Build SortOption[] versions for the popover
|
||||
this.allSortAsOptions = this.sortOptions.map(o => ({
|
||||
label: this.t.translate('settingsView.librarySort.' + o.translationKey),
|
||||
field: o.field,
|
||||
direction: SortDirection.ASCENDING
|
||||
}));
|
||||
this.globalSortAsOptions = this.toSortOptions(this.sortCriteria);
|
||||
|
||||
this.visibleSortFields = userState.user?.userSettings?.visibleSortFields
|
||||
? [...userState.user.userSettings.visibleSortFields]
|
||||
: [...DEFAULT_VISIBLE_SORT_FIELDS];
|
||||
|
||||
this.overrides = (prefs?.overrides ?? []).map(o => {
|
||||
const sc = o.preferences.sortCriteria?.length
|
||||
? [...o.preferences.sortCriteria]
|
||||
: [{field: o.preferences.sortKey, direction: o.preferences.sortDir ?? 'ASC'} as SortCriterion];
|
||||
return {
|
||||
entityType: o.entityType,
|
||||
library: o.entityId,
|
||||
sort: o.preferences.sortKey,
|
||||
sortDir: o.preferences.sortDir ?? 'ASC',
|
||||
sortCriteria: sc,
|
||||
sortCriteriaAsOptions: this.toSortOptions(sc),
|
||||
view: o.preferences.view ?? 'GRID'
|
||||
};
|
||||
});
|
||||
|
||||
this.libraryOptions = (librariesState.libraries ?? []).filter(lib => lib.id !== undefined).map(lib => ({
|
||||
label: lib.name,
|
||||
@@ -198,11 +234,14 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
addOverride(): void {
|
||||
const next = this.availableLibraries[0];
|
||||
if (next) {
|
||||
const defaultCriteria: SortCriterion[] = [{field: 'title', direction: 'ASC'}];
|
||||
this.overrides.push({
|
||||
entityType: next.entityType,
|
||||
library: next.value,
|
||||
sort: 'title',
|
||||
sortDir: 'ASC',
|
||||
sortCriteria: defaultCriteria,
|
||||
sortCriteriaAsOptions: this.toSortOptions(defaultCriteria),
|
||||
view: 'GRID'
|
||||
});
|
||||
}
|
||||
@@ -212,51 +251,87 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
this.overrides.splice(index, 1);
|
||||
}
|
||||
|
||||
// Multi-sort criteria methods
|
||||
get availableSortFields(): {label: string; field: string; translationKey: string}[] {
|
||||
const usedFields = new Set(this.sortCriteria.map(c => c.field));
|
||||
return this.sortOptions.filter(opt => !usedFields.has(opt.field));
|
||||
// Conversion helpers
|
||||
private toSortOptions(criteria: SortCriterion[]): SortOption[] {
|
||||
return criteria.map(c => ({
|
||||
label: this.t.translate('settingsView.librarySort.' + (this.sortOptions.find(o => o.field === c.field)?.translationKey ?? c.field)),
|
||||
field: c.field,
|
||||
direction: c.direction === 'ASC' ? SortDirection.ASCENDING : SortDirection.DESCENDING
|
||||
}));
|
||||
}
|
||||
|
||||
getSortLabel(field: string): string {
|
||||
const key = this.sortOptions.find(opt => opt.field === field)?.translationKey;
|
||||
return key ? this.t.translate('settingsView.librarySort.' + key) : field;
|
||||
private toSortCriteria(options: SortOption[]): SortCriterion[] {
|
||||
return options.map(o => ({
|
||||
field: o.field,
|
||||
direction: o.direction === SortDirection.ASCENDING ? 'ASC' as const : 'DESC' as const
|
||||
}));
|
||||
}
|
||||
|
||||
addSortCriterion(): void {
|
||||
if (this.selectedAddField) {
|
||||
this.sortCriteria.push({field: this.selectedAddField, direction: 'ASC'});
|
||||
this.selectedAddField = null;
|
||||
this.syncLegacySort();
|
||||
}
|
||||
}
|
||||
|
||||
removeSortCriterion(index: number): void {
|
||||
if (this.sortCriteria.length > 1) {
|
||||
this.sortCriteria.splice(index, 1);
|
||||
this.syncLegacySort();
|
||||
}
|
||||
}
|
||||
|
||||
toggleSortDirection(index: number): void {
|
||||
const criterion = this.sortCriteria[index];
|
||||
criterion.direction = criterion.direction === 'ASC' ? 'DESC' : 'ASC';
|
||||
onGlobalSortCriteriaChange(criteria: SortOption[]): void {
|
||||
this.globalSortAsOptions = criteria;
|
||||
this.sortCriteria = this.toSortCriteria(criteria);
|
||||
this.syncLegacySort();
|
||||
}
|
||||
|
||||
onSortCriteriaDrop(event: CdkDragDrop<SortCriterion[]>): void {
|
||||
moveItemInArray(this.sortCriteria, event.previousIndex, event.currentIndex);
|
||||
this.syncLegacySort();
|
||||
onOverrideSortCriteriaChange(index: number, criteria: SortOption[]): void {
|
||||
this.overrides[index].sortCriteriaAsOptions = criteria;
|
||||
this.overrides[index].sortCriteria = this.toSortCriteria(criteria);
|
||||
this.overrides[index].sort = criteria[0]?.field ?? 'title';
|
||||
this.overrides[index].sortDir = criteria[0]?.direction === SortDirection.ASCENDING ? 'ASC' : 'DESC';
|
||||
}
|
||||
|
||||
private syncLegacySort(): void {
|
||||
// Keep legacy fields in sync with first criterion
|
||||
if (this.sortCriteria.length > 0) {
|
||||
this.selectedSort = this.sortCriteria[0].field;
|
||||
this.selectedSortDir = this.sortCriteria[0].direction;
|
||||
}
|
||||
}
|
||||
|
||||
// Visible sort fields management
|
||||
getSortFieldLabel(field: string): string {
|
||||
const key = this.sortOptions.find(opt => opt.field === field)?.translationKey;
|
||||
return key ? this.t.translate('settingsView.librarySort.' + key) : field;
|
||||
}
|
||||
|
||||
get availableSortFieldsToAdd(): {label: string; value: string}[] {
|
||||
const used = new Set(this.visibleSortFields);
|
||||
return this.sortOptions
|
||||
.filter(opt => !used.has(opt.field))
|
||||
.map(opt => ({label: this.t.translate('settingsView.librarySort.' + opt.translationKey), value: opt.field}));
|
||||
}
|
||||
|
||||
get sortFieldSelectionCountText(): string {
|
||||
return this.t.translate('settingsView.librarySort.sortFieldCount', {
|
||||
count: this.visibleSortFields.length,
|
||||
total: this.sortOptions.length
|
||||
});
|
||||
}
|
||||
|
||||
onSortFieldDrop(event: CdkDragDrop<string[]>): void {
|
||||
moveItemInArray(this.visibleSortFields, event.previousIndex, event.currentIndex);
|
||||
}
|
||||
|
||||
addSortField(): void {
|
||||
if (this.selectedAddSortField) {
|
||||
this.visibleSortFields.push(this.selectedAddSortField);
|
||||
this.selectedAddSortField = null;
|
||||
requestAnimationFrame(() => {
|
||||
const el = this.sortFieldList()?.nativeElement;
|
||||
if (el) el.scrollTop = el.scrollHeight;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
removeSortField(index: number): void {
|
||||
if (this.visibleSortFields.length > this.minSortFields) {
|
||||
this.visibleSortFields.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
resetSortFieldsToDefaults(): void {
|
||||
this.visibleSortFields = [...DEFAULT_VISIBLE_SORT_FIELDS];
|
||||
}
|
||||
|
||||
saveSettings(): void {
|
||||
if (!this.user) return;
|
||||
|
||||
@@ -279,8 +354,9 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
entityType: o.entityType,
|
||||
entityId: o.library,
|
||||
preferences: {
|
||||
sortKey: o.sort,
|
||||
sortDir: o.sortDir,
|
||||
sortKey: o.sortCriteria[0]?.field ?? o.sort,
|
||||
sortDir: o.sortCriteria[0]?.direction ?? o.sortDir,
|
||||
sortCriteria: [...o.sortCriteria],
|
||||
view: o.view,
|
||||
coverSize: existing?.coverSize ?? 1.0,
|
||||
seriesCollapsed: existing?.seriesCollapsed ?? false,
|
||||
@@ -291,6 +367,7 @@ export class ViewPreferencesComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.userService.updateUserSetting(this.user.id, 'entityViewPreferences', prefs);
|
||||
this.userService.updateUserSetting(this.user.id, 'autoSaveMetadata', this.autoSaveMetadata);
|
||||
this.userService.updateUserSetting(this.user.id, 'visibleSortFields', this.visibleSortFields);
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
|
||||
Reference in New Issue
Block a user