Improve Angular project structure and code organization (#1328)
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<div class="layout-wrapper" [ngClass]="containerClass">
|
||||
<app-topbar></app-topbar>
|
||||
<div class="layout-sidebar layout-sidebar-custom">
|
||||
<app-sidebar></app-sidebar>
|
||||
</div>
|
||||
<div class="layout-main-container">
|
||||
<div class="layout-main">
|
||||
<router-outlet></router-outlet>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layout-mask"></div>
|
||||
</div>
|
||||
@@ -0,0 +1,119 @@
|
||||
import {Component, OnDestroy, Renderer2, ViewChild} from '@angular/core';
|
||||
import {NavigationEnd, Router, RouterOutlet} from '@angular/router';
|
||||
import {filter, Subscription} from 'rxjs';
|
||||
import {LayoutService} from "./service/app.layout.service";
|
||||
import {AppSidebarComponent} from "../layout-sidebar/app.sidebar.component";
|
||||
import {AppTopBarComponent} from '../layout-topbar/app.topbar.component';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
|
||||
@Component({
|
||||
selector: 'app-layout',
|
||||
imports: [
|
||||
RouterOutlet,
|
||||
AppSidebarComponent,
|
||||
AppTopBarComponent,
|
||||
NgClass,
|
||||
ToastModule
|
||||
],
|
||||
templateUrl: './app.layout.component.html'
|
||||
})
|
||||
export class AppLayoutComponent implements OnDestroy {
|
||||
|
||||
overlayMenuOpenSubscription: Subscription;
|
||||
|
||||
menuOutsideClickListener: any;
|
||||
|
||||
profileMenuOutsideClickListener: any;
|
||||
|
||||
@ViewChild(AppSidebarComponent) appSidebar!: AppSidebarComponent;
|
||||
|
||||
@ViewChild(AppTopBarComponent) appTopbar!: AppTopBarComponent;
|
||||
|
||||
constructor(public layoutService: LayoutService, public renderer: Renderer2, public router: Router) {
|
||||
this.overlayMenuOpenSubscription = this.layoutService.overlayOpen$.subscribe(() => {
|
||||
if (!this.menuOutsideClickListener) {
|
||||
this.menuOutsideClickListener = this.renderer.listen('document', 'click', (event) => {
|
||||
if (this.isOutsideClicked(event)) {
|
||||
this.hideMenu();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.layoutService.state.staticMenuMobileActive) {
|
||||
this.blockBodyScroll();
|
||||
}
|
||||
});
|
||||
|
||||
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(() => {
|
||||
this.hideMenu();
|
||||
this.hideProfileMenu();
|
||||
});
|
||||
}
|
||||
|
||||
isOutsideClicked(event: MouseEvent): boolean {
|
||||
const sidebarEl = document.querySelector('.layout-sidebar');
|
||||
const topbarEl = document.querySelector('.layout-menu-button');
|
||||
const eventTarget = event.target as Node;
|
||||
const clickedInsideSidebar = sidebarEl?.isSameNode(eventTarget) || sidebarEl?.contains(eventTarget);
|
||||
const clickedInsideTopbar = topbarEl?.isSameNode(eventTarget) || topbarEl?.contains(eventTarget);
|
||||
return !(clickedInsideSidebar || clickedInsideTopbar);
|
||||
}
|
||||
|
||||
hideMenu() {
|
||||
this.layoutService.state.overlayMenuActive = false;
|
||||
this.layoutService.state.staticMenuMobileActive = false;
|
||||
this.layoutService.state.menuHoverActive = false;
|
||||
if (this.menuOutsideClickListener) {
|
||||
this.menuOutsideClickListener();
|
||||
this.menuOutsideClickListener = null;
|
||||
}
|
||||
this.unblockBodyScroll();
|
||||
}
|
||||
|
||||
hideProfileMenu() {
|
||||
this.layoutService.state.profileSidebarVisible = false;
|
||||
if (this.profileMenuOutsideClickListener) {
|
||||
this.profileMenuOutsideClickListener();
|
||||
this.profileMenuOutsideClickListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
blockBodyScroll(): void {
|
||||
if (document.body.classList) {
|
||||
document.body.classList.add('blocked-scroll');
|
||||
} else {
|
||||
document.body.className += ' blocked-scroll';
|
||||
}
|
||||
}
|
||||
|
||||
unblockBodyScroll(): void {
|
||||
if (document.body.classList) {
|
||||
document.body.classList.remove('blocked-scroll');
|
||||
} else {
|
||||
document.body.className = document.body.className.replace(new RegExp('(^|\\b)' +
|
||||
'blocked-scroll'.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
|
||||
}
|
||||
}
|
||||
|
||||
get containerClass() {
|
||||
return {
|
||||
'layout-overlay': this.layoutService.config().menuMode === 'overlay',
|
||||
'layout-static': this.layoutService.config().menuMode === 'static',
|
||||
'layout-static-inactive': this.layoutService.state.staticMenuDesktopInactive && this.layoutService.config().menuMode === 'static',
|
||||
'layout-overlay-active': this.layoutService.state.overlayMenuActive,
|
||||
'layout-mobile-active': this.layoutService.state.staticMenuMobileActive
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.overlayMenuOpenSubscription) {
|
||||
this.overlayMenuOpenSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
if (this.menuOutsideClickListener) {
|
||||
this.menuOutsideClickListener();
|
||||
}
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
import {Injectable, effect, signal} from '@angular/core';
|
||||
import {Subject} from 'rxjs';
|
||||
|
||||
export interface AppConfig {
|
||||
inputStyle: string;
|
||||
colorScheme: string;
|
||||
theme: string;
|
||||
ripple: boolean;
|
||||
menuMode: string;
|
||||
scale: number;
|
||||
}
|
||||
|
||||
interface LayoutState {
|
||||
staticMenuDesktopInactive: boolean;
|
||||
overlayMenuActive: boolean;
|
||||
profileSidebarVisible: boolean;
|
||||
configSidebarVisible: boolean;
|
||||
staticMenuMobileActive: boolean;
|
||||
menuHoverActive: boolean;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class LayoutService {
|
||||
_config: AppConfig = {
|
||||
ripple: false,
|
||||
inputStyle: 'outlined',
|
||||
menuMode: 'static',
|
||||
colorScheme: 'light',
|
||||
theme: 'lara-light-indigo',
|
||||
scale: 14,
|
||||
};
|
||||
|
||||
config = signal<AppConfig>(this._config);
|
||||
|
||||
state: LayoutState = {
|
||||
staticMenuDesktopInactive: false,
|
||||
overlayMenuActive: false,
|
||||
profileSidebarVisible: false,
|
||||
configSidebarVisible: false,
|
||||
staticMenuMobileActive: false,
|
||||
menuHoverActive: false,
|
||||
};
|
||||
|
||||
private configUpdate = new Subject<AppConfig>();
|
||||
private overlayOpen = new Subject<any>();
|
||||
overlayOpen$ = this.overlayOpen.asObservable();
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const config = this.config();
|
||||
if (this.updateStyle(config)) {
|
||||
this.changeTheme();
|
||||
}
|
||||
this.changeScale(config.scale);
|
||||
this.onConfigUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
updateStyle(config: AppConfig) {
|
||||
return (
|
||||
config.theme !== this._config.theme ||
|
||||
config.colorScheme !== this._config.colorScheme
|
||||
);
|
||||
}
|
||||
|
||||
onMenuToggle() {
|
||||
if (this.isOverlay()) {
|
||||
this.state.overlayMenuActive = !this.state.overlayMenuActive;
|
||||
if (this.state.overlayMenuActive) {
|
||||
this.overlayOpen.next(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isDesktop()) {
|
||||
this.state.staticMenuDesktopInactive = !this.state.staticMenuDesktopInactive;
|
||||
} else {
|
||||
this.state.staticMenuMobileActive = !this.state.staticMenuMobileActive;
|
||||
if (this.state.staticMenuMobileActive) {
|
||||
this.overlayOpen.next(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isOverlay() {
|
||||
return this.config().menuMode === 'overlay';
|
||||
}
|
||||
|
||||
isDesktop() {
|
||||
return window.innerWidth > 991;
|
||||
}
|
||||
|
||||
onConfigUpdate() {
|
||||
this._config = {...this.config()};
|
||||
this.configUpdate.next(this.config());
|
||||
}
|
||||
|
||||
changeTheme() {
|
||||
const config = this.config();
|
||||
const themeLink = document.getElementById('theme-css') as HTMLLinkElement;
|
||||
const themeLinkHref = themeLink.getAttribute('href')!;
|
||||
const newHref = themeLinkHref
|
||||
.split('/')
|
||||
.map((el) =>
|
||||
el == this._config.theme
|
||||
? (el = config.theme)
|
||||
: el == `theme-${this._config.colorScheme}`
|
||||
? (el = `theme-${config.colorScheme}`)
|
||||
: el
|
||||
)
|
||||
.join('/');
|
||||
|
||||
this.replaceThemeLink(newHref);
|
||||
}
|
||||
|
||||
replaceThemeLink(href: string) {
|
||||
const id = 'theme-css';
|
||||
const themeLink = document.getElementById(id) as HTMLLinkElement;
|
||||
const cloneLinkElement = themeLink.cloneNode(true) as HTMLLinkElement;
|
||||
|
||||
cloneLinkElement.setAttribute('href', href);
|
||||
cloneLinkElement.setAttribute('id', id + '-clone');
|
||||
|
||||
themeLink.parentNode!.insertBefore(
|
||||
cloneLinkElement,
|
||||
themeLink.nextSibling
|
||||
);
|
||||
cloneLinkElement.addEventListener('load', () => {
|
||||
themeLink.remove();
|
||||
cloneLinkElement.setAttribute('id', id);
|
||||
});
|
||||
}
|
||||
|
||||
changeScale(value: number) {
|
||||
document.documentElement.style.fontSize = `${value}px`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<div class="flex flex-col h-full">
|
||||
<div>
|
||||
<ul class="layout-menu">
|
||||
@if (homeMenu$ | async; as homeMenu) {
|
||||
@for (item of homeMenu; track item; let i = $index) {
|
||||
@if (!item.separator) {
|
||||
<li app-menuitem [item]="item" [index]="i" [root]="true"></li>
|
||||
}
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
|
||||
<ul class="layout-menu">
|
||||
@if (libraryMenu$ | async; as libraryMenu) {
|
||||
@for (item of libraryMenu; track item; let i = $index) {
|
||||
@if (!item.separator) {
|
||||
<li app-menuitem [item]="item" [index]="i" [root]="true"></li>
|
||||
}
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
|
||||
<ul class="layout-menu">
|
||||
@if (shelfMenu$ | async; as shelfMenu) {
|
||||
@for (item of shelfMenu; track item; let i = $index) {
|
||||
@if (!item.separator) {
|
||||
<li app-menuitem [item]="item" [index]="i" [root]="true"></li>
|
||||
}
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
|
||||
<ul class="layout-menu">
|
||||
@if (magicShelfMenu$ | async; as shelfMenu) {
|
||||
@for (item of shelfMenu; track item; let i = $index) {
|
||||
@if (!item.separator) {
|
||||
<li app-menuitem [item]="item" [index]="i" [root]="true"></li>
|
||||
}
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@if (versionInfo) {
|
||||
<div style="margin-top: auto;" class="p-4 text-center w-full text-sm">
|
||||
<div class="text-gray-200">
|
||||
<a
|
||||
[href]="getVersionUrl(versionInfo.current)"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="hover:underline hover:text-gray-100 text-sm"
|
||||
>
|
||||
{{ versionInfo.current }}
|
||||
</a>
|
||||
</div>
|
||||
@if (versionInfo.latest && versionInfo.latest !== versionInfo.current) {
|
||||
<div>
|
||||
<a
|
||||
(click)="openChangelogDialog()"
|
||||
class="cursor-pointer text-orange-400 hover:underline hover:text-orange-300 text-xs"
|
||||
>
|
||||
(Update)
|
||||
</a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,236 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {AppMenuitemComponent} from './app.menuitem.component';
|
||||
import {AsyncPipe} from '@angular/common';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
import {LibraryService} from '../../../../features/book/service/library.service';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {filter, map} from 'rxjs/operators';
|
||||
import {ShelfService} from '../../../../features/book/service/shelf.service';
|
||||
import {BookService} from '../../../../features/book/service/book.service';
|
||||
import {LibraryShelfMenuService} from '../../../../features/book/service/library-shelf-menu.service';
|
||||
import {AppVersion, VersionService} from '../../../service/version.service';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {VersionChangelogDialogComponent} from './version-changelog-dialog/version-changelog-dialog.component';
|
||||
import {UserService} from '../../../../features/settings/user-management/user.service';
|
||||
import {MagicShelfService, MagicShelfState} from '../../../../features/magic-shelf/service/magic-shelf.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-menu',
|
||||
standalone: true,
|
||||
imports: [AppMenuitemComponent, MenuModule, AsyncPipe],
|
||||
templateUrl: './app.menu.component.html',
|
||||
})
|
||||
export class AppMenuComponent implements OnInit {
|
||||
libraryMenu$: Observable<any> | undefined;
|
||||
shelfMenu$: Observable<any> | undefined;
|
||||
homeMenu$: Observable<any> | undefined;
|
||||
magicShelfMenu$: Observable<any> | undefined;
|
||||
|
||||
versionInfo: AppVersion | null = null;
|
||||
dynamicDialogRef: DynamicDialogRef | undefined;
|
||||
|
||||
private libraryService = inject(LibraryService);
|
||||
private shelfService = inject(ShelfService);
|
||||
private bookService = inject(BookService);
|
||||
private versionService = inject(VersionService);
|
||||
private libraryShelfMenuService = inject(LibraryShelfMenuService);
|
||||
private dialogService = inject(DialogService);
|
||||
private userService = inject(UserService);
|
||||
private magicShelfService = inject(MagicShelfService);
|
||||
|
||||
librarySortField: 'name' | 'id' = 'name';
|
||||
librarySortOrder: 'asc' | 'desc' = 'desc';
|
||||
shelfSortField: 'name' | 'id' = 'name';
|
||||
shelfSortOrder: 'asc' | 'desc' = 'asc';
|
||||
|
||||
|
||||
ngOnInit(): void {
|
||||
this.versionService.getVersion().subscribe((data) => {
|
||||
this.versionInfo = data;
|
||||
});
|
||||
|
||||
this.userService.userState$.pipe(
|
||||
filter(userState => !!userState?.user && userState.loaded))
|
||||
.subscribe(userState => {
|
||||
if (userState.user?.userSettings.sidebarLibrarySorting) {
|
||||
this.librarySortField = this.validateSortField(userState.user.userSettings.sidebarLibrarySorting.field);
|
||||
this.librarySortOrder = this.validateSortOrder(userState.user.userSettings.sidebarLibrarySorting.order);
|
||||
}
|
||||
if (userState.user?.userSettings.sidebarShelfSorting) {
|
||||
this.shelfSortField = this.validateSortField(userState.user.userSettings.sidebarShelfSorting.field);
|
||||
this.shelfSortOrder = this.validateSortOrder(userState.user.userSettings.sidebarShelfSorting.order);
|
||||
}
|
||||
this.initMenus();
|
||||
});
|
||||
|
||||
this.homeMenu$ = this.bookService.bookState$.pipe(
|
||||
map((bookState) => [
|
||||
{
|
||||
label: 'Home',
|
||||
items: [
|
||||
{
|
||||
label: 'Dashboard',
|
||||
icon: 'pi pi-fw pi-home',
|
||||
routerLink: ['/dashboard'],
|
||||
},
|
||||
{
|
||||
label: 'All Books',
|
||||
type: 'All Books',
|
||||
icon: 'pi pi-fw pi-book',
|
||||
routerLink: ['/all-books'],
|
||||
bookCount$: of(bookState.books ? bookState.books.length : 0),
|
||||
}
|
||||
],
|
||||
},
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
private initMenus(): void {
|
||||
this.libraryMenu$ = this.libraryService.libraryState$.pipe(
|
||||
map((state) => {
|
||||
const libraries = state.libraries ?? [];
|
||||
const sortedLibraries = this.sortArray(libraries, this.librarySortField, this.librarySortOrder);
|
||||
return [
|
||||
{
|
||||
label: 'Libraries',
|
||||
type: 'library',
|
||||
hasDropDown: true,
|
||||
hasCreate: true,
|
||||
items: sortedLibraries.map((library) => ({
|
||||
menu: this.libraryShelfMenuService.initializeLibraryMenuItems(library),
|
||||
label: library.name,
|
||||
type: 'Library',
|
||||
icon: 'pi pi-' + library.icon,
|
||||
routerLink: [`/library/${library.id}/books`],
|
||||
bookCount$: this.libraryService.getBookCount(library.id ?? 0),
|
||||
})),
|
||||
},
|
||||
];
|
||||
})
|
||||
);
|
||||
|
||||
this.magicShelfMenu$ = this.magicShelfService.shelvesState$.pipe(
|
||||
map((state: MagicShelfState) => {
|
||||
const shelves = state.shelves ?? [];
|
||||
const sortedShelves = this.sortArray(shelves, 'name', 'asc');
|
||||
return [
|
||||
{
|
||||
label: 'Magic Shelves',
|
||||
type: 'magicShelf',
|
||||
hasDropDown: true,
|
||||
hasCreate: true,
|
||||
items: sortedShelves.map((shelf) => ({
|
||||
label: shelf.name,
|
||||
type: 'magicShelfItem',
|
||||
icon: 'pi pi-' + shelf.icon,
|
||||
menu: this.libraryShelfMenuService.initializeMagicShelfMenuItems(shelf),
|
||||
routerLink: [`/magic-shelf/${shelf.id}/books`],
|
||||
bookCount$: this.magicShelfService.getBookCount(shelf.id ?? 0),
|
||||
})),
|
||||
},
|
||||
];
|
||||
})
|
||||
);
|
||||
|
||||
this.shelfMenu$ = this.shelfService.shelfState$.pipe(
|
||||
map((state) => {
|
||||
const shelves = state.shelves ?? [];
|
||||
const sortedShelves = this.sortArray(shelves, this.shelfSortField, this.shelfSortOrder);
|
||||
|
||||
const koboShelfIndex = sortedShelves.findIndex(shelf => shelf.name === 'Kobo');
|
||||
let koboShelf = null;
|
||||
if (koboShelfIndex !== -1) {
|
||||
koboShelf = sortedShelves.splice(koboShelfIndex, 1)[0];
|
||||
}
|
||||
|
||||
const shelfItems = sortedShelves.map((shelf) => ({
|
||||
menu: this.libraryShelfMenuService.initializeShelfMenuItems(shelf),
|
||||
label: shelf.name,
|
||||
type: 'Shelf',
|
||||
icon: 'pi pi-' + shelf.icon,
|
||||
routerLink: [`/shelf/${shelf.id}/books`],
|
||||
bookCount$: this.shelfService.getBookCount(shelf.id ?? 0),
|
||||
}));
|
||||
|
||||
const unshelvedItem = {
|
||||
label: 'Unshelved',
|
||||
type: 'Shelf',
|
||||
icon: 'pi pi-inbox',
|
||||
routerLink: ['/unshelved-books'],
|
||||
bookCount$: this.shelfService.getUnshelvedBookCount?.() ?? of(0),
|
||||
};
|
||||
|
||||
const items = [unshelvedItem];
|
||||
if (koboShelf) {
|
||||
items.push({
|
||||
label: koboShelf.name,
|
||||
type: 'Shelf',
|
||||
icon: 'pi pi-' + koboShelf.icon,
|
||||
routerLink: [`/shelf/${koboShelf.id}/books`],
|
||||
bookCount$: this.shelfService.getBookCount(koboShelf.id ?? 0),
|
||||
});
|
||||
}
|
||||
items.push(...shelfItems);
|
||||
|
||||
return [
|
||||
{
|
||||
type: 'shelf',
|
||||
label: 'Shelves',
|
||||
hasDropDown: true,
|
||||
hasCreate: false,
|
||||
items,
|
||||
},
|
||||
];
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
openChangelogDialog() {
|
||||
const isMobile = window.innerWidth <= 768;
|
||||
this.dynamicDialogRef = this.dialogService.open(VersionChangelogDialogComponent, {
|
||||
header: 'What’s New',
|
||||
modal: true,
|
||||
closable: true,
|
||||
style: {
|
||||
position: 'absolute',
|
||||
top: '10%',
|
||||
bottom: '10%',
|
||||
width: isMobile ? '90vw' : '800px',
|
||||
maxWidth: isMobile ? '90vw' : '800px',
|
||||
minWidth: isMobile ? '90vw' : '800px',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
getVersionUrl(version: string | undefined): string {
|
||||
if (!version) return '#';
|
||||
return version.startsWith('v')
|
||||
? `https://github.com/adityachandelgit/BookLore/releases/tag/${version}`
|
||||
: `https://github.com/adityachandelgit/BookLore/commit/${version}`;
|
||||
}
|
||||
|
||||
private sortArray<T>(array: T[], field: 'name' | 'id', order: 'asc' | 'desc'): T[] {
|
||||
return [...array].sort((a, b) => {
|
||||
const aVal = (a as any)[field] ?? '';
|
||||
const bVal = (b as any)[field] ?? '';
|
||||
let comparison = 0;
|
||||
|
||||
if (typeof aVal === 'string' && typeof bVal === 'string') {
|
||||
comparison = aVal.localeCompare(bVal);
|
||||
} else if (typeof aVal === 'number' && typeof bVal === 'number') {
|
||||
comparison = aVal - bVal;
|
||||
}
|
||||
|
||||
return order === 'asc' ? comparison : -comparison;
|
||||
});
|
||||
}
|
||||
|
||||
private validateSortField(field: string): 'name' | 'id' {
|
||||
return field === 'id' ? 'id' : 'name';
|
||||
}
|
||||
|
||||
private validateSortOrder(order: string): 'asc' | 'desc' {
|
||||
return order === 'desc' ? 'desc' : 'asc';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<ng-container>
|
||||
@if (root) {
|
||||
@if (item.hasDropDown) {
|
||||
<div class=" flex items-center justify-between layout-menuitem-root-text cursor-pointer pt-4">
|
||||
<div class="flex items-center justify-between gap-2 cursor-pointer">
|
||||
<div>{{ item.label }}</div>
|
||||
@if (item.hasCreate) {
|
||||
<i
|
||||
class="pi pi-plus text-surface-500 hover:text-surface-200"
|
||||
style="font-size: 0.8rem"
|
||||
(click)="openDialog(item)"
|
||||
></i>
|
||||
}
|
||||
</div>
|
||||
<i
|
||||
(click)="toggleExpand(key)"
|
||||
[ngClass]="{
|
||||
'pi': true,
|
||||
'pi-angle-up': isExpanded(key),
|
||||
'pi-angle-down': !isExpanded(key),
|
||||
'text-surface-500': true,
|
||||
'hover:text-surface-200': true,
|
||||
'pr-3': true
|
||||
}"></i>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="flex items-center justify-between layout-menuitem-root-text">
|
||||
<div>{{ item.label }}</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<div>
|
||||
<div
|
||||
class="flex flex-row items-center justify-between hover:bg-surface-800 rounded-md cursor-pointer"
|
||||
(click)="triggerLink()"
|
||||
>
|
||||
@if ((item.routerLink && !item.items)) {
|
||||
<a
|
||||
#link
|
||||
(click)="itemClick($event)"
|
||||
[ngClass]="item.class + ' flex items-center gap-2 w-full'"
|
||||
[routerLink]="item.routerLink"
|
||||
routerLinkActive="active-route"
|
||||
[routerLinkActiveOptions]="item.routerLinkActiveOptions || { paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' }"
|
||||
[fragment]="item.fragment"
|
||||
[queryParamsHandling]="item.queryParamsHandling"
|
||||
[preserveFragment]="item.preserveFragment"
|
||||
[skipLocationChange]="item.skipLocationChange"
|
||||
[replaceUrl]="item.replaceUrl"
|
||||
[state]="item.state"
|
||||
[queryParams]="item.queryParams"
|
||||
[attr.target]="item.target"
|
||||
tabindex="0"
|
||||
pRipple
|
||||
>
|
||||
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
||||
<span class="layout-menuitem-text w-full truncate">
|
||||
{{ item.label }}
|
||||
</span>
|
||||
</a>
|
||||
}
|
||||
|
||||
<span>
|
||||
@if (item.type === 'Library' || item.type === 'Shelf' || item.type === 'magicShelfItem') {
|
||||
@if ((item.type !== 'Library' || (admin || canManipulateLibrary)) && item.label !== 'Unshelved' && item.label !== 'Kobo') {
|
||||
<p-button
|
||||
(click)="entitymenu.toggle($event); $event.stopPropagation()"
|
||||
(mouseover)="hovered = true"
|
||||
(mouseleave)="hovered = false"
|
||||
[text]="true"
|
||||
[outlined]="false"
|
||||
[rounded]="true"
|
||||
[label]="hovered ? '' : (item.bookCount$ | async)?.toString() || ''"
|
||||
[icon]="hovered ? 'pi pi-ellipsis-v' : ''"
|
||||
[style.height]="'30px'"
|
||||
[style.display]="'flex'"
|
||||
></p-button>
|
||||
}
|
||||
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
|
||||
}
|
||||
|
||||
@if (item.type === 'Library' && (!admin && !canManipulateLibrary) || item.type === 'All Books' || item.label === 'Unshelved' || item.label === 'Kobo') {
|
||||
<p class="text-[var(--primary-color)] pr-3">
|
||||
{{ (item.bookCount$ | async)?.toString() || '0' }}
|
||||
</p>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div [@children]="isExpanded(key) ? 'expanded' : 'collapsed'" style="overflow: hidden;">
|
||||
@if (item.items) {
|
||||
<ul>
|
||||
@for (child of item.items; track child; let i = $index) {
|
||||
<li app-menuitem [item]="child" [index]="i" [parentKey]="key" [class]="child.badgeClass"></li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -0,0 +1,166 @@
|
||||
import {Component, ElementRef, HostBinding, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
||||
import {NavigationEnd, Router, RouterLink, RouterLinkActive} from '@angular/router';
|
||||
import {animate, state, style, transition, trigger} from '@angular/animations';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {filter} from 'rxjs/operators';
|
||||
import {MenuService} from './service/app.menu.service';
|
||||
import {AsyncPipe, NgClass} from '@angular/common';
|
||||
import {Ripple} from 'primeng/ripple';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Menu} from 'primeng/menu';
|
||||
import {UserService} from '../../../../features/settings/user-management/user.service';
|
||||
import {DialogLauncherService} from '../../../../core/service/dialog-launcher.service';
|
||||
|
||||
@Component({
|
||||
selector: '[app-menuitem]',
|
||||
templateUrl: './app.menuitem.component.html',
|
||||
styleUrls: ['./app.menuitem.component.scss'],
|
||||
imports: [
|
||||
RouterLink,
|
||||
RouterLinkActive,
|
||||
NgClass,
|
||||
Ripple,
|
||||
AsyncPipe,
|
||||
Button,
|
||||
Menu
|
||||
],
|
||||
animations: [
|
||||
trigger('children', [
|
||||
state('collapsed', style({
|
||||
height: '0'
|
||||
})),
|
||||
state('expanded', style({
|
||||
height: '*'
|
||||
})),
|
||||
transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
|
||||
])
|
||||
]
|
||||
})
|
||||
export class AppMenuitemComponent implements OnInit, OnDestroy {
|
||||
@Input() item: any;
|
||||
@Input() index!: number;
|
||||
@Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
|
||||
@Input() parentKey!: string;
|
||||
@ViewChild('linkRef') linkRef!: ElementRef<HTMLAnchorElement>;
|
||||
|
||||
hovered = false;
|
||||
active = false;
|
||||
key: string = "";
|
||||
canManipulateLibrary: boolean = false;
|
||||
admin: boolean = false;
|
||||
expandedItems = new Set<string>();
|
||||
menuSourceSubscription: Subscription;
|
||||
menuResetSubscription: Subscription;
|
||||
|
||||
constructor(
|
||||
public router: Router,
|
||||
private menuService: MenuService,
|
||||
private userService: UserService,
|
||||
private dialogLauncher: DialogLauncherService
|
||||
) {
|
||||
this.userService.userState$.subscribe(userState => {
|
||||
if (userState?.user) {
|
||||
this.canManipulateLibrary = userState.user.permissions.canManipulateLibrary;
|
||||
this.admin = userState.user.permissions.admin;
|
||||
}
|
||||
});
|
||||
|
||||
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
|
||||
Promise.resolve(null).then(() => {
|
||||
if (value.routeEvent) {
|
||||
this.active = (value.key === this.key || value.key.startsWith(this.key + '-')) ? true : false;
|
||||
} else {
|
||||
if (value.key !== this.key && !value.key.startsWith(this.key + '-')) {
|
||||
this.active = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.menuResetSubscription = this.menuService.resetSource$.subscribe(() => {
|
||||
this.active = false;
|
||||
});
|
||||
|
||||
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(() => {
|
||||
if (this.item.routerLink) {
|
||||
this.updateActiveStateFromRoute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index);
|
||||
this.expandedItems.add(this.key);
|
||||
if (this.item.routerLink) {
|
||||
this.updateActiveStateFromRoute();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.menuSourceSubscription) {
|
||||
this.menuSourceSubscription.unsubscribe();
|
||||
}
|
||||
if (this.menuResetSubscription) {
|
||||
this.menuResetSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
toggleExpand(key: string) {
|
||||
if (this.expandedItems.has(key)) {
|
||||
this.expandedItems.delete(key);
|
||||
} else {
|
||||
this.expandedItems.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
isExpanded(key: string): boolean {
|
||||
return this.expandedItems.has(key);
|
||||
}
|
||||
|
||||
updateActiveStateFromRoute() {
|
||||
const activeRoute = this.router.isActive(this.item.routerLink[0], {
|
||||
paths: 'exact',
|
||||
queryParams: 'ignored',
|
||||
matrixParams: 'ignored',
|
||||
fragment: 'ignored'
|
||||
});
|
||||
if (activeRoute) {
|
||||
this.menuService.onMenuStateChange({key: this.key, routeEvent: true});
|
||||
}
|
||||
}
|
||||
|
||||
itemClick(event: Event) {
|
||||
if (this.item.disabled) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (this.item.command) {
|
||||
this.item.command({originalEvent: event, item: this.item});
|
||||
}
|
||||
if (this.item.items) {
|
||||
this.active = !this.active;
|
||||
}
|
||||
this.menuService.onMenuStateChange({key: this.key});
|
||||
}
|
||||
|
||||
openDialog(item: any) {
|
||||
if (item.type === 'library' && this.canManipulateLibrary) {
|
||||
this.dialogLauncher.openLibraryCreatorDialog();
|
||||
}
|
||||
if (item.type === 'magicShelf') {
|
||||
this.dialogLauncher.openMagicShelfDialog();
|
||||
}
|
||||
}
|
||||
|
||||
triggerLink() {
|
||||
if (this.item.routerLink && !this.item.items && this.linkRef) {
|
||||
this.linkRef.nativeElement.click();
|
||||
}
|
||||
}
|
||||
|
||||
@HostBinding('class.active-menuitem')
|
||||
get activeClass() {
|
||||
return this.active && !this.root;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { MenuChangeEvent } from '../../../api/menuchangeevent';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MenuService {
|
||||
|
||||
private menuSource = new Subject<MenuChangeEvent>();
|
||||
private resetSource = new Subject();
|
||||
|
||||
menuSource$ = this.menuSource.asObservable();
|
||||
resetSource$ = this.resetSource.asObservable();
|
||||
|
||||
onMenuStateChange(event: MenuChangeEvent) {
|
||||
this.menuSource.next(event);
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.resetSource.next(true);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
@if (loading) {
|
||||
<div class="p-4 text-center text-gray-400">
|
||||
Loading changelog...
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!loading && changelog.length === 0) {
|
||||
<div class="p-4 text-center text-gray-400">
|
||||
No updates available.
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!loading && changelog.length > 0) {
|
||||
<div class="space-y-6 p-4 max-h-[70vh] overflow-auto">
|
||||
@for (release of changelog; track release) {
|
||||
<div class="border-b pb-4">
|
||||
<p class="font-bold text-2xl pb-2">
|
||||
<a [href]="release.url" target="_blank" rel="noopener noreferrer" class="text-blue-400 hover:underline">
|
||||
{{ release.name }} ({{ release.publishedAt | date: 'mediumDate' }})
|
||||
</a>
|
||||
</p>
|
||||
<div [innerHTML]="markdownToHtml(release.changelog)" class="prose prose-invert w-full max-w-full"></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
:host ::ng-deep .prose h3 {
|
||||
margin-top: 0px;
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import { ReleaseNote, VersionService } from '../../../../service/version.service';
|
||||
|
||||
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
||||
import showdown from 'showdown';
|
||||
import {DatePipe} from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-version-changelog-dialog',
|
||||
standalone: true,
|
||||
imports: [
|
||||
DatePipe
|
||||
],
|
||||
templateUrl: './version-changelog-dialog.component.html',
|
||||
styleUrl: './version-changelog-dialog.component.scss'
|
||||
})
|
||||
export class VersionChangelogDialogComponent implements OnInit {
|
||||
|
||||
private versionService = inject(VersionService);
|
||||
private sanitizer = inject(DomSanitizer);
|
||||
|
||||
changelog: ReleaseNote[] = [];
|
||||
loading = true;
|
||||
|
||||
private converter = new showdown.Converter({ tables: true, emoji: true });
|
||||
|
||||
ngOnInit(): void {
|
||||
this.versionService.getChangelog().subscribe({
|
||||
next: (data) => {
|
||||
this.changelog = data;
|
||||
this.loading = false;
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
markdownToHtml(markdown: string): SafeHtml {
|
||||
let html = this.converter.makeHtml(markdown);
|
||||
html = html.replace(/<h2\b([^>]*)>/g, '<h3$1>').replace(/<\/h2>/g, '</h3>');
|
||||
return this.sanitizer.bypassSecurityTrustHtml(html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<app-menu></app-menu>
|
||||
@@ -0,0 +1,3 @@
|
||||
.layout-sidebar-custom {
|
||||
width: 250px !important;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Component, ElementRef } from '@angular/core';
|
||||
import { LayoutService } from "../layout-main/service/app.layout.service";
|
||||
import {AppMenuComponent} from '../layout-menu/app.menu.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-sidebar',
|
||||
imports: [
|
||||
AppMenuComponent
|
||||
],
|
||||
templateUrl: './app.sidebar.component.html'
|
||||
})
|
||||
export class AppSidebarComponent {
|
||||
constructor(public layoutService: LayoutService, public el: ElementRef) { }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
<div class="layout-topbar">
|
||||
|
||||
<a class="layout-topbar-logo pl-5 pr-24 flex gap-2" routerLink="">
|
||||
<svg class="w-[1.875rem] h-[1.875rem] half-title" viewBox="0 0 126 126" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M59 4.79297C71.5051 11.5557 80 24.7854 80 40C80 40.5959 79.987 41.1888 79.9609 41.7783C79.8609 44.0406 81.7355 46 84 46C106.091 46 124 63.9086 124 86C124 108.091 106.091 126 84 126H10C4.47715 126 0 121.523 0 116V39.0068L0.0126953 38.9941C0.357624 25.0252 7.86506 12.8347 19 5.95215V63.832C19 64.8345 20.0676 65.4391 20.9121 64.9902L21.0771 64.8867L38.2227 52.3428C38.6819 52.0068 39.3064 52.0068 39.7656 52.3428L56.9229 64.8945L57.0879 64.998C57.9324 65.447 59 64.8423 59 63.8398V4.79297Z"/>
|
||||
<path
|
||||
d="M40 0C43.8745 0 47.6199 0.552381 51.1631 1.58008V50.9697L44.3926 46.0176L44.0879 45.8037C40.9061 43.6679 36.7098 43.7393 33.5957 46.0176L26.8369 50.9619V2.21875C30.9593 0.782634 35.3881 0 40 0Z"
|
||||
fill="white"/>
|
||||
</svg>
|
||||
<span class="flex items-center pt-2">
|
||||
<p>Book</p>
|
||||
<p class="half-title text-3xl">lore</p>
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<p-button
|
||||
class="layout-menu-button"
|
||||
#menubutton
|
||||
icon="pi pi-bars"
|
||||
[rounded]="true"
|
||||
[outlined]="true"
|
||||
(click)="toggleMenu()"
|
||||
[ngClass]="{ 'rotate-right': !isMenuVisible, 'rotate-left': isMenuVisible }"
|
||||
>
|
||||
</p-button>
|
||||
|
||||
<div class="flex items-center w-full gap-4">
|
||||
<app-book-searcher class="md:block flex-grow"></app-book-searcher>
|
||||
<ul class="topbar-items hidden md:flex items-center gap-3 ml-auto pl-4">
|
||||
<div class="flex gap-4">
|
||||
@if (userService.userState$ | async; as userState) {
|
||||
<li>
|
||||
@if (userState.user?.permissions?.canManipulateLibrary || userState.user?.permissions?.admin) {
|
||||
<a class="topbar-item" (click)="navigateToBookdrop()" pTooltip="Bookdrop" tooltipPosition="bottom">
|
||||
<i class="pi pi-inbox text-surface-100"></i>
|
||||
</a>
|
||||
}
|
||||
</li>
|
||||
<li>
|
||||
@if (userState.user?.permissions?.canManipulateLibrary || userState.user?.permissions?.admin) {
|
||||
<a class="topbar-item" (click)="openLibraryCreatorDialog()" pTooltip="Create New Library" tooltipPosition="bottom">
|
||||
<i class="pi pi-plus-circle text-surface-100"></i>
|
||||
</a>
|
||||
}
|
||||
</li>
|
||||
<li>
|
||||
@if (userState.user?.permissions?.canManipulateLibrary || userState.user?.permissions?.admin) {
|
||||
<a class="topbar-item" (click)="openFileUploadDialog()" pTooltip="Upload Book" tooltipPosition="bottom">
|
||||
<i class="pi pi-upload text-surface-100"></i>
|
||||
</a>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
<li>
|
||||
<a class="topbar-item" (click)="navigateToStats()" pTooltip="Stats" tooltipPosition="bottom">
|
||||
<i class="pi pi-chart-bar text-surface-100"></i>
|
||||
</a>
|
||||
</li>
|
||||
@if (userService.userState$ | async; as userState) {
|
||||
<li>
|
||||
@if (userState.user?.permissions?.canManipulateLibrary || userState.user?.permissions?.admin) {
|
||||
<a class="topbar-item" (click)="navigateToMetadataManager()" pTooltip="Metadata Manager" tooltipPosition="bottom">
|
||||
<i class="pi pi-sparkles text-surface-100"></i>
|
||||
</a>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
<li>
|
||||
<a class="topbar-item" (click)="navigateToSettings()" pTooltip="Settings" tooltipPosition="bottom">
|
||||
<i class="pi pi-cog text-surface-100"></i>
|
||||
</a>
|
||||
</li>
|
||||
</div>
|
||||
|
||||
<p-divider layout="vertical"/>
|
||||
|
||||
|
||||
<div class="flex gap-4">
|
||||
<li class="relative">
|
||||
<button
|
||||
type="button"
|
||||
class="topbar-item"
|
||||
(click)="notificationPopover.toggle($event)"
|
||||
>
|
||||
<i
|
||||
class="pi"
|
||||
[ngClass]="iconClass"
|
||||
[ngStyle]="{ color: iconColor }"
|
||||
style="font-size: 1.25rem"
|
||||
[class.pulsating]="iconPulsating"
|
||||
aria-label="Unified Notification Icon"
|
||||
></i>
|
||||
</button>
|
||||
|
||||
@if (shouldShowNotificationBadge) {
|
||||
<span class="notification-badge">{{ completedTaskCount }}</span>
|
||||
}
|
||||
|
||||
<p-popover #notificationPopover>
|
||||
<app-unified-notification-popover-component></app-unified-notification-popover-component>
|
||||
</p-popover>
|
||||
</li>
|
||||
|
||||
<li class="relative group overflow-hidden !border-transparent topbar-item" (click)="openGithubSupportDialog()">
|
||||
<span
|
||||
style="animation-duration: 2s; background: conic-gradient(from 90deg, #f97316, #f59e0b, #eab308, #84cc16, #22c55e, #10b981, #14a8a6, #06b6d4, #0ea5e9, #3b82f6, #6366f1, #8b5cf6, #a855f7, #d946ef, #ec4899, #f43f5e)"
|
||||
class="absolute -top-5 -left-5 w-20 h-20 animate-spin">
|
||||
</span>
|
||||
<span style="inset: 1px; border-radius: 4px" class="absolute z-2 bg-surface-900 transition-all"></span>
|
||||
<i class="pi pi-heart z-10"></i>
|
||||
</li>
|
||||
<li class="relative">
|
||||
<button type="button"
|
||||
class="topbar-item config-item"
|
||||
enterActiveClass="animate-scalein"
|
||||
enterFromClass="hidden"
|
||||
leaveActiveClass="animate-fadeout"
|
||||
leaveToClass="hidden"
|
||||
pStyleClass="@next" [hideOnOutsideClick]="true">
|
||||
<i class="pi pi-palette"></i>
|
||||
</button>
|
||||
<app-theme-configurator></app-theme-configurator>
|
||||
</li>
|
||||
</div>
|
||||
<p-divider layout="vertical"/>
|
||||
<div class="flex gap-4">
|
||||
<li>
|
||||
<a class="topbar-item"
|
||||
href="https://booklore-app.github.io/booklore-docs/docs/getting-started/"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
pTooltip="Documentation"
|
||||
tooltipPosition="bottom">
|
||||
<i class="pi pi-info-circle text-surface-100"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<button class="topbar-item" (click)="openUserProfileDialog()" pTooltip="Profile" tooltipPosition="bottom">
|
||||
<i class="pi pi-user text-surface-100"></i>
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button class="topbar-item" (click)="logout()" pTooltip="Logout" tooltipPosition="left">
|
||||
<i class="pi pi-sign-out text-surface-100"></i>
|
||||
</button>
|
||||
</li>
|
||||
</div>
|
||||
</ul>
|
||||
<!-- Trigger Button -->
|
||||
<div class="md:hidden relative ml-auto">
|
||||
<p-button
|
||||
icon="pi pi-ellipsis-v"
|
||||
outlined
|
||||
(click)="mobileMenu.toggle($event)"
|
||||
/>
|
||||
<p-popover #mobileMenu>
|
||||
<ul class="flex flex-col gap-1 w-48">
|
||||
@if (userService.userState$ | async; as userState) {
|
||||
@if (userState.user?.permissions?.canManipulateLibrary || userState.user?.permissions?.admin) {
|
||||
<li>
|
||||
<button
|
||||
class="flex items-center gap-2 w-full text-left p-2 hover:bg-surface-200 dark:hover:bg-surface-700 rounded"
|
||||
(click)="openLibraryCreatorDialog(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-plus-circle text-surface-100"></i>
|
||||
Create Library
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
class="flex items-center gap-2 w-full text-left p-2 hover:bg-surface-200 dark:hover:bg-surface-700 rounded"
|
||||
(click)="openFileUploadDialog(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-upload text-surface-100"></i>
|
||||
Upload Book
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
class="flex items-center gap-2 w-full text-left p-2 hover:bg-surface-200 dark:hover:bg-surface-700 rounded"
|
||||
(click)="navigateToBookdrop(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-inbox text-surface-100"></i>
|
||||
Bookdrop
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
}
|
||||
<li>
|
||||
<button
|
||||
class="flex items-center gap-2 w-full text-left p-2 hover:bg-surface-200 dark:hover:bg-surface-700 rounded"
|
||||
(click)="navigateToStats(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-chart-bar text-surface-100"></i>
|
||||
Charts
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
class="flex items-center gap-2 w-full text-left p-2 hover:bg-surface-200 dark:hover:bg-surface-700 rounded"
|
||||
(click)="navigateToSettings(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-cog text-surface-100"></i>
|
||||
Settings
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
class="flex items-center gap-2 w-full text-left p-2 hover:bg-surface-200 dark:hover:bg-surface-700 rounded"
|
||||
href="https://booklore-app.github.io/booklore-docs/docs/getting-started/"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">
|
||||
<i class="pi pi-info-circle text-surface-100"></i>
|
||||
Documentation
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
class="flex items-center gap-2 w-full text-left p-2 hover:bg-surface-200 dark:hover:bg-surface-700 rounded"
|
||||
(click)="openGithubSupportDialog(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-thumbs-up text-surface-100"></i>
|
||||
Support BookLore
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
class="flex items-center gap-2 w-full text-left p-2 hover:bg-surface-200 dark:hover:bg-surface-700 rounded"
|
||||
(click)="openUserProfileDialog(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-user text-surface-100"></i>
|
||||
Profile
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
class="flex items-center gap-2 w-full text-left p-2 hover:bg-surface-200 dark:hover:bg-surface-700 rounded"
|
||||
(click)="logout(); mobileMenu.hide()"
|
||||
>
|
||||
<i class="pi pi-sign-out text-surface-100"></i>
|
||||
Logout
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</p-popover>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,40 @@
|
||||
.highlight {
|
||||
color: red !important;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.spin {
|
||||
animation: spin 1.5s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes pulsate {
|
||||
0% { transform: scale(1); opacity: 1; }
|
||||
50% { transform: scale(1.25); opacity: 0.8; }
|
||||
100% { transform: scale(1); opacity: 1; }
|
||||
}
|
||||
|
||||
.pulsating {
|
||||
animation: pulsate 1.5s infinite ease-in-out;
|
||||
}
|
||||
|
||||
.notification-badge {
|
||||
position: absolute;
|
||||
top: -0.4rem;
|
||||
right: -0.4rem;
|
||||
background-color: red;
|
||||
color: white;
|
||||
border-radius: 50%;
|
||||
width: 1.2rem;
|
||||
height: 1.2rem;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
import {Component, ElementRef, OnDestroy, ViewChild} from '@angular/core';
|
||||
import {MenuItem} from 'primeng/api';
|
||||
import {LayoutService} from '../layout-main/service/app.layout.service';
|
||||
import {Router, RouterLink} from '@angular/router';
|
||||
import {DialogService as PrimeDialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {BookSearcherComponent} from '../../../../features/book/components/book-searcher/book-searcher.component';
|
||||
import {AsyncPipe, NgClass, NgStyle} from '@angular/common';
|
||||
import {NotificationEventService} from '../../../websocket/notification-event.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {StyleClass} from 'primeng/styleclass';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {ThemeConfiguratorComponent} from '../theme-configurator/theme-configurator.component';
|
||||
import {AuthService} from '../../../service/auth.service';
|
||||
import {UserService} from '../../../../features/settings/user-management/user.service';
|
||||
import {Popover} from 'primeng/popover';
|
||||
import {MetadataProgressService} from '../../../service/metadata-progress-service';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {Subject} from 'rxjs';
|
||||
import {MetadataBatchProgressNotification} from '../../../model/metadata-batch-progress.model';
|
||||
import {BookdropFileService} from '../../../../features/bookdrop/service/bookdrop-file.service';
|
||||
import {DialogLauncherService} from '../../../../core/service/dialog-launcher.service';
|
||||
import {DuplicateFileService} from '../../../websocket/duplicate-file.service';
|
||||
import {UnifiedNotificationBoxComponent} from '../../../components/unified-notification-popover/unified-notification-popover-component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-topbar',
|
||||
templateUrl: './app.topbar.component.html',
|
||||
styleUrls: ['./app.topbar.component.scss'],
|
||||
standalone: true,
|
||||
imports: [
|
||||
RouterLink,
|
||||
TooltipModule,
|
||||
FormsModule,
|
||||
InputTextModule,
|
||||
BookSearcherComponent,
|
||||
Button,
|
||||
ThemeConfiguratorComponent,
|
||||
StyleClass,
|
||||
NgClass,
|
||||
Divider,
|
||||
AsyncPipe,
|
||||
Popover,
|
||||
UnifiedNotificationBoxComponent,
|
||||
NgStyle,
|
||||
],
|
||||
})
|
||||
export class AppTopBarComponent implements OnDestroy {
|
||||
items!: MenuItem[];
|
||||
ref?: DynamicDialogRef;
|
||||
|
||||
@ViewChild('menubutton') menuButton!: ElementRef;
|
||||
@ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef;
|
||||
@ViewChild('topbarmenu') menu!: ElementRef;
|
||||
|
||||
isMenuVisible = true;
|
||||
progressHighlight = false;
|
||||
completedTaskCount = 0;
|
||||
hasActiveOrCompletedTasks = false;
|
||||
showPulse = false;
|
||||
hasAnyTasks = false;
|
||||
hasPendingBookdropFiles = false;
|
||||
hasDuplicateFiles = false;
|
||||
|
||||
private eventTimer: any;
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
private latestTasks: { [taskId: string]: MetadataBatchProgressNotification } = {};
|
||||
private latestHasPendingFiles = false;
|
||||
private latestHasDuplicateFiles = false;
|
||||
|
||||
constructor(
|
||||
public layoutService: LayoutService,
|
||||
public dialogService: PrimeDialogService,
|
||||
private notificationService: NotificationEventService,
|
||||
private router: Router,
|
||||
private authService: AuthService,
|
||||
protected userService: UserService,
|
||||
private metadataProgressService: MetadataProgressService,
|
||||
private bookdropFileService: BookdropFileService,
|
||||
private dialogLauncher: DialogLauncherService,
|
||||
private duplicateFileService: DuplicateFileService
|
||||
) {
|
||||
this.subscribeToMetadataProgress();
|
||||
this.subscribeToNotifications();
|
||||
this.subscribeToDuplicateFiles();
|
||||
|
||||
this.metadataProgressService.activeTasks$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((tasks) => {
|
||||
this.latestTasks = tasks;
|
||||
this.hasAnyTasks = Object.keys(tasks).length > 0;
|
||||
this.updateCompletedTaskCount();
|
||||
this.updateTaskVisibility(tasks);
|
||||
});
|
||||
|
||||
this.bookdropFileService.hasPendingFiles$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((hasPending) => {
|
||||
this.latestHasPendingFiles = hasPending;
|
||||
this.hasPendingBookdropFiles = hasPending;
|
||||
this.updateCompletedTaskCount();
|
||||
this.updateTaskVisibilityWithBookdrop();
|
||||
});
|
||||
|
||||
this.duplicateFileService.duplicateFiles$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((duplicateFiles) => {
|
||||
this.latestHasDuplicateFiles = duplicateFiles && duplicateFiles.length > 0;
|
||||
this.hasDuplicateFiles = this.latestHasDuplicateFiles;
|
||||
this.updateCompletedTaskCount();
|
||||
this.updateTaskVisibilityWithDuplicates();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.ref) this.ref.close();
|
||||
clearTimeout(this.eventTimer);
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
toggleMenu() {
|
||||
this.isMenuVisible = !this.isMenuVisible;
|
||||
this.layoutService.onMenuToggle();
|
||||
}
|
||||
|
||||
openGithubSupportDialog(): void {
|
||||
this.dialogLauncher.openGithubSupportDialog();
|
||||
}
|
||||
|
||||
openLibraryCreatorDialog(): void {
|
||||
this.dialogLauncher.openLibraryCreatorDialog();
|
||||
}
|
||||
|
||||
openFileUploadDialog(): void {
|
||||
this.dialogLauncher.openFileUploadDialog();
|
||||
}
|
||||
|
||||
openUserProfileDialog(): void {
|
||||
this.dialogLauncher.openUserProfileDialog();
|
||||
}
|
||||
|
||||
navigateToSettings() {
|
||||
this.router.navigate(['/settings']);
|
||||
}
|
||||
|
||||
navigateToBookdrop() {
|
||||
this.router.navigate(['/bookdrop']);
|
||||
}
|
||||
|
||||
navigateToMetadataManager() {
|
||||
this.router.navigate(['/metadata-manager']);
|
||||
}
|
||||
|
||||
navigateToStats() {
|
||||
this.router.navigate(['/stats']);
|
||||
}
|
||||
|
||||
logout() {
|
||||
this.authService.logout();
|
||||
}
|
||||
|
||||
private subscribeToMetadataProgress() {
|
||||
this.metadataProgressService.progressUpdates$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((progress) => {
|
||||
this.progressHighlight = progress.status === 'IN_PROGRESS';
|
||||
});
|
||||
}
|
||||
|
||||
private subscribeToNotifications() {
|
||||
this.notificationService.latestNotification$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(() => {
|
||||
this.triggerPulseEffect();
|
||||
});
|
||||
}
|
||||
|
||||
private subscribeToDuplicateFiles() {
|
||||
this.duplicateFileService.duplicateFiles$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe((duplicateFiles) => {
|
||||
if (duplicateFiles && duplicateFiles.length > 0) {
|
||||
this.triggerPulseEffect();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private triggerPulseEffect() {
|
||||
this.showPulse = true;
|
||||
clearTimeout(this.eventTimer);
|
||||
this.eventTimer = setTimeout(() => {
|
||||
this.showPulse = false;
|
||||
}, 4000);
|
||||
}
|
||||
|
||||
private updateCompletedTaskCount() {
|
||||
const completedMetadataTasks = Object.values(this.latestTasks).length;
|
||||
const bookdropFileTaskCount = this.latestHasPendingFiles ? 1 : 0;
|
||||
const duplicateFileTaskCount = this.latestHasDuplicateFiles ? 1 : 0;
|
||||
this.completedTaskCount = completedMetadataTasks + bookdropFileTaskCount + duplicateFileTaskCount;
|
||||
}
|
||||
|
||||
private updateTaskVisibility(tasks: { [taskId: string]: MetadataBatchProgressNotification }) {
|
||||
this.hasActiveOrCompletedTasks =
|
||||
this.progressHighlight || this.completedTaskCount > 0 || Object.keys(tasks).length > 0;
|
||||
this.updateTaskVisibilityWithBookdrop();
|
||||
}
|
||||
|
||||
private updateTaskVisibilityWithBookdrop() {
|
||||
this.hasActiveOrCompletedTasks = this.hasActiveOrCompletedTasks || this.hasPendingBookdropFiles;
|
||||
this.updateTaskVisibilityWithDuplicates();
|
||||
}
|
||||
|
||||
private updateTaskVisibilityWithDuplicates() {
|
||||
this.hasActiveOrCompletedTasks = this.hasActiveOrCompletedTasks || this.hasDuplicateFiles;
|
||||
}
|
||||
|
||||
get iconClass(): string {
|
||||
if (this.progressHighlight) return 'pi-spinner spin';
|
||||
if (this.iconPulsating) return 'pi-wave-pulse';
|
||||
if (this.completedTaskCount > 0 || this.hasPendingBookdropFiles) return 'pi-bell';
|
||||
return 'pi-wave-pulse';
|
||||
}
|
||||
|
||||
get iconColor(): string {
|
||||
if (this.progressHighlight) return 'yellow';
|
||||
if (this.showPulse) return 'orange';
|
||||
if (this.completedTaskCount > 0 || this.hasPendingBookdropFiles || this.hasDuplicateFiles) return 'yellowgreen';
|
||||
return 'inherit';
|
||||
}
|
||||
|
||||
get iconPulsating(): boolean {
|
||||
return !this.progressHighlight && (this.showPulse);
|
||||
}
|
||||
|
||||
get shouldShowNotificationBadge(): boolean {
|
||||
return (
|
||||
(this.completedTaskCount > 0 || this.hasPendingBookdropFiles || this.hasDuplicateFiles) &&
|
||||
!this.progressHighlight &&
|
||||
!this.showPulse
|
||||
);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable, map, tap} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../core/config/api-config';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class BackgroundUploadService {
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/background`;
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
uploadFile(file: File): Observable<string> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return this.http.post<{ url: string }>(`${this.baseUrl}/upload`, formData).pipe(
|
||||
tap(response => console.log('File upload response:', response)),
|
||||
map(resp => resp?.url)
|
||||
);
|
||||
}
|
||||
|
||||
uploadUrl(url: string): Observable<string> {
|
||||
return this.http.post<{ url: string }>(`${this.baseUrl}/url`, {url}).pipe(
|
||||
tap(response => console.log('URL upload response:', response)),
|
||||
map(resp => resp?.url)
|
||||
);
|
||||
}
|
||||
|
||||
resetToDefault(): Observable<void> {
|
||||
return this.http.delete<void>(this.baseUrl).pipe(
|
||||
tap(() => console.log('Background reset to default'))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class FaviconService {
|
||||
private svgTemplate = (color: string) => `
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 126 126" fill="currentColor">
|
||||
<path d="M59 4.79297C71.5051 11.5557 80 24.7854 80 40C80 40.5959 79.987 41.1888 79.9609 41.7783C79.8609 44.0406 81.7355 46 84 46C106.091 46 124 63.9086 124 86C124 108.091 106.091 126 84 126H10C4.47715 126 0 121.523 0 116V39.0068L0.0126953 38.9941C0.357624 25.0252 7.86506 12.8347 19 5.95215V63.832C19 64.8345 20.0676 65.4391 20.9121 64.9902L21.0771 64.8867L38.2227 52.3428C38.6819 52.0068 39.3064 52.0068 39.7656 52.3428L56.9229 64.8945L57.0879 64.998C57.9324 65.447 59 64.8423 59 63.8398V4.79297Z" fill="${color}"/>
|
||||
<path d="M40 0C43.8745 0 47.6199 0.552381 51.1631 1.58008V50.9697L44.3926 46.0176L44.0879 45.8037C40.9061 43.6679 36.7098 43.7393 33.5957 46.0176L26.8369 50.9619V2.21875C30.9593 0.782634 35.3881 0 40 0Z" fill="white"/>
|
||||
</svg>
|
||||
`;
|
||||
|
||||
updateFavicon(color: string) {
|
||||
const svg = this.svgTemplate(color);
|
||||
const blob = new Blob([svg], {type: 'image/svg+xml'});
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
let favicon = document.querySelector("link[rel*='icon']") as HTMLLinkElement;
|
||||
if (!favicon) {
|
||||
favicon = document.createElement('link');
|
||||
favicon.rel = 'icon';
|
||||
document.head.appendChild(favicon);
|
||||
}
|
||||
|
||||
favicon.type = 'image/svg+xml';
|
||||
favicon.href = url;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<div class="config-panel-content">
|
||||
|
||||
<div class="config-panel-colors">
|
||||
<span class="config-panel-label">Primary</span>
|
||||
<div>
|
||||
@for (primaryColor of primaryColors(); track primaryColor.name) {
|
||||
<button
|
||||
type="button"
|
||||
[title]="primaryColor.name"
|
||||
(click)="updateColors($event, 'primary', primaryColor)"
|
||||
[ngClass]="{ 'active-color': primaryColor.name === selectedPrimaryColor() }"
|
||||
[style]="{ 'background-color': primaryColor.name === 'noir' ? 'var(--text-color)' : primaryColor.palette['500'] || 'transparent' }"
|
||||
></button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="config-panel-colors">
|
||||
<span class="config-panel-label">Surface</span>
|
||||
<div>
|
||||
@for (surface of surfaces; track surface.name) {
|
||||
<button
|
||||
type="button"
|
||||
[title]="surface.name"
|
||||
(click)="updateColors($event, 'surface', surface)"
|
||||
[ngClass]="{ 'active-color': selectedSurfaceColor() ? selectedSurfaceColor() === surface.name : surface.name === 'zinc' }"
|
||||
[style]="{'background-color': surface.name === 'noir' ? 'var(--text-color)' : surface.palette['500'] }">
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {Component, computed, effect, inject} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {RadioButtonModule} from 'primeng/radiobutton';
|
||||
import {ToggleSwitchModule} from 'primeng/toggleswitch';
|
||||
|
||||
import Aura from '../theme-palette-extend';
|
||||
|
||||
import {AppConfigService} from '../../../service/app-config.service';
|
||||
import {FaviconService} from './favicon-service';
|
||||
|
||||
type ColorPalette = Record<string, string>;
|
||||
|
||||
interface Palette {
|
||||
name: string;
|
||||
palette: ColorPalette;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-theme-configurator',
|
||||
standalone: true,
|
||||
templateUrl: './theme-configurator.component.html',
|
||||
host: {
|
||||
class: 'config-panel hidden'
|
||||
},
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
ButtonModule,
|
||||
RadioButtonModule,
|
||||
ToggleSwitchModule
|
||||
]
|
||||
})
|
||||
export class ThemeConfiguratorComponent {
|
||||
readonly configService = inject(AppConfigService);
|
||||
readonly faviconService = inject(FaviconService);
|
||||
|
||||
readonly surfaces = this.configService.surfaces;
|
||||
|
||||
readonly selectedPrimaryColor = computed(() => this.configService.appState().primary);
|
||||
readonly selectedSurfaceColor = computed(() => this.configService.appState().surface);
|
||||
|
||||
readonly faviconColor = computed(() => {
|
||||
const name = this.selectedPrimaryColor() ?? 'green';
|
||||
const presetPalette = (Aura.primitive ?? {}) as Record<string, ColorPalette>;
|
||||
const colorPalette = presetPalette[name];
|
||||
return colorPalette?.[500] ?? name;
|
||||
});
|
||||
|
||||
private readonly _faviconSyncEffect = effect(() => {
|
||||
this.faviconService.updateFavicon(this.faviconColor());
|
||||
});
|
||||
|
||||
readonly primaryColors = computed<Palette[]>(() => {
|
||||
const presetPalette = (Aura.primitive ?? {}) as Record<string, ColorPalette>;
|
||||
const colors = [
|
||||
'emerald', 'green', 'lime', 'orange', 'amber', 'yellow',
|
||||
'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet',
|
||||
'purple', 'fuchsia', 'pink', 'rose', 'red',
|
||||
'coralSunset', 'roseBlush', 'melonBlush', 'cottonCandy',
|
||||
'apricotSunrise', 'antiqueBronze', 'butteryYellow', 'vanillaCream',
|
||||
'citrusMint', 'freshMint', 'sagePearl', 'skyBlue','periwinkleCream',
|
||||
'pastelRoyalBlue', 'lavenderDream', 'dustyNeutral'
|
||||
];
|
||||
return [{name: 'noir', palette: {}}].concat(
|
||||
colors.map(name => ({
|
||||
name,
|
||||
palette: presetPalette[name] ?? {}
|
||||
}))
|
||||
);
|
||||
});
|
||||
|
||||
updateColors(event: Event, type: 'primary' | 'surface', color: { name: string; palette?: ColorPalette }) {
|
||||
this.configService.appState.update((state) => ({
|
||||
...state,
|
||||
[type]: color.name
|
||||
}));
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<div class="upload-dialog-content">
|
||||
<div class="upload-section">
|
||||
<div class="file-selector">
|
||||
<label class="file-label">Choose File:</label>
|
||||
<p-button
|
||||
label="Select Image"
|
||||
icon="pi pi-upload"
|
||||
(click)="fileInput.click()"
|
||||
outlined
|
||||
severity="info">
|
||||
</p-button>
|
||||
</div>
|
||||
<input
|
||||
#fileInput
|
||||
type="file"
|
||||
accept=".jpg,.jpeg,.png,image/jpeg,image/png"
|
||||
(change)="onFileSelected($event)"
|
||||
style="display: none;">
|
||||
<small class="file-note">Supported formats: JPEG, PNG • Maximum file size: 5 MB</small>
|
||||
@if (uploadFile) {
|
||||
<small class="selected-file">{{ uploadFile.name }}</small>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p-divider align="center" type="solid">
|
||||
<span class="or-text">OR</span>
|
||||
</p-divider>
|
||||
|
||||
<div class="url-section">
|
||||
<label for="urlInput" class="url-label">Image URL:</label>
|
||||
<input
|
||||
id="urlInput"
|
||||
type="text"
|
||||
[(ngModel)]="uploadImageUrl"
|
||||
placeholder="Paste image URL here"
|
||||
class="url-input"
|
||||
pInputText>
|
||||
<small class="url-note">Supported formats: JPEG, PNG • Maximum file size: 5 MB</small>
|
||||
</div>
|
||||
|
||||
@if (uploadError) {
|
||||
<p-message severity="error">{{uploadError}}</p-message>
|
||||
}
|
||||
|
||||
<div class="dialog-footer">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
icon="pi pi-times"
|
||||
(click)="cancel()"
|
||||
severity="secondary"
|
||||
outlined>
|
||||
</p-button>
|
||||
<p-button
|
||||
label="Submit"
|
||||
icon="pi pi-check"
|
||||
(click)="submit()">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
.upload-dialog-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
padding: 1rem 0;
|
||||
|
||||
.upload-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
.file-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.file-label {
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.file-input {
|
||||
padding: 0.75rem;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--p-border-radius);
|
||||
background: var(--ground-background);
|
||||
}
|
||||
|
||||
.file-note {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.selected-file {
|
||||
color: var(--text-secondary-color);
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
|
||||
.url-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
|
||||
.url-label {
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.url-input {
|
||||
width: 100%;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.url-note {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.875rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
.or-text {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-color);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
p-message {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
justify-content: flex-end;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {DividerModule} from 'primeng/divider';
|
||||
import {MessageModule} from 'primeng/message';
|
||||
import {BackgroundUploadService} from '../background-upload.service';
|
||||
import {take} from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-upload-dialog',
|
||||
standalone: true,
|
||||
templateUrl: './upload-dialog.component.html',
|
||||
styleUrls: ['./upload-dialog.component.scss'],
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
ButtonModule,
|
||||
InputTextModule,
|
||||
DividerModule,
|
||||
MessageModule
|
||||
]
|
||||
})
|
||||
export class UploadDialogComponent {
|
||||
private readonly dialogRef = inject(DynamicDialogRef);
|
||||
private readonly backgroundUploadService = inject(BackgroundUploadService);
|
||||
|
||||
uploadImageUrl = '';
|
||||
uploadFile: File | null = null;
|
||||
uploadError = '';
|
||||
|
||||
onFileSelected(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
if (input.files && input.files.length > 0) {
|
||||
this.uploadFile = input.files[0];
|
||||
this.uploadImageUrl = '';
|
||||
}
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.uploadError = '';
|
||||
let upload$;
|
||||
if (this.uploadFile) {
|
||||
upload$ = this.backgroundUploadService.uploadFile(this.uploadFile);
|
||||
} else if (this.uploadImageUrl.trim()) {
|
||||
upload$ = this.backgroundUploadService.uploadUrl(this.uploadImageUrl.trim());
|
||||
} else {
|
||||
this.uploadError = 'Please select a file or paste a URL.';
|
||||
return;
|
||||
}
|
||||
|
||||
upload$.pipe(take(1)).subscribe({
|
||||
next: (imageUrl) => {
|
||||
if (imageUrl) {
|
||||
this.dialogRef.close({ imageUrl });
|
||||
} else {
|
||||
this.uploadError = 'Failed to upload image.';
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Upload failed:', err);
|
||||
this.uploadError = 'Upload failed. Please try again.';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
import Aura from '@primeng/themes/aura';
|
||||
|
||||
type ColorPalette = Record<string, string>;
|
||||
|
||||
const customPalettes: Record<string, ColorPalette> = {
|
||||
coralSunset: {
|
||||
50: '#fef7f0',
|
||||
100: '#feede1',
|
||||
200: '#fcd9c2',
|
||||
300: '#f9be9e',
|
||||
400: '#f59673',
|
||||
500: '#ef7550',
|
||||
600: '#de5a3a',
|
||||
700: '#b94730',
|
||||
800: '#943a2e',
|
||||
900: '#78322a',
|
||||
950: '#401814'
|
||||
},
|
||||
roseBlush: {
|
||||
50: '#fef7f7',
|
||||
100: '#feebeb',
|
||||
200: '#fddcdc',
|
||||
300: '#fbbfbf',
|
||||
400: '#f69393',
|
||||
500: '#ed6767',
|
||||
600: '#d93f3f',
|
||||
700: '#b73030',
|
||||
800: '#982d2d',
|
||||
900: '#7f2d2d',
|
||||
950: '#451313'
|
||||
},
|
||||
melonBlush: {
|
||||
50: '#fffafb',
|
||||
100: '#fff2f4',
|
||||
200: '#ffdfe7',
|
||||
300: '#ffcbd4',
|
||||
400: '#ffaebb',
|
||||
500: '#ff90a2',
|
||||
600: '#ff6f88',
|
||||
700: '#e8506b',
|
||||
800: '#b7384d',
|
||||
900: '#7f2231',
|
||||
950: '#3f1118'
|
||||
},
|
||||
cottonCandy: {
|
||||
50: '#fff9fb',
|
||||
100: '#fff0f6',
|
||||
200: '#ffdfee',
|
||||
300: '#ffc0e0',
|
||||
400: '#ffa3cf',
|
||||
500: '#ff86bf',
|
||||
600: '#ff69ad',
|
||||
700: '#e14f93',
|
||||
800: '#b93a72',
|
||||
900: '#86284f',
|
||||
950: '#42142a'
|
||||
},
|
||||
apricotSunrise: {
|
||||
50: '#fffaf7',
|
||||
100: '#fff1e8',
|
||||
200: '#ffe2c9',
|
||||
300: '#ffd2a8',
|
||||
400: '#ffbf88',
|
||||
500: '#ffad68',
|
||||
600: '#ff974f',
|
||||
700: '#e67a3b',
|
||||
800: '#b6572b',
|
||||
900: '#7f351b',
|
||||
950: '#3f190f'
|
||||
},
|
||||
antiqueBronze: {
|
||||
50: '#faf7f2',
|
||||
100: '#f4ede0',
|
||||
200: '#e8d9c0',
|
||||
300: '#d9c199',
|
||||
400: '#c8a56f',
|
||||
500: '#b8904f',
|
||||
600: '#a67c44',
|
||||
700: '#8a6439',
|
||||
800: '#715233',
|
||||
900: '#5c442c',
|
||||
950: '#302316'
|
||||
},
|
||||
butteryYellow: {
|
||||
50: '#fffef7',
|
||||
100: '#fffceb',
|
||||
200: '#fff7d1',
|
||||
300: '#ffeea7',
|
||||
400: '#ffe072',
|
||||
500: '#ffcf45',
|
||||
600: '#ffb61f',
|
||||
700: '#ff9b0a',
|
||||
800: '#cc7606',
|
||||
900: '#a35f0c',
|
||||
950: '#633204'
|
||||
},
|
||||
vanillaCream: {
|
||||
50: '#fefdfb',
|
||||
100: '#fefbf6',
|
||||
200: '#fdf5ea',
|
||||
300: '#fbecd5',
|
||||
400: '#f7dbb5',
|
||||
500: '#f1c589',
|
||||
600: '#e8a95c',
|
||||
700: '#d88d3e',
|
||||
800: '#b47134',
|
||||
900: '#915c2e',
|
||||
950: '#4e2f17'
|
||||
},
|
||||
citrusMint: {
|
||||
50: '#fbfff9',
|
||||
100: '#f4fff2',
|
||||
200: '#e8ffd9',
|
||||
300: '#d1ffbc',
|
||||
400: '#b7ffa0',
|
||||
500: '#96ff84',
|
||||
600: '#76e96e',
|
||||
700: '#4fb84c',
|
||||
800: '#2f7f32',
|
||||
900: '#1a4f20',
|
||||
950: '#0a2410'
|
||||
},
|
||||
freshMint: {
|
||||
50: '#f8fff9',
|
||||
100: '#f0fff3',
|
||||
200: '#dcffea',
|
||||
300: '#bfffd6',
|
||||
400: '#99ffc2',
|
||||
500: '#7fffae',
|
||||
600: '#5fe592',
|
||||
700: '#3fbf75',
|
||||
800: '#2d8f55',
|
||||
900: '#1e5f39',
|
||||
950: '#0f2f1d'
|
||||
},
|
||||
sagePearl: {
|
||||
50: '#fbfdfb',
|
||||
100: '#f4f8f4',
|
||||
200: '#e6efe6',
|
||||
300: '#d1e6d1',
|
||||
400: '#bcdcbf',
|
||||
500: '#9fcfa8',
|
||||
600: '#84b792',
|
||||
700: '#5f8f6e',
|
||||
800: '#3f6648',
|
||||
900: '#25442e',
|
||||
950: '#0f2118'
|
||||
},
|
||||
skyBlue: {
|
||||
50: '#f7fbff',
|
||||
100: '#eef6ff',
|
||||
200: '#dceefd',
|
||||
300: '#c1e8ff',
|
||||
400: '#99dfff',
|
||||
500: '#6fc8ff',
|
||||
600: '#48afff',
|
||||
700: '#2e88e6',
|
||||
800: '#2360b3',
|
||||
900: '#153d80',
|
||||
950: '#071d40'
|
||||
},
|
||||
periwinkleCream: {
|
||||
50: '#fbfbff',
|
||||
100: '#f2f3ff',
|
||||
200: '#e7eaff',
|
||||
300: '#d2dcff',
|
||||
400: '#b9c9ff',
|
||||
500: '#9fb2ff',
|
||||
600: '#7f97ff',
|
||||
700: '#5f78e6',
|
||||
800: '#4559b3',
|
||||
900: '#2b387f',
|
||||
950: '#151c40'
|
||||
},
|
||||
pastelRoyalBlue: {
|
||||
50: '#f6fbff',
|
||||
100: '#eef6ff',
|
||||
200: '#dbeeff',
|
||||
300: '#b9ddff',
|
||||
400: '#92c7ff',
|
||||
500: '#63aaff',
|
||||
600: '#3b88ff',
|
||||
700: '#2e66cc',
|
||||
800: '#235099',
|
||||
900: '#183366',
|
||||
950: '#0d1a33'
|
||||
},
|
||||
lavenderDream: {
|
||||
50: '#fbf7ff',
|
||||
100: '#f6eeff',
|
||||
200: '#ebdcff',
|
||||
300: '#dcc0ff',
|
||||
400: '#caa1ff',
|
||||
500: '#b47fff',
|
||||
600: '#9366e6',
|
||||
700: '#6f45b3',
|
||||
800: '#4c2f80',
|
||||
900: '#2d1b4f',
|
||||
950: '#15082a'
|
||||
},
|
||||
dustyNeutral: {
|
||||
50: '#faf9f7',
|
||||
100: '#f3f1ed',
|
||||
200: '#e8e3db',
|
||||
300: '#d8cfc2',
|
||||
400: '#c4b5a3',
|
||||
500: '#b39c85',
|
||||
600: '#a28a70',
|
||||
700: '#87725d',
|
||||
800: '#6f5e4e',
|
||||
900: '#5a4e42',
|
||||
950: '#2f2821'
|
||||
}
|
||||
};
|
||||
|
||||
if (!Aura.primitive) {
|
||||
Aura.primitive = {};
|
||||
}
|
||||
|
||||
Object.assign(Aura.primitive, customPalettes);
|
||||
|
||||
export default Aura;
|
||||
Reference in New Issue
Block a user