From 4b90b0e1b2ef6c44c94af37b84a7682155f642e6 Mon Sep 17 00:00:00 2001 From: Sana EL HIRI Date: Sun, 6 Mar 2022 20:49:53 +0100 Subject: [PATCH] =?UTF-8?q?avanc=C3=A9es=20et=20bloquage=20sur=20delete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app-routing.module.ts | 2 +- .../card-member/card-member.component.html | 2 +- .../page-account/page-account.component.ts | 16 +--------- .../page-delete-member.component.html | 4 +-- .../page-delete-member.component.ts | 32 +++++++++++++++---- .../page-update-member.component.ts | 2 +- src/app/services/membre.service.ts | 4 +-- 7 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index b4b104e..ef655e3 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -30,7 +30,7 @@ const routes: Routes = [ { path: 'ajout-membre', canActivate: [AuthGuard], component: PageAddMemberComponent }, { path: 'agenda', canActivate: [AuthGuard], component: PageAgendaComponent }, { path: 'tableau-de-bord', canActivate: [AuthGuard], component: PageDashboardComponent }, - { path: 'supprimer-membre', canActivate: [AuthGuard], component: PageDeleteMemberComponent }, + { path: 'supprimer-membre/:id', canActivate: [AuthGuard], component: PageDeleteMemberComponent }, { path: 'password-oublie', component: PageForgotPasswordComponent }, { path: 'menu', canActivate: [AuthGuard], component: PageMenuSemaineComponent }, { path: 'repertoire', canActivate: [AuthGuard], component: PageRepertoireComponent }, diff --git a/src/app/components/card-member/card-member.component.html b/src/app/components/card-member/card-member.component.html index d6eb7af..207be88 100644 --- a/src/app/components/card-member/card-member.component.html +++ b/src/app/components/card-member/card-member.component.html @@ -11,7 +11,7 @@ routerLinkActive="active-custom"> Modifier diff --git a/src/app/pages/page-account/page-account.component.ts b/src/app/pages/page-account/page-account.component.ts index a368213..d1d05a6 100644 --- a/src/app/pages/page-account/page-account.component.ts +++ b/src/app/pages/page-account/page-account.component.ts @@ -1,5 +1,4 @@ import { Component, OnInit } from '@angular/core'; -import { Router } from '@angular/router'; import { MembreService } from 'src/app/services/membre.service'; import { TeamService } from 'src/app/services/team.service'; import { TokenService } from 'src/app/services/token.service'; @@ -19,8 +18,7 @@ export class PageAccountComponent implements OnInit { constructor(private membreService: MembreService, private teamService: TeamService, - private tokenService: TokenService, - private router: Router) { + private tokenService: TokenService) { this.listMembres = []; this.parent = false; } @@ -46,16 +44,4 @@ export class PageAccountComponent implements OnInit { } } - /** Méthode qui au click va supprimer un contact en faisant appel au service dédié dans Membre Service **/ - onClickDelete(membreId: number){ - this.membreService.deleteMembre(membreId).subscribe((resp) => { - if(membreId) { - this.listMembres.forEach(membreId => console.log(membreId)) - }else{ - window.alert("Le profil ne peut pas être supprimé!") - } - this.router.navigate(['compte/']); - }); - window.location.reload(); - } } diff --git a/src/app/pages/page-delete-member/page-delete-member.component.html b/src/app/pages/page-delete-member/page-delete-member.component.html index df389ce..493f902 100644 --- a/src/app/pages/page-delete-member/page-delete-member.component.html +++ b/src/app/pages/page-delete-member/page-delete-member.component.html @@ -12,7 +12,7 @@ id = "bouton-ajout" type="button" class="btn btn-primary btn-lg bouton-non" - routerLink="../compte" + routerLink="/compte" routerLinkActive="active-custom" >Non, je ne souhaite pas supprimer ce compte @@ -22,7 +22,7 @@ id = "bouton-ajout" type="button" class="btn btn-primary btn-lg bouton-oui" - (clickDelete)="onClickDelete($event)" + (clickDelete)="onClickDelete()" >Oui, je souhaite supprimer ce compte diff --git a/src/app/pages/page-delete-member/page-delete-member.component.ts b/src/app/pages/page-delete-member/page-delete-member.component.ts index e52310e..cf3af15 100644 --- a/src/app/pages/page-delete-member/page-delete-member.component.ts +++ b/src/app/pages/page-delete-member/page-delete-member.component.ts @@ -1,5 +1,5 @@ import { Component, EventEmitter, OnInit, Output } from '@angular/core'; -import { Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { Membre } from 'src/app/models/membre'; import { MembreService } from 'src/app/services/membre.service'; import { TokenService } from 'src/app/services/token.service'; @@ -12,13 +12,31 @@ import { TokenService } from 'src/app/services/token.service'; export class PageDeleteMemberComponent implements OnInit { @Output() clickDelete = new EventEmitter(); parent: boolean; + public membreId: any; + public membreInfos: any; - constructor(private membreService: MembreService, private tokenService: TokenService) { + + constructor(private membreService: MembreService, + private tokenService: TokenService, + private router: Router, + private route: ActivatedRoute) { + this.membreInfos = ''; this.parent = false; } ngOnInit(): void { + /** Pour récuperer l'id du membre à modifier **/ + this.membreId = this.route.snapshot.paramMap.get('id'); + + /** Appel Api **/ + this.membreService + .getMembreId(this.membreId) + .subscribe((membreInfos: any) => { + this.membreInfos = membreInfos; + console.log(membreInfos.id); + }); + const roleUser = this.tokenService.getRole(); if(roleUser == "ROLE_PARENT"){ @@ -27,9 +45,11 @@ export class PageDeleteMemberComponent implements OnInit { } - onClickDelete(membreId: any){ - window.alert("Le profil à bien été supprimé!") - this.clickDelete.emit(membreId); + /** Suppresion d'un membre au clik */ + onClickDelete(): void { + console.log(this.membreInfos); + this.membreService.deleteMembre(this.membreInfos.id).subscribe((resp) => { + return resp + }); } - } diff --git a/src/app/pages/page-update-member/page-update-member.component.ts b/src/app/pages/page-update-member/page-update-member.component.ts index e97f81a..b7c5c52 100644 --- a/src/app/pages/page-update-member/page-update-member.component.ts +++ b/src/app/pages/page-update-member/page-update-member.component.ts @@ -103,7 +103,7 @@ export class PageUpdateMemberComponent implements OnInit { console.log(membre); this.membreService.updateMembre(membre)?.subscribe((resp) => { - //this.router.navigate(['compte']); + this.router.navigate(['compte']); }); } diff --git a/src/app/services/membre.service.ts b/src/app/services/membre.service.ts index ff88d34..105aa78 100644 --- a/src/app/services/membre.service.ts +++ b/src/app/services/membre.service.ts @@ -45,8 +45,8 @@ export class MembreService { } } - deleteMembre(membreId: number): Observable{ - return this.http.delete(`${this.apiUrl}/membres/delete/${membreId}`); + deleteMembre(membre: Membre): Observable{ + return this.http.delete(`${this.apiUrl}/membres/delete/${membre.id}`); } updateMembre(membre: Membre): Observable | void {