add favorit page
This commit is contained in:
1 parent
299f566b96
commit
8b7c10317f
10 files changed
+370
-17
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<!--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>
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { FavoritComponent } from './favorit.component';
|
||||
|
||||
describe('FavoritComponent', () => {
|
||||
let component: FavoritComponent;
|
||||
let fixture: ComponentFixture<FavoritComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [FavoritComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(FavoritComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user