import { Component, OnInit } from '@angular/core'; import { CustomMediaService } from '../../../core/services/custom-media.service'; import { Media } from '../../../shared/models/media.model'; import { environment } from '../../../../environments/environment.prod'; import { EntryService } from '../../../core/services/entry.service'; @Component({ selector: 'app-media-page', templateUrl: './media-page.component.html', styleUrls: ['./media-page.component.css'], }) export class MediaPageComponent implements OnInit { customMedia: Media[] = []; tab: string = 'poster'; constructor( private customMediaService: CustomMediaService, private entryService: EntryService ) {} ngOnInit() { this.customMediaService.fetchCustomMedia().subscribe({ next: (result) => { this.customMedia = result; console.log(result); }, error: (error) => {}, }); } filterMedia(type: string) { return this.customMedia.filter((media) => media.type == type); } getPath(type: string, fileName: string) { return `${environment.API_URL}/media/entries/${type}/preview/${fileName}`; } setTab(tab: string) { this.tab = tab; } 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); }, }); } 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; } if ((m.id = result.id)) { m.isSelected = true; } }); }, error: (error) => { console.log(error); }, }); } expandMedia(media: any) { const fullSizePath = `${environment.API_URL}/media/entries/${media.type}s/original/${media.path}`; window.open(fullSizePath, '_blank'); } }