changes + fixes to collections related component + add filter by collection type

This commit is contained in:
X4Lo committed 2024-09-10 01:15:14 +01:00
1 parent eba9721a3c
commit 776506b232
14 files changed
+219 -129

No files matched your search

@@ -1,6 +1,6 @@
<div class="card-coat">
<div class="d-flex flex-column align-items-center collection-card" @fadeInOut>
<img id="poster" [src]="getPostPath()" width="150" class="" alt="List poster" (click)="redirectTo()">
<img id="poster" [src]="getCollectionPosterPath()" width="150" class="" alt="List poster" (click)="redirectTo()">
<div class="list-item-1 mt-2 text-center">
<h6 class="mb-0 list-title" (click)="redirectTo()">{{list.name}}</h6>
<!-- <p class="mb-0">Created: {{getCreatedDate() | dateFormat}}</p> -->
@@ -3,6 +3,8 @@ import { UserCollection } from '../../../../shared/models/userCollection.model';
import { UserCollectionService } from '../../../../core/services/userCollection.service';
import { Router } from '@angular/router';
import { trigger, transition, style, animate } from '@angular/animations';
import { environment } from '../../../../../environments/environment.prod';
import { Entry } from '../../../../shared/models/entry.model';
@Component({
selector: 'app-userCollections-list-item',
@@ -30,15 +32,51 @@ export class UserCollectionsListItemComponent {
private router: Router
) {}
getPostPath() {
if (this.list.poster_path == null) return 'https://pic.pnnet.dev/256x256';
if (this.list.poster_path.startsWith('/'))
return `https://image.tmdb.org/t/p/w500` + this.list.poster_path;
getCollectionPosterPath() {
if (this.list.isLocal) {
if (this.list.posterPath == null)
return 'assets/images/default/default-poster.png';
return (
`http://localhost:4000/api/v1/media/collections/posters/` +
this.list.poster_path
);
// * use the collection custom poster
return (
environment.API_URL +
`/media/collections/posters/preview/` +
this.list.posterPath
);
} else {
// * use the poster of the first entry in the collection if its no empty
if (this.list.entries.length != 0) {
return this.getEntryPosterPath(this.list.entries[0]);
}
// * if the collection is empty
return 'assets/images/default/default-poster.png';
}
}
getEntryPosterPath(entry: Entry) {
// * Is in library: use a local poster
if (entry.medias) {
const selectedPosters = entry.medias.filter(
(m) => m.type == 'poster' && m.isSelected
);
if (
selectedPosters.length &&
selectedPosters[0] &&
selectedPosters[0].path
) {
const name = selectedPosters[0].path;
return environment.API_URL + `/media/entries/posters/preview/${name}`;
}
}
// * No local poster available, Use TMDB poster
if (entry.poster_path)
return `https://image.tmdb.org/t/p/w300` + entry.poster_path;
// * No poster found, use default poster image as a last stand
return 'assets/images/default/default-poster.png';
}
getCreatedDate(): string {
@@ -15,35 +15,41 @@
</div>
<!--end breadcrumb-->
<div>
<div class="col d-flex ">
<div class="card w-100">
<div class="card-header border-0 p-3 border-bottom d-flex align-items-center justify-content-between">
<div class="position-relative flex-grow-1 align-items-center">
<input [formControl]="searchControl" matInput class="form-control rounded-5 px-5" type="text"
placeholder="Collection name...">
<span class="material-icons-outlined position-absolute ms-3 translate-middle-y start-0 top-50">search</span>
</div>
<button type="button" class="btn btn-primary d-flex align-items-center m-2" *ngIf="doShowCreate()" (click)="createCollection()"><i
class="material-icons-outlined">add</i>
</button>
<div class="row my-2">
<!-- Search Input for name -->
<div class="col-lg-6 col-md-6">
<div class="input-group">
<span class="input-group-text material-icons-outlined">search</span>
<input [formControl]="searchControl" matInput class="form-control" type="text" placeholder="Collection name...">
<button type="button" class="btn btn-primary d-flex align-items-center" *ngIf="doShowCreate()"
(click)="createCollection()">
<i class="material-icons-outlined">add</i>
</button>
</div>
</div>
<div class="col-3">
<select name="seasons" class="form-select" [(ngModel)]="collectionType" (change)="onCollectionTypeChange($event)"
aria-placeholder="Select a season">
<option value="" disabled selected>Select a season</option>
<option value="All">All</option>
<option value="Custom">Custom</option>
<option value="Official">Official</option>
</select>
</div>
</div>
<div class="col d-flex mt-2">
<div class="card w-100">
<div class="card-body p-0">
<div class="collections-container">
<app-userCollections-list-item *ngFor="let list of collectionsToShow" [list]="list"
@animateDestroy></app-userCollections-list-item>
</div>
<div class="card-body p-0">
<div class="collections-container">
<app-userCollections-list-item *ngFor="let list of collectionsToShow"
[list]="list" @animateDestroy></app-userCollections-list-item>
</div>
<!-- <div class="p-3 ps ps--active-y">
<div class="d-flex flex-column gap-3">
<app-userCollections-list-item *ngFor="let list of collectionsToShow"
[list]="list" @animateDestroy></app-userCollections-list-item>
</div>
</div> -->
</div>
</div>
</div>
</div>
@@ -28,6 +28,7 @@ export class UserCollectionsPageComponent implements OnInit {
collections: UserCollection[] = [];
collectionsToShow: UserCollection[] = [];
collectionType: string = 'All';
lockActions: boolean = false;
@@ -54,16 +55,26 @@ export class UserCollectionsPageComponent implements OnInit {
});
}
onCollectionTypeChange(event: any): void {
this.applyFilter();
}
applyFilter() {
let filterValue = this.searchControl.value;
if (filterValue == null) {
this.collectionsToShow = [...this.collections];
return;
// * type filter
let collections = this.collections;
if (this.collectionType != 'All') {
const type = this.collectionType == 'Custom' ? true : false;
collections = this.collections.filter(
(collection) => collection.isUserCollection == type
);
}
const filterValue = this.searchControl.value;
if (filterValue == null) return;
const normalizedFilter = filterValue.toLowerCase().trim();
this.collectionsToShow = this.collections.filter((collection) =>
this.collectionsToShow = collections.filter((collection) =>
collection.name.toLowerCase().trim().includes(normalizedFilter)
);
this.collectionsCount = this.collectionsToShow.length;
@@ -90,9 +101,6 @@ export class UserCollectionsPageComponent implements OnInit {
}
doShowCreate() {
return (
this.searchControl.value?.trim() != '' &&
this.collectionsToShow.length == 0
);
return this.searchControl.value && !this.collections.some(c => c.name.trim().toLowerCase() == this.searchControl.value?.trim().toLowerCase());
}
}