From 7c55a54d060f851f04568be9ff538ca82bdd448d Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 16:59:24 +0100 Subject: [PATCH] feat(admin) : add commentary --- .../validation-attachment.component.html | 2 +- .../validation-attachment.component.ts | 9 +++++++-- src/app/admin/models/demandAttachment.model.ts | 3 --- src/app/admin/services/admin.service.ts | 16 +++++++++------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/app/admin/components/validation-attachment/validation-attachment.component.html b/src/app/admin/components/validation-attachment/validation-attachment.component.html index 03e52cde1..f32fd6e7b 100644 --- a/src/app/admin/components/validation-attachment/validation-attachment.component.html +++ b/src/app/admin/components/validation-attachment/validation-attachment.component.html @@ -1,5 +1,5 @@ <div fxLayout="row" fxLayoutAlign="center center"> - <table> + <table *ngIf="demandsAttachment"> <thead> <th>Utilisateur</th> <th>Structure</th> diff --git a/src/app/admin/components/validation-attachment/validation-attachment.component.ts b/src/app/admin/components/validation-attachment/validation-attachment.component.ts index 78fe3329b..e7d1ff21f 100644 --- a/src/app/admin/components/validation-attachment/validation-attachment.component.ts +++ b/src/app/admin/components/validation-attachment/validation-attachment.component.ts @@ -15,21 +15,26 @@ export class ValidationAttachmentComponent implements OnInit { constructor(private adminService: AdminService) {} ngOnInit(): void { - this.demandsAttachment = this.adminService.getPendingAttachmentsStructure(); + this.adminService.getPendingAttachmentsStructure().subscribe((demands) => { + this.demandsAttachment = demands; + }); } + // Todo : Appeler removeDemand(demand) dans le subscribe de acceptAttachmentStructure() quand l'api sera faite. public acceptDemand(demand: demandAttachment): void { console.log('accept'); - this.removeDemand(demand); this.adminService.acceptAttachmentStructure(demand.userEmail, demand.structureId); + this.removeDemand(demand); } + // Todo : Appeler removeDemand(demand) dans le subscribe de acceptAttachmentStructure() quand l'api sera faite. public refuseDemand(demand: demandAttachment): void { console.log('refuse'); this.adminService.refuseAttachmentStructure(demand.userEmail, demand.structureId); this.removeDemand(demand); } + // Remove the request that was accepted or refused private removeDemand(demand: demandAttachment): void { const index = this.demandsAttachment.findIndex((d: demandAttachment) => d === demand); if (index > -1) { diff --git a/src/app/admin/models/demandAttachment.model.ts b/src/app/admin/models/demandAttachment.model.ts index 497b93b81..a7fb8378f 100644 --- a/src/app/admin/models/demandAttachment.model.ts +++ b/src/app/admin/models/demandAttachment.model.ts @@ -1,6 +1,3 @@ -import { Structure } from '../../models/structure.model'; -import { User } from '../../models/user.model'; - export class demandAttachment { userEmail: string; structureId: number; diff --git a/src/app/admin/services/admin.service.ts b/src/app/admin/services/admin.service.ts index f5f928647..4b50fd04a 100644 --- a/src/app/admin/services/admin.service.ts +++ b/src/app/admin/services/admin.service.ts @@ -1,20 +1,22 @@ +import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; import { demandAttachment } from '../models/demandAttachment.model'; @Injectable({ providedIn: 'root', }) export class AdminService { - constructor() {} + constructor(private http: HttpClient) {} // Return pendingAttachments of all profiles. - public getPendingAttachmentsStructure(): demandAttachment[] { - return [{ userEmail: 'jb@test.fr', structureId: 53 }]; + public getPendingAttachmentsStructure(): Observable<demandAttachment[]> { + return this.http.get<any>('api/users/pendingAttachments'); } - // Post - public acceptAttachmentStructure(mailUser, idStructure): void {} + // Todo : Api post qui retourne vrai si aucune erreur sinon httpException + public acceptAttachmentStructure(mailUser, idStructure) {} - // Post - public refuseAttachmentStructure(mailUser, idStructure): void {} + // Todo : Api post qui retourne vrai si aucune erreur sinon httpException + public refuseAttachmentStructure(mailUser, idStructure) {} } -- GitLab