From 940cdd88014dde0e71084057b7cdd3344615e661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yana=C3=ABl=20GRETTE?= Date: Fri, 5 Feb 2021 10:43:31 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20l'affichage=20de=20?= =?UTF-8?q?la=20liste=20des=20r=C3=A9f=C3=A9rents=20avec=20un=20fonctionne?= =?UTF-8?q?ment=20similaire=20que=20celui=20de=20la=20page=20de=20la=20lis?= =?UTF-8?q?te=20des=20collaborateurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../collaborateurs.component.html | 10 +- .../collaborateurs.component.ts | 25 ++-- src/app/referents/referents.component.html | 61 ++++++-- src/app/referents/referents.component.ts | 141 +++++++++++++++--- src/app/referents/referents.module.ts | 4 +- 5 files changed, 187 insertions(+), 54 deletions(-) diff --git a/src/app/collaborateurs/collaborateurs.component.html b/src/app/collaborateurs/collaborateurs.component.html index 60cd2e3..1629be5 100644 --- a/src/app/collaborateurs/collaborateurs.component.html +++ b/src/app/collaborateurs/collaborateurs.component.html @@ -17,16 +17,16 @@ - - - + + - + + Date de début @@ -80,7 +80,7 @@ [pageIndex]="numPage-1" [pageSize]="parPage" [pageSizeOptions]="pageOption" - (page)="pageEvent = updatePageInfo($event)" + (page)="updatePageInfo($event)" > diff --git a/src/app/collaborateurs/collaborateurs.component.ts b/src/app/collaborateurs/collaborateurs.component.ts index 0691473..b54bba2 100644 --- a/src/app/collaborateurs/collaborateurs.component.ts +++ b/src/app/collaborateurs/collaborateurs.component.ts @@ -1,12 +1,9 @@ -import { Component, OnInit, OnDestroy, ViewChild, ViewChildren } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; -import { MatDatepickerInputEvent } from '@angular/material/datepicker'; -import { Observable, Subscription } from 'rxjs'; +import { Subscription } from 'rxjs'; import {MatTableDataSource} from '@angular/material/table'; -import {MatPaginator, PageEvent} from '@angular/material/paginator'; -import {MatSort} from '@angular/material/sort'; import { BusinessUnitDTO, CollaborateurDTO } from '@shared/api-swagger/model/models' import { CollaborateursService } from "@shared/api-swagger/api/api"; @@ -39,16 +36,18 @@ export class CollaborateursComponent implements OnInit { /** * Rôle des collaborateurs à récupérer via le service collaborateur, ici nous ne voulons que les collaborateurs (pour le moment...). */ - roles : string[] = []; + private roles : string[] = ["Collaborateur"]; /** * Observable pour faire des requêtes sur le service collaborateur. */ private collaborateursDisponiblesSubscription : Subscription; - /** - * Observable pour faire des requêtes sur le service collaborateur. - */ - private collaborateursDisponiblesCountSubscription : Subscription; + /** + * Observable pour faire des requêtes sur le service collaborateur. + */ + private collaborateursDisponiblesCountSubscription : Subscription; + + /** * Liste des colonnes du tableau à afficher. */ displayedColumns : string[] = ["businessunit", "collaborateur", "datearrivee", "referent"]; @@ -89,9 +88,6 @@ export class CollaborateursComponent implements OnInit { */ pageOption = [ 5, 15, 20, 30, 50]; - pageEvent: PageEvent; - - /** * Spécifie si la liste des collaborateurs est en cours de chargement dans le tableau. */ @@ -151,11 +147,10 @@ export class CollaborateursComponent implements OnInit { * 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) : PageEvent{ + updatePageInfo(event){ this.parPage = event.pageSize; this.numPage = event.pageIndex+1; this.updateDataSource(); - return event; } /** diff --git a/src/app/referents/referents.component.html b/src/app/referents/referents.component.html index 2d6ac8e..45b1a41 100644 --- a/src/app/referents/referents.component.html +++ b/src/app/referents/referents.component.html @@ -1,20 +1,51 @@

Liste des référents

- - - - Agence - {{ row.businessUnit.nom}} - + + + - - Référent - - {{row.prenom}} {{row.nom}} - + + + + Rechercher un référent + + + close + + + + +
    +
  • + {{bu.nom}} +
  • +
+ + + + + Agence + {{ row.businessUnit.nom}} + + + + Référent + {{row.nom}} {{row.prenom}} + + + + + + + + + - - - -
+ \ No newline at end of file diff --git a/src/app/referents/referents.component.ts b/src/app/referents/referents.component.ts index 8b8f268..d468a28 100644 --- a/src/app/referents/referents.component.ts +++ b/src/app/referents/referents.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy, ViewChild, ViewChildren } from '@angular/core'; +import { Component, OnInit, ViewChild } from '@angular/core'; import { Subscription } from 'rxjs'; @@ -8,8 +8,8 @@ import {MatSort} from '@angular/material/sort'; import { CollaborateursService } from "@shared/api-swagger/api/api"; -import { CollaborateurDTO } from "@shared/api-swagger/model/models"; - +import { BusinessUnitDTO, CollaborateurDTO } from "@shared/api-swagger/model/models"; +import { CollaborateurConnecte } from "@shared/globales/collaborateur-connecte" /** */ @@ -30,7 +30,7 @@ export class ReferentsComponent implements OnInit { /** * Nombre d'élément du tableau à affiche en une page. */ - parPage = 5; + parPage = 15; /** * Rôle des collaborateurs à récupérer via le service collaborateur, ici nous ne voulons que les collaborateurs (pour le moment...). */ @@ -40,10 +40,15 @@ export class ReferentsComponent implements OnInit { */ private referentsDisponiblesSubscription : Subscription; + /** + * Observable pour faire des requêtes sur le service référent. + */ + private referentsDisponiblesCountSubscription : Subscription; + /** * Liste des colonnes du tableau à afficher. */ - displayedColumns : string[] = ["agence", "referent"]; + displayedColumns : string[] = ["businessunit", "collaborateur"]; /** * Objet pour stocker la liste des référents qui seront récupérés par le service référént @@ -52,34 +57,49 @@ export class ReferentsComponent implements OnInit { /** * Liste des rôles pour préciser que l'on souhaite récupérer les commerciaux */ - roles : string[] = ["referent"]; + roles : string[] = ["Manager", "RA", "CP", "TL"]; + + /** * contenu de la recherche. */ search = ""; + /** * Permet d'indiquer au serveur sur quel attribut de l'objet CollaborateurDTO on souhaite faire le tri */ - tri = ""; + tri = "collaborateur"; + /** - * Pagination du tableau. - */ - @ViewChild(MatPaginator) paginator: MatPaginator; + * Options pour choisir le nombre de page à affiche + */ + pageOption = [ 5, 15, 20, 30, 50]; + + /** + * Liste des business units du collaborateur connecté + */ + bus: Array = []; /** - * Tri par les éléments du tableau selon la colonne choisie. - */ - @ViewChild(MatSort) sort: MatSort; + * Liste des id des business units des collaborateurs à afficher + */ + private busIds: Array = []; + + /** + * Nombre total d'élément du tableau + */ + taille: number; + /** * Spécifie si la liste des référents est en cours de chargement et d'écriture dans le tableau. */ chargement = true; - constructor(private service: CollaborateursService) {} + constructor(private service: CollaborateursService, private collaborateurConnecte: CollaborateurConnecte) {} ngOnInit() { - this.updateDataSource(); + this.setBUsId(); } /** @@ -87,12 +107,97 @@ export class ReferentsComponent implements OnInit { * Devra se faire à l'ouverture de la page, au changement de page ou du nombre d'éléments à afficher, au moment d'un tri ou encore lors de l'utilisation de la barre de recherche. */ updateDataSource() { - this.referentsDisponiblesSubscription = this.service.getCollaborateurs(this.roles,[1],this.asc, this.numPage, this.parPage, this.search, this.tri).subscribe( + if(this.busIds.length == 0) { + this.taille = 0; + this.dataSource = new MatTableDataSource(undefined); + return; + } + this.referentsDisponiblesSubscription = this.service.getCollaborateurs(this.roles, this.busIds,this.asc, this.numPage, this.parPage, this.search, this.tri).subscribe( referents => this.dataSource = new MatTableDataSource(referents), err => console.log(err) ); - //this.dataSource.paginator = this.paginator; - //this.dataSource.sort = this.sort; + this.referentsDisponiblesCountSubscription = this.service.getCollaborateursCount(this.roles, this.busIds, this.asc, this.numPage, this.parPage, this.search, this.tri).subscribe( + count => this.taille=count, + err => console.log(err) + ); + } + + /** + * 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(); + } + + + /** + * 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(); + } + + /** + * création de la liste des business unit du collaborateur connecté pour afficher les checkboxes + */ + setBUsId() { + if(this.collaborateurConnecte.collaborateur == undefined) { + setTimeout( () => this.setBUsId(), 1000); + } + else { + this.bus = this.collaborateurConnecte.collaborateur.businessUnit.agence.bu; + for(let bu of this.bus) { + this.busIds.push(bu.id); + } + this.updateDataSource(); + this.chargement = false; + } + } + + /** + * Vider la barre de recherche et remettre le tableau à la première page + */ + resetSearch() { + this.search = ""; + this.setSearch(); + } + + /** + * 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(); } /** diff --git a/src/app/referents/referents.module.ts b/src/app/referents/referents.module.ts index 931fff6..5ecdd9f 100644 --- a/src/app/referents/referents.module.ts +++ b/src/app/referents/referents.module.ts @@ -1,7 +1,7 @@ import { NgModule } from "@angular/core"; import { CommonModule } from "@angular/common"; import { RouterModule } from '@angular/router'; - +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MaterialModule } from "@shared/angular-material/angular-material.module"; import {NavMenuModule} from '@shared/nav-menu/nav-menu.module'; @@ -19,7 +19,9 @@ import { ReferentsRoutingModule } from './referents.routing.module'; CommonModule, MaterialModule, NavMenuModule, + FormsModule, RouterModule, + ReactiveFormsModule, ReferentsRoutingModule ], })