From 69eaf38f251010bc99f837fb38773807503ff2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yana=C3=ABl=20GRETTE?= Date: Thu, 18 Feb 2021 17:02:16 +0100 Subject: [PATCH] =?UTF-8?q?impl=C3=A9mentation=20de=20la=20r=C3=A9ponse=20?= =?UTF-8?q?=C3=A0=20une=20demande=20de=20d=C3=A9l=C3=A9gation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demandes-delegation.component.html | 2 +- .../demandes-delegation.component.ts | 18 ++++ .../demandes-delegation.module.ts | 6 +- .../demande-delegation.component.html | 4 +- .../demande-delegation.component.ts | 91 ++++++++++++++++++- 5 files changed, 112 insertions(+), 9 deletions(-) diff --git a/src/app/demandes-delegation/demandes-delegation.component.html b/src/app/demandes-delegation/demandes-delegation.component.html index b432884..5b82a7c 100644 --- a/src/app/demandes-delegation/demandes-delegation.component.html +++ b/src/app/demandes-delegation/demandes-delegation.component.html @@ -1,4 +1,4 @@

Liste des demandes de délégations

- \ No newline at end of file + \ No newline at end of file diff --git a/src/app/demandes-delegation/demandes-delegation.component.ts b/src/app/demandes-delegation/demandes-delegation.component.ts index e260c2a..d56844e 100644 --- a/src/app/demandes-delegation/demandes-delegation.component.ts +++ b/src/app/demandes-delegation/demandes-delegation.component.ts @@ -19,6 +19,7 @@ export class DemandesDelegationComponent implements OnInit { demandesDelegation: DemandeDelegationDTO[] = []; demandeDelegationSubscription: Subscription; + demandeDelegationReponseSubscription: Subscription; constructor(private demandeDelegationService: DemandesDelegationService) {} @@ -43,6 +44,23 @@ export class DemandesDelegationComponent implements OnInit { demandeDelegations => this.demandesDelegation = demandeDelegations, err => console.log(err) ); + } + donnerReponse(event: DemandeDelegationDTO) { + console.log(event); + const id: number = event.id; + this.demandeDelegationReponseSubscription = this.demandeDelegationService.updateDemandeDelegation(event, event.id).subscribe( + () => this.demandesDelegation.filter(d => d.id != id), + err => console.log(err) + ); + } + + ngOnDestroy() { + if(this.demandeDelegationSubscription != undefined) { + this.demandeDelegationSubscription.unsubscribe(); + } + if(this.demandeDelegationReponseSubscription != undefined) { + this.demandeDelegationReponseSubscription.unsubscribe(); + } } } diff --git a/src/app/demandes-delegation/demandes-delegation.module.ts b/src/app/demandes-delegation/demandes-delegation.module.ts index 4431f3e..6adf732 100644 --- a/src/app/demandes-delegation/demandes-delegation.module.ts +++ b/src/app/demandes-delegation/demandes-delegation.module.ts @@ -9,12 +9,14 @@ import {NavMenuModule} from '@shared/nav-menu/nav-menu.module'; import { DemandesDelegationComponent } from './demandes-delegation.component'; -import { DemandeDelegationComponent } from './details-demande-delegation/demande-delegation.component'; +import { DemandeDelegationComponent, DialogReponseDemandeDelegation } from './details-demande-delegation/demande-delegation.component'; import { DemandesDelegationRoutingModule } from './demandes-delegation.routing.module'; @NgModule({ - declarations: [ DemandesDelegationComponent, DemandeDelegationComponent + declarations: [ + DemandesDelegationComponent, DemandeDelegationComponent, + DialogReponseDemandeDelegation ], exports: [ DemandesDelegationComponent ], diff --git a/src/app/demandes-delegation/details-demande-delegation/demande-delegation.component.html b/src/app/demandes-delegation/details-demande-delegation/demande-delegation.component.html index fc93be2..0bdb86f 100644 --- a/src/app/demandes-delegation/details-demande-delegation/demande-delegation.component.html +++ b/src/app/demandes-delegation/details-demande-delegation/demande-delegation.component.html @@ -9,7 +9,7 @@ - - + + \ No newline at end of file diff --git a/src/app/demandes-delegation/details-demande-delegation/demande-delegation.component.ts b/src/app/demandes-delegation/details-demande-delegation/demande-delegation.component.ts index 1e6df7d..c701b47 100644 --- a/src/app/demandes-delegation/details-demande-delegation/demande-delegation.component.ts +++ b/src/app/demandes-delegation/details-demande-delegation/demande-delegation.component.ts @@ -1,5 +1,9 @@ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { DemandeDelegationDTO } from '@shared/api-swagger'; +import { i18nMetaToJSDoc } from '@angular/compiler/src/render3/view/i18n/meta'; +import { Component, EventEmitter, Inject, Input, OnInit, Output } from '@angular/core'; +import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { DemandeDelegationDTO, DemandeEPIDTO, EtatDemande } from '@shared/api-swagger'; +import { BrowserStack } from 'protractor/built/driverProviders'; +import { Subscription } from 'rxjs'; /** @@ -9,12 +13,91 @@ import { DemandeDelegationDTO } from '@shared/api-swagger'; templateUrl: './demande-delegation.component.html' }) export class DemandeDelegationComponent implements OnInit { - @Input() demandeDelegation: DemandeDelegationDTO; @Output() eventEmitter: EventEmitter = new EventEmitter(); + etatDemande: any = EtatDemande; + + dialogSubscription: Subscription; + + - constructor() {} + + + constructor(private matDialog: MatDialog) {} ngOnInit() { } + + accepter() { + this.repondreALaDemande(EtatDemande.Validee); + } + + + repondreALaDemande(etatDemande: EtatDemande) { + const data : any = { + etatDemande : etatDemande, + demandeDelegation : this.demandeDelegation + }; + const dialogRef: MatDialogRef = this.matDialog.open(DialogReponseDemandeDelegation, {data: data}) + + this.dialogSubscription = dialogRef.afterClosed().subscribe( + reponse => { + if(reponse.engistree) { + this.eventEmitter.emit(reponse.demandeDelegation); + } + } + ); + } + + ngOnDestroy() { + if(this.dialogSubscription != undefined) { + this.dialogSubscription.unsubscribe(); + } + } } + +@Component({ + selector: "dialog-reponse-demande-delegation", + templateUrl: "./dialog-reponse-demande-delegation.html" +}) +export class DialogReponseDemandeDelegation { + + texte: string =""; + estRefus: boolean = false; + raisonRefus: string; + reponse: any = { + engistree: false + } + + constructor(@Inject(MAT_DIALOG_DATA) public data, private dialogRef: MatDialogRef) { + switch(data.etatDemande) { + case EtatDemande.Validee: + this.texte = "Souhaitez-vous vraiment accepter la demande de délégation et devenir le nouveau référent de l'EP ?"; + break; + case EtatDemande.Rejetee: + this.texte = "Souhaitez-vous vraiment refuser la demande de délégation ?"; + this.estRefus = true; + break; + } + } + +enregistrer() { + if(this.estRefus && this.raisonRefus == "") + return; + let demandeDelegation: DemandeDelegationDTO = this.data.demandeDelegation; + demandeDelegation.etatDemande = this.data.etatDemande; + this.reponse = { + engistree: true, + demandeDelegation: demandeDelegation + } + this.fermer(); +} + + + + fermer() { + this.dialogRef.close(this.reponse); + } + + +} \ No newline at end of file