gestion des erreurs dans quand on ajoute une video dans une playlist

This commit is contained in:
MiharyR 2021-12-14 18:44:05 +01:00
parent 95e88f93ab
commit c1ecb3cb5e
6 changed files with 86 additions and 73 deletions

View file

@ -52,8 +52,8 @@ export class PageLoginComponent implements OnInit
onSeConnecterCallback(retour): void onSeConnecterCallback(retour): void
{ {
console.log(retour);
if(retour.status !== "success") { if(retour.status !== "success") {
console.log(retour);
this.errorMessage = retour.error.reason; this.errorMessage = retour.error.reason;
this.hasError = true; this.hasError = true;
} }

View file

@ -46,16 +46,22 @@ export class PageMyPlaylistsComponent implements OnInit
transmitPlaylistToVideoList(playlist): void transmitPlaylistToVideoList(playlist): void
{ {
this.messageService if ((playlist === null) || (playlist === undefined)) {
.get("playlist/findOne/"+playlist.id) this.playlist = playlist;
.subscribe(ret => this.afterReceivingPlaylistWithVideo(ret), err => this.afterReceivingPlaylistWithVideo(err)); }
else {
this.messageService
.get("playlist/findOne/" + playlist.id)
.subscribe(ret => this.afterReceivingPlaylistWithVideo(ret, playlist), err => this.afterReceivingPlaylistWithVideo(err, playlist));
}
} }
afterReceivingPlaylistWithVideo(retour: any): void afterReceivingPlaylistWithVideo(retour: any, playlist): void
{ {
if(retour.status !== "success") { if(retour.status !== "success") {
console.log(retour); console.log(retour);
this.playlist = playlist;
} }
else { else {
this.playlist = retour.data; this.playlist = retour.data;

View file

@ -65,7 +65,6 @@ export class PageSearchComponent implements OnInit
else if((!this.tabPlateform[0].isSelected) && this.tabPlateform[1].isSelected) sources += "dm" ; else if((!this.tabPlateform[0].isSelected) && this.tabPlateform[1].isSelected) sources += "dm" ;
else if(this.tabPlateform[0].isSelected && (!this.tabPlateform[1].isSelected)) sources += "yt" ; else if(this.tabPlateform[0].isSelected && (!this.tabPlateform[1].isSelected)) sources += "yt" ;
else sources += "" ; else sources += "" ;
console.log(sources);
params = params.append('sources', sources); params = params.append('sources', sources);
this.messageService this.messageService

View file

@ -35,7 +35,8 @@
<mat-divider></mat-divider><!-------------------------------------------------------------------------------------------------------------> <mat-divider></mat-divider><!------------------------------------------------------------------------------------------------------------->
<span *ngIf="hasError" class="mat-error"> {{errorMessage}} </span>
<mat-dialog-actions style="justify-content: flex-end;"> <mat-dialog-actions style="justify-content: flex-end;">
<button mat-button mat-dialog-close (click)="onAnnuler()">Annuler</button> <button mat-button (click)="onAnnuler()">Annuler</button>
<button mat-button mat-dialog-close="success" cdkFocusInitial (click)="onValider()">Valider</button> <button mat-button cdkFocusInitial (click)="onValider()">Valider</button>
</mat-dialog-actions> </mat-dialog-actions>

View file

@ -20,6 +20,9 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
goToCreatePlaylist = false; goToCreatePlaylist = false;
newPlaylistName = ""; newPlaylistName = "";
hasError: boolean = false;
tabNomPlaylist: string[] = [];
errorMessage: string = "" ;
constructor( public dialogRef: MatDialogRef<PopupAddVideoToPlaylistsComponent>, constructor( public dialogRef: MatDialogRef<PopupAddVideoToPlaylistsComponent>,
@ -34,83 +37,69 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
this.source = this.data.source; this.source = this.data.source;
this.interest = this.data.interest; this.interest = this.data.interest;
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) for(let playlist of this.data.playlists)
{ {
if(playlist.videoIds.includes(this._idVideo)) playlist["isSelected"] = true; if(playlist.videoIds.includes(this._idVideo)) playlist["isSelected"] = true;
else playlist["isSelected"] = false; else playlist["isSelected"] = false;
this.tabPlaylistAndBool.push(playlist); this.tabPlaylistAndBool.push(playlist);
this.tabNomPlaylist.push(playlist.name);
} }
} }
onValider(): void onValider(): void
{ {
// --- Existing playlists --- this.checkError();
let listeDesPlaylistsSelected = "" ; if(!this.hasError)
let listeDesPlaylistsNotSelected = "" ;
for(let playlist of this.tabPlaylistAndBool)
{ {
if(playlist.isSelected) listeDesPlaylistsSelected += playlist.id + "," ; // --- Existing playlists ---
else listeDesPlaylistsNotSelected += playlist.id + "," ; let listeDesPlaylistsSelected = "" ;
} let listeDesPlaylistsNotSelected = "" ;
if(listeDesPlaylistsSelected.endsWith(",")) listeDesPlaylistsSelected = listeDesPlaylistsSelected.slice(0, listeDesPlaylistsSelected.length-1); for(let playlist of this.tabPlaylistAndBool)
if(listeDesPlaylistsNotSelected.endsWith(",")) listeDesPlaylistsNotSelected = listeDesPlaylistsNotSelected.slice(0, listeDesPlaylistsNotSelected.length-1); {
if(playlist.isSelected) listeDesPlaylistsSelected += playlist.id + "," ;
else listeDesPlaylistsNotSelected += playlist.id + "," ;
}
if(listeDesPlaylistsSelected.endsWith(",")) listeDesPlaylistsSelected = listeDesPlaylistsSelected.slice(0, listeDesPlaylistsSelected.length-1);
if(listeDesPlaylistsNotSelected.endsWith(",")) listeDesPlaylistsNotSelected = listeDesPlaylistsNotSelected.slice(0, listeDesPlaylistsNotSelected.length-1);
if(listeDesPlaylistsSelected !== "") if(listeDesPlaylistsSelected !== "")
{ {
const data1 = { videoId: { id: this._idVideo, action: "add" } }; const data1 = { videoId: { id: this._idVideo, action: "add" } };
this.messageService this.messageService
.put( "playlist/update/"+listeDesPlaylistsSelected, data1) .put( "playlist/update/"+listeDesPlaylistsSelected, data1)
.subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err)); .subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err));
} }
if(listeDesPlaylistsNotSelected !== "") if(listeDesPlaylistsNotSelected !== "")
{ {
const data2 = { videoId: { id: this._idVideo, action: "delete" } }; const data2 = { videoId: { id: this._idVideo, action: "delete" } };
this.messageService this.messageService
.put( "playlist/update/"+listeDesPlaylistsNotSelected, data2) .put( "playlist/update/"+listeDesPlaylistsNotSelected, data2)
.subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err)); .subscribe( ret => this.callbackForExistingPlaylists(ret), err => this.callbackForExistingPlaylists(err));
} }
// --- New playlists --- // --- New playlists ---
if(this.goToCreatePlaylist) if(this.goToCreatePlaylist)
{ {
const data3 = { const data3 = {
name: this.newPlaylistName, name: this.newPlaylistName,
video: {videoId: this.videoId, interest: this.interest, source: this.source} video: {videoId: this.videoId, interest: this.interest, source: this.source}
}; };
this.messageService this.messageService
.post("playlist/create", data3) .post("playlist/create", data3)
.subscribe( ret => this.callbackForNewPlaylist(ret), err => this.callbackForNewPlaylist(err)); .subscribe( ret => this.callbackForNewPlaylist(ret), err => this.callbackForNewPlaylist(err));
}
// --- Finalement ---
this.dialogRef.close("success");
} }
} }
callbackForExistingPlaylists(retour: any): void callbackForExistingPlaylists(retour: any): void
{ {
console.log("onValiderCallback");
console.log(retour);
if(retour.status !== "success") {
//console.log(retour);
this.dialogRef.close(null);
}
}
callbackForNewPlaylist(retour: any): void
{
console.log("callbackForNewPlaylist");
console.log(retour);
if(retour.status !== "success") { if(retour.status !== "success") {
console.log(retour); console.log(retour);
this.dialogRef.close(null); this.dialogRef.close(null);
@ -118,10 +107,35 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
} }
callbackForNewPlaylist(retour: any): void
{
if(retour.status !== "success") {
console.log(retour);
this.dialogRef.close(null);
}
}
onAnnuler(): void onAnnuler(): void
{ {
this.dialogRef.close("annulation"); this.dialogRef.close("annulation");
} }
checkError(): void
{
if(this.goToCreatePlaylist && (this.newPlaylistName === "")) {
this.errorMessage = "Le nom ne peut pas être vide" ;
this.hasError = true;
}
else if(this.goToCreatePlaylist && this.tabNomPlaylist.includes(this.newPlaylistName)){
this.errorMessage = "Ce nom est déjà utilisé" ;
this.hasError = true;
}
else {
this.hasError = false;
this.errorMessage = "" ;
}
}
} }

View file

@ -4,7 +4,6 @@ import {MatDialog} from "@angular/material/dialog";
import {PopupAddVideoToPlaylistsComponent} from "../../components/popup-add-video-to-playlists/popup-add-video-to-playlists.component"; import {PopupAddVideoToPlaylistsComponent} from "../../components/popup-add-video-to-playlists/popup-add-video-to-playlists.component";
import {MatSnackBar} from "@angular/material/snack-bar"; import {MatSnackBar} from "@angular/material/snack-bar";
import {FictitiousVideosService} from "../../../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service"; import {FictitiousVideosService} from "../../../../utils/services/fictitiousDatas/fictitiousVideos/fictitious-videos.service";
import {HttpParams} from "@angular/common/http";
@ -40,11 +39,8 @@ export class AddVideoToPlaylistsService
private afterCreatingVideo(retour: any): void private afterCreatingVideo(retour: any): void
{ {
console.log("afterCreatingVideo");
console.log(retour);
if(retour.status !== "success") { if(retour.status !== "success") {
//console.log(retour); console.log(retour);
} }
else { else {
this._idVideo = retour.data.id; this._idVideo = retour.data.id;
@ -58,11 +54,8 @@ export class AddVideoToPlaylistsService
private afterReceivingPlaylists(retour: any): void private afterReceivingPlaylists(retour: any): void
{ {
console.log("afterReceivingPlaylists");
console.log(retour);
if(retour.status !== "success") { if(retour.status !== "success") {
//console.log(retour); console.log(retour);
} }
else else
{ {