From 011bfd88147db140261a4f496344869a17ba2420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yana=C3=ABl=20GRETTE?= Date: Tue, 23 Feb 2021 13:08:57 +0100 Subject: [PATCH] Ajout dun module ep-table --- .../shared/mat-tables/ep-table/ep-table.css | 0 .../shared/mat-tables/ep-table/ep-table.html | 123 +++++++++ .../shared/mat-tables/ep-table/ep-table.ts | 251 ++++++++++++++++++ .../shared/mat-tables/mat-tables.module.ts | 7 +- src/app/shared/utils/cles.ts | 5 + 5 files changed, 384 insertions(+), 2 deletions(-) create mode 100644 src/app/shared/mat-tables/ep-table/ep-table.css create mode 100644 src/app/shared/mat-tables/ep-table/ep-table.html create mode 100644 src/app/shared/mat-tables/ep-table/ep-table.ts diff --git a/src/app/shared/mat-tables/ep-table/ep-table.css b/src/app/shared/mat-tables/ep-table/ep-table.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/shared/mat-tables/ep-table/ep-table.html b/src/app/shared/mat-tables/ep-table/ep-table.html new file mode 100644 index 0000000..cc5be97 --- /dev/null +++ b/src/app/shared/mat-tables/ep-table/ep-table.html @@ -0,0 +1,123 @@ + + + + + + + Rechercher une un collaborateur + + + + + + + + + + + + + + + + + + Date de début + + clear + + + + + + + Date de fin + + clear + + + + + + + + + Business Unit + + + + {{row.collaborateur.businessUnit.nom}} + + + + Collaborateur + {{row.collaborateur.nom}} {{row.collaborateur.prenom}} + + + + Référent + {{row.referent.nom}} {{row.referent.prenom}} + + + + Date d'embauche + {{row.collaborateur.datearrivee | date : 'dd/MM/yyyy'}} + + + + Staut de l'EP + {{ afficherStatutEP(row.statut)}} + + + + Type EP + {{ afficherTypeEP(row.type) }} + + + + Date prévisionnelle + {{ row.dataPrevisionnelle | date : 'dd/MM/yyyy'}} + + + + + {{ row.dateDisponibilite | date : 'dd/MM/yyyy'}} + + + + + Consulter EP + + + + + + + + + + \ No newline at end of file diff --git a/src/app/shared/mat-tables/ep-table/ep-table.ts b/src/app/shared/mat-tables/ep-table/ep-table.ts new file mode 100644 index 0000000..ecd2611 --- /dev/null +++ b/src/app/shared/mat-tables/ep-table/ep-table.ts @@ -0,0 +1,251 @@ +import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core"; +import { MatTableDataSource } from "@angular/material/table"; +import { BusinessUnitDTO, CollaborateurDTO, EpInformationDTO, EpService, StatutEp, TypeEp } from "@shared/api-swagger"; +import { cles, epTypeRecherche } from "@shared/utils/cles"; +import { Subscription } from "rxjs"; + +@Component({ + selector: "ep-table", + templateUrl: "./ep-table.html" +}) +export class EpTableComponent implements OnInit{ + chargement: boolean = true; + + + /** + * * Ordre de tri à envoyer au serveur (true : croissant, false : décroissantà). + */ + asc : boolean = true; + + /** + * Numéro de la page à afficher dans le tableau. + */ + numPage: number = 1; + + /** + * Nombre d'élément du tableau à affiche en une page. + */ + parPage: number = 15; + + /** + * Nombre total d'élément du tableau + */ + taille: number = 0; + + /** + * Liste des business units du collaborateur connecté + */ + bus: Array = []; + + /** + * contenu de la recherche pour trouver un collaborateur. + */ + search: string = ""; + + /** + * Options pour choisir le nombre de page à affiche + */ + pageOption = [ 5, 15, 20, 30, 50]; + + /** + * Permet de savoir sur quelle attribut d'un CollaborateurDTO doit être trié le tableau. + */ + tri: string = "dateprevisionnelle"; + + /** + * Liste des id des business units des collaborateurs à afficher + */ + private busIds: Array = []; + + dateDebut : Date; + + dateFin: Date; + + dataSource : MatTableDataSource; + + @Input() typeRechercheEP : string; + + @Input() displayedColumns: string[]; + + @Input() rechercherParBU: boolean = true; + + + @Input() rechercherParDate: boolean = true; + + @Output() eventEmitter: EventEmitter; + + + epSubscription: Subscription; + epCountSubscription: Subscription; + + + constructor(private epService: EpService) {} + + ngOnInit() { + this.setBUsId(); + } + + updateDataSource() { + switch(this.typeRechercheEP) { + case epTypeRecherche.EPEnCours: + this.getEPEnCours(); + break; + case epTypeRecherche.EPSignes: + this.getEPEnSignes(); + break; + } + + } + + getEPEnCours() { + this.epSubscription = this.epService.getEPEnCours(this.busIds, this.asc, this.numPage, this.parPage, this.search, this.tri, this.dateDebut, this.dateFin).subscribe( + eps => { + this.dataSource = new MatTableDataSource(eps); + this.epCountSubscription = this.epService.getEPEnCoursCount(this.busIds, this.asc, this.numPage, this.parPage, this.search, this.tri, this.dateDebut, this.dateFin).subscribe( + count => this.taille = count, + err => console.log(err) + ); + }, + err => console.log(err) + ); + } + + getEPEnSignes() { + this.epSubscription = this.epService.getEPSignes(this.busIds, this.asc, this.numPage, this.parPage, this.search, this.tri, this.dateDebut, this.dateFin).subscribe( + eps => { + this.dataSource = new MatTableDataSource(eps); + this.epCountSubscription = this.epService.getEPSignesCount(this.busIds, this.asc, this.numPage, this.parPage, this.search, this.tri, this.dateDebut, this.dateFin).subscribe( + count => this.taille = count, + err => console.log(err) + ); + }, + err => console.log(err) + ); + } + + /** + * création de la liste des business unit du collaborateur connecté pour afficher les checkboxes + */ + setBUsId() { + if(sessionStorage.getItem(cles.sessionKeyConnectee) == undefined){ + setTimeout( () => this.setBUsId(), 1000); + } + else { + const collaborateurConnecte : CollaborateurDTO = JSON.parse(sessionStorage.getItem(cles.sessionKeyConnectee)); + this.bus = collaborateurConnecte.businessUnit.agence.bu; + for(let bu of this.bus) { + this.busIds.push(bu.id); + } + this.updateDataSource(); + this.chargement = false; + } + } + + /** + * Mettre à undefined la date de début ou la date de fin + * @param val Valeur pour inidiquer quel variable doit être mis à undefined + */ + updateDateToUndefined(val : number) { + if(val == 1) + this.dateDebut = undefined; + if(val == 2) + this.dateFin = undefined; + this.updateDataSource(); + } + + /** + * Mettre à jour le nomre d'élément à afficher par page et le numéro de la page + * @param event évènement de la pagination + */ + updatePageInfo(event){ + this.parPage = event.pageSize; + this.numPage = event.pageIndex+1; + this.updateDataSource(); + } + + /** + * Remettre au début la liste lors d'une recherche via la barre de recherche + */ + setSearch() { + this.numPage = 1; + this.updateDataSource(); + } + + /** + * Vider la barre de recherche et remettre le tableau à la première page + */ + resetSearch() { + this.search = ""; + this.setSearch(); + } + + + afficherStatutEP(statut: StatutEp) { + return "statut"; + } + + afficherTypeEP(type: TypeEp) { + return "typeEP" + } + + /** + * Mettre à jour toutes les checkox + * @param event case cochée ou décochée + * */ + updateAllCheckbox(event) { + this.busIds = []; + // si la checkbox a été cochée + if(event) + this.bus.map(statut => this.busIds.push(statut.id)); + else + this.busIds = []; + + this.numPage = 1; + this.updateDataSource(); + } + + /** + * Mettre à jour la liste des + * @param event case cochée ou décochée + * @param bu business unit concerné par la checkbox cochée ou décochée + */ + updateCheckbox(event, bu) { + // si la checkbox a été cochée + if(event) { + this.busIds.push(bu.id) + } + else{ + this.busIds = this.busIds.filter( (id) => id != bu.id); + } + this.numPage = 1; + this.updateDataSource(); + } + + /** + * Trier le tableau en fonction de l'évènement de la colonne + * @param e évènement du tri + */ + triTableau(e) { + this.tri = e.active; + switch(e.direction) { + case "asc": + this.asc = true; + break; + case "desc": + this.asc = false; + break; + } + this.updateDataSource(); + } + + + ngDestroy() { + if(!this.epSubscription != undefined) { + this.epSubscription.unsubscribe(); + } + + if(!this.epCountSubscription != undefined) { + this.epCountSubscription.unsubscribe(); + } + } +} \ No newline at end of file diff --git a/src/app/shared/mat-tables/mat-tables.module.ts b/src/app/shared/mat-tables/mat-tables.module.ts index 94e3941..ef79079 100644 --- a/src/app/shared/mat-tables/mat-tables.module.ts +++ b/src/app/shared/mat-tables/mat-tables.module.ts @@ -8,13 +8,15 @@ import { CollaborateursTableComponent } from "@shared/mat-tables/collaborateurs- import { EngagementTableComponent } from "@shared/mat-tables/engagements-table/engagements-table" import { FormationsTableComponent } from "@shared/mat-tables/formations-table/formations.table"; import { FilterModule } from "@shared/filter/filter.module"; +import { EpTableComponent } from "./ep-table/ep-table"; @NgModule({ declarations: [ CollaborateursTableComponent, EngagementTableComponent, - FormationsTableComponent + FormationsTableComponent , + EpTableComponent, ], imports: [ MaterialModule, @@ -26,7 +28,8 @@ import { FilterModule } from "@shared/filter/filter.module"; exports: [ CollaborateursTableComponent, EngagementTableComponent, - FormationsTableComponent + FormationsTableComponent, + EpTableComponent ] }) export class MatTablesModule {} diff --git a/src/app/shared/utils/cles.ts b/src/app/shared/utils/cles.ts index ac3f33d..d2154cd 100644 --- a/src/app/shared/utils/cles.ts +++ b/src/app/shared/utils/cles.ts @@ -12,4 +12,9 @@ export const engagementTypeRecherche = { saisieEP: "saisieEP", consultationEP: "consultationEP", engagementsRH: "engagementRH" +} + +export const epTypeRecherche = { + EPEnCours: "EPEnCours", + EPSignes: "EPSignes" } \ No newline at end of file