connexion avec le back pour 'page search' et 'page watching'
This commit is contained in:
parent
d53bc27b7c
commit
5e62d2e4ef
10 changed files with 290 additions and 76 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<div *ngIf="from==='search' || from==='myPlaylists'" class="myContainer">
|
||||
<span class="helper"></span>
|
||||
<img [src]="'assets/pub/'+ad.images[idxImage].url"
|
||||
[alt]="ad.images[idxImage].url"
|
||||
[alt]="ad.title"
|
||||
(click)="onClick()"
|
||||
id="imgFromSearchOrMyPlaylists">
|
||||
</div>
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<img *ngIf="from === 'watchingLeft'"
|
||||
[src]="'assets/pub/'+ad.images[idxImage].url"
|
||||
[alt]="ad.images[idxImage].url"
|
||||
[alt]="ad.title"
|
||||
(click)="onClick()"
|
||||
id="imgFromWatchingLeft">
|
||||
|
||||
|
|
@ -18,6 +18,6 @@
|
|||
|
||||
<img *ngIf="from === 'watchingRight'"
|
||||
[src]="'assets/pub/'+ad.images[idxImage].url"
|
||||
[alt]="ad.images[idxImage].url"
|
||||
[alt]="ad.title"
|
||||
(click)="onClick()"
|
||||
id="imgFromWatchingRight">
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import {Router} from "@angular/router";
|
|||
})
|
||||
export class AdvertComponent implements OnInit
|
||||
{
|
||||
@Input() ad: Advert;
|
||||
@Input() ad: any;
|
||||
@Input() from: string = "search";
|
||||
idxImage: number = 0;
|
||||
|
||||
|
|
@ -20,7 +20,10 @@ export class AdvertComponent implements OnInit
|
|||
ngOnInit(): void
|
||||
{
|
||||
const nbImages = this.ad.images.length;
|
||||
if(nbImages === 0) this.ad.images.push({url: "img pub"});
|
||||
this.idxImage = Math.floor(Math.random() * nbImages);
|
||||
|
||||
if(this.ad.title === "") this.ad.title = "--- pub ---" ;
|
||||
}
|
||||
|
||||
onClick(): void
|
||||
|
|
|
|||
|
|
@ -12,11 +12,20 @@ import {MessageService} from "../../../../utils/services/message/message.service
|
|||
})
|
||||
export class PopupAddVideoToPlaylistsComponent implements OnInit
|
||||
{
|
||||
video: VideoDB;
|
||||
_idVideo: string = "";
|
||||
videoId: string = "";
|
||||
source: string = "";
|
||||
interest: string = "";
|
||||
|
||||
tabPlaylistAndBool = [];
|
||||
|
||||
goToCreatePlaylist = false;
|
||||
newPlaylistName = "";
|
||||
|
||||
isFinishedForExistingPlaylist: boolean = false;
|
||||
isFinishedForNewPlaylist: boolean = false;
|
||||
|
||||
|
||||
|
||||
constructor( public dialogRef: MatDialogRef<PopupAddVideoToPlaylistsComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data,
|
||||
|
|
@ -25,7 +34,18 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
|
|||
|
||||
ngOnInit(): void
|
||||
{
|
||||
this.video = this.data.video;
|
||||
this._idVideo = this.data._idVideo;
|
||||
this.videoId = this.data.videoId;
|
||||
this.source = this.data.source;
|
||||
this.interest = this.data.interest;
|
||||
|
||||
console.log("---");
|
||||
console.log(this.data._idVideo);
|
||||
console.log(this.data.videoId);
|
||||
console.log(this.data.source);
|
||||
console.log(this.data.interest);
|
||||
console.log("---");
|
||||
|
||||
for(let playlist of this.data.playlists)
|
||||
{
|
||||
playlist["isSelected"] = false;
|
||||
|
|
@ -34,34 +54,125 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
|
|||
}
|
||||
|
||||
|
||||
|
||||
onValider(): void
|
||||
{
|
||||
const tabPlaylist = [];
|
||||
for(let playlist of this.tabPlaylistAndBool)
|
||||
// --- Existing playlists ---
|
||||
|
||||
let listeDesPlaylists = "" ;
|
||||
for(let playlist of this.tabPlaylistAndBool) listeDesPlaylists += playlist.id + ","
|
||||
if(listeDesPlaylists.endsWith(",")) listeDesPlaylists = listeDesPlaylists.slice(0, listeDesPlaylists.length-1);
|
||||
|
||||
console.log(listeDesPlaylists);
|
||||
const data1 = { videoId: this._idVideo }
|
||||
this.messageService
|
||||
.put( "playlist/update/"+ listeDesPlaylists, data1)
|
||||
.subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err));
|
||||
|
||||
|
||||
// --- New playlists ---
|
||||
|
||||
if(this.goToCreatePlaylist)
|
||||
{
|
||||
if(playlist.isSelected) {
|
||||
delete playlist["isSelected"];
|
||||
tabPlaylist.push(playlist);
|
||||
}
|
||||
const data2 = {
|
||||
name: this.newPlaylistName,
|
||||
video: {videoId: this.videoId, interest: this.interest, source: this.source}
|
||||
};
|
||||
this.messageService
|
||||
.post("playlist/create", data2)
|
||||
.subscribe( ret => this.callbackForNewPlaylist(ret), err => this.callbackForNewPlaylist(err));
|
||||
}
|
||||
else {
|
||||
this.isFinishedForNewPlaylist = true;
|
||||
}
|
||||
|
||||
// --- FAUX CODE ---
|
||||
this.dialogRef.close("success");
|
||||
|
||||
// --- VRAI CODE ---
|
||||
/*
|
||||
if(!this.goToCreatePlaylist) this.newPlaylistName = "";
|
||||
const data = { "video": this.video, "playlists": tabPlaylist, "newPlaylistName": this.newPlaylistName };
|
||||
this.messageService
|
||||
.sendMessage("user/add/vidéo", data)
|
||||
.subscribe( retour => { this.dialogRef.close(retour.status) });
|
||||
*/
|
||||
// Attente active
|
||||
while((!this.isFinishedForExistingPlaylist) || (!this.isFinishedForNewPlaylist)) {}
|
||||
this.dialogRef.close("success");
|
||||
}
|
||||
|
||||
|
||||
|
||||
callbackForExistingPlaylists(retour: any): void
|
||||
{
|
||||
console.log("onValiderCallback");
|
||||
//console.log(retour);
|
||||
|
||||
if(retour.status !== "success") {
|
||||
console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
}
|
||||
else {
|
||||
this.isFinishedForExistingPlaylist = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
callbackForNewPlaylist(retour: any): void
|
||||
{
|
||||
console.log("callbackForNewPlaylist");
|
||||
|
||||
if(retour.status !== "success") {
|
||||
//console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
}
|
||||
else {
|
||||
this.isFinishedForNewPlaylist = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
onAnnuler(): void
|
||||
{
|
||||
this.dialogRef.close("annulation")
|
||||
this.dialogRef.close("annulation");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
//nbPlaylistSelected: number = 0;
|
||||
//numPlaylistSelected: number = 0;
|
||||
|
||||
onValider(): void
|
||||
{
|
||||
for(let playlist of this.tabPlaylistAndBool)
|
||||
{
|
||||
if(playlist.isSelected) this.nbPlaylistSelected += 1;
|
||||
}
|
||||
|
||||
for(let playlist of this.tabPlaylistAndBool)
|
||||
{
|
||||
if(playlist.isSelected)
|
||||
{
|
||||
playlist.videoIds.push(this._idVideo);
|
||||
this.messageService
|
||||
.put("playlist/update/"+playlist._id, playlist.videoIds)
|
||||
.subscribe(ret => this.onAddingToExistingPlaylist(ret), err => this.onAddingToExistingPlaylist(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onAddingToExistingPlaylist(retour: any): void
|
||||
{
|
||||
console.log("onValiderCallback");
|
||||
console.log(retour);
|
||||
this.numPlaylistSelected += 1;
|
||||
|
||||
if(retour.status !== "success") {
|
||||
this.dialogRef.close("annulation");
|
||||
}
|
||||
else {
|
||||
if(this.numPlaylistSelected === this.numPlaylistSelected)
|
||||
{
|
||||
this.dialogRef.close("success");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue