F: implemented load media on scroll for media page
This commit is contained in:
1 parent
7f6202c897
commit
ec9e21dd0f
12 files changed
+240
-193
No files matched your search
-4
@@ -4,10 +4,6 @@
|
||||
<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">Collections</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
@@ -4,11 +4,7 @@
|
||||
<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">Watchlist</li>
|
||||
<li class="breadcrumb-item active" aria-current="page">{{displayType | titlecase}}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
<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">Library</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
@@ -13,6 +13,7 @@ import { WatchlistComponent } from './watchlist-page/watchlist.component';
|
||||
import { EntriesDisplayComponent } from './entries-display/entries-display.component';
|
||||
import { FavoritComponent } from './favorit-page/favorit.component';
|
||||
import { MultiSelectModule } from 'primeng/multiselect';
|
||||
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -26,6 +27,8 @@ import { MultiSelectModule } from 'primeng/multiselect';
|
||||
|
||||
MultiSelectModule,
|
||||
DragDropModule,
|
||||
|
||||
NgbDropdownModule
|
||||
],
|
||||
declarations: [
|
||||
EntriesDisplayComponent,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/* ! media hover buttons */
|
||||
.image-hover-container {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.image-hover-container img {
|
||||
width: 100%;
|
||||
display: block;
|
||||
transition: transform 0.3s ease;
|
||||
transform-origin: center;
|
||||
}
|
||||
|
||||
.image-hover-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.image-hover-container:hover .image-hover-overlay {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.btn-icon-delete:hover {
|
||||
color: var(--shz-red-danger);
|
||||
}
|
||||
|
||||
.btn-icon-select:hover {
|
||||
color: var(--shz-blue-default);
|
||||
}
|
||||
|
||||
.btn-icon-expand:hover {
|
||||
color: var(--shz-green-success);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<div class="row row-cols-4 row-cols-md-6 g-4">
|
||||
<div class="col" *ngFor="let media of mediaToDisplay">
|
||||
<div class="card image-hover-container">
|
||||
<img [src]="getPath(media.type+'s' , media)" class="card-img-top" alt="Media Image">
|
||||
<div class="image-hover-overlay">
|
||||
<button class="btn btn-icon btn-icon-delete" (click)="deleteMedia(media)">
|
||||
<span class="material-symbols-outlined">delete</span>
|
||||
</button>
|
||||
<button class="btn btn-icon btn-icon-select" (click)="selectMedia(media)">
|
||||
<span class="material-symbols-outlined">check_circle</span>
|
||||
</button>
|
||||
<button class="btn btn-icon btn-icon-expand" (click)="expandMedia(media)">
|
||||
<span class="material-symbols-outlined">zoom_out_map</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,28 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { DebugElement } from '@angular/core';
|
||||
|
||||
import { MediaGridComponent } from './media-grid.component';
|
||||
|
||||
describe('MediaGridComponent', () => {
|
||||
let component: MediaGridComponent;
|
||||
let fixture: ComponentFixture<MediaGridComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ MediaGridComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(MediaGridComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { EntryService } from '../../../core/services/entry.service';
|
||||
import { ConfigService } from '../../../core/services/config.service';
|
||||
import { CustomMediaService } from '../../../core/services/custom-media.service';
|
||||
import { Media } from '../../../shared/models/media.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-media-grid',
|
||||
templateUrl: './media-grid.component.html',
|
||||
styleUrls: ['./media-grid.component.css'],
|
||||
})
|
||||
export class MediaGridComponent implements OnInit {
|
||||
@Input() mediaToDisplay: Media[] = [];
|
||||
|
||||
constructor(
|
||||
private customMediaService: CustomMediaService,
|
||||
private configService: ConfigService,
|
||||
private entryService: EntryService
|
||||
) {}
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
getPath(type: string, media: Media) {
|
||||
let category = 'entries';
|
||||
if (media.mediaable == 'collection') category = 'collections';
|
||||
|
||||
return `${this.configService.getBackendApiUrl()}/media/${category}/${type}/preview/${
|
||||
media.path
|
||||
}`;
|
||||
}
|
||||
|
||||
selectMedia(media: any) {
|
||||
this.entryService.selectEntryMedia(media.entry.id, media.id).subscribe({
|
||||
next: (result) => {
|
||||
// TODO add confirm modal
|
||||
this.mediaToDisplay.forEach((m) => {
|
||||
if (m.type == media.type) {
|
||||
m.isSelected = false;
|
||||
}
|
||||
if ((m.id = result.id)) {
|
||||
m.isSelected = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
expandMedia(media: any) {
|
||||
let category = 'entries';
|
||||
if (media.mediaable == 'collection') category = 'collections';
|
||||
|
||||
const fullSizePath = `${this.configService.getBackendApiUrl()}/media/${category}/${
|
||||
media.type
|
||||
}s/original/${media.path}`;
|
||||
window.open(fullSizePath, '_blank');
|
||||
}
|
||||
|
||||
deleteMedia(media: Media) {
|
||||
this.entryService.deleteEntryMedia(media.entry.id, media.id).subscribe({
|
||||
next: (result) => {
|
||||
// TODO add confirm modal
|
||||
// TODO propagate delete to parent
|
||||
this.mediaToDisplay = this.mediaToDisplay.filter(
|
||||
(m) => m.id != media.id
|
||||
);
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(error);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -53,54 +53,3 @@
|
||||
.add-btn:hover {
|
||||
color: var(--shz-blue-default);
|
||||
}
|
||||
|
||||
/* ! media hover buttons */
|
||||
.image-hover-container {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.image-hover-container img {
|
||||
width: 100%;
|
||||
display: block;
|
||||
transition: transform 0.3s ease;
|
||||
transform-origin: center;
|
||||
}
|
||||
|
||||
.image-hover-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.image-hover-container:hover .image-hover-overlay {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.btn-icon-delete:hover {
|
||||
color: var(--shz-red-danger);
|
||||
}
|
||||
|
||||
.btn-icon-select:hover {
|
||||
color: var(--shz-blue-default);
|
||||
}
|
||||
|
||||
.btn-icon-expand:hover {
|
||||
color: var(--shz-green-success);
|
||||
}
|
||||
@@ -1,30 +1,37 @@
|
||||
<div class="row row-cols-1 row-cols-md-1 row-cols-lg-1 row-cols-xl-1">
|
||||
<div class="col">
|
||||
<h6 class="mb-0 text-uppercase">Custom Uploaded Media</h6>
|
||||
<hr>
|
||||
<!--breadcrumb-->
|
||||
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
|
||||
<div class="breadcrumb-title pe-3">Library</div>
|
||||
<div class="ps-3">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb mb-0 p-0">
|
||||
<li class="breadcrumb-item active" aria-current="page">Media</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
<!--end breadcrumb-->
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<ul class="nav nav-pills mb-3" role="tablist">
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link active" data-bs-toggle="pill" href="#posters-content" role="tab" aria-selected="true">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link cursor-pointer" [class.active]="tab == 'poster'" (click)="setTab('poster')">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="tab-icon"><i class="bi bi-file-image me-1 fs-6"></i></div>
|
||||
<div class="tab-title">Posters</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#backdrops-content" role="tab" aria-selected="false"
|
||||
tabindex="-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link cursor-pointer" [class.active]="tab == 'backdrop'" (click)="setTab('backdrop')">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="tab-icon"><i class="bi bi-card-image me-1 fs-6"></i></div>
|
||||
<div class="tab-title">Backdrops</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#logos-content" role="tab" aria-selected="false"
|
||||
tabindex="-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link cursor-pointer" [class.active]="tab == 'logo'" (click)="setTab('logo')">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="tab-icon"><i class="bi bi-alphabet-uppercase me-1 fs-6"></i>
|
||||
</div>
|
||||
@@ -35,66 +42,7 @@
|
||||
</ul>
|
||||
<div class=" tab-content" id="pills-tabContent">
|
||||
<div class="tab-pane fade active show" id="posters-content" role="tabpanel">
|
||||
<div class="row row-cols-4 row-cols-md-6 g-4">
|
||||
<div class="col" *ngFor="let media of filterMedia('poster')">
|
||||
<div class="card image-hover-container">
|
||||
<img [src]="getPath('posters' , media)" class="card-img-top" alt="Media Image">
|
||||
<div class="image-hover-overlay">
|
||||
<button class="btn btn-icon btn-icon-delete" (click)="deleteMedia(media)">
|
||||
<span class="material-symbols-outlined">delete</span>
|
||||
</button>
|
||||
<button class="btn btn-icon btn-icon-select" (click)="selectMedia(media)">
|
||||
<span class="material-symbols-outlined">check_circle</span>
|
||||
</button>
|
||||
<button class="btn btn-icon btn-icon-expand" (click)="expandMedia(media)">
|
||||
<span class="material-symbols-outlined">zoom_out_map</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="backdrops-content" role="tabpanel">
|
||||
<div class="row row-cols-2 row-cols-md-4 g-4">
|
||||
<div class="col" *ngFor="let media of filterMedia('backdrop')">
|
||||
<div class="card image-hover-container">
|
||||
<img [src]="getPath('backdrops', media)" class="card-img-top" alt="Media Image">
|
||||
<div class="image-hover-overlay">
|
||||
<button class="btn btn-icon btn-icon-delete" (click)="deleteMedia(media)">
|
||||
<span class="material-symbols-outlined">delete</span>
|
||||
</button>
|
||||
<button class="btn btn-icon btn-icon-select" (click)="selectMedia(media)">
|
||||
<span class="material-symbols-outlined">check_circle</span>
|
||||
</button>
|
||||
<button class="btn btn-icon btn-icon-expand" (click)="expandMedia(media)">
|
||||
<span class="material-symbols-outlined">zoom_out_map</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="logos-content" role="tabpanel">
|
||||
<div class="row row-cols-1 row-cols-md-5 g-4">
|
||||
<div class="col" *ngFor="let media of filterMedia('logo')">
|
||||
<div class="card image-hover-container">
|
||||
<img [src]="getPath('logos', media)" class="card-img-top" alt="Media Image">
|
||||
<div class="image-hover-overlay">
|
||||
<button class="btn btn-icon btn-icon-delete" (click)="deleteMedia(media)">
|
||||
<span class="material-symbols-outlined">delete</span>
|
||||
</button>
|
||||
<button class="btn btn-icon btn-icon-select" (click)="selectMedia(media)">
|
||||
<span class="material-symbols-outlined">check_circle</span>
|
||||
</button>
|
||||
<button class="btn btn-icon btn-icon-expand" (click)="expandMedia(media)">
|
||||
<span class="material-symbols-outlined">zoom_out_map</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<app-media-grid [mediaToDisplay]="mediaToDisplay"></app-media-grid>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,89 +1,76 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { CustomMediaService } from '../../../core/services/custom-media.service';
|
||||
import { Media } from '../../../shared/models/media.model';
|
||||
import { EntryService } from '../../../core/services/entry.service';
|
||||
import { ConfigService } from '../../../core/services/config.service';
|
||||
import { ScrollService } from '../../../core/services/scroll.service';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-media-page',
|
||||
templateUrl: './media-page.component.html',
|
||||
styleUrls: ['./media-page.component.css'],
|
||||
})
|
||||
export class MediaPageComponent implements OnInit {
|
||||
customMedia: Media[] = [];
|
||||
export class MediaPageComponent implements OnInit, OnDestroy {
|
||||
media: Media[] = [];
|
||||
mediaFiltered: Media[] = [];
|
||||
mediaToDisplay: Media[] = [];
|
||||
tab: string = 'poster';
|
||||
|
||||
private scrollSubscription!: Subscription;
|
||||
private mediaServiceSubscription!: Subscription;
|
||||
|
||||
constructor(
|
||||
private customMediaService: CustomMediaService,
|
||||
private configService: ConfigService,
|
||||
private entryService: EntryService
|
||||
private scrollService: ScrollService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.customMediaService.fetchCustomMedia().subscribe({
|
||||
this.mediaServiceSubscription = this.customMediaService
|
||||
.fetchCustomMedia()
|
||||
.subscribe({
|
||||
next: (result) => {
|
||||
console.log(result);
|
||||
this.customMedia = result;
|
||||
console.log(result);
|
||||
this.media = result;
|
||||
this.filterMedia();
|
||||
this.loadNext();
|
||||
},
|
||||
error: (error) => {},
|
||||
error: (error) => {
|
||||
console.log("Couldn't fetch media.");
|
||||
},
|
||||
});
|
||||
|
||||
this.scrollSubscription = this.scrollService.scrollEnd$.subscribe(() => {
|
||||
this.loadNext();
|
||||
});
|
||||
}
|
||||
|
||||
filterMedia(type: string) {
|
||||
return this.customMedia.filter((media) => media.type == type);
|
||||
ngOnDestroy(): void {
|
||||
// Unsubscribe to avoid memory leaks
|
||||
if (this.scrollSubscription) {
|
||||
this.scrollSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
getPath(type: string, media: Media) {
|
||||
let category = 'entries';
|
||||
if (media.mediaable == 'collection') category = 'collections';
|
||||
|
||||
return `${this.configService.getBackendApiUrl()}/media/${category}/${type}/preview/${
|
||||
media.path
|
||||
}`;
|
||||
if (this.mediaServiceSubscription) {
|
||||
this.mediaServiceSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
setTab(tab: string) {
|
||||
this.tab = tab;
|
||||
this.filterMedia();
|
||||
this.loadNext();
|
||||
}
|
||||
|
||||
deleteMedia(media: Media) {
|
||||
this.entryService.deleteEntryMedia(media.entry.id, media.id).subscribe({
|
||||
next: (result) => {
|
||||
// TODO add confirm modal
|
||||
this.customMedia = this.customMedia.filter((m) => m.id != media.id);
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(error);
|
||||
},
|
||||
});
|
||||
filterMedia() {
|
||||
this.mediaToDisplay = [];
|
||||
this.mediaFiltered = this.media.filter((media) => media.type == this.tab);
|
||||
}
|
||||
|
||||
selectMedia(media: any) {
|
||||
this.entryService.selectEntryMedia(media.entry.id, media.id).subscribe({
|
||||
next: (result) => {
|
||||
this.customMedia.forEach((m) => {
|
||||
if (m.type == media.type) {
|
||||
m.isSelected = false;
|
||||
loadNext(): void {
|
||||
const nextItems = this.mediaFiltered.slice(
|
||||
this.mediaToDisplay.length,
|
||||
Math.min(this.mediaToDisplay.length + 30, this.mediaFiltered.length)
|
||||
);
|
||||
if (nextItems.length > 0) {
|
||||
this.mediaToDisplay = [...this.mediaToDisplay, ...nextItems];
|
||||
}
|
||||
if ((m.id = result.id)) {
|
||||
m.isSelected = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
expandMedia(media: any) {
|
||||
let category = 'entries';
|
||||
if (media.mediaable == 'collection') category = 'collections';
|
||||
|
||||
const fullSizePath = `${this.configService.getBackendApiUrl()}/media/${category}/${
|
||||
media.type
|
||||
}s/original/${media.path}`;
|
||||
window.open(fullSizePath, '_blank');
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
import { MediaPageComponent } from './media-page/media-page.component';
|
||||
import { MediaRoutingModule } from './media-routing.module';
|
||||
import { MediaGridComponent } from './media-grid/media-grid.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -17,7 +18,7 @@ import { MediaRoutingModule } from './media-routing.module';
|
||||
|
||||
MediaRoutingModule,
|
||||
],
|
||||
declarations: [MediaPageComponent],
|
||||
declarations: [MediaPageComponent, MediaGridComponent],
|
||||
exports: [],
|
||||
})
|
||||
export class MediaModule {}
|
||||
Reference in new issue
Block a user