connexion avec le back
This commit is contained in:
parent
91e4bba793
commit
4620f0dff9
16 changed files with 178 additions and 110 deletions
|
|
@ -77,6 +77,8 @@ export class PageUserListComponent implements AfterViewInit
|
|||
this.snackBar.open( "Opération annulée", "", this.configSnackBar);
|
||||
}
|
||||
else {
|
||||
if(retour.data.is_admin) retour.data.role = "admin" ;
|
||||
else retour.data.role = "utilisateur" ;
|
||||
this.dataSource.data.push(retour.data);
|
||||
this.dataSource.data = this.dataSource.data;
|
||||
this.dataSource = this.dataSource;
|
||||
|
|
@ -96,17 +98,17 @@ export class PageUserListComponent implements AfterViewInit
|
|||
this.dialog
|
||||
.open(PopupUpdatePersonAdminComponent, config)
|
||||
.afterClosed()
|
||||
.subscribe( retour => {
|
||||
.subscribe( is_admin => {
|
||||
|
||||
if((retour === null) || (retour === undefined))
|
||||
if((is_admin === null) || (is_admin === undefined))
|
||||
{
|
||||
this.snackBar.open("Opération annulée", "", this.configSnackBar);
|
||||
}
|
||||
else {
|
||||
const index = this.dataSource.data.findIndex( elt => (elt.id === personToUpdate.id));
|
||||
this.dataSource.data.splice(index, 1, retour.data);
|
||||
this.dataSource.data = this.dataSource.data;
|
||||
this.dataSource = this.dataSource;
|
||||
const index = this.dataSource.data.findIndex(elt => (elt.id === personToUpdate.id));
|
||||
this.dataSource.data[index].is_admin = is_admin;
|
||||
if(is_admin) this.dataSource.data[index].role = "admin";
|
||||
else this.dataSource.data[index].role = "utilisateur";
|
||||
this.snackBar.open("L'utilisateur a bien été modifié ✔", "", this.configSnackBar);
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +137,7 @@ export class PageUserListComponent implements AfterViewInit
|
|||
}
|
||||
else if(retour.status === "error")
|
||||
{
|
||||
this.snackBar.open(retour.message, "", this.configSnackBar);
|
||||
this.snackBar.open(retour.error.message, "", this.configSnackBar);
|
||||
}
|
||||
else {
|
||||
const index = this.dataSource.data.findIndex( elt => (elt.id === personToDelete.id));
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@
|
|||
<!-- nickname -->
|
||||
<mat-form-field appearance="fill">
|
||||
<mat-label>Pseudo</mat-label>
|
||||
<input matInput type="text" [(ngModel)]="person.nickname" required>
|
||||
<input matInput type="text" [(ngModel)]="nickname" required>
|
||||
</mat-form-field><br>
|
||||
|
||||
<!-- email -->
|
||||
<mat-form-field appearance="fill">
|
||||
<mat-label>Email</mat-label>
|
||||
<input matInput type="text" [(ngModel)]="person.email" required>
|
||||
<input matInput type="text" [(ngModel)]="email" required>
|
||||
</mat-form-field><br>
|
||||
|
||||
<!-- mot de passe -->
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
</mat-form-field><br>
|
||||
|
||||
<!-- role -->
|
||||
<mat-radio-group aria-labelledby="label-radio-group" [(ngModel)]="person.is_admin">
|
||||
<mat-radio-group aria-labelledby="label-radio-group" [(ngModel)]="is_admin">
|
||||
<mat-radio-button [value]="false" checked>Utilisateur </mat-radio-button>
|
||||
<mat-radio-button [value]="true">Admin</mat-radio-button>
|
||||
</mat-radio-group><br><br>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {Component, Inject} from '@angular/core';
|
||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||
import {CheckEmailService} from "../../../common/services/checkEmail/check-email.service";
|
||||
import {HashageService} from "../../../common/services/hashage/hashage.service";
|
||||
import {MessageService} from "../../../common/services/message/message.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -12,16 +12,12 @@ import {HashageService} from "../../../common/services/hashage/hashage.service";
|
|||
})
|
||||
export class PopupCreatePersonComponent
|
||||
{
|
||||
person = {
|
||||
id: "",
|
||||
nickname: "",
|
||||
email: "",
|
||||
hash_pass: "",
|
||||
is_admin: false,
|
||||
};
|
||||
nickname: string = "";
|
||||
email: string = "";
|
||||
is_admin: boolean = false;
|
||||
password: string = "";
|
||||
|
||||
confirmPassword: string = "" ;
|
||||
changePassword: boolean = false ;
|
||||
hasError: boolean = false;
|
||||
errorMessage: string = "" ;
|
||||
|
||||
|
|
@ -29,7 +25,7 @@ export class PopupCreatePersonComponent
|
|||
constructor( public dialogRef: MatDialogRef<PopupCreatePersonComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private checkEmailService: CheckEmailService,
|
||||
private hashageService: HashageService ) { }
|
||||
private messageService: MessageService ) { }
|
||||
|
||||
|
||||
// Appuie sur le bouton "valider"
|
||||
|
|
@ -38,13 +34,15 @@ export class PopupCreatePersonComponent
|
|||
this.checkField();
|
||||
if(!this.hasError)
|
||||
{
|
||||
if(this.changePassword) this.person.hash_pass = this.hashageService.run(this.password);
|
||||
const data = { user: this.person };
|
||||
|
||||
// ...
|
||||
|
||||
// Faux code
|
||||
this.onValiderCallback({ status: "success", data: {}});
|
||||
const data = {
|
||||
email: this.email,
|
||||
nickname: this.nickname,
|
||||
password: this.password,
|
||||
is_admin: this.is_admin
|
||||
};
|
||||
this.messageService
|
||||
.post("admin/create/user", data)
|
||||
.subscribe(ret => this.onValiderCallback(ret), err => this.onValiderCallback(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,19 +50,15 @@ export class PopupCreatePersonComponent
|
|||
// Callback de 'onValider'
|
||||
onValiderCallback(retour: any)
|
||||
{
|
||||
if(retour.status === 'success')
|
||||
{
|
||||
this.dialogRef.close(retour);
|
||||
}
|
||||
else if(retour.status === 'error')
|
||||
if(retour.status !== 'success')
|
||||
{
|
||||
console.log(retour);
|
||||
this.errorMessage = retour.message;
|
||||
this.errorMessage = retour.error.message;
|
||||
this.hasError = true;
|
||||
}
|
||||
else {
|
||||
console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
else
|
||||
{
|
||||
this.dialogRef.close(retour);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,15 +66,15 @@ export class PopupCreatePersonComponent
|
|||
// Check les champs saisis par l'utilisateur
|
||||
checkField(): void
|
||||
{
|
||||
if(this.person.nickname.length === 0) {
|
||||
if(this.nickname.length === 0) {
|
||||
this.errorMessage = "Veuillez remplir le champ 'pseudo'.";
|
||||
this.hasError = true;
|
||||
}
|
||||
else if(this.person.email.length === 0) {
|
||||
else if(this.email.length === 0) {
|
||||
this.errorMessage = "Veuillez remplir le champ 'email'.";
|
||||
this.hasError = true;
|
||||
}
|
||||
else if(!this.checkEmailService.isValidEmail(this.person.email)) {
|
||||
else if(!this.checkEmailService.isValidEmail(this.email)) {
|
||||
this.errorMessage = "Email invalide.";
|
||||
this.hasError = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,11 @@
|
|||
<mat-divider></mat-divider><br>
|
||||
|
||||
<!-- role -->
|
||||
<mat-radio-group [(ngModel)]="personCopy.is_admin">
|
||||
<mat-radio-group [(ngModel)]="is_admin">
|
||||
<mat-radio-button [value]="false"
|
||||
[checked]="!personCopy.is_admin"
|
||||
(click)="personCopy.role = 'utilisateur'">Utilisateur</mat-radio-button>
|
||||
[checked]="!is_admin">Utilisateur</mat-radio-button>
|
||||
<mat-radio-button [value]="true"
|
||||
[checked]="personCopy.is_admin"
|
||||
(click)="personCopy.role = 'admin'">Admin</mat-radio-button>
|
||||
[checked]="is_admin">Admin</mat-radio-button>
|
||||
</mat-radio-group><br><br>
|
||||
|
||||
<!-- divider -->
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {Component, Inject, OnInit} from '@angular/core';
|
||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||
import {CheckEmailService} from "../../../common/services/checkEmail/check-email.service";
|
||||
import {HashageService} from "../../../common/services/hashage/hashage.service";
|
||||
import {MessageService} from "../../../common/services/message/message.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -12,15 +12,10 @@ import {HashageService} from "../../../common/services/hashage/hashage.service";
|
|||
})
|
||||
export class PopupUpdatePersonAdminComponent implements OnInit
|
||||
{
|
||||
personCopy: any = {
|
||||
id: "",
|
||||
nickname: "",
|
||||
email: "",
|
||||
hash_pass: "",
|
||||
is_admin: true,
|
||||
role: "utilisateur"
|
||||
};
|
||||
id: number = 0;
|
||||
is_admin: boolean = false;
|
||||
newPassword: string = "";
|
||||
|
||||
confirmNewPassword: string = "" ;
|
||||
changePassword: boolean = false ;
|
||||
hasError: boolean = false;
|
||||
|
|
@ -30,41 +25,28 @@ export class PopupUpdatePersonAdminComponent implements OnInit
|
|||
constructor( public dialogRef: MatDialogRef<PopupUpdatePersonAdminComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private checkEmailService: CheckEmailService,
|
||||
private hashageService: HashageService ) { }
|
||||
private messageService: MessageService ) { }
|
||||
|
||||
|
||||
ngOnInit(): void
|
||||
{
|
||||
const person = this.data.person;
|
||||
this.personCopy = {
|
||||
id: person.id,
|
||||
nickname: person.nickname,
|
||||
email: person.email,
|
||||
hash_pass: person.hash_pass,
|
||||
is_admin: person.is_admin,
|
||||
role: person.role,
|
||||
};
|
||||
console.log("ngOnInit")
|
||||
console.log(this.personCopy);
|
||||
this.id = this.data.person.id;
|
||||
this.is_admin = this.data.person.is_admin;
|
||||
}
|
||||
|
||||
|
||||
// Appuie sur le bouton "valider"
|
||||
onValider(): void
|
||||
{
|
||||
console.log("onValider")
|
||||
console.log(this.personCopy);
|
||||
|
||||
this.checkField();
|
||||
if(!this.hasError)
|
||||
{
|
||||
if(this.changePassword) this.personCopy.hash_pass = this.hashageService.run(this.newPassword);
|
||||
const data = { user: this.personCopy };
|
||||
|
||||
// ...
|
||||
|
||||
// Faux code
|
||||
this.onValiderCallback({ status: "success"});
|
||||
let data = {};
|
||||
if(this.changePassword) data = { id: this.id, is_admin: this.is_admin, password: this.newPassword }
|
||||
else data = { id: this.id, is_admin: this.is_admin };
|
||||
this.messageService
|
||||
.put("admin/update/user", data)
|
||||
.subscribe(ret => this.onValiderCallback(ret), err => this.onValiderCallback(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,14 +54,15 @@ export class PopupUpdatePersonAdminComponent implements OnInit
|
|||
// Callback de 'onValider'
|
||||
onValiderCallback(retour: any)
|
||||
{
|
||||
if(retour.status === 'error')
|
||||
if(retour.status !== 'success')
|
||||
{
|
||||
console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
this.errorMessage = retour.error.message;
|
||||
this.hasError = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dialogRef.close(this.personCopy);
|
||||
this.dialogRef.close(this.is_admin);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue