add: unified component for watchlist/favorit pages

This commit is contained in:
X4Lo committed 2024-06-23 17:00:46 +01:00
1 parent 8d9a6a5da1
commit ef444f211d
21 files changed
+709 -310

No files matched your search

+9 -4
View File
@@ -4,9 +4,8 @@ import { HomeComponent } from './features/home/home.component';
import { SearchPageComponent } from './features/discover/search-page/search-page.component'; import { SearchPageComponent } from './features/discover/search-page/search-page.component';
import { TrendingComponent } from './features/discover/trending/trending.component'; import { TrendingComponent } from './features/discover/trending/trending.component';
import { PopularComponent } from './features/discover/popular/popular.component'; import { PopularComponent } from './features/discover/popular/popular.component';
import { LibraryPageComponent } from './features/library/library-page/library-page.component'; import { FavoritComponent } from './features/library/favorit-page/favorit.component';
import { FavoritComponent } from './features/favorit/favorit.component'; import { WatchlistComponent } from './features/library/watchlist-page/watchlist.component';
import { WatchlistComponent } from './features/watchlist/watchlist.component';
const routes: Routes = [ const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' }, { path: '', redirectTo: '/home', pathMatch: 'full' },
@@ -15,7 +14,13 @@ const routes: Routes = [
{ path: 'popular', component: PopularComponent }, { path: 'popular', component: PopularComponent },
{ path: 'trending', component: TrendingComponent }, { path: 'trending', component: TrendingComponent },
{ path: 'library', component: LibraryPageComponent }, {
path: 'library',
loadChildren: () =>
import('./features/library/library.module').then(
(m) => m.LibraryModule
),
},
{ path: 'favorit', component: FavoritComponent }, { path: 'favorit', component: FavoritComponent },
{ path: 'watchlist', component: WatchlistComponent }, { path: 'watchlist', component: WatchlistComponent },
{ {
-17
View File
@@ -15,17 +15,9 @@ import { HomeComponent } from './features/home/home.component';
import { PopularComponent } from './features/discover/popular/popular.component'; import { PopularComponent } from './features/discover/popular/popular.component';
import { TrendingComponent } from './features/discover/trending/trending.component'; import { TrendingComponent } from './features/discover/trending/trending.component';
import { SearchPageComponent } from './features/discover/search-page/search-page.component'; import { SearchPageComponent } from './features/discover/search-page/search-page.component';
import { LibraryPageComponent } from './features/library/library-page/library-page.component';
import { DynamicEntryListComponent } from './shared/components/lists/dynamic-entry-list/dynamic-entry-list.component';
import { NotificationPopupComponent } from './shared/components/notification-popup/notification-popup.component';
import { MainCardComponent } from './shared/components/cards/main-card/main-card.component';
import { FavoritComponent } from './features/favorit/favorit.component';
import { WatchlistComponent } from './features/watchlist/watchlist.component';
import { SharedModule } from './shared/shared.module'; import { SharedModule } from './shared/shared.module';
import { ToastrModule } from 'ngx-toastr'; import { ToastrModule } from 'ngx-toastr';
import { LibraryTableComponent } from './features/library/library-table/library-table.component';
import { LibraryTableLineComponent } from './features/library/library-table-line/library-table-line.component';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -55,16 +47,7 @@ import { LibraryTableLineComponent } from './features/library/library-table-line
PopularComponent, PopularComponent,
TrendingComponent, TrendingComponent,
SearchPageComponent, SearchPageComponent,
LibraryPageComponent,
LibraryTableComponent,
LibraryTableLineComponent,
FavoritComponent,
WatchlistComponent,
// ? temp shared components
MainCardComponent,
DynamicEntryListComponent,
NotificationPopupComponent,
], ],
providers: [DatePipe], providers: [DatePipe],
bootstrap: [AppComponent], bootstrap: [AppComponent],
@@ -1,74 +0,0 @@
<!--breadcrumb-->
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
<div class="breadcrumb-title pe-3">Favorit</div>
<div class="ps-3">
<nav aria-label="breadcrumb">
<ol class="breadcrumb mb-0 p-0">
<li class="breadcrumb-item">
<a href="javascript:;">
</a>
</li>
<li class="breadcrumb-item active" aria-current="page">Favorit</li>
</ol>
</nav>
</div>
<div class="ms-auto">
<div class="input-group custom-group">
<div class="input-group-text">Show</div>
<select class="form-select" id="single-select-field" data-placeholder="Choose one thing" style="max-width: 150px;"
[(ngModel)]="pageSize" (change)="setPageSize($event)">
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="250">250</option>
<option value="500">500</option>
<option value="1000">1000</option>
</select>
<div class="btn-group">
<button type="button" class="btn btn-outline-dark left-btn" [class.active]="entryType === 0"
(click)="setEntryType(0)">All</button>
<button type="button" class="btn btn-outline-dark" [class.active]="entryType === 1"
(click)="setEntryType(1)">Movies</button>
<button type="button" class="btn btn-outline-dark right-btn" [class.active]="entryType === 2"
(click)="setEntryType(2)">TV-Series</button>
</div>
</div>
</div>
</div>
<!--end breadcrumb-->
<!-- Pagination -->
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0">
<ul class="pagination pagination-sm">
<li class="page-item" [class.disabled]="currentPage === 1">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
</li>
<!-- Dynamically generate page numbers -->
<li class="page-item" *ngFor="let page of pageNumbers" [class.active]="currentPage === page">
<a class="page-link" href="javascript:;" (click)="goToPage(page)">{{ page }}</a>
</li>
<li class="page-item" [class.disabled]="currentPage == maxPage">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage + 1)">Next</a>
</li>
</ul>
</div>
<app-dynamic-entry-list [entries]="entriesToShow"></app-dynamic-entry-list>
<!-- Pagination -->
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0">
<ul class="pagination pagination-sm">
<li class="page-item" [class.disabled]="currentPage === 1">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
</li>
<!-- Dynamically generate page numbers -->
<li class="page-item" *ngFor="let page of pageNumbers" [class.active]="currentPage === page">
<a class="page-link" href="javascript:;" (click)="goToPage(page)">{{ page }}</a>
</li>
<li class="page-item" [class.disabled]="currentPage == maxPage">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage + 1)">Next</a>
</li>
</ul>
</div>
@@ -1,3 +1,4 @@
/* ! buttons style */
.custom-group .form-select { .custom-group .form-select {
border-top-right-radius: 0; border-top-right-radius: 0;
border-bottom-right-radius: 0; border-bottom-right-radius: 0;
@@ -33,4 +34,22 @@
#single-select-field { #single-select-field {
max-width: 120px; max-width: 120px;
} }
.align-items-baseline {
align-items: baseline;
}
/* ! filter switches style */
.form-check-label {
margin-bottom: 0;
}
a.clear-filter-link {
display: inline-block;
padding: 0.375rem 0;
}
.filter-switches {
margin-left: auto;
}
@@ -0,0 +1,127 @@
<!--breadcrumb-->
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
<div class="breadcrumb-title pe-3">Library</div>
<div class="ps-3">
<nav aria-label="breadcrumb">
<ol class="breadcrumb mb-0 p-0">
<li class="breadcrumb-item">
<a href="javascript:;">
</a>
</li>
<li class="breadcrumb-item active" aria-current="page">Watchlist</li>
</ol>
</nav>
</div>
</div>
<!--end breadcrumb-->
<div class="d-flex align-items-baseline gap-3 flex-wrap">
<div class="product-count d-flex align-items-center gap-3 gap-lg-4 mb-4 fw-medium flex-wrap font-text1">
<a href="javascript:;" (click)="onEntryTypeChange(0)"><span class="me-1">All</span><span
class="text-secondary">({{entries.length}})</span></a>
<a href="javascript:;" (click)="onEntryTypeChange(1)"><span class="me-1">Movies</span><span
class="text-secondary">({{moviesCount()}})</span></a>
<a href="javascript:;" (click)="onEntryTypeChange(2)"><span class="me-1">Tv-Series</span><span
class="text-secondary">({{seriesCount()}})</span></a>
</div>
<!-- filter switches -->
<div class="d-flex align-items-baseline gap-3 flex-wrap filter-switches">
<!-- Match All Criteria -->
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="matchAllSwitch"
[(ngModel)]="filterCriteria.matchAll" (click)="onFilterChange()">
<label class="form-check-label" for="matchAllSwitch">Match All Criteria</label>
</div>
<!-- Clear Filter Link -->
<a class="clear-filter-link" (click)="clearFilter()">Clear Filter</a>
</div>
<div class="button-container justify-content-end align-items-end">
<button class="btn btn-link align-content-center justify-content-end p-0" *ngIf="viewMode == 'grid'"
(click)="setViewMode('table')">
<span class="material-symbols-outlined link-primary">
table_rows_narrow
</span>
</button>
<button class="btn btn-link align-items-center m-0 p-0" *ngIf="viewMode == 'table'" (click)="setViewMode('grid')">
<span class="material-symbols-outlined link-primary">
grid_on
</span>
</button>
</div>
</div>
<div class="containder">
<div class="row">
<!-- Search Input for Title -->
<div class="col-sm-4">
<div class="input-group">
<span class="input-group-text material-icons-outlined">search</span>
<input class="form-control" type="search" placeholder="Title..." [(ngModel)]="filterCriteria.title"
(ngModelChange)="onFilterChange()">
</div>
</div>
<!-- Year Selector -->
<div class="col-sm-4" [class.visible]="select2Visible" [class.invisible]="!select2Visible">
<div class="d-flex justify-content-start align-items-center">
<select class="form-control select2" id="year-select2" multiple (change)="onYearsChange($event)">
<option *ngFor="let year of years" [value]="year">{{ year }}</option>
</select>
</div>
</div>
<!-- Genre Selector -->
<div class="col-sm-4" [class.visible]="select2Visible" [class.invisible]="!select2Visible">
<div class="d-flex justify-content-start align-items-center">
<select class="form-control select2" id="genre-select2" multiple (change)="onGenresChange($event)">
<option *ngFor="let genre of genres" [value]="genre">{{ genre }}</option>
</select>
</div>
</div>
</div>
</div>
<!-- filter end -->
<br>
<!-- Pagination -->
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0">
<ul class="pagination pagination-sm">
<li class="page-item" [class.disabled]="currentPage === 1">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
</li>
<!-- Dynamically generate page numbers -->
<li class="page-item" *ngFor="let page of pageNumbers" [class.active]="currentPage === page">
<a class="page-link" href="javascript:;" (click)="goToPage(page)">{{ page }}</a>
</li>
<li class="page-item" [class.disabled]="currentPage == maxPage">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage + 1)">Next</a>
</li>
</ul>
</div>
<app-library-table *ngIf="viewMode == 'table'" [entries]="entriesToShow"
(onEntryRemove)="entryRemoved($event)"></app-library-table>
<app-dynamic-entry-list *ngIf="viewMode == 'grid'" [entries]="entriesToShow"
(onEntryRemove)="entryRemoved($event)"></app-dynamic-entry-list>
<!-- Pagination -->
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0">
<ul class=" pagination pagination-sm">
<li class="page-item" [class.disabled]="currentPage === 1">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
</li>
<!-- Dynamically generate page numbers -->
<li class="page-item" *ngFor="let page of pageNumbers" [class.active]="currentPage === page">
<a class="page-link" href="javascript:;" (click)="goToPage(page)">{{ page }}</a>
</li>
<li class="page-item" [class.disabled]="currentPage == maxPage">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage + 1)">Next</a>
</li>
</ul>
</div>
@@ -0,0 +1,28 @@
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { EntriesDisplayComponent } from './entries-display.component';
describe('EntriesDisplayComponent', () => {
let component: EntriesDisplayComponent;
let fixture: ComponentFixture<EntriesDisplayComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EntriesDisplayComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EntriesDisplayComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,431 @@
import {
AfterViewInit,
Component,
Input,
OnDestroy,
OnInit,
} from '@angular/core';
import { Entry } from '../../../shared/models/entry.model';
import { LibraryService } from '../../../core/services/library.service';
import { ToastrService } from 'ngx-toastr';
import { SettingsService } from '../../../core/services/settings.service';
import { Settings } from '../../../shared/models/settings.model';
import { LibraryQueryParams } from '../../../shared/models/LibraryQueryParams';
import { ActivatedRoute, Router } from '@angular/router';
declare var $: any;
@Component({
selector: 'app-entries-display',
templateUrl: './entries-display.component.html',
styleUrls: ['./entries-display.component.css'],
})
export class EntriesDisplayComponent
implements OnInit, AfterViewInit, OnDestroy
{
@Input() displayType: string = 'favorit';
entryType: number = 0;
entries: Entry[] = [];
entriesToShow: Entry[] = [];
entriesCount: number = 0;
maxPage: number = 10;
currentPage: number = 1;
pageSize: number = 10;
viewMode: string = 'grid';
// ? filter
select2Visible: boolean = false; // temp fix to select flashing
years: number[] = [];
genres: string[] = [
'Action & Adventure',
'Animation',
'Comedy',
'Crime',
'Documentary',
'Drama',
'Family',
'Kids',
'Mystery',
'News',
'Reality',
'Sci-Fi & Fantasy',
'Soap',
'Talk',
'War & Politics',
'Western',
'Action',
'Adventure',
'Fantasy',
'History',
'Horror',
'Music',
'Romance',
'Science Fiction',
'TV Movie',
'Thriller',
'War',
];
filterCriteria: {
title?: string;
type: number;
years?: number[];
genres?: string[];
matchAll: boolean;
} = {
title: '',
type: 0,
years: [],
genres: [],
matchAll: true,
};
constructor(
private router: Router,
private route: ActivatedRoute,
private libraryService: LibraryService,
private settingsService: SettingsService,
private toastr: ToastrService
) {}
async ngOnInit() {
this.getDefaultViewMode();
this.pageSize = this.getDefaultPageSize();
this.getEntries();
await this.populateYears();
}
ngAfterViewInit() {
setTimeout(() => {
$('#year-select2')
.select2({
placeholder: 'Year(s)...',
allowClear: true,
closeOnSelect: false,
})
.on('change', (event: { target: any }) => {
this.onYearsChange(event);
});
$('#genre-select2')
.select2({
placeholder: 'Genre(s)...',
allowClear: true,
closeOnSelect: false,
})
.on('change', (event: { target: any }) => {
this.onGenresChange(event);
});
this.select2Visible = true;
}, 0);
}
ngOnDestroy() {
if ($('#year-select2').data('select2')) {
$('#year-select2').select2('destroy');
}
if ($('#genre-select2').data('select2')) {
$('#genre-select2').select2('destroy');
}
}
// uses libraryService to get library all content
getEntries(forceFetch: boolean = false) {
this.libraryService.getAllEntries(forceFetch).subscribe({
next: (entries) => {
if (this.displayType == 'favorit') {
this.entries = entries.filter((e) => e.favorit);
} else if (this.displayType == 'watchlist') {
this.entries = entries.filter((e) => e.watchlist);
}
this.getQueryParameters();
this.filterEntries();
},
error: (error) => {
console.log(`Couldn't get entries.`, error);
this.toastr.success(
'Error',
`Couldn't get ${this.displayType} items.`,
{
tapToDismiss: true,
progressBar: true,
progressAnimation: 'increasing',
}
);
},
});
}
// ! FILTER
async filterEntries() {
var temp = [] as Entry[];
const formattedTitle =
this.filterCriteria.title?.toLowerCase().trim() || '';
temp = await this.entries.filter((entry) => {
// * Type check
let filterType = this.filterCriteria.type - 1 == 0 ? false : true;
if (this.filterCriteria.type != 0 && filterType != entry.is_tvseries) {
return false; // Skip entry if the type does not match, unless type is 'all' (0)
}
const year = new Date(entry.release_date).getFullYear();
// ! Match all criteria logic
if (this.filterCriteria.matchAll) {
return (
(formattedTitle
? entry.title.toLowerCase().includes(formattedTitle) ||
entry.original_title.toLowerCase().includes(formattedTitle)
: true) &&
(this.filterCriteria.genres?.length
? this.filterCriteria.genres.every((genre) =>
entry.genres.includes(genre)
)
: true) &&
(this.filterCriteria.years?.length
? this.filterCriteria.years.includes(year)
: true)
);
}
// ! Match at least one criteria logic
return (
(formattedTitle
? entry.title.toLowerCase().includes(formattedTitle) ||
entry.original_title.toLowerCase().includes(formattedTitle)
: true) ||
(this.filterCriteria.genres?.length &&
this.filterCriteria.genres.some((genre) =>
entry.genres.includes(genre)
)) ||
(this.filterCriteria.years?.length &&
this.filterCriteria.years.includes(year))
);
});
// ? sort filter
temp = await this.sortEntries(temp);
this.entriesCount = temp.length;
this.maxPage = Math.ceil(this.entriesCount / this.pageSize);
if (this.currentPage > this.maxPage) this.currentPage = this.maxPage; // fix for when 1 entry in the last page is removed
const startIndex = (this.currentPage - 1) * this.pageSize;
const endIndex = startIndex + this.pageSize;
this.entriesToShow = temp.slice(startIndex, endIndex);
}
clearFilter() {
this.filterCriteria = {
title: '',
type: 0,
years: [],
genres: [],
matchAll: true,
};
this.setQueryParameters();
this.filterEntries();
}
sortEntries(entries: Entry[]) {
return entries.sort(
(a, b) =>
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
);
}
getQueryParameters() {
this.route.queryParams.subscribe((params) => {
this.currentPage = params['page'] ? parseInt(params['page'], 10) : 1;
this.filterCriteria.title = params['title'] || '';
this.filterCriteria.years = params['years']
? params['years'].split(',')
: [];
this.filterCriteria.genres = params['genres']
? params['genres'].split(',')
: [];
this.filterCriteria.type = params.hasOwnProperty('type')
? params['type']
: 0;
});
}
setQueryParameters() {
let params = { page: this.currentPage } as LibraryQueryParams;
// ? title
if (this.filterCriteria.title?.trim() != '') {
params.title = this.filterCriteria.title?.trim();
}
// ? years
if (this.filterCriteria.years?.length) {
params.years = this.filterCriteria.years.join(',');
}
// ? genres
if (this.filterCriteria.genres?.length) {
params.genres = this.filterCriteria.genres.join(',');
}
// ? type
if (this.filterCriteria.type != 0) {
params.type = this.filterCriteria.type;
}
this.router.navigate([], {
relativeTo: this.route,
queryParams: params,
queryParamsHandling: '',
});
}
populateYears() {
const currentYear = new Date().getFullYear();
for (let year = currentYear; year >= 1950; year--) {
this.years.push(year);
}
}
// + FILTER END
getDefaultViewMode() {
this.settingsService.getSettings().subscribe({
next: (s) => {
if (this.displayType == 'favorit') {
this.viewMode = s.favoritViewMode || 'grid';
} else if (this.displayType == 'watchlist') {
this.viewMode = s.watchlistViewMode || 'grid';
}
},
error: (error) => {
console.log(`Couldn't get settings information, `, error);
},
});
}
setViewMode(mode: string) {
this.viewMode = mode;
let newSettings = {} as Settings;
if (this.displayType == 'favorit') {
newSettings = { favoritViewMode: this.viewMode } as Settings;
} else if (this.displayType == 'watchlist') {
newSettings = { watchlistViewMode: this.viewMode } as Settings;
}
this.settingsService.updateSettings(newSettings).subscribe({
next: (s) => {
// ? view mode updated
},
error: (error) => {
// error updating view mode
},
});
}
// ! calculated fields
moviesCount() {
return this.entries.filter((e) => !e.is_tvseries).length;
}
seriesCount() {
return this.entries.filter((e) => e.is_tvseries).length;
}
hiddenCount() {
return this.entries.filter((e) => e.hidden).length;
}
// ! events
entryRemoved(event: Event) {
this.entries = this.entries.filter(
(e) => e.id.toString() != event.toString()
);
this.pageSize = this.getDefaultPageSize();
this.filterEntries();
}
// * filter events
onYearsChange(event: any) {
this.currentPage = 1;
const selected = $(event.target).val();
this.filterCriteria.years = Array.isArray(selected)
? selected.map(Number)
: [Number(selected)];
this.filterEntries();
this.setQueryParameters(); // * update url query
}
onGenresChange(event: any) {
this.currentPage = 1;
const selected = $(event.target).val();
this.filterCriteria.genres = Array.isArray(selected) ? selected : [];
this.filterEntries();
this.setQueryParameters(); // * update url query
}
onFilterChange() {
this.currentPage = 1;
this.filterEntries();
this.setQueryParameters(); // * update url query
}
onEntryTypeChange(entryType: number) {
this.filterCriteria.type = entryType;
this.currentPage = 1;
this.filterEntries();
this.setQueryParameters(); // * update url query
}
// + FILTER EVENTS END
// + EVENTS END
// ! pagination
setPageSize(event: any) {
this.pageSize = event.target.value;
this.filterEntries();
}
getDefaultPageSize() {
// TODO get default page size from settings service
return 54;
}
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
);
}
}
@@ -0,0 +1 @@
<app-entries-display [displayType]="'favorit'"></app-entries-display>
@@ -1,6 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Entry } from '../../shared/models/entry.model'; import { Entry } from '../../../shared/models/entry.model';
import { LibraryService } from '../../core/services/library.service'; import { LibraryService } from '../../../core/services/library.service';
@Component({ @Component({
selector: 'app-favorit', selector: 'app-favorit',
@@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LibraryPageComponent } from './library-page/library-page.component';
// ! /library
const routes: Routes = [
{
path: '',
component: LibraryPageComponent,
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class LibraryRoutingModule {}
@@ -0,0 +1,39 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule } from '../../shared/shared.module';
import { DragDropModule } from '@angular/cdk/drag-drop';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { LibraryPageComponent } from './library-page/library-page.component';
import { LibraryTableComponent } from './library-table/library-table.component';
import { LibraryTableLineComponent } from './library-table-line/library-table-line.component';
import { LibraryRoutingModule } from './library-routing.module';
import { WatchlistComponent } from './watchlist-page/watchlist.component';
import { EntriesDisplayComponent } from './entries-display/entries-display.component';
import { FavoritComponent } from './favorit-page/favorit.component';
@NgModule({
imports: [
CommonModule,
SharedModule,
FormsModule,
ReactiveFormsModule,
LibraryRoutingModule,
DragDropModule,
],
declarations: [
EntriesDisplayComponent,
LibraryPageComponent,
WatchlistComponent,
FavoritComponent,
LibraryTableComponent,
LibraryTableLineComponent,
],
exports: [],
})
export class LibraryModule {}
Whitespace-only changes.
@@ -0,0 +1 @@
<app-entries-display displayType="watchlist"></app-entries-display>
@@ -0,0 +1,17 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-watchlist',
templateUrl: './watchlist.component.html',
styleUrl: './watchlist.component.css',
})
export class WatchlistComponent implements OnInit{
constructor(
) {}
async ngOnInit() {
}
}
@@ -1,61 +0,0 @@
<!--breadcrumb-->
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
<div class="breadcrumb-title pe-3">Library</div>
<div class="ps-3">
<nav aria-label="breadcrumb">
<ol class="breadcrumb mb-0 p-0">
<li class="breadcrumb-item">
<a href="javascript:;">
</a>
</li>
<li class="breadcrumb-item active" aria-current="page">Watchlist</li>
</ol>
</nav>
</div>
</div>
<!--end breadcrumb-->
<div class="d-flex align-items-baseline gap-3">
<div class="product-count d-flex align-items-center gap-3 gap-lg-4 mb-4 fw-medium flex-wrap font-text1">
<a href="javascript:;" (click)="onEntryTypeChange(0)"><span class="me-1">All</span><span
class="text-secondary">({{entries.length}})</span></a>
<a href="javascript:;" (click)="onEntryTypeChange(1)"><span class="me-1">Movies</span><span
class="text-secondary">({{moviesCount()}})</span></a>
<a href="javascript:;" (click)="onEntryTypeChange(2)"><span class="me-1">Tv-Series</span><span
class="text-secondary">({{seriesCount()}})</span></a>
</div>
</div>
<!-- Pagination -->
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0">
<ul class="pagination pagination-sm">
<li class="page-item" [class.disabled]="currentPage === 1">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
</li>
<!-- Dynamically generate page numbers -->
<li class="page-item" *ngFor="let page of pageNumbers" [class.active]="currentPage === page">
<a class="page-link" href="javascript:;" (click)="goToPage(page)">{{ page }}</a>
</li>
<li class="page-item" [class.disabled]="currentPage == maxPage">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage + 1)">Next</a>
</li>
</ul>
</div>
<app-dynamic-entry-list [entries]="entriesToShow" (removedEvent)="entryRemoved($event)"></app-dynamic-entry-list>
<!-- Pagination -->
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0">
<ul class=" pagination pagination-sm">
<li class="page-item" [class.disabled]="currentPage === 1">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
</li>
<!-- Dynamically generate page numbers -->
<li class="page-item" *ngFor="let page of pageNumbers" [class.active]="currentPage === page">
<a class="page-link" href="javascript:;" (click)="goToPage(page)">{{ page }}</a>
</li>
<li class="page-item" [class.disabled]="currentPage == maxPage">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage + 1)">Next</a>
</li>
</ul>
</div>
@@ -1,151 +0,0 @@
import { Component } from '@angular/core';
import { Entry } from '../../shared/models/entry.model';
import { LibraryService } from '../../core/services/library.service';
import { ToastrService } from 'ngx-toastr';
@Component({
selector: 'app-watchlist',
templateUrl: './watchlist.component.html',
styleUrl: './watchlist.component.css',
})
export class WatchlistComponent {
entryType: number = 0;
entries: Entry[] = [];
entriesToShow: Entry[] = [];
entriesCount: number = 0;
maxPage: number = 10;
currentPage: number = 1;
pageSize: number = 10;
constructor(
private libraryService: LibraryService,
private toastr: ToastrService
) {}
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.watchlist);
this.filterEntries();
},
error: (error) => {
console.log(`Couldn't get entries.`, error);
this.toastr.success('Error', "Couldn't get watchlist items.", {
tapToDismiss: true,
progressBar: true,
progressAnimation: 'increasing',
});
},
});
}
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;
}
temp = await this.sortEntries(temp);
this.entriesCount = temp.length;
this.maxPage = Math.ceil(this.entriesCount / this.pageSize);
if (this.currentPage > this.maxPage) this.currentPage = this.maxPage; // fix for when 1 entry in the last page is removed
const startIndex = (this.currentPage - 1) * this.pageSize;
const endIndex = startIndex + this.pageSize;
this.entriesToShow = temp.slice(startIndex, endIndex);
}
sortEntries(entries: Entry[]) {
return entries.sort(
(a, b) =>
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
);
}
// ! calculated fields
moviesCount() {
return this.entries.filter((e) => !e.is_tvseries).length;
}
seriesCount() {
return this.entries.filter((e) => e.is_tvseries).length;
}
hiddenCount() {
return this.entries.filter((e) => e.hidden).length;
}
// ! events
entryRemoved(event: Event) {
this.entries = this.entries.filter(
(e) => e.id.toString() != event.toString()
);
this.pageSize = this.getDefaultPageSize();
this.filterEntries();
}
onEntryTypeChange(entryType: number) {
this.entryType = entryType;
this.currentPage = 1;
this.filterEntries();
}
// ! pagination
setPageSize(event: any) {
this.pageSize = event.target.value;
this.filterEntries();
}
getDefaultPageSize() {
// TODO get default page size from settings service
return 54;
}
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
);
}
}
@@ -5,4 +5,10 @@ export interface Settings {
frontPort: number; frontPort: number;
backPort: number; backPort: number;
portableMode: string; portableMode: string;
libraryViewMode: string;
favoritViewMode: string;
watchlistViewMode: string;
CollectionsViewMode: string;
CollectionItemsViewMode: string;
} }
+11
View File
@@ -14,6 +14,9 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CollectionEditModalComponent } from '../features/collections/user-collection-info/collection-edit-modal/collection-edit-modal.component'; import { CollectionEditModalComponent } from '../features/collections/user-collection-info/collection-edit-modal/collection-edit-modal.component';
import { FloatFormatPipe } from './pipes/float-format/float-format.pipe'; import { FloatFormatPipe } from './pipes/float-format/float-format.pipe';
import { EpisodeSeenModalComponent } from './components/modals/episode-seen-modal/episode-seen-modal.component'; import { EpisodeSeenModalComponent } from './components/modals/episode-seen-modal/episode-seen-modal.component';
import { MainCardComponent } from './components/cards/main-card/main-card.component';
import { DynamicEntryListComponent } from './components/lists/dynamic-entry-list/dynamic-entry-list.component';
import { NotificationPopupComponent } from './components/notification-popup/notification-popup.component';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -34,6 +37,10 @@ import { EpisodeSeenModalComponent } from './components/modals/episode-seen-moda
CollectionEditModalComponent, CollectionEditModalComponent,
ConfirmModalComponent, ConfirmModalComponent,
EpisodeSeenModalComponent, EpisodeSeenModalComponent,
MainCardComponent,
DynamicEntryListComponent,
NotificationPopupComponent,
], ],
exports: [ exports: [
// * pipes // * pipes
@@ -46,6 +53,10 @@ import { EpisodeSeenModalComponent } from './components/modals/episode-seen-moda
SeenModalComponent, SeenModalComponent,
ConfirmModalComponent, ConfirmModalComponent,
RatingModule, RatingModule,
MainCardComponent,
DynamicEntryListComponent,
NotificationPopupComponent,
], ],
}) })
export class SharedModule {} export class SharedModule {}