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
{
console.log(retour);
if(retour.status !== "success") {
console.log(retour);
this.errorMessage = retour.error.reason;
this.hasError = true;
}

View file

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

View file

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

View file

@ -20,6 +20,9 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
goToCreatePlaylist = false;
newPlaylistName = "";
hasError: boolean = false;
tabNomPlaylist: string[] = [];
errorMessage: string = "" ;
constructor( public dialogRef: MatDialogRef<PopupAddVideoToPlaylistsComponent>,
@ -34,22 +37,20 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
this.source = this.data.source;
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)
{
if(playlist.videoIds.includes(this._idVideo)) playlist["isSelected"] = true;
else playlist["isSelected"] = false;
this.tabPlaylistAndBool.push(playlist);
this.tabNomPlaylist.push(playlist.name);
}
}
onValider(): void
{
this.checkError();
if(!this.hasError)
{
// --- Existing playlists ---
let listeDesPlaylistsSelected = "" ;
@ -89,28 +90,25 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
.post("playlist/create", data3)
.subscribe( ret => this.callbackForNewPlaylist(ret), err => this.callbackForNewPlaylist(err));
}
}
// --- Finalement ---
this.dialogRef.close("success");
}
}
callbackForExistingPlaylists(retour: any): void
{
console.log("onValiderCallback");
console.log(retour);
if(retour.status !== "success") {
//console.log(retour);
console.log(retour);
this.dialogRef.close(null);
}
}
callbackForNewPlaylist(retour: any): void
{
console.log("callbackForNewPlaylist");
console.log(retour);
if(retour.status !== "success") {
console.log(retour);
this.dialogRef.close(null);
@ -118,10 +116,26 @@ export class PopupAddVideoToPlaylistsComponent implements OnInit
}
onAnnuler(): void
{
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 {MatSnackBar} from "@angular/material/snack-bar";
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
{
console.log("afterCreatingVideo");
console.log(retour);
if(retour.status !== "success") {
//console.log(retour);
console.log(retour);
}
else {
this._idVideo = retour.data.id;
@ -58,11 +54,8 @@ export class AddVideoToPlaylistsService
private afterReceivingPlaylists(retour: any): void
{
console.log("afterReceivingPlaylists");
console.log(retour);
if(retour.status !== "success") {
//console.log(retour);
console.log(retour);
}
else
{