add library page component
This commit is contained in:
1 parent
f0970a07e8
commit
6c8a60656d
4 files changed
+143
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Entry } from '../../../shared/models/entry.model';
|
||||
import { LibraryService } from '../../../core/services/library.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-library',
|
||||
templateUrl: './library.component.html',
|
||||
styleUrls: ['./library.component.css'],
|
||||
})
|
||||
export class LibraryComponent {
|
||||
entryType: number = 0;
|
||||
|
||||
allEntries: Entry[] = [];
|
||||
|
||||
entries: Entry[] = [];
|
||||
|
||||
currentPage: number = 1;
|
||||
pageSize: number = 20;
|
||||
|
||||
constructor(private libraryService: LibraryService) {}
|
||||
|
||||
ngOnInit() {
|
||||
console.log('initing');
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
// uses libraryService to get library all content
|
||||
fetchEntries() {
|
||||
this.libraryService.getAllEntries().subscribe({
|
||||
next: (entries) => {
|
||||
this.allEntries = entries;
|
||||
this.filterEntries();
|
||||
},
|
||||
error: (error) => {
|
||||
// Handle any errors, possibly informing the user.
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
filterEntries() {
|
||||
var temp = [] as Entry[];
|
||||
|
||||
// ? type filter
|
||||
if (this.entryType != 0) {
|
||||
this.allEntries.forEach((entry) => {
|
||||
if (Boolean(this.entryType - 1) == entry.is_tvseries) temp.push(entry);
|
||||
});
|
||||
} else {
|
||||
temp = this.allEntries;
|
||||
}
|
||||
|
||||
// ? title search
|
||||
// let len = temp.length;
|
||||
// for (let i = 0; i < len; i++) {
|
||||
// if (!temp[i].title.toLocaleLowerCase().includes('od')) {
|
||||
// temp.splice(i);
|
||||
// len--;
|
||||
// }
|
||||
// }
|
||||
|
||||
const startIndex = (this.currentPage - 1) * this.pageSize;
|
||||
const endIndex = startIndex + this.pageSize;
|
||||
|
||||
this.entries = temp.slice(startIndex, endIndex);
|
||||
}
|
||||
|
||||
// ? pagination
|
||||
goToPage(page: number) {
|
||||
this.currentPage = page;
|
||||
this.fetchEntries();
|
||||
}
|
||||
|
||||
get pageNumbers(): number[] {
|
||||
this.currentPage = this.currentPage <= 0 ? 1 : this.currentPage; // page <= 0 fix
|
||||
let startPage = this.currentPage <= 3 ? 1 : this.currentPage - 2;
|
||||
let endPage = startPage + 4;
|
||||
|
||||
return Array.from(
|
||||
{ length: endPage - startPage + 1 },
|
||||
(_, i) => startPage + i
|
||||
);
|
||||
}
|
||||
|
||||
// ? setter
|
||||
setEntryType(entryType: number) {
|
||||
this.entryType = entryType;
|
||||
this.filterEntries();
|
||||
}
|
||||
|
||||
setPageSize(pageSize: number) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user