avancement dans la connexion du back avec la partie user
This commit is contained in:
parent
7030a0ea21
commit
7444715b2f
11 changed files with 121 additions and 168 deletions
|
|
@ -37,5 +37,5 @@
|
|||
|
||||
<mat-dialog-actions style="justify-content: flex-end;">
|
||||
<button mat-button mat-dialog-close (click)="onAnnuler()">Annuler</button>
|
||||
<button mat-button [mat-dialog-close]="true" cdkFocusInitial (click)="onValider()">Valider</button>
|
||||
<button mat-button mat-dialog-close="success" cdkFocusInitial (click)="onValider()">Valider</button>
|
||||
</mat-dialog-actions>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import {Component, Inject, OnInit} from '@angular/core';
|
||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||
import {VideoDB} from "../../../../utils/interfaces/video";
|
||||
import {MessageService} from "../../../../utils/services/message/message.service";
|
||||
|
||||
|
||||
|
|
@ -22,10 +21,6 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
|
|||
goToCreatePlaylist = false;
|
||||
newPlaylistName = "";
|
||||
|
||||
isFinishedForExistingPlaylist: boolean = false;
|
||||
isFinishedForNewPlaylist: boolean = false;
|
||||
|
||||
|
||||
|
||||
constructor( public dialogRef: MatDialogRef<PopupAddVideoToPlaylistsComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data,
|
||||
|
|
@ -39,12 +34,10 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
|
|||
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("---");
|
||||
console.log("_id: " + this._idVideo);
|
||||
console.log("videoId: " + this.videoId);
|
||||
console.log("source: " + this.source);
|
||||
console.log("interest: " + this.interest);
|
||||
|
||||
for(let playlist of this.data.playlists)
|
||||
{
|
||||
|
|
@ -58,20 +51,24 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
|
|||
onValider(): void
|
||||
{
|
||||
// --- Existing playlists ---
|
||||
|
||||
let listeDesPlaylists = "" ;
|
||||
for(let playlist of this.tabPlaylistAndBool) listeDesPlaylists += playlist.id + ","
|
||||
for(let playlist of this.tabPlaylistAndBool)
|
||||
{
|
||||
if(playlist.isSelected) 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));
|
||||
if(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)
|
||||
{
|
||||
const data2 = {
|
||||
|
|
@ -82,14 +79,6 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
|
|||
.post("playlist/create", data2)
|
||||
.subscribe( ret => this.callbackForNewPlaylist(ret), err => this.callbackForNewPlaylist(err));
|
||||
}
|
||||
else {
|
||||
this.isFinishedForNewPlaylist = true;
|
||||
}
|
||||
|
||||
|
||||
// Attente active
|
||||
while((!this.isFinishedForExistingPlaylist) || (!this.isFinishedForNewPlaylist)) {}
|
||||
this.dialogRef.close("success");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -97,16 +86,12 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
|
|||
callbackForExistingPlaylists(retour: any): void
|
||||
{
|
||||
console.log("onValiderCallback");
|
||||
//console.log(retour);
|
||||
console.log(retour);
|
||||
|
||||
if(retour.status !== "success") {
|
||||
console.log(retour);
|
||||
//console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
}
|
||||
else {
|
||||
this.isFinishedForExistingPlaylist = true;
|
||||
console.log("isFinishedForExistingPlaylist: true");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -114,15 +99,12 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
|
|||
callbackForNewPlaylist(retour: any): void
|
||||
{
|
||||
console.log("callbackForNewPlaylist");
|
||||
console.log(retour);
|
||||
|
||||
if(retour.status !== "success") {
|
||||
//console.log(retour);
|
||||
console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
}
|
||||
else {
|
||||
this.isFinishedForNewPlaylist = true;
|
||||
console.log("isFinishedForNewPlaylist: true");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -132,49 +114,4 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
|
|||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,49 +19,25 @@ export class AddVideoToPlaylistsService
|
|||
private interest: string = "" ;
|
||||
|
||||
|
||||
|
||||
constructor( private messageService: MessageService,
|
||||
public dialog: MatDialog,
|
||||
private fictitiousVideosService: FictitiousVideosService,
|
||||
private snackBar: MatSnackBar ) { }
|
||||
|
||||
|
||||
|
||||
|
||||
run(videoId: string, source: string): void
|
||||
run(videoId: string, source: string, interest: string): void
|
||||
{
|
||||
this.videoId = videoId;
|
||||
this.source = source;
|
||||
this.interest = interest;
|
||||
|
||||
let params = new HttpParams();
|
||||
if(source === "Youtube") params = params.append("source", "yt");
|
||||
else params = params.append("source", "dm");
|
||||
const data = { source: this.source, interest: this.interest };
|
||||
this.messageService
|
||||
.get("video/get/"+videoId, params)
|
||||
.subscribe(ret => this.afterAskingVideoInfo(ret), err => this.afterAskingVideoInfo(err));
|
||||
.post("video/create/"+this.videoId, data)
|
||||
.subscribe(ret => this.afterCreatingVideo(ret), err => this.afterCreatingVideo(err));
|
||||
}
|
||||
|
||||
|
||||
|
||||
afterAskingVideoInfo(retour: any): void
|
||||
{
|
||||
console.log("afterAskingVideoInfo");
|
||||
console.log(retour);
|
||||
|
||||
if(retour.status !== "success") {
|
||||
//console.log(retour);
|
||||
}
|
||||
else {
|
||||
this.interest = retour.data.interest;
|
||||
const data = { source: this.source, interest: this.interest };
|
||||
this.messageService
|
||||
.post("video/create/"+this.videoId, data)
|
||||
.subscribe(ret => this.afterCreatingVideo(ret), err => this.afterCreatingVideo(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private afterCreatingVideo(retour: any): void
|
||||
{
|
||||
console.log("afterCreatingVideo");
|
||||
|
|
|
|||
Reference in a new issue