implémentation de la réponse à une demande de délégation

develop
Yanaël GRETTE 4 years ago
parent eace2b936c
commit 69eaf38f25
  1. 2
      src/app/demandes-delegation/demandes-delegation.component.html
  2. 18
      src/app/demandes-delegation/demandes-delegation.component.ts
  3. 6
      src/app/demandes-delegation/demandes-delegation.module.ts
  4. 4
      src/app/demandes-delegation/details-demande-delegation/demande-delegation.component.html
  5. 91
      src/app/demandes-delegation/details-demande-delegation/demande-delegation.component.ts

@ -1,4 +1,4 @@
<app-nav-menu></app-nav-menu>
<h1>Liste des demandes de délégations</h1>
<app-demande-delegation *ngFor="let demandeDelegation of demandesDelegation" [demandeDelegation]="demandeDelegation"></app-demande-delegation>
<app-demande-delegation *ngFor="let demandeDelegation of demandesDelegation" [demandeDelegation]="demandeDelegation" (eventEmitter)="donnerReponse($event)"></app-demande-delegation>

@ -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();
}
}
}

@ -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
],

@ -9,7 +9,7 @@
</mat-card-content>
<mat-card-footer>
<button mat-raised-button color="primary">Accepter la demande</button>
<button mat-raised-button color="warn">Refuser la demande</button>
<button mat-raised-button (click)="repondreALaDemande(etatDemande.Validee)" color="primary">Accepter la demande</button>
<button mat-raised-button (click)="repondreALaDemande(etatDemande.Rejetee)" color="warn">Refuser la demande</button>
</mat-card-footer>
</mat-card>

@ -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<any> = new EventEmitter<any>();
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<DialogReponseDemandeDelegation> = 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<DialogReponseDemandeDelegation>) {
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);
}
}
Loading…
Cancel
Save