From 8b7c10317fbe452cca729f45278e544c89ec40bc Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Sun, 28 Apr 2024 00:26:46 +0100 Subject: [PATCH] add favorit page --- angular.json | 4 + frontend/src/app/app-routing.module.ts | 17 +-- frontend/src/app/app.module.ts | 9 +- .../features/favorit/favorit.component.css | 36 ++++++ .../features/favorit/favorit.component.html | 74 ++++++++++++ .../favorit/favorit.component.spec.ts | 23 ++++ .../app/features/favorit/favorit.component.ts | 111 ++++++++++++++++++ frontend/src/styles.css | 2 +- package-lock.json | 109 +++++++++++++++++ package.json | 2 + 10 files changed, 370 insertions(+), 17 deletions(-) create mode 100644 frontend/src/app/features/favorit/favorit.component.css create mode 100644 frontend/src/app/features/favorit/favorit.component.html create mode 100644 frontend/src/app/features/favorit/favorit.component.spec.ts create mode 100644 frontend/src/app/features/favorit/favorit.component.ts diff --git a/angular.json b/angular.json index 637dc7d..608cdf8 100644 --- a/angular.json +++ b/angular.json @@ -40,6 +40,8 @@ "frontend/src/assets/plugins/select2/css/select2.min.css", "frontend/src/assets/plugins/select2/css/select2-bootstrap4.css", + "node_modules/flatpickr/dist/flatpickr.min.css", + "frontend/src/assets/sass/responsive.css" ], "scripts": [ @@ -53,6 +55,8 @@ "frontend/src/assets/plugins/peity/jquery.peity.min.js", "frontend/src/assets/plugins/select2/js/select2-custom.js", "frontend/src/assets/plugins/select2/js/select2.min.js", + + "node_modules/flatpickr/dist/flatpickr.min.js", "frontend/src/assets/js/index.js", "frontend/src/assets/js/main.js" diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index 17a3ae9..97fe649 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -5,6 +5,8 @@ import { SearchComponent } from './features/discover/search/search.component'; import { TrendingComponent } from './features/discover/trending/trending.component'; import { PopularComponent } from './features/discover/popular/popular.component'; import { LibraryComponent } from './features/library/library.component'; +import { FavoritComponent } from './features/favorit/favorit.component'; +import { WatchlistComponent } from './features/watchlist/watchlist.component'; const routes: Routes = [ { path: '', redirectTo: '/home', pathMatch: 'full' }, @@ -14,20 +16,13 @@ const routes: Routes = [ { path: 'trending', component: TrendingComponent }, { path: 'library', component: LibraryComponent }, - { path: 'entry', component: LibraryComponent }, - // { - // path: 'entry/:id', - // component: EntryPageComponent, - // resolve: { - // entry: EntryResolverService, - // }, - // }, + { path: 'favorit', component: FavoritComponent }, + { path: 'watchlist', component: WatchlistComponent }, + // { path: 'entry', component: LibraryComponent }, { path: 'entry', loadChildren: () => - import('./features/entry/entries.module').then( - (m) => m.EntriesModule - ), + import('./features/entry/entries.module').then((m) => m.EntriesModule), }, { path: 'user-collections', diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 12fe7f3..09afadd 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -12,10 +12,6 @@ import { DragDropModule } from '@angular/cdk/drag-drop'; import { CoreModule } from './core/core.module'; import { CommonModule, DatePipe } from '@angular/common'; -import { ModalModule } from 'ngx-bootstrap/modal'; -import { AccordionModule } from 'ngx-bootstrap/accordion'; - - import { HomeComponent } from './features/home/home.component'; import { PopularComponent } from './features/discover/popular/popular.component'; import { TrendingComponent } from './features/discover/trending/trending.component'; @@ -26,6 +22,8 @@ import { DynamicEntryListComponent } from './shared/components/lists/dynamic-ent import { NotificationPopupComponent } from './shared/components/notification-popup/notification-popup.component'; import { MainCardComponent } from './shared/components/cards/main-card/main-card.component'; import { UserCollectionsModalComponent } from './shared/components/modals/list-selection-modal/user-collections-modal.component'; +import { FavoritComponent } from './features/favorit/favorit.component'; +import { WatchlistComponent } from './features/watchlist/watchlist.component'; @NgModule({ declarations: [ @@ -37,7 +35,8 @@ import { UserCollectionsModalComponent } from './shared/components/modals/list-s TrendingComponent, SearchComponent, LibraryComponent, - // EntryPageComponent, + FavoritComponent, + WatchlistComponent, // ? temp shared components MainCardComponent, diff --git a/frontend/src/app/features/favorit/favorit.component.css b/frontend/src/app/features/favorit/favorit.component.css new file mode 100644 index 0000000..2709cf5 --- /dev/null +++ b/frontend/src/app/features/favorit/favorit.component.css @@ -0,0 +1,36 @@ +.custom-group .form-select { + border-top-right-radius: 0; + border-bottom-right-radius: 0; +} + +.custom-group .form-select, +.custom-group .input-group-text { + border: 1px black solid; +} + +.custom-group .btn-group .btn { + border-radius: 0; +} + +.custom-group .btn-group .left-btn { + /* border-top-left-radius: 0.25rem; */ + /* border-bottom-left-radius: 0.25rem; */ + border-left: 0; + border-right: 0; +} + +.custom-group .btn-group .right-btn { + border-top-right-radius: 0.25rem; + border-bottom-right-radius: 0.25rem; + border-left: 0; + +} + +.custom-group .form-select, +.custom-group .btn-outline-dark { + margin-right: -1px; +} + +#single-select-field { + max-width: 120px; +} \ No newline at end of file diff --git a/frontend/src/app/features/favorit/favorit.component.html b/frontend/src/app/features/favorit/favorit.component.html new file mode 100644 index 0000000..21a52f2 --- /dev/null +++ b/frontend/src/app/features/favorit/favorit.component.html @@ -0,0 +1,74 @@ + + + + + +
+ +
+ + + + + +
+ +
\ No newline at end of file diff --git a/frontend/src/app/features/favorit/favorit.component.spec.ts b/frontend/src/app/features/favorit/favorit.component.spec.ts new file mode 100644 index 0000000..ac5d41e --- /dev/null +++ b/frontend/src/app/features/favorit/favorit.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { FavoritComponent } from './favorit.component'; + +describe('FavoritComponent', () => { + let component: FavoritComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [FavoritComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(FavoritComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/favorit/favorit.component.ts b/frontend/src/app/features/favorit/favorit.component.ts new file mode 100644 index 0000000..6a7f05e --- /dev/null +++ b/frontend/src/app/features/favorit/favorit.component.ts @@ -0,0 +1,111 @@ +import { Component } from '@angular/core'; +import { Entry } from '../../shared/models/entry.model'; +import { LibraryService } from '../../core/services/library.service'; + +@Component({ + selector: 'app-favorit', + templateUrl: './favorit.component.html', + styleUrl: './favorit.component.css', +}) +export class FavoritComponent { + entryType: number = 0; + + entries: Entry[] = []; + entriesToShow: Entry[] = []; + + entriesCount: number = 0; + maxPage: number = 10; + currentPage: number = 1; + pageSize: number = 10; + + constructor(private libraryService: LibraryService) {} + + ngOnInit() { + this.pageSize = this.getDefaultPageSize(); + this.getEntries(); + } + + // uses libraryService to get library all content + getEntries(forceFetch: boolean = false) { + this.libraryService.getAllEntries(forceFetch).subscribe({ + next: (entries) => { + this.entries = entries.filter((e) => e.favorit); + + this.filterEntries(); + }, + error: (error) => { + console.log(`Couldn't get entries.`, error); + // TODO show notification + }, + }); + } + + async filterEntries() { + var temp = [] as Entry[]; + + // ? type filter + if (this.entryType != 0) { + await this.entries.forEach((entry) => { + if (this.entryType == 1 && !entry.is_tvseries) temp.push(entry); + else if (this.entryType == 2 && entry.is_tvseries) temp.push(entry); + }); + } else { + temp = this.entries; + } + + const startIndex = (this.currentPage - 1) * this.pageSize; + const endIndex = startIndex + this.pageSize; + + this.entriesCount = temp.length; + this.maxPage = Math.ceil(this.entriesCount / this.pageSize); + this.entriesToShow = temp.slice(startIndex, endIndex); + } + + // ? pagination + goToPage(page: number) { + this.currentPage = page; + this.filterEntries(); + } + + get pageNumbers(): number[] { + let pagesToShow = 5; // Total pages to show at any time + let startPage: number, endPage: number; + + if (this.maxPage <= pagesToShow) { + startPage = 1; + endPage = this.maxPage; + } else { + startPage = Math.max(this.currentPage - Math.floor(pagesToShow / 2), 1); + endPage = startPage + pagesToShow - 1; + + if (endPage >= this.maxPage) { + endPage = this.maxPage; + startPage = endPage - pagesToShow + 1; + } + } + + // Generate the page numbers array. + return Array.from( + { length: endPage - startPage + 1 }, + (_, i) => startPage + i + ); + } + // ? end pagination + + // ? setter + setEntryType(entryType: number) { + this.entryType = entryType; + this.currentPage = 1; + + this.filterEntries(); + } + + setPageSize(event: any) { + this.pageSize = event.target.value; + this.filterEntries(); + } + + getDefaultPageSize() { + return 20; + } +} diff --git a/frontend/src/styles.css b/frontend/src/styles.css index c7b2ac6..846d31b 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -32,7 +32,7 @@ --shz-dark-bg: #181c1f; --shz-dark-bgh: rgba(255, 255, 255, 0.05); - --shz-gold-1: #ffc600; + --shz-gold-1: #fcc409; --shz-red-danger: #fc185a; --shz-blue-default: #008cff; --shz-green-success: #ffc600; diff --git a/package-lock.json b/package-lock.json index 7a743bb..704bf69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,10 +19,12 @@ "@angular/platform-browser-dynamic": "^17.0.0", "@angular/router": "^17.0.0", "angular-star-rating": "^7.0.0", + "apexcharts": "^3.49.0", "axios": "^1.6.8", "bootstrap": "^5.3.3", "date-fns": "^3.6.0", "express": "^4.19.2", + "flatpickr": "^4.6.13", "mysql2": "^3.9.3", "ngx-bootstrap": "^12.0.0", "rxjs": "~7.8.0", @@ -5526,6 +5528,11 @@ "integrity": "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==", "dev": true }, + "node_modules/@yr/monotone-cubic-spline": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@yr/monotone-cubic-spline/-/monotone-cubic-spline-1.0.3.tgz", + "integrity": "sha512-FQXkOta0XBSUPHndIKON2Y9JeQz5ZeMqLYZVVK93FliNBFm7LNMIZmY6FrMEB9XPcDbE2bekMbZD6kzDkxwYjA==" + }, "node_modules/7zip-bin": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/7zip-bin/-/7zip-bin-5.2.0.tgz", @@ -5771,6 +5778,20 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/apexcharts": { + "version": "3.49.0", + "resolved": "https://registry.npmjs.org/apexcharts/-/apexcharts-3.49.0.tgz", + "integrity": "sha512-2T9HnbQFLCuYRPndQLmh+bEQFoz0meUbvASaGgiSKDuYhWcLBodJtIpKql2aOtMx4B/sHrWW0dm90HsW4+h2PQ==", + "dependencies": { + "@yr/monotone-cubic-spline": "^1.0.3", + "svg.draggable.js": "^2.2.2", + "svg.easing.js": "^2.0.0", + "svg.filter.js": "^2.0.2", + "svg.pathmorphing.js": "^0.1.3", + "svg.resize.js": "^1.4.3", + "svg.select.js": "^3.0.1" + } + }, "node_modules/app-builder-bin": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/app-builder-bin/-/app-builder-bin-4.0.0.tgz", @@ -10096,6 +10117,11 @@ "flat": "cli.js" } }, + "node_modules/flatpickr": { + "version": "4.6.13", + "resolved": "https://registry.npmjs.org/flatpickr/-/flatpickr-4.6.13.tgz", + "integrity": "sha512-97PMG/aywoYpB4IvbvUJi0RQi8vearvU0oov1WW3k0WZPBMrTQVqekSX5CjSG/M4Q3i6A/0FKXC7RyAoAUUSPw==" + }, "node_modules/flatted": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", @@ -16167,6 +16193,89 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/svg.draggable.js": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/svg.draggable.js/-/svg.draggable.js-2.2.2.tgz", + "integrity": "sha512-JzNHBc2fLQMzYCZ90KZHN2ohXL0BQJGQimK1kGk6AvSeibuKcIdDX9Kr0dT9+UJ5O8nYA0RB839Lhvk4CY4MZw==", + "dependencies": { + "svg.js": "^2.0.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/svg.easing.js": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/svg.easing.js/-/svg.easing.js-2.0.0.tgz", + "integrity": "sha512-//ctPdJMGy22YoYGV+3HEfHbm6/69LJUTAqI2/5qBvaNHZ9uUFVC82B0Pl299HzgH13rKrBgi4+XyXXyVWWthA==", + "dependencies": { + "svg.js": ">=2.3.x" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/svg.filter.js": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/svg.filter.js/-/svg.filter.js-2.0.2.tgz", + "integrity": "sha512-xkGBwU+dKBzqg5PtilaTb0EYPqPfJ9Q6saVldX+5vCRy31P6TlRCP3U9NxH3HEufkKkpNgdTLBJnmhDHeTqAkw==", + "dependencies": { + "svg.js": "^2.2.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/svg.js": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/svg.js/-/svg.js-2.7.1.tgz", + "integrity": "sha512-ycbxpizEQktk3FYvn/8BH+6/EuWXg7ZpQREJvgacqn46gIddG24tNNe4Son6omdXCnSOaApnpZw6MPCBA1dODA==" + }, + "node_modules/svg.pathmorphing.js": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/svg.pathmorphing.js/-/svg.pathmorphing.js-0.1.3.tgz", + "integrity": "sha512-49HWI9X4XQR/JG1qXkSDV8xViuTLIWm/B/7YuQELV5KMOPtXjiwH4XPJvr/ghEDibmLQ9Oc22dpWpG0vUDDNww==", + "dependencies": { + "svg.js": "^2.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/svg.resize.js": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/svg.resize.js/-/svg.resize.js-1.4.3.tgz", + "integrity": "sha512-9k5sXJuPKp+mVzXNvxz7U0uC9oVMQrrf7cFsETznzUDDm0x8+77dtZkWdMfRlmbkEEYvUn9btKuZ3n41oNA+uw==", + "dependencies": { + "svg.js": "^2.6.5", + "svg.select.js": "^2.1.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/svg.resize.js/node_modules/svg.select.js": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/svg.select.js/-/svg.select.js-2.1.2.tgz", + "integrity": "sha512-tH6ABEyJsAOVAhwcCjF8mw4crjXSI1aa7j2VQR8ZuJ37H2MBUbyeqYr5nEO7sSN3cy9AR9DUwNg0t/962HlDbQ==", + "dependencies": { + "svg.js": "^2.2.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/svg.select.js": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/svg.select.js/-/svg.select.js-3.0.1.tgz", + "integrity": "sha512-h5IS/hKkuVCbKSieR9uQCj9w+zLHoPh+ce19bBYyqF53g6mnPB8sAtIbe1s9dh2S2fCmYX2xel1Ln3PJBbK4kw==", + "dependencies": { + "svg.js": "^2.6.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/symbol-observable": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz", diff --git a/package.json b/package.json index 02813bc..4c5c400 100644 --- a/package.json +++ b/package.json @@ -31,10 +31,12 @@ "@angular/platform-browser-dynamic": "^17.0.0", "@angular/router": "^17.0.0", "angular-star-rating": "^7.0.0", + "apexcharts": "^3.49.0", "axios": "^1.6.8", "bootstrap": "^5.3.3", "date-fns": "^3.6.0", "express": "^4.19.2", + "flatpickr": "^4.6.13", "mysql2": "^3.9.3", "ngx-bootstrap": "^12.0.0", "rxjs": "~7.8.0",