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 46ad936006602ba6b4bd0c54d57b47acba4cd2de..cd68a92cd8eb5d379d1fb54bf60bb711f962f2a5 100644 --- a/src/app/admin/components/validation-attachment/validation-attachment.component.html +++ b/src/app/admin/components/validation-attachment/validation-attachment.component.html @@ -1 +1,21 @@ -<div fxLayout="row" fxLayoutAlign="center center"><p>validation-attachment works!</p></div> +<div fxLayout="row" fxLayoutAlign="center center"> + <table> + <thead> + <th>Utilisateur</th> + <th>Structure</th> + <th>Options</th> + </thead> + <tbody> + <tr *ngFor="let demand of demandsAttachment"> + <td>{{ demand.user.email }}</td> + <td>{{ demande.structure.structureName }}</td> + <td> + <button (click)="acceptDemand(demand)">Valider</button><button (click)="refuseDemand(demand)">Refuser</button> + </td> + </tr> + <tr *ngIf="!demandsAttachment.length"> + <td colspan="3">Aucune demande en attente</td> + </tr> + </tbody> + </table> +</div> 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 09d9095c6f6994ad277863d807726d7770cc4e75..4211d3c0a5b45496314f2a071b7e8b1df7a0a8bf 100644 --- a/src/app/admin/components/validation-attachment/validation-attachment.component.ts +++ b/src/app/admin/components/validation-attachment/validation-attachment.component.ts @@ -1,4 +1,9 @@ import { Component, OnInit } from '@angular/core'; +import { userInfo } from 'os'; +import { Structure } from '../../../models/structure.model'; +import { User } from '../../../models/user.model'; +import { demandAttachment } from '../../models/demandAttachment.model'; +import { AdminService } from '../../services/admin.service'; @Component({ selector: 'app-admin-validation-attachment', @@ -6,7 +11,30 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./validation-attachment.component.scss'], }) export class ValidationAttachmentComponent implements OnInit { - constructor() {} + demandsAttachment: demandAttachment[]; + constructor(private adminService: AdminService) {} - ngOnInit(): void {} + ngOnInit(): void { + this.demandsAttachment = this.adminService.getPendingAttachmentsStructure(); + } + + public acceptDemand(demand: demandAttachment): void { + console.log('accept'); + this.removeDemand(demand); + + this.adminService.acceptAttachmentStructure(demand.user.email, demand.structure.id); + } + + public refuseDemand(demand: demandAttachment): void { + console.log('refuse'); + this.adminService.refuseAttachmentStructure(demand.user.email, demand.structure.id); + this.removeDemand(demand); + } + + private removeDemand(demand: demandAttachment): void { + const index = this.demandsAttachment.findIndex((d: demandAttachment) => d === demand); + if (index > -1) { + this.demandsAttachment.splice(index, 1); + } + } } diff --git a/src/app/admin/models/demandAttachment.model.ts b/src/app/admin/models/demandAttachment.model.ts new file mode 100644 index 0000000000000000000000000000000000000000..26509d27790584d34cfd78b05337fbc438abeeb0 --- /dev/null +++ b/src/app/admin/models/demandAttachment.model.ts @@ -0,0 +1,7 @@ +import { Structure } from '../../models/structure.model'; +import { User } from '../../models/user.model'; + +export class demandAttachment { + user: User; + structure: Structure; +} diff --git a/src/app/admin/services/admin.service.spec.ts b/src/app/admin/services/admin.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..c83b4be6f9ceda3a120fa4568447d71178ea4373 --- /dev/null +++ b/src/app/admin/services/admin.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { AdminService } from './admin.service'; + +describe('AdminService', () => { + let service: AdminService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(AdminService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/admin/services/admin.service.ts b/src/app/admin/services/admin.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..dac27d9c343005190a753a9c8610451d828b1649 --- /dev/null +++ b/src/app/admin/services/admin.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@angular/core'; +import { demandAttachment } from '../models/demandAttachment.model'; + +@Injectable({ + providedIn: 'root', +}) +export class AdminService { + constructor() {} + + // Return pendingAttachments of all profiles. + public getPendingAttachmentsStructure(): demandAttachment[] { + return [new demandAttachment()]; + } + + public acceptAttachmentStructure(mailUser, idStructure): void {} + public refuseAttachmentStructure(mailUser, idStructure): void {} +}