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:
@@ -0,0 +1,60 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
|
||||
export interface AuditLog {
|
||||
id: number;
|
||||
userId: number | null;
|
||||
username: string;
|
||||
action: string;
|
||||
entityType: string | null;
|
||||
entityId: number | null;
|
||||
description: string;
|
||||
ipAddress: string | null;
|
||||
countryCode: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface PageableResponse<T> {
|
||||
content: T[];
|
||||
page: {
|
||||
totalElements: number;
|
||||
totalPages: number;
|
||||
number: number;
|
||||
size: number;
|
||||
};
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuditLogService {
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/audit-logs`;
|
||||
|
||||
getAuditLogs(page: number = 0, size: number = 25, action?: string, username?: string, from?: string, to?: string): Observable<PageableResponse<AuditLog>> {
|
||||
let params = new HttpParams()
|
||||
.set('page', page.toString())
|
||||
.set('size', size.toString());
|
||||
|
||||
if (action) {
|
||||
params = params.set('action', action);
|
||||
}
|
||||
if (username) {
|
||||
params = params.set('username', username);
|
||||
}
|
||||
if (from) {
|
||||
params = params.set('from', from);
|
||||
}
|
||||
if (to) {
|
||||
params = params.set('to', to);
|
||||
}
|
||||
|
||||
return this.http.get<PageableResponse<AuditLog>>(this.url, {params});
|
||||
}
|
||||
|
||||
getDistinctUsernames(): Observable<string[]> {
|
||||
return this.http.get<string[]>(`${this.url}/usernames`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsAuditLogs'">
|
||||
<div class="main-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-history"></i>
|
||||
{{ t('title') }}
|
||||
</h2>
|
||||
<p class="settings-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-list"></i>
|
||||
{{ t('sectionTitle') }}
|
||||
</h3>
|
||||
<div class="filter-controls">
|
||||
<p-select
|
||||
[options]="actionOptions"
|
||||
[(ngModel)]="selectedAction"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[placeholder]="t('filterPlaceholder')"
|
||||
(onChange)="onFilterChange()"
|
||||
class="action-filter">
|
||||
</p-select>
|
||||
<p-select
|
||||
[options]="usernameOptions"
|
||||
[(ngModel)]="selectedUsername"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[placeholder]="t('userFilterPlaceholder')"
|
||||
(onChange)="onFilterChange()"
|
||||
class="user-filter">
|
||||
</p-select>
|
||||
<p-datepicker
|
||||
[(ngModel)]="dateRange"
|
||||
(ngModelChange)="onDateRangeChange()"
|
||||
selectionMode="range"
|
||||
[placeholder]="t('dateRangePlaceholder')"
|
||||
dateFormat="yy-mm-dd"
|
||||
[showIcon]="true"
|
||||
[showButtonBar]="true"
|
||||
class="date-range-filter">
|
||||
</p-datepicker>
|
||||
<button
|
||||
*ngIf="hasActiveFilters"
|
||||
(click)="clearAllFilters()"
|
||||
class="icon-btn clear-btn"
|
||||
[title]="t('clearFilters')">
|
||||
<i class="pi pi-filter-slash"></i>
|
||||
</button>
|
||||
<button
|
||||
(click)="toggleAutoRefresh()"
|
||||
class="icon-btn refresh-btn"
|
||||
[class.active]="autoRefresh"
|
||||
[title]="t('autoRefresh')">
|
||||
<i class="pi pi-sync" [class.pi-spin]="autoRefresh"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-body">
|
||||
<p-table
|
||||
[value]="logs"
|
||||
[lazy]="true"
|
||||
[paginator]="true"
|
||||
[rows]="rows"
|
||||
[first]="currentPage * rows"
|
||||
[totalRecords]="totalRecords"
|
||||
[loading]="loading"
|
||||
[showCurrentPageReport]="true"
|
||||
[currentPageReportTemplate]="t('pageReport')"
|
||||
(onLazyLoad)="onLazyLoad($event)"
|
||||
[rowsPerPageOptions]="[10, 25, 50]"
|
||||
styleClass="p-datatable-sm p-datatable-striped">
|
||||
|
||||
<ng-template pTemplate="header">
|
||||
<tr>
|
||||
<th style="width: 120px">{{ t('columns.timestamp') }}</th>
|
||||
<th style="width: 100px">{{ t('columns.user') }}</th>
|
||||
<th style="width: 200px">{{ t('columns.action') }}</th>
|
||||
<th>{{ t('columns.description') }}</th>
|
||||
<th style="width: 160px">{{ t('columns.ip') }}</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
|
||||
<ng-template pTemplate="body" let-log>
|
||||
<tr>
|
||||
<td class="timestamp-cell" [title]="log.createdAt | date:'medium'">
|
||||
{{ getRelativeTime(log.createdAt) }}
|
||||
</td>
|
||||
<td>{{ log.username }}</td>
|
||||
<td>
|
||||
<app-tag [color]="getActionColor(log.action)" size="2xs" [rounded]="true">
|
||||
{{ formatAction(log.action) }}
|
||||
</app-tag>
|
||||
</td>
|
||||
<td class="description-cell"
|
||||
[class.expanded]="expandedRows.has(log.id)"
|
||||
(click)="toggleDescription(log.id)">
|
||||
{{ log.description }}
|
||||
</td>
|
||||
<td class="ip-cell">
|
||||
<span *ngIf="log.countryCode" class="flag-emoji">{{ countryCodeToFlag(log.countryCode) }}</span>
|
||||
{{ log.ipAddress || '—' }}
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
|
||||
<ng-template pTemplate="emptymessage">
|
||||
<tr>
|
||||
<td colspan="5" class="empty-message">
|
||||
<i class="pi pi-inbox"></i>
|
||||
<span>{{ t('empty') }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,131 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.main-container {
|
||||
@include settings.settings-page-container;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
@include settings.settings-section-body;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.filter-controls {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
::ng-deep .action-filter {
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
::ng-deep .user-filter {
|
||||
min-width: 140px;
|
||||
}
|
||||
|
||||
::ng-deep .date-range-filter {
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
.icon-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: var(--p-text-muted-color);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: var(--p-content-hover-background);
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
border-color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .p-datatable-table {
|
||||
table-layout: fixed;
|
||||
}
|
||||
|
||||
|
||||
.timestamp-cell {
|
||||
white-space: nowrap;
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.description-cell {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
|
||||
&.expanded {
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
}
|
||||
}
|
||||
|
||||
.ip-cell {
|
||||
font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
|
||||
font-size: 0.8rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.flag-emoji {
|
||||
font-size: 1.15rem;
|
||||
margin-right: 0.25rem;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
::ng-deep .p-datatable.p-datatable-sm .p-datatable-tbody > tr > td.empty-message {
|
||||
text-align: center;
|
||||
padding: 3rem 2rem;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
.pi {
|
||||
display: block;
|
||||
font-size: 2rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
import {Component, inject, OnInit, OnDestroy} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {TableLazyLoadEvent, TableModule} from 'primeng/table';
|
||||
import {Select} from 'primeng/select';
|
||||
import {DatePicker} from 'primeng/datepicker';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {Subscription, interval} from 'rxjs';
|
||||
import {AuditLog, AuditLogService} from './audit-log.service';
|
||||
import {TagColor, TagComponent} from '../../../shared/components/tag/tag.component';
|
||||
|
||||
const ACTION_COLOR_GROUPS: [TagColor, string[]][] = [
|
||||
['red', ['USER_DELETED', 'LIBRARY_DELETED', 'BOOK_DELETED', 'SHELF_DELETED', 'MAGIC_SHELF_DELETED', 'EMAIL_PROVIDER_DELETED', 'OPDS_USER_DELETED', 'AUTHOR_DELETED']],
|
||||
['green', ['USER_CREATED', 'LIBRARY_CREATED', 'BOOK_UPLOADED', 'SHELF_CREATED', 'MAGIC_SHELF_CREATED', 'EMAIL_PROVIDER_CREATED', 'OPDS_USER_CREATED', 'LOGIN_SUCCESS']],
|
||||
['blue', ['USER_UPDATED', 'LIBRARY_UPDATED', 'SHELF_UPDATED', 'MAGIC_SHELF_UPDATED', 'EMAIL_PROVIDER_UPDATED', 'OPDS_USER_UPDATED']],
|
||||
['purple', ['METADATA_UPDATED', 'AUTHOR_METADATA_UPDATED']],
|
||||
['orange', ['SETTINGS_UPDATED', 'OIDC_CONFIG_CHANGED', 'NAMING_PATTERN_CHANGED']],
|
||||
['amber', ['PASSWORD_CHANGED', 'PERMISSIONS_CHANGED']],
|
||||
['fuchsia', ['LOGIN_FAILED']],
|
||||
['pink', ['LOGIN_RATE_LIMITED', 'REFRESH_RATE_LIMITED']],
|
||||
['teal', ['LIBRARY_SCANNED', 'BOOK_SENT', 'BOOK_FILE_DETACHED', 'DUPLICATE_BOOKS_MERGED']],
|
||||
['indigo', ['TASK_EXECUTED']],
|
||||
];
|
||||
|
||||
const ACTION_COLOR_MAP = new Map<string, TagColor>(
|
||||
ACTION_COLOR_GROUPS.flatMap(([color, actions]) => actions.map(a => [a, color]))
|
||||
);
|
||||
|
||||
interface ActionOption {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface UsernameOption {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-audit-logs',
|
||||
standalone: true,
|
||||
imports: [CommonModule, TableModule, Select, DatePicker, FormsModule, TranslocoDirective, TagComponent],
|
||||
templateUrl: './audit-logs.component.html',
|
||||
styleUrl: './audit-logs.component.scss'
|
||||
})
|
||||
export class AuditLogsComponent implements OnInit, OnDestroy {
|
||||
private readonly auditLogService = inject(AuditLogService);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly router = inject(Router);
|
||||
|
||||
logs: AuditLog[] = [];
|
||||
totalRecords = 0;
|
||||
rows = 25;
|
||||
loading = false;
|
||||
selectedAction: string | null = null;
|
||||
selectedUsername: string | null = null;
|
||||
dateRange: Date[] | null = null;
|
||||
expandedRows = new Set<number>();
|
||||
autoRefresh = false;
|
||||
private autoRefreshSub?: Subscription;
|
||||
|
||||
usernameOptions: UsernameOption[] = [{label: 'All Users', value: ''}];
|
||||
|
||||
actionOptions: ActionOption[] = [
|
||||
{label: 'All Actions', value: ''},
|
||||
{label: 'Login Success', value: 'LOGIN_SUCCESS'},
|
||||
{label: 'Login Failed', value: 'LOGIN_FAILED'},
|
||||
{label: 'User Created', value: 'USER_CREATED'},
|
||||
{label: 'User Updated', value: 'USER_UPDATED'},
|
||||
{label: 'User Deleted', value: 'USER_DELETED'},
|
||||
{label: 'Password Changed', value: 'PASSWORD_CHANGED'},
|
||||
{label: 'Library Created', value: 'LIBRARY_CREATED'},
|
||||
{label: 'Library Updated', value: 'LIBRARY_UPDATED'},
|
||||
{label: 'Library Deleted', value: 'LIBRARY_DELETED'},
|
||||
{label: 'Library Scanned', value: 'LIBRARY_SCANNED'},
|
||||
{label: 'Book Uploaded', value: 'BOOK_UPLOADED'},
|
||||
{label: 'Book Deleted', value: 'BOOK_DELETED'},
|
||||
{label: 'Permissions Changed', value: 'PERMISSIONS_CHANGED'},
|
||||
{label: 'Metadata Updated', value: 'METADATA_UPDATED'},
|
||||
{label: 'Settings Updated', value: 'SETTINGS_UPDATED'},
|
||||
{label: 'OIDC Config Changed', value: 'OIDC_CONFIG_CHANGED'},
|
||||
{label: 'Task Executed', value: 'TASK_EXECUTED'},
|
||||
{label: 'Book Sent', value: 'BOOK_SENT'},
|
||||
{label: 'Shelf Created', value: 'SHELF_CREATED'},
|
||||
{label: 'Shelf Updated', value: 'SHELF_UPDATED'},
|
||||
{label: 'Shelf Deleted', value: 'SHELF_DELETED'},
|
||||
{label: 'Magic Shelf Created', value: 'MAGIC_SHELF_CREATED'},
|
||||
{label: 'Magic Shelf Updated', value: 'MAGIC_SHELF_UPDATED'},
|
||||
{label: 'Magic Shelf Deleted', value: 'MAGIC_SHELF_DELETED'},
|
||||
{label: 'Email Provider Created', value: 'EMAIL_PROVIDER_CREATED'},
|
||||
{label: 'Email Provider Updated', value: 'EMAIL_PROVIDER_UPDATED'},
|
||||
{label: 'Email Provider Deleted', value: 'EMAIL_PROVIDER_DELETED'},
|
||||
{label: 'OPDS User Created', value: 'OPDS_USER_CREATED'},
|
||||
{label: 'OPDS User Deleted', value: 'OPDS_USER_DELETED'},
|
||||
{label: 'OPDS User Updated', value: 'OPDS_USER_UPDATED'},
|
||||
{label: 'Naming Pattern Changed', value: 'NAMING_PATTERN_CHANGED'},
|
||||
{label: 'Login Rate Limited', value: 'LOGIN_RATE_LIMITED'},
|
||||
{label: 'Refresh Rate Limited', value: 'REFRESH_RATE_LIMITED'},
|
||||
{label: 'Duplicate Books Merged', value: 'DUPLICATE_BOOKS_MERGED'},
|
||||
{label: 'Book File Detached', value: 'BOOK_FILE_DETACHED'},
|
||||
{label: 'Author Metadata Updated', value: 'AUTHOR_METADATA_UPDATED'},
|
||||
{label: 'Author Deleted', value: 'AUTHOR_DELETED'},
|
||||
];
|
||||
|
||||
currentPage = 0;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.restoreFromQueryParams();
|
||||
this.loadUsernames();
|
||||
this.loadLogs();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.autoRefreshSub?.unsubscribe();
|
||||
}
|
||||
|
||||
loadUsernames(): void {
|
||||
this.auditLogService.getDistinctUsernames().subscribe({
|
||||
next: (usernames) => {
|
||||
this.usernameOptions = [
|
||||
{label: 'All Users', value: ''},
|
||||
...usernames.map(u => ({label: u, value: u}))
|
||||
];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loadLogs(showLoading = true): void {
|
||||
if (showLoading) {
|
||||
this.loading = true;
|
||||
}
|
||||
const action = this.selectedAction || undefined;
|
||||
const username = this.selectedUsername || undefined;
|
||||
const from = this.dateRange?.[0] ? this.formatDateTime(this.dateRange[0]) : undefined;
|
||||
const to = this.dateRange?.[1] ? this.formatDateTime(this.dateRange[1], true) : undefined;
|
||||
this.auditLogService.getAuditLogs(this.currentPage, this.rows, action, username, from, to).subscribe({
|
||||
next: (response) => {
|
||||
this.logs = response.content;
|
||||
this.totalRecords = response.page.totalElements;
|
||||
this.loading = false;
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onLazyLoad(event: TableLazyLoadEvent): void {
|
||||
this.rows = event.rows ?? this.rows;
|
||||
this.currentPage = (event.first ?? 0) / this.rows;
|
||||
this.updateQueryParams();
|
||||
this.loadLogs();
|
||||
}
|
||||
|
||||
onFilterChange(): void {
|
||||
this.currentPage = 0;
|
||||
this.updateQueryParams();
|
||||
this.loadLogs();
|
||||
}
|
||||
|
||||
onDateRangeChange(): void {
|
||||
if (!this.dateRange || (this.dateRange[0] && this.dateRange[1])) {
|
||||
this.onFilterChange();
|
||||
}
|
||||
}
|
||||
|
||||
toggleAutoRefresh(): void {
|
||||
this.autoRefresh = !this.autoRefresh;
|
||||
if (this.autoRefresh) {
|
||||
this.autoRefreshSub = interval(10000).subscribe(() => this.loadLogs(false));
|
||||
} else {
|
||||
this.autoRefreshSub?.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
clearAllFilters(): void {
|
||||
this.selectedAction = null;
|
||||
this.selectedUsername = null;
|
||||
this.dateRange = null;
|
||||
this.currentPage = 0;
|
||||
this.updateQueryParams();
|
||||
this.loadLogs();
|
||||
}
|
||||
|
||||
get hasActiveFilters(): boolean {
|
||||
return !!this.selectedAction || !!this.selectedUsername ||
|
||||
(this.dateRange != null && this.dateRange.length > 0 && this.dateRange[0] != null);
|
||||
}
|
||||
|
||||
toggleDescription(logId: number): void {
|
||||
if (this.expandedRows.has(logId)) {
|
||||
this.expandedRows.delete(logId);
|
||||
} else {
|
||||
this.expandedRows.add(logId);
|
||||
}
|
||||
}
|
||||
|
||||
countryCodeToFlag(code: string): string {
|
||||
if (!code || code.length !== 2) return '';
|
||||
return [...code.toUpperCase()]
|
||||
.map(c => String.fromCodePoint(0x1F1E6 + c.charCodeAt(0) - 65))
|
||||
.join('');
|
||||
}
|
||||
|
||||
getRelativeTime(dateStr: string): string {
|
||||
const now = new Date();
|
||||
const date = new Date(dateStr);
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffSec = Math.floor(diffMs / 1000);
|
||||
const diffMin = Math.floor(diffSec / 60);
|
||||
const diffHour = Math.floor(diffMin / 60);
|
||||
const diffDay = Math.floor(diffHour / 24);
|
||||
|
||||
if (diffSec < 60) return 'Just now';
|
||||
if (diffMin < 60) return `${diffMin}m ago`;
|
||||
if (diffHour < 24) return `${diffHour}h ago`;
|
||||
if (diffDay < 30) return `${diffDay}d ago`;
|
||||
return new Intl.DateTimeFormat(undefined, {dateStyle: 'medium'}).format(date);
|
||||
}
|
||||
|
||||
formatAction(action: string): string {
|
||||
return action.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase()).replace(/\B\w+/g, c => c.toLowerCase());
|
||||
}
|
||||
|
||||
getActionColor(action: string): TagColor {
|
||||
return ACTION_COLOR_MAP.get(action) ?? 'gray';
|
||||
}
|
||||
|
||||
private restoreFromQueryParams(): void {
|
||||
const params = this.route.snapshot.queryParams;
|
||||
if (params['page']) this.currentPage = +params['page'];
|
||||
if (params['size']) this.rows = +params['size'];
|
||||
if (params['action']) this.selectedAction = params['action'];
|
||||
if (params['username']) this.selectedUsername = params['username'];
|
||||
if (params['from'] || params['to']) {
|
||||
const from = params['from'] ? new Date(params['from'] + 'T00:00:00') : null;
|
||||
const to = params['to'] ? new Date(params['to'] + 'T00:00:00') : null;
|
||||
if (from) this.dateRange = [from, to!];
|
||||
}
|
||||
}
|
||||
|
||||
private updateQueryParams(): void {
|
||||
const queryParams: Record<string, string | null> = {
|
||||
page: this.currentPage > 0 ? String(this.currentPage) : null,
|
||||
size: this.rows !== 25 ? String(this.rows) : null,
|
||||
action: this.selectedAction || null,
|
||||
username: this.selectedUsername || null,
|
||||
from: this.dateRange?.[0] ? this.formatDate(this.dateRange[0]) : null,
|
||||
to: this.dateRange?.[1] ? this.formatDate(this.dateRange[1]) : null,
|
||||
};
|
||||
this.router.navigate([], {queryParams, queryParamsHandling: 'merge', replaceUrl: true});
|
||||
}
|
||||
|
||||
private formatDate(date: Date): string {
|
||||
return date.getFullYear() + '-' +
|
||||
String(date.getMonth() + 1).padStart(2, '0') + '-' +
|
||||
String(date.getDate()).padStart(2, '0');
|
||||
}
|
||||
|
||||
private formatDateTime(date: Date, endOfDay = false): string {
|
||||
const d = new Date(date);
|
||||
if (endOfDay) {
|
||||
d.setHours(23, 59, 59);
|
||||
} else {
|
||||
d.setHours(0, 0, 0);
|
||||
}
|
||||
return d.getFullYear() + '-' +
|
||||
String(d.getMonth() + 1).padStart(2, '0') + '-' +
|
||||
String(d.getDate()).padStart(2, '0') + 'T' +
|
||||
String(d.getHours()).padStart(2, '0') + ':' +
|
||||
String(d.getMinutes()).padStart(2, '0') + ':' +
|
||||
String(d.getSeconds()).padStart(2, '0');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsReader.fonts'">
|
||||
<div>
|
||||
<div class="settings-content" style="position: relative;">
|
||||
<div class="float-top-right">
|
||||
<p-button
|
||||
icon="pi pi-upload"
|
||||
rounded
|
||||
size="large"
|
||||
(click)="openUploadDialog()"
|
||||
[disabled]="customFonts.length >= maxFonts"
|
||||
></p-button>
|
||||
</div>
|
||||
@if (customFonts.length === 0 && !isLoading) {
|
||||
<div class="preferences-section">
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon-wrapper">
|
||||
<i class="pi pi-palette empty-icon"></i>
|
||||
</div>
|
||||
<h3 class="empty-title">{{ t('emptyTitle') }}</h3>
|
||||
<p class="empty-description">
|
||||
{{ t('emptyDesc') }}<br>
|
||||
{{ t('emptyHint') }}
|
||||
</p>
|
||||
<p class="empty-hint">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('supportedFormats') }} <strong>TTF</strong>, <strong>OTF</strong>, <strong>WOFF</strong>, <strong>WOFF2</strong>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<div>
|
||||
<h3 class="section-title">
|
||||
{{ t('yourLibrary') }}
|
||||
<span class="font-count">({{ customFonts.length }})</span>
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="fonts-grid">
|
||||
@for (font of customFonts; track font.id) {
|
||||
<div class="settings-card font-card">
|
||||
<div class="font-card-header">
|
||||
<div class="font-title-group">
|
||||
<h4 class="font-name">{{ font.fontName }}</h4>
|
||||
<span class="format-tag">{{ font.format }}</span>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
severity="danger"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
size="small"
|
||||
(click)="deleteFont(font)"
|
||||
[pTooltip]="t('deleteFont')"
|
||||
tooltipPosition="left"
|
||||
></p-button>
|
||||
</div>
|
||||
|
||||
<div class="font-preview-area">
|
||||
<label class="preview-label">
|
||||
<i class="pi pi-eye"></i>
|
||||
{{ t('preview') }}
|
||||
</label>
|
||||
@if (!fontsLoadedInBrowser) {
|
||||
<div class="font-preview-skeleton">
|
||||
<p-skeleton width="100%" height="1rem" class="mb-3"></p-skeleton>
|
||||
<p-skeleton width="100%" height="1rem" class="mb-3"></p-skeleton>
|
||||
<p-skeleton width="85%" height="1rem" class="mb-3"></p-skeleton>
|
||||
<p-skeleton width="60%" height="1rem" class="mb-3"></p-skeleton>
|
||||
<p-skeleton width="85%" height="1rem" class="mb-3"></p-skeleton>
|
||||
<p-skeleton width="95%" height="0.875rem"></p-skeleton>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="font-preview" [style.font-family]="font.fontName">
|
||||
<p class="preview-paragraph">
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
</p>
|
||||
<p class="preview-paragraph-small">
|
||||
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
</p>
|
||||
<div class="preview-characters">
|
||||
<span>ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="font-metadata">
|
||||
<div class="metadata-row">
|
||||
<span class="meta-label"><i class="pi pi-file"></i>{{ t('file') }}</span>
|
||||
<span class="meta-value">{{ font.originalFileName }}</span>
|
||||
</div>
|
||||
<div class="metadata-row">
|
||||
<span class="meta-label"><i class="pi pi-database"></i>{{ t('size') }}</span>
|
||||
<span class="meta-value">{{ formatFileSize(font.fileSize) }}</span>
|
||||
</div>
|
||||
<div class="metadata-row">
|
||||
<span class="meta-label"><i class="pi pi-calendar"></i>{{ t('uploaded') }}</span>
|
||||
<span class="meta-value">{{ font.uploadedAt | date: 'mediumDate' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-confirmDialog></p-confirmDialog>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,382 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.main-container {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
height: calc(100dvh - 10.5rem);
|
||||
overflow-y: auto;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
height: calc(100dvh - 11.65rem);
|
||||
}
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-header {
|
||||
.header-content {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.header-text {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.75rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.5rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
.font-count {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.section-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--p-content-background);
|
||||
padding: 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
// ==================== Empty State ====================
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
padding: 3rem 1.5rem;
|
||||
min-height: 300px;
|
||||
|
||||
.empty-icon-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 10%, transparent);
|
||||
border-radius: 50%;
|
||||
margin-bottom: 1.5rem;
|
||||
border: 3px dashed var(--p-primary-color);
|
||||
|
||||
.empty-icon {
|
||||
font-size: 2.5rem;
|
||||
color: var(--p-primary-color);
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
margin: 0 0 0.75rem 0;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.empty-description {
|
||||
margin: 0 0 1rem 0;
|
||||
font-size: 0.9375rem;
|
||||
color: var(--p-text-muted-color);
|
||||
max-width: 500px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.empty-hint {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
margin: 0;
|
||||
padding: 0.75rem 1.25rem;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 5%, transparent);
|
||||
border: 1px solid color-mix(in srgb, var(--p-primary-color) 20%, transparent);
|
||||
border-radius: 6px;
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
max-width: 500px;
|
||||
|
||||
i {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 0.875rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
strong {
|
||||
color: var(--p-text-color);
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 2rem 1rem;
|
||||
min-height: 250px;
|
||||
|
||||
.empty-icon-wrapper {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
.empty-icon {
|
||||
font-size: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
|
||||
.empty-description {
|
||||
font-size: 0.875rem;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.empty-hint {
|
||||
font-size: 0.75rem;
|
||||
padding: 0.625rem 1rem;
|
||||
max-width: 100%;
|
||||
flex-direction: column;
|
||||
text-align: center;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Fonts Grid ====================
|
||||
.fonts-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
||||
gap: 1.5rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Font Card ====================
|
||||
.font-card {
|
||||
padding: 0;
|
||||
gap: 0;
|
||||
|
||||
.font-card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
gap: 1rem;
|
||||
padding: 1rem 1rem 0.75rem;
|
||||
border-bottom: 1px solid var(--p-content-border-color);
|
||||
|
||||
.font-title-group {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.font-name {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.format-tag {
|
||||
display: inline-block;
|
||||
padding: 0.1875rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
background: transparent;
|
||||
border: 1px solid var(--p-primary-color);
|
||||
color: var(--p-primary-color);
|
||||
font-size: 0.6875rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.025em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.font-preview-area {
|
||||
padding: 1rem;
|
||||
border-bottom: 1px solid var(--p-content-border-color);
|
||||
|
||||
.preview-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-muted-color);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.025em;
|
||||
margin-bottom: 0.75rem;
|
||||
|
||||
i {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.font-preview {
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
background: color-mix(in srgb, var(--p-surface-ground) 30%, var(--p-content-background));
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
|
||||
.preview-paragraph {
|
||||
color: var(--p-text-color);
|
||||
font-size: 0.9375rem;
|
||||
line-height: 1.7;
|
||||
margin: 0;
|
||||
text-align: justify;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.preview-paragraph-small {
|
||||
color: var(--p-text-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
text-align: justify;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.preview-characters {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
padding-top: 0.5rem;
|
||||
margin-top: 0.25rem;
|
||||
border-top: 1px solid var(--p-content-border-color);
|
||||
|
||||
span {
|
||||
font-size: 0.6875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
letter-spacing: 0.025em;
|
||||
font-weight: 400;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.font-preview-skeleton {
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
background: color-mix(in srgb, var(--p-surface-ground) 30%, var(--p-content-background));
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.font-metadata {
|
||||
padding: 1rem;
|
||||
background: color-mix(in srgb, var(--p-surface-ground) 20%, var(--p-content-background));
|
||||
|
||||
.metadata-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 0.375rem 0;
|
||||
|
||||
&:not(:last-child) {
|
||||
border-bottom: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.meta-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-weight: 500;
|
||||
|
||||
i {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.meta-value {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-color);
|
||||
font-weight: 500;
|
||||
text-align: right;
|
||||
word-break: break-word;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.float-top-right {
|
||||
position: absolute;
|
||||
top: -0.5rem;
|
||||
right: -0.5rem;
|
||||
z-index: 10;
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {CustomFontService} from '../../../shared/service/custom-font.service';
|
||||
import {CustomFont, formatFileSize} from '../../../shared/model/custom-font.model';
|
||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||
import {ConfirmationService} from 'primeng/api';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {FontUploadDialogComponent} from './font-upload-dialog/font-upload-dialog.component';
|
||||
import {Skeleton} from 'primeng/skeleton';
|
||||
import {DialogSize, DialogStyle} from '../../../shared/services/dialog-launcher.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-custom-fonts',
|
||||
standalone: true,
|
||||
imports: [CommonModule, Button, ConfirmDialog, Tooltip, Skeleton, TranslocoDirective],
|
||||
templateUrl: './custom-fonts.component.html',
|
||||
styleUrls: ['./custom-fonts.component.scss'],
|
||||
providers: [ConfirmationService, DialogService]
|
||||
})
|
||||
export class CustomFontsComponent implements OnInit {
|
||||
customFonts: CustomFont[] = [];
|
||||
isLoading = true;
|
||||
fontsLoadedInBrowser = false;
|
||||
uploadDialogRef: DynamicDialogRef | null = null;
|
||||
|
||||
readonly maxFonts = 10;
|
||||
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
constructor(
|
||||
private customFontService: CustomFontService,
|
||||
private messageService: MessageService,
|
||||
private confirmationService: ConfirmationService,
|
||||
private dialogService: DialogService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadFonts();
|
||||
}
|
||||
|
||||
async loadFonts(): Promise<void> {
|
||||
this.fontsLoadedInBrowser = false;
|
||||
|
||||
try {
|
||||
const fonts = await this.customFontService.ensureFonts();
|
||||
|
||||
this.customFonts = fonts;
|
||||
this.isLoading = false;
|
||||
|
||||
await this.customFontService.loadAllFonts(fonts);
|
||||
|
||||
this.fontsLoadedInBrowser = true;
|
||||
} catch (error) {
|
||||
console.error('Failed to load fonts:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsReader.fonts.loadError')
|
||||
});
|
||||
this.isLoading = false;
|
||||
this.fontsLoadedInBrowser = true;
|
||||
}
|
||||
}
|
||||
|
||||
openUploadDialog(): void {
|
||||
if (this.customFonts.length >= this.maxFonts) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsReader.fonts.quotaExceeded'),
|
||||
detail: this.t.translate('settingsReader.fonts.quotaExceededDetail', {max: this.maxFonts})
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.uploadDialogRef = this.dialogService.open(FontUploadDialogComponent, {
|
||||
showHeader: false,
|
||||
styleClass: `${DialogSize.MD} ${DialogStyle.MINIMAL}`,
|
||||
modal: true,
|
||||
dismissableMask: false,
|
||||
closable: false,
|
||||
});
|
||||
|
||||
if (this.uploadDialogRef) {
|
||||
this.uploadDialogRef.onClose.subscribe((font: CustomFont | null) => {
|
||||
if (font) {
|
||||
this.customFonts.push(font);
|
||||
}
|
||||
this.uploadDialogRef = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteFont(font: CustomFont): void {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('settingsReader.fonts.deleteFontConfirm', {name: font.fontName}),
|
||||
header: this.t.translate('settingsReader.fonts.deleteFontHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => {
|
||||
this.customFontService.deleteFont(font.id).subscribe({
|
||||
next: () => {
|
||||
this.customFonts = this.customFonts.filter(f => f.id !== font.id);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('settingsReader.fonts.deleteSuccess', {name: font.fontName})
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to delete font:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsReader.fonts.deleteFailed'),
|
||||
detail: this.t.translate('settingsReader.fonts.deleteError')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
formatFileSize(bytes: number): string {
|
||||
return formatFileSize(bytes);
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsReader.fonts.upload'">
|
||||
<div class="font-upload-dialog">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-upload header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
(click)="cancel()"
|
||||
severity="secondary"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
[disabled]="isUploading"
|
||||
class="close-button"/>
|
||||
</div>
|
||||
|
||||
<div class="upload-container">
|
||||
<div class="file-upload-section">
|
||||
<div class="section-header">
|
||||
<span class="section-title">
|
||||
<i class="pi pi-file"></i>
|
||||
{{ t('selectFile') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@if (!selectedFile) {
|
||||
<div class="upload-zone"
|
||||
[class.drag-over]="isDragOver"
|
||||
(click)="onUploadZoneClick()"
|
||||
(drop)="onDrop($event)"
|
||||
(dragover)="onDragOver($event)"
|
||||
(dragleave)="onDragLeave($event)">
|
||||
<input
|
||||
#fileInput
|
||||
type="file"
|
||||
accept=".ttf,.otf,.woff,.woff2"
|
||||
[disabled]="isUploading"
|
||||
(change)="onFileInputChange($event)"
|
||||
style="display: none;"
|
||||
/>
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon-wrapper">
|
||||
<i class="pi pi-cloud-upload empty-icon"></i>
|
||||
</div>
|
||||
<h3 class="empty-title">{{ t('dragDrop') }}</h3>
|
||||
<p class="empty-description" [innerHTML]="t('supportedFormats')"></p>
|
||||
<p class="empty-description">{{ t('maxSize') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="file-selected">
|
||||
<div class="file-info-card">
|
||||
<i class="pi pi-file"></i>
|
||||
<div class="file-details">
|
||||
<span class="file-name">{{ selectedFile.name }}</span>
|
||||
<span class="file-meta">{{ formatFileSize(selectedFile.size) }} • {{ selectedFile.name.split('.').pop()?.toUpperCase() }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (previewFontFamily) {
|
||||
<div class="preview-section">
|
||||
<label class="preview-label">
|
||||
<i class="pi pi-eye"></i>
|
||||
{{ t('fontPreview') }}
|
||||
</label>
|
||||
<div class="font-preview" [style.font-family]="previewFontFamily">
|
||||
<p class="preview-paragraph">
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
</p>
|
||||
<p class="preview-paragraph-small">
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
||||
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
</p>
|
||||
<div class="preview-characters">
|
||||
<span>ABCDEFGHIJKLMNOPQRSTUVWXYZ</span>
|
||||
<span>abcdefghijklmnopqrstuvwxyz</span>
|
||||
<span>0123456789 !@#$%^&*()</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<label for="fontName" class="setting-label">{{ t('displayName') }}</label>
|
||||
<p class="setting-description">
|
||||
{{ t('displayNameDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<input
|
||||
pInputText
|
||||
id="fontName"
|
||||
[(ngModel)]="uploadedFontName"
|
||||
[placeholder]="t('displayNamePlaceholder')"
|
||||
[disabled]="isUploading"
|
||||
class="font-name-input"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(click)="cancel()"
|
||||
[disabled]="isUploading"
|
||||
></p-button>
|
||||
<p-button
|
||||
[label]="t('uploadBtn')"
|
||||
icon="pi pi-upload"
|
||||
(click)="uploadFont()"
|
||||
[disabled]="isUploading || !selectedFile || !uploadedFontName.trim()"
|
||||
[loading]="isUploading"
|
||||
></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+357
@@ -0,0 +1,357 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.font-upload-dialog {
|
||||
width: 700px;
|
||||
max-width: 700px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.upload-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 1.75rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 0 0 10px 10px;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 1rem;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.file-upload-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0.625rem 0.875rem;
|
||||
background: var(--overlay-background);
|
||||
border-radius: 6px;
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
|
||||
i {
|
||||
color: var(--primary-color);
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 0.5rem 0.625rem;
|
||||
|
||||
.section-title {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
padding: 1.5rem 1rem;
|
||||
|
||||
.empty-icon-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: var(--overlay-background);
|
||||
border-radius: 50%;
|
||||
margin-bottom: 1rem;
|
||||
border: 3px dashed var(--border-color);
|
||||
|
||||
.empty-icon {
|
||||
font-size: 2.5rem;
|
||||
color: var(--text-secondary-color);
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
margin: 0 0 0.5rem 0;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.empty-description {
|
||||
margin: 0;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary-color);
|
||||
max-width: 450px;
|
||||
line-height: 1.5;
|
||||
|
||||
strong {
|
||||
color: var(--text-color);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 1.5rem 0.75rem;
|
||||
min-height: 180px;
|
||||
|
||||
.empty-icon-wrapper {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
margin-bottom: 0.75rem;
|
||||
|
||||
.empty-icon {
|
||||
font-size: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.empty-description {
|
||||
font-size: 0.8rem;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Upload Zone ====================
|
||||
.upload-zone {
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
border: 2px dashed var(--border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--ground-background);
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover:not(.disabled) {
|
||||
border-color: var(--primary-color);
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--primary-color) 3%,
|
||||
var(--ground-background)
|
||||
);
|
||||
}
|
||||
|
||||
&.drag-over {
|
||||
border-color: var(--primary-color);
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--primary-color) 8%,
|
||||
var(--ground-background)
|
||||
);
|
||||
|
||||
.empty-icon-wrapper {
|
||||
border-color: var(--primary-color);
|
||||
|
||||
.empty-icon {
|
||||
color: var(--primary-color);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== File Selected ====================
|
||||
.file-selected {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.file-info-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
background: var(--overlay-background);
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
i {
|
||||
font-size: 2rem;
|
||||
color: var(--primary-color);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.file-details {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
|
||||
.file-name {
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
font-size: 0.9375rem;
|
||||
word-break: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
.file-meta {
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.preview-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
.preview-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary-color);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.025em;
|
||||
|
||||
i {
|
||||
font-size: 0.75rem;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.font-preview {
|
||||
padding: 1.5rem;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
background: var(--overlay-background);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
box-sizing: border-box;
|
||||
|
||||
.preview-paragraph {
|
||||
color: var(--text-color);
|
||||
font-size: 1rem;
|
||||
line-height: 1.7;
|
||||
margin: 0;
|
||||
text-align: justify;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.preview-paragraph-small {
|
||||
color: var(--text-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.6;
|
||||
margin: 0;
|
||||
text-align: justify;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.preview-characters {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.375rem;
|
||||
padding-top: 0.75rem;
|
||||
margin-top: 0.5rem;
|
||||
border-top: 1px solid var(--border-color);
|
||||
|
||||
span {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
letter-spacing: 0.025em;
|
||||
font-weight: 400;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
width: 100%;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
width: 100%;
|
||||
|
||||
.font-name-input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Dialog Footer ====================
|
||||
.dialog-footer {
|
||||
@include panel.dialog-footer-end;
|
||||
border-top: 1px solid var(--border-color);
|
||||
border-left: none;
|
||||
border-right: none;
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
+245
@@ -0,0 +1,245 @@
|
||||
import {Component, ViewChild, ElementRef, OnDestroy, inject} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {CustomFontService} from '../../../../shared/service/custom-font.service';
|
||||
import {formatFileSize} from '../../../../shared/model/custom-font.model';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-font-upload-dialog',
|
||||
standalone: true,
|
||||
imports: [CommonModule, Button, InputText, FormsModule, TranslocoDirective, TranslocoPipe],
|
||||
templateUrl: './font-upload-dialog.component.html',
|
||||
styleUrls: ['./font-upload-dialog.component.scss']
|
||||
})
|
||||
export class FontUploadDialogComponent implements OnDestroy {
|
||||
@ViewChild('fileInput') fileInput!: ElementRef<HTMLInputElement>;
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
isUploading = false;
|
||||
uploadedFontName = '';
|
||||
selectedFile: File | null = null;
|
||||
isDragOver = false;
|
||||
previewFontFamily: string | null = null;
|
||||
isLoadingPreview = false;
|
||||
currentPreviewToken: number | null = null;
|
||||
|
||||
readonly maxFileSize = 5242880;
|
||||
readonly maxFonts = 10;
|
||||
readonly acceptedFormats = ['.ttf', '.otf', '.woff', '.woff2'];
|
||||
|
||||
constructor(
|
||||
private customFontService: CustomFontService,
|
||||
private messageService: MessageService,
|
||||
private dialogRef: DynamicDialogRef
|
||||
) {}
|
||||
|
||||
onUploadZoneClick(): void {
|
||||
if (this.isUploading) {
|
||||
return;
|
||||
}
|
||||
this.fileInput.nativeElement.click();
|
||||
}
|
||||
|
||||
onFileInputChange(event: Event): void {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
|
||||
if (!file) return;
|
||||
|
||||
if (!this.validateFile(file)) {
|
||||
input.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
this.processFile(file);
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
async loadFontPreview(file: File): Promise<void> {
|
||||
this.cleanupPreviewFont();
|
||||
|
||||
const previewToken = Date.now();
|
||||
this.currentPreviewToken = previewToken;
|
||||
|
||||
if (this.isLoadingPreview) {
|
||||
console.log('Cancelling previous preview load');
|
||||
}
|
||||
|
||||
this.isLoadingPreview = true;
|
||||
|
||||
try {
|
||||
const previewFontName = `preview-font-${previewToken}`;
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
|
||||
if (this.currentPreviewToken !== previewToken) {
|
||||
console.log('Preview operation cancelled - newer preview started');
|
||||
return;
|
||||
}
|
||||
|
||||
const fontFace = new FontFace(previewFontName, arrayBuffer);
|
||||
await fontFace.load();
|
||||
|
||||
if (this.currentPreviewToken !== previewToken) {
|
||||
console.log('Preview operation cancelled after load - newer preview started');
|
||||
document.fonts.delete(fontFace);
|
||||
return;
|
||||
}
|
||||
|
||||
document.fonts.add(fontFace);
|
||||
this.previewFontFamily = `"${previewFontName}"`;
|
||||
} catch (error) {
|
||||
if (this.currentPreviewToken === previewToken) {
|
||||
console.error('Failed to load font preview:', error);
|
||||
this.previewFontFamily = null;
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('settingsReader.fonts.upload.previewFailed'),
|
||||
detail: this.t.translate('settingsReader.fonts.upload.previewFailedDetail')
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
if (this.currentPreviewToken === previewToken) {
|
||||
this.isLoadingPreview = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uploadFont(): void {
|
||||
if (!this.selectedFile) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('settingsReader.fonts.upload.noFileSelected'),
|
||||
detail: this.t.translate('settingsReader.fonts.upload.noFileSelectedDetail')
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.isUploading = true;
|
||||
this.customFontService.uploadFont(this.selectedFile, this.uploadedFontName || undefined).subscribe({
|
||||
next: (font) => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsReader.fonts.upload.success'),
|
||||
detail: this.t.translate('settingsReader.fonts.upload.successDetail', {name: font.fontName})
|
||||
});
|
||||
this.isUploading = false;
|
||||
this.dialogRef.close(font); // Return the uploaded font
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to upload font:', error);
|
||||
const errorMessage = error.status === 400
|
||||
? this.t.translate('settingsReader.fonts.upload.uploadFailedInvalid')
|
||||
: this.t.translate('settingsReader.fonts.upload.uploadFailedDefault');
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsReader.fonts.upload.uploadFailed'),
|
||||
detail: errorMessage
|
||||
});
|
||||
|
||||
this.isUploading = false;
|
||||
this.selectedFile = null;
|
||||
this.uploadedFontName = '';
|
||||
this.cleanupPreviewFont();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
formatFileSize(bytes: number): string {
|
||||
return formatFileSize(bytes);
|
||||
}
|
||||
|
||||
cancel(): void {
|
||||
this.cleanupPreviewFont();
|
||||
this.dialogRef.close(null);
|
||||
}
|
||||
|
||||
onDragOver(event: DragEvent): void {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.isDragOver = true;
|
||||
}
|
||||
|
||||
onDragLeave(event: DragEvent): void {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.isDragOver = false;
|
||||
}
|
||||
|
||||
onDrop(event: DragEvent): void {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.isDragOver = false;
|
||||
|
||||
const files = event.dataTransfer?.files;
|
||||
if (files && files.length > 0) {
|
||||
const file = files[0];
|
||||
|
||||
if (!this.validateFile(file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.processFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
private validateFile(file: File): boolean {
|
||||
const fileName = file.name.toLowerCase();
|
||||
const isValidFormat = this.acceptedFormats.some(format => fileName.endsWith(format));
|
||||
|
||||
if (!isValidFormat) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsReader.fonts.upload.invalidFileType'),
|
||||
detail: this.t.translate('settingsReader.fonts.upload.invalidFileTypeDetail')
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.size > this.maxFileSize) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsReader.fonts.upload.fileTooLarge'),
|
||||
detail: this.t.translate('settingsReader.fonts.upload.fileTooLargeDetail', {size: this.formatFileSize(this.maxFileSize)})
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private processFile(file: File): void {
|
||||
this.selectedFile = file;
|
||||
this.uploadedFontName = file.name.replace(/\.[^/.]+$/, '');
|
||||
this.loadFontPreview(file);
|
||||
}
|
||||
|
||||
cleanupPreviewFont(): void {
|
||||
if (this.previewFontFamily) {
|
||||
const fontName = this.previewFontFamily.replace(/"/g, '');
|
||||
|
||||
try {
|
||||
for (const font of document.fonts) {
|
||||
if (font.family === fontName) {
|
||||
document.fonts.delete(font);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to cleanup preview font:', fontName, error);
|
||||
}
|
||||
|
||||
this.previewFontFamily = null;
|
||||
}
|
||||
|
||||
this.currentPreviewToken = null;
|
||||
this.isLoadingPreview = false;
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.cleanupPreviewFont();
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsDevice'">
|
||||
<p-toast position="top-right"></p-toast>
|
||||
|
||||
<div class="main-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-book"></i>
|
||||
{{ t('hardcover.title') }}
|
||||
<app-external-doc-link docType="hardcover"></app-external-doc-link>
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
{{ t('hardcover.description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@if (hasPermission) {
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-sync"></i>
|
||||
{{ t('hardcover.syncConfig') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('hardcover.syncConfigDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">
|
||||
{{ t('hardcover.syncLabel') }}</label>
|
||||
<p-toggle-switch
|
||||
id="hardcoverSyncEnabled"
|
||||
name="hardcoverSyncEnabled"
|
||||
[(ngModel)]="hardcoverSyncEnabled"
|
||||
(ngModelChange)="onHardcoverSyncToggle()">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('hardcover.syncDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (hardcoverSyncEnabled) {
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('hardcover.apiKey') }}</label>
|
||||
<div class="token-input-group">
|
||||
<input
|
||||
pInputText
|
||||
id="hardcoverApiKey"
|
||||
[(ngModel)]="hardcoverApiKey"
|
||||
[type]="showHardcoverApiKey ? 'text' : 'password'"
|
||||
name="hardcoverApiKey"
|
||||
class="token-input"
|
||||
[placeholder]="t('hardcover.apiKeyPlaceholder')"
|
||||
(blur)="onHardcoverApiKeyChange()"
|
||||
/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="copyText(hardcoverApiKey, 'API Key')"
|
||||
[disabled]="!hardcoverApiKey">
|
||||
</p-button>
|
||||
<p-button
|
||||
[icon]="showHardcoverApiKey ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="toggleShowHardcoverApiKey()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description" [innerHTML]="t('hardcover.apiKeyDesc')">
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="settings-content">
|
||||
<div class="access-denied-card">
|
||||
<i class="pi pi-lock"></i>
|
||||
<div class="access-denied-content">
|
||||
<h3>{{ t('accessRestricted') }}</h3>
|
||||
<p>
|
||||
{{ t('hardcover.accessDenied') }}
|
||||
<br>
|
||||
{{ t('contactAdmin') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
@use '../../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.main-container {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
margin-top: 1.5rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
@media (max-width: 768px) {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
margin-bottom: 1rem;
|
||||
margin-left: 1rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
padding: 1rem 1.5rem 1.5rem 1.5rem;
|
||||
margin-left: 1rem;
|
||||
margin-right: 1rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 1rem;
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
padding: 0.5rem 0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 0.5rem 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.token-input-group {
|
||||
flex: 1;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 250px;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.token-input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
width: 100%;
|
||||
|
||||
.token-input {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 150px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.access-denied-card {
|
||||
@include settings.settings-access-denied-card;
|
||||
}
|
||||
|
||||
.access-denied-content {
|
||||
@include settings.settings-access-denied-content;
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
import {Component, effect, inject} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {Button} from 'primeng/button';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {ExternalDocLinkComponent} from '../../../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import {UserService} from '../../../user-management/user.service';
|
||||
import {HardcoverSyncSettingsService} from './hardcover-sync-settings.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: 'app-hardcover-settings-component',
|
||||
imports: [
|
||||
FormsModule,
|
||||
InputText,
|
||||
ToggleSwitch,
|
||||
Button,
|
||||
ToastModule,
|
||||
ExternalDocLinkComponent,
|
||||
TranslocoDirective
|
||||
],
|
||||
providers: [MessageService],
|
||||
templateUrl: './hardcover-settings-component.html',
|
||||
styleUrls: ['./hardcover-settings-component.scss']
|
||||
})
|
||||
export class HardcoverSettingsComponent {
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly hardcoverSyncSettingsService = inject(HardcoverSyncSettingsService);
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
hasPermission = false;
|
||||
hardcoverSyncEnabled = false;
|
||||
hardcoverApiKey = '';
|
||||
showHardcoverApiKey = false;
|
||||
private prevHasPermission = false;
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (!user) return;
|
||||
|
||||
const currHasPermission = (user.permissions.canSyncKoReader
|
||||
|| user.permissions.canSyncKobo
|
||||
|| user.permissions.admin) ?? false;
|
||||
this.hasPermission = currHasPermission;
|
||||
if (currHasPermission && !this.prevHasPermission) {
|
||||
this.loadHardcoverSettings();
|
||||
}
|
||||
this.prevHasPermission = currHasPermission;
|
||||
});
|
||||
}
|
||||
|
||||
private loadHardcoverSettings() {
|
||||
this.hardcoverSyncSettingsService.getSettings().subscribe({
|
||||
next: settings => {
|
||||
this.hardcoverSyncEnabled = settings.hardcoverSyncEnabled ?? false;
|
||||
this.hardcoverApiKey = settings.hardcoverApiKey ?? '';
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsDevice.hardcover.loadError')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleShowHardcoverApiKey() {
|
||||
this.showHardcoverApiKey = !this.showHardcoverApiKey;
|
||||
}
|
||||
|
||||
onHardcoverSyncToggle() {
|
||||
const message = this.hardcoverSyncEnabled
|
||||
? this.t.translate('settingsDevice.hardcover.syncEnabledMsg')
|
||||
: this.t.translate('settingsDevice.hardcover.syncDisabledMsg');
|
||||
this.updateHardcoverSettings(message);
|
||||
}
|
||||
|
||||
onHardcoverApiKeyChange() {
|
||||
this.updateHardcoverSettings(this.t.translate('settingsDevice.hardcover.apiKeyUpdated'));
|
||||
}
|
||||
|
||||
private updateHardcoverSettings(successMessage: string) {
|
||||
this.hardcoverSyncSettingsService.updateSettings({
|
||||
hardcoverSyncEnabled: this.hardcoverSyncEnabled,
|
||||
hardcoverApiKey: this.hardcoverApiKey
|
||||
}).subscribe({
|
||||
next: settings => {
|
||||
this.hardcoverSyncEnabled = settings.hardcoverSyncEnabled ?? false;
|
||||
this.hardcoverApiKey = settings.hardcoverApiKey ?? '';
|
||||
this.messageService.add({severity: 'success', summary: this.t.translate('settingsDevice.hardcover.settingsUpdated'), detail: successMessage});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsDevice.hardcover.updateFailed'),
|
||||
detail: this.t.translate('settingsDevice.hardcover.updateError')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
copyText(text: string, label: string = 'Text') {
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsDevice.copied'),
|
||||
detail: this.t.translate('settingsDevice.copiedDetail', {label})
|
||||
});
|
||||
}).catch(err => {
|
||||
console.error('Copy failed', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsDevice.copyFailed'),
|
||||
detail: this.t.translate('settingsDevice.copyFailedDetail', {label})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../../core/config/api-config';
|
||||
|
||||
export interface HardcoverSyncSettings {
|
||||
hardcoverApiKey?: string;
|
||||
hardcoverSyncEnabled?: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HardcoverSyncSettingsService {
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/hardcover-sync-settings`;
|
||||
|
||||
getSettings(): Observable<HardcoverSyncSettings> {
|
||||
return this.http.get<HardcoverSyncSettings>(this.baseUrl);
|
||||
}
|
||||
|
||||
updateSettings(settings: HardcoverSyncSettings): Observable<HardcoverSyncSettings> {
|
||||
return this.http.put<HardcoverSyncSettings>(this.baseUrl, settings);
|
||||
}
|
||||
}
|
||||
+332
@@ -0,0 +1,332 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsDevice'">
|
||||
<p-toast position="top-right"></p-toast>
|
||||
<p-confirmDialog></p-confirmDialog>
|
||||
|
||||
<div class="main-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-tablet"></i>
|
||||
{{ t('kobo.title') }}
|
||||
<app-external-doc-link docType="kobo"></app-external-doc-link>
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
{{ t('kobo.description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@if (hasKoboTokenPermission) {
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-sync"></i>
|
||||
{{ t('kobo.syncConfig') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('kobo.syncConfigDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.enableSync') }}</label>
|
||||
<p-toggle-switch
|
||||
id="syncEnabled"
|
||||
name="syncEnabled"
|
||||
[(ngModel)]="koboSyncSettings.syncEnabled"
|
||||
(ngModelChange)="onSyncToggle()">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('kobo.enableSyncDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (koboSyncSettings.syncEnabled) {
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.twoWaySyncLabel') }}</label>
|
||||
<p-toggle-switch
|
||||
id="twoWayProgressSync"
|
||||
name="twoWayProgressSync"
|
||||
[(ngModel)]="koboSyncSettings.twoWayProgressSync"
|
||||
(ngModelChange)="onTwoWaySyncToggle()">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('kobo.twoWaySyncDesc') }}
|
||||
<br>
|
||||
<strong>{{ t('kobo.twoWaySyncNote') }}</strong>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (koboSyncSettings.syncEnabled) {
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.token') }}</label>
|
||||
<div class="token-input-group">
|
||||
<input
|
||||
pInputText
|
||||
id="koboToken"
|
||||
[(ngModel)]="koboSyncSettings.token"
|
||||
[type]="showToken ? 'text' : 'password'"
|
||||
readonly
|
||||
name="koboToken"
|
||||
class="token-input"
|
||||
/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="copyText(koboSyncSettings.token, 'Token')"
|
||||
[disabled]="!koboSyncSettings.token">
|
||||
</p-button>
|
||||
<p-button
|
||||
[icon]="showToken ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="toggleShowToken()"
|
||||
[disabled]="!koboSyncSettings.token">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-refresh"
|
||||
outlined="true"
|
||||
severity="warn"
|
||||
size="small"
|
||||
(onClick)="confirmRegenerateToken()"
|
||||
[disabled]="!credentialsSaved">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('kobo.tokenDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.markAsReading', {value: koboSyncSettings.progressMarkAsReadingThreshold?.toFixed(0)}) }}</label>
|
||||
<div class="slider-container">
|
||||
<p-slider
|
||||
id="markAsReadingThreshold"
|
||||
name="markAsReadingThreshold"
|
||||
[(ngModel)]="koboSyncSettings.progressMarkAsReadingThreshold"
|
||||
[min]="1"
|
||||
[max]="10"
|
||||
[step]="1"
|
||||
(ngModelChange)="onProgressThresholdsChange()">
|
||||
</p-slider>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('kobo.markAsReadingDesc') }}
|
||||
<br>
|
||||
<strong>{{ t('kobo.recommended') }}</strong> {{ t('kobo.markAsReadingRec') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.markAsFinished', {value: koboSyncSettings.progressMarkAsFinishedThreshold?.toFixed(0)}) }}</label>
|
||||
<div class="slider-container">
|
||||
<p-slider
|
||||
id="markAsFinishedThreshold"
|
||||
name="markAsFinishedThreshold"
|
||||
[(ngModel)]="koboSyncSettings.progressMarkAsFinishedThreshold"
|
||||
[min]="90"
|
||||
[max]="100"
|
||||
[step]="1"
|
||||
(ngModelChange)="onProgressThresholdsChange()">
|
||||
</p-slider>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('kobo.markAsFinishedDesc') }}
|
||||
<br>
|
||||
<strong>{{ t('kobo.recommended') }}</strong> {{ t('kobo.markAsFinishedRec') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.autoAddLabel') }}</label>
|
||||
<p-toggle-switch
|
||||
id="autoAddToShelf"
|
||||
name="autoAddToShelf"
|
||||
[(ngModel)]="koboSyncSettings.autoAddToShelf"
|
||||
(ngModelChange)="onAutoAddToggle()">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('kobo.autoAddDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (isAdmin) {
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-cog"></i>
|
||||
{{ t('kobo.adminSettings') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('kobo.adminSettingsDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.convertKepub') }}</label>
|
||||
<p-toggle-switch
|
||||
id="convertToKepub"
|
||||
[(ngModel)]="koboSettings.convertToKepub"
|
||||
(ngModelChange)="onToggleChange()">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
<strong>{{ t('kobo.pros') }}</strong> {{ t('kobo.convertKepubPros') }}
|
||||
<br>
|
||||
<strong>{{ t('kobo.cons') }}</strong> {{ t('kobo.convertKepubCons') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.conversionSizeLimit', {value: koboSettings.conversionLimitInMb}) }}</label>
|
||||
<div class="slider-container">
|
||||
<p-slider
|
||||
id="conversionLimit"
|
||||
[(ngModel)]="koboSettings.conversionLimitInMb"
|
||||
[min]="1"
|
||||
[max]="250"
|
||||
[step]="1"
|
||||
(ngModelChange)="onSliderChange()">
|
||||
</p-slider>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('kobo.conversionSizeLimitDesc') }}
|
||||
<br>
|
||||
<strong>{{ t('kobo.recommended') }}</strong> {{ t('kobo.conversionSizeLimitRec') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.forceHyphenation') }}</label>
|
||||
<p-toggle-switch
|
||||
id="forceEnableHyphenation"
|
||||
[(ngModel)]="koboSettings.forceEnableHyphenation"
|
||||
(ngModelChange)="onToggleChange()">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description" [innerHTML]="t('kobo.forceHyphenationDesc')">
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.convertCbx') }}</label>
|
||||
<p-toggle-switch
|
||||
id="convertCbxToEpub"
|
||||
[(ngModel)]="koboSettings.convertCbxToEpub"
|
||||
(ngModelChange)="onToggleChange()">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('kobo.convertCbxDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.imageCompression', {value: koboSettings.conversionImageCompressionPercentage}) }}</label>
|
||||
<div class="slider-container">
|
||||
<p-slider
|
||||
id="conversionLimit"
|
||||
[(ngModel)]="koboSettings.conversionImageCompressionPercentage"
|
||||
[min]="1"
|
||||
[max]="100"
|
||||
[step]="1"
|
||||
(ngModelChange)="onSliderChange()">
|
||||
</p-slider>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('kobo.imageCompressionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('kobo.cbxSizeLimit', {value: koboSettings.conversionLimitInMbForCbx}) }}</label>
|
||||
<div class="slider-container">
|
||||
<p-slider
|
||||
id="conversionLimitForCbx"
|
||||
[(ngModel)]="koboSettings.conversionLimitInMbForCbx"
|
||||
[min]="1"
|
||||
[max]="500"
|
||||
[step]="1"
|
||||
(ngModelChange)="onSliderChange()">
|
||||
</p-slider>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('kobo.cbxSizeLimitDesc') }}
|
||||
<br>
|
||||
<strong>{{ t('kobo.recommended') }}</strong> {{ t('kobo.cbxSizeLimitRec') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
<div class="settings-content">
|
||||
<div class="access-denied-card">
|
||||
<i class="pi pi-lock"></i>
|
||||
<div class="access-denied-content">
|
||||
<h3>{{ t('accessRestricted') }}</h3>
|
||||
<p>
|
||||
{{ t('kobo.accessDenied') }}
|
||||
<br>
|
||||
{{ t('contactAdmin') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
@use '../../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.main-container {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
@media (min-width: 768px) {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
padding: 1.75rem;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.slider-container {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
max-width: 300px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 180px;
|
||||
max-width: 250px;
|
||||
}
|
||||
}
|
||||
|
||||
.token-input-group {
|
||||
flex: 1;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 250px;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
align-items: flex-end;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.token-input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
|
||||
.token-input {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
}
|
||||
}
|
||||
|
||||
.slider-container {
|
||||
width: 250px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 200px;
|
||||
}
|
||||
}
|
||||
|
||||
.access-denied-card {
|
||||
@include settings.settings-access-denied-card;
|
||||
}
|
||||
|
||||
.access-denied-content {
|
||||
@include settings.settings-access-denied-content;
|
||||
}
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
import {Component, effect, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {KoboService, KoboSyncSettings} from './kobo.service';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||
import {UserService} from '../../../user-management/user.service';
|
||||
import {Subject} from 'rxjs';
|
||||
import {debounceTime, takeUntil} from 'rxjs/operators';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {AppSettingsService} from '../../../../../shared/service/app-settings.service';
|
||||
import {SettingsHelperService} from '../../../../../shared/service/settings-helper.service';
|
||||
import {AppSettingKey, KoboSettings} from '../../../../../shared/model/app-settings.model';
|
||||
import {ShelfService} from '../../../../book/service/shelf.service';
|
||||
import {ExternalDocLinkComponent} from '../../../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-kobo-sync-setting-component',
|
||||
standalone: true,
|
||||
templateUrl: './kobo-sync-settings-component.html',
|
||||
styleUrl: './kobo-sync-settings-component.scss',
|
||||
imports: [FormsModule, Button, InputText, ConfirmDialog, ToggleSwitch, Slider, Divider, ExternalDocLinkComponent, ToastModule, TranslocoDirective],
|
||||
providers: [MessageService, ConfirmationService]
|
||||
})
|
||||
export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
private koboService = inject(KoboService);
|
||||
private messageService = inject(MessageService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
protected userService = inject(UserService);
|
||||
protected appSettingsService = inject(AppSettingsService);
|
||||
protected settingsHelperService = inject(SettingsHelperService);
|
||||
private shelfService = inject(ShelfService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly sliderChange$ = new Subject<void>();
|
||||
private readonly progressThresholdChange$ = new Subject<void>();
|
||||
|
||||
hasKoboTokenPermission = false;
|
||||
isAdmin = false;
|
||||
credentialsSaved = false;
|
||||
showToken = false;
|
||||
|
||||
koboSettings: KoboSettings = {
|
||||
convertToKepub: false,
|
||||
conversionLimitInMb: 100,
|
||||
convertCbxToEpub: false,
|
||||
conversionImageCompressionPercentage: 85,
|
||||
conversionLimitInMbForCbx: 100,
|
||||
forceEnableHyphenation: false
|
||||
};
|
||||
|
||||
koboSyncSettings: KoboSyncSettings = {
|
||||
token: '',
|
||||
syncEnabled: false,
|
||||
progressMarkAsReadingThreshold: 1,
|
||||
progressMarkAsFinishedThreshold: 99,
|
||||
autoAddToShelf: true,
|
||||
twoWayProgressSync: false
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.setupSliderDebouncing();
|
||||
}
|
||||
|
||||
private setupSliderDebouncing() {
|
||||
this.sliderChange$.pipe(
|
||||
debounceTime(500),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(() => {
|
||||
this.saveSettings();
|
||||
});
|
||||
|
||||
this.progressThresholdChange$.pipe(
|
||||
debounceTime(500),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(() => {
|
||||
this.updateKoboSettings(this.t.translate('settingsDevice.kobo.progressUpdated'));
|
||||
});
|
||||
}
|
||||
|
||||
private prevHasKoboTokenPermission = false;
|
||||
private prevIsAdmin = false;
|
||||
|
||||
private readonly syncUserEffect = effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (!user) return;
|
||||
|
||||
const currHasKoboTokenPermission = (user.permissions.canSyncKobo) ?? false;
|
||||
const currIsAdmin = user.permissions.admin ?? false;
|
||||
|
||||
if (currHasKoboTokenPermission && !this.prevHasKoboTokenPermission) {
|
||||
this.hasKoboTokenPermission = true;
|
||||
this.loadKoboUserSettings();
|
||||
} else {
|
||||
this.hasKoboTokenPermission = currHasKoboTokenPermission;
|
||||
}
|
||||
|
||||
if (currIsAdmin && !this.prevIsAdmin) {
|
||||
this.isAdmin = true;
|
||||
this.loadKoboAdminSettings();
|
||||
} else {
|
||||
this.isAdmin = currIsAdmin;
|
||||
}
|
||||
|
||||
this.prevHasKoboTokenPermission = currHasKoboTokenPermission;
|
||||
this.prevIsAdmin = currIsAdmin;
|
||||
});
|
||||
|
||||
private loadKoboUserSettings() {
|
||||
this.koboService.getUser().subscribe({
|
||||
next: (settings: KoboSyncSettings) => {
|
||||
this.koboSyncSettings.token = settings.token;
|
||||
this.koboSyncSettings.syncEnabled = settings.syncEnabled;
|
||||
this.koboSyncSettings.progressMarkAsReadingThreshold = settings.progressMarkAsReadingThreshold ?? 1;
|
||||
this.koboSyncSettings.progressMarkAsFinishedThreshold = settings.progressMarkAsFinishedThreshold ?? 99;
|
||||
this.koboSyncSettings.autoAddToShelf = settings.autoAddToShelf ?? false;
|
||||
this.koboSyncSettings.twoWayProgressSync = settings.twoWayProgressSync ?? false;
|
||||
this.credentialsSaved = !!settings.token;
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: this.t.translate('common.error'), detail: this.t.translate('settingsDevice.kobo.loadError')});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private loadKoboAdminSettings() {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.koboSettings.convertToKepub = settings.koboSettings?.convertToKepub ?? true;
|
||||
this.koboSettings.conversionLimitInMb = settings.koboSettings?.conversionLimitInMb ?? 100;
|
||||
this.koboSettings.convertCbxToEpub = settings.koboSettings?.convertCbxToEpub ?? false;
|
||||
this.koboSettings.conversionLimitInMbForCbx = settings.koboSettings?.conversionLimitInMbForCbx ?? 100;
|
||||
this.koboSettings.forceEnableHyphenation = settings.koboSettings?.forceEnableHyphenation ?? false;
|
||||
this.koboSettings.conversionImageCompressionPercentage = settings.koboSettings?.conversionImageCompressionPercentage ?? 85;
|
||||
}
|
||||
}
|
||||
|
||||
copyText(text: string, label: string = 'Text') {
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsDevice.copied'),
|
||||
detail: this.t.translate('settingsDevice.copiedDetail', {label})
|
||||
});
|
||||
}).catch(err => {
|
||||
console.error('Copy failed', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsDevice.copyFailed'),
|
||||
detail: this.t.translate('settingsDevice.copyFailedDetail', {label})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
toggleShowToken() {
|
||||
this.showToken = !this.showToken;
|
||||
}
|
||||
|
||||
|
||||
confirmRegenerateToken() {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('settingsDevice.kobo.confirmRegenerate'),
|
||||
header: this.t.translate('settingsDevice.kobo.confirmRegenerateHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => this.regenerateToken()
|
||||
});
|
||||
}
|
||||
|
||||
private regenerateToken() {
|
||||
this.koboService.createOrUpdateToken().subscribe({
|
||||
next: (settings) => {
|
||||
this.koboSyncSettings.token = settings.token;
|
||||
this.credentialsSaved = true;
|
||||
this.messageService.add({severity: 'success', summary: this.t.translate('settingsDevice.kobo.tokenRegenerated'), detail: this.t.translate('settingsDevice.kobo.tokenRegeneratedDetail')});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: this.t.translate('common.error'), detail: this.t.translate('settingsDevice.kobo.tokenRegenerateError')});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onToggleChange() {
|
||||
this.saveSettings();
|
||||
}
|
||||
|
||||
onSliderChange() {
|
||||
this.sliderChange$.next();
|
||||
}
|
||||
|
||||
onSyncToggle() {
|
||||
if (!this.koboSyncSettings.syncEnabled) {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('settingsDevice.kobo.confirmDisable'),
|
||||
header: this.t.translate('settingsDevice.kobo.confirmDisableHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
accept: () => this.updateKoboSettings(this.t.translate('settingsDevice.kobo.syncDisabled')),
|
||||
reject: () => {
|
||||
this.koboSyncSettings.syncEnabled = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.updateKoboSettings(this.t.translate('settingsDevice.kobo.syncEnabled'));
|
||||
}
|
||||
}
|
||||
|
||||
onProgressThresholdsChange() {
|
||||
this.progressThresholdChange$.next();
|
||||
}
|
||||
|
||||
onAutoAddToggle() {
|
||||
const message = this.koboSyncSettings.autoAddToShelf
|
||||
? this.t.translate('settingsDevice.kobo.autoAddEnabled')
|
||||
: this.t.translate('settingsDevice.kobo.autoAddDisabled');
|
||||
this.updateKoboSettings(message);
|
||||
}
|
||||
|
||||
onTwoWaySyncToggle() {
|
||||
const message = this.koboSyncSettings.twoWayProgressSync
|
||||
? this.t.translate('settingsDevice.kobo.twoWaySyncEnabled')
|
||||
: this.t.translate('settingsDevice.kobo.twoWaySyncDisabled');
|
||||
this.updateKoboSettings(message);
|
||||
}
|
||||
|
||||
private updateKoboSettings(successMessage: string) {
|
||||
this.koboService.updateSettings(this.koboSyncSettings).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsDevice.kobo.settingsUpdated'),
|
||||
detail: successMessage
|
||||
});
|
||||
this.shelfService.reloadShelves();
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsDevice.kobo.settingsUpdateError')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
saveSettings() {
|
||||
this.settingsHelperService.saveSetting(AppSettingKey.KOBO_SETTINGS, this.koboSettings)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsDevice.kobo.settingsSaved'),
|
||||
detail: this.t.translate('settingsDevice.kobo.settingsSuccess')
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsDevice.kobo.saveFailed'),
|
||||
detail: this.t.translate('settingsDevice.kobo.saveError')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../../core/config/api-config';
|
||||
|
||||
export interface KoboSyncSettings {
|
||||
token: string;
|
||||
syncEnabled: boolean;
|
||||
progressMarkAsReadingThreshold?: number;
|
||||
progressMarkAsFinishedThreshold?: number;
|
||||
autoAddToShelf: boolean;
|
||||
twoWayProgressSync: boolean;
|
||||
hardcoverApiKey?: string;
|
||||
hardcoverSyncEnabled?: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class KoboService {
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/kobo-settings`;
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
getUser(): Observable<KoboSyncSettings> {
|
||||
return this.http.get<KoboSyncSettings>(`${this.baseUrl}`);
|
||||
}
|
||||
|
||||
createOrUpdateToken(): Observable<KoboSyncSettings> {
|
||||
return this.http.put<KoboSyncSettings>(`${this.baseUrl}/token`, null);
|
||||
}
|
||||
|
||||
updateSettings(settings: KoboSyncSettings): Observable<KoboSyncSettings> {
|
||||
return this.http.put<KoboSyncSettings>(`${this.baseUrl}`, settings);
|
||||
}
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsDevice'">
|
||||
<p-toast position="top-right"></p-toast>
|
||||
|
||||
<div class="main-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-mobile"></i>
|
||||
{{ t('koreader.title') }}
|
||||
<app-external-doc-link docType="koReader"></app-external-doc-link>
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
{{ t('koreader.description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@if (hasPermission) {
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-sync"></i>
|
||||
{{ t('koreader.syncConfig') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('koreader.syncConfigDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<form #koreaderForm="ngForm">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('koreader.enableSync') }}</label>
|
||||
<p-toggle-switch
|
||||
name="syncEnabled"
|
||||
[(ngModel)]="koReaderSyncEnabled"
|
||||
(ngModelChange)="onToggleEnabled($event)"
|
||||
inputId="syncEnabled"
|
||||
[disabled]="!credentialsSaved">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('koreader.enableSyncDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('koreader.syncWithGrimmory') }}</label>
|
||||
<p-toggle-switch
|
||||
name="syncWithGrimmoryReader"
|
||||
[(ngModel)]="syncWithGrimmoryReader"
|
||||
(ngModelChange)="onToggleSyncWithGrimmoryReader($event)"
|
||||
inputId="syncWithGrimmoryReader"
|
||||
[disabled]="!credentialsSaved || !koReaderSyncEnabled">
|
||||
</p-toggle-switch>
|
||||
</div>
|
||||
<p class="setting-description" [innerHTML]="t('koreader.syncWithGrimmoryDesc')">
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('koreader.apiPath') }}</label>
|
||||
<div class="token-input-group">
|
||||
<input
|
||||
pInputText
|
||||
id="koreaderEndpoint"
|
||||
[value]="koreaderEndpoint"
|
||||
readonly
|
||||
class="token-input"/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="copyText(koreaderEndpoint, 'API Path')"
|
||||
[disabled]="!koreaderEndpoint">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('koreader.apiPathDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('koreader.username') }}</label>
|
||||
<div class="token-input-group">
|
||||
<input
|
||||
pInputText
|
||||
id="username"
|
||||
name="username"
|
||||
required
|
||||
[(ngModel)]="koReaderUsername"
|
||||
#usernameModel="ngModel"
|
||||
[class.p-invalid]="usernameModel.invalid && usernameModel.touched"
|
||||
[disabled]="editMode"
|
||||
class="token-input"/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="copyText(koReaderUsername, 'Username')"
|
||||
[disabled]="!koReaderUsername">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('koreader.usernameDesc') }}
|
||||
</p>
|
||||
@if (editMode && usernameModel.invalid && usernameModel.touched) {
|
||||
<small class="error-message">
|
||||
{{ t('koreader.usernameRequired') }}
|
||||
</small>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('koreader.password') }}</label>
|
||||
<div class="token-input-group">
|
||||
<input
|
||||
pInputText
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
minlength="6"
|
||||
[type]="showPassword ? 'text' : 'password'"
|
||||
[(ngModel)]="koReaderPassword"
|
||||
#passwordModel="ngModel"
|
||||
[class.p-invalid]="passwordModel.invalid && passwordModel.touched"
|
||||
[disabled]="editMode"
|
||||
class="token-input-password"/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="copyText(koReaderPassword, 'Password')"
|
||||
[disabled]="!koReaderPassword">
|
||||
</p-button>
|
||||
<p-button
|
||||
[icon]="showPassword ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
||||
outlined="true"
|
||||
severity="info"
|
||||
size="small"
|
||||
(onClick)="toggleShowPassword()"
|
||||
[disabled]="!koReaderPassword">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('koreader.passwordDesc') }}
|
||||
</p>
|
||||
@if (editMode && passwordModel.invalid && passwordModel.touched) {
|
||||
<small class="error-message">
|
||||
{{ t('koreader.passwordMinLength') }}
|
||||
</small>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('koreader.settingsManagement') }}</label>
|
||||
<p-button
|
||||
[icon]="!editMode ? 'pi pi-save' : 'pi pi-pencil'"
|
||||
outlined="true"
|
||||
[severity]="!editMode ? 'success' : 'warn'"
|
||||
[label]="!editMode ? ('common.save' | transloco) : ('common.edit' | transloco)"
|
||||
size="small"
|
||||
(onClick)="onEditSave()"
|
||||
[disabled]="!editMode && !canSave">
|
||||
</p-button>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('koreader.settingsManagementDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
} @else {
|
||||
<div class="settings-content">
|
||||
<div class="access-denied-card">
|
||||
<i class="pi pi-lock"></i>
|
||||
<div class="access-denied-content">
|
||||
<h3>{{ t('accessRestricted') }}</h3>
|
||||
<p>
|
||||
{{ t('koreader.accessDenied') }}
|
||||
<br>
|
||||
{{ t('contactAdmin') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
@use '../../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.main-container {
|
||||
width: 100%;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
@media (min-width: 768px) {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
margin-top: 1.25rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
padding: 0.5rem 0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 0.5rem 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-color);
|
||||
font-size: settings.$settings-label-size;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.token-input-group {
|
||||
flex: 1;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 250px;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-description-size;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
align-items: flex-end;
|
||||
min-width: 350px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
min-width: unset;
|
||||
}
|
||||
}
|
||||
|
||||
.token-input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
width: 100%;
|
||||
|
||||
.token-input {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 150px;
|
||||
}
|
||||
}
|
||||
|
||||
.token-input-password {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 150px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: var(--p-red-500);
|
||||
font-size: 0.75rem;
|
||||
margin-top: 0.25rem;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.access-denied-card {
|
||||
@include settings.settings-access-denied-card;
|
||||
}
|
||||
|
||||
.access-denied-content {
|
||||
@include settings.settings-access-denied-content;
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
import {Component, effect, inject} from '@angular/core';
|
||||
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {Button} from 'primeng/button';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {KoreaderService} from './koreader.service';
|
||||
import {UserService} from '../../../user-management/user.service';
|
||||
import {ExternalDocLinkComponent} from '../../../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: 'app-koreader-settings-component',
|
||||
imports: [
|
||||
FormsModule,
|
||||
InputText,
|
||||
ToggleSwitch,
|
||||
Button,
|
||||
ToastModule,
|
||||
ExternalDocLinkComponent,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
],
|
||||
providers: [MessageService],
|
||||
templateUrl: './koreader-settings-component.html',
|
||||
styleUrls: ['./koreader-settings-component.scss']
|
||||
})
|
||||
export class KoreaderSettingsComponent {
|
||||
editMode = true;
|
||||
showPassword = false;
|
||||
koReaderSyncEnabled = false;
|
||||
syncWithGrimmoryReader = false;
|
||||
koReaderUsername = '';
|
||||
koReaderPassword = '';
|
||||
credentialsSaved = false;
|
||||
readonly koreaderEndpoint = `${window.location.origin}/api/koreader`;
|
||||
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly koreaderService = inject(KoreaderService);
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
hasPermission = false;
|
||||
private prevHasPermission = false;
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (!user) return;
|
||||
|
||||
const currHasPermission = (user.permissions.canSyncKoReader || user.permissions.admin) ?? false;
|
||||
this.hasPermission = currHasPermission;
|
||||
if (currHasPermission && !this.prevHasPermission) {
|
||||
this.loadKoreaderSettings();
|
||||
}
|
||||
this.prevHasPermission = currHasPermission;
|
||||
});
|
||||
}
|
||||
|
||||
private loadKoreaderSettings() {
|
||||
this.koreaderService.getUser().subscribe({
|
||||
next: koreaderUser => {
|
||||
this.koReaderUsername = koreaderUser.username;
|
||||
this.koReaderPassword = koreaderUser.password;
|
||||
this.koReaderSyncEnabled = koreaderUser.syncEnabled;
|
||||
this.syncWithGrimmoryReader = koreaderUser.syncWithGrimmoryReader ?? koreaderUser.syncWithBookloreReader ?? false;
|
||||
this.credentialsSaved = true;
|
||||
},
|
||||
error: err => {
|
||||
if (err.status !== 404) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsDevice.koreader.loadError')
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
get canSave(): boolean {
|
||||
const u = this.koReaderUsername?.trim() ?? '';
|
||||
const p = this.koReaderPassword ?? '';
|
||||
return u.length > 0 && p.length >= 6;
|
||||
}
|
||||
|
||||
onEditSave() {
|
||||
if (!this.editMode) {
|
||||
this.saveCredentials();
|
||||
}
|
||||
this.editMode = !this.editMode;
|
||||
}
|
||||
|
||||
onToggleEnabled(enabled: boolean) {
|
||||
this.koreaderService.toggleSync(enabled).subscribe({
|
||||
next: () => {
|
||||
this.koReaderSyncEnabled = enabled;
|
||||
this.messageService.add({severity: 'success', summary: this.t.translate('settingsDevice.koreader.syncUpdated'), detail: enabled ? this.t.translate('settingsDevice.koreader.syncEnabled') : this.t.translate('settingsDevice.koreader.syncDisabled')});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: this.t.translate('settingsDevice.koreader.syncUpdateFailed'), detail: this.t.translate('settingsDevice.koreader.syncUpdateError')});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onToggleSyncWithGrimmoryReader(enabled: boolean) {
|
||||
this.koreaderService.toggleSyncProgressWithGrimmoryReader(enabled).subscribe({
|
||||
next: () => {
|
||||
this.syncWithGrimmoryReader = enabled;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsDevice.koreader.syncUpdated'),
|
||||
detail: enabled ? this.t.translate('settingsDevice.koreader.grimmoryReaderEnabled') : this.t.translate('settingsDevice.koreader.grimmoryReaderDisabled')
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsDevice.koreader.syncUpdateFailed'),
|
||||
detail: this.t.translate('settingsDevice.koreader.grimmoryReaderError')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleShowPassword() {
|
||||
this.showPassword = !this.showPassword;
|
||||
}
|
||||
|
||||
|
||||
saveCredentials() {
|
||||
this.koreaderService.createUser(this.koReaderUsername, this.koReaderPassword)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.credentialsSaved = true;
|
||||
this.messageService.add({severity: 'success', summary: this.t.translate('settingsDevice.koreader.saved'), detail: this.t.translate('settingsDevice.koreader.credentialsSaved')});
|
||||
},
|
||||
error: () =>
|
||||
this.messageService.add({severity: 'error', summary: this.t.translate('common.error'), detail: this.t.translate('settingsDevice.koreader.credentialsError')})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
copyText(text: string, label: string = 'Text') {
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsDevice.copied'),
|
||||
detail: this.t.translate('settingsDevice.copiedDetail', {label})
|
||||
});
|
||||
}).catch(err => {
|
||||
console.error('Copy failed', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsDevice.copyFailed'),
|
||||
detail: this.t.translate('settingsDevice.copyFailedDetail', {label})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../../core/config/api-config';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
|
||||
|
||||
export interface KoreaderUser {
|
||||
username: string;
|
||||
password: string;
|
||||
syncEnabled: boolean;
|
||||
syncWithGrimmoryReader?: boolean;
|
||||
// TODO(grimmory-cleanup): Remove once the backend no longer returns the legacy Booklore KOReader sync field.
|
||||
syncWithBookloreReader?: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class KoreaderService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/koreader-users`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
createUser(username: string, password: string): Observable<KoreaderUser> {
|
||||
const payload: unknown = {username, password};
|
||||
return this.http.put<KoreaderUser>(`${this.url}/me`, payload);
|
||||
}
|
||||
|
||||
getUser(): Observable<KoreaderUser> {
|
||||
return this.http.get<KoreaderUser>(`${this.url}/me`);
|
||||
}
|
||||
|
||||
toggleSync(enabled: boolean): Observable<void> {
|
||||
return this.http.patch<void>(`${this.url}/me/sync`, null, {
|
||||
params: {enabled: enabled.toString()}
|
||||
});
|
||||
}
|
||||
|
||||
toggleSyncProgressWithGrimmoryReader(enabled: boolean): Observable<void> {
|
||||
return this.http.patch<void>(`${this.url}/me/sync-progress-with-grimmory`, null, {
|
||||
params: {enabled: enabled.toString()}
|
||||
}).pipe(
|
||||
// TODO(grimmory-cleanup): Remove the legacy endpoint fallback after all supported backends expose the Grimmory route.
|
||||
catchError(() => this.http.patch<void>(`${this.url}/me/sync-progress-with-booklore`, null, {
|
||||
params: {enabled: enabled.toString()}
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<div class="device-settings-container">
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<app-koreader-settings-component></app-koreader-settings-component>
|
||||
</div>
|
||||
<div class="preferences-section">
|
||||
<app-hardcover-settings-component></app-hardcover-settings-component>
|
||||
</div>
|
||||
<div class="preferences-section">
|
||||
<app-kobo-sync-setting-component></app-kobo-sync-setting-component>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,11 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.device-settings-container {
|
||||
@include settings.settings-page-container;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {KoreaderSettingsComponent} from './component/koreader-settings/koreader-settings-component';
|
||||
import {KoboSyncSettingsComponent} from './component/kobo-sync-settings/kobo-sync-settings-component';
|
||||
import {HardcoverSettingsComponent} from './component/hardcover-settings/hardcover-settings-component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-device-settings-component',
|
||||
imports: [
|
||||
KoreaderSettingsComponent,
|
||||
KoboSyncSettingsComponent,
|
||||
HardcoverSettingsComponent
|
||||
],
|
||||
templateUrl: './device-settings-component.html',
|
||||
styleUrl: './device-settings-component.scss'
|
||||
})
|
||||
export class DeviceSettingsComponent {
|
||||
|
||||
}
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsEmail.provider.create'">
|
||||
<div class="email-provider-creator">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-envelope header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
(click)="closeDialog()"
|
||||
severity="secondary"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
class="close-button"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<form [formGroup]="emailProviderForm" (ngSubmit)="createEmailProvider()">
|
||||
<div class="form-container">
|
||||
<div class="form-group highlight-group">
|
||||
<label for="providerName" class="form-label">
|
||||
<i class="pi pi-tag label-icon"></i>
|
||||
{{ t('providerName') }}
|
||||
<span class="required-indicator">*</span>
|
||||
</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
id="providerName"
|
||||
type="text"
|
||||
pInputText
|
||||
formControlName="name"
|
||||
class="input-full"
|
||||
[placeholder]="t('providerNamePlaceholder')"
|
||||
[class.filled]="emailProviderForm.get('name')?.value"
|
||||
|
||||
/>
|
||||
@if (emailProviderForm.get('name')?.value && emailProviderForm.get('name')?.valid) {
|
||||
<i class="pi pi-check-circle input-icon success"></i>
|
||||
}
|
||||
</div>
|
||||
@if (emailProviderForm.get('name')?.invalid && (emailProviderForm.get('name')?.dirty || emailProviderForm.get('name')?.touched)) {
|
||||
<small class="field-error">{{ t('providerNameRequired') }}</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label for="host" class="form-label">
|
||||
<i class="pi pi-server label-icon"></i>
|
||||
{{ t('host') }}
|
||||
<span class="required-indicator">*</span>
|
||||
</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
id="host"
|
||||
type="text"
|
||||
pInputText
|
||||
formControlName="host"
|
||||
class="input-full"
|
||||
[placeholder]="t('hostPlaceholder')"
|
||||
[class.filled]="emailProviderForm.get('host')?.value"
|
||||
/>
|
||||
@if (emailProviderForm.get('host')?.value && emailProviderForm.get('host')?.valid) {
|
||||
<i class="pi pi-check-circle input-icon success"></i>
|
||||
}
|
||||
</div>
|
||||
@if (emailProviderForm.get('host')?.invalid && (emailProviderForm.get('host')?.dirty || emailProviderForm.get('host')?.touched)) {
|
||||
<small class="field-error">{{ t('hostRequired') }}</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label for="port" class="form-label">
|
||||
<i class="pi pi-hashtag label-icon"></i>
|
||||
{{ t('port') }}
|
||||
<span class="required-indicator">*</span>
|
||||
</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
id="port"
|
||||
type="number"
|
||||
pInputText
|
||||
formControlName="port"
|
||||
class="input-full"
|
||||
[placeholder]="t('portPlaceholder')"
|
||||
[class.filled]="emailProviderForm.get('port')?.value"
|
||||
/>
|
||||
@if (emailProviderForm.get('port')?.value && emailProviderForm.get('port')?.valid) {
|
||||
<i class="pi pi-check-circle input-icon success"></i>
|
||||
}
|
||||
</div>
|
||||
@if (emailProviderForm.get('port')?.invalid && (emailProviderForm.get('port')?.dirty || emailProviderForm.get('port')?.touched)) {
|
||||
<small class="field-error">{{ t('portRequired') }}</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label for="username" class="form-label">
|
||||
<i class="pi pi-user label-icon"></i>
|
||||
{{ t('username') }}
|
||||
</label>
|
||||
<input
|
||||
id="username"
|
||||
type="text"
|
||||
pInputText
|
||||
formControlName="username"
|
||||
class="input-full"
|
||||
[placeholder]="t('usernamePlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label for="password" class="form-label">
|
||||
<i class="pi pi-lock label-icon"></i>
|
||||
{{ t('password') }}
|
||||
</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
pInputText
|
||||
formControlName="password"
|
||||
class="input-full"
|
||||
[placeholder]="t('passwordPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label for="fromAddress" class="form-label">
|
||||
<i class="pi pi-at label-icon"></i>
|
||||
{{ t('fromAddress') }}
|
||||
</label>
|
||||
<input
|
||||
id="fromAddress"
|
||||
type="text"
|
||||
pInputText
|
||||
formControlName="fromAddress"
|
||||
class="input-full"
|
||||
[placeholder]="t('fromAddressPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-group highlight-group checkbox-group">
|
||||
<div class="checkbox-row">
|
||||
<p-checkbox formControlName="auth" [binary]="true" inputId="auth"></p-checkbox>
|
||||
<label for="auth" class="checkbox-label">
|
||||
<span class="checkbox-title">{{ t('enableAuth') }}</span>
|
||||
<span class="checkbox-description">{{ t('enableAuthDesc') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group highlight-group checkbox-group">
|
||||
<div class="checkbox-row">
|
||||
<p-checkbox formControlName="startTls" [binary]="true" inputId="startTls"></p-checkbox>
|
||||
<label for="startTls" class="checkbox-label">
|
||||
<span class="checkbox-title">{{ t('enableStartTls') }}</span>
|
||||
<span class="checkbox-description">{{ t('enableStartTlsDesc') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="validation-status">
|
||||
@if (emailProviderForm.invalid) {
|
||||
<div class="validation-message error">
|
||||
<i class="pi pi-exclamation-circle"></i>
|
||||
<span>{{ t('requiredFieldsError') }}</span>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="validation-message success">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<span>{{ t('readyToCreate') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(onClick)="closeDialog()"
|
||||
type="button"
|
||||
/>
|
||||
<p-button
|
||||
[label]="t('createBtn')"
|
||||
icon="pi pi-plus"
|
||||
severity="success"
|
||||
type="submit"
|
||||
[disabled]="emailProviderForm.invalid"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</ng-container>
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.email-provider-form {
|
||||
padding: 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.email-provider-creator {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 600px;
|
||||
|
||||
@media (max-width: 640px) {
|
||||
min-width: auto;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
}
|
||||
|
||||
.form-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 1.5rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
&.highlight-group {
|
||||
padding: 0.875rem;
|
||||
}
|
||||
|
||||
&.checkbox-group {
|
||||
padding: 0.75rem 0.875rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
gap: 0.375rem;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
&.highlight-group {
|
||||
padding: 0.625rem;
|
||||
}
|
||||
|
||||
&.checkbox-group {
|
||||
padding: 0.5rem 0.625rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
|
||||
.label-icon {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.required-indicator {
|
||||
color: var(--p-red-500);
|
||||
margin-left: 0.125rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.form-input {
|
||||
width: 100%;
|
||||
max-width: 20rem;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
position: relative;
|
||||
|
||||
.input-full {
|
||||
width: 100%;
|
||||
padding-right: 2.5rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.input-icon {
|
||||
position: absolute;
|
||||
right: 0.75rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
font-size: 1rem;
|
||||
pointer-events: none;
|
||||
|
||||
&.success {
|
||||
color: var(--p-green-500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.input-full {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.form-error {
|
||||
color: #ef4444;
|
||||
padding-left: 10rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.field-error {
|
||||
color: #ef4444;
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.25rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
|
||||
&::before {
|
||||
content: '⚠';
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.checkbox-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.125rem;
|
||||
cursor: pointer;
|
||||
flex: 1;
|
||||
|
||||
.checkbox-title {
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.checkbox-description {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
gap: 0.5rem;
|
||||
|
||||
.checkbox-label {
|
||||
.checkbox-title {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.checkbox-description {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.gradient-divider {
|
||||
height: 1px;
|
||||
background: linear-gradient(
|
||||
to right,
|
||||
transparent,
|
||||
var(--border-color) 20%,
|
||||
var(--border-color) 80%,
|
||||
transparent
|
||||
);
|
||||
margin: 1.25rem 0;
|
||||
|
||||
@media (max-width: 480px) {
|
||||
margin: 1rem 0;
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
@include panel.dialog-footer;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.validation-message {
|
||||
@include panel.validation-message;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
|
||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {EmailV2ProviderService} from '../email-v2-provider/email-v2-provider.service';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-email-provider-dialog',
|
||||
imports: [
|
||||
Button,
|
||||
Checkbox,
|
||||
InputText,
|
||||
ReactiveFormsModule,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
],
|
||||
templateUrl: './create-email-provider-dialog.component.html',
|
||||
styleUrl: './create-email-provider-dialog.component.scss'
|
||||
})
|
||||
export class CreateEmailProviderDialogComponent implements OnInit {
|
||||
emailProviderForm!: FormGroup;
|
||||
|
||||
private fb = inject(FormBuilder);
|
||||
private emailProviderService = inject(EmailV2ProviderService);
|
||||
private messageService = inject(MessageService);
|
||||
private ref = inject(DynamicDialogRef);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
ngOnInit() {
|
||||
this.emailProviderForm = this.fb.group({
|
||||
name: ['', [Validators.required, Validators.minLength(3)]],
|
||||
host: ['', Validators.required],
|
||||
port: [null, [Validators.required, Validators.min(1)]],
|
||||
username: [''],
|
||||
password: [''],
|
||||
fromAddress: ['', [Validators.email]],
|
||||
auth: [false],
|
||||
startTls: [false]
|
||||
});
|
||||
}
|
||||
|
||||
createEmailProvider() {
|
||||
if (this.emailProviderForm.invalid) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('settingsEmail.provider.create.validationError'),
|
||||
detail: this.t.translate('settingsEmail.provider.create.validationErrorDetail')
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const emailProviderData = this.emailProviderForm.value;
|
||||
|
||||
this.emailProviderService.createEmailProvider(emailProviderData).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsEmail.provider.create.success'),
|
||||
detail: this.t.translate('settingsEmail.provider.create.successDetail')
|
||||
});
|
||||
this.ref.close(true);
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsEmail.provider.create.failed'),
|
||||
detail: err?.error?.message
|
||||
? this.t.translate('settingsEmail.provider.create.failedDetail', {message: err.error.message})
|
||||
: this.t.translate('settingsEmail.provider.create.failedDefault')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
this.ref.close();
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsEmail.recipient.create'">
|
||||
<div class="email-recipient-creator">
|
||||
<div class="panel-header">
|
||||
<div class="header-icon-wrapper">
|
||||
<i class="pi pi-user header-icon"></i>
|
||||
</div>
|
||||
<div class="header-text">
|
||||
<h2 class="panel-title">{{ t('title') }}</h2>
|
||||
<p class="panel-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
(click)="closeDialog()"
|
||||
severity="secondary"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
class="close-button"
|
||||
[pTooltip]="'common.close' | transloco"
|
||||
tooltipPosition="left"/>
|
||||
</div>
|
||||
|
||||
<form [formGroup]="emailRecipientForm" (ngSubmit)="createEmailRecipient()">
|
||||
<div class="form-container">
|
||||
<div class="form-group highlight-group">
|
||||
<label for="recipientName" class="form-label">
|
||||
<i class="pi pi-user label-icon"></i>
|
||||
{{ t('recipientName') }}
|
||||
<span class="required-indicator">*</span>
|
||||
</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
id="recipientName"
|
||||
type="text"
|
||||
pInputText
|
||||
formControlName="name"
|
||||
class="input-full"
|
||||
[placeholder]="t('recipientNamePlaceholder')"
|
||||
[class.filled]="emailRecipientForm.get('name')?.value"
|
||||
|
||||
/>
|
||||
@if (emailRecipientForm.get('name')?.value && emailRecipientForm.get('name')?.valid) {
|
||||
<i class="pi pi-check-circle input-icon success"></i>
|
||||
}
|
||||
</div>
|
||||
@if (emailRecipientForm.get('name')?.invalid && (emailRecipientForm.get('name')?.dirty || emailRecipientForm.get('name')?.touched)) {
|
||||
<small class="field-error">{{ t('recipientNameRequired') }}</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-group highlight-group">
|
||||
<label for="email" class="form-label">
|
||||
<i class="pi pi-at label-icon"></i>
|
||||
{{ t('emailAddress') }}
|
||||
<span class="required-indicator">*</span>
|
||||
</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
id="email"
|
||||
type="email"
|
||||
pInputText
|
||||
formControlName="email"
|
||||
class="input-full"
|
||||
[placeholder]="t('emailAddressPlaceholder')"
|
||||
[class.filled]="emailRecipientForm.get('email')?.value"
|
||||
/>
|
||||
@if (emailRecipientForm.get('email')?.value && emailRecipientForm.get('email')?.valid) {
|
||||
<i class="pi pi-check-circle input-icon success"></i>
|
||||
}
|
||||
</div>
|
||||
@if (emailRecipientForm.get('email')?.invalid && (emailRecipientForm.get('email')?.dirty || emailRecipientForm.get('email')?.touched)) {
|
||||
<small class="field-error">{{ t('emailRequired') }}</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="gradient-divider"></div>
|
||||
|
||||
<div class="form-group highlight-group checkbox-group">
|
||||
<div class="checkbox-row">
|
||||
<p-checkbox formControlName="defaultRecipient" [binary]="true" inputId="defaultRecipient"></p-checkbox>
|
||||
<label for="defaultRecipient" class="checkbox-label">
|
||||
<span class="checkbox-title">{{ t('defaultRecipient') }}</span>
|
||||
<span class="checkbox-description">{{ t('defaultRecipientDesc') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="validation-status">
|
||||
@if (emailRecipientForm.invalid) {
|
||||
<div class="validation-message error">
|
||||
<i class="pi pi-exclamation-circle"></i>
|
||||
<span>{{ t('requiredFieldsError') }}</span>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="validation-message success">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<span>{{ t('readyToAdd') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="footer-actions">
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(onClick)="closeDialog()"
|
||||
type="button"
|
||||
/>
|
||||
<p-button
|
||||
[label]="t('addBtn')"
|
||||
icon="pi pi-plus"
|
||||
severity="success"
|
||||
type="submit"
|
||||
[disabled]="emailRecipientForm.invalid"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</ng-container>
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
@use '../../../../shared/styles/panel-shared' as panel;
|
||||
|
||||
.email-recipient-creator {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 600px;
|
||||
|
||||
@media (max-width: 640px) {
|
||||
min-width: auto;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
@include panel.panel-header;
|
||||
}
|
||||
|
||||
.form-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 1.5rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-top: none;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
|
||||
@media (max-width: 480px) {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
&.highlight-group {
|
||||
padding: 0.875rem;
|
||||
}
|
||||
|
||||
&.checkbox-group {
|
||||
padding: 0.75rem 0.875rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
gap: 0.375rem;
|
||||
|
||||
&.highlight-group {
|
||||
padding: 0.625rem;
|
||||
}
|
||||
|
||||
&.checkbox-group {
|
||||
padding: 0.5rem 0.625rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
|
||||
.label-icon {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
.required-indicator {
|
||||
color: var(--p-red-500);
|
||||
margin-left: 0.125rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
position: relative;
|
||||
|
||||
.input-full {
|
||||
width: 100%;
|
||||
padding-right: 2.5rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.input-icon {
|
||||
position: absolute;
|
||||
right: 0.75rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
font-size: 1rem;
|
||||
pointer-events: none;
|
||||
|
||||
&.success {
|
||||
color: var(--p-green-500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.input-full {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.field-error {
|
||||
color: #ef4444;
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.25rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
|
||||
&::before {
|
||||
content: '⚠';
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.checkbox-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.125rem;
|
||||
cursor: pointer;
|
||||
flex: 1;
|
||||
|
||||
.checkbox-title {
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.checkbox-description {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
gap: 0.5rem;
|
||||
|
||||
.checkbox-label {
|
||||
.checkbox-title {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.checkbox-description {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.gradient-divider {
|
||||
height: 1px;
|
||||
background: linear-gradient(
|
||||
to right,
|
||||
transparent,
|
||||
var(--border-color) 20%,
|
||||
var(--border-color) 80%,
|
||||
transparent
|
||||
);
|
||||
margin: 1.25rem 0;
|
||||
|
||||
@media (max-width: 480px) {
|
||||
margin: 1rem 0;
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
@include panel.dialog-footer;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.validation-message {
|
||||
@include panel.validation-message;
|
||||
}
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {EmailV2RecipientService} from '../email-v2-recipient/email-v2-recipient.service';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-email-recipient-dialog',
|
||||
imports: [
|
||||
Checkbox,
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
InputText,
|
||||
Tooltip,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
],
|
||||
templateUrl: './create-email-recipient-dialog.component.html',
|
||||
styleUrls: ['./create-email-recipient-dialog.component.scss']
|
||||
})
|
||||
export class CreateEmailRecipientDialogComponent {
|
||||
emailRecipientForm: FormGroup;
|
||||
private fb = inject(FormBuilder);
|
||||
private emailRecipientService = inject(EmailV2RecipientService);
|
||||
private messageService = inject(MessageService);
|
||||
private ref = inject(DynamicDialogRef);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
constructor() {
|
||||
this.emailRecipientForm = this.fb.group({
|
||||
name: ['', Validators.required],
|
||||
email: ['', [Validators.required, Validators.email]],
|
||||
defaultRecipient: [false]
|
||||
});
|
||||
}
|
||||
|
||||
closeDialog(): void {
|
||||
this.ref.close();
|
||||
}
|
||||
|
||||
createEmailRecipient(): void {
|
||||
if (this.emailRecipientForm.invalid) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: this.t.translate('settingsEmail.recipient.create.validationError'),
|
||||
detail: this.t.translate('settingsEmail.recipient.create.validationErrorDetail')
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const emailRecipientData = this.emailRecipientForm.value;
|
||||
|
||||
this.emailRecipientService.createRecipient(emailRecipientData).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsEmail.recipient.create.success'),
|
||||
detail: this.t.translate('settingsEmail.recipient.create.successDetail', {name: emailRecipientData.name})
|
||||
});
|
||||
this.ref.close(true);
|
||||
},
|
||||
error: (err) => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsEmail.recipient.create.failed'),
|
||||
detail: err?.error?.message
|
||||
? this.t.translate('settingsEmail.recipient.create.failedDetail', {message: err.error.message})
|
||||
: this.t.translate('settingsEmail.recipient.create.failedDefault')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export interface EmailProvider {
|
||||
isEditing: boolean;
|
||||
id: number;
|
||||
userId: number;
|
||||
name: string;
|
||||
host: string;
|
||||
port: number;
|
||||
username: string;
|
||||
password: string;
|
||||
fromAddress: string;
|
||||
auth: boolean;
|
||||
startTls: boolean;
|
||||
defaultProvider: boolean;
|
||||
shared: boolean;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export interface EmailRecipient {
|
||||
id: number;
|
||||
email: string;
|
||||
name: string;
|
||||
defaultRecipient: boolean;
|
||||
isEditing: boolean;
|
||||
}
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsEmail.provider'">
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<div class="section-header-row">
|
||||
<div class="section-header-text">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-server"></i>
|
||||
{{ t('title') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-plus"
|
||||
[label]="t('addProvider')"
|
||||
severity="success"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
(onClick)="openCreateProviderDialog()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
@if (emailProviders.length === 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-envelope"></i>
|
||||
<p class="empty-title">{{ t('emptyTitle') }}</p>
|
||||
<p class="empty-subtitle">{{ t('emptySubtitle') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="providers-list">
|
||||
@for (provider of emailProviders; track provider.id) {
|
||||
<div class="provider-item" [class.is-default]="provider.id === defaultProviderId">
|
||||
<div class="provider-header">
|
||||
<div class="provider-info">
|
||||
<div class="provider-name-row">
|
||||
<p-radioButton
|
||||
name="defaultProvider"
|
||||
[value]="provider.id"
|
||||
[(ngModel)]="defaultProviderId"
|
||||
(onClick)="setDefaultProvider(provider)">
|
||||
</p-radioButton>
|
||||
@if (provider.isEditing) {
|
||||
<input type="text" pInputText [(ngModel)]="provider.name" [placeholder]="t('providerNamePlaceholder')" class="name-input"/>
|
||||
} @else {
|
||||
<span class="provider-name">{{ provider.name }}</span>
|
||||
@if (provider.shared) {
|
||||
<span class="shared-badge" [pTooltip]="t('sharedTooltip')">
|
||||
<i class="pi pi-share-alt"></i>
|
||||
</span>
|
||||
}
|
||||
@if (provider.id === defaultProviderId) {
|
||||
<span class="default-badge">{{ t('default') }}</span>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="provider-actions">
|
||||
@if (!provider.isEditing) {
|
||||
<p-button
|
||||
[icon]="canModifyProvider(provider) ? 'pi pi-pencil' : 'pi pi-lock'"
|
||||
[severity]="canModifyProvider(provider) ? 'info' : 'secondary'"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
[disabled]="!canModifyProvider(provider)"
|
||||
(onClick)="canModifyProvider(provider) && toggleEdit(provider)"
|
||||
[pTooltip]="canModifyProvider(provider) ? t('editProvider') : t('cannotEditShared')"
|
||||
tooltipPosition="left">
|
||||
</p-button>
|
||||
<p-button
|
||||
[icon]="canModifyProvider(provider) ? 'pi pi-trash' : 'pi pi-lock'"
|
||||
[severity]="canModifyProvider(provider) ? 'danger' : 'secondary'"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
[disabled]="!canModifyProvider(provider)"
|
||||
(onClick)="canModifyProvider(provider) && deleteProvider(provider)"
|
||||
[pTooltip]="canModifyProvider(provider) ? t('deleteProvider') : t('cannotDeleteShared')"
|
||||
tooltipPosition="left">
|
||||
</p-button>
|
||||
} @else {
|
||||
<p-button
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="saveProvider(provider)"
|
||||
[pTooltip]="t('saveChanges')">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="toggleEdit(provider)"
|
||||
[pTooltip]="'common.cancel' | transloco">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="provider-details">
|
||||
<div class="detail-grid">
|
||||
<div class="detail-item">
|
||||
<label class="detail-label">
|
||||
<i class="pi pi-server"></i>
|
||||
{{ t('host') }}
|
||||
</label>
|
||||
@if (provider.isEditing) {
|
||||
<input type="text" pInputText [(ngModel)]="provider.host" [placeholder]="t('hostPlaceholder')"/>
|
||||
} @else {
|
||||
<span class="detail-value">{{ provider.host }}</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="detail-item">
|
||||
<label class="detail-label">
|
||||
<i class="pi pi-link"></i>
|
||||
{{ t('port') }}
|
||||
</label>
|
||||
@if (provider.isEditing) {
|
||||
<input type="number" pInputText [(ngModel)]="provider.port" [placeholder]="t('portPlaceholder')"/>
|
||||
} @else {
|
||||
<span class="detail-value">{{ provider.port }}</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="detail-item">
|
||||
<label class="detail-label">
|
||||
<i class="pi pi-user"></i>
|
||||
{{ t('username') }}
|
||||
</label>
|
||||
@if (provider.isEditing) {
|
||||
<input type="text" pInputText [(ngModel)]="provider.username" [placeholder]="t('usernamePlaceholder')"/>
|
||||
} @else {
|
||||
<span class="detail-value">{{ provider.username }}</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="detail-item">
|
||||
<label class="detail-label">
|
||||
<i class="pi pi-lock"></i>
|
||||
{{ t('password') }}
|
||||
</label>
|
||||
@if (provider.isEditing) {
|
||||
<input type="password" pInputText [(ngModel)]="provider.password" [placeholder]="t('passwordPlaceholder')"/>
|
||||
} @else {
|
||||
<span class="detail-value password-hidden">********</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="detail-item detail-item-wide">
|
||||
<label class="detail-label">
|
||||
<i class="pi pi-envelope"></i>
|
||||
{{ t('fromAddress') }}
|
||||
</label>
|
||||
@if (provider.isEditing) {
|
||||
<input type="email" pInputText [(ngModel)]="provider.fromAddress" [placeholder]="t('fromAddressPlaceholder')"/>
|
||||
} @else {
|
||||
<span class="detail-value">{{ provider.fromAddress }}</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toggle-options">
|
||||
<div class="toggle-item">
|
||||
<p-checkbox
|
||||
[(ngModel)]="provider.auth"
|
||||
[binary]="true"
|
||||
[disabled]="!provider.isEditing"
|
||||
inputId="auth-{{provider.id}}">
|
||||
</p-checkbox>
|
||||
<label [for]="'auth-' + provider.id" class="toggle-label">{{ t('authentication') }}</label>
|
||||
</div>
|
||||
|
||||
<div class="toggle-item">
|
||||
<p-checkbox
|
||||
[(ngModel)]="provider.startTls"
|
||||
[binary]="true"
|
||||
[disabled]="!provider.isEditing"
|
||||
inputId="starttls-{{provider.id}}">
|
||||
</p-checkbox>
|
||||
<label [for]="'starttls-' + provider.id" class="toggle-label">{{ t('startTls') }}</label>
|
||||
</div>
|
||||
|
||||
@if (isAdmin) {
|
||||
<div class="toggle-item">
|
||||
<p-checkbox
|
||||
[(ngModel)]="provider.shared"
|
||||
[binary]="true"
|
||||
(onChange)="toggleShared(provider)"
|
||||
inputId="shared-{{provider.id}}"
|
||||
[pTooltip]="t('shareTooltip')">
|
||||
</p-checkbox>
|
||||
<label [for]="'shared-' + provider.id" class="toggle-label">{{ t('shared') }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+256
@@ -0,0 +1,256 @@
|
||||
@use '../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
}
|
||||
|
||||
.section-header-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
p-button {
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.section-header-text {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
// Empty state
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 2rem;
|
||||
text-align: center;
|
||||
color: var(--p-text-muted-color);
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border-radius: 6px;
|
||||
|
||||
.pi {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 1rem;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
margin: 0 0 0.5rem 0;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.empty-subtitle {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Provider list
|
||||
.providers-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.provider-item {
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-left: 3px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
padding: 1rem;
|
||||
transition: border-color 0.2s ease, background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
|
||||
}
|
||||
|
||||
&.is-default {
|
||||
border-left-color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.provider-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
padding-bottom: 0.75rem;
|
||||
border-bottom: 1px dashed var(--p-content-border-color);
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.provider-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.provider-name-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.provider-name {
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.name-input {
|
||||
width: 200px;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.shared-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
background: color-mix(in srgb, var(--p-green-600) 20%, transparent);
|
||||
color: var(--p-green-400);
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
|
||||
.pi {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.default-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.125rem 0.5rem;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.provider-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
// Provider details grid
|
||||
.provider-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.detail-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.detail-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.375rem;
|
||||
|
||||
&.detail-item-wide {
|
||||
grid-column: span 2;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
grid-column: span 1;
|
||||
}
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.detail-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: settings.$settings-description-size;
|
||||
font-weight: 500;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
.pi {
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.detail-value {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
color: var(--p-text-color);
|
||||
word-break: break-word;
|
||||
|
||||
&.password-hidden {
|
||||
color: var(--p-text-muted-color);
|
||||
font-style: italic;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle options
|
||||
.toggle-options {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 1.5rem;
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px dashed var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.toggle-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.toggle-label {
|
||||
font-size: settings.$settings-description-size;
|
||||
color: var(--p-text-color);
|
||||
cursor: pointer;
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {EmailV2ProviderService} from './email-v2-provider.service';
|
||||
import {EmailProvider} from '../email-provider.model';
|
||||
import {UserService} from '../../user-management/user.service';
|
||||
import {DialogLauncherService} from '../../../../shared/services/dialog-launcher.service';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-email-v2-provider',
|
||||
imports: [
|
||||
Button,
|
||||
Checkbox,
|
||||
RadioButton,
|
||||
ReactiveFormsModule,
|
||||
TableModule,
|
||||
Tooltip,
|
||||
FormsModule,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
],
|
||||
templateUrl: './email-v2-provider.component.html',
|
||||
styleUrl: './email-v2-provider.component.scss'
|
||||
})
|
||||
export class EmailV2ProviderComponent implements OnInit {
|
||||
emailProviders: EmailProvider[] = [];
|
||||
editingProviderIds: number[] = [];
|
||||
ref: DynamicDialogRef | undefined | null;
|
||||
private dialogLauncherService = inject(DialogLauncherService);
|
||||
private emailProvidersService = inject(EmailV2ProviderService);
|
||||
private messageService = inject(MessageService);
|
||||
private userService = inject(UserService);
|
||||
private t = inject(TranslocoService);
|
||||
defaultProviderId: unknown;
|
||||
currentUserId: number | null = null;
|
||||
isAdmin: boolean = false;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadCurrentUser();
|
||||
this.loadEmailProviders();
|
||||
}
|
||||
|
||||
loadCurrentUser(): void {
|
||||
const currentUser = this.userService.getCurrentUser();
|
||||
this.currentUserId = currentUser?.id ?? null;
|
||||
this.isAdmin = currentUser?.permissions.admin ?? false;
|
||||
}
|
||||
|
||||
loadEmailProviders(): void {
|
||||
this.emailProvidersService.getEmailProviders().subscribe({
|
||||
next: (emailProviders: EmailProvider[]) => {
|
||||
this.emailProviders = emailProviders.map((provider) => ({
|
||||
...provider,
|
||||
isEditing: false,
|
||||
}));
|
||||
const defaultProvider = emailProviders.find((provider) => provider.defaultProvider);
|
||||
this.defaultProviderId = defaultProvider ? defaultProvider.id : null;
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsEmail.provider.loadError'),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
toggleEdit(provider: EmailProvider): void {
|
||||
provider.isEditing = !provider.isEditing;
|
||||
if (provider.isEditing) {
|
||||
this.editingProviderIds.push(provider.id);
|
||||
} else {
|
||||
this.editingProviderIds = this.editingProviderIds.filter((id) => id !== provider.id);
|
||||
}
|
||||
}
|
||||
|
||||
saveProvider(provider: EmailProvider): void {
|
||||
this.emailProvidersService.updateProvider(provider).subscribe({
|
||||
next: () => {
|
||||
provider.isEditing = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('settingsEmail.provider.updateSuccess'),
|
||||
});
|
||||
this.loadEmailProviders();
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsEmail.provider.updateError'),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
deleteProvider(provider: EmailProvider): void {
|
||||
if (confirm(this.t.translate('settingsEmail.provider.deleteConfirm', {name: provider.name}))) {
|
||||
this.emailProvidersService.deleteProvider(provider.id).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('settingsEmail.provider.deleteSuccess', {name: provider.name}),
|
||||
});
|
||||
this.loadEmailProviders();
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsEmail.provider.deleteError'),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
openCreateProviderDialog() {
|
||||
this.ref = this.dialogLauncherService.openEmailProviderDialog();
|
||||
this.ref?.onClose.subscribe((result) => {
|
||||
if (result) {
|
||||
this.loadEmailProviders();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setDefaultProvider(provider: EmailProvider) {
|
||||
this.emailProvidersService.setDefaultProvider(provider.id).subscribe({
|
||||
next: () => {
|
||||
this.defaultProviderId = provider.id;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsEmail.provider.defaultSetSummary'),
|
||||
detail: this.t.translate('settingsEmail.provider.defaultSetDetail', {name: provider.name}),
|
||||
});
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Failed to set default provider', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsEmail.provider.defaultSetError', {name: provider.name}),
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
canModifyProvider(provider: EmailProvider): boolean {
|
||||
return !provider.shared || provider.userId === this.currentUserId;
|
||||
}
|
||||
|
||||
toggleShared(provider: EmailProvider): void {
|
||||
this.emailProvidersService.updateProvider(provider).subscribe({
|
||||
next: () => {
|
||||
const status = this.t.translate(provider.shared ? 'settingsEmail.provider.sharedStatusOn' : 'settingsEmail.provider.sharedStatusOff');
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('settingsEmail.provider.sharedSuccess', {name: provider.name, status}),
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
provider.shared = !provider.shared;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsEmail.provider.sharedError'),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../core/config/api-config';
|
||||
import {EmailProvider} from '../email-provider.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class EmailV2ProviderService {
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/email/providers`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getEmailProviders(): Observable<EmailProvider[]> {
|
||||
return this.http.get<EmailProvider[]>(this.url);
|
||||
}
|
||||
|
||||
createEmailProvider(provider: EmailProvider): Observable<EmailProvider> {
|
||||
return this.http.post<EmailProvider>(this.url, provider);
|
||||
}
|
||||
|
||||
updateProvider(provider: EmailProvider): Observable<EmailProvider> {
|
||||
return this.http.put<EmailProvider>(`${this.url}/${provider.id}`, provider);
|
||||
}
|
||||
|
||||
deleteProvider(id: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.url}/${id}`);
|
||||
}
|
||||
|
||||
setDefaultProvider(id: number): Observable<void> {
|
||||
return this.http.patch<void>(`${this.url}/${id}/set-default`, {});
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsEmail.recipient'">
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<div class="section-header-row">
|
||||
<div class="section-header-text">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-users"></i>
|
||||
{{ t('title') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-plus"
|
||||
[label]="t('addRecipient')"
|
||||
severity="success"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
(onClick)="openAddRecipientDialog()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
@if (recipientEmails.length === 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-users"></i>
|
||||
<p class="empty-title">{{ t('emptyTitle') }}</p>
|
||||
<p class="empty-subtitle">{{ t('emptySubtitle') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="recipients-list">
|
||||
@for (recipient of recipientEmails; track recipient.id) {
|
||||
<div class="recipient-item" [class.is-default]="recipient.id === defaultRecipientId">
|
||||
<div class="recipient-content">
|
||||
<div class="recipient-select">
|
||||
<p-radioButton
|
||||
name="defaultRecipient"
|
||||
[value]="recipient.id"
|
||||
[(ngModel)]="defaultRecipientId"
|
||||
(onClick)="setDefaultRecipient(recipient)">
|
||||
</p-radioButton>
|
||||
</div>
|
||||
|
||||
<div class="recipient-info">
|
||||
@if (recipient.isEditing) {
|
||||
<div class="edit-form">
|
||||
<div class="form-field">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-envelope"></i>
|
||||
{{ t('email') }}
|
||||
</label>
|
||||
<input type="email" pInputText [(ngModel)]="recipient.email" [placeholder]="t('emailPlaceholder')"/>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label class="field-label">
|
||||
<i class="pi pi-user"></i>
|
||||
{{ t('name') }}
|
||||
</label>
|
||||
<input type="text" pInputText [(ngModel)]="recipient.name" [placeholder]="t('namePlaceholder')"/>
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="recipient-details">
|
||||
<div class="recipient-email">
|
||||
<i class="pi pi-envelope"></i>
|
||||
<span>{{ recipient.email }}</span>
|
||||
@if (recipient.id === defaultRecipientId) {
|
||||
<span class="default-badge">{{ t('default') }}</span>
|
||||
}
|
||||
</div>
|
||||
@if (recipient.name) {
|
||||
<div class="recipient-name">
|
||||
<i class="pi pi-user"></i>
|
||||
<span>{{ recipient.name }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="recipient-actions">
|
||||
@if (!recipient.isEditing) {
|
||||
<p-button
|
||||
icon="pi pi-pencil"
|
||||
severity="info"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="toggleEditRecipient(recipient)"
|
||||
[pTooltip]="t('editRecipient')">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
severity="danger"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="deleteRecipient(recipient)"
|
||||
[pTooltip]="t('deleteRecipient')">
|
||||
</p-button>
|
||||
} @else {
|
||||
<p-button
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="saveRecipient(recipient)"
|
||||
[pTooltip]="t('saveChanges')">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="toggleEditRecipient(recipient)"
|
||||
[pTooltip]="'common.cancel' | transloco">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+213
@@ -0,0 +1,213 @@
|
||||
@use '../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
}
|
||||
|
||||
.section-header-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
p-button {
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.section-header-text {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
// Empty state
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 2rem;
|
||||
text-align: center;
|
||||
color: var(--p-text-muted-color);
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border-radius: 6px;
|
||||
|
||||
.pi {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 1rem;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
margin: 0 0 0.5rem 0;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.empty-subtitle {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Recipients list
|
||||
.recipients-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.recipient-item {
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-left: 3px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
padding: 0.875rem 1rem;
|
||||
transition: border-color 0.2s ease, background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
|
||||
}
|
||||
|
||||
&.is-default {
|
||||
border-left-color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.recipient-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.recipient-select {
|
||||
flex-shrink: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
align-self: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.recipient-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.recipient-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.recipient-email {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-weight: 500;
|
||||
color: var(--p-text-color);
|
||||
|
||||
.pi {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.recipient-name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: settings.$settings-description-size;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
.pi {
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
}
|
||||
|
||||
.default-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.125rem 0.5rem;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
border-radius: 4px;
|
||||
font-size: 0.7rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
// Edit form
|
||||
.edit-form {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.form-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
flex: 1;
|
||||
min-width: 180px;
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.field-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: settings.$settings-description-size;
|
||||
font-weight: 500;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
.pi {
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.recipient-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {EmailV2RecipientService} from './email-v2-recipient.service';
|
||||
import {EmailRecipient} from '../email-recipient.model';
|
||||
import {DialogLauncherService} from '../../../../shared/services/dialog-launcher.service';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-email-v2-recipient',
|
||||
imports: [
|
||||
Button,
|
||||
RadioButton,
|
||||
ReactiveFormsModule,
|
||||
TableModule,
|
||||
Tooltip,
|
||||
FormsModule,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
],
|
||||
templateUrl: './email-v2-recipient.component.html',
|
||||
styleUrl: './email-v2-recipient.component.scss'
|
||||
})
|
||||
export class EmailV2RecipientComponent implements OnInit {
|
||||
recipientEmails: EmailRecipient[] = [];
|
||||
editingRecipientIds: number[] = [];
|
||||
ref: DynamicDialogRef | undefined | null;
|
||||
private dialogLauncherService = inject(DialogLauncherService);
|
||||
private emailRecipientService = inject(EmailV2RecipientService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
defaultRecipientId: unknown;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadRecipientEmails();
|
||||
}
|
||||
|
||||
loadRecipientEmails(): void {
|
||||
this.emailRecipientService.getRecipients().subscribe({
|
||||
next: (recipients: EmailRecipient[]) => {
|
||||
this.recipientEmails = recipients.map((recipient) => ({
|
||||
...recipient,
|
||||
isEditing: false,
|
||||
}));
|
||||
const defaultRecipient = recipients.find((recipient) => recipient.defaultRecipient);
|
||||
this.defaultRecipientId = defaultRecipient ? defaultRecipient.id : null;
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsEmail.recipient.loadError'),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
toggleEditRecipient(recipient: EmailRecipient): void {
|
||||
recipient.isEditing = !recipient.isEditing;
|
||||
if (recipient.isEditing) {
|
||||
this.editingRecipientIds.push(recipient.id);
|
||||
} else {
|
||||
this.editingRecipientIds = this.editingRecipientIds.filter((id) => id !== recipient.id);
|
||||
}
|
||||
}
|
||||
|
||||
saveRecipient(recipient: EmailRecipient): void {
|
||||
this.emailRecipientService.updateRecipient(recipient).subscribe({
|
||||
next: () => {
|
||||
recipient.isEditing = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('settingsEmail.recipient.updateSuccess'),
|
||||
});
|
||||
this.loadRecipientEmails();
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsEmail.recipient.updateError'),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
deleteRecipient(recipient: EmailRecipient): void {
|
||||
if (confirm(this.t.translate('settingsEmail.recipient.deleteConfirm', {email: recipient.email}))) {
|
||||
this.emailRecipientService.deleteRecipient(recipient.id).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('settingsEmail.recipient.deleteSuccess', {email: recipient.email}),
|
||||
});
|
||||
this.loadRecipientEmails();
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsEmail.recipient.deleteError'),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
openAddRecipientDialog() {
|
||||
this.ref = this.dialogLauncherService.openEmailRecipientDialog();
|
||||
this.ref?.onClose.subscribe((result) => {
|
||||
if (result) {
|
||||
this.loadRecipientEmails();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setDefaultRecipient(recipient: EmailRecipient) {
|
||||
this.emailRecipientService.setDefaultRecipient(recipient.id).subscribe(() => {
|
||||
this.defaultRecipientId = recipient.id;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsEmail.recipient.defaultSetSummary'),
|
||||
detail: this.t.translate('settingsEmail.recipient.defaultSetDetail', {email: recipient.email}),
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { API_CONFIG } from '../../../../core/config/api-config';
|
||||
import {EmailRecipient} from '../email-recipient.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class EmailV2RecipientService {
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/email/recipients`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getRecipients(): Observable<EmailRecipient[]> {
|
||||
return this.http.get<EmailRecipient[]>(this.url);
|
||||
}
|
||||
|
||||
createRecipient(recipient: EmailRecipient): Observable<EmailRecipient> {
|
||||
return this.http.post<EmailRecipient>(this.url, recipient);
|
||||
}
|
||||
|
||||
updateRecipient(recipient: EmailRecipient): Observable<EmailRecipient> {
|
||||
return this.http.put<EmailRecipient>(`${this.url}/${recipient.id}`, recipient);
|
||||
}
|
||||
|
||||
deleteRecipient(id: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.url}/${id}`);
|
||||
}
|
||||
|
||||
setDefaultRecipient(id: number): Observable<void> {
|
||||
return this.http.patch<void>(`${this.url}/${id}/set-default`, {});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsEmail'">
|
||||
<div class="email-settings-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-envelope"></i>
|
||||
{{ t('title') }}
|
||||
<app-external-doc-link docType="email"></app-external-doc-link>
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@if (hasPermission()) {
|
||||
<app-email-v2-provider></app-email-v2-provider>
|
||||
<div class="section-divider"><hr></div>
|
||||
<app-email-v2-recipient></app-email-v2-recipient>
|
||||
} @else {
|
||||
<div class="access-denied-card">
|
||||
<i class="pi pi-lock"></i>
|
||||
<div class="access-denied-content">
|
||||
<h3>{{ t('accessRestricted') }}</h3>
|
||||
<p>
|
||||
{{ t('accessDenied') }}
|
||||
<br>
|
||||
{{ t('contactAdmin') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,51 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.email-settings-container {
|
||||
@include settings.settings-page-container;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
@include settings.settings-section-divider;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.access-denied-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 1.5rem;
|
||||
border-radius: settings.$settings-card-border-radius;
|
||||
background: color-mix(in srgb, var(--ground-background) 85%, var(--p-red-600) 15%);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-left: 3px solid var(--p-red-500);
|
||||
max-width: 500px;
|
||||
|
||||
> .pi {
|
||||
font-size: 1.5rem;
|
||||
flex-shrink: 0;
|
||||
color: var(--p-red-400);
|
||||
}
|
||||
|
||||
.access-denied-content {
|
||||
h3 {
|
||||
margin: 0 0 0.5rem 0;
|
||||
font-size: 1rem;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-red-300);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import {Component, computed, inject} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {EmailV2ProviderComponent} from './email-v2-provider/email-v2-provider.component';
|
||||
import {EmailV2RecipientComponent} from './email-v2-recipient/email-v2-recipient.component';
|
||||
import {ExternalDocLinkComponent} from '../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import {UserService} from '../user-management/user.service';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-email-v2',
|
||||
imports: [
|
||||
FormsModule,
|
||||
TableModule,
|
||||
EmailV2ProviderComponent,
|
||||
EmailV2RecipientComponent,
|
||||
ExternalDocLinkComponent,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './email-v2.component.html',
|
||||
styleUrls: ['./email-v2.component.scss'],
|
||||
})
|
||||
export class EmailV2Component {
|
||||
private userService = inject(UserService);
|
||||
|
||||
readonly hasPermission = computed(() => {
|
||||
const user = this.userService.currentUser();
|
||||
return !!(user?.permissions.canEmailBook || user?.permissions.admin);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class EmailService {
|
||||
|
||||
private readonly apiUrl = `${API_CONFIG.BASE_URL}/api/v1/email`;
|
||||
|
||||
private http = inject(HttpClient);
|
||||
|
||||
emailBook(request: { bookId: number, providerId: number, recipientId: number, bookFileId?: number }): Observable<void> {
|
||||
return this.http.post<void>(`${this.apiUrl}/book`, request);
|
||||
}
|
||||
|
||||
emailBookQuick(bookId: number): Observable<void> {
|
||||
return this.http.post<void>(`${this.apiUrl}/book/${bookId}`, {});
|
||||
}
|
||||
}
|
||||
+436
@@ -0,0 +1,436 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsNaming'">
|
||||
<div class="file-naming-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-file"></i>
|
||||
{{ t('title') }}
|
||||
<app-external-doc-link docType="fileNamePatterns"></app-external-doc-link>
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="warning-notice">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<div>
|
||||
<strong>{{ t('warning.title') }}</strong> {{ t('warning.text') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-bolt"></i>
|
||||
{{ t('defaultPattern.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">{{ t('defaultPattern.sectionDesc') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
<div class="default-pattern-card">
|
||||
<div class="pattern-input-container">
|
||||
<div class="pattern-input-row">
|
||||
<input
|
||||
pInputText
|
||||
id="defaultPattern"
|
||||
[(ngModel)]="defaultPattern"
|
||||
[placeholder]="t('defaultPattern.placeholder')"
|
||||
(input)="onDefaultPatternChange(defaultPattern)"
|
||||
class="pattern-input"/>
|
||||
<p-button
|
||||
[label]="'common.save' | transloco"
|
||||
icon="pi pi-save"
|
||||
(onClick)="savePatterns()"
|
||||
severity="success"
|
||||
[outlined]="true"
|
||||
[disabled]="!!defaultErrorMessage">
|
||||
</p-button>
|
||||
</div>
|
||||
@if (defaultErrorMessage) {
|
||||
<span class="error-text">{{ defaultErrorMessage }}</span>
|
||||
}
|
||||
<div class="preview-row">
|
||||
<span class="preview-label">
|
||||
<i class="pi pi-eye"></i>
|
||||
{{ t('defaultPattern.preview') }}
|
||||
</span>
|
||||
<code class="preview-value">{{ generateDefaultPreview() }}</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-folder"></i>
|
||||
{{ t('libraryOverrides.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('libraryOverrides.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
@if (libraries.length === 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-folder-open"></i>
|
||||
<p class="empty-title">{{ t('libraryOverrides.emptyTitle') }}</p>
|
||||
<p class="empty-subtitle">{{ t('libraryOverrides.emptySubtitle') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="libraries-list">
|
||||
@for (library of libraries; track library.id) {
|
||||
<div class="library-item" [class.has-pattern]="library.fileNamingPattern">
|
||||
<div class="library-header">
|
||||
<div class="library-info">
|
||||
<div class="library-icon">
|
||||
<i [class]="'pi pi-' + library.icon"></i>
|
||||
</div>
|
||||
<span class="library-name">{{ library.name }}</span>
|
||||
@if (library.fileNamingPattern) {
|
||||
<span class="custom-badge">{{ t('libraryOverrides.custom') }}</span>
|
||||
} @else {
|
||||
<span class="default-badge">{{ t('libraryOverrides.usingDefault') }}</span>
|
||||
}
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="clearLibraryPattern(library)"
|
||||
[disabled]="!library.fileNamingPattern"
|
||||
[pTooltip]="t('libraryOverrides.clearPattern')">
|
||||
</p-button>
|
||||
</div>
|
||||
<div class="library-body">
|
||||
<div class="pattern-input-container">
|
||||
<input
|
||||
pInputText
|
||||
[(ngModel)]="library.fileNamingPattern"
|
||||
[placeholder]="t('libraryOverrides.placeholder')"
|
||||
(input)="onLibraryPatternChange(library)"
|
||||
class="pattern-input"/>
|
||||
<div class="preview-row">
|
||||
<span class="preview-label">
|
||||
<i class="pi pi-eye"></i>
|
||||
{{ t('libraryOverrides.preview') }}
|
||||
</span>
|
||||
<code class="preview-value">{{ generateLibraryPreview(library) }}</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="actions-row">
|
||||
<p-button
|
||||
[label]="t('libraryOverrides.saveAll')"
|
||||
(onClick)="saveLibraryPatterns()"
|
||||
severity="success"
|
||||
icon="pi pi-save"
|
||||
[outlined]="true">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('placeholders.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('placeholders.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
<div class="placeholders-grid">
|
||||
<div class="placeholder-group">
|
||||
<h4 class="group-title">
|
||||
<i class="pi pi-hashtag"></i>
|
||||
{{ t('placeholders.available') }}
|
||||
</h4>
|
||||
<div class="placeholder-list">
|
||||
<div class="placeholder-item"><code>{{ '{title}' }}</code><span>{{ t('placeholders.title') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{subtitle}' }}</code><span>{{ t('placeholders.subtitle') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{authors}' }}</code><span>{{ t('placeholders.authors') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{year}' }}</code><span>{{ t('placeholders.year') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{series}' }}</code><span>{{ t('placeholders.series') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{seriesIndex}' }}</code><span>{{ t('placeholders.seriesIndex') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{language}' }}</code><span>{{ t('placeholders.language') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{publisher}' }}</code><span>{{ t('placeholders.publisher') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{isbn}' }}</code><span>{{ t('placeholders.isbn') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{currentFilename}' }}</code><span>{{ t('placeholders.currentFilename') }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="placeholder-group">
|
||||
<h4 class="group-title">
|
||||
<i class="pi pi-code"></i>
|
||||
{{ t('placeholders.optionalBlocks') }}
|
||||
</h4>
|
||||
<p class="group-description" [innerHTML]="t('placeholders.optionalDesc', { syntax: '{<...>}' })">
|
||||
</p>
|
||||
<div class="example-block">
|
||||
<div class="example-pattern">
|
||||
<span class="pattern-prefix">{{ t('placeholders.pattern') }}</span>
|
||||
<code>{{ '{<{seriesIndex} - >{title}' }}</code>
|
||||
</div>
|
||||
<div class="example-results">
|
||||
<div class="result-item">
|
||||
<span class="result-prefix">{{ t('placeholders.withIndex') }}</span>
|
||||
<code>01 - Dune</code>
|
||||
</div>
|
||||
<div class="result-item">
|
||||
<span class="result-prefix">{{ t('placeholders.without') }}</span>
|
||||
<code>Dune</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="placeholder-group">
|
||||
<h4 class="group-title">
|
||||
<i class="pi pi-replay"></i>
|
||||
{{ t('placeholders.elseClause') }}
|
||||
</h4>
|
||||
<p class="group-description" [innerHTML]="t('placeholders.elseDesc')">
|
||||
</p>
|
||||
<div class="example-block">
|
||||
<div class="example-pattern">
|
||||
<span class="pattern-prefix">{{ t('placeholders.pattern') }}</span>
|
||||
<code>{{ '{<{series}|Standalone>/{title}' }}</code>
|
||||
</div>
|
||||
<div class="example-results">
|
||||
<div class="result-item">
|
||||
<span class="result-prefix">{{ t('placeholders.withSeries') }}</span>
|
||||
<code>The Kingkiller Chronicle/The Name of the Wind</code>
|
||||
</div>
|
||||
<div class="result-item">
|
||||
<span class="result-prefix">{{ t('placeholders.withoutSeries') }}</span>
|
||||
<code>Standalone/The Name of the Wind</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="placeholder-group">
|
||||
<h4 class="group-title">
|
||||
<i class="pi pi-wrench"></i>
|
||||
{{ t('placeholders.modifiers') }}
|
||||
</h4>
|
||||
<p class="group-description" [innerHTML]="t('placeholders.modifiersDesc')">
|
||||
</p>
|
||||
<div class="placeholder-list">
|
||||
<div class="placeholder-item"><code>{{ '{authors:first}' }}</code><span>{{ t('placeholders.modFirst') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{authors:sort}' }}</code><span>{{ t('placeholders.modSort') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{title:initial}' }}</code><span>{{ t('placeholders.modInitial') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{title:upper}' }}</code><span>{{ t('placeholders.modUpper') }}</span></div>
|
||||
<div class="placeholder-item"><code>{{ '{title:lower}' }}</code><span>{{ t('placeholders.modLower') }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-eye"></i>
|
||||
{{ t('examples.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('examples.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
<div class="examples-container">
|
||||
<div class="metadata-reference">
|
||||
<div class="metadata-panel metadata-panel-full">
|
||||
<div class="metadata-panel-header">
|
||||
<i class="pi pi-check-circle metadata-icon-full"></i>
|
||||
<span>{{ t('examples.fullMetadata') }}</span>
|
||||
</div>
|
||||
<div class="metadata-grid">
|
||||
<span class="metadata-key">title</span><code class="metadata-val">The Name of the Wind</code>
|
||||
<span class="metadata-key">subtitle</span><code class="metadata-val">Special Edition</code>
|
||||
<span class="metadata-key">authors</span><code class="metadata-val">Patrick Rothfuss</code>
|
||||
<span class="metadata-key">series</span><code class="metadata-val">The Kingkiller Chronicle</code>
|
||||
<span class="metadata-key">seriesIndex</span><code class="metadata-val">01</code>
|
||||
<span class="metadata-key">year</span><code class="metadata-val">2007</code>
|
||||
</div>
|
||||
</div>
|
||||
<div class="metadata-panel metadata-panel-partial">
|
||||
<div class="metadata-panel-header">
|
||||
<i class="pi pi-question-circle metadata-icon-partial"></i>
|
||||
<span>{{ t('examples.partialMetadata') }}</span>
|
||||
</div>
|
||||
<div class="metadata-grid">
|
||||
<span class="metadata-key">title</span><code class="metadata-val">Project Hail Mary</code>
|
||||
<span class="metadata-key">subtitle</span><em class="metadata-val not-set">{{ t('examples.notSet') }}</em>
|
||||
<span class="metadata-key">authors</span><code class="metadata-val">Andy Weir</code>
|
||||
<span class="metadata-key">year</span><code class="metadata-val">2021</code>
|
||||
<span class="metadata-key">series</span><em class="metadata-val not-set">{{ t('examples.notSet') }}</em>
|
||||
<span class="metadata-key">seriesIndex</span><em class="metadata-val not-set">{{ t('examples.notSet') }}</em>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="example-category">
|
||||
<h4 class="category-title">
|
||||
<i class="pi pi-hashtag"></i>
|
||||
{{ t('examples.basicGroup') }}
|
||||
</h4>
|
||||
<div class="example-grid">
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.basicPattern') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{authors} - {title}' }}</code></span>
|
||||
<span class="result-col"><code>Patrick Rothfuss - The Name of the Wind.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.seriesInFolder') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{authors}/{series}/{seriesIndex} - {title}' }}</code></span>
|
||||
<span class="result-col"><code>Patrick Rothfuss/The Kingkiller Chronicle/01 - The Name of the Wind.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.titleSubtitle') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{title}: {subtitle}' }}</code></span>
|
||||
<span class="result-col"><code>The Name of the Wind: Special Edition.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.absolutePath') }}</span>
|
||||
<span class="pattern-col"><code>{{ '/{authors}/{title}' }}</code></span>
|
||||
<span class="result-col"><code>/Patrick Rothfuss/The Name of the Wind.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.folderOnly') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{title}/' }}</code></span>
|
||||
<span class="result-col"><code>The Name of the Wind/name_of_the_wind_original.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.yearPrefix') }}</span>
|
||||
<span class="pattern-col"><code>{{ '({year}) {title}' }}</code></span>
|
||||
<span class="result-col"><code>(2007) The Name of the Wind.epub</code></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-divider"><hr></div>
|
||||
|
||||
<div class="example-category">
|
||||
<h4 class="category-title">
|
||||
<i class="pi pi-code"></i>
|
||||
{{ t('examples.conditionalGroup') }}
|
||||
</h4>
|
||||
<div class="example-grid">
|
||||
<div class="example-row-conditional">
|
||||
<span class="pattern-label">{{ t('examples.optionalBlock') }}</span>
|
||||
<span class="pattern-col"><code>{{ '<{seriesIndex}. >{title}' }}</code></span>
|
||||
<div class="result-col-dual">
|
||||
<span class="result-with"><i class="pi pi-check-circle"></i> <code>01. The Name of the Wind.epub</code></span>
|
||||
<span class="result-without"><i class="pi pi-question-circle"></i> <code>Project Hail Mary.epub</code></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="example-row-conditional">
|
||||
<span class="pattern-label">{{ t('examples.subtitleConditional') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{title}<: {subtitle}>' }}</code></span>
|
||||
<div class="result-col-dual">
|
||||
<span class="result-with"><i class="pi pi-check-circle"></i> <code>The Name of the Wind: Special Edition.epub</code></span>
|
||||
<span class="result-without"><i class="pi pi-question-circle"></i> <code>Project Hail Mary.epub</code></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="example-row-conditional">
|
||||
<span class="pattern-label">{{ t('examples.multipleOptional') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{authors}/<{series}/><{seriesIndex}. >{title}< ({year})>' }}</code></span>
|
||||
<div class="result-col-dual">
|
||||
<span class="result-with"><i class="pi pi-check-circle"></i> <code>Patrick Rothfuss/The Kingkiller Chronicle/01. The Name of the Wind (2007).epub</code></span>
|
||||
<span class="result-without"><i class="pi pi-question-circle"></i> <code>Andy Weir/Project Hail Mary (2021).epub</code></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="example-row-conditional">
|
||||
<span class="pattern-label">{{ t('examples.elseClause') }}</span>
|
||||
<span class="pattern-col"><code>{{ '<{series}|Standalone>/{title}' }}</code></span>
|
||||
<div class="result-col-dual">
|
||||
<span class="result-with"><i class="pi pi-check-circle"></i> <code>The Kingkiller Chronicle/The Name of the Wind.epub</code></span>
|
||||
<span class="result-without"><i class="pi pi-question-circle"></i> <code>Standalone/Project Hail Mary.epub</code></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="example-row-conditional">
|
||||
<span class="pattern-label">{{ t('examples.elseClauseFallback') }}</span>
|
||||
<span class="pattern-col"><code>{{ '<{series}/{seriesIndex} - {title}|{title}>' }}</code></span>
|
||||
<div class="result-col-dual">
|
||||
<span class="result-with"><i class="pi pi-check-circle"></i> <code>The Kingkiller Chronicle/01 - The Name of the Wind.epub</code></span>
|
||||
<span class="result-without"><i class="pi pi-question-circle"></i> <code>Project Hail Mary.epub</code></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="example-row-conditional">
|
||||
<span class="pattern-label">{{ t('examples.elseWithModifier') }}</span>
|
||||
<span class="pattern-col"><code>{{ '<{series}|{authors:sort}>/{title}' }}</code></span>
|
||||
<div class="result-col-dual">
|
||||
<span class="result-with"><i class="pi pi-check-circle"></i> <code>The Kingkiller Chronicle/The Name of the Wind.epub</code></span>
|
||||
<span class="result-without"><i class="pi pi-question-circle"></i> <code>Weir, Andy/Project Hail Mary.epub</code></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-divider"><hr></div>
|
||||
|
||||
<div class="example-category">
|
||||
<h4 class="category-title">
|
||||
<i class="pi pi-wrench"></i>
|
||||
{{ t('examples.modifiersGroup') }}
|
||||
</h4>
|
||||
<div class="example-grid">
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.modifierSort') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{authors:sort}/{title}' }}</code></span>
|
||||
<span class="result-col"><code>Rothfuss, Patrick/The Name of the Wind.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.modifierInitial') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{authors:initial}/{authors:sort}/{title}' }}</code></span>
|
||||
<span class="result-col"><code>R/Rothfuss, Patrick/The Name of the Wind.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.modFirst') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{authors:first}/{title}' }}</code></span>
|
||||
<span class="result-col"><code>Patrick Rothfuss/The Name of the Wind.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.modUpper') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{title:upper}' }}</code></span>
|
||||
<span class="result-col"><code>THE NAME OF THE WIND.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.modLower') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{title:lower}' }}</code></span>
|
||||
<span class="result-col"><code>the name of the wind.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.letterFolder') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{title:initial}/{authors}/{title}' }}</code></span>
|
||||
<span class="result-col"><code>T/Patrick Rothfuss/The Name of the Wind.epub</code></span>
|
||||
</div>
|
||||
<div class="example-row">
|
||||
<span class="pattern-label">{{ t('examples.combinedMods') }}</span>
|
||||
<span class="pattern-col"><code>{{ '{authors:sort} - {title:lower}' }}</code></span>
|
||||
<span class="result-col"><code>Rothfuss, Patrick - the name of the wind.epub</code></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+586
@@ -0,0 +1,586 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.file-naming-container {
|
||||
@include settings.settings-page-container;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
@include settings.settings-section-divider;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.warning-notice {
|
||||
margin-top: -2rem;
|
||||
margin-bottom: 1rem;
|
||||
@include settings.settings-warning-notice;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
@include settings.settings-section-body;
|
||||
}
|
||||
|
||||
// Empty state
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 2rem;
|
||||
text-align: center;
|
||||
color: var(--p-text-muted-color);
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border-radius: 6px;
|
||||
|
||||
.pi {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 1rem;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
margin: 0 0 0.5rem 0;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.empty-subtitle {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Default pattern card
|
||||
.default-pattern-card {
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-left: 3px solid var(--p-primary-color);
|
||||
border-radius: 6px;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.pattern-input-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.pattern-input-row {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
align-items: flex-start;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
p-button {
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pattern-input {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
@include settings.settings-error-text;
|
||||
}
|
||||
|
||||
.preview-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-top: 0.25rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.preview-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
white-space: nowrap;
|
||||
|
||||
.pi {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.preview-value {
|
||||
color: var(--p-green-400);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
// Libraries list
|
||||
.libraries-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.library-item {
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-left: 3px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
transition: border-color 0.2s ease, background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
|
||||
}
|
||||
|
||||
&.has-pattern {
|
||||
border-left-color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.library-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding: 0.75rem 1rem;
|
||||
border-bottom: 1px dashed var(--p-content-border-color);
|
||||
|
||||
@media (max-width: 600px) {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
.library-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.library-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
border-radius: 6px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.pi {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.library-name {
|
||||
font-weight: 600;
|
||||
font-size: 0.9375rem;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.custom-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.125rem 0.5rem;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
border-radius: 12px;
|
||||
font-size: 0.625rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.default-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.125rem 0.5rem;
|
||||
background: color-mix(in srgb, #6b7280 15%, transparent);
|
||||
color: #6b7280;
|
||||
border-radius: 12px;
|
||||
font-size: 0.625rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.library-body {
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.actions-row {
|
||||
@include settings.settings-actions-row;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
// Placeholders Reference Section
|
||||
.placeholders-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 1rem;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.placeholder-group {
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border-radius: 6px;
|
||||
padding: 1rem;
|
||||
border-left: 3px solid var(--p-primary-color);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.group-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: settings.$settings-label-size;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.75rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.group-description {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
color: var(--p-text-muted-color);
|
||||
margin: 0 0 0.75rem 0;
|
||||
|
||||
code {
|
||||
color: var(--p-orange-400);
|
||||
font-size: settings.$settings-description-size;
|
||||
}
|
||||
}
|
||||
|
||||
.placeholder-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
|
||||
.placeholder-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
|
||||
code {
|
||||
color: var(--p-orange-400);
|
||||
font-size: settings.$settings-description-size;
|
||||
min-width: 130px;
|
||||
}
|
||||
|
||||
span {
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
}
|
||||
|
||||
.example-block {
|
||||
background: color-mix(in srgb, var(--p-surface-800) 30%, transparent);
|
||||
border-radius: 4px;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.example-pattern {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.pattern-prefix {
|
||||
font-size: settings.$settings-description-size;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
code {
|
||||
color: var(--p-orange-400);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
}
|
||||
}
|
||||
|
||||
.example-results {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
|
||||
.result-prefix {
|
||||
font-size: settings.$settings-description-size;
|
||||
color: var(--p-text-muted-color);
|
||||
min-width: 70px;
|
||||
}
|
||||
|
||||
code {
|
||||
color: var(--p-green-400);
|
||||
font-size: settings.$settings-description-size;
|
||||
}
|
||||
}
|
||||
|
||||
// Pattern Examples Section
|
||||
.examples-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.metadata-reference {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.metadata-panel {
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
padding: 1rem 1.25rem;
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid var(--p-content-border-color);
|
||||
|
||||
&.metadata-panel-full {
|
||||
border-left-color: var(--p-green-400);
|
||||
}
|
||||
|
||||
&.metadata-panel-partial {
|
||||
border-left-color: var(--p-orange-400);
|
||||
}
|
||||
}
|
||||
|
||||
.metadata-panel-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: settings.$settings-label-size;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin-bottom: 0.875rem;
|
||||
padding-bottom: 0.625rem;
|
||||
border-bottom: 1px solid color-mix(in srgb, var(--p-content-border-color) 50%, transparent);
|
||||
|
||||
.pi {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.metadata-icon-full {
|
||||
color: var(--p-green-400);
|
||||
}
|
||||
|
||||
.metadata-icon-partial {
|
||||
color: var(--p-orange-400);
|
||||
}
|
||||
|
||||
.metadata-grid {
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: 0.5rem 0.75rem;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.metadata-key {
|
||||
color: var(--p-text-muted-color);
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
|
||||
&::after {
|
||||
content: ':';
|
||||
}
|
||||
}
|
||||
|
||||
.metadata-val {
|
||||
color: var(--p-text-color);
|
||||
font-size: settings.$settings-description-size;
|
||||
|
||||
&.not-set {
|
||||
opacity: 0.5;
|
||||
font-style: italic;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
}
|
||||
|
||||
.example-category {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.category-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: settings.$settings-label-size;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin: 0;
|
||||
|
||||
.pi {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.example-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.example-row {
|
||||
display: grid;
|
||||
grid-template-columns: 130px 1fr 1fr;
|
||||
gap: 0.75rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border-radius: 4px;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
align-items: center;
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
}
|
||||
|
||||
.example-row-conditional {
|
||||
display: grid;
|
||||
grid-template-columns: 130px 1fr 1fr;
|
||||
gap: 0.75rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border-radius: 4px;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
align-items: start;
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
}
|
||||
|
||||
.pattern-label {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
white-space: nowrap;
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
font-weight: 500;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
}
|
||||
|
||||
.pattern-col {
|
||||
code {
|
||||
color: var(--p-orange-400);
|
||||
font-size: settings.$settings-description-size;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
padding-left: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.result-col {
|
||||
code {
|
||||
color: var(--p-green-400);
|
||||
font-size: settings.$settings-description-size;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
padding-left: 0.5rem;
|
||||
border-left: 2px solid var(--p-green-400);
|
||||
}
|
||||
}
|
||||
|
||||
.result-col-dual {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.375rem;
|
||||
|
||||
code {
|
||||
font-size: settings.$settings-description-size;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.pi {
|
||||
font-size: 0.625rem;
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.result-with {
|
||||
color: var(--p-green-400);
|
||||
|
||||
.pi {
|
||||
color: var(--p-green-400);
|
||||
}
|
||||
|
||||
code {
|
||||
color: var(--p-green-400);
|
||||
}
|
||||
}
|
||||
|
||||
.result-without {
|
||||
color: var(--p-orange-400);
|
||||
|
||||
.pi {
|
||||
color: var(--p-orange-400);
|
||||
}
|
||||
|
||||
code {
|
||||
color: var(--p-orange-400);
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {AppSettingsService} from '../../../shared/service/app-settings.service';
|
||||
import {forkJoin, of} from 'rxjs';
|
||||
import {AppSettingKey} from '../../../shared/model/app-settings.model';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {Library} from '../../book/model/library.model';
|
||||
import {LibraryService} from '../../book/service/library.service';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {ExternalDocLinkComponent} from '../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
import {replacePlaceholders} from '../../../shared/util/pattern-resolver';
|
||||
|
||||
@Component({
|
||||
selector: 'app-file-naming-pattern',
|
||||
templateUrl: './file-naming-pattern.component.html',
|
||||
standalone: true,
|
||||
imports: [FormsModule, Button, InputText, Tooltip, ExternalDocLinkComponent, TranslocoDirective, TranslocoPipe],
|
||||
styleUrls: ['./file-naming-pattern.component.scss'],
|
||||
})
|
||||
export class FileNamingPatternComponent implements OnInit {
|
||||
readonly exampleMetadata: Record<string, string> = {
|
||||
title: "The Name of the Wind",
|
||||
subtitle: "Special Edition",
|
||||
authors: "Patrick Rothfuss",
|
||||
year: "2007",
|
||||
series: "The Kingkiller Chronicle",
|
||||
seriesIndex: "01",
|
||||
language: "English",
|
||||
publisher: "DAW Books",
|
||||
isbn: "9780756404741",
|
||||
};
|
||||
|
||||
defaultPattern = '';
|
||||
defaultErrorMessage = '';
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
private libraryService = inject(LibraryService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
ngOnInit(): void {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.defaultPattern = settings.uploadPattern ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
get libraries(): Library[] {
|
||||
return this.libraryService.libraries();
|
||||
}
|
||||
|
||||
private resolvePattern(pattern: string, values: Record<string, string>): string {
|
||||
return replacePlaceholders(pattern, values);
|
||||
}
|
||||
|
||||
private appendExtensionIfMissing(path: string, ext = '.pdf'): string {
|
||||
const lastSegment = path.split('/').pop() ?? '';
|
||||
const hasExtension = /\.[a-z0-9]{2,5}$/i.test(lastSegment);
|
||||
return hasExtension ? path : path + ext;
|
||||
}
|
||||
|
||||
private generatePreview(pattern: string): string {
|
||||
let path = this.resolvePattern(pattern || '', this.exampleMetadata);
|
||||
|
||||
if (!path) return '/original_filename.pdf';
|
||||
if (path.endsWith('/')) return path + 'original_filename.pdf';
|
||||
if (path.includes('{originalFilename}')) {
|
||||
path = path.replace('{originalFilename}', 'original_filename.pdf');
|
||||
return path.startsWith('/') ? path : `/${path}`;
|
||||
}
|
||||
path = this.appendExtensionIfMissing(path);
|
||||
return path.startsWith('/') ? path : `/${path}`;
|
||||
}
|
||||
|
||||
generateDefaultPreview(): string {
|
||||
return this.generatePreview(this.defaultPattern);
|
||||
}
|
||||
|
||||
generateLibraryPreview(library: Library): string {
|
||||
return this.generatePreview(library.fileNamingPattern || this.defaultPattern);
|
||||
}
|
||||
|
||||
validatePattern(pattern: string): boolean {
|
||||
const validPatternRegex = /^[\w\s\-{}[/().<>.,:'"#|\]]*$/;
|
||||
return validPatternRegex.test(pattern);
|
||||
}
|
||||
|
||||
onDefaultPatternChange(pattern: string): void {
|
||||
this.defaultPattern = pattern;
|
||||
this.defaultErrorMessage = this.validatePattern(pattern) ? '' : this.t.translate('settingsNaming.defaultPattern.invalidChars');
|
||||
}
|
||||
|
||||
onLibraryPatternChange(_library: Library): void {
|
||||
// Optionally add per-library validation here
|
||||
}
|
||||
|
||||
clearLibraryPattern(library: Library): void {
|
||||
library.fileNamingPattern = '';
|
||||
}
|
||||
|
||||
savePatterns(): void {
|
||||
if (this.defaultErrorMessage) {
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsNaming.defaultPattern.invalidError'));
|
||||
return;
|
||||
}
|
||||
this.appSettingsService
|
||||
.saveSettings([
|
||||
{key: AppSettingKey.UPLOAD_FILE_PATTERN, newValue: this.defaultPattern},
|
||||
])
|
||||
.subscribe({
|
||||
next: () => this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsNaming.defaultPattern.saveSuccess')),
|
||||
error: () => this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsNaming.defaultPattern.saveError')),
|
||||
});
|
||||
}
|
||||
|
||||
saveLibraryPatterns(): void {
|
||||
const patchRequests = this.libraries.map(library =>
|
||||
this.libraryService.updateLibraryFileNamingPattern(library.id!, library.fileNamingPattern || '').pipe(
|
||||
catchError(() => of(null))
|
||||
)
|
||||
);
|
||||
forkJoin(patchRequests).subscribe(results => {
|
||||
const failures = results.filter(result => result === null);
|
||||
if (failures.length === 0) {
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsNaming.libraryOverrides.saveSuccess'));
|
||||
} else {
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsNaming.libraryOverrides.saveError', {count: failures.length}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private showMessage(severity: 'success' | 'error', summary: string, detail: string): void {
|
||||
this.messageService.add({severity, summary, detail});
|
||||
}
|
||||
}
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsApp'">
|
||||
<div class="main-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-cog"></i>
|
||||
{{ t('title') }}
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-image"></i>
|
||||
{{ t('covers.sectionTitle') }}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('covers.regenerate') }}</label>
|
||||
<p-splitbutton
|
||||
[label]="t('covers.regenerateAllBtn')"
|
||||
icon="pi pi-refresh"
|
||||
outlined="true"
|
||||
size="small"
|
||||
severity="info"
|
||||
[model]="regenerateCoverMenuItems"
|
||||
(onClick)="regenerateCovers()">
|
||||
</p-splitbutton>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('covers.regenerateDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('covers.verticalCropping') }}</label>
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="coverCroppingSettings.verticalCroppingEnabled"
|
||||
(onChange)="onCoverCroppingChange()">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('covers.verticalCroppingDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('covers.horizontalCropping') }}</label>
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="coverCroppingSettings.horizontalCroppingEnabled"
|
||||
(onChange)="onCoverCroppingChange()">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('covers.horizontalCroppingDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('covers.aspectRatio', {value: coverCroppingSettings.aspectRatioThreshold}) }}</label>
|
||||
<div class="slider-container">
|
||||
<p-slider
|
||||
[(ngModel)]="coverCroppingSettings.aspectRatioThreshold"
|
||||
[min]="1.5"
|
||||
[max]="3"
|
||||
[step]="0.1"
|
||||
(onSlideEnd)="onCoverCroppingChange()">
|
||||
</p-slider>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('covers.aspectRatioDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('covers.smartCropping') }}</label>
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="coverCroppingSettings.smartCroppingEnabled"
|
||||
(onChange)="onCoverCroppingChange()">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('covers.smartCroppingDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-search"></i>
|
||||
{{ t('search.sectionTitle') }}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('search.autoBookSearch') }}</label>
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="toggles.autoBookSearch"
|
||||
(onChange)="onToggleChange('autoBookSearch', $event.checked)">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('search.autoBookSearchDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('search.similarBook') }}</label>
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="toggles.similarBookRecommendation"
|
||||
(onChange)="onToggleChange('similarBookRecommendation', $event.checked)">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('search.similarBookDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-upload"></i>
|
||||
{{ t('fileManagement.sectionTitle') }}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('fileManagement.maxUploadSize') }}</label>
|
||||
<div class="input-group">
|
||||
<div class="input-with-unit">
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="maxFileUploadSizeInMb"
|
||||
[placeholder]="t('fileManagement.maxUploadPlaceholder')"/>
|
||||
<span class="unit">MB</span>
|
||||
</div>
|
||||
<p-button [label]="'common.save' | transloco" outlined severity="success" (onClick)="saveFileSize()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('fileManagement.maxUploadDesc') }}
|
||||
</p>
|
||||
<div class="warning-message">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<span>{{ t('fileManagement.restartWarning') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.main-container {
|
||||
@include settings.settings-page-container;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
@media (min-width: 768px) {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
margin-top: 0.125rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
align-items: flex-end;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.input-with-unit {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
input {
|
||||
padding-right: 2.5rem;
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.unit {
|
||||
position: absolute;
|
||||
right: 0.75rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.warning-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
margin-top: 0.5rem;
|
||||
|
||||
.pi {
|
||||
color: var(--p-orange-500);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.slider-container {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
max-width: 300px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
min-width: 180px;
|
||||
max-width: 250px;
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
import {Component, effect, inject, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {MenuItem, MessageService} from 'primeng/api';
|
||||
import {Button} from 'primeng/button';
|
||||
import {SplitButton} from 'primeng/splitbutton';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
|
||||
import {AppSettingsService} from '../../../shared/service/app-settings.service';
|
||||
import {BookMetadataManageService} from '../../book/service/book-metadata-manage.service';
|
||||
import {AppSettingKey, CoverCroppingSettings} from '../../../shared/model/app-settings.model';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {ExternalDocLinkComponent} from '../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-global-preferences',
|
||||
standalone: true,
|
||||
imports: [
|
||||
Button,
|
||||
ToggleSwitch,
|
||||
FormsModule,
|
||||
InputText,
|
||||
Slider,
|
||||
SplitButton,
|
||||
ExternalDocLinkComponent,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
],
|
||||
templateUrl: './global-preferences.component.html',
|
||||
styleUrl: './global-preferences.component.scss'
|
||||
})
|
||||
export class GlobalPreferencesComponent implements OnInit {
|
||||
|
||||
toggles = {
|
||||
autoBookSearch: false,
|
||||
similarBookRecommendation: false,
|
||||
};
|
||||
|
||||
coverCroppingSettings: CoverCroppingSettings = {
|
||||
verticalCroppingEnabled: false,
|
||||
horizontalCroppingEnabled: false,
|
||||
aspectRatioThreshold: 2.5,
|
||||
smartCroppingEnabled: false
|
||||
};
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private bookMetadataManageService = inject(BookMetadataManageService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
private readonly syncSettingsEffect = effect(() => {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (!settings) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (settings.maxFileUploadSizeInMb) {
|
||||
this.maxFileUploadSizeInMb = settings.maxFileUploadSizeInMb;
|
||||
}
|
||||
if (settings.coverCroppingSettings) {
|
||||
this.coverCroppingSettings = {...settings.coverCroppingSettings};
|
||||
}
|
||||
this.toggles.autoBookSearch = settings.autoBookSearch ?? false;
|
||||
this.toggles.similarBookRecommendation = settings.similarBookRecommendation ?? false;
|
||||
});
|
||||
|
||||
maxFileUploadSizeInMb?: number;
|
||||
regenerateCoverMenuItems: MenuItem[] = [];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.regenerateCoverMenuItems = [
|
||||
{
|
||||
label: this.t.translate('settingsApp.covers.regenerateMissingBtn'),
|
||||
icon: 'pi pi-images',
|
||||
command: () => this.regenerateCovers(true)
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
onToggleChange(settingKey: keyof typeof this.toggles, checked: boolean): void {
|
||||
this.toggles[settingKey] = checked;
|
||||
const toggleKeyMap: Record<string, AppSettingKey> = {
|
||||
autoBookSearch: AppSettingKey.AUTO_BOOK_SEARCH,
|
||||
similarBookRecommendation: AppSettingKey.SIMILAR_BOOK_RECOMMENDATION,
|
||||
};
|
||||
const keyToSend = toggleKeyMap[settingKey];
|
||||
if (keyToSend) {
|
||||
this.saveSetting(keyToSend, checked);
|
||||
} else {
|
||||
console.warn(`Unknown toggle key: ${settingKey}`);
|
||||
}
|
||||
}
|
||||
|
||||
onCoverCroppingChange(): void {
|
||||
this.saveSetting(AppSettingKey.COVER_CROPPING_SETTINGS, this.coverCroppingSettings);
|
||||
}
|
||||
|
||||
saveFileSize() {
|
||||
if (!this.maxFileUploadSizeInMb || this.maxFileUploadSizeInMb <= 0) {
|
||||
this.showMessage('error', this.t.translate('settingsApp.fileManagement.invalidInput'), this.t.translate('settingsApp.fileManagement.invalidInputDetail'));
|
||||
return;
|
||||
}
|
||||
this.saveSetting(AppSettingKey.MAX_FILE_UPLOAD_SIZE_IN_MB, this.maxFileUploadSizeInMb);
|
||||
}
|
||||
|
||||
regenerateCovers(missingOnly = false): void {
|
||||
this.bookMetadataManageService.regenerateCovers(missingOnly).subscribe({
|
||||
next: () =>
|
||||
this.showMessage('success', this.t.translate('settingsApp.covers.regenerateStarted'), this.t.translate('settingsApp.covers.regenerateStartedDetail')),
|
||||
error: () =>
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsApp.covers.regenerateError'))
|
||||
});
|
||||
}
|
||||
|
||||
private saveSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
next: () =>
|
||||
this.showMessage('success', this.t.translate('settingsApp.settingsSaved'), this.t.translate('settingsApp.settingsSavedDetail')),
|
||||
error: () =>
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsApp.settingsError'))
|
||||
});
|
||||
}
|
||||
|
||||
private showMessage(severity: 'success' | 'error', summary: string, detail: string): void {
|
||||
this.messageService.add({severity, summary, detail});
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsMeta.matchWeights'">
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-sliders-h"></i>
|
||||
{{ t('sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
<div class="setting-item action-item">
|
||||
<div class="action-row">
|
||||
<div class="action-info">
|
||||
<span class="action-label">{{ t('recalculateLabel') }}</span>
|
||||
<span class="action-description">{{ t('recalculateDesc') }}</span>
|
||||
</div>
|
||||
<p-button
|
||||
type="button"
|
||||
icon="pi pi-refresh"
|
||||
[label]="t('recalculateBtn')"
|
||||
[disabled]="isRecalculating"
|
||||
(click)="recalculate()"
|
||||
outlined>
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item weights-item">
|
||||
<div class="weights-header">
|
||||
<span class="weights-icon pi pi-sliders-v"></span>
|
||||
<h4 class="weights-label">{{ t('fieldWeights') }}</h4>
|
||||
</div>
|
||||
|
||||
<form [formGroup]="form" class="weights-form">
|
||||
<div class="weights-grid">
|
||||
@for (key of orderedKeys; track key) {
|
||||
<div class="weight-field">
|
||||
<label class="field-label">{{ getFieldLabel(key) }}</label>
|
||||
<p-inputNumber
|
||||
size="small"
|
||||
[formControlName]="key"
|
||||
[min]="0"
|
||||
[max]="10"
|
||||
fluid
|
||||
[showButtons]="true"/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<p-button
|
||||
type="button"
|
||||
severity="success"
|
||||
[label]="t('saveWeights')"
|
||||
icon="pi pi-save"
|
||||
outlined
|
||||
[disabled]="isSaving"
|
||||
(click)="save()">
|
||||
</p-button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
.settings-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.25rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
padding: 1.5rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 1rem;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color);
|
||||
margin: 0 0 0.5rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--primary-color);
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
color: var(--p-text-muted-color);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
padding-left: 1rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding-left: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
padding: 0.875rem 1rem;
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid var(--primary-color);
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.action-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.action-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.125rem;
|
||||
}
|
||||
|
||||
.action-label {
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.action-description {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.weights-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.weights-icon {
|
||||
color: var(--primary-color);
|
||||
font-size: 0.875rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.weights-label {
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.weights-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.weights-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
||||
gap: 0.625rem;
|
||||
padding-top: 0.5rem;
|
||||
border-top: 1px dashed var(--p-content-border-color);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 400px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.weight-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem 0.625rem;
|
||||
background: var(--ground-background);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 4px;
|
||||
|
||||
.field-label {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
::ng-deep p-inputnumber {
|
||||
width: 6rem;
|
||||
}
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px dashed var(--p-content-border-color);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
p-button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {MetadataMatchWeightsService} from '../../../../shared/service/metadata-match-weights.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {AppSettingKey, AppSettings} from '../../../../shared/model/app-settings.model';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {InputNumber} from 'primeng/inputnumber';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-match-weights-component',
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
InputNumber,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './metadata-match-weights-component.html',
|
||||
styleUrl: './metadata-match-weights-component.scss'
|
||||
})
|
||||
export class MetadataMatchWeightsComponent implements OnInit {
|
||||
|
||||
readonly orderedFieldKeys: string[] = [
|
||||
'title', 'subtitle', 'authors', 'description', 'publisher', 'publishedDate',
|
||||
'categories', 'coverImage', 'seriesName', 'seriesNumber', 'seriesTotal',
|
||||
'language', 'isbn13', 'isbn10', 'pageCount',
|
||||
'amazonRating', 'amazonReviewCount', 'goodreadsRating', 'goodreadsReviewCount',
|
||||
'hardcoverRating', 'hardcoverReviewCount', 'audibleRating', 'audibleReviewCount',
|
||||
'doubanRating', 'doubanReviewCount', 'ranobedbRating'
|
||||
];
|
||||
|
||||
form!: FormGroup;
|
||||
isSaving = false;
|
||||
isRecalculating = false;
|
||||
|
||||
private weightsService = inject(MetadataMatchWeightsService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
private fb = inject(FormBuilder);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form = this.fb.group({
|
||||
title: [0, [Validators.required, Validators.min(0)]],
|
||||
subtitle: [0, [Validators.required, Validators.min(0)]],
|
||||
description: [0, [Validators.required, Validators.min(0)]],
|
||||
publisher: [0, [Validators.required, Validators.min(0)]],
|
||||
publishedDate: [0, [Validators.required, Validators.min(0)]],
|
||||
authors: [0, [Validators.required, Validators.min(0)]],
|
||||
categories: [0, [Validators.required, Validators.min(0)]],
|
||||
seriesName: [0, [Validators.required, Validators.min(0)]],
|
||||
seriesNumber: [0, [Validators.required, Validators.min(0)]],
|
||||
seriesTotal: [0, [Validators.required, Validators.min(0)]],
|
||||
isbn13: [0, [Validators.required, Validators.min(0)]],
|
||||
isbn10: [0, [Validators.required, Validators.min(0)]],
|
||||
pageCount: [0, [Validators.required, Validators.min(0)]],
|
||||
language: [0, [Validators.required, Validators.min(0)]],
|
||||
amazonRating: [0, [Validators.required, Validators.min(0)]],
|
||||
amazonReviewCount: [0, [Validators.required, Validators.min(0)]],
|
||||
goodreadsRating: [0, [Validators.required, Validators.min(0)]],
|
||||
goodreadsReviewCount: [0, [Validators.required, Validators.min(0)]],
|
||||
hardcoverRating: [0, [Validators.required, Validators.min(0)]],
|
||||
hardcoverReviewCount: [0, [Validators.required, Validators.min(0)]],
|
||||
doubanRating: [0, [Validators.required, Validators.min(0)]],
|
||||
doubanReviewCount: [0, [Validators.required, Validators.min(0)]],
|
||||
ranobedbRating: [0, [Validators.required, Validators.min(0)]],
|
||||
audibleRating: [0, [Validators.required, Validators.min(0)]],
|
||||
audibleReviewCount: [0, [Validators.required, Validators.min(0)]],
|
||||
coverImage: [0, [Validators.required, Validators.min(0)]],
|
||||
});
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings?.metadataMatchWeights) {
|
||||
this.form.patchValue(settings.metadataMatchWeights);
|
||||
}
|
||||
}
|
||||
|
||||
get orderedKeys(): string[] {
|
||||
return this.orderedFieldKeys;
|
||||
}
|
||||
|
||||
getFieldLabel(key: string): string {
|
||||
return this.t.translate('settingsMeta.matchWeights.fields.' + key);
|
||||
}
|
||||
|
||||
save(): void {
|
||||
if (this.form.invalid) return;
|
||||
|
||||
this.isSaving = true;
|
||||
|
||||
const payload = [
|
||||
{
|
||||
key: AppSettingKey.METADATA_MATCH_WEIGHTS,
|
||||
newValue: this.form.value
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(payload).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('settingsMeta.matchWeights.saveSuccess')
|
||||
});
|
||||
this.isSaving = false;
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsMeta.matchWeights.saveError')
|
||||
});
|
||||
this.isSaving = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
recalculate(): void {
|
||||
this.isRecalculating = true;
|
||||
this.weightsService.recalculateAll().subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('settingsMeta.matchWeights.recalcSuccess')
|
||||
});
|
||||
this.isRecalculating = false;
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsMeta.matchWeights.recalcError')
|
||||
});
|
||||
this.isRecalculating = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsMeta.providers'">
|
||||
<div class="metadata-settings">
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-cloud"></i>
|
||||
{{ t('sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
<div class="configurable-providers-section">
|
||||
<h4 class="provider-group-title">{{ t('configurableTitle') }}</h4>
|
||||
|
||||
<div class="configurable-providers-list">
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch [(ngModel)]="amazonEnabled"></p-toggleswitch>
|
||||
<label class="setting-label">Amazon</label>
|
||||
</div>
|
||||
@if (amazonEnabled) {
|
||||
<div class="setting-options">
|
||||
<div class="config-field">
|
||||
<label class="config-label">{{ t('region') }}</label>
|
||||
<p-select
|
||||
[options]="amazonDomains"
|
||||
[(ngModel)]="selectedAmazonDomain"
|
||||
[placeholder]="t('selectDomain')"
|
||||
class="config-select">
|
||||
</p-select>
|
||||
</div>
|
||||
<div class="config-field">
|
||||
<div class="config-label-row">
|
||||
<label class="config-label">{{ t('cookieLabel') }}</label>
|
||||
<app-external-doc-link docType="amazonCookie"></app-external-doc-link>
|
||||
</div>
|
||||
<p class="config-description">{{ t('cookieDesc') }}</p>
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[placeholder]="t('cookiePlaceholder')"
|
||||
[(ngModel)]="amazonCookie"
|
||||
class="config-input"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch [(ngModel)]="googleEnabled"></p-toggleswitch>
|
||||
<label class="setting-label">Google Books</label>
|
||||
</div>
|
||||
@if (googleEnabled) {
|
||||
<div class="setting-options">
|
||||
<div class="config-field">
|
||||
<label class="config-label">{{ t('languageRestriction') }}</label>
|
||||
<p-select
|
||||
[options]="googleLanguages"
|
||||
[(ngModel)]="selectedGoogleLanguage"
|
||||
[showClear]="!!selectedGoogleLanguage"
|
||||
[placeholder]="t('selectLanguage')"
|
||||
class="config-select">
|
||||
</p-select>
|
||||
</div>
|
||||
<div class="config-field">
|
||||
<label class="config-label">{{ t('apiKeyOptional') }}</label>
|
||||
<p class="config-description">{{ t('googleApiDesc') }}</p>
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[placeholder]="t('googleApiPlaceholder')"
|
||||
[(ngModel)]="googleApiKey"
|
||||
class="config-input"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="hardcoverEnabled"
|
||||
[disabled]="!hardcoverToken">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">Hardcover</label>
|
||||
</div>
|
||||
<div class="setting-options">
|
||||
<div class="config-field">
|
||||
<div class="config-label-row">
|
||||
<label class="config-label">{{ t('apiToken') }}</label>
|
||||
<app-external-doc-link docType="hardcover"></app-external-doc-link>
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[placeholder]="t('hardcoverPlaceholder')"
|
||||
[(ngModel)]="hardcoverToken"
|
||||
(ngModelChange)="onTokenChange($event)"
|
||||
class="config-input"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch [(ngModel)]="comicvineEnabled"></p-toggleswitch>
|
||||
<label class="setting-label">Comic Vine</label>
|
||||
</div>
|
||||
@if (comicvineEnabled) {
|
||||
<div class="setting-options">
|
||||
<div class="config-field">
|
||||
<label class="config-label">{{ t('apiToken') }}</label>
|
||||
<input
|
||||
type="text"
|
||||
pInputText
|
||||
[placeholder]="t('comicvinePlaceholder')"
|
||||
[(ngModel)]="comicvineToken"
|
||||
(ngModelChange)="onComicTokenChange($event)"
|
||||
class="config-input"/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch [(ngModel)]="audibleEnabled"></p-toggleswitch>
|
||||
<label class="setting-label">Audible</label>
|
||||
</div>
|
||||
@if (audibleEnabled) {
|
||||
<div class="setting-options">
|
||||
<div class="config-field">
|
||||
<label class="config-label">{{ t('region') }}</label>
|
||||
<p-select
|
||||
[options]="audibleDomains"
|
||||
[(ngModel)]="selectedAudibleDomain"
|
||||
[placeholder]="t('selectDomain')"
|
||||
class="config-select">
|
||||
</p-select>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="simple-providers-section">
|
||||
<h4 class="provider-group-title">{{ t('readyToUseTitle') }}</h4>
|
||||
|
||||
<div class="simple-providers-grid">
|
||||
<div class="setting-item simple-provider">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch [(ngModel)]="goodreadsEnabled"></p-toggleswitch>
|
||||
<label class="setting-label">Goodreads</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item simple-provider">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch [(ngModel)]="doubanEnabled"></p-toggleswitch>
|
||||
<label class="setting-label">Douban</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item simple-provider">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch [(ngModel)]="lubimyCzytacEnabled"></p-toggleswitch>
|
||||
<label class="setting-label">Lubimyczytac</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item simple-provider">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch [(ngModel)]="ranobedbEnabled"></p-toggleswitch>
|
||||
<label class="setting-label">Ranobedb</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-actions">
|
||||
<p-button [label]="t('saveConfigurations')" icon="pi pi-save" severity="success" [outlined]="true" (click)="saveSettings()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
@use '../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.metadata-settings {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
@include settings.settings-section-body;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.configurable-providers-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.configurable-providers-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.simple-providers-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.provider-group-title {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-muted-color);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.025em;
|
||||
margin: 0 0 0.25rem 0;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
@include settings.settings-item;
|
||||
}
|
||||
|
||||
.setting-header {
|
||||
@include settings.settings-item-header;
|
||||
}
|
||||
|
||||
.setting-label {
|
||||
@include settings.settings-label;
|
||||
}
|
||||
|
||||
.setting-options {
|
||||
@include settings.settings-options;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.config-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
|
||||
.config-label {
|
||||
font-weight: settings.$settings-label-weight;
|
||||
color: var(--text-color);
|
||||
font-size: settings.$settings-description-size;
|
||||
}
|
||||
|
||||
.config-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.config-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-description-size;
|
||||
line-height: 1.4;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
::ng-deep .config-select {
|
||||
width: 100%;
|
||||
max-width: 20rem;
|
||||
}
|
||||
|
||||
.config-input {
|
||||
width: 100%;
|
||||
max-width: 40rem;
|
||||
padding: 0.375rem 0.625rem;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 4px;
|
||||
background: var(--ground-background);
|
||||
color: var(--text-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
transition: border-color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
&::placeholder {
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
}
|
||||
|
||||
.simple-providers-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 0.75rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.simple-provider {
|
||||
padding: 0.625rem 0.875rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
padding: 0.5rem 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding-top: 0.5rem;
|
||||
border-top: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
import {Component, DestroyRef, effect, inject, OnInit} from '@angular/core';
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Button} from 'primeng/button';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {AppSettingKey} from '../../../../shared/model/app-settings.model';
|
||||
import {Select} from 'primeng/select';
|
||||
import {ExternalDocLinkComponent} from '../../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import { ToggleSwitchModule } from 'primeng/toggleswitch';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-provider-settings',
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
TableModule,
|
||||
InputText,
|
||||
Button,
|
||||
FormsModule,
|
||||
Select,
|
||||
ExternalDocLinkComponent,
|
||||
ToggleSwitchModule,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './metadata-provider-settings.component.html',
|
||||
styleUrl: './metadata-provider-settings.component.scss'
|
||||
})
|
||||
export class MetadataProviderSettingsComponent implements OnInit {
|
||||
|
||||
amazonDomains = [
|
||||
{label: 'amazon.com', value: 'com'},
|
||||
{label: 'amazon.de', value: 'de'},
|
||||
{label: 'amazon.co.uk', value: 'co.uk'},
|
||||
{label: 'amazon.co.jp', value: 'co.jp'},
|
||||
{label: 'amazon.ca', value: 'ca'},
|
||||
{label: 'amazon.in', value: 'in'},
|
||||
{label: 'amazon.com.au', value: 'com.au'},
|
||||
{label: 'amazon.fr', value: 'fr'},
|
||||
{label: 'amazon.it', value: 'it'},
|
||||
{label: 'amazon.es', value: 'es'},
|
||||
{label: 'amazon.nl', value: 'nl'},
|
||||
{label: 'amazon.se', value: 'se'},
|
||||
{label: 'amazon.com.br', value: 'com.br'},
|
||||
{label: 'amazon.sg', value: 'sg'},
|
||||
{label: 'amazon.com.mx', value: 'com.mx'},
|
||||
{label: 'amazon.pl', value: 'pl'},
|
||||
{label: 'amazon.ae', value: 'ae'},
|
||||
{label: 'amazon.sa', value: 'sa'},
|
||||
{label: 'amazon.tr', value: 'tr'}
|
||||
];
|
||||
|
||||
selectedAmazonDomain = 'com';
|
||||
|
||||
googleLanguages = [
|
||||
{label: 'Dutch', value: 'nl'},
|
||||
{label: 'English', value: 'en'},
|
||||
{label: 'French', value: 'fr'},
|
||||
{label: 'German', value: 'de'},
|
||||
{label: 'Italian', value: 'it'},
|
||||
{label: 'Japanese', value: 'ja'},
|
||||
{label: 'Polish', value: 'pl'},
|
||||
{label: 'Portuguese', value: 'pt'},
|
||||
{label: 'Spanish', value: 'es'},
|
||||
{label: 'Swedish', value: 'sv'}
|
||||
];
|
||||
|
||||
selectedGoogleLanguage = '';
|
||||
|
||||
audibleDomains = [
|
||||
{label: 'audible.com', value: 'com'},
|
||||
{label: 'audible.co.uk', value: 'co.uk'},
|
||||
{label: 'audible.de', value: 'de'},
|
||||
{label: 'audible.fr', value: 'fr'},
|
||||
{label: 'audible.it', value: 'it'},
|
||||
{label: 'audible.es', value: 'es'},
|
||||
{label: 'audible.ca', value: 'ca'},
|
||||
{label: 'audible.com.au', value: 'com.au'},
|
||||
{label: 'audible.co.jp', value: 'co.jp'},
|
||||
{label: 'audible.in', value: 'in'}
|
||||
];
|
||||
|
||||
selectedAudibleDomain = 'com';
|
||||
audibleEnabled: boolean = false;
|
||||
|
||||
hardcoverToken: string = '';
|
||||
amazonCookie: string = '';
|
||||
hardcoverEnabled: boolean = false;
|
||||
amazonEnabled: boolean = false;
|
||||
goodreadsEnabled: boolean = false;
|
||||
googleEnabled: boolean = false;
|
||||
comicvineEnabled: boolean = false;
|
||||
comicvineToken: string = '';
|
||||
doubanEnabled: boolean = false;
|
||||
lubimyCzytacEnabled: boolean = false;
|
||||
ranobedbEnabled: boolean = false;
|
||||
googleApiKey: string = '';
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
private readonly syncSettingsEffect = effect(() => {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.applySettings(settings);
|
||||
}
|
||||
});
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
private applySettings(settings: NonNullable<ReturnType<typeof this.appSettingsService.appSettings>>): void {
|
||||
const metadataProviderSettings = settings.metadataProviderSettings;
|
||||
this.amazonEnabled = metadataProviderSettings?.amazon?.enabled ?? false;
|
||||
this.amazonCookie = metadataProviderSettings?.amazon?.cookie ?? "";
|
||||
this.selectedAmazonDomain = metadataProviderSettings?.amazon?.domain ?? 'com';
|
||||
this.goodreadsEnabled = metadataProviderSettings?.goodReads?.enabled ?? false;
|
||||
this.googleEnabled = metadataProviderSettings?.google?.enabled ?? false;
|
||||
this.selectedGoogleLanguage = metadataProviderSettings?.google?.language ?? '';
|
||||
this.googleApiKey = metadataProviderSettings?.google?.apiKey ?? '';
|
||||
this.hardcoverToken = metadataProviderSettings?.hardcover?.apiKey ?? '';
|
||||
this.hardcoverEnabled = metadataProviderSettings?.hardcover?.enabled ?? false;
|
||||
this.comicvineEnabled = metadataProviderSettings?.comicvine?.enabled ?? false;
|
||||
this.comicvineToken = metadataProviderSettings?.comicvine?.apiKey ?? '';
|
||||
this.doubanEnabled = metadataProviderSettings?.douban?.enabled ?? false;
|
||||
this.lubimyCzytacEnabled = metadataProviderSettings?.lubimyczytac?.enabled ?? false;
|
||||
this.ranobedbEnabled = metadataProviderSettings?.ranobedb?.enabled ?? false;
|
||||
this.audibleEnabled = metadataProviderSettings?.audible?.enabled ?? false;
|
||||
this.selectedAudibleDomain = metadataProviderSettings?.audible?.domain ?? 'com';
|
||||
}
|
||||
|
||||
onTokenChange(newToken: string): void {
|
||||
this.hardcoverToken = newToken;
|
||||
if (!newToken.trim()) {
|
||||
this.hardcoverEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
onComicTokenChange(newToken: string): void {
|
||||
this.comicvineToken = newToken;
|
||||
}
|
||||
|
||||
saveSettings(): void {
|
||||
const payload = [
|
||||
{
|
||||
key: AppSettingKey.METADATA_PROVIDER_SETTINGS,
|
||||
newValue: {
|
||||
amazon: {
|
||||
enabled: this.amazonEnabled,
|
||||
cookie: this.amazonCookie,
|
||||
domain: this.selectedAmazonDomain
|
||||
},
|
||||
comicvine: {
|
||||
enabled: this.comicvineEnabled,
|
||||
apiKey: this.comicvineToken.trim()
|
||||
},
|
||||
goodReads: {enabled: this.goodreadsEnabled},
|
||||
google: {
|
||||
enabled: this.googleEnabled,
|
||||
language: this.selectedGoogleLanguage,
|
||||
apiKey: this.googleApiKey.trim()
|
||||
},
|
||||
hardcover: {
|
||||
enabled: this.hardcoverEnabled,
|
||||
apiKey: this.hardcoverToken.trim()
|
||||
},
|
||||
douban: {enabled: this.doubanEnabled},
|
||||
lubimyczytac: {enabled: this.lubimyCzytacEnabled},
|
||||
ranobedb: {enabled: this.ranobedbEnabled},
|
||||
audible: {
|
||||
enabled: this.audibleEnabled,
|
||||
domain: this.selectedAudibleDomain
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(payload).subscribe({
|
||||
next: () =>
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('common.success'),
|
||||
detail: this.t.translate('settingsMeta.providers.saveSuccess')
|
||||
}),
|
||||
error: () =>
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsMeta.providers.saveError')
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsLibMeta'">
|
||||
<div class="main-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-database"></i>
|
||||
{{ t('title') }}
|
||||
<app-external-doc-link docType="fetchConfig"></app-external-doc-link>
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-content">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-globe"></i>
|
||||
{{ t('defaultSettings.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('defaultSettings.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<app-metadata-advanced-fetch-options
|
||||
[currentMetadataOptions]="defaultMetadataOptions"
|
||||
[submitButtonLabel]="t('defaultSettings.saveButton')"
|
||||
(metadataOptionsSubmitted)="onDefaultMetadataOptionsSubmitted($event)">
|
||||
</app-metadata-advanced-fetch-options>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-book"></i>
|
||||
{{ t('libraryOverrides.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('libraryOverrides.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
@if (libraries; as libraries) {
|
||||
<p-accordion [value]="activePanel" (valueChange)="onPanelChange($event)">
|
||||
@for (library of libraries; track trackByLibrary($index, library); let i = $index) {
|
||||
<p-accordion-panel [value]="i">
|
||||
<p-accordion-header>
|
||||
<div class="accordion-header-content">
|
||||
<div class="library-info">
|
||||
<i [class]="'pi pi-' + library.icon" class="library-icon"></i>
|
||||
<span class="library-name">{{ library.name }}</span>
|
||||
<span class="dot-separator">•</span>
|
||||
@if (hasLibraryOverride(library.id!)) {
|
||||
<span class="override-indicator custom">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
{{ t('libraryOverrides.customSettings') }}
|
||||
</span>
|
||||
} @else {
|
||||
<span class="default-indicator default">
|
||||
<i class="pi pi-globe"></i>
|
||||
{{ t('libraryOverrides.defaultSettings') }}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
@if (isLocalStorage) {
|
||||
<div class="sidecar-actions">
|
||||
<p-button
|
||||
icon="pi pi-upload"
|
||||
[label]="t('libraryOverrides.exportSidecar')"
|
||||
size="small"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
[loading]="isSidecarExporting(library.id!)"
|
||||
(onClick)="exportSidecarForLibrary(library.id!, $event)"
|
||||
[pTooltip]="t('libraryOverrides.exportTooltip')"
|
||||
tooltipPosition="top"
|
||||
/>
|
||||
<p-button
|
||||
icon="pi pi-download"
|
||||
[label]="t('libraryOverrides.importSidecar')"
|
||||
size="small"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
[loading]="isSidecarImporting(library.id!)"
|
||||
(onClick)="importSidecarForLibrary(library.id!, $event)"
|
||||
[pTooltip]="t('libraryOverrides.importTooltip')"
|
||||
tooltipPosition="top"
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</p-accordion-header>
|
||||
<p-accordion-content>
|
||||
<div class="accordion-content-wrapper">
|
||||
@if (activePanel === i) {
|
||||
<app-metadata-advanced-fetch-options
|
||||
[currentMetadataOptions]="getLibraryOptions(library.id!)"
|
||||
[submitButtonLabel]="t('libraryOverrides.saveLibraryButton', {name: library.name})"
|
||||
(metadataOptionsSubmitted)="onLibraryMetadataOptionsSubmitted(library.id!, $event)">
|
||||
</app-metadata-advanced-fetch-options>
|
||||
}
|
||||
</div>
|
||||
</p-accordion-content>
|
||||
</p-accordion-panel>
|
||||
}
|
||||
</p-accordion>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.main-container {
|
||||
@include settings.settings-page-container;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
@media (min-width: 768px) {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
margin: 0.5rem 0 0 0;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
margin-top: 0.125rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
|
||||
app-metadata-advanced-fetch-options {
|
||||
display: block;
|
||||
width: 100%;
|
||||
|
||||
::ng-deep {
|
||||
> div,
|
||||
> .container,
|
||||
> .main-container {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
border: none !important;
|
||||
background: transparent !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:host ::ng-deep {
|
||||
.p-accordion {
|
||||
.p-accordion-panel {
|
||||
margin-bottom: 0.5rem;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.p-accordion-header {
|
||||
background: var(--p-surface-100);
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
|
||||
&:hover {
|
||||
background: var(--p-surface-200);
|
||||
}
|
||||
|
||||
.p-accordion-header-content {
|
||||
width: 100%;
|
||||
padding: 1rem 1.25rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.p-accordion-content {
|
||||
border: none;
|
||||
border-top: 1px solid var(--p-content-border-color);
|
||||
|
||||
.p-accordion-content-content {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.accordion-header-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.sidecar-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-left: auto;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 100%;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.library-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
|
||||
.library-icon {
|
||||
font-size: 1.2rem;
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
.library-name {
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.dot-separator {
|
||||
color: var(--p-text-muted-color);
|
||||
font-weight: bold;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
margin: 0 0.25rem;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.override-indicator,
|
||||
.default-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
font-weight: settings.$settings-label-weight;
|
||||
|
||||
&.custom {
|
||||
color: var(--p-green-500);
|
||||
}
|
||||
|
||||
&.default {
|
||||
color: var(--p-blue-500);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.accordion-content-wrapper {
|
||||
padding: 1.5rem;
|
||||
|
||||
app-metadata-advanced-fetch-options {
|
||||
display: block;
|
||||
width: 100%;
|
||||
|
||||
::ng-deep {
|
||||
> div,
|
||||
> .container,
|
||||
> .main-container {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
border: none !important;
|
||||
background: transparent !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+288
@@ -0,0 +1,288 @@
|
||||
import {Component, effect, inject, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {AccordionModule} from 'primeng/accordion';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
import {Library} from '../../book/model/library.model';
|
||||
import {LibraryService} from '../../book/service/library.service';
|
||||
import {MetadataRefreshOptions} from '../../metadata/model/request/metadata-refresh-options.model';
|
||||
import {AppSettingKey, AppSettings} from '../../../shared/model/app-settings.model';
|
||||
import {AppSettingsService} from '../../../shared/service/app-settings.service';
|
||||
import {ExternalDocLinkComponent} from '../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import {MetadataAdvancedFetchOptionsComponent} from '../../metadata/component/metadata-options-dialog/metadata-advanced-fetch-options/metadata-advanced-fetch-options.component';
|
||||
import {SidecarService} from '../../metadata/service/sidecar.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-library-metadata-settings-component',
|
||||
standalone: true,
|
||||
imports: [CommonModule, FormsModule, MetadataAdvancedFetchOptionsComponent, AccordionModule, ExternalDocLinkComponent, Button, Tooltip, TranslocoDirective],
|
||||
templateUrl: './library-metadata-settings.component.html',
|
||||
styleUrls: ['./library-metadata-settings.component.scss']
|
||||
})
|
||||
export class LibraryMetadataSettingsComponent implements OnInit {
|
||||
private libraryService = inject(LibraryService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
private sidecarService = inject(SidecarService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
defaultMetadataOptions: MetadataRefreshOptions = this.getDefaultMetadataOptions();
|
||||
libraryMetadataOptions: Record<number, MetadataRefreshOptions> = {};
|
||||
activePanel: number | null = null;
|
||||
sidecarExporting: Record<number, boolean> = {};
|
||||
sidecarImporting: Record<number, boolean> = {};
|
||||
isLocalStorage = true;
|
||||
private cachedDefaultOptions: Record<number, MetadataRefreshOptions> = {};
|
||||
private readonly syncLibraryOptionsEffect = effect(() => {
|
||||
this.libraries.forEach(library => {
|
||||
if (library.id && !this.libraryMetadataOptions[library.id]) {
|
||||
const libraryOptions = this.getLibrarySpecificOptions(library.id);
|
||||
if (libraryOptions) {
|
||||
this.libraryMetadataOptions[library.id] = libraryOptions;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
get libraries(): Library[] {
|
||||
return this.libraryService.libraries();
|
||||
}
|
||||
|
||||
private readonly syncAppSettingsEffect = effect(() => {
|
||||
const appSettings = this.appSettingsService.appSettings();
|
||||
if (appSettings) {
|
||||
this.isLocalStorage = appSettings.diskType === 'LOCAL';
|
||||
this.defaultMetadataOptions = appSettings.defaultMetadataRefreshOptions;
|
||||
this.cachedDefaultOptions = {};
|
||||
this.initializeLibraryOptions(appSettings);
|
||||
this.updateLibraryOptionsFromSettings(appSettings);
|
||||
}
|
||||
});
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
onPanelChange(event: unknown) {
|
||||
this.activePanel = typeof event === 'number' ? event : null;
|
||||
}
|
||||
|
||||
onDefaultMetadataOptionsSubmitted(options: MetadataRefreshOptions) {
|
||||
this.defaultMetadataOptions = options;
|
||||
this.saveDefaultMetadataOptions(options);
|
||||
}
|
||||
|
||||
onLibraryMetadataOptionsSubmitted(libraryId: number, options: MetadataRefreshOptions) {
|
||||
this.libraryMetadataOptions[libraryId] = {...options, libraryId};
|
||||
this.saveLibraryMetadataOptions();
|
||||
}
|
||||
|
||||
hasLibraryOverride(libraryId: number): boolean {
|
||||
return libraryId in this.libraryMetadataOptions;
|
||||
}
|
||||
|
||||
getLibraryOptions(libraryId: number): MetadataRefreshOptions {
|
||||
if (this.libraryMetadataOptions[libraryId]) {
|
||||
return this.libraryMetadataOptions[libraryId];
|
||||
}
|
||||
if (!this.cachedDefaultOptions[libraryId]) {
|
||||
this.cachedDefaultOptions[libraryId] = {...this.defaultMetadataOptions, libraryId};
|
||||
}
|
||||
return this.cachedDefaultOptions[libraryId];
|
||||
}
|
||||
|
||||
trackByLibrary(index: number, library: Library): number | undefined {
|
||||
return library.id;
|
||||
}
|
||||
|
||||
private saveDefaultMetadataOptions(options: MetadataRefreshOptions) {
|
||||
const settingsToSave = [
|
||||
{
|
||||
key: AppSettingKey.QUICK_BOOK_MATCH,
|
||||
newValue: options
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(settingsToSave).subscribe({
|
||||
next: () => {
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsLibMeta.defaultSettings.saveSuccess'));
|
||||
this.updateLibrariesUsingDefaults();
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error saving default metadata options:', error);
|
||||
this.showMessage('error', this.t.translate('settingsLibMeta.defaultSettings.saveFailed'), this.t.translate('settingsLibMeta.defaultSettings.saveError'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private saveLibraryMetadataOptions() {
|
||||
const libraryOptionsArray = Object.values(this.libraryMetadataOptions).filter(option =>
|
||||
option.libraryId !== null && option.libraryId !== undefined
|
||||
);
|
||||
|
||||
const settingsToSave = [
|
||||
{
|
||||
key: AppSettingKey.LIBRARY_METADATA_REFRESH_OPTIONS,
|
||||
newValue: libraryOptionsArray
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(settingsToSave).subscribe({
|
||||
next: () => {
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsLibMeta.libraryOverrides.saveSuccess'));
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error saving library metadata options:', error);
|
||||
this.showMessage('error', this.t.translate('settingsLibMeta.libraryOverrides.saveFailed'), this.t.translate('settingsLibMeta.libraryOverrides.saveError'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private updateLibrariesUsingDefaults() {
|
||||
Object.keys(this.libraryMetadataOptions).forEach(libraryIdStr => {
|
||||
const libraryId = parseInt(libraryIdStr, 10);
|
||||
if (!this.hasLibrarySpecificOptionsInSettings(libraryId)) {
|
||||
delete this.libraryMetadataOptions[libraryId];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private showMessage(severity: 'success' | 'error', summary: string, detail: string) {
|
||||
this.messageService.add({
|
||||
severity,
|
||||
summary,
|
||||
detail,
|
||||
life: 5000
|
||||
});
|
||||
}
|
||||
|
||||
private initializeLibraryOptions(appSettings: AppSettings) {
|
||||
if (appSettings?.libraryMetadataRefreshOptions) {
|
||||
appSettings.libraryMetadataRefreshOptions.forEach(option => {
|
||||
if (option.libraryId) {
|
||||
this.libraryMetadataOptions[option.libraryId] = option;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private updateLibraryOptionsFromSettings(appSettings: AppSettings) {
|
||||
void appSettings;
|
||||
Object.keys(this.libraryMetadataOptions).forEach(libraryIdStr => {
|
||||
const libraryId = parseInt(libraryIdStr, 10);
|
||||
if (!this.hasLibrarySpecificOptions(libraryId)) {
|
||||
this.libraryMetadataOptions[libraryId] = {...this.defaultMetadataOptions};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private hasLibrarySpecificOptions(libraryId: number): boolean {
|
||||
return libraryId in this.libraryMetadataOptions;
|
||||
}
|
||||
|
||||
private hasLibrarySpecificOptionsInSettings(libraryId: number): boolean {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
return settings?.libraryMetadataRefreshOptions?.some(
|
||||
option => option.libraryId === libraryId
|
||||
) || false;
|
||||
}
|
||||
|
||||
private getLibrarySpecificOptions(libraryId: number): MetadataRefreshOptions | null {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
return settings?.libraryMetadataRefreshOptions?.find(
|
||||
option => option.libraryId === libraryId
|
||||
) || null;
|
||||
}
|
||||
|
||||
private getDefaultMetadataOptions(): MetadataRefreshOptions {
|
||||
return {
|
||||
libraryId: null,
|
||||
refreshCovers: false,
|
||||
mergeCategories: false,
|
||||
reviewBeforeApply: false,
|
||||
fieldOptions: {
|
||||
title: {p1: null, p2: null, p3: null, p4: null},
|
||||
subtitle: {p1: null, p2: null, p3: null, p4: null},
|
||||
description: {p1: null, p2: null, p3: null, p4: null},
|
||||
authors: {p1: null, p2: null, p3: null, p4: null},
|
||||
publisher: {p1: null, p2: null, p3: null, p4: null},
|
||||
publishedDate: {p1: null, p2: null, p3: null, p4: null},
|
||||
seriesName: {p1: null, p2: null, p3: null, p4: null},
|
||||
seriesNumber: {p1: null, p2: null, p3: null, p4: null},
|
||||
seriesTotal: {p1: null, p2: null, p3: null, p4: null},
|
||||
isbn13: {p1: null, p2: null, p3: null, p4: null},
|
||||
isbn10: {p1: null, p2: null, p3: null, p4: null},
|
||||
language: {p1: null, p2: null, p3: null, p4: null},
|
||||
categories: {p1: null, p2: null, p3: null, p4: null},
|
||||
cover: {p1: null, p2: null, p3: null, p4: null},
|
||||
pageCount: {p1: null, p2: null, p3: null, p4: null},
|
||||
asin: {p1: null, p2: null, p3: null, p4: null},
|
||||
goodreadsId: {p1: null, p2: null, p3: null, p4: null},
|
||||
comicvineId: {p1: null, p2: null, p3: null, p4: null},
|
||||
hardcoverId: {p1: null, p2: null, p3: null, p4: null},
|
||||
hardcoverBookId: {p1: null, p2: null, p3: null, p4: null},
|
||||
googleId: {p1: null, p2: null, p3: null, p4: null},
|
||||
amazonRating: {p1: null, p2: null, p3: null, p4: null},
|
||||
amazonReviewCount: {p1: null, p2: null, p3: null, p4: null},
|
||||
goodreadsRating: {p1: null, p2: null, p3: null, p4: null},
|
||||
goodreadsReviewCount: {p1: null, p2: null, p3: null, p4: null},
|
||||
hardcoverRating: {p1: null, p2: null, p3: null, p4: null},
|
||||
hardcoverReviewCount: {p1: null, p2: null, p3: null, p4: null},
|
||||
lubimyczytacId: {p1: null, p2: null, p3: null, p4: null},
|
||||
lubimyczytacRating: {p1: null, p2: null, p3: null, p4: null},
|
||||
ranobedbId: {p1: null, p2: null, p3: null, p4: null},
|
||||
ranobedbRating: {p1: null, p2: null, p3: null, p4: null},
|
||||
audibleId: {p1: null, p2: null, p3: null, p4: null},
|
||||
audibleRating: {p1: null, p2: null, p3: null, p4: null},
|
||||
audibleReviewCount: {p1: null, p2: null, p3: null, p4: null},
|
||||
moods: {p1: null, p2: null, p3: null, p4: null},
|
||||
tags: {p1: null, p2: null, p3: null, p4: null}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exportSidecarForLibrary(libraryId: number, event: Event): void {
|
||||
event.stopPropagation();
|
||||
this.sidecarExporting[libraryId] = true;
|
||||
|
||||
this.sidecarService.bulkExport(libraryId).subscribe({
|
||||
next: (response) => {
|
||||
this.sidecarExporting[libraryId] = false;
|
||||
this.showMessage('success', this.t.translate('settingsLibMeta.libraryOverrides.exportComplete'), this.t.translate('settingsLibMeta.libraryOverrides.exportSuccess', {count: response.exported}));
|
||||
},
|
||||
error: (error) => {
|
||||
this.sidecarExporting[libraryId] = false;
|
||||
console.error('Bulk sidecar export failed:', error);
|
||||
this.showMessage('error', this.t.translate('settingsLibMeta.libraryOverrides.exportFailed'), this.t.translate('settingsLibMeta.libraryOverrides.exportError'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
importSidecarForLibrary(libraryId: number, event: Event): void {
|
||||
event.stopPropagation();
|
||||
this.sidecarImporting[libraryId] = true;
|
||||
|
||||
this.sidecarService.bulkImport(libraryId).subscribe({
|
||||
next: (response) => {
|
||||
this.sidecarImporting[libraryId] = false;
|
||||
this.showMessage('success', this.t.translate('settingsLibMeta.libraryOverrides.importComplete'), this.t.translate('settingsLibMeta.libraryOverrides.importSuccess', {count: response.imported}));
|
||||
},
|
||||
error: (error) => {
|
||||
this.sidecarImporting[libraryId] = false;
|
||||
console.error('Bulk sidecar import failed:', error);
|
||||
this.showMessage('error', this.t.translate('settingsLibMeta.libraryOverrides.importFailed'), this.t.translate('settingsLibMeta.libraryOverrides.importError'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
isSidecarExporting(libraryId: number): boolean {
|
||||
return this.sidecarExporting[libraryId] ?? false;
|
||||
}
|
||||
|
||||
isSidecarImporting(libraryId: number): boolean {
|
||||
return this.sidecarImporting[libraryId] ?? false;
|
||||
}
|
||||
}
|
||||
+250
@@ -0,0 +1,250 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsMeta.persistence'">
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-save"></i>
|
||||
{{ t('sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@if (isNetworkStorage) {
|
||||
<div class="section-notice">
|
||||
<div class="info-notice">
|
||||
<i class="pi pi-lock"></i>
|
||||
<div>
|
||||
<strong>{{ t('networkModeTitle') }}</strong> {{ t('networkModeDesc') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="section-notice">
|
||||
<div class="warning-notice">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<div>
|
||||
<strong>{{ t('networkWarningTitle') }}</strong> {{ t('networkWarning') }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-notice unsupported-formats-note">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<div>
|
||||
<strong>Note:</strong> <span [innerHTML]="t('unsupportedNote')"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="section-body" [class.network-disabled]="isNetworkStorage">
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.saveToOriginalFile.epub.enabled"
|
||||
(onChange)="onSaveToOriginalFileToggle('epub')"
|
||||
[disabled]="isNetworkStorage">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('writeEpub') }}</label>
|
||||
</div>
|
||||
<p class="setting-description">{{ t('writeEpubDesc') }}</p>
|
||||
@if (metadataPersistence.saveToOriginalFile.epub.enabled) {
|
||||
<div class="setting-options">
|
||||
<div class="filesize-input">
|
||||
<label>{{ t('maxFileSize') }}</label>
|
||||
<input
|
||||
type="number"
|
||||
[(ngModel)]="metadataPersistence.saveToOriginalFile.epub.maxFileSizeInMb"
|
||||
(change)="onFilesizeChange('epub')"
|
||||
min="1"
|
||||
max="1000"
|
||||
class="filesize-field">
|
||||
<span class="filesize-unit">MB</span>
|
||||
<i
|
||||
class="pi pi-info-circle"
|
||||
[pTooltip]="t('maxFileSizeTooltip')"
|
||||
tooltipPosition="right">
|
||||
</i>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.saveToOriginalFile.cbx.enabled"
|
||||
(onChange)="onSaveToOriginalFileToggle('cbx')"
|
||||
[disabled]="isNetworkStorage">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('writeCbx') }}</label>
|
||||
</div>
|
||||
<p class="setting-description">{{ t('writeCbxDesc') }}</p>
|
||||
@if (metadataPersistence.saveToOriginalFile.cbx.enabled) {
|
||||
<div class="setting-options">
|
||||
<div class="filesize-input">
|
||||
<label>{{ t('maxFileSize') }}</label>
|
||||
<input
|
||||
type="number"
|
||||
[(ngModel)]="metadataPersistence.saveToOriginalFile.cbx.maxFileSizeInMb"
|
||||
(change)="onFilesizeChange('cbx')"
|
||||
min="1"
|
||||
max="1000"
|
||||
class="filesize-field">
|
||||
<span class="filesize-unit">MB</span>
|
||||
<i
|
||||
class="pi pi-info-circle"
|
||||
[pTooltip]="t('maxFileSizeTooltip')"
|
||||
tooltipPosition="right">
|
||||
</i>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.saveToOriginalFile.pdf.enabled"
|
||||
(onChange)="onSaveToOriginalFileToggle('pdf')"
|
||||
[disabled]="isNetworkStorage">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('writePdf') }}</label>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('writePdfDesc') }}
|
||||
<span class="setting-note">{{ t('writePdfNote') }}</span>
|
||||
</p>
|
||||
@if (metadataPersistence.saveToOriginalFile.pdf.enabled) {
|
||||
<div class="setting-options">
|
||||
<div class="filesize-input">
|
||||
<label>{{ t('maxFileSize') }}</label>
|
||||
<input
|
||||
type="number"
|
||||
[(ngModel)]="metadataPersistence.saveToOriginalFile.pdf.maxFileSizeInMb"
|
||||
(change)="onFilesizeChange('pdf')"
|
||||
min="1"
|
||||
max="1000"
|
||||
class="filesize-field">
|
||||
<span class="filesize-unit">MB</span>
|
||||
<i
|
||||
class="pi pi-info-circle"
|
||||
[pTooltip]="t('maxFileSizeTooltip')"
|
||||
tooltipPosition="right">
|
||||
</i>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.saveToOriginalFile.audiobook.enabled"
|
||||
(onChange)="onSaveToOriginalFileToggle('audiobook')"
|
||||
[disabled]="isNetworkStorage">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('writeAudiobook') }}</label>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('writeAudiobookDesc') }}
|
||||
<span class="setting-note">{{ t('writeAudiobookNote') }}</span>
|
||||
</p>
|
||||
@if (metadataPersistence.saveToOriginalFile.audiobook.enabled) {
|
||||
<div class="setting-options">
|
||||
<div class="filesize-input">
|
||||
<label>{{ t('maxFileSize') }}</label>
|
||||
<input
|
||||
type="number"
|
||||
[(ngModel)]="metadataPersistence.saveToOriginalFile.audiobook.maxFileSizeInMb"
|
||||
(change)="onFilesizeChange('audiobook')"
|
||||
min="1"
|
||||
max="2000"
|
||||
class="filesize-field">
|
||||
<span class="filesize-unit">MB</span>
|
||||
<i
|
||||
class="pi pi-info-circle"
|
||||
[pTooltip]="t('maxFileSizeTooltip')"
|
||||
tooltipPosition="right">
|
||||
</i>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (!isNetworkStorage) {
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.moveFilesToLibraryPattern"
|
||||
(onChange)="onPersistenceToggle('moveFilesToLibraryPattern')">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('autoMove') }}</label>
|
||||
</div>
|
||||
<p class="setting-description">{{ t('autoMoveDesc') }}</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="section-header sidecar-section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-file"></i>
|
||||
{{ t('sidecarTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('sidecarDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body" [class.network-disabled]="isNetworkStorage">
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.sidecarSettings?.enabled"
|
||||
(onChange)="onSidecarToggle('enabled')"
|
||||
[disabled]="isNetworkStorage">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('enableSidecar') }}</label>
|
||||
</div>
|
||||
<p class="setting-description" [innerHTML]="t('enableSidecarDesc')"></p>
|
||||
</div>
|
||||
|
||||
@if (metadataPersistence.sidecarSettings?.enabled) {
|
||||
<div class="setting-item nested-setting">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.sidecarSettings?.writeOnUpdate"
|
||||
(onChange)="onSidecarToggle('writeOnUpdate')"
|
||||
[disabled]="isNetworkStorage">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('writeOnUpdate') }}</label>
|
||||
</div>
|
||||
<p class="setting-description">{{ t('writeOnUpdateDesc') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="setting-item nested-setting">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.sidecarSettings?.writeOnScan"
|
||||
(onChange)="onSidecarToggle('writeOnScan')"
|
||||
[disabled]="isNetworkStorage">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('writeOnScan') }}</label>
|
||||
</div>
|
||||
<p class="setting-description">{{ t('writeOnScanDesc') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="setting-item nested-setting">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.sidecarSettings?.includeCoverFile"
|
||||
(onChange)="onSidecarToggle('includeCoverFile')"
|
||||
[disabled]="isNetworkStorage">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('includeCover') }}</label>
|
||||
</div>
|
||||
<p class="setting-description" [innerHTML]="t('includeCoverDesc')"></p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
@use '../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.section-notice {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.warning-notice {
|
||||
@include settings.settings-warning-notice;
|
||||
}
|
||||
|
||||
.info-notice {
|
||||
@include settings.settings-info-notice;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
@include settings.settings-section-body;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
@include settings.settings-item;
|
||||
}
|
||||
|
||||
.setting-header {
|
||||
@include settings.settings-item-header;
|
||||
}
|
||||
|
||||
.setting-label {
|
||||
@include settings.settings-label;
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
@include settings.settings-item-description;
|
||||
}
|
||||
|
||||
.setting-note {
|
||||
@include settings.settings-note;
|
||||
}
|
||||
|
||||
.setting-options {
|
||||
@include settings.settings-options;
|
||||
}
|
||||
|
||||
.filesize-input {
|
||||
@include settings.settings-filesize-input;
|
||||
}
|
||||
|
||||
.network-disabled {
|
||||
opacity: 0.5;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.sidecar-section-header {
|
||||
margin-top: 1.5rem;
|
||||
padding-top: 1.5rem;
|
||||
border-top: 1px solid var(--surface-border);
|
||||
}
|
||||
|
||||
.nested-setting {
|
||||
margin-left: 1.5rem;
|
||||
padding-left: 1rem;
|
||||
border-left: 2px solid var(--surface-border);
|
||||
}
|
||||
|
||||
code {
|
||||
background: var(--surface-ground);
|
||||
padding: 0.125rem 0.375rem;
|
||||
border-radius: 4px;
|
||||
font-family: monospace;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {AppSettingKey, AppSettings, MetadataPersistenceSettings, SaveToOriginalFileSettings, SidecarSettings} from '../../../../shared/model/app-settings.model';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {SettingsHelperService} from '../../../../shared/service/settings-helper.service';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-persistence-settings-component',
|
||||
imports: [
|
||||
ToggleSwitch,
|
||||
FormsModule,
|
||||
Tooltip,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './metadata-persistence-settings-component.html',
|
||||
styleUrl: './metadata-persistence-settings-component.scss'
|
||||
})
|
||||
export class MetadataPersistenceSettingsComponent implements OnInit {
|
||||
|
||||
metadataPersistence: MetadataPersistenceSettings = {
|
||||
saveToOriginalFile: {
|
||||
epub: {
|
||||
enabled: false,
|
||||
maxFileSizeInMb: 250
|
||||
},
|
||||
pdf: {
|
||||
enabled: false,
|
||||
maxFileSizeInMb: 250
|
||||
},
|
||||
cbx: {
|
||||
enabled: false,
|
||||
maxFileSizeInMb: 250
|
||||
},
|
||||
audiobook: {
|
||||
enabled: false,
|
||||
maxFileSizeInMb: 1000
|
||||
}
|
||||
},
|
||||
convertCbrCb7ToCbz: false,
|
||||
moveFilesToLibraryPattern: false,
|
||||
sidecarSettings: {
|
||||
enabled: false,
|
||||
writeOnUpdate: false,
|
||||
writeOnScan: false,
|
||||
includeCoverFile: false
|
||||
}
|
||||
};
|
||||
|
||||
isNetworkStorage = false;
|
||||
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly settingsHelper = inject(SettingsHelperService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadSettings();
|
||||
}
|
||||
|
||||
onPersistenceToggle(key: keyof MetadataPersistenceSettings): void {
|
||||
if (key !== 'saveToOriginalFile' && key !== 'sidecarSettings') {
|
||||
(this.metadataPersistence as any)[key] = !this.metadataPersistence[key];
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_PERSISTENCE_SETTINGS, this.metadataPersistence);
|
||||
}
|
||||
}
|
||||
|
||||
onSaveToOriginalFileToggle(format: keyof SaveToOriginalFileSettings): void {
|
||||
this.metadataPersistence.saveToOriginalFile[format].enabled =
|
||||
!this.metadataPersistence.saveToOriginalFile[format].enabled;
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_PERSISTENCE_SETTINGS, this.metadataPersistence);
|
||||
}
|
||||
|
||||
onFilesizeChange(format: keyof SaveToOriginalFileSettings): void {
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_PERSISTENCE_SETTINGS, this.metadataPersistence);
|
||||
}
|
||||
|
||||
onSidecarToggle(key: keyof SidecarSettings): void {
|
||||
if (this.metadataPersistence.sidecarSettings) {
|
||||
(this.metadataPersistence.sidecarSettings as any)[key] = !this.metadataPersistence.sidecarSettings[key];
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_PERSISTENCE_SETTINGS, this.metadataPersistence);
|
||||
}
|
||||
}
|
||||
|
||||
private loadSettings(): void {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.initializeSettings(settings);
|
||||
}
|
||||
}
|
||||
|
||||
private initializeSettings(settings: AppSettings): void {
|
||||
this.isNetworkStorage = settings.diskType !== 'LOCAL';
|
||||
if (settings.metadataPersistenceSettings) {
|
||||
const persistenceSettings = settings.metadataPersistenceSettings;
|
||||
|
||||
this.metadataPersistence = {
|
||||
...persistenceSettings,
|
||||
saveToOriginalFile: {
|
||||
epub: {
|
||||
enabled: persistenceSettings.saveToOriginalFile?.epub?.enabled ?? false,
|
||||
maxFileSizeInMb: persistenceSettings.saveToOriginalFile?.epub?.maxFileSizeInMb ?? 250
|
||||
},
|
||||
pdf: {
|
||||
enabled: persistenceSettings.saveToOriginalFile?.pdf?.enabled ?? false,
|
||||
maxFileSizeInMb: persistenceSettings.saveToOriginalFile?.pdf?.maxFileSizeInMb ?? 250
|
||||
},
|
||||
cbx: {
|
||||
enabled: persistenceSettings.saveToOriginalFile?.cbx?.enabled ?? false,
|
||||
maxFileSizeInMb: persistenceSettings.saveToOriginalFile?.cbx?.maxFileSizeInMb ?? 250
|
||||
},
|
||||
audiobook: {
|
||||
enabled: persistenceSettings.saveToOriginalFile?.audiobook?.enabled ?? false,
|
||||
maxFileSizeInMb: persistenceSettings.saveToOriginalFile?.audiobook?.maxFileSizeInMb ?? 1000
|
||||
}
|
||||
},
|
||||
sidecarSettings: {
|
||||
enabled: persistenceSettings.sidecarSettings?.enabled ?? false,
|
||||
writeOnUpdate: persistenceSettings.sidecarSettings?.writeOnUpdate ?? false,
|
||||
writeOnScan: persistenceSettings.sidecarSettings?.writeOnScan ?? false,
|
||||
includeCoverFile: persistenceSettings.sidecarSettings?.includeCoverFile ?? false
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsMeta'">
|
||||
<div class="metadata-settings-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-tags"></i>
|
||||
{{ t('title') }}
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<app-metadata-persistence-settings-component></app-metadata-persistence-settings-component>
|
||||
<div class="section-divider"><hr></div>
|
||||
<div class="preferences-section">
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-download"></i>
|
||||
{{ t('autoDownload.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<span>{{ t('autoDownload.warning') }}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="metadataDownloadOnBookdrop"
|
||||
(onChange)="onMetadataDownloadOnBookdropToggle($event.checked)">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('autoDownload.enableLabel') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<app-metadata-provider-settings></app-metadata-provider-settings>
|
||||
<div class="section-divider"><hr></div>
|
||||
<app-metadata-provider-field-selector></app-metadata-provider-field-selector>
|
||||
<div class="section-divider"><hr></div>
|
||||
<app-public-reviews-settings-component></app-public-reviews-settings-component>
|
||||
<div class="section-divider"><hr></div>
|
||||
<app-metadata-match-weights-component></app-metadata-match-weights-component>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,69 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.metadata-settings-container {
|
||||
@include settings.settings-page-container;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
@include settings.settings-section-divider;
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
color: var(--p-text-muted-color);
|
||||
margin: 0;
|
||||
|
||||
.pi {
|
||||
margin-top: 0.125rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.pi-exclamation-triangle {
|
||||
color: var(--p-orange-500);
|
||||
}
|
||||
|
||||
.pi-info-circle {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.section-body {
|
||||
@include settings.settings-section-body;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
@include settings.settings-item;
|
||||
}
|
||||
|
||||
.setting-header {
|
||||
@include settings.settings-item-header;
|
||||
}
|
||||
|
||||
.setting-label {
|
||||
@include settings.settings-label;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {MetadataProviderSettingsComponent} from '../global-preferences/metadata-provider-settings/metadata-provider-settings.component';
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {MetadataRefreshOptions} from '../../metadata/model/request/metadata-refresh-options.model';
|
||||
import {AppSettingsService} from '../../../shared/service/app-settings.service';
|
||||
import {SettingsHelperService} from '../../../shared/service/settings-helper.service';
|
||||
import {AppSettingKey, AppSettings} from '../../../shared/model/app-settings.model';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {MetadataMatchWeightsComponent} from '../global-preferences/metadata-match-weights/metadata-match-weights-component';
|
||||
import {MetadataPersistenceSettingsComponent} from './metadata-persistence-settings/metadata-persistence-settings-component';
|
||||
import {PublicReviewsSettingsComponent} from './public-reviews-settings/public-reviews-settings-component';
|
||||
import {MetadataProviderFieldSelectorComponent} from '../../metadata/component/metadata-provider-field-selector/metadata-provider-field-selector.component';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-settings-component',
|
||||
standalone: true,
|
||||
imports: [
|
||||
MetadataProviderSettingsComponent,
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
MetadataMatchWeightsComponent,
|
||||
ToggleSwitch,
|
||||
MetadataPersistenceSettingsComponent,
|
||||
PublicReviewsSettingsComponent,
|
||||
MetadataProviderFieldSelectorComponent,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './metadata-settings-component.html',
|
||||
styleUrl: './metadata-settings-component.scss'
|
||||
})
|
||||
export class MetadataSettingsComponent implements OnInit {
|
||||
|
||||
currentMetadataOptions!: MetadataRefreshOptions;
|
||||
metadataDownloadOnBookdrop = true;
|
||||
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly settingsHelper = inject(SettingsHelperService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadSettings();
|
||||
}
|
||||
|
||||
onMetadataDownloadOnBookdropToggle(checked: boolean): void {
|
||||
this.metadataDownloadOnBookdrop = checked;
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_DOWNLOAD_ON_BOOKDROP, checked);
|
||||
}
|
||||
|
||||
onMetadataSubmit(metadataRefreshOptions: MetadataRefreshOptions): void {
|
||||
this.currentMetadataOptions = metadataRefreshOptions;
|
||||
this.settingsHelper.saveSetting(AppSettingKey.QUICK_BOOK_MATCH, metadataRefreshOptions);
|
||||
}
|
||||
|
||||
private loadSettings(): void {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.initializeSettings(settings);
|
||||
}
|
||||
}
|
||||
|
||||
private initializeSettings(settings: AppSettings): void {
|
||||
if (settings.defaultMetadataRefreshOptions) {
|
||||
this.currentMetadataOptions = settings.defaultMetadataRefreshOptions;
|
||||
}
|
||||
|
||||
this.metadataDownloadOnBookdrop = settings.metadataDownloadOnBookdrop ?? true;
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsMeta.publicReviews'">
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-star"></i>
|
||||
{{ t('sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="publicReviewSettings.downloadEnabled"
|
||||
(onChange)="onPublicReviewsToggle($event.checked)">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('downloadLabel') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (publicReviewSettings.downloadEnabled) {
|
||||
<div class="setting-item">
|
||||
<div class="setting-header">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="publicReviewSettings.autoDownloadEnabled"
|
||||
(onChange)="onAutoDownloadToggle($event.checked)">
|
||||
</p-toggleswitch>
|
||||
<label class="setting-label">{{ t('autoDownloadLabel') }}</label>
|
||||
</div>
|
||||
<p class="setting-description">{{ t('autoDownloadDesc') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-header-standalone">
|
||||
<label class="setting-label">{{ t('reviewSources') }}</label>
|
||||
</div>
|
||||
<p class="setting-description">{{ t('reviewSourcesDesc') }}</p>
|
||||
@if (publicReviewSettings.providers.length > 0) {
|
||||
<div class="setting-options">
|
||||
<div class="providers-grid">
|
||||
@for (provider of publicReviewSettings.providers; track provider.provider) {
|
||||
<div class="provider-item">
|
||||
<div class="provider-row">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="provider.enabled"
|
||||
(onChange)="onProviderToggle(provider.provider, $event.checked)">
|
||||
</p-toggleswitch>
|
||||
<label class="provider-label">{{ provider.provider }}</label>
|
||||
</div>
|
||||
@if (provider.enabled) {
|
||||
<div class="max-reviews-control">
|
||||
<label class="max-reviews-label">{{ t('maxLabel') }}</label>
|
||||
<input
|
||||
type="number"
|
||||
class="max-reviews-input"
|
||||
min="1"
|
||||
max="10"
|
||||
[(ngModel)]="provider.maxReviews"
|
||||
(blur)="onMaxReviewsChange(provider.provider, provider.maxReviews)"
|
||||
[title]="t('maxTooltip')">
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="no-providers-message">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<span>{{ t('noProviders') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
@use '../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
@include settings.settings-section-body;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
@include settings.settings-item;
|
||||
}
|
||||
|
||||
.setting-header {
|
||||
@include settings.settings-item-header;
|
||||
}
|
||||
|
||||
.setting-header-standalone {
|
||||
@include settings.settings-item-header-standalone;
|
||||
}
|
||||
|
||||
.setting-label {
|
||||
@include settings.settings-label;
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
@include settings.settings-item-description;
|
||||
}
|
||||
|
||||
.setting-options {
|
||||
@include settings.settings-options;
|
||||
}
|
||||
|
||||
.providers-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
||||
gap: 0.625rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 400px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.provider-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background: var(--ground-background);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 4px;
|
||||
transition: border-color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.provider-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.provider-label {
|
||||
font-weight: settings.$settings-label-weight;
|
||||
color: var(--text-color);
|
||||
font-size: settings.$settings-description-size;
|
||||
}
|
||||
|
||||
.max-reviews-control {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
|
||||
.max-reviews-label {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.max-reviews-input {
|
||||
width: 3rem;
|
||||
padding: 0.25rem 0.375rem;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 4px;
|
||||
background: var(--p-surface-800);
|
||||
color: var(--text-color);
|
||||
font-size: settings.$settings-description-size;
|
||||
text-align: center;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.no-providers-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-description-size;
|
||||
font-style: italic;
|
||||
margin-top: 0.5rem;
|
||||
padding: 0.75rem;
|
||||
background: var(--ground-background);
|
||||
border-radius: 4px;
|
||||
|
||||
.pi {
|
||||
color: var(--p-orange-500);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormsModule} from "@angular/forms";
|
||||
import {ToggleSwitch} from "primeng/toggleswitch";
|
||||
import {AppSettingKey, AppSettings, PublicReviewSettings, ReviewProviderConfig} from '../../../../shared/model/app-settings.model';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {SettingsHelperService} from '../../../../shared/service/settings-helper.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
const DEFAULT_PROVIDERS: readonly ReviewProviderConfig[] = [
|
||||
{provider: 'Amazon', enabled: true, maxReviews: 5},
|
||||
{provider: 'GoodReads', enabled: false, maxReviews: 5},
|
||||
{provider: 'Douban', enabled: false, maxReviews: 5}
|
||||
] as const;
|
||||
|
||||
const REQUIRED_PROVIDERS = ['Amazon', 'GoodReads', 'Douban'] as const;
|
||||
|
||||
@Component({
|
||||
selector: 'app-public-reviews-settings-component',
|
||||
imports: [FormsModule, ToggleSwitch, TranslocoDirective],
|
||||
templateUrl: './public-reviews-settings-component.html',
|
||||
styleUrl: './public-reviews-settings-component.scss'
|
||||
})
|
||||
export class PublicReviewsSettingsComponent implements OnInit {
|
||||
|
||||
publicReviewSettings: PublicReviewSettings = {
|
||||
downloadEnabled: true,
|
||||
autoDownloadEnabled: false,
|
||||
providers: [...DEFAULT_PROVIDERS]
|
||||
};
|
||||
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly settingsHelper = inject(SettingsHelperService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadSettings();
|
||||
}
|
||||
|
||||
onPublicReviewsToggle(checked: boolean): void {
|
||||
this.publicReviewSettings.downloadEnabled = checked;
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_PUBLIC_REVIEWS_SETTINGS, this.publicReviewSettings);
|
||||
}
|
||||
|
||||
onAutoDownloadToggle(checked: boolean): void {
|
||||
this.publicReviewSettings.autoDownloadEnabled = checked;
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_PUBLIC_REVIEWS_SETTINGS, this.publicReviewSettings);
|
||||
}
|
||||
|
||||
onProviderToggle(providerName: string, enabled: boolean): void {
|
||||
this.updateProviderProperty(providerName, 'enabled', enabled);
|
||||
}
|
||||
|
||||
onMaxReviewsChange(providerName: string, maxReviews: number): void {
|
||||
this.updateProviderProperty(providerName, 'maxReviews', maxReviews);
|
||||
}
|
||||
|
||||
private loadSettings(): void {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.initializeSettings(settings);
|
||||
}
|
||||
}
|
||||
|
||||
private initializeSettings(settings: AppSettings): void {
|
||||
if (settings.metadataPublicReviewsSettings) {
|
||||
this.publicReviewSettings = {...settings.metadataPublicReviewsSettings};
|
||||
}
|
||||
|
||||
this.ensureAllProviders();
|
||||
}
|
||||
|
||||
private updateProviderProperty<T extends keyof ReviewProviderConfig>(
|
||||
providerName: string,
|
||||
property: T,
|
||||
value: ReviewProviderConfig[T]
|
||||
): void {
|
||||
const provider = this.findProvider(providerName);
|
||||
if (provider) {
|
||||
provider[property] = value;
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_PUBLIC_REVIEWS_SETTINGS, this.publicReviewSettings);
|
||||
}
|
||||
}
|
||||
|
||||
private findProvider(providerName: string): ReviewProviderConfig | undefined {
|
||||
return this.publicReviewSettings.providers.find(p => p.provider === providerName);
|
||||
}
|
||||
|
||||
private ensureAllProviders(): void {
|
||||
REQUIRED_PROVIDERS.forEach(providerName => {
|
||||
const exists = this.findProvider(providerName);
|
||||
if (!exists) {
|
||||
this.publicReviewSettings.providers.push({
|
||||
provider: providerName,
|
||||
enabled: false,
|
||||
maxReviews: 10
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsOpds'">
|
||||
<div class="main-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-server"></i>
|
||||
{{ t('title') }}
|
||||
<app-external-doc-link docType="opds"></app-external-doc-link>
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@if (hasPermission) {
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-sliders-h"></i>
|
||||
{{ t('server.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('server.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
<div class="toggle-list">
|
||||
<div class="toggle-item" [class.is-active]="opdsEnabled">
|
||||
<div class="toggle-content">
|
||||
<div class="toggle-header">
|
||||
<div class="toggle-icon">
|
||||
<i class="pi pi-globe"></i>
|
||||
</div>
|
||||
<div class="toggle-info">
|
||||
<span class="toggle-label">{{ t('server.opdsLabel') }}</span>
|
||||
<span class="toggle-status" [class.active]="opdsEnabled">
|
||||
{{ opdsEnabled ? t('server.enabled') : t('server.disabled') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="toggle-description">
|
||||
{{ t('server.opdsDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="opdsEnabled"
|
||||
(onChange)="toggleOpdsServer()">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
|
||||
<div class="toggle-item" [class.is-active]="komgaApiEnabled">
|
||||
<div class="toggle-content">
|
||||
<div class="toggle-header">
|
||||
<div class="toggle-icon">
|
||||
<i class="pi pi-box"></i>
|
||||
</div>
|
||||
<div class="toggle-info">
|
||||
<span class="toggle-label">{{ t('server.komgaLabel') }}</span>
|
||||
<span class="toggle-status" [class.active]="komgaApiEnabled">
|
||||
{{ komgaApiEnabled ? t('server.enabled') : t('server.disabled') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="toggle-description">
|
||||
{{ t('server.komgaDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="komgaApiEnabled"
|
||||
(onChange)="toggleKomgaApi()">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
|
||||
@if (komgaApiEnabled) {
|
||||
<div class="toggle-item sub-item" [class.is-active]="komgaGroupUnknown">
|
||||
<div class="toggle-content">
|
||||
<div class="toggle-header">
|
||||
<div class="toggle-icon sub-icon">
|
||||
<i class="pi pi-folder"></i>
|
||||
</div>
|
||||
<div class="toggle-info">
|
||||
<span class="toggle-label">{{ t('server.groupUnknownLabel') }}</span>
|
||||
<span class="toggle-status" [class.active]="komgaGroupUnknown">
|
||||
{{ komgaGroupUnknown ? t('server.grouped') : t('server.individual') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="toggle-description">
|
||||
{{ t('server.groupUnknownDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="komgaGroupUnknown"
|
||||
(onChange)="toggleKomgaGroupUnknown()">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (opdsEnabled || komgaApiEnabled) {
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-link"></i>
|
||||
{{ t('endpoints.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('endpoints.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
<div class="endpoints-list">
|
||||
@if (opdsEnabled) {
|
||||
<div class="endpoint-item">
|
||||
<div class="endpoint-header">
|
||||
<div class="endpoint-icon">
|
||||
<i class="pi pi-globe"></i>
|
||||
</div>
|
||||
<div class="endpoint-info">
|
||||
<span class="endpoint-label">{{ t('endpoints.opdsCatalog') }}</span>
|
||||
<span class="endpoint-hint">{{ t('endpoints.opdsHint') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="endpoint-url-row">
|
||||
<input
|
||||
id="endpoint-url"
|
||||
class="endpoint-input"
|
||||
type="text"
|
||||
pInputText
|
||||
[value]="opdsEndpoint"
|
||||
readonly/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
severity="info"
|
||||
[outlined]="true"
|
||||
size="small"
|
||||
(onClick)="copyEndpoint()"
|
||||
[pTooltip]="t('endpoints.copyUrl')">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (komgaApiEnabled) {
|
||||
<div class="endpoint-item">
|
||||
<div class="endpoint-header">
|
||||
<div class="endpoint-icon">
|
||||
<i class="pi pi-box"></i>
|
||||
</div>
|
||||
<div class="endpoint-info">
|
||||
<span class="endpoint-label">{{ t('endpoints.komgaBase') }}</span>
|
||||
<span class="endpoint-hint">{{ t('endpoints.komgaHint') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="endpoint-url-row">
|
||||
<input
|
||||
id="komga-endpoint-url"
|
||||
class="endpoint-input"
|
||||
type="text"
|
||||
pInputText
|
||||
[value]="komgaEndpoint"
|
||||
readonly/>
|
||||
<p-button
|
||||
icon="pi pi-copy"
|
||||
severity="info"
|
||||
[outlined]="true"
|
||||
size="small"
|
||||
(onClick)="copyKomgaEndpoint()"
|
||||
[pTooltip]="t('endpoints.copyUrl')">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (opdsEnabled) {
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<div class="section-header-row">
|
||||
<div class="section-header-text">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-users"></i>
|
||||
{{ t('users.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('users.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
<p-button
|
||||
icon="pi pi-plus"
|
||||
[label]="t('users.addUser')"
|
||||
severity="success"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
(onClick)="showCreateUserDialog = true">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
@if (users.length === 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-users"></i>
|
||||
<p class="empty-title">{{ t('users.emptyTitle') }}</p>
|
||||
<p class="empty-subtitle">{{ t('users.emptySubtitle') }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="users-list">
|
||||
@for (user of users; track user.id) {
|
||||
<div class="user-item">
|
||||
<div class="user-info">
|
||||
<div class="user-avatar">
|
||||
{{ user.username.charAt(0).toUpperCase() }}
|
||||
</div>
|
||||
<div class="user-details">
|
||||
<span class="username">{{ user.username }}</span>
|
||||
<div class="user-meta">
|
||||
<i class="pi pi-sort-alt"></i>
|
||||
@if (editingUserId === user.id) {
|
||||
<p-select
|
||||
[options]="sortOrderOptions"
|
||||
[(ngModel)]="editingSortOrder"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[style]="{width: '160px'}"
|
||||
size="small"
|
||||
[appendTo]="'body'">
|
||||
<ng-template pTemplate="selectedItem" let-selected>
|
||||
{{ selected.translationKey | transloco }}
|
||||
</ng-template>
|
||||
<ng-template pTemplate="item" let-option>
|
||||
{{ option.translationKey | transloco }}
|
||||
</ng-template>
|
||||
</p-select>
|
||||
} @else {
|
||||
<span class="sort-order-badge">{{ getSortOrderLabel(user.sortOrder) }}</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-actions">
|
||||
@if (editingUserId === user.id) {
|
||||
<p-button
|
||||
icon="pi pi-check"
|
||||
severity="success"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="saveSortOrder(user)"
|
||||
[pTooltip]="'common.save' | transloco">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
severity="secondary"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="cancelEdit()"
|
||||
[pTooltip]="'common.cancel' | transloco">
|
||||
</p-button>
|
||||
} @else {
|
||||
<p-button
|
||||
icon="pi pi-pencil"
|
||||
severity="info"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="startEdit(user)"
|
||||
[pTooltip]="t('users.editSortOrder')">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
severity="danger"
|
||||
size="small"
|
||||
[outlined]="true"
|
||||
[rounded]="true"
|
||||
(onClick)="confirmDelete(user)"
|
||||
[pTooltip]="t('users.deleteUser')">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<p-dialog
|
||||
[header]="t('createDialog.title')"
|
||||
[(visible)]="showCreateUserDialog"
|
||||
[modal]="true"
|
||||
class="user-dialog"
|
||||
[style]="{width: '400px'}">
|
||||
<div class="dialog-form">
|
||||
<div class="form-field">
|
||||
<label for="username">{{ t('createDialog.username') }}</label>
|
||||
<input
|
||||
id="username"
|
||||
type="text"
|
||||
pInputText
|
||||
[(ngModel)]="newUser.username"
|
||||
[placeholder]="t('createDialog.enterUsername')"/>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label for="password">{{ t('createDialog.password') }}</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
pInputText
|
||||
[(ngModel)]="newUser.password"
|
||||
[placeholder]="t('createDialog.enterPassword')"/>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label for="sortOrder">{{ t('createDialog.sortOrder') }}</label>
|
||||
<p-select
|
||||
id="sortOrder"
|
||||
[options]="sortOrderOptions"
|
||||
[(ngModel)]="newUser.sortOrder"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[style]="{width: '100%'}"
|
||||
[placeholder]="t('createDialog.selectSortOrder')"
|
||||
[appendTo]="'body'">
|
||||
<ng-template pTemplate="selectedItem" let-selected>
|
||||
{{ selected.translationKey | transloco }}
|
||||
</ng-template>
|
||||
<ng-template pTemplate="item" let-option>
|
||||
{{ option.translationKey | transloco }}
|
||||
</ng-template>
|
||||
</p-select>
|
||||
<small class="form-hint">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
{{ t('createDialog.sortHint') }}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<ng-template pTemplate="footer">
|
||||
<div class="dialog-actions">
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
severity="secondary"
|
||||
outlined="true"
|
||||
(onClick)="cancelCreateUser()">
|
||||
</p-button>
|
||||
<p-button
|
||||
[label]="t('createDialog.create')"
|
||||
severity="success"
|
||||
[disabled]="!newUser.username || !newUser.password"
|
||||
(onClick)="createUser()">
|
||||
</p-button>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
|
||||
<p-confirmDialog></p-confirmDialog>
|
||||
} @else {
|
||||
<div class="access-denied-card">
|
||||
<i class="pi pi-lock"></i>
|
||||
<div class="access-denied-content">
|
||||
<h3>{{ t('accessRestricted') }}</h3>
|
||||
<p>
|
||||
{{ t('accessDenied') }}
|
||||
<br>
|
||||
{{ t('contactAdmin') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,485 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.main-container {
|
||||
@include settings.settings-page-container;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
}
|
||||
|
||||
.section-header-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
p-button {
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.section-header-text {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
@include settings.settings-section-body;
|
||||
}
|
||||
|
||||
// Toggle list (Server Settings)
|
||||
.toggle-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.toggle-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-left: 3px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
padding: 1rem;
|
||||
transition: border-color 0.2s ease, background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
border-left-color: var(--p-green-500);
|
||||
}
|
||||
|
||||
&.sub-item {
|
||||
margin-left: 1.5rem;
|
||||
border-left-color: var(--p-orange-500);
|
||||
|
||||
&.is-active {
|
||||
border-left-color: var(--p-green-500);
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.toggle-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.toggle-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.toggle-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
border-radius: 8px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.pi {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
&.sub-icon {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
background: color-mix(in srgb, var(--p-orange-500) 15%, transparent);
|
||||
color: var(--p-orange-500);
|
||||
border-radius: 6px;
|
||||
|
||||
.pi {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.toggle-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.125rem;
|
||||
}
|
||||
|
||||
.toggle-label {
|
||||
font-weight: 600;
|
||||
font-size: 0.9375rem;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.toggle-status {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
&.active {
|
||||
color: var(--p-green-400);
|
||||
}
|
||||
}
|
||||
|
||||
.toggle-description {
|
||||
font-size: settings.$settings-description-size;
|
||||
color: var(--p-text-muted-color);
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
padding-left: calc(36px + 0.75rem);
|
||||
|
||||
@media (max-width: 600px) {
|
||||
padding-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Endpoints list
|
||||
.endpoints-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.endpoint-item {
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-left: 3px solid var(--p-primary-color);
|
||||
border-radius: 6px;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.endpoint-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.endpoint-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
border-radius: 6px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.pi {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.endpoint-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.125rem;
|
||||
}
|
||||
|
||||
.endpoint-label {
|
||||
font-weight: 600;
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.endpoint-hint {
|
||||
font-size: settings.$settings-description-size;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.endpoint-url-row {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
|
||||
@media (max-width: 600px) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
p-button {
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.endpoint-input {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
font-family: monospace;
|
||||
font-size: settings.$settings-description-size;
|
||||
}
|
||||
|
||||
// Empty state
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 2rem;
|
||||
text-align: center;
|
||||
color: var(--p-text-muted-color);
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border-radius: 6px;
|
||||
|
||||
.pi {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 1rem;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
margin: 0 0 0.5rem 0;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.empty-subtitle {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Users list
|
||||
.users-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.user-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-left: 3px solid var(--p-primary-color);
|
||||
border-radius: 6px;
|
||||
padding: 0.875rem 1rem;
|
||||
transition: background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.user-avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
background: var(--p-primary-color);
|
||||
color: var(--p-primary-contrast-color);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.user-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.username {
|
||||
font-weight: 600;
|
||||
font-size: 0.9375rem;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.user-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: settings.$settings-description-size;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
.pi {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.sort-order-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.125rem 0.5rem;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
border-radius: 12px;
|
||||
font-size: 0.6875rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.user-actions {
|
||||
display: flex;
|
||||
gap: 0.375rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
@media (max-width: 600px) {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
// Dialog styles
|
||||
.user-dialog {
|
||||
.p-dialog-content {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.p-dialog-footer {
|
||||
padding: 1rem 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
.form-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
label {
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
transition: border-color 0.2s;
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
border-color: var(--p-primary-color);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--p-primary-color) 20%, transparent);
|
||||
}
|
||||
|
||||
&::placeholder {
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.375rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.4;
|
||||
margin-top: 0.25rem;
|
||||
|
||||
.pi {
|
||||
font-size: 0.625rem;
|
||||
margin-top: 0.125rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
// Access denied card
|
||||
.access-denied-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 1.5rem;
|
||||
border-radius: settings.$settings-card-border-radius;
|
||||
background: color-mix(in srgb, var(--ground-background) 85%, var(--p-red-600) 15%);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-left: 3px solid var(--p-red-500);
|
||||
max-width: 500px;
|
||||
|
||||
> .pi {
|
||||
font-size: 1.5rem;
|
||||
flex-shrink: 0;
|
||||
color: var(--p-red-400);
|
||||
}
|
||||
|
||||
.access-denied-content {
|
||||
h3 {
|
||||
margin: 0 0 0.5rem 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-red-300);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
import {Component, effect, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
|
||||
import {Button} from 'primeng/button';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {Dialog} from 'primeng/dialog';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {OpdsService, OpdsSortOrder, OpdsUserV2, OpdsUserV2CreateRequest} from './opds.service';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {UserService} from '../user-management/user.service';
|
||||
import {of, Subject} from 'rxjs';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {AppSettingsService} from '../../../shared/service/app-settings.service';
|
||||
import {AppSettingKey} from '../../../shared/model/app-settings.model';
|
||||
import {ExternalDocLinkComponent} from '../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import {Select} from 'primeng/select';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-opds-settings',
|
||||
imports: [
|
||||
Button,
|
||||
InputText,
|
||||
Tooltip,
|
||||
Dialog,
|
||||
FormsModule,
|
||||
ConfirmDialog,
|
||||
TableModule,
|
||||
ToggleSwitch,
|
||||
ExternalDocLinkComponent,
|
||||
Select,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
],
|
||||
providers: [ConfirmationService],
|
||||
templateUrl: './opds-settings.html',
|
||||
styleUrl: './opds-settings.scss'
|
||||
})
|
||||
export class OpdsSettings implements OnInit, OnDestroy {
|
||||
|
||||
opdsEndpoint = `${API_CONFIG.BASE_URL}/api/v1/opds`;
|
||||
komgaEndpoint = `${API_CONFIG.BASE_URL}/komga`;
|
||||
opdsEnabled = false;
|
||||
komgaApiEnabled = false;
|
||||
komgaGroupUnknown = true;
|
||||
|
||||
private opdsService = inject(OpdsService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private messageService = inject(MessageService);
|
||||
private userService = inject(UserService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
users: OpdsUserV2[] = [];
|
||||
loading = false;
|
||||
showCreateUserDialog = false;
|
||||
newUser: OpdsUserV2CreateRequest = {username: '', password: '', sortOrder: 'RECENT'};
|
||||
passwordVisibility: boolean[] = [];
|
||||
hasPermission = false;
|
||||
|
||||
editingUserId: number | null = null;
|
||||
editingSortOrder: OpdsSortOrder | null = null;
|
||||
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
dummyPassword: string = "***********************";
|
||||
|
||||
sortOrderOptions = [
|
||||
{label: 'Recently Added', value: 'RECENT' as OpdsSortOrder, translationKey: 'settingsOpds.sortOrders.recent'},
|
||||
{label: 'Title (A-Z)', value: 'TITLE_ASC' as OpdsSortOrder, translationKey: 'settingsOpds.sortOrders.titleAsc'},
|
||||
{label: 'Title (Z-A)', value: 'TITLE_DESC' as OpdsSortOrder, translationKey: 'settingsOpds.sortOrders.titleDesc'},
|
||||
{label: 'Author (A-Z)', value: 'AUTHOR_ASC' as OpdsSortOrder, translationKey: 'settingsOpds.sortOrders.authorAsc'},
|
||||
{label: 'Author (Z-A)', value: 'AUTHOR_DESC' as OpdsSortOrder, translationKey: 'settingsOpds.sortOrders.authorDesc'},
|
||||
{label: 'Series (A-Z)', value: 'SERIES_ASC' as OpdsSortOrder, translationKey: 'settingsOpds.sortOrders.seriesAsc'},
|
||||
{label: 'Series (Z-A)', value: 'SERIES_DESC' as OpdsSortOrder, translationKey: 'settingsOpds.sortOrders.seriesDesc'},
|
||||
{label: 'Rating (Low to High)', value: 'RATING_ASC' as OpdsSortOrder, translationKey: 'settingsOpds.sortOrders.ratingAsc'},
|
||||
{label: 'Rating (High to Low)', value: 'RATING_DESC' as OpdsSortOrder, translationKey: 'settingsOpds.sortOrders.ratingDesc'}
|
||||
];
|
||||
|
||||
private prevHasPermission = false;
|
||||
|
||||
private readonly syncPermissionEffect = effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (!user) return;
|
||||
|
||||
this.hasPermission = !!(user.permissions.canAccessOpds || user.permissions.admin);
|
||||
if (this.hasPermission && !this.prevHasPermission) {
|
||||
this.loadAppSettings();
|
||||
}
|
||||
this.prevHasPermission = this.hasPermission;
|
||||
});
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loading = true;
|
||||
}
|
||||
|
||||
private loadAppSettings(): void {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
if (settings) {
|
||||
this.opdsEnabled = settings.opdsServerEnabled ?? false;
|
||||
this.komgaApiEnabled = settings.komgaApiEnabled ?? false;
|
||||
this.komgaGroupUnknown = settings.komgaGroupUnknown ?? true;
|
||||
if (this.opdsEnabled || this.komgaApiEnabled) {
|
||||
this.loadUsers();
|
||||
} else {
|
||||
this.loading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private loadUsers(): void {
|
||||
this.opdsService.getUser().pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError(err => {
|
||||
console.error('Error loading users:', err);
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsOpds.loadError'));
|
||||
return of([]);
|
||||
})
|
||||
).subscribe(users => {
|
||||
this.users = users;
|
||||
this.passwordVisibility = new Array(users.length).fill(false);
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
createUser(): void {
|
||||
if (!this.newUser.username || !this.newUser.password) return;
|
||||
|
||||
this.opdsService.createUser(this.newUser).pipe(
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe({
|
||||
next: user => {
|
||||
this.users.push(user);
|
||||
this.resetCreateUserDialog();
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsOpds.createSuccess'));
|
||||
},
|
||||
error: err => {
|
||||
console.error('Error creating user:', err);
|
||||
const message = err?.error?.message || this.t.translate('settingsOpds.createError');
|
||||
this.showMessage('error', this.t.translate('common.error'), message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
confirmDelete(user: OpdsUserV2): void {
|
||||
this.confirmationService.confirm({
|
||||
message: this.t.translate('settingsOpds.deleteConfirm', {username: user.username}),
|
||||
header: this.t.translate('settingsOpds.deleteHeader'),
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => this.deleteUser(user)
|
||||
});
|
||||
}
|
||||
|
||||
deleteUser(user: OpdsUserV2): void {
|
||||
if (!user.id) return;
|
||||
|
||||
this.opdsService.deleteCredential(user.id).pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError(err => {
|
||||
console.error('Error deleting user:', err);
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsOpds.deleteError'));
|
||||
return of(null);
|
||||
})
|
||||
).subscribe(() => {
|
||||
this.users = this.users.filter(u => u.id !== user.id);
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsOpds.deleteSuccess'));
|
||||
});
|
||||
}
|
||||
|
||||
cancelCreateUser(): void {
|
||||
this.resetCreateUserDialog();
|
||||
}
|
||||
|
||||
copyEndpoint(): void {
|
||||
navigator.clipboard.writeText(this.opdsEndpoint).then(() => {
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsOpds.opdsCopied'));
|
||||
});
|
||||
}
|
||||
|
||||
toggleOpdsServer(): void {
|
||||
this.saveSetting(AppSettingKey.OPDS_SERVER_ENABLED, this.opdsEnabled);
|
||||
if (this.opdsEnabled || this.komgaApiEnabled) {
|
||||
this.loadUsers();
|
||||
} else {
|
||||
this.users = [];
|
||||
}
|
||||
}
|
||||
|
||||
toggleKomgaApi(): void {
|
||||
this.saveKomgaSetting(AppSettingKey.KOMGA_API_ENABLED, this.komgaApiEnabled);
|
||||
if (this.opdsEnabled || this.komgaApiEnabled) {
|
||||
this.loadUsers();
|
||||
} else {
|
||||
this.users = [];
|
||||
}
|
||||
}
|
||||
|
||||
copyKomgaEndpoint(): void {
|
||||
navigator.clipboard.writeText(this.komgaEndpoint).then(() => {
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsOpds.komgaCopied'));
|
||||
});
|
||||
}
|
||||
|
||||
toggleKomgaGroupUnknown(): void {
|
||||
this.appSettingsService.saveSettings([{key: AppSettingKey.KOMGA_GROUP_UNKNOWN, newValue: this.komgaGroupUnknown}]).subscribe({
|
||||
next: () => {
|
||||
const successMessage = (this.komgaGroupUnknown === true)
|
||||
? this.t.translate('settingsOpds.groupEnabled')
|
||||
: this.t.translate('settingsOpds.groupDisabled');
|
||||
this.showMessage('success', this.t.translate('settingsOpds.settingsSaved'), successMessage);
|
||||
},
|
||||
error: () => {
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsOpds.settingsError'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private saveSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
next: () => {
|
||||
const successMessage = (value === true)
|
||||
? this.t.translate('settingsOpds.opdsEnabled')
|
||||
: this.t.translate('settingsOpds.opdsDisabled');
|
||||
this.showMessage('success', this.t.translate('settingsOpds.settingsSaved'), successMessage);
|
||||
},
|
||||
error: () => {
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsOpds.settingsError'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private saveKomgaSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
next: () => {
|
||||
const successMessage = (value === true)
|
||||
? this.t.translate('settingsOpds.komgaEnabled')
|
||||
: this.t.translate('settingsOpds.komgaDisabled');
|
||||
this.showMessage('success', this.t.translate('settingsOpds.settingsSaved'), successMessage);
|
||||
},
|
||||
error: () => {
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsOpds.settingsError'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private resetCreateUserDialog(): void {
|
||||
this.showCreateUserDialog = false;
|
||||
this.newUser = {username: '', password: '', sortOrder: 'RECENT'};
|
||||
}
|
||||
|
||||
private showMessage(severity: string, summary: string, detail: string): void {
|
||||
this.messageService.add({severity, summary, detail});
|
||||
}
|
||||
|
||||
getSortOrderLabel(sortOrder?: OpdsSortOrder): string {
|
||||
if (!sortOrder) return this.t.translate('settingsOpds.sortOrders.recent');
|
||||
const option = this.sortOrderOptions.find(o => o.value === sortOrder);
|
||||
return option ? this.t.translate(option.translationKey) : this.t.translate('settingsOpds.sortOrders.recent');
|
||||
}
|
||||
|
||||
startEdit(user: OpdsUserV2): void {
|
||||
this.editingUserId = user.id;
|
||||
this.editingSortOrder = user.sortOrder || 'RECENT';
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.editingUserId = null;
|
||||
this.editingSortOrder = null;
|
||||
}
|
||||
|
||||
saveSortOrder(user: OpdsUserV2): void {
|
||||
if (!this.editingSortOrder || !user.id) return;
|
||||
|
||||
this.opdsService.updateUser(user.id, this.editingSortOrder).pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError(err => {
|
||||
console.error('Error updating sort order:', err);
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsOpds.sortUpdateError'));
|
||||
return of(null);
|
||||
})
|
||||
).subscribe(updatedUser => {
|
||||
if (updatedUser) {
|
||||
const index = this.users.findIndex(u => u.id === user.id);
|
||||
if (index !== -1) {
|
||||
this.users[index] = updatedUser;
|
||||
}
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsOpds.sortUpdateSuccess'));
|
||||
}
|
||||
this.cancelEdit();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
|
||||
export type OpdsSortOrder = 'RECENT' | 'TITLE_ASC' | 'TITLE_DESC' | 'AUTHOR_ASC' | 'AUTHOR_DESC' | 'SERIES_ASC' | 'SERIES_DESC' | 'RATING_ASC' | 'RATING_DESC';
|
||||
|
||||
export interface OpdsUserV2CreateRequest {
|
||||
username: string;
|
||||
password: string;
|
||||
sortOrder?: OpdsSortOrder;
|
||||
}
|
||||
|
||||
export interface OpdsUserV2 {
|
||||
id: number;
|
||||
userId: number;
|
||||
username: string;
|
||||
sortOrder?: OpdsSortOrder;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class OpdsService {
|
||||
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v2/opds-users`;
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getUser(): Observable<OpdsUserV2[]> {
|
||||
return this.http.get<OpdsUserV2[]>(this.baseUrl);
|
||||
}
|
||||
|
||||
createUser(user: OpdsUserV2CreateRequest): Observable<OpdsUserV2> {
|
||||
return this.http.post<OpdsUserV2>(this.baseUrl, user);
|
||||
}
|
||||
|
||||
updateUser(id: number, sortOrder: OpdsSortOrder): Observable<OpdsUserV2> {
|
||||
return this.http.patch<OpdsUserV2>(`${this.baseUrl}/${id}`, {sortOrder});
|
||||
}
|
||||
|
||||
deleteCredential(id: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.baseUrl}/${id}`);
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsReader.cbx'">
|
||||
<div class="cbx-preferences-container">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('pageSpread') }}</label>
|
||||
<div class="button-group">
|
||||
@for (spread of cbxSpreads; track spread) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedCbxSpread === spread.key"
|
||||
(click)="selectedCbxSpread = spread.key">
|
||||
<i [class]="spread.icon"></i>
|
||||
<span class="option-text">{{ t(spread.translationKey) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('pageSpreadDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('pageLayout') }}</label>
|
||||
<div class="button-group">
|
||||
@for (mode of cbxViewModes; track mode) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedCbxViewMode === mode.key"
|
||||
(click)="selectedCbxViewMode = mode.key">
|
||||
<i [class]="mode.icon"></i>
|
||||
<span class="option-text">{{ t(mode.translationKey) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('pageLayoutDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('fitMode') }}</label>
|
||||
<div class="button-group">
|
||||
@for (mode of cbxFitModes; track mode) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedCbxFitMode === mode.key"
|
||||
(click)="selectedCbxFitMode = mode.key"
|
||||
[pTooltip]="t(mode.translationKey)"
|
||||
tooltipPosition="bottom">
|
||||
<i [class]="mode.icon"></i>
|
||||
<span class="option-text">{{ t(mode.translationKey) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('fitModeDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('scrollMode') }}</label>
|
||||
<div class="button-group">
|
||||
@for (mode of cbxScrollModes; track mode) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedCbxScrollMode === mode.key"
|
||||
(click)="selectedCbxScrollMode = mode.key">
|
||||
<i [class]="mode.icon"></i>
|
||||
<span class="option-text">{{ t(mode.translationKey) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('scrollModeDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('backgroundColor') }}</label>
|
||||
<div class="theme-selector">
|
||||
@for (color of cbxBackgroundColors; track color) {
|
||||
<button
|
||||
type="button"
|
||||
class="theme-option"
|
||||
[class.selected]="selectedCbxBackgroundColor === color.key"
|
||||
[style.background-color]="color.color"
|
||||
(click)="selectedCbxBackgroundColor = color.key"
|
||||
[attr.aria-label]="t(color.translationKey)"
|
||||
[pTooltip]="t(color.translationKey)"
|
||||
tooltipPosition="bottom">
|
||||
@if (selectedCbxBackgroundColor === color.key) {
|
||||
<i class="pi pi-check"></i>
|
||||
}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('backgroundColorDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
@use '../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.cbx-preferences-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
min-width: 100px;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.button-group {
|
||||
@include settings.settings-button-group;
|
||||
}
|
||||
|
||||
.theme-selector {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.theme-option {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border-radius: 0.375rem;
|
||||
border: 1.5px solid transparent;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
i {
|
||||
color: white;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
font-weight: bold;
|
||||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 25%, transparent);
|
||||
}
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
import {Component, inject, Input} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, UserSettings} from '../../user-management/user.service';
|
||||
import {ReaderPreferencesService} from '../reader-preferences.service';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
|
||||
@Component({
|
||||
selector: 'app-cbx-reader-preferences-component',
|
||||
imports: [
|
||||
FormsModule,
|
||||
TranslocoDirective,
|
||||
TooltipModule
|
||||
],
|
||||
templateUrl: './cbx-reader-preferences-component.html',
|
||||
styleUrl: './cbx-reader-preferences-component.scss'
|
||||
})
|
||||
export class CbxReaderPreferencesComponent {
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
private static readonly SETTING_ROOT = 'cbxReaderSetting';
|
||||
private static readonly PROP_PAGE_SPREAD = 'pageSpread';
|
||||
private static readonly PROP_PAGE_VIEW_MODE = 'pageViewMode';
|
||||
private static readonly PROP_FIT_MODE = 'fitMode';
|
||||
private static readonly PROP_SCROLL_MODE = 'scrollMode';
|
||||
private static readonly PROP_BACKGROUND_COLOR = 'backgroundColor';
|
||||
|
||||
readonly cbxSpreads = [
|
||||
{name: 'Even', key: CbxPageSpread.EVEN, icon: 'pi pi-align-left', translationKey: 'even'},
|
||||
{name: 'Odd', key: CbxPageSpread.ODD, icon: 'pi pi-align-right', translationKey: 'odd'}
|
||||
];
|
||||
|
||||
readonly cbxViewModes = [
|
||||
{name: 'Single Page', key: CbxPageViewMode.SINGLE_PAGE, icon: 'pi pi-book', translationKey: 'singlePage'},
|
||||
{name: 'Two Page', key: CbxPageViewMode.TWO_PAGE, icon: 'pi pi-copy', translationKey: 'twoPage'},
|
||||
];
|
||||
|
||||
readonly cbxFitModes = [
|
||||
{name: 'Fit Page', key: CbxFitMode.FIT_PAGE, icon: 'pi pi-window-maximize', translationKey: 'fitPage'},
|
||||
{name: 'Fit Width', key: CbxFitMode.FIT_WIDTH, icon: 'pi pi-arrows-h', translationKey: 'fitWidth'},
|
||||
{name: 'Fit Height', key: CbxFitMode.FIT_HEIGHT, icon: 'pi pi-arrows-v', translationKey: 'fitHeight'},
|
||||
{name: 'Actual Size', key: CbxFitMode.ACTUAL_SIZE, icon: 'pi pi-expand', translationKey: 'actualSize'},
|
||||
{name: 'Automatic', key: CbxFitMode.AUTO, icon: 'pi pi-sparkles', translationKey: 'automatic'}
|
||||
];
|
||||
|
||||
readonly cbxScrollModes = [
|
||||
{name: 'Paginated', key: CbxScrollMode.PAGINATED, icon: 'pi pi-book', translationKey: 'paginated'},
|
||||
{name: 'Infinite', key: CbxScrollMode.INFINITE, icon: 'pi pi-sort-alt', translationKey: 'infinite'}
|
||||
];
|
||||
|
||||
readonly cbxBackgroundColors = [
|
||||
{name: 'Gray', key: CbxBackgroundColor.GRAY, color: '#808080', translationKey: 'gray'},
|
||||
{name: 'Black', key: CbxBackgroundColor.BLACK, color: '#000000', translationKey: 'black'},
|
||||
{name: 'White', key: CbxBackgroundColor.WHITE, color: '#FFFFFF', translationKey: 'white'}
|
||||
];
|
||||
|
||||
get selectedCbxSpread(): CbxPageSpread {
|
||||
return this.userSettings.cbxReaderSetting.pageSpread ?? CbxPageSpread.EVEN;
|
||||
}
|
||||
|
||||
set selectedCbxSpread(value: CbxPageSpread) {
|
||||
this.userSettings.cbxReaderSetting.pageSpread = value;
|
||||
this.readerPreferencesService.updatePreference([CbxReaderPreferencesComponent.SETTING_ROOT, CbxReaderPreferencesComponent.PROP_PAGE_SPREAD], value);
|
||||
}
|
||||
|
||||
get selectedCbxViewMode(): CbxPageViewMode {
|
||||
return this.userSettings.cbxReaderSetting.pageViewMode ?? CbxPageViewMode.SINGLE_PAGE;
|
||||
}
|
||||
|
||||
set selectedCbxViewMode(value: CbxPageViewMode) {
|
||||
this.userSettings.cbxReaderSetting.pageViewMode = value;
|
||||
this.readerPreferencesService.updatePreference([CbxReaderPreferencesComponent.SETTING_ROOT, CbxReaderPreferencesComponent.PROP_PAGE_VIEW_MODE], value);
|
||||
}
|
||||
|
||||
get selectedCbxFitMode(): CbxFitMode {
|
||||
return this.userSettings.cbxReaderSetting.fitMode ?? CbxFitMode.FIT_PAGE;
|
||||
}
|
||||
|
||||
set selectedCbxFitMode(value: CbxFitMode) {
|
||||
this.userSettings.cbxReaderSetting.fitMode = value;
|
||||
this.readerPreferencesService.updatePreference([CbxReaderPreferencesComponent.SETTING_ROOT, CbxReaderPreferencesComponent.PROP_FIT_MODE], value);
|
||||
}
|
||||
|
||||
get selectedCbxScrollMode(): CbxScrollMode {
|
||||
return this.userSettings.cbxReaderSetting.scrollMode ?? CbxScrollMode.PAGINATED;
|
||||
}
|
||||
|
||||
set selectedCbxScrollMode(value: CbxScrollMode) {
|
||||
this.userSettings.cbxReaderSetting.scrollMode = value;
|
||||
this.readerPreferencesService.updatePreference([CbxReaderPreferencesComponent.SETTING_ROOT, CbxReaderPreferencesComponent.PROP_SCROLL_MODE], value);
|
||||
}
|
||||
|
||||
get selectedCbxBackgroundColor(): CbxBackgroundColor {
|
||||
return this.userSettings.cbxReaderSetting.backgroundColor ?? CbxBackgroundColor.GRAY;
|
||||
}
|
||||
|
||||
set selectedCbxBackgroundColor(value: CbxBackgroundColor) {
|
||||
this.userSettings.cbxReaderSetting.backgroundColor = value;
|
||||
this.readerPreferencesService.updatePreference([CbxReaderPreferencesComponent.SETTING_ROOT, CbxReaderPreferencesComponent.PROP_BACKGROUND_COLOR], value);
|
||||
}
|
||||
}
|
||||
+291
@@ -0,0 +1,291 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsReader.ebook'">
|
||||
<div class="epub-preferences-container">
|
||||
|
||||
<div class="settings-group">
|
||||
<h3 class="group-title">{{ t('appearance') }}</h3>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('theme') }}</label>
|
||||
<div class="theme-selector">
|
||||
@for (theme of themes; track theme) {
|
||||
<button
|
||||
type="button"
|
||||
class="theme-option"
|
||||
[class.selected]="selectedTheme === theme.name"
|
||||
(click)="selectedTheme = theme.name"
|
||||
[attr.aria-label]="theme.label"
|
||||
[pTooltip]="theme.label"
|
||||
tooltipPosition="bottom">
|
||||
<span class="theme-colors">
|
||||
<span class="theme-color" [style.background-color]="theme.light.bg"></span>
|
||||
<span class="theme-color" [style.background-color]="theme.dark.bg"></span>
|
||||
</span>
|
||||
@if (selectedTheme === theme.name) {
|
||||
<i class="pi pi-check"></i>
|
||||
}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('themeDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('darkMode') }}</label>
|
||||
<div class="button-group">
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="!isDark"
|
||||
(click)="isDark = false">
|
||||
<i class="pi pi-sun"></i>
|
||||
<span class="option-text">{{ t('light') }}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="isDark"
|
||||
(click)="isDark = true">
|
||||
<i class="pi pi-moon"></i>
|
||||
<span class="option-text">{{ t('dark') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('darkModeDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<h3 class="group-title">{{ t('typography') }}</h3>
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('fontFamily') }}</label>
|
||||
<div class="button-group">
|
||||
@for (font of fonts; track font) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button font-button"
|
||||
[class.selected]="selectedFont === font.key"
|
||||
[class.separator]="font.key === 'separator'"
|
||||
[attr.data-font]="font.key"
|
||||
[disabled]="font.key === 'separator'"
|
||||
(click)="selectedFont = font.key"
|
||||
[pTooltip]="font.name"
|
||||
tooltipPosition="bottom">
|
||||
<span class="option-text" [style.font-family]="font.key && font.key.startsWith('custom:') ? getCustomFontName(font.key) : null">
|
||||
{{ font.displayName }}
|
||||
</span>
|
||||
</button>
|
||||
}
|
||||
|
||||
@if (!customFontsReady) {
|
||||
<p-skeleton width="3.5rem" height="2.5rem" borderRadius="6px"></p-skeleton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('fontFamilyDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('fontSize') }}</label>
|
||||
<div class="font-size-controls">
|
||||
<p-button icon="pi pi-minus" size="small" rounded outlined (click)="decreaseFontSize()"></p-button>
|
||||
<span class="font-size-value">{{ fontSize }}pt</span>
|
||||
<p-button icon="pi pi-plus" size="small" rounded outlined (click)="increaseFontSize()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('fontSizeDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('lineHeight') }}</label>
|
||||
<div class="font-size-controls">
|
||||
<p-button icon="pi pi-minus" size="small" rounded outlined (click)="decreaseLineHeight()"></p-button>
|
||||
<span class="font-size-value">{{ lineHeight.toFixed(1) }}</span>
|
||||
<p-button icon="pi pi-plus" size="small" rounded outlined (click)="increaseLineHeight()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('lineHeightDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('textJustification') }}</label>
|
||||
<div class="button-group">
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="!justify"
|
||||
(click)="justify = false">
|
||||
<i class="pi pi-align-left"></i>
|
||||
<span class="option-text">{{ t('left') }}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="justify"
|
||||
(click)="justify = true">
|
||||
<i class="pi pi-align-justify"></i>
|
||||
<span class="option-text">{{ t('justified') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('textJustificationDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('hyphenation') }}</label>
|
||||
<div class="button-group">
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="!hyphenate"
|
||||
(click)="hyphenate = false">
|
||||
<i class="pi pi-times"></i>
|
||||
<span class="option-text">{{ t('off') }}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="hyphenate"
|
||||
(click)="hyphenate = true">
|
||||
<i class="pi pi-check"></i>
|
||||
<span class="option-text">{{ t('on') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('hyphenationDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<h3 class="group-title">{{ t('layout') }}</h3>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('flow') }}</label>
|
||||
<div class="button-group">
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="flow === 'paginated'"
|
||||
(click)="flow = 'paginated'">
|
||||
<i class="pi pi-clone"></i>
|
||||
<span class="option-text">{{ t('paginated') }}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="flow === 'scrolled'"
|
||||
(click)="flow = 'scrolled'">
|
||||
<i class="pi pi-arrows-v"></i>
|
||||
<span class="option-text">{{ t('scrolled') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('flowDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('maxColumns') }}</label>
|
||||
<div class="font-size-controls">
|
||||
<p-button icon="pi pi-minus" size="small" rounded outlined (click)="maxColumnCount = maxColumnCount > 1 ? maxColumnCount - 1 : 1"></p-button>
|
||||
<span class="font-size-value">{{ maxColumnCount }}</span>
|
||||
<p-button icon="pi pi-plus" size="small" rounded outlined (click)="maxColumnCount = maxColumnCount < 4 ? maxColumnCount + 1 : 4"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('maxColumnsDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('columnGap') }}</label>
|
||||
<div class="font-size-controls">
|
||||
<p-button icon="pi pi-minus" size="small" rounded outlined (click)="decreaseGap()"></p-button>
|
||||
<span class="font-size-value">{{ gap * 100 | number : '1.0-0' }}%</span>
|
||||
<p-button icon="pi pi-plus" size="small" rounded outlined (click)="increaseGap()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('columnGapDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('maxWidth') }}</label>
|
||||
<div class="font-size-controls">
|
||||
<p-button icon="pi pi-minus" size="small" rounded outlined (click)="decreaseMaxInlineSize()"></p-button>
|
||||
<span class="font-size-value">{{ maxInlineSize }}px</span>
|
||||
<p-button icon="pi pi-plus" size="small" rounded outlined (click)="increaseMaxInlineSize()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('maxWidthDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('maxHeight') }}</label>
|
||||
<div class="font-size-controls">
|
||||
<p-button icon="pi pi-minus" size="small" rounded outlined (click)="decreaseMaxBlockSize()"></p-button>
|
||||
<span class="font-size-value">{{ maxBlockSize }}px</span>
|
||||
<p-button icon="pi pi-plus" size="small" rounded outlined (click)="increaseMaxBlockSize()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('maxHeightDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+237
@@ -0,0 +1,237 @@
|
||||
@use '../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.epub-preferences-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 1.5rem;
|
||||
border-radius: 0.75rem;
|
||||
border: 1px solid color-mix(in srgb, var(--text-color) 10%, transparent);
|
||||
|
||||
.group-title {
|
||||
font-size: settings.$settings-section-title-size;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.5rem 0;
|
||||
padding-bottom: 0.75rem;
|
||||
border-bottom: 1px solid color-mix(in srgb, var(--text-color) 10%, transparent);
|
||||
}
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
min-width: 100px;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.radio-group {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.radio-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
label {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
color: var(--p-text-color);
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.font-size-controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
.font-size-value {
|
||||
min-width: 3rem;
|
||||
text-align: center;
|
||||
font-weight: settings.$settings-label-weight;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
}
|
||||
|
||||
.theme-selector {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.theme-option {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
background: color-mix(in srgb, var(--text-color) 5%, transparent);
|
||||
color: var(--text-color);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
position: relative;
|
||||
min-width: 48px;
|
||||
|
||||
.theme-colors {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
padding: 0;
|
||||
border-radius: 0.5rem;
|
||||
overflow: hidden;
|
||||
border: 2px solid color-mix(in srgb, var(--text-color) 20%, transparent);
|
||||
box-sizing: border-box;
|
||||
width: 72px;
|
||||
height: 36px;
|
||||
background: none;
|
||||
}
|
||||
|
||||
.theme-color {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
display: inline-block;
|
||||
border-radius: 0;
|
||||
border: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
i {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
font-size: 0.75rem;
|
||||
color: var(--primary-color);
|
||||
margin-left: 0;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
|
||||
.theme-colors {
|
||||
border-color: color-mix(in srgb, var(--primary-color) 40%, transparent);
|
||||
}
|
||||
}
|
||||
|
||||
&.selected {
|
||||
.theme-colors {
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 15%, transparent);
|
||||
}
|
||||
color: var(--primary-color);
|
||||
background: color-mix(in srgb, var(--primary-color) 10%, transparent);
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.button-group {
|
||||
@include settings.settings-button-group;
|
||||
|
||||
.option-button {
|
||||
&.font-button {
|
||||
font-size: 1rem;
|
||||
|
||||
&[data-font="serif"] .option-text {
|
||||
font-family: Georgia, 'Times New Roman', serif;
|
||||
}
|
||||
|
||||
&[data-font="sans-serif"] .option-text {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
&[data-font="roboto"] .option-text {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
}
|
||||
|
||||
&[data-font="cursive"] .option-text {
|
||||
font-family: cursive;
|
||||
}
|
||||
|
||||
&[data-font="monospace"] .option-text {
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
|
||||
// Custom font buttons use the loaded font
|
||||
&[data-font^="custom:"] .option-text {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
}
|
||||
}
|
||||
|
||||
&.separator {
|
||||
cursor: default;
|
||||
pointer-events: none;
|
||||
opacity: 0.6;
|
||||
background: transparent;
|
||||
border-color: transparent;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-muted-color);
|
||||
min-width: auto;
|
||||
padding: 0.25rem 0.5rem;
|
||||
|
||||
&:hover {
|
||||
transform: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+299
@@ -0,0 +1,299 @@
|
||||
import {DecimalPipe} from '@angular/common';
|
||||
import {Component, effect, inject, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {ReaderPreferencesService} from '../reader-preferences.service';
|
||||
import {UserSettings} from '../../user-management/user.service';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {CustomFontService} from '../../../../shared/service/custom-font.service';
|
||||
import {CustomFont} from '../../../../shared/model/custom-font.model';
|
||||
import {skip, Subject, takeUntil} from 'rxjs';
|
||||
import {addCustomFontsToDropdown} from '../../../../shared/util/custom-font.util';
|
||||
import {Skeleton} from 'primeng/skeleton';
|
||||
import {themes} from '../../../readers/ebook-reader/state/themes.constant';
|
||||
|
||||
@Component({
|
||||
selector: 'app-epub-reader-preferences-component',
|
||||
imports: [
|
||||
Button,
|
||||
DecimalPipe,
|
||||
FormsModule,
|
||||
TranslocoDirective,
|
||||
Tooltip,
|
||||
Skeleton
|
||||
],
|
||||
templateUrl: './epub-reader-preferences-component.html',
|
||||
styleUrl: './epub-reader-preferences-component.scss'
|
||||
})
|
||||
export class EpubReaderPreferencesComponent implements OnInit, OnDestroy {
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
private readonly customFontService = inject(CustomFontService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
customFonts: CustomFont[] = [];
|
||||
|
||||
fonts = [
|
||||
{name: 'Book Default', displayName: 'Default', key: null},
|
||||
{name: 'Serif', displayName: 'Serif', key: 'serif'},
|
||||
{name: 'Sans Serif', displayName: 'Sans Serif', key: 'sans-serif'},
|
||||
{name: 'Roboto', displayName: 'Roboto', key: 'roboto'},
|
||||
{name: 'Cursive', displayName: 'Cursive', key: 'cursive'},
|
||||
{name: 'Monospace', displayName: 'Monospace', key: 'monospace'}
|
||||
];
|
||||
|
||||
readonly themes = themes;
|
||||
|
||||
customFontsReady = false;
|
||||
|
||||
private readonly syncFontsEffect = effect(() => {
|
||||
const fonts = this.customFontService.fonts();
|
||||
if (fonts.length > 0 || !this.customFontService.isFontsLoading()) {
|
||||
this.customFontsReady = true;
|
||||
}
|
||||
if (this.hasCustomFontsChanged(fonts)) {
|
||||
this.onFontsChanged(fonts);
|
||||
}
|
||||
});
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private async onFontsChanged(fonts: CustomFont[]): Promise<void> {
|
||||
try {
|
||||
const selectedFontDeleted = this.isCurrentlySelectedFontDeleted(fonts);
|
||||
|
||||
this.customFonts = fonts;
|
||||
await this.customFontService.loadAllFonts(fonts);
|
||||
this.updateFontsDropdown(fonts);
|
||||
|
||||
if (selectedFontDeleted) {
|
||||
this.resetToDefaultFont();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to process custom fonts:', err);
|
||||
}
|
||||
}
|
||||
|
||||
private hasCustomFontsChanged(newFonts: CustomFont[]): boolean {
|
||||
if (newFonts.length !== this.customFonts.length) {
|
||||
return true;
|
||||
}
|
||||
const newIds = new Set(newFonts.map(f => f.id));
|
||||
const currentIds = new Set(this.customFonts.map(f => f.id));
|
||||
return newFonts.some(f => !currentIds.has(f.id)) || this.customFonts.some(f => !newIds.has(f.id));
|
||||
}
|
||||
|
||||
private updateFontsDropdown(fonts: CustomFont[]): void {
|
||||
this.fonts = this.fonts.filter(font => !font.key || !font.key.startsWith('custom:'));
|
||||
addCustomFontsToDropdown(fonts, this.fonts, 'preference');
|
||||
}
|
||||
|
||||
private isCurrentlySelectedFontDeleted(newFonts: CustomFont[]): boolean {
|
||||
const fontFamily = this.userSettings.ebookReaderSetting.fontFamily;
|
||||
if (!fontFamily || !fontFamily.startsWith('custom:')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const fontId = fontFamily.split(':')[1];
|
||||
const fontStillExists = newFonts.some(font => font.id === parseInt(fontId, 10));
|
||||
return !fontStillExists;
|
||||
}
|
||||
|
||||
private resetToDefaultFont(): void {
|
||||
console.log('Selected custom font was deleted, resetting to default font');
|
||||
this.selectedFont = null;
|
||||
}
|
||||
|
||||
get selectedTheme(): string | null {
|
||||
return this.userSettings.ebookReaderSetting.theme;
|
||||
}
|
||||
|
||||
set selectedTheme(value: string | null) {
|
||||
if (typeof value === "string") {
|
||||
this.userSettings.ebookReaderSetting.theme = value;
|
||||
}
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'theme'], value);
|
||||
}
|
||||
|
||||
get selectedFont(): string | null {
|
||||
return this.userSettings.ebookReaderSetting.fontFamily;
|
||||
}
|
||||
|
||||
set selectedFont(value: string | null) {
|
||||
if (typeof value === "string") {
|
||||
this.userSettings.ebookReaderSetting.fontFamily = value;
|
||||
} else {
|
||||
this.userSettings.ebookReaderSetting.fontFamily = null as any;
|
||||
}
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'fontFamily'], value);
|
||||
}
|
||||
|
||||
get fontSize(): number {
|
||||
return this.userSettings.ebookReaderSetting.fontSize;
|
||||
}
|
||||
|
||||
set fontSize(value: number) {
|
||||
this.userSettings.ebookReaderSetting.fontSize = value;
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'fontSize'], value);
|
||||
}
|
||||
|
||||
get lineHeight(): number {
|
||||
return this.userSettings.ebookReaderSetting.lineHeight;
|
||||
}
|
||||
|
||||
set lineHeight(value: number) {
|
||||
this.userSettings.ebookReaderSetting.lineHeight = value;
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'lineHeight'], value);
|
||||
}
|
||||
|
||||
get justify(): boolean {
|
||||
return this.userSettings.ebookReaderSetting.justify;
|
||||
}
|
||||
|
||||
set justify(value: boolean) {
|
||||
this.userSettings.ebookReaderSetting.justify = value;
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'justify'], value);
|
||||
}
|
||||
|
||||
get hyphenate(): boolean {
|
||||
return this.userSettings.ebookReaderSetting.hyphenate;
|
||||
}
|
||||
|
||||
set hyphenate(value: boolean) {
|
||||
this.userSettings.ebookReaderSetting.hyphenate = value;
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'hyphenate'], value);
|
||||
}
|
||||
|
||||
get maxColumnCount(): number {
|
||||
return this.userSettings.ebookReaderSetting.maxColumnCount;
|
||||
}
|
||||
|
||||
set maxColumnCount(value: number) {
|
||||
this.userSettings.ebookReaderSetting.maxColumnCount = value;
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'maxColumnCount'], value);
|
||||
}
|
||||
|
||||
get gap(): number {
|
||||
return this.userSettings.ebookReaderSetting.gap;
|
||||
}
|
||||
|
||||
set gap(value: number) {
|
||||
this.userSettings.ebookReaderSetting.gap = value;
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'gap'], value);
|
||||
}
|
||||
|
||||
get maxInlineSize(): number {
|
||||
return this.userSettings.ebookReaderSetting.maxInlineSize;
|
||||
}
|
||||
|
||||
set maxInlineSize(value: number) {
|
||||
this.userSettings.ebookReaderSetting.maxInlineSize = value;
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'maxInlineSize'], value);
|
||||
}
|
||||
|
||||
get maxBlockSize(): number {
|
||||
return this.userSettings.ebookReaderSetting.maxBlockSize;
|
||||
}
|
||||
|
||||
set maxBlockSize(value: number) {
|
||||
this.userSettings.ebookReaderSetting.maxBlockSize = value;
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'maxBlockSize'], value);
|
||||
}
|
||||
|
||||
get isDark(): boolean {
|
||||
return this.userSettings.ebookReaderSetting.isDark;
|
||||
}
|
||||
|
||||
set isDark(value: boolean) {
|
||||
this.userSettings.ebookReaderSetting.isDark = value;
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'isDark'], value);
|
||||
}
|
||||
|
||||
get flow(): 'paginated' | 'scrolled' {
|
||||
return this.userSettings.ebookReaderSetting.flow;
|
||||
}
|
||||
|
||||
set flow(value: 'paginated' | 'scrolled') {
|
||||
this.userSettings.ebookReaderSetting.flow = value;
|
||||
this.readerPreferencesService.updatePreference(['ebookReaderSetting', 'flow'], value);
|
||||
}
|
||||
|
||||
increaseFontSize() {
|
||||
if (this.fontSize < 72) {
|
||||
this.fontSize += 1;
|
||||
}
|
||||
}
|
||||
|
||||
decreaseFontSize() {
|
||||
if (this.fontSize > 8) {
|
||||
this.fontSize -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
increaseLineHeight() {
|
||||
if (this.lineHeight < 3) {
|
||||
this.lineHeight = Math.round((this.lineHeight + 0.1) * 10) / 10;
|
||||
}
|
||||
}
|
||||
|
||||
decreaseLineHeight() {
|
||||
if (this.lineHeight > 1) {
|
||||
this.lineHeight = Math.round((this.lineHeight - 0.1) * 10) / 10;
|
||||
}
|
||||
}
|
||||
|
||||
increaseGap() {
|
||||
|
||||
if (this.gap < 0.5) {
|
||||
this.gap = Math.round((this.gap + 0.05) * 100) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
decreaseGap() {
|
||||
if (this.gap > 0) {
|
||||
this.gap = Math.round((this.gap - 0.05) * 100) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
increaseMaxInlineSize() {
|
||||
if (this.maxInlineSize < 2000) {
|
||||
this.maxInlineSize += 50;
|
||||
}
|
||||
}
|
||||
|
||||
decreaseMaxInlineSize() {
|
||||
if (this.maxInlineSize > 400) {
|
||||
this.maxInlineSize -= 50;
|
||||
}
|
||||
}
|
||||
|
||||
increaseMaxBlockSize() {
|
||||
if (this.maxBlockSize < 2000) {
|
||||
this.maxBlockSize += 50;
|
||||
}
|
||||
}
|
||||
|
||||
decreaseMaxBlockSize() {
|
||||
if (this.maxBlockSize > 400) {
|
||||
this.maxBlockSize -= 50;
|
||||
}
|
||||
}
|
||||
|
||||
getCustomFontName(fontKey: string): string | null {
|
||||
if (!fontKey || !fontKey.startsWith('custom:')) {
|
||||
return null;
|
||||
}
|
||||
const fontId = parseInt(fontKey.split(':')[1]);
|
||||
const customFont = this.customFonts.find(f => f.id === fontId);
|
||||
return customFont ? customFont.fontName : null;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsReader.pdf'">
|
||||
<div class="pdf-preferences-container">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('pageSpread') }}</label>
|
||||
<div class="button-group">
|
||||
@for (spread of spreads; track spread) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedSpread === spread.key"
|
||||
(click)="selectedSpread = spread.key"
|
||||
[pTooltip]="t(spread.translationKey)"
|
||||
tooltipPosition="bottom">
|
||||
<i [class]="spread.icon"></i>
|
||||
<span class="option-text">{{ t(spread.translationKey) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('pageSpreadDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('pageZoom') }}</label>
|
||||
<div class="button-group">
|
||||
@for (zoom of zooms; track zoom) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedZoom === zoom.key"
|
||||
(click)="selectedZoom = zoom.key"
|
||||
[pTooltip]="t(zoom.translationKey)"
|
||||
tooltipPosition="bottom">
|
||||
<i [class]="zoom.icon"></i>
|
||||
<span class="option-text">{{ t(zoom.translationKey) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('pageZoomDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
@use '../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.pdf-preferences-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
min-width: 100px;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.button-group {
|
||||
@include settings.settings-button-group;
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
import {Component, inject, Input} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {ReaderPreferencesService} from '../reader-preferences.service';
|
||||
import {PageSpread, UserSettings} from '../../user-management/user.service';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
|
||||
@Component({
|
||||
selector: 'app-pdf-reader-preferences-component',
|
||||
imports: [
|
||||
FormsModule,
|
||||
TranslocoDirective,
|
||||
TooltipModule
|
||||
],
|
||||
templateUrl: './pdf-reader-preferences-component.html',
|
||||
styleUrl: './pdf-reader-preferences-component.scss'
|
||||
})
|
||||
export class PdfReaderPreferencesComponent {
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
readonly spreads: {name: string; key: PageSpread; icon: string; translationKey: string}[] = [
|
||||
{name: 'Even', key: 'even', icon: 'pi pi-align-left', translationKey: 'even'},
|
||||
{name: 'Odd', key: 'odd', icon: 'pi pi-align-right', translationKey: 'odd'},
|
||||
{name: 'None', key: 'off', icon: 'pi pi-minus', translationKey: 'none'}
|
||||
];
|
||||
|
||||
readonly zooms: {name: string; key: string; icon: string; translationKey: string}[] = [
|
||||
{name: 'Auto Zoom', key: 'auto', icon: 'pi pi-sparkles', translationKey: 'autoZoom'},
|
||||
{name: 'Page Fit', key: 'page-fit', icon: 'pi pi-window-maximize', translationKey: 'pageFit'},
|
||||
{name: 'Page Width', key: 'page-width', icon: 'pi pi-arrows-h', translationKey: 'pageWidth'},
|
||||
{name: 'Actual Size', key: 'page-actual', icon: 'pi pi-expand', translationKey: 'actualSize'}
|
||||
];
|
||||
|
||||
get selectedSpread(): 'even' | 'odd' | 'off' {
|
||||
return this.userSettings.pdfReaderSetting.pageSpread;
|
||||
}
|
||||
|
||||
set selectedSpread(value: 'even' | 'odd' | 'off') {
|
||||
this.userSettings.pdfReaderSetting.pageSpread = value;
|
||||
this.readerPreferencesService.updatePreference(['pdfReaderSetting', 'pageSpread'], value);
|
||||
}
|
||||
|
||||
get selectedZoom(): string {
|
||||
return this.userSettings.pdfReaderSetting.pageZoom;
|
||||
}
|
||||
|
||||
set selectedZoom(value: string) {
|
||||
this.userSettings.pdfReaderSetting.pageZoom = value;
|
||||
this.readerPreferencesService.updatePreference(['pdfReaderSetting', 'pageZoom'], value);
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsReader'">
|
||||
<div class="main-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-book"></i>
|
||||
{{ t('title') }}
|
||||
</h2>
|
||||
<p class="settings-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-content">
|
||||
<app-settings-application-mode [userSettings]="userSettings"></app-settings-application-mode>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-book"></i>
|
||||
{{ t('ebook.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('ebook.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<app-epub-reader-preferences-component
|
||||
[userSettings]="userSettings">
|
||||
</app-epub-reader-preferences-component>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-file-pdf"></i>
|
||||
{{ t('pdf.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('pdf.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<app-pdf-reader-preferences-component
|
||||
[userSettings]="userSettings">
|
||||
</app-pdf-reader-preferences-component>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-images"></i>
|
||||
{{ t('cbx.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('cbx.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<app-cbx-reader-preferences-component
|
||||
[userSettings]="userSettings">
|
||||
</app-cbx-reader-preferences-component>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (hasFontManagementPermission) {
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-palette"></i>
|
||||
{{ t('fonts.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('fonts.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="settings-card">
|
||||
<app-custom-fonts></app-custom-fonts>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.main-container {
|
||||
@include settings.settings-page-container;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
@media (min-width: 768px) {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
|
||||
app-epub-reader-preferences-component,
|
||||
app-pdf-reader-preferences-component,
|
||||
app-cbx-reader-preferences-component {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
align-items: flex-end;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.radio-group {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.radio-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
label {
|
||||
font-size: settings.$settings-section-description-size;
|
||||
color: var(--p-text-color);
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.button-group {
|
||||
@include settings.settings-button-group;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import {Component, effect, inject} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {UserService, UserSettings} from '../user-management/user.service';
|
||||
import {ReaderPreferencesService} from './reader-preferences.service';
|
||||
import {EpubReaderPreferencesComponent} from './epub-reader-preferences/epub-reader-preferences-component';
|
||||
import {PdfReaderPreferencesComponent} from './pdf-reader-preferences/pdf-reader-preferences-component';
|
||||
import {CbxReaderPreferencesComponent} from './cbx-reader-preferences/cbx-reader-preferences-component';
|
||||
import {CustomFontsComponent} from '../custom-fonts/custom-fonts.component';
|
||||
import {SettingsApplicationModeComponent} from './settings-application-mode/settings-application-mode.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-reader-preferences',
|
||||
templateUrl: './reader-preferences.component.html',
|
||||
standalone: true,
|
||||
styleUrls: ['./reader-preferences.component.scss'],
|
||||
imports: [FormsModule, TooltipModule, TranslocoDirective, EpubReaderPreferencesComponent, PdfReaderPreferencesComponent, CbxReaderPreferencesComponent, CustomFontsComponent, SettingsApplicationModeComponent]
|
||||
})
|
||||
export class ReaderPreferences {
|
||||
private readonly userService = inject(UserService);
|
||||
|
||||
userSettings!: UserSettings;
|
||||
|
||||
hasFontManagementPermission = false;
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (!user) return;
|
||||
|
||||
this.userSettings = user.userSettings;
|
||||
const perms = user.permissions;
|
||||
this.hasFontManagementPermission = (perms.admin || perms.canManageFonts);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import {effect, inject, Injectable} from '@angular/core';
|
||||
import {User, UserService, UserSettings} from '../user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class ReaderPreferencesService {
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private currentUser: User | null = null;
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const user = this.userService.currentUser();
|
||||
if (user) {
|
||||
this.currentUser = user;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updatePreference(path: string[], value: unknown): void {
|
||||
if (!this.currentUser) return;
|
||||
|
||||
let target: any = this.currentUser.userSettings;
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
target = target[path[i]] ||= {};
|
||||
}
|
||||
target[path.at(-1)!] = value;
|
||||
|
||||
const [rootKey] = path;
|
||||
const updatedValue = this.currentUser.userSettings[rootKey as keyof UserSettings];
|
||||
|
||||
this.userService.updateUserSetting(this.currentUser.id, rootKey, updatedValue);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsReader.toast.preferencesUpdated'),
|
||||
detail: this.t.translate('settingsReader.toast.preferencesUpdatedDetail'),
|
||||
life: 2000
|
||||
});
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsReader.appMode'">
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-cog"></i>
|
||||
{{ t('title') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('description') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('pdfLabel') }}</label>
|
||||
<div class="button-group">
|
||||
@for (item of scopeOptions; track item) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedPdfScope === item.key"
|
||||
(click)="selectedPdfScope = item.key; onPdfScopeChange()">
|
||||
<i [class]="item.icon"></i>
|
||||
<span class="option-text">{{ item.key === 'Global' ? t('defaultOverride') : t('bookSpecific') }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('pdfDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('ebookLabel') }}</label>
|
||||
<div class="button-group">
|
||||
@for (item of scopeOptions; track item) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedEpubScope === item.key"
|
||||
(click)="selectedEpubScope = item.key; onEpubScopeChange()">
|
||||
<i [class]="item.icon"></i>
|
||||
<span class="option-text">{{ item.key === 'Global' ? t('defaultOverride') : t('bookSpecific') }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('ebookDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('comicLabel') }}</label>
|
||||
<div class="button-group">
|
||||
@for (item of scopeOptions; track item) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedCbxScope === item.key"
|
||||
(click)="selectedCbxScope = item.key; onCbxScopeChange()">
|
||||
<i [class]="item.icon"></i>
|
||||
<span class="option-text">{{ item.key === 'Global' ? t('defaultOverride') : t('bookSpecific') }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('comicDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('streamingPdfLabel') }}</label>
|
||||
<div class="button-group">
|
||||
@for (item of scopeOptions; track item) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedNewPdfScope === item.key"
|
||||
(click)="selectedNewPdfScope = item.key; onNewPdfScopeChange()">
|
||||
<i [class]="item.icon"></i>
|
||||
<span class="option-text">{{ item.key === 'Global' ? t('defaultOverride') : t('bookSpecific') }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('streamingPdfDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
.preferences-section {
|
||||
@media (min-width: 768px) {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
margin: 0 0 0.5rem 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.section-description {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
margin-top: 0.125rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--p-content-background);
|
||||
padding: 1.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
min-width: 220px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
min-width: 220px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.button-group {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.option-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-radius: 0.375rem;
|
||||
border: 1.5px solid color-mix(in srgb, var(--text-color) 20%, transparent);
|
||||
background: color-mix(in srgb, var(--text-color) 5%, transparent);
|
||||
color: var(--text-color);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
min-width: 4.5rem;
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.option-text {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
border-color: color-mix(in srgb, var(--primary-color) 40%, transparent);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: var(--primary-color);
|
||||
background: color-mix(in srgb, var(--primary-color) 10%, transparent);
|
||||
color: var(--primary-color);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 15%, transparent);
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import {ChangeDetectionStrategy, Component, inject, Input, OnInit} from '@angular/core';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {ReaderPreferencesService} from '../reader-preferences.service';
|
||||
import {UserSettings} from '../../user-management/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings-application-mode',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
templateUrl: './settings-application-mode.component.html',
|
||||
standalone: true,
|
||||
styleUrls: ['./settings-application-mode.component.scss'],
|
||||
imports: [TranslocoDirective]
|
||||
})
|
||||
export class SettingsApplicationModeComponent implements OnInit {
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
readonly scopeOptions = [
|
||||
{name: 'Global', key: 'Global', icon: 'pi pi-globe'},
|
||||
{name: 'Individual', key: 'Individual', icon: 'pi pi-user'}
|
||||
];
|
||||
|
||||
selectedPdfScope!: string;
|
||||
selectedNewPdfScope!: string;
|
||||
selectedEpubScope!: string;
|
||||
selectedCbxScope!: string;
|
||||
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadPreferences();
|
||||
}
|
||||
|
||||
private loadPreferences(): void {
|
||||
this.selectedPdfScope = this.userSettings.perBookSetting.pdf;
|
||||
this.selectedNewPdfScope = this.userSettings.perBookSetting.newPdf || 'Global';
|
||||
this.selectedEpubScope = this.userSettings.perBookSetting.epub;
|
||||
this.selectedCbxScope = this.userSettings.perBookSetting.cbx;
|
||||
}
|
||||
|
||||
onPdfScopeChange() {
|
||||
this.readerPreferencesService.updatePreference(['perBookSetting', 'pdf'], this.selectedPdfScope);
|
||||
}
|
||||
|
||||
onNewPdfScopeChange() {
|
||||
this.readerPreferencesService.updatePreference(['perBookSetting', 'newPdf'], this.selectedNewPdfScope);
|
||||
}
|
||||
|
||||
onEpubScopeChange() {
|
||||
this.readerPreferencesService.updatePreference(['perBookSetting', 'epub'], this.selectedEpubScope);
|
||||
}
|
||||
|
||||
onCbxScopeChange() {
|
||||
this.readerPreferencesService.updatePreference(['perBookSetting', 'cbx'], this.selectedCbxScope);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<ng-container *transloco="let t; prefix: 'settings.tabs'">
|
||||
@if (userService.currentUser(); as currentUser) {
|
||||
@if (currentUser) {
|
||||
<div class="settings-container">
|
||||
<p-tabs [(value)]="activeTab" lazy scrollable>
|
||||
<p-tablist>
|
||||
<p-tab [value]="SettingsTab.ReaderSettings">
|
||||
<i class="pi pi-book"></i> {{ t('reader') }}
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.ViewPreferences">
|
||||
<i class="pi pi-desktop"></i> {{ t('view') }}
|
||||
</p-tab>
|
||||
@if (currentUser.permissions.admin || currentUser.permissions.canManageMetadataConfig) {
|
||||
<p-tab [value]="SettingsTab.MetadataSettings">
|
||||
<i class="pi pi-sliders-h"></i> {{ t('metadata1') }}
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.LibraryMetadataSettings">
|
||||
<i class="pi pi-database"></i> {{ t('metadata2') }}
|
||||
</p-tab>
|
||||
}
|
||||
@if (currentUser.permissions.admin || currentUser.permissions.canManageGlobalPreferences) {
|
||||
<p-tab [value]="SettingsTab.ApplicationSettings">
|
||||
<i class="pi pi-cog"></i> {{ t('application') }}
|
||||
</p-tab>
|
||||
}
|
||||
@if (currentUser.permissions.admin) {
|
||||
<p-tab [value]="SettingsTab.UserManagement">
|
||||
<i class="pi pi-users"></i> {{ t('users') }}
|
||||
</p-tab>
|
||||
}
|
||||
<p-tab [value]="SettingsTab.EmailSettingsV2">
|
||||
<i class="pi pi-envelope"></i> {{ t('email') }}
|
||||
</p-tab>
|
||||
@if (currentUser.permissions.admin || currentUser.permissions.canManageMetadataConfig) {
|
||||
<p-tab [value]="SettingsTab.NamingPattern">
|
||||
<i class="pi pi-sitemap"></i> {{ t('patterns') }}
|
||||
</p-tab>
|
||||
}
|
||||
@if (currentUser.permissions.admin) {
|
||||
<p-tab [value]="SettingsTab.AuthenticationSettings">
|
||||
<i class="pi pi-lock"></i> {{ t('authentication') }}
|
||||
</p-tab>
|
||||
}
|
||||
@if (currentUser.permissions.admin || currentUser.permissions.canAccessTaskManager) {
|
||||
<p-tab [value]="SettingsTab.Tasks">
|
||||
<i class="pi pi-list-check"></i> {{ t('tasks') }}
|
||||
</p-tab>
|
||||
}
|
||||
@if (currentUser.permissions.admin) {
|
||||
<p-tab [value]="SettingsTab.AuditLogs">
|
||||
<i class="pi pi-history"></i> {{ t('auditLogs') }}
|
||||
</p-tab>
|
||||
}
|
||||
<p-tab [value]="SettingsTab.OpdsV2">
|
||||
<i class="pi pi-globe"></i> {{ t('opds') }}
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.DeviceSettings">
|
||||
<i class="pi pi-mobile"></i> {{ t('devices') }}
|
||||
</p-tab>
|
||||
</p-tablist>
|
||||
<p-tabpanels>
|
||||
<p-tabpanel [value]="SettingsTab.ReaderSettings">
|
||||
<ng-template #content>
|
||||
<app-reader-preferences></app-reader-preferences>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.ViewPreferences">
|
||||
<ng-template #content>
|
||||
<app-view-preferences-parent></app-view-preferences-parent>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
@if (currentUser.permissions.admin || currentUser.permissions.canManageMetadataConfig) {
|
||||
<p-tabpanel [value]="SettingsTab.MetadataSettings">
|
||||
<ng-template #content>
|
||||
<app-metadata-settings-component></app-metadata-settings-component>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.LibraryMetadataSettings">
|
||||
<ng-template #content>
|
||||
<app-library-metadata-settings-component></app-library-metadata-settings-component>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
}
|
||||
@if (currentUser.permissions.admin || currentUser.permissions.canManageGlobalPreferences) {
|
||||
<p-tabpanel [value]="SettingsTab.ApplicationSettings">
|
||||
<ng-template #content>
|
||||
<app-global-preferences></app-global-preferences>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
}
|
||||
@if (currentUser.permissions.admin) {
|
||||
<p-tabpanel [value]="SettingsTab.UserManagement">
|
||||
<ng-template #content>
|
||||
<app-user-management></app-user-management>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
}
|
||||
<p-tabpanel [value]="SettingsTab.EmailSettingsV2">
|
||||
<ng-template #content>
|
||||
<app-email-v2></app-email-v2>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
@if (currentUser.permissions.admin || currentUser.permissions.canManageMetadataConfig) {
|
||||
<p-tabpanel [value]="SettingsTab.NamingPattern">
|
||||
<ng-template #content>
|
||||
<app-file-naming-pattern></app-file-naming-pattern>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
}
|
||||
@if (currentUser.permissions.admin) {
|
||||
<p-tabpanel [value]="SettingsTab.AuthenticationSettings">
|
||||
<ng-template #content>
|
||||
<app-authentication-settings></app-authentication-settings>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
}
|
||||
@if (currentUser.permissions.admin || currentUser.permissions.canAccessTaskManager) {
|
||||
<p-tabpanel [value]="SettingsTab.Tasks">
|
||||
<ng-template #content>
|
||||
<app-task-management></app-task-management>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
}
|
||||
@if (currentUser.permissions.admin) {
|
||||
<p-tabpanel [value]="SettingsTab.AuditLogs">
|
||||
<ng-template #content>
|
||||
<app-audit-logs></app-audit-logs>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
}
|
||||
<p-tabpanel [value]="SettingsTab.OpdsV2">
|
||||
<ng-template #content>
|
||||
<app-opds-settings></app-opds-settings>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.DeviceSettings">
|
||||
<ng-template #content>
|
||||
<app-device-settings-component></app-device-settings-component>
|
||||
</ng-template>
|
||||
</p-tabpanel>
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</ng-container>
|
||||
@@ -0,0 +1,5 @@
|
||||
.settings-container {
|
||||
border-radius: 0.75rem;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {UserService} from './user-management/user.service';
|
||||
import {GlobalPreferencesComponent} from './global-preferences/global-preferences.component';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {UserManagementComponent} from './user-management/user-management.component';
|
||||
import {AuthenticationSettingsComponent} from '../../core/security/oauth2-management/authentication-settings.component';
|
||||
import {ViewPreferencesParentComponent} from './view-preferences-parent/view-preferences-parent.component';
|
||||
import {ReaderPreferences} from './reader-preferences/reader-preferences.component';
|
||||
import {FileNamingPatternComponent} from './file-naming-pattern/file-naming-pattern.component';
|
||||
import {TaskManagementComponent} from './task-management/task-management.component';
|
||||
import {AuditLogsComponent} from './audit-logs/audit-logs.component';
|
||||
import {OpdsSettings} from './opds-settings/opds-settings';
|
||||
import {MetadataSettingsComponent} from './metadata-settings/metadata-settings-component';
|
||||
import {DeviceSettingsComponent} from './device-settings/device-settings-component';
|
||||
import {LibraryMetadataSettingsComponent} from './library-metadata-settings/library-metadata-settings.component';
|
||||
import {PageTitleService} from "../../shared/service/page-title.service";
|
||||
import {EmailV2Component} from './email-v2/email-v2.component';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
|
||||
export enum SettingsTab {
|
||||
ReaderSettings = 'reader',
|
||||
ViewPreferences = 'view',
|
||||
DeviceSettings = 'device',
|
||||
UserManagement = 'user',
|
||||
EmailSettingsV2 = 'email-v2',
|
||||
NamingPattern = 'naming-pattern',
|
||||
MetadataSettings = 'metadata',
|
||||
LibraryMetadataSettings = 'metadata-library',
|
||||
ApplicationSettings = 'application',
|
||||
AuthenticationSettings = 'authentication',
|
||||
OpdsV2 = 'opds',
|
||||
Tasks = 'task',
|
||||
AuditLogs = 'audit-logs',
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings',
|
||||
imports: [
|
||||
Tabs,
|
||||
TabList,
|
||||
Tab,
|
||||
TabPanels,
|
||||
TabPanel,
|
||||
GlobalPreferencesComponent,
|
||||
UserManagementComponent,
|
||||
AuthenticationSettingsComponent,
|
||||
ViewPreferencesParentComponent,
|
||||
ReaderPreferences,
|
||||
MetadataSettingsComponent,
|
||||
DeviceSettingsComponent,
|
||||
FileNamingPatternComponent,
|
||||
OpdsSettings,
|
||||
LibraryMetadataSettingsComponent,
|
||||
TaskManagementComponent,
|
||||
AuditLogsComponent,
|
||||
EmailV2Component,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './settings.component.html',
|
||||
styleUrl: './settings.component.scss'
|
||||
})
|
||||
export class SettingsComponent implements OnInit, OnDestroy {
|
||||
|
||||
protected userService = inject(UserService);
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
private pageTitle = inject(PageTitleService);
|
||||
|
||||
private routeSub!: Subscription;
|
||||
|
||||
SettingsTab = SettingsTab;
|
||||
|
||||
private validTabs = Object.values(SettingsTab);
|
||||
private _activeTab: SettingsTab = SettingsTab.ReaderSettings;
|
||||
|
||||
get activeTab(): SettingsTab {
|
||||
return this._activeTab;
|
||||
}
|
||||
|
||||
set activeTab(value: SettingsTab) {
|
||||
this._activeTab = value;
|
||||
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: {tab: value},
|
||||
queryParamsHandling: 'merge'
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.pageTitle.setPageTitle('Settings');
|
||||
|
||||
this.routeSub = this.route.queryParams.subscribe(params => {
|
||||
const tabParam = params['tab'];
|
||||
if (this.validTabs.includes(tabParam)) {
|
||||
this._activeTab = tabParam as SettingsTab;
|
||||
} else {
|
||||
this._activeTab = SettingsTab.ReaderSettings;
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: {tab: this._activeTab},
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: true
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.routeSub.unsubscribe();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {MetadataRefreshRequest} from '../../metadata/model/request/metadata-refresh-request.model';
|
||||
import {catchError, map} from 'rxjs/operators';
|
||||
import {of} from 'rxjs';
|
||||
import {TaskCreateRequest, TaskService, TaskType} from './task.service';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TaskHelperService {
|
||||
private taskService = inject(TaskService);
|
||||
private messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
refreshMetadataTask(options: MetadataRefreshRequest) {
|
||||
const request: TaskCreateRequest = {
|
||||
taskType: TaskType.REFRESH_METADATA_MANUAL,
|
||||
triggeredByCron: false,
|
||||
options
|
||||
};
|
||||
return this.taskService.startTask(request).pipe(
|
||||
map(() => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('settingsTasks.toast.metadataScheduled'),
|
||||
detail: this.t.translate('settingsTasks.toast.metadataScheduledDetail')
|
||||
});
|
||||
return {success: true};
|
||||
}),
|
||||
catchError((e) => {
|
||||
if (e.status === 409) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsTasks.toast.alreadyRunning'),
|
||||
life: 5000,
|
||||
detail: this.t.translate('settingsTasks.toast.metadataAlreadyRunningDetail')
|
||||
});
|
||||
} else {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: this.t.translate('settingsTasks.toast.metadataFailed'),
|
||||
life: 5000,
|
||||
detail: this.t.translate('settingsTasks.toast.metadataFailedDetail')
|
||||
});
|
||||
}
|
||||
return of({success: false});
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsTasks'">
|
||||
<div class="main-container">
|
||||
<div class="settings-header">
|
||||
<h2 class="settings-title">
|
||||
<i class="pi pi-list-check"></i>
|
||||
{{ t('title') }}
|
||||
<app-external-doc-link docType="taskManagement"></app-external-doc-link>
|
||||
</h2>
|
||||
<p class="settings-description" [innerHTML]="t('description')"></p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-cog"></i>
|
||||
{{ t('systemTasks.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('systemTasks.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
@if (loading && taskInfos.length === 0) {
|
||||
<div class="loading-state">
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
<span>{{ t('loading') }}</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!loading && taskInfos.length === 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<p class="empty-title">{{ t('emptyTitle') }}</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="tasks-list">
|
||||
@for (taskInfo of taskInfos; track taskInfo.taskType) {
|
||||
<div class="task-item" [class.is-running]="isTaskRunning(taskInfo.taskType)" [class.is-stale]="isTaskStale(getTaskHistory(taskInfo.taskType))">
|
||||
<div class="task-header">
|
||||
<div class="task-info">
|
||||
<div class="task-icon">
|
||||
<i class="pi" [ngClass]="getTaskIcon(taskInfo.taskType)"></i>
|
||||
</div>
|
||||
<div class="task-details">
|
||||
<div class="task-name-row">
|
||||
<span class="task-name">{{ getTaskLabel(taskInfo.taskType) }}</span>
|
||||
@if (isTaskRunning(taskInfo.taskType)) {
|
||||
<span class="status-badge running">
|
||||
<i class="pi pi-spin pi-spinner"></i>
|
||||
{{ t('status.running') }}
|
||||
</span>
|
||||
} @else if (isTaskStale(getTaskHistory(taskInfo.taskType))) {
|
||||
<span class="status-badge stale">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
{{ t('status.stale') }}
|
||||
</span>
|
||||
} @else if (getTaskHistory(taskInfo.taskType)?.id) {
|
||||
<span class="status-badge" [ngClass]="getLastRunInfoClass(taskInfo.taskType)">
|
||||
<span class="status-dot"></span>
|
||||
{{ getLastRunMessage(taskInfo.taskType) }}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
<p class="task-description">{{ getTaskDescription(taskInfo.taskType) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="task-controls">
|
||||
@if (!isTaskRunning(taskInfo.taskType) && isCronSupported(taskInfo.taskType) && getCronConfig(taskInfo.taskType)) {
|
||||
<div class="cron-section">
|
||||
<div class="cron-row">
|
||||
<i class="pi pi-clock"></i>
|
||||
@if (!isEditingCron(taskInfo.taskType)) {
|
||||
@if (getCronConfig(taskInfo.taskType)?.cronExpression) {
|
||||
<code class="cron-value">{{ getCronConfig(taskInfo.taskType)!.cronExpression }}</code>
|
||||
} @else {
|
||||
<span class="cron-empty">{{ t('cron.noSchedule') }}</span>
|
||||
}
|
||||
<p-button
|
||||
icon="pi pi-pencil"
|
||||
size="small"
|
||||
[text]="true"
|
||||
[rounded]="true"
|
||||
severity="info"
|
||||
[disabled]="cronUpdating"
|
||||
[pTooltip]="t('cron.edit')"
|
||||
(onClick)="startEditingCron(taskInfo.taskType)">
|
||||
</p-button>
|
||||
} @else {
|
||||
<div class="cron-edit">
|
||||
<input
|
||||
type="text"
|
||||
class="cron-input"
|
||||
[class.has-error]="!!cronValidationError"
|
||||
[(ngModel)]="editingCronExpression"
|
||||
(ngModelChange)="onCronExpressionChange()"
|
||||
[placeholder]="t('cron.placeholder')"
|
||||
(keyup.enter)="saveCronExpression(taskInfo.taskType)"
|
||||
(keyup.escape)="cancelEditingCron()">
|
||||
<p-button
|
||||
[icon]="cronUpdating ? 'pi pi-spinner pi-spin' : 'pi pi-check'"
|
||||
size="small"
|
||||
[rounded]="true"
|
||||
severity="success"
|
||||
[disabled]="!!cronValidationError || cronUpdating"
|
||||
(onClick)="saveCronExpression(taskInfo.taskType)">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-times"
|
||||
size="small"
|
||||
[rounded]="true"
|
||||
severity="secondary"
|
||||
(onClick)="cancelEditingCron()">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
<p-toggleswitch
|
||||
[ngModel]="getCronConfig(taskInfo.taskType)?.enabled ?? false"
|
||||
[disabled]="isEditingCron(taskInfo.taskType) || cronUpdating"
|
||||
(ngModelChange)="toggleCronEnabled(taskInfo.taskType)">
|
||||
</p-toggleswitch>
|
||||
</div>
|
||||
@if (isEditingCron(taskInfo.taskType) && cronValidationError) {
|
||||
<div class="cron-error">
|
||||
<i class="pi pi-exclamation-circle"></i>
|
||||
<span>{{ cronValidationError }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="task-actions">
|
||||
@if (canExecuteTask(taskInfo.taskType) || isTaskStale(getTaskHistory(taskInfo.taskType))) {
|
||||
<p-button
|
||||
[label]="getTaskButtonLabel(taskInfo.taskType)"
|
||||
[icon]="getTaskButtonIcon(taskInfo.taskType)"
|
||||
severity="info"
|
||||
[outlined]="true"
|
||||
[disabled]="isTaskExecuting(taskInfo.taskType)"
|
||||
(onClick)="executeTask(taskInfo.taskType)">
|
||||
</p-button>
|
||||
}
|
||||
@if (canCancelTask(getTaskHistory(taskInfo.taskType)) && !isTaskStale(getTaskHistory(taskInfo.taskType))) {
|
||||
<p-button
|
||||
[label]="'common.cancel' | transloco"
|
||||
[icon]="getCancelButtonIcon(taskInfo.taskType)"
|
||||
severity="danger"
|
||||
[outlined]="true"
|
||||
[disabled]="isTaskExecuting(taskInfo.taskType)"
|
||||
(onClick)="cancelTask(taskInfo.taskType)">
|
||||
</p-button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="task-body">
|
||||
@if (!isTaskRunning(taskInfo.taskType) && hasMetadata(taskInfo.taskType)) {
|
||||
<div class="task-metadata">
|
||||
<i class="pi" [ngClass]="getMetadataIcon(taskInfo.taskType)"></i>
|
||||
<span>{{ getTaskMetadata(taskInfo.taskType) }}</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!isTaskRunning(taskInfo.taskType) && taskInfo.taskType === TaskType.REFRESH_LIBRARY_METADATA) {
|
||||
<div class="task-options">
|
||||
<label class="option-label">{{ t('metadataReplace.label') }}</label>
|
||||
<p-select
|
||||
[options]="metadataReplaceOptions"
|
||||
[(ngModel)]="selectedMetadataReplaceMode"
|
||||
size="small"
|
||||
optionValue="value"
|
||||
[placeholder]="t('metadataReplace.selectMode')"
|
||||
class="mode-select">
|
||||
<ng-template let-option pTemplate="item">
|
||||
{{ option.translationKey | transloco }}
|
||||
</ng-template>
|
||||
<ng-template let-option pTemplate="selectedItem">
|
||||
{{ option.translationKey | transloco }}
|
||||
</ng-template>
|
||||
</p-select>
|
||||
<span class="option-hint">{{ getMetadataReplaceDescription(selectedMetadataReplaceMode) }}</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (isTaskRunning(taskInfo.taskType)) {
|
||||
<div class="task-progress">
|
||||
@if (isTaskStale(getTaskHistory(taskInfo.taskType))) {
|
||||
<div class="stale-warning">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
<span>{{ t('progress.staleWarning') }}</span>
|
||||
</div>
|
||||
}
|
||||
@if (getTaskHistory(taskInfo.taskType)?.message) {
|
||||
<div class="progress-row">
|
||||
<span class="progress-label">{{ t('progress.statusLabel') }}</span>
|
||||
<span class="progress-value">{{ getTaskStatusMessage(taskInfo.taskType) }}</span>
|
||||
</div>
|
||||
}
|
||||
@if (getTaskProgressPercentage(taskInfo.taskType) !== null) {
|
||||
<div class="progress-row">
|
||||
<span class="progress-label">{{ t('progress.progressLabel') }}</span>
|
||||
<div class="progress-bar-container">
|
||||
<p-progressbar [value]="getTaskProgressPercentage(taskInfo.taskType)!"></p-progressbar>
|
||||
<span class="progress-percent">{{ getTaskProgressPercentage(taskInfo.taskType) }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@if (getTaskUpdatedAt(taskInfo.taskType)) {
|
||||
<div class="progress-row">
|
||||
<span class="progress-label">{{ t('progress.startedLabel') }}</span>
|
||||
<span class="progress-value">{{ formatDate(getTaskUpdatedAt(taskInfo.taskType)!) }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,488 @@
|
||||
@use '../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.main-container {
|
||||
@include settings.settings-page-container;
|
||||
}
|
||||
|
||||
@include settings.settings-page-header;
|
||||
|
||||
.settings-title {
|
||||
@include settings.settings-page-title;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.settings-description {
|
||||
@include settings.settings-page-description;
|
||||
}
|
||||
|
||||
.cron-link {
|
||||
color: var(--p-primary-color);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
@include settings.settings-card;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
@include settings.settings-section-header;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
@include settings.settings-section-title;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
@include settings.settings-section-description;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
@include settings.settings-section-body;
|
||||
}
|
||||
|
||||
// Loading & Empty States
|
||||
.loading-state,
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem 2rem;
|
||||
text-align: center;
|
||||
color: var(--p-text-muted-color);
|
||||
|
||||
.pi {
|
||||
font-size: 2rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.pi-spinner {
|
||||
color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
.pi-check-circle {
|
||||
color: var(--p-green-500);
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
}
|
||||
|
||||
// Tasks List
|
||||
.tasks-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2.5rem;
|
||||
}
|
||||
|
||||
.task-item {
|
||||
background: color-mix(in srgb, var(--ground-background) 50%, var(--p-surface-800) 50%);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-left: 3px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
transition: border-color 0.2s ease, background 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: color-mix(in srgb, var(--ground-background) 40%, var(--p-surface-800) 60%);
|
||||
}
|
||||
|
||||
&.is-running {
|
||||
border-left-color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
&.is-stale {
|
||||
border-left-color: var(--p-orange-500);
|
||||
}
|
||||
}
|
||||
|
||||
.task-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.task-info {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.task-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
border-radius: 8px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.pi {
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
}
|
||||
|
||||
.task-details {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.task-name-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 0.375rem;
|
||||
}
|
||||
|
||||
.task-name {
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
color: var(--p-text-color);
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.125rem 0.5rem;
|
||||
border-radius: 12px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
|
||||
&.running {
|
||||
background: color-mix(in srgb, var(--p-primary-color) 15%, transparent);
|
||||
color: var(--p-primary-color);
|
||||
|
||||
.pi {
|
||||
font-size: 0.625rem;
|
||||
}
|
||||
}
|
||||
|
||||
&.stale {
|
||||
background: color-mix(in srgb, var(--p-orange-500) 15%, transparent);
|
||||
color: var(--p-orange-500);
|
||||
|
||||
.pi {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
&.success {
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
&.error {
|
||||
color: var(--p-red-400);
|
||||
}
|
||||
|
||||
&.warning {
|
||||
color: var(--p-orange-400);
|
||||
}
|
||||
|
||||
&.info {
|
||||
color: var(--p-text-muted-color);
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: currentColor;
|
||||
}
|
||||
}
|
||||
|
||||
.task-description {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.task-controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.task-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
// Task Body
|
||||
.task-body {
|
||||
padding: 0 1rem 1rem 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
|
||||
&:empty {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.task-metadata {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: var(--p-text-color);
|
||||
background: color-mix(in srgb, var(--p-primary-color) 10%, transparent);
|
||||
border: 1px solid color-mix(in srgb, var(--p-primary-color) 20%, transparent);
|
||||
padding: 0.375rem 0.75rem;
|
||||
border-radius: 6px;
|
||||
width: fit-content;
|
||||
|
||||
.pi {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
// Task Options
|
||||
.task-options {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
padding: 0.75rem;
|
||||
background: var(--p-surface-800);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.option-label {
|
||||
font-weight: 600;
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-color);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.option-hint {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
flex: 1;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex: none;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .mode-select {
|
||||
min-width: 200px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
// Cron Section (in header)
|
||||
.cron-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
background: var(--p-surface-800);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.cron-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: nowrap;
|
||||
|
||||
.pi-clock {
|
||||
color: var(--p-primary-color);
|
||||
font-size: 0.875rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
.cron-value {
|
||||
font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-primary-color);
|
||||
background: var(--p-surface-900);
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--p-surface-700);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.cron-empty {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-style: italic;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.cron-edit {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
|
||||
@media (max-width: 600px) {
|
||||
flex-wrap: wrap;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.cron-input {
|
||||
width: 130px;
|
||||
font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-text-color);
|
||||
background: var(--p-surface-900);
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--p-surface-700);
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
|
||||
&:focus {
|
||||
border-color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
&.has-error {
|
||||
border-color: var(--p-red-500);
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.cron-error {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--p-orange-400);
|
||||
padding: 0.375rem 0.5rem;
|
||||
background: color-mix(in srgb, var(--p-orange-500) 10%, transparent);
|
||||
border: 1px solid var(--p-orange-500);
|
||||
border-radius: 4px;
|
||||
line-height: 1.4;
|
||||
|
||||
.pi {
|
||||
font-size: 0.75rem;
|
||||
margin-top: 0.0625rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Task Progress (Running State)
|
||||
.task-progress {
|
||||
padding: 1rem;
|
||||
background: var(--p-surface-800);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.625rem;
|
||||
}
|
||||
|
||||
.stale-warning {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
padding: 0.625rem 0.75rem;
|
||||
background: color-mix(in srgb, var(--p-orange-500) 15%, transparent);
|
||||
border: 1px solid var(--p-orange-500);
|
||||
border-radius: 4px;
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-orange-400);
|
||||
|
||||
.pi {
|
||||
font-size: 1rem;
|
||||
margin-top: 0.0625rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.progress-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
|
||||
@media (max-width: 600px) {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
}
|
||||
|
||||
.progress-label {
|
||||
font-weight: 600;
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-color);
|
||||
min-width: 70px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.progress-value {
|
||||
font-size: 0.875rem;
|
||||
color: var(--p-text-muted-color);
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.progress-bar-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
@media (max-width: 600px) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.progress-percent {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: var(--p-text-muted-color);
|
||||
min-width: 40px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
@@ -0,0 +1,622 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {Button} from 'primeng/button';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {
|
||||
LibraryRescanOptions,
|
||||
MetadataReplaceMode,
|
||||
TASK_TYPE_CONFIG,
|
||||
TaskCreateRequest,
|
||||
TaskCronConfigRequest,
|
||||
TaskHistory,
|
||||
TaskInfo,
|
||||
TaskProgressPayload,
|
||||
TaskService,
|
||||
TaskStatus,
|
||||
TaskType
|
||||
} from './task.service';
|
||||
import {MetadataRefreshRequest} from '../../metadata/model/request/metadata-refresh-request.model';
|
||||
import {finalize, forkJoin, Subscription} from 'rxjs';
|
||||
import {ExternalDocLinkComponent} from '../../../shared/components/external-doc-link/external-doc-link.component';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Component({
|
||||
selector: 'app-task-management',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
Button,
|
||||
ProgressBar,
|
||||
Select,
|
||||
FormsModule,
|
||||
ExternalDocLinkComponent,
|
||||
ToggleSwitch,
|
||||
Tooltip,
|
||||
TranslocoDirective,
|
||||
TranslocoPipe
|
||||
],
|
||||
templateUrl: './task-management.component.html',
|
||||
styleUrl: './task-management.component.scss'
|
||||
})
|
||||
export class TaskManagementComponent implements OnInit, OnDestroy {
|
||||
// Services
|
||||
private messageService = inject(MessageService);
|
||||
private taskService = inject(TaskService);
|
||||
private t = inject(TranslocoService);
|
||||
|
||||
// State
|
||||
taskInfos: TaskInfo[] = [];
|
||||
taskHistories = new Map<string, TaskHistory>();
|
||||
loading = false;
|
||||
executingTasks = new Set<string>();
|
||||
private subscription?: Subscription;
|
||||
|
||||
// Metadata Replace Options
|
||||
metadataReplaceOptions = [
|
||||
{
|
||||
label: 'Update Missing Metadata Only (Recommended)',
|
||||
value: MetadataReplaceMode.REPLACE_MISSING,
|
||||
translationKey: 'settingsTasks.metadataReplace.replaceMissing',
|
||||
descriptionKey: 'settingsTasks.metadataReplace.replaceMissingDesc'
|
||||
},
|
||||
{
|
||||
label: 'Replace All Metadata (Overwrite Existing)',
|
||||
value: MetadataReplaceMode.REPLACE_ALL,
|
||||
translationKey: 'settingsTasks.metadataReplace.replaceAll',
|
||||
descriptionKey: 'settingsTasks.metadataReplace.replaceAllDesc'
|
||||
}
|
||||
];
|
||||
selectedMetadataReplaceMode: MetadataReplaceMode = MetadataReplaceMode.REPLACE_MISSING;
|
||||
|
||||
// Cron Editing State
|
||||
cronUpdating = false;
|
||||
editingCronTaskType: string | null = null;
|
||||
editingCronExpression: string = '';
|
||||
cronValidationError: string | null = null;
|
||||
|
||||
// Constants
|
||||
private readonly STALE_TASK_THRESHOLD_MS = 5 * 60 * 1000; // 5 minutes
|
||||
protected readonly TaskType = TaskType;
|
||||
|
||||
// ============================================================================
|
||||
// Lifecycle Hooks
|
||||
// ============================================================================
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadTasks();
|
||||
this.subscribeToTaskProgress();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscription?.unsubscribe();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Data Loading & Real-time Updates
|
||||
// ============================================================================
|
||||
|
||||
loadTasks(): void {
|
||||
this.loading = true;
|
||||
|
||||
forkJoin({
|
||||
available: this.taskService.getAvailableTasks(),
|
||||
latest: this.taskService.getLatestTasksForEachType()
|
||||
})
|
||||
.pipe(finalize(() => this.loading = false))
|
||||
.subscribe({
|
||||
next: ({available, latest}) => {
|
||||
this.taskInfos = this.sortTasksByDisplayOrder(available);
|
||||
this.taskHistories.clear();
|
||||
latest.taskHistories.forEach(history => {
|
||||
this.taskHistories.set(history.type, history);
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error loading tasks:', error);
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsTasks.toast.loadError'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private subscribeToTaskProgress(): void {
|
||||
this.subscription = this.taskService.taskProgress$.subscribe(progress => {
|
||||
if (progress) {
|
||||
this.updateTaskWithProgress(progress);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private updateTaskWithProgress(progress: TaskProgressPayload): void {
|
||||
const existingHistory = this.taskHistories.get(progress.taskType);
|
||||
|
||||
const updatedHistory: TaskHistory = {
|
||||
id: progress.taskId,
|
||||
type: progress.taskType,
|
||||
status: progress.taskStatus,
|
||||
progressPercentage: progress.progress,
|
||||
message: progress.message,
|
||||
createdAt: existingHistory?.createdAt || new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
completedAt: (progress.taskStatus === TaskStatus.COMPLETED || progress.taskStatus === TaskStatus.FAILED)
|
||||
? new Date().toISOString()
|
||||
: existingHistory?.completedAt || null
|
||||
};
|
||||
|
||||
this.taskHistories.set(progress.taskType, updatedHistory);
|
||||
|
||||
if (progress.taskStatus === TaskStatus.COMPLETED || progress.taskStatus === TaskStatus.FAILED) {
|
||||
setTimeout(() => this.loadTasks(), 1000);
|
||||
}
|
||||
}
|
||||
|
||||
private sortTasksByDisplayOrder(tasks: TaskInfo[]): TaskInfo[] {
|
||||
return tasks.sort((a, b) => {
|
||||
const orderA = TASK_TYPE_CONFIG[a.taskType as TaskType]?.displayOrder ?? 999;
|
||||
const orderB = TASK_TYPE_CONFIG[b.taskType as TaskType]?.displayOrder ?? 999;
|
||||
return orderA - orderB;
|
||||
});
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Task Execution Operations
|
||||
// ============================================================================
|
||||
|
||||
canExecuteTask(taskType: string): boolean {
|
||||
const history = this.taskHistories.get(taskType);
|
||||
return this.canRunTask(history) || this.isTaskStale(history);
|
||||
}
|
||||
|
||||
executeTask(taskType: string): void {
|
||||
this.runTask(taskType);
|
||||
}
|
||||
|
||||
runTask(type: string): void {
|
||||
const history = this.taskHistories.get(type);
|
||||
if (!this.canRunTask(history) && !this.isTaskStale(history)) {
|
||||
this.showMessage('warn', this.t.translate('settingsTasks.toast.alreadyRunning'), this.t.translate('settingsTasks.toast.alreadyRunningDetail'));
|
||||
return;
|
||||
}
|
||||
|
||||
let options = null;
|
||||
|
||||
if (type === TaskType.REFRESH_LIBRARY_METADATA) {
|
||||
options = {
|
||||
metadataReplaceMode: this.selectedMetadataReplaceMode
|
||||
};
|
||||
}
|
||||
|
||||
this.runTaskWithOptions(type, options);
|
||||
}
|
||||
|
||||
private runTaskWithOptions(type: string, options: LibraryRescanOptions | MetadataRefreshRequest | null): void {
|
||||
const request: TaskCreateRequest = {
|
||||
taskType: type as TaskType,
|
||||
triggeredByCron: false,
|
||||
options: options
|
||||
};
|
||||
|
||||
const isAsync = TASK_TYPE_CONFIG[type as TaskType]?.async || false;
|
||||
|
||||
this.executingTasks.add(type);
|
||||
this.taskService.startTask(request)
|
||||
.pipe(finalize(() => this.executingTasks.delete(type)))
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
const name = this.getTaskDisplayName(type);
|
||||
if (isAsync) {
|
||||
this.showMessage('info', this.t.translate('settingsTasks.toast.taskQueued'), this.t.translate('settingsTasks.toast.taskQueuedDetail', {name}));
|
||||
} else {
|
||||
if (response.status === TaskStatus.COMPLETED) {
|
||||
this.showMessage('success', this.t.translate('settingsTasks.toast.taskCompleted'), this.t.translate('settingsTasks.toast.taskCompletedDetail', {name}));
|
||||
} else if (response.status === TaskStatus.FAILED) {
|
||||
this.showMessage('error', this.t.translate('settingsTasks.toast.taskFailed'), response.message || this.t.translate('settingsTasks.toast.taskFailedDetail', {name}));
|
||||
} else {
|
||||
this.showMessage('success', this.t.translate('settingsTasks.toast.taskStarted'), this.t.translate('settingsTasks.toast.taskStartedDetail', {name}));
|
||||
}
|
||||
}
|
||||
this.loadTasks();
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error starting task:', error);
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsTasks.toast.startError', {name: this.getTaskDisplayName(type)}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancelTask(taskType: string): void {
|
||||
const history = this.taskHistories.get(taskType);
|
||||
if (!history?.id) {
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsTasks.toast.cancelNoId'));
|
||||
return;
|
||||
}
|
||||
|
||||
this.executingTasks.add(taskType);
|
||||
this.taskService.cancelTask(history.id)
|
||||
.pipe(finalize(() => this.executingTasks.delete(taskType)))
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
if (response.cancelled) {
|
||||
this.showMessage('success', this.t.translate('settingsTasks.toast.taskCancelled'), response.message || this.t.translate('settingsTasks.toast.cancelledDetail'));
|
||||
this.loadTasks();
|
||||
} else {
|
||||
this.showMessage('error', this.t.translate('settingsTasks.toast.cancelFailed'), response.message || this.t.translate('settingsTasks.toast.cancelError'));
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error cancelling task:', error);
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsTasks.toast.cancelError'));
|
||||
this.loadTasks();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
canRunTask(history: TaskHistory | undefined): boolean {
|
||||
return !history?.status || history.status === TaskStatus.COMPLETED || history.status === TaskStatus.FAILED || history.status === TaskStatus.CANCELLED;
|
||||
}
|
||||
|
||||
canCancelTask(history: TaskHistory | undefined): boolean {
|
||||
return history?.status === TaskStatus.IN_PROGRESS || history?.status === TaskStatus.PENDING;
|
||||
}
|
||||
|
||||
isTaskExecuting(taskType: string): boolean {
|
||||
return this.executingTasks.has(taskType);
|
||||
}
|
||||
|
||||
isTaskRunning(taskType: string): boolean {
|
||||
const history = this.taskHistories.get(taskType);
|
||||
return history?.status === TaskStatus.IN_PROGRESS || history?.status === TaskStatus.PENDING;
|
||||
}
|
||||
|
||||
isTaskStale(history: TaskHistory | undefined): boolean {
|
||||
if (!history || !this.isTaskRunningForHistory(history) || !history.updatedAt) {
|
||||
return false;
|
||||
}
|
||||
const lastUpdate = new Date(history.updatedAt).getTime();
|
||||
const now = Date.now();
|
||||
return (now - lastUpdate) > this.STALE_TASK_THRESHOLD_MS;
|
||||
}
|
||||
|
||||
private isTaskRunningForHistory(history: TaskHistory): boolean {
|
||||
return history.status === TaskStatus.IN_PROGRESS || history.status === TaskStatus.PENDING;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Cron Configuration Management
|
||||
// ============================================================================
|
||||
|
||||
isCronSupported(taskType: string): boolean {
|
||||
const taskInfo = this.taskInfos.find(t => t.taskType === taskType);
|
||||
return taskInfo?.cronSupported || false;
|
||||
}
|
||||
|
||||
getCronConfig(taskType: string): { enabled?: boolean; cronExpression?: string } | null | undefined {
|
||||
const taskInfo = this.taskInfos.find(t => t.taskType === taskType);
|
||||
if (!taskInfo?.cronConfig) return null;
|
||||
|
||||
const cronConfig = taskInfo.cronConfig;
|
||||
return {
|
||||
enabled: cronConfig.enabled,
|
||||
cronExpression: cronConfig.cronExpression ?? undefined
|
||||
};
|
||||
}
|
||||
|
||||
toggleCronEnabled(taskType: string): void {
|
||||
const cronConfig = this.getCronConfig(taskType);
|
||||
if (!cronConfig) return;
|
||||
|
||||
const request: TaskCronConfigRequest = {
|
||||
enabled: !(cronConfig.enabled ?? false)
|
||||
};
|
||||
|
||||
this.updateCronConfig(taskType, request);
|
||||
}
|
||||
|
||||
isEditingCron(taskType: string): boolean {
|
||||
return this.editingCronTaskType === taskType;
|
||||
}
|
||||
|
||||
startEditingCron(taskType: string): void {
|
||||
const cronConfig = this.getCronConfig(taskType);
|
||||
this.editingCronTaskType = taskType;
|
||||
this.editingCronExpression = cronConfig?.cronExpression || '';
|
||||
this.cronValidationError = null;
|
||||
this.validateCronExpression(this.editingCronExpression);
|
||||
}
|
||||
|
||||
cancelEditingCron(): void {
|
||||
this.editingCronTaskType = null;
|
||||
this.editingCronExpression = '';
|
||||
this.cronValidationError = null;
|
||||
}
|
||||
|
||||
onCronExpressionChange(): void {
|
||||
this.validateCronExpression(this.editingCronExpression);
|
||||
}
|
||||
|
||||
saveCronExpression(taskType: string): void {
|
||||
if (this.cronValidationError) {
|
||||
return;
|
||||
}
|
||||
|
||||
const expression = this.editingCronExpression.trim() || null;
|
||||
this.updateCronExpression(taskType, expression);
|
||||
this.cancelEditingCron();
|
||||
}
|
||||
|
||||
updateCronExpression(taskType: string, expression: string | null): void {
|
||||
const request: TaskCronConfigRequest = {
|
||||
cronExpression: expression
|
||||
};
|
||||
|
||||
this.updateCronConfig(taskType, request);
|
||||
}
|
||||
|
||||
private updateCronConfig(taskType: string, request: TaskCronConfigRequest): void {
|
||||
this.cronUpdating = true;
|
||||
this.taskService.updateCronConfig(taskType, request)
|
||||
.pipe(finalize(() => this.cronUpdating = false))
|
||||
.subscribe({
|
||||
next: (updatedConfig) => {
|
||||
const taskInfoIndex = this.taskInfos.findIndex(t => t.taskType === taskType);
|
||||
if (taskInfoIndex !== -1) {
|
||||
this.taskInfos[taskInfoIndex].cronConfig = updatedConfig;
|
||||
}
|
||||
this.showMessage('success', this.t.translate('common.success'), this.t.translate('settingsTasks.cron.updateSuccess'));
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error updating cron config:', error);
|
||||
this.showMessage('error', this.t.translate('common.error'), this.t.translate('settingsTasks.cron.updateError'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Cron Validation
|
||||
// ============================================================================
|
||||
|
||||
private validateCronExpression(expression: string): void {
|
||||
if (!expression || expression.trim() === '') {
|
||||
this.cronValidationError = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const trimmed = expression.trim();
|
||||
const parts = trimmed.split(/\s+/);
|
||||
|
||||
if (parts.length !== 6) {
|
||||
this.cronValidationError = this.t.translate('settingsTasks.cron.validationPrefix');
|
||||
return;
|
||||
}
|
||||
|
||||
const validations = [
|
||||
{field: parts[0], name: 'Seconds', range: [0, 59]},
|
||||
{field: parts[1], name: 'Minutes', range: [0, 59]},
|
||||
{field: parts[2], name: 'Hours', range: [0, 23]},
|
||||
{field: parts[3], name: 'Day of Month', range: [1, 31]},
|
||||
{field: parts[4], name: 'Month', range: [1, 12]},
|
||||
{field: parts[5], name: 'Day of Week', range: [0, 7]}
|
||||
];
|
||||
|
||||
for (const validation of validations) {
|
||||
if (!this.isValidCronField(validation.field, validation.range[0], validation.range[1])) {
|
||||
this.cronValidationError = this.t.translate('settingsTasks.cron.invalidField', {name: validation.name, value: validation.field});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.cronValidationError = null;
|
||||
}
|
||||
|
||||
private isValidCronField(field: string, min: number, max: number): boolean {
|
||||
if (field === '*' || field === '?') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (field.includes('-')) {
|
||||
const [start, end] = field.split('-').map(Number);
|
||||
return !isNaN(start) && !isNaN(end) && start >= min && end <= max && start <= end;
|
||||
}
|
||||
|
||||
if (field.includes('/')) {
|
||||
const [range, step] = field.split('/');
|
||||
const stepNum = Number(step);
|
||||
if (isNaN(stepNum) || stepNum <= 0) return false;
|
||||
|
||||
if (range === '*') return true;
|
||||
if (range.includes('-')) {
|
||||
const [start, end] = range.split('-').map(Number);
|
||||
return !isNaN(start) && !isNaN(end) && start >= min && end <= max;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (field.includes(',')) {
|
||||
const values = field.split(',').map(Number);
|
||||
return values.every(val => !isNaN(val) && val >= min && val <= max);
|
||||
}
|
||||
|
||||
const num = Number(field);
|
||||
return !isNaN(num) && num >= min && num <= max;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// UI Helper Methods - Task Information
|
||||
// ============================================================================
|
||||
|
||||
getTaskDisplayName(type: string): string {
|
||||
const taskInfo = this.taskInfos.find(t => t.taskType === type);
|
||||
return taskInfo?.name || type.replace(/_/g, ' ').toLowerCase().replace(/\b\w/g, l => l.toUpperCase());
|
||||
}
|
||||
|
||||
getTaskDescription(type: string): string {
|
||||
const taskInfo = this.taskInfos.find(t => t.taskType === type);
|
||||
return taskInfo?.description || 'System maintenance task.';
|
||||
}
|
||||
|
||||
getTaskDisplayOrder(type: string): number {
|
||||
return TASK_TYPE_CONFIG[type as TaskType]?.displayOrder ?? 999;
|
||||
}
|
||||
|
||||
getTaskLabel(taskType: string): string {
|
||||
return `${this.getTaskDisplayOrder(taskType)}. ${this.getTaskDisplayName(taskType)}`;
|
||||
}
|
||||
|
||||
getTaskIcon(taskType: string): string {
|
||||
const icons: Record<string, string> = {
|
||||
[TaskType.CLEAR_PDF_CACHE]: 'pi-database',
|
||||
[TaskType.REFRESH_LIBRARY_METADATA]: 'pi-refresh',
|
||||
[TaskType.UPDATE_BOOK_RECOMMENDATIONS]: 'pi-sparkles',
|
||||
[TaskType.CLEANUP_DELETED_BOOKS]: 'pi-trash',
|
||||
[TaskType.SYNC_LIBRARY_FILES]: 'pi-sync',
|
||||
[TaskType.BOOKDROP_PERIODIC_SCANNING]: 'pi-inbox',
|
||||
[TaskType.CLEANUP_TEMP_METADATA]: 'pi-file'
|
||||
};
|
||||
return icons[taskType] || 'pi-cog';
|
||||
}
|
||||
|
||||
getTaskMetadata(taskType: string): string | null {
|
||||
const taskInfo = this.taskInfos.find(t => t.taskType === taskType);
|
||||
return taskInfo?.metadata || null;
|
||||
}
|
||||
|
||||
hasMetadata(taskType: string): boolean {
|
||||
const taskInfo = this.taskInfos.find(t => t.taskType === taskType);
|
||||
return !!taskInfo?.metadata && taskInfo.metadata.trim().length > 0;
|
||||
}
|
||||
|
||||
getMetadataIcon(taskType: string): string {
|
||||
const icons: Record<string, string> = {
|
||||
[TaskType.CLEAR_PDF_CACHE]: 'pi-database',
|
||||
[TaskType.CLEANUP_DELETED_BOOKS]: 'pi-trash',
|
||||
[TaskType.CLEANUP_TEMP_METADATA]: 'pi-file'
|
||||
};
|
||||
return icons[taskType] || 'pi-info-circle';
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// UI Helper Methods - Task History & Status
|
||||
// ============================================================================
|
||||
|
||||
getTaskHistory(taskType: string): TaskHistory | undefined {
|
||||
return this.taskHistories.get(taskType);
|
||||
}
|
||||
|
||||
getTaskProgressPercentage(taskType: string): number | null {
|
||||
return this.taskHistories.get(taskType)?.progressPercentage || null;
|
||||
}
|
||||
|
||||
getTaskUpdatedAt(taskType: string): string | null {
|
||||
return this.taskHistories.get(taskType)?.updatedAt || null;
|
||||
}
|
||||
|
||||
getTaskStatusMessage(taskType: string): string {
|
||||
const history = this.taskHistories.get(taskType);
|
||||
if (this.isTaskStale(history)) {
|
||||
return this.t.translate('settingsTasks.progress.stuckMessage');
|
||||
}
|
||||
return history?.message || this.t.translate('settingsTasks.progress.processing');
|
||||
}
|
||||
|
||||
getLastRunMessage(taskType: string): string {
|
||||
const history = this.taskHistories.get(taskType);
|
||||
if (!history?.completedAt && !history?.updatedAt) {
|
||||
return this.t.translate('settingsTasks.status.neverRun');
|
||||
}
|
||||
|
||||
const dateStr = history.completedAt || history.updatedAt;
|
||||
if (!dateStr) return this.t.translate('settingsTasks.status.neverRun');
|
||||
|
||||
const date = new Date(dateStr);
|
||||
const now = new Date();
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffMins = Math.floor(diffMs / 60000);
|
||||
const diffHours = Math.floor(diffMs / 3600000);
|
||||
const diffDays = Math.floor(diffMs / 86400000);
|
||||
|
||||
if (diffMins < 1) return this.t.translate('settingsTasks.status.justNow');
|
||||
if (diffMins < 60) return `${diffMins}m ago`;
|
||||
if (diffHours < 24) return `${diffHours}h ago`;
|
||||
if (diffDays < 7) return `${diffDays}d ago`;
|
||||
|
||||
return date.toLocaleDateString();
|
||||
}
|
||||
|
||||
getLastRunInfoClass(taskType: string): string {
|
||||
const history = this.taskHistories.get(taskType);
|
||||
if (!history?.status) return 'info';
|
||||
|
||||
switch (history.status) {
|
||||
case TaskStatus.COMPLETED:
|
||||
return 'success';
|
||||
case TaskStatus.FAILED:
|
||||
return 'error';
|
||||
case TaskStatus.CANCELLED:
|
||||
return 'warning';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// UI Helper Methods - Buttons & Icons
|
||||
// ============================================================================
|
||||
|
||||
getTaskButtonIcon(taskType: string): string {
|
||||
if (this.isTaskExecuting(taskType)) {
|
||||
return 'pi pi-spinner pi-spin';
|
||||
}
|
||||
return 'pi ' + this.getTaskIcon(taskType);
|
||||
}
|
||||
|
||||
getTaskButtonLabel(taskType: string): string {
|
||||
const history = this.taskHistories.get(taskType);
|
||||
if (this.isTaskStale(history)) {
|
||||
return this.t.translate('settingsTasks.buttons.rerun');
|
||||
}
|
||||
return this.t.translate('settingsTasks.buttons.run');
|
||||
}
|
||||
|
||||
getCancelButtonIcon(taskType: string): string {
|
||||
if (this.isTaskExecuting(taskType)) {
|
||||
return 'pi pi-spinner pi-spin';
|
||||
}
|
||||
return 'pi pi-times';
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// UI Helper Methods - Metadata Replace
|
||||
// ============================================================================
|
||||
|
||||
getMetadataReplaceDescription(mode: MetadataReplaceMode): string {
|
||||
switch (mode) {
|
||||
case MetadataReplaceMode.REPLACE_MISSING:
|
||||
return this.t.translate('settingsTasks.metadataReplace.replaceMissingDesc');
|
||||
case MetadataReplaceMode.REPLACE_ALL:
|
||||
return this.t.translate('settingsTasks.metadataReplace.replaceAllDesc');
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Utility Methods
|
||||
// ============================================================================
|
||||
|
||||
formatDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
private showMessage(severity: 'success' | 'info' | 'warn' | 'error', summary: string, detail: string): void {
|
||||
this.messageService.add({
|
||||
severity,
|
||||
summary,
|
||||
detail
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {MetadataRefreshRequest} from '../../metadata/model/request/metadata-refresh-request.model';
|
||||
|
||||
export enum TaskType {
|
||||
CLEAR_PDF_CACHE = 'CLEAR_PDF_CACHE',
|
||||
REFRESH_LIBRARY_METADATA = 'REFRESH_LIBRARY_METADATA',
|
||||
UPDATE_BOOK_RECOMMENDATIONS = 'UPDATE_BOOK_RECOMMENDATIONS',
|
||||
CLEANUP_DELETED_BOOKS = 'CLEANUP_DELETED_BOOKS',
|
||||
SYNC_LIBRARY_FILES = 'SYNC_LIBRARY_FILES',
|
||||
BOOKDROP_PERIODIC_SCANNING = 'BOOKDROP_PERIODIC_SCANNING',
|
||||
CLEANUP_TEMP_METADATA = 'CLEANUP_TEMP_METADATA',
|
||||
REFRESH_METADATA_MANUAL = 'REFRESH_METADATA_MANUAL'
|
||||
}
|
||||
|
||||
export const TASK_TYPE_CONFIG: Record<TaskType, { parallel: boolean; async: boolean; displayOrder: number }> = {
|
||||
[TaskType.REFRESH_LIBRARY_METADATA]: {parallel: false, async: true, displayOrder: 1},
|
||||
[TaskType.SYNC_LIBRARY_FILES]: {parallel: false, async: false, displayOrder: 2},
|
||||
[TaskType.BOOKDROP_PERIODIC_SCANNING]: {parallel: false, async: false, displayOrder: 3},
|
||||
[TaskType.UPDATE_BOOK_RECOMMENDATIONS]: {parallel: false, async: true, displayOrder: 4},
|
||||
[TaskType.CLEANUP_DELETED_BOOKS]: {parallel: false, async: false, displayOrder: 5},
|
||||
[TaskType.CLEANUP_TEMP_METADATA]: {parallel: false, async: false, displayOrder: 6},
|
||||
[TaskType.REFRESH_METADATA_MANUAL]: {parallel: false, async: false, displayOrder: 7},
|
||||
[TaskType.CLEAR_PDF_CACHE]: {parallel: false, async: false, displayOrder: 8},
|
||||
};
|
||||
|
||||
export enum MetadataReplaceMode {
|
||||
REPLACE_ALL = 'REPLACE_ALL',
|
||||
REPLACE_MISSING = 'REPLACE_MISSING'
|
||||
}
|
||||
|
||||
export interface LibraryRescanOptions {
|
||||
metadataReplaceMode?: MetadataReplaceMode;
|
||||
}
|
||||
|
||||
export interface TaskCreateRequest {
|
||||
taskType: TaskType;
|
||||
triggeredByCron?: boolean;
|
||||
options?: LibraryRescanOptions | MetadataRefreshRequest | null;
|
||||
}
|
||||
|
||||
export interface TaskCreateResponse {
|
||||
id?: string;
|
||||
type: string;
|
||||
status: TaskStatus;
|
||||
message?: string;
|
||||
createdAt?: string;
|
||||
}
|
||||
|
||||
export interface TaskStatusResponse {
|
||||
taskHistories: TaskHistory[];
|
||||
}
|
||||
|
||||
export enum TaskStatus {
|
||||
ACCEPTED = 'ACCEPTED',
|
||||
IN_PROGRESS = 'IN_PROGRESS',
|
||||
COMPLETED = 'COMPLETED',
|
||||
FAILED = 'FAILED',
|
||||
CANCELLED = 'CANCELLED',
|
||||
PENDING = 'PENDING'
|
||||
}
|
||||
|
||||
export interface CronConfig {
|
||||
id: number | null;
|
||||
taskType: string;
|
||||
cronExpression: string | null;
|
||||
enabled: boolean;
|
||||
options: Record<string, unknown> | null;
|
||||
createdAt: string | null;
|
||||
updatedAt: string | null;
|
||||
}
|
||||
|
||||
export interface TaskInfo {
|
||||
taskType: string;
|
||||
name: string;
|
||||
description: string;
|
||||
parallel: boolean;
|
||||
async: boolean;
|
||||
cronSupported: boolean;
|
||||
cronConfig: CronConfig | null;
|
||||
metadata?: string | null;
|
||||
}
|
||||
|
||||
export interface TaskHistory {
|
||||
id: string | null;
|
||||
type: string;
|
||||
status: TaskStatus | null;
|
||||
progressPercentage: number | null;
|
||||
message: string | null;
|
||||
createdAt: string | null;
|
||||
updatedAt: string | null;
|
||||
completedAt: string | null;
|
||||
}
|
||||
|
||||
export interface TaskCancelResponse {
|
||||
taskId: string;
|
||||
cancelled: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface TaskCronConfigRequest {
|
||||
cronExpression?: string | null;
|
||||
enabled?: boolean | null;
|
||||
}
|
||||
|
||||
export interface TaskProgressPayload {
|
||||
taskId: string;
|
||||
taskType: string;
|
||||
message: string;
|
||||
progress: number; // 0-100 percentage
|
||||
taskStatus: TaskStatus;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TaskService {
|
||||
private http = inject(HttpClient);
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/tasks`;
|
||||
|
||||
private taskProgressSubject = new BehaviorSubject<TaskProgressPayload | null>(null);
|
||||
public taskProgress$ = this.taskProgressSubject.asObservable();
|
||||
|
||||
getAvailableTasks(): Observable<TaskInfo[]> {
|
||||
return this.http.get<TaskInfo[]>(`${this.baseUrl}`);
|
||||
}
|
||||
|
||||
startTask(request: TaskCreateRequest): Observable<TaskCreateResponse> {
|
||||
return this.http.post<TaskCreateResponse>(`${this.baseUrl}/start`, request);
|
||||
}
|
||||
|
||||
getLatestTasksForEachType(): Observable<TaskStatusResponse> {
|
||||
return this.http.get<TaskStatusResponse>(`${this.baseUrl}/last`);
|
||||
}
|
||||
|
||||
cancelTask(taskId: string): Observable<TaskCancelResponse> {
|
||||
return this.http.delete<TaskCancelResponse>(`${this.baseUrl}/${taskId}/cancel`);
|
||||
}
|
||||
|
||||
updateCronConfig(taskType: string, request: TaskCronConfigRequest): Observable<CronConfig> {
|
||||
return this.http.patch<CronConfig>(`${this.baseUrl}/${taskType}/cron`, request);
|
||||
}
|
||||
|
||||
handleTaskProgress(progress: TaskProgressPayload): void {
|
||||
this.taskProgressSubject.next(progress);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
export enum ContentRestrictionType {
|
||||
CATEGORY = 'CATEGORY',
|
||||
TAG = 'TAG',
|
||||
MOOD = 'MOOD',
|
||||
AGE_RATING = 'AGE_RATING',
|
||||
CONTENT_RATING = 'CONTENT_RATING'
|
||||
}
|
||||
|
||||
export enum ContentRestrictionMode {
|
||||
EXCLUDE = 'EXCLUDE',
|
||||
ALLOW_ONLY = 'ALLOW_ONLY'
|
||||
}
|
||||
|
||||
export enum ContentRating {
|
||||
EVERYONE = 'EVERYONE',
|
||||
TEEN = 'TEEN',
|
||||
MATURE = 'MATURE',
|
||||
ADULT = 'ADULT',
|
||||
EXPLICIT = 'EXPLICIT'
|
||||
}
|
||||
|
||||
export interface ContentRestriction {
|
||||
id?: number;
|
||||
userId: number;
|
||||
restrictionType: ContentRestrictionType;
|
||||
mode: ContentRestrictionMode;
|
||||
value: string;
|
||||
createdAt?: string;
|
||||
}
|
||||
|
||||
export const CONTENT_RATINGS = Object.values(ContentRating);
|
||||
|
||||
export const AGE_RATING_OPTIONS = [
|
||||
{ value: '0', label: 'All Ages' },
|
||||
{ value: '6', label: '6+' },
|
||||
{ value: '10', label: '10+' },
|
||||
{ value: '13', label: '13+' },
|
||||
{ value: '16', label: '16+' },
|
||||
{ value: '18', label: '18+' },
|
||||
{ value: '21', label: '21+' }
|
||||
];
|
||||
@@ -0,0 +1,33 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {ContentRestriction} from './content-restriction.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ContentRestrictionService {
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/users`;
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getUserRestrictions(userId: number): Observable<ContentRestriction[]> {
|
||||
return this.http.get<ContentRestriction[]>(`${this.baseUrl}/${userId}/content-restrictions`);
|
||||
}
|
||||
|
||||
addRestriction(userId: number, restriction: ContentRestriction): Observable<ContentRestriction> {
|
||||
return this.http.post<ContentRestriction>(`${this.baseUrl}/${userId}/content-restrictions`, restriction);
|
||||
}
|
||||
|
||||
updateRestrictions(userId: number, restrictions: ContentRestriction[]): Observable<ContentRestriction[]> {
|
||||
return this.http.put<ContentRestriction[]>(`${this.baseUrl}/${userId}/content-restrictions`, restrictions);
|
||||
}
|
||||
|
||||
deleteRestriction(userId: number, restrictionId: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.baseUrl}/${userId}/content-restrictions/${restrictionId}`);
|
||||
}
|
||||
|
||||
deleteAllRestrictions(userId: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.baseUrl}/${userId}/content-restrictions`);
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsUsers.contentRestrictions'">
|
||||
<div class="content-restrictions-editor">
|
||||
@if (isEditing) {
|
||||
<div class="add-restriction-form">
|
||||
<div class="form-row">
|
||||
<div class="form-field">
|
||||
<label>{{ t('type') }}</label>
|
||||
<p-select
|
||||
[options]="restrictionTypes"
|
||||
[(ngModel)]="newRestriction.restrictionType"
|
||||
optionValue="value"
|
||||
[placeholder]="t('selectType')"
|
||||
appendTo="body">
|
||||
<ng-template let-item pTemplate="item">
|
||||
{{ item.translationKey | transloco }}
|
||||
</ng-template>
|
||||
<ng-template let-item pTemplate="selectedItem">
|
||||
{{ item.translationKey | transloco }}
|
||||
</ng-template>
|
||||
</p-select>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label>{{ t('mode') }}</label>
|
||||
<p-select
|
||||
[options]="restrictionModes"
|
||||
[(ngModel)]="newRestriction.mode"
|
||||
optionValue="value"
|
||||
[placeholder]="t('selectMode')"
|
||||
appendTo="body">
|
||||
<ng-template let-item pTemplate="item">
|
||||
{{ item.translationKey | transloco }}
|
||||
</ng-template>
|
||||
<ng-template let-item pTemplate="selectedItem">
|
||||
{{ item.translationKey | transloco }}
|
||||
</ng-template>
|
||||
</p-select>
|
||||
</div>
|
||||
<div class="form-field form-field-wide">
|
||||
<label>{{ t('value') }}</label>
|
||||
<p-select
|
||||
[options]="getValueOptions()"
|
||||
[(ngModel)]="newRestriction.value"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
[placeholder]="t('selectValue')"
|
||||
[filter]="true"
|
||||
[filterPlaceholder]="t('searchFilter')"
|
||||
appendTo="body">
|
||||
</p-select>
|
||||
</div>
|
||||
<div class="form-field form-field-button">
|
||||
<p-button
|
||||
icon="pi pi-plus"
|
||||
severity="success"
|
||||
[outlined]="true"
|
||||
(onClick)="addRestriction()"
|
||||
[pTooltip]="t('addTooltip')">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (restrictions.length === 0) {
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
<p>{{ t('emptyTitle') }}</p>
|
||||
<span class="empty-hint">{{ t('emptyHint') }}</span>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="restrictions-list">
|
||||
@if (getExcludeRestrictions().length > 0) {
|
||||
<div class="restrictions-group">
|
||||
<h5 class="group-title">
|
||||
<i class="pi pi-ban"></i>
|
||||
{{ t('excludeTitle') }}
|
||||
</h5>
|
||||
<p class="group-description">{{ t('excludeDesc') }}</p>
|
||||
<div class="restrictions-chips">
|
||||
@for (restriction of getExcludeRestrictions(); track restriction.id) {
|
||||
<div class="restriction-chip mode-exclude">
|
||||
<span class="chip-type">{{ getRestrictionTypeLabel(restriction.restrictionType) }}</span>
|
||||
<span class="chip-value">{{ restriction.value }}</span>
|
||||
@if (isEditing) {
|
||||
<button class="chip-remove" (click)="removeRestriction(restriction)">
|
||||
<i class="pi pi-times"></i>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (getAllowOnlyRestrictions().length > 0) {
|
||||
<div class="restrictions-group">
|
||||
<h5 class="group-title">
|
||||
<i class="pi pi-check"></i>
|
||||
{{ t('allowOnlyTitle') }}
|
||||
</h5>
|
||||
<p class="group-description">{{ t('allowOnlyDesc') }}</p>
|
||||
<div class="restrictions-chips">
|
||||
@for (restriction of getAllowOnlyRestrictions(); track restriction.id) {
|
||||
<div class="restriction-chip mode-allow">
|
||||
<span class="chip-type">{{ getRestrictionTypeLabel(restriction.restrictionType) }}</span>
|
||||
<span class="chip-value">{{ restriction.value }}</span>
|
||||
@if (isEditing) {
|
||||
<button class="chip-remove" (click)="removeRestriction(restriction)">
|
||||
<i class="pi pi-times"></i>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="restrictions-info">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<span>{{ t('infoNote') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user