switched to using ngprime multiselect in library and watchlist pages
This commit is contained in:
1 parent
4fbbc4b113
commit
c5883cf6f5
14 files changed
+285
-233
No files matched your search
@@ -5,6 +5,7 @@ import { ActivatedRoute, Event, NavigationEnd, Router } from '@angular/router';
|
||||
import { LibraryQueryParams } from '../../../shared/models/LibraryQueryParams';
|
||||
import { SettingsService } from '../../../core/services/settings.service';
|
||||
import { Settings } from '../../../shared/models/settings.model';
|
||||
import { ValueSetter } from 'date-fns/parse/_lib/Setter';
|
||||
|
||||
declare var $: any;
|
||||
@Component({
|
||||
@@ -25,41 +26,41 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
viewMode: string = 'grid';
|
||||
|
||||
// ? filter
|
||||
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',
|
||||
years: { label: string; value: string }[] = [];
|
||||
genres = [
|
||||
{ label: 'Action & Adventure', value: 'Action & Adventure' },
|
||||
{ label: 'Animation', value: 'Animation' },
|
||||
{ label: 'Comedy', value: 'Comedy' },
|
||||
{ label: 'Crime', value: 'Crime' },
|
||||
{ label: 'Documentary', value: 'Documentary' },
|
||||
{ label: 'Drama', value: 'Drama' },
|
||||
{ label: 'Family', value: 'Family' },
|
||||
{ label: 'Kids', value: 'Kids' },
|
||||
{ label: 'Mystery', value: 'Mystery' },
|
||||
{ label: 'News', value: 'News' },
|
||||
{ label: 'Reality', value: 'Reality' },
|
||||
{ label: 'Sci-Fi & Fantasy', value: 'Sci-Fi & Fantasy' },
|
||||
{ label: 'Soap', value: 'Soap' },
|
||||
{ label: 'Talk', value: 'Talk' },
|
||||
{ label: 'War & Politics', value: 'War & Politics' },
|
||||
{ label: 'Western', value: 'Western' },
|
||||
{ label: 'Action', value: 'Action' },
|
||||
{ label: 'Adventure', value: 'Adventure' },
|
||||
{ label: 'Fantasy', value: 'Fantasy' },
|
||||
{ label: 'History', value: 'History' },
|
||||
{ label: 'Horror', value: 'Horror' },
|
||||
{ label: 'Music', value: 'Music' },
|
||||
{ label: 'Romance', value: 'Romance' },
|
||||
{ label: 'Science Fiction', value: 'Science Fiction' },
|
||||
{ label: 'TV Movie', value: 'TV Movie' },
|
||||
{ label: 'Thriller', value: 'Thriller' },
|
||||
{ label: 'War', value: 'War' },
|
||||
];
|
||||
|
||||
filterCriteria: {
|
||||
title?: string;
|
||||
type: number;
|
||||
years?: number[];
|
||||
years?: string[];
|
||||
genres?: string[];
|
||||
favorit: boolean;
|
||||
watchlist: boolean;
|
||||
@@ -94,29 +95,29 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
// this.getEntries(true);
|
||||
// }
|
||||
// });
|
||||
await this.populateYears();
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
$('#year-select')
|
||||
.select2({
|
||||
placeholder: 'Year(s)...',
|
||||
allowClear: true,
|
||||
closeOnSelect: false,
|
||||
})
|
||||
.on('change', (event: { target: any }) => {
|
||||
this.onYearsChange(event);
|
||||
});
|
||||
|
||||
$('#genre-select')
|
||||
.select2({
|
||||
placeholder: 'Genre(s)...',
|
||||
allowClear: true,
|
||||
closeOnSelect: false,
|
||||
})
|
||||
.on('change', (event: { target: any }) => {
|
||||
this.onGenresChange(event);
|
||||
});
|
||||
// $('#year-select')
|
||||
// .select2({
|
||||
// placeholder: 'Year(s)...',
|
||||
// allowClear: true,
|
||||
// closeOnSelect: false,
|
||||
// })
|
||||
// .on('change', (event: { target: any }) => {
|
||||
// this.onYearsChange(event);
|
||||
// });
|
||||
// $('#genre-select')
|
||||
// .select2({
|
||||
// placeholder: 'Genre(s)...',
|
||||
// allowClear: true,
|
||||
// closeOnSelect: false,
|
||||
// })
|
||||
// .on('change', (event: { target: any }) => {
|
||||
// this.onGenresChange(event);
|
||||
// });
|
||||
// $('#year-select').val(this.filterCriteria.years)
|
||||
// $('#genre-select').val(this.filterCriteria.genres)
|
||||
}
|
||||
|
||||
// ? uses libraryService to get library all entries
|
||||
@@ -124,6 +125,7 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
this.libraryService.getAllEntries(forceFetch).subscribe({
|
||||
next: (entries) => {
|
||||
this.entries = entries.filter((e) => !e.watchlist);
|
||||
this.populateYears();
|
||||
this.getQueryParameters();
|
||||
this.filterEntries();
|
||||
},
|
||||
@@ -158,7 +160,6 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// ! FILTER
|
||||
getQueryParameters() {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
@@ -182,6 +183,10 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
this.filterCriteria.matchAll = params.hasOwnProperty('matchAll')
|
||||
? params['matchAll']
|
||||
: true;
|
||||
|
||||
// this.filterCriteria();
|
||||
// this.setQueryParameters(); // * update url query
|
||||
console.log(this.filterCriteria);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -221,6 +226,8 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
if (this.filterCriteria.matchAll != true) {
|
||||
params.matchAll = this.filterCriteria.matchAll;
|
||||
}
|
||||
// $('#year-select').val([])
|
||||
// console.log( $('#year-select').val());
|
||||
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
@@ -229,24 +236,14 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will generate a bunch of years starting from 1950 to the current year
|
||||
*/
|
||||
populateYears() {
|
||||
const currentYear = new Date().getFullYear();
|
||||
for (let year = currentYear; year >= 1950; year--) {
|
||||
this.years.push(year);
|
||||
}
|
||||
}
|
||||
|
||||
initializeSelect2() {
|
||||
setTimeout(() => {
|
||||
// Ensure that the DOM is fully loaded
|
||||
$('.select2').select2({
|
||||
placeholder: 'Select an option',
|
||||
allowClear: true,
|
||||
});
|
||||
}, 500);
|
||||
this.years = [
|
||||
...new Set(
|
||||
this.entries.map((entry) => new Date(entry.release_date).getFullYear())
|
||||
),
|
||||
]
|
||||
.sort((a, b) => b - a)
|
||||
.map((year) => ({ label: year.toString(), value: year.toString() }));
|
||||
}
|
||||
|
||||
clearFilter() {
|
||||
@@ -283,7 +280,7 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
return false;
|
||||
}
|
||||
|
||||
const year = new Date(entry.release_date).getFullYear();
|
||||
const entryYear = new Date(entry.release_date).getFullYear().toString();
|
||||
// ! Match all criteria logic
|
||||
if (this.filterCriteria.matchAll) {
|
||||
return (
|
||||
@@ -297,7 +294,7 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
)
|
||||
: true) &&
|
||||
(this.filterCriteria.years?.length
|
||||
? this.filterCriteria.years.includes(year)
|
||||
? this.filterCriteria.years.includes(entryYear)
|
||||
: true) &&
|
||||
(this.filterCriteria.favorit ? entry.favorit : true) &&
|
||||
(this.filterCriteria.watchlist ? entry.watchlist : true) &&
|
||||
@@ -316,7 +313,7 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
entry.genres.includes(genre)
|
||||
)) ||
|
||||
(this.filterCriteria.years?.length &&
|
||||
this.filterCriteria.years.includes(year)) ||
|
||||
this.filterCriteria.years.includes(entryYear)) ||
|
||||
(this.filterCriteria.favorit && entry.favorit) ||
|
||||
(this.filterCriteria.watchlist && entry.watchlist)
|
||||
);
|
||||
@@ -375,10 +372,10 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
onYearsChange(event: any) {
|
||||
this.currentPage = 1;
|
||||
|
||||
const selected = $(event.target).val();
|
||||
this.filterCriteria.years = Array.isArray(selected)
|
||||
? selected.map(Number)
|
||||
: [Number(selected)];
|
||||
// const selected = $(event.target).val();
|
||||
// this.filterCriteria.years = Array.isArray(selected)
|
||||
// ? selected.map(Number)
|
||||
// : [Number(selected)];
|
||||
|
||||
this.filterEntries();
|
||||
this.setQueryParameters(); // * update url query
|
||||
@@ -387,8 +384,8 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
|
||||
onGenresChange(event: any) {
|
||||
this.currentPage = 1;
|
||||
|
||||
const selected = $(event.target).val();
|
||||
this.filterCriteria.genres = Array.isArray(selected) ? selected : [];
|
||||
// const selected = $(event.target).val();
|
||||
// this.filterCriteria.genres = Array.isArray(selected) ? selected : [];
|
||||
|
||||
this.filterEntries();
|
||||
this.setQueryParameters(); // * update url query
|
||||
|
||||
Reference in new issue
Block a user