fix: a few library filter bugs

This commit is contained in:
X4Lo committed 2024-05-19 17:36:05 +01:00
1 parent 29d6e3f503
commit 6c30218a51
2 files changed
+14 -22

No files matched your search

@@ -50,7 +50,7 @@
<!-- Match All Criteria --> <!-- Match All Criteria -->
<div class="form-check form-switch"> <div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="matchAllSwitch" <input class="form-check-input" type="checkbox" role="switch" id="matchAllSwitch"
[(ngModel)]="filterCriteria.matchAll" (ngModelChange)="onFilterChange()"> [(ngModel)]="filterCriteria.matchAll" (click)="onFilterChange()" >
<label class="form-check-label" for="matchAllSwitch">Match All Criteria</label> <label class="form-check-label" for="matchAllSwitch">Match All Criteria</label>
</div> </div>
@@ -102,7 +102,7 @@
<div class="dataTables_info" role="status" aria-live="polite"> <div class="dataTables_info" role="status" aria-live="polite">
Total entries {{entriesCount}} Total entries {{entriesCount}}
</div> </div>
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0"> <div class="pagination-container d-flex justify-content-end" *ngIf="maxPage > 1 && entries.length != 0">
<ul class="pagination pagination-sm"> <ul class="pagination pagination-sm">
<li class="page-item" [class.disabled]="currentPage === 1"> <li class="page-item" [class.disabled]="currentPage === 1">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a> <a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
@@ -125,7 +125,7 @@
<!-- Pagination --> <!-- Pagination -->
<div class="pagination-container d-flex justify-content-end" *ngIf="maxPage != 1 && entries.length != 0"> <div class="pagination-container d-flex justify-content-end" *ngIf="maxPage > 1 && entries.length != 0">
<ul class="pagination pagination-sm"> <ul class="pagination pagination-sm">
<li class="page-item" [class.disabled]="currentPage === 1"> <li class="page-item" [class.disabled]="currentPage === 1">
<a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a> <a class="page-link" href="javascript:;" (click)="goToPage(currentPage - 1)">Previous</a>
@@ -105,6 +105,7 @@ export class LibraryComponent implements OnInit, AfterViewInit {
}); });
} }
// ! FILTER
getQueryParameters() { getQueryParameters() {
this.route.queryParams.subscribe((params) => { this.route.queryParams.subscribe((params) => {
this.currentPage = params['page'] ? parseInt(params['page'], 10) : 1; this.currentPage = params['page'] ? parseInt(params['page'], 10) : 1;
@@ -133,46 +134,38 @@ export class LibraryComponent implements OnInit, AfterViewInit {
setQueryParameters() { setQueryParameters() {
let params = { page: this.currentPage } as LibraryQueryParams; let params = { page: this.currentPage } as LibraryQueryParams;
// ? title
if (this.filterCriteria.title?.trim() != '') { if (this.filterCriteria.title?.trim() != '') {
params.title = this.filterCriteria.title?.trim(); params.title = this.filterCriteria.title?.trim();
} else {
delete params.title;
} }
// ? years
if (this.filterCriteria.years?.length) { if (this.filterCriteria.years?.length) {
params.years = this.filterCriteria.years.join(','); params.years = this.filterCriteria.years.join(',');
} else {
delete params.years;
} }
// ? genres
if (this.filterCriteria.genres?.length) { if (this.filterCriteria.genres?.length) {
params.genres = this.filterCriteria.genres.join(','); params.genres = this.filterCriteria.genres.join(',');
} else {
delete params.genres;
} }
// ? type
if (this.filterCriteria.type != 0) { if (this.filterCriteria.type != 0) {
params.type = this.filterCriteria.type; params.type = this.filterCriteria.type;
} else {
delete params.type;
} }
// ? favorit
if (this.filterCriteria.favorit != false) { if (this.filterCriteria.favorit != false) {
params.favorit = this.filterCriteria.favorit; params.favorit = this.filterCriteria.favorit;
} else {
delete params.favorit;
} }
// ? hidden
if (this.filterCriteria.hidden != false) { if (this.filterCriteria.hidden != false) {
params.hidden = this.filterCriteria.hidden; params.hidden = this.filterCriteria.hidden;
} else {
delete params.hidden;
} }
// ? matchAll
if (this.filterCriteria.matchAll != true) { if (this.filterCriteria.matchAll != true) {
params.matchAll = this.filterCriteria.matchAll; params.matchAll = this.filterCriteria.matchAll;
} else {
delete params.matchAll;
} }
this.router.navigate([], { this.router.navigate([], {
@@ -182,7 +175,6 @@ export class LibraryComponent implements OnInit, AfterViewInit {
}); });
} }
// ! FILTER
ngAfterViewInit() { ngAfterViewInit() {
$('#year-select') $('#year-select')
.select2({ .select2({
@@ -244,14 +236,14 @@ export class LibraryComponent implements OnInit, AfterViewInit {
const formattedTitle = const formattedTitle =
this.filterCriteria.title?.toLowerCase().trim() || ''; this.filterCriteria.title?.toLowerCase().trim() || '';
temp = await this.entries.filter((entry) => { temp = await this.entries.filter((entry) => {
// Type check // * Type check
let filterType = this.filterCriteria.type - 1 == 0 ? false : true; let filterType = this.filterCriteria.type - 1 == 0 ? false : true;
if (this.filterCriteria.type != 0 && filterType != entry.is_tvseries) { if (this.filterCriteria.type != 0 && filterType != entry.is_tvseries) {
return false; // Skip entry if the type does not match, unless type is 'all' (0) return false; // Skip entry if the type does not match, unless type is 'all' (0)
} }
// Hidden check // * Hidden check
// skip hidden if show hidden is not check // ? skip hidden if show hidden is not checked
if (!this.filterCriteria.hidden && entry.hidden) { if (!this.filterCriteria.hidden && entry.hidden) {
return false; return false;
} }