From 61e958040980c8aa0347df6410a19d505399bd99 Mon Sep 17 00:00:00 2001
From: "aditya.chandel" <>
Date: Mon, 16 Dec 2024 21:53:25 -0700
Subject: [PATCH] Add theme selector
---
.../book-metadata/book-metadata.component.ts | 2 +-
.../dashboard/dashboard.component.html | 3 +-
.../dashboard/dashboard.component.scss | 4 ++
.../dashboard/dashboard.component.ts | 2 +-
.../layout/app.topbar.component.html | 7 +--
.../component/layout/app.topbar.component.ts | 27 +++++----
.../library-creator.component.ts | 2 +-
.../theme-switcher.component.html | 11 ++++
.../theme-switcher.component.scss | 0
.../theme-switcher.component.ts | 59 +++++++++++++++++++
.../assets/layout/styles/layout/_topbar.scss | 5 ++
booklore-ui/src/assets/themes/themes.json | 41 +++++++++++++
booklore-ui/src/index.html | 2 +-
13 files changed, 144 insertions(+), 21 deletions(-)
create mode 100644 booklore-ui/src/app/theme-switcher/theme-switcher.component.html
create mode 100644 booklore-ui/src/app/theme-switcher/theme-switcher.component.scss
create mode 100644 booklore-ui/src/app/theme-switcher/theme-switcher.component.ts
create mode 100644 booklore-ui/src/assets/themes/themes.json
diff --git a/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.ts b/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.ts
index b28b6e725..757a248d4 100644
--- a/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.ts
+++ b/booklore-ui/src/app/book/component/book-metadata/book-metadata.component.ts
@@ -76,7 +76,7 @@ export class BookMetadataComponent implements OnInit, OnDestroy {
openEditDialog(bookId: number | undefined, libraryId: number | undefined) {
this.dialogRef = this.dialogService.open(BooksMetadataDialogComponent, {
header: 'Metadata: Google Books',
- modal: false,
+ modal: true,
width: '65%',
height: '85%',
data: {
diff --git a/booklore-ui/src/app/book/component/dashboard/dashboard.component.html b/booklore-ui/src/app/book/component/dashboard/dashboard.component.html
index 935f2a7b0..07a05e6e7 100644
--- a/booklore-ui/src/app/book/component/dashboard/dashboard.component.html
+++ b/booklore-ui/src/app/book/component/dashboard/dashboard.component.html
@@ -1,5 +1,6 @@
-
+
+
diff --git a/booklore-ui/src/app/book/component/dashboard/dashboard.component.scss b/booklore-ui/src/app/book/component/dashboard/dashboard.component.scss
index 71591377a..932cbbb8e 100644
--- a/booklore-ui/src/app/book/component/dashboard/dashboard.component.scss
+++ b/booklore-ui/src/app/book/component/dashboard/dashboard.component.scss
@@ -12,6 +12,10 @@
color: var(--text-color);
}
+.dashboard-no-library {
+ margin-top: 3rem;
+}
+
.dashboard .p-dialog {
max-width: 90%;
}
diff --git a/booklore-ui/src/app/book/component/dashboard/dashboard.component.ts b/booklore-ui/src/app/book/component/dashboard/dashboard.component.ts
index f6f42214c..39c064990 100644
--- a/booklore-ui/src/app/book/component/dashboard/dashboard.component.ts
+++ b/booklore-ui/src/app/book/component/dashboard/dashboard.component.ts
@@ -10,12 +10,12 @@ import {DashboardScrollerComponent} from '../dashboard-scroller/dashboard-scroll
@Component({
selector: 'app-home-page',
templateUrl: './dashboard.component.html',
+ styleUrls: ['./dashboard.component.scss'],
imports: [
Button,
NgIf,
DashboardScrollerComponent
],
- styleUrls: ['./dashboard.component.scss'],
providers: [DialogService],
})
export class DashboardComponent {
diff --git a/booklore-ui/src/app/book/component/layout/app.topbar.component.html b/booklore-ui/src/app/book/component/layout/app.topbar.component.html
index 53720a29c..c7847cf82 100644
--- a/booklore-ui/src/app/book/component/layout/app.topbar.component.html
+++ b/booklore-ui/src/app/book/component/layout/app.topbar.component.html
@@ -30,10 +30,9 @@
Profile
-
+
diff --git a/booklore-ui/src/app/book/component/layout/app.topbar.component.ts b/booklore-ui/src/app/book/component/layout/app.topbar.component.ts
index 01dde8b4f..4aa0ee6fd 100644
--- a/booklore-ui/src/app/book/component/layout/app.topbar.component.ts
+++ b/booklore-ui/src/app/book/component/layout/app.topbar.component.ts
@@ -4,6 +4,7 @@ import {LayoutService} from './service/app.layout.service';
import {RouterLink} from '@angular/router';
import {DialogService as PrimeDialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
import {LibraryCreatorComponent} from '../library-creator/library-creator.component';
+import {ThemeSwitcherComponent} from '../../../theme-switcher/theme-switcher.component';
import {TooltipModule} from 'primeng/tooltip';
import {FormsModule} from '@angular/forms';
import {InputTextModule} from 'primeng/inputtext';
@@ -19,7 +20,8 @@ import {FileUploadComponent} from '../file-upload/file-upload.component';
FormsModule,
InputTextModule,
SearchComponent,
- NotificationComponent
+ NotificationComponent,
+ ThemeSwitcherComponent
],
templateUrl: './app.topbar.component.html',
})
@@ -37,9 +39,20 @@ export class AppTopBarComponent implements OnDestroy {
openLibraryCreatorDialog(): void {
this.ref = this.dialogService.open(LibraryCreatorComponent, {
header: 'Create New Library',
- modal: false,
+ modal: true,
width: '50%',
height: '50%',
+ style: {bottom: '15%'}
+ });
+ }
+
+ openFileUploadDialog() {
+ this.ref = this.dialogService.open(FileUploadComponent, {
+ header: 'Upload Book',
+ modal: true,
+ width: '45%',
+ height: '40%',
+ style: {bottom: '20%'}
});
}
@@ -48,14 +61,4 @@ export class AppTopBarComponent implements OnDestroy {
this.ref.close();
}
}
-
- openFileUploadDialog() {
- this.ref = this.dialogService.open(FileUploadComponent, {
- header: 'Upload Book',
- modal: false,
- width: '45%',
- height: '40%',
- style: { bottom: '20%' }
- });
- }
}
diff --git a/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts b/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts
index f59f0ad16..ef1a54a76 100644
--- a/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts
+++ b/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts
@@ -29,7 +29,7 @@ export class LibraryCreatorComponent {
show() {
this.ref = this.dialogService.open(DirectoryPickerComponent, {
header: 'Select Media Directory',
- modal: false,
+ modal: true,
width: '50%',
height: '75%',
contentStyle: {overflow: 'auto'},
diff --git a/booklore-ui/src/app/theme-switcher/theme-switcher.component.html b/booklore-ui/src/app/theme-switcher/theme-switcher.component.html
new file mode 100644
index 000000000..c8075fa57
--- /dev/null
+++ b/booklore-ui/src/app/theme-switcher/theme-switcher.component.html
@@ -0,0 +1,11 @@
+
diff --git a/booklore-ui/src/app/theme-switcher/theme-switcher.component.scss b/booklore-ui/src/app/theme-switcher/theme-switcher.component.scss
new file mode 100644
index 000000000..e69de29bb
diff --git a/booklore-ui/src/app/theme-switcher/theme-switcher.component.ts b/booklore-ui/src/app/theme-switcher/theme-switcher.component.ts
new file mode 100644
index 000000000..8c64d150a
--- /dev/null
+++ b/booklore-ui/src/app/theme-switcher/theme-switcher.component.ts
@@ -0,0 +1,59 @@
+import { Component, OnInit } from '@angular/core';
+import { HttpClient } from '@angular/common/http';
+import {DropdownChangeEvent, DropdownModule} from 'primeng/dropdown';
+import {FormsModule} from '@angular/forms';
+
+@Component({
+ selector: 'app-theme-switcher',
+ templateUrl: './theme-switcher.component.html',
+ standalone: true,
+ imports: [
+ FormsModule,
+ DropdownModule
+ ],
+ styleUrl: './theme-switcher.component.scss'
+})
+export class ThemeSwitcherComponent implements OnInit {
+ themes: { value: string; label: string }[] = [];
+ currentTheme: string = '';
+
+ constructor(private http: HttpClient) {}
+
+ ngOnInit(): void {
+ this.http
+ .get<{ value: string; label: string }[]>('assets/themes/themes.json')
+ .subscribe(
+ (data) => {
+ this.themes = data;
+ const savedTheme = localStorage.getItem('selected-theme');
+ if (savedTheme) {
+ this.currentTheme = savedTheme;
+ this.applyTheme(savedTheme);
+ } else if (this.themes.length > 0) {
+ this.currentTheme = this.themes[0].value;
+ this.applyTheme(this.currentTheme);
+ }
+ },
+ (error) => {
+ console.error('Error loading themes:', error);
+ }
+ );
+ }
+
+ changeTheme(event: DropdownChangeEvent) {
+ const selectedTheme = event.value;
+ this.currentTheme = selectedTheme;
+ this.applyTheme(selectedTheme);
+ localStorage.setItem('selected-theme', selectedTheme);
+ }
+
+ private applyTheme(theme: string) {
+ const themeLink = document.getElementById('theme-link') as HTMLLinkElement;
+ if (themeLink) {
+ themeLink.href = `assets/layout/styles/theme/${theme}/theme.css`;
+ console.log(`Theme applied: ${theme}`);
+ } else {
+ console.error('Theme link element not found!');
+ }
+ }
+}
diff --git a/booklore-ui/src/assets/layout/styles/layout/_topbar.scss b/booklore-ui/src/assets/layout/styles/layout/_topbar.scss
index 1ccd3eba3..83ea3e559 100644
--- a/booklore-ui/src/assets/layout/styles/layout/_topbar.scss
+++ b/booklore-ui/src/assets/layout/styles/layout/_topbar.scss
@@ -1,3 +1,7 @@
+.top-bar-app-theme-switcher {
+ margin-left: 1.25rem;
+}
+
.layout-topbar {
position: fixed;
height: 4.25rem;
@@ -79,6 +83,7 @@
padding: 0;
list-style: none;
display: flex;
+ align-items: center;
.layout-topbar-button {
margin-left: 1rem;
diff --git a/booklore-ui/src/assets/themes/themes.json b/booklore-ui/src/assets/themes/themes.json
new file mode 100644
index 000000000..97f68afbd
--- /dev/null
+++ b/booklore-ui/src/assets/themes/themes.json
@@ -0,0 +1,41 @@
+[
+ { "value": "arya-blue", "label": "Arya Blue" },
+ { "value": "arya-green", "label": "Arya Green" },
+ { "value": "arya-orange", "label": "Arya Orange" },
+ { "value": "arya-purple", "label": "Arya Purple" },
+ { "value": "aura-dark-amber", "label": "Aura Dark Amber" },
+ { "value": "aura-dark-blue", "label": "Aura Dark Blue" },
+ { "value": "aura-dark-cyan", "label": "Aura Dark Cyan" },
+ { "value": "aura-dark-green", "label": "Aura Dark Green" },
+ { "value": "aura-dark-indigo", "label": "Aura Dark Indigo" },
+ { "value": "aura-dark-lime", "label": "Aura Dark Lime" },
+ { "value": "aura-dark-noir", "label": "Aura Dark Noir" },
+ { "value": "aura-dark-pink", "label": "Aura Dark Pink" },
+ { "value": "aura-dark-purple", "label": "Aura Dark Purple" },
+ { "value": "aura-dark-teal", "label": "Aura Dark Teal" },
+ { "value": "bootstrap4-dark-blue", "label": "Bootstrap4 Dark Blue" },
+ { "value": "bootstrap4-dark-purple", "label": "Bootstrap4 Dark Purple" },
+ { "value": "lara-dark-amber", "label": "Lara Dark Amber" },
+ { "value": "lara-dark-blue", "label": "Lara Dark Blue" },
+ { "value": "lara-dark-cyan", "label": "Lara Dark Cyan" },
+ { "value": "lara-dark-green", "label": "Lara Dark Green" },
+ { "value": "lara-dark-indigo", "label": "Lara Dark Indigo" },
+ { "value": "lara-dark-pink", "label": "Lara Dark Pink" },
+ { "value": "lara-dark-purple", "label": "Lara Dark Purple" },
+ { "value": "lara-dark-teal", "label": "Lara Dark Teal" },
+ { "value": "luna-amber", "label": "Luna Amber" },
+ { "value": "luna-blue", "label": "Luna Blue" },
+ { "value": "luna-green", "label": "Luna Green" },
+ { "value": "luna-pink", "label": "Luna Pink" },
+ { "value": "md-dark-deeppurple", "label": "MD Dark Deep Purple" },
+ { "value": "md-dark-indigo", "label": "MD Dark Indigo" },
+ { "value": "mdc-dark-deeppurple", "label": "MDC Dark Deep Purple" },
+ { "value": "mdc-dark-indigo", "label": "MDC Dark Indigo" },
+ { "value": "mira", "label": "Mira" },
+ { "value": "soho-dark", "label": "Soho Dark" },
+ { "value": "vela-blue", "label": "Vela Blue" },
+ { "value": "vela-green", "label": "Vela Green" },
+ { "value": "vela-orange", "label": "Vela Orange" },
+ { "value": "vela-purple", "label": "Vela Purple" },
+ { "value": "viva-dark", "label": "Viva Dark" }
+]
diff --git a/booklore-ui/src/index.html b/booklore-ui/src/index.html
index e4c1d0452..cbdf71502 100644
--- a/booklore-ui/src/index.html
+++ b/booklore-ui/src/index.html
@@ -7,7 +7,7 @@
-
+