This repository has been archived on 2026-05-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
PolyNotFound/src/app/user/myPlaylists/playlist-list/playlist-list.component.ts
2021-11-21 12:56:11 +01:00

70 lines
2.6 KiB
TypeScript

import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {ThemeService} from "../../../utils/services/theme/theme.service";
import {PlaylistDB} from "../../../utils/interfaces/playlist";
import {MessageService} from "../../../utils/services/message/message.service";
import {MatDialog} from "@angular/material/dialog";
import {MatSnackBar} from "@angular/material/snack-bar";
import {PopupCreatePlaylistComponent} from "../popup-create-playlist/popup-create-playlist.component";
import {FictitiousVideosService} from "../../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service";
@Component({
selector: 'app-playlist-list',
templateUrl: './playlist-list.component.html',
styleUrls: ['./playlist-list.component.scss']
})
export class PlaylistListComponent implements OnInit
{
allPlaylists: PlaylistDB[] = []; // toutes les playlists
@Output() eventEmitter = new EventEmitter<PlaylistDB>(); // pour envoyer au parent la playlist selectionner
search: string = "" ; // contenu de la barre de recherche
tabPlaylist: PlaylistDB[] = []; // playlist affichées
constructor( public themeService: ThemeService,
public dialog: MatDialog,
public snackBar: MatSnackBar,
private fictitiousVideosService: FictitiousVideosService ) { }
ngOnInit(): void
{
//this.allPlaylists = this.fictitiousVideosService.getRandomTabPlaylistDB(10, 10);
this.allPlaylists = this.fictitiousVideosService.getNoRandomTabPlaylistDB(10);
this.tabPlaylist = [].concat(this.allPlaylists);
}
whileSearch()
{
console.log("whileSearch");
this.tabPlaylist = [];
for(let playlist of this.allPlaylists)
{
if(playlist.name.includes(this.search)) this.tabPlaylist.push(playlist);
}
}
onCreatePlaylist(): void
{
const config = { data: this.tabPlaylist };
this.dialog
.open(PopupCreatePlaylistComponent, config )
.afterClosed()
.subscribe(playlist => {
const config = { duration: 1000, panelClass: "custom-class" };
if((playlist === null) || (playlist === undefined)) {
this.snackBar.open("Opération annulée", "", config);
}
else {
this.allPlaylists.push(playlist);
this.tabPlaylist.push(playlist);
this.snackBar.open("La playlist a bien été créée ✔", "", config);
}
});
}
}