diff --git a/src/app/referents/assignation-referent/assignation-referent.component.html b/src/app/referents/assignation-referent/assignation-referent.component.html index 3930f8b..645b1e0 100644 --- a/src/app/referents/assignation-referent/assignation-referent.component.html +++ b/src/app/referents/assignation-referent/assignation-referent.component.html @@ -9,7 +9,8 @@ - + +

Référent sélectionné : {{referentChoisi.nom}} {{referentChoisi.prenom}}

Veuillez sélectionner un collaborateur

@@ -25,11 +26,18 @@ - +
- - +

Référent sélectionné : {{referentChoisi.nom}} {{referentChoisi.prenom}}

+

Collaborateurs sélectionnés :

+ + + {{collaborateur.nom}} {{collaborateur.prenom}} + + +
\ No newline at end of file diff --git a/src/app/referents/assignation-referent/assignation-referent.component.ts b/src/app/referents/assignation-referent/assignation-referent.component.ts index 7308e16..08c351c 100644 --- a/src/app/referents/assignation-referent/assignation-referent.component.ts +++ b/src/app/referents/assignation-referent/assignation-referent.component.ts @@ -1,14 +1,21 @@ -import { Component, OnInit } from "@angular/core"; -import { CollaborateurDTO, CollaborateursService } from "@shared/api-swagger"; +import { Component, Inject } from "@angular/core"; +import { CollaborateurDTO, CollaborateursService, ReferentsEPService, ReferentEPDTO } from "@shared/api-swagger"; import { collaborateurTypeRecherche } from "@shared/utils/cles"; + +import {MatDialog, MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog'; +import { MatSnackBar } from '@angular/material/snack-bar'; + + import { Subscription } from "rxjs"; +import { Router } from "@angular/router"; + + @Component({ selector: 'assignation-referent', templateUrl: './assignation-referent.component.html' }) -export class AssignationReferentComponent implements OnInit { - +export class AssignationReferentComponent { rechercherParDate: boolean = false; rechercherParBu: boolean = true; @@ -40,13 +47,13 @@ export class AssignationReferentComponent implements OnInit { collaborateurSubscription: Subscription; - constructor(private collaborateurService: CollaborateursService) {} - - ngOnInit() { + referentEPSubscription: Subscription; + constructor(private collaborateurService: CollaborateursService, private referentEPService: ReferentsEPService, private dialog: MatDialog, + private snackBar: MatSnackBar) { } - choixReferent(event) { + choixReferent(event: any) { this.referentChoisi = event.collaborateur; this.setCollaborateurEP(); } @@ -55,21 +62,101 @@ export class AssignationReferentComponent implements OnInit { this.collaborateurSubscription = this.collaborateurService.getCollaborateursByReferent(this.referentChoisi.id).subscribe( collaborateurs => { this.collaborateursEP = collaborateurs; - + this.collaborateursSelectionnes = this.collaborateursSelectionnes.filter(c => !this.contientCollaborateur(this.collaborateursEP, c)); }, error => console.log(error) ); } ajoutCollaborateur(event:any) { - console.log(event); - if(!this.collaborateursSelectionnes.includes(event.collaborateur)) - this.collaborateursSelectionnes.push(event.collaborateur); - console.log(this.collaborateursSelectionnes); + if(event.type != "collaborateur") + return; + if(event.collaborateur.id == this.referentChoisi.id) { + this.openSnackBar("Un collaborateur ne peut pas être son propre référent"); + return; + } + if(this.contientCollaborateur(this.collaborateursSelectionnes, event.collaborateur)){ + this.enleverCollaborateur(event.collaborateur); + return; + } + if(this.contientCollaborateur(this.collaborateursEP, event.collaborateur)){ + this.openSnackBar("Le référent choisi est déjà le référent EP du collaborateur sélectionné") + return; + } + this.collaborateursSelectionnes.push(event.collaborateur); + } + + peutAjouterCollaborateur(event) : boolean { + return event.type == "collaborateur" && !this.collaborateursSelectionnes.some(event.collaborateur) && !this.collaborateursEP.includes(event.collaborateur); + } + + contientCollaborateur(listes: CollaborateurDTO[], collaborateur: CollaborateurDTO ) : boolean { + return listes.some(c => c.id == collaborateur.id); } enleverCollaborateur(collaborateur: CollaborateurDTO) { this.collaborateursSelectionnes = this.collaborateursSelectionnes.filter(c => c.id != collaborateur.id); } + mettreAJourReferentEP() { + const referentEP :ReferentEPDTO = { + idReferent: this.referentChoisi.id, + idsCollaborateur: this.collaborateursSelectionnes.map( collaborateur => collaborateur.id) + }; + this.referentEPSubscription = this.referentEPService.updateCollaborateursReferent(referentEP, this.referentChoisi.id).subscribe( + () => this.openDialog(), + err => console.log(err) + ) + } + + openDialog() { + this.dialog.open(DialogAssignationReferentComponent, { disableClose: true, data: this.referentChoisi.id}); + } + + openSnackBar(message: string) { + this.snackBar.open(message,"", { + duration: 5000, + horizontalPosition: "center", + verticalPosition: "top", + }); + } + + /* + etapeAccessible(etape: number) { + switch(etape) { + case 1: + if(this.referentChoisi == undefined) + this.openSnackBar("Vous devez choisir un référent avant d'accéder à l'étape 2"); + break; + case 2: + if(this.collaborateursSelectionnes.length == 0) + this.openSnackBar("Vous devez sélectionner au moins un collaborateur pour accéder à l'étape de confirmation"); + break; + } + }*/ + +} + +@Component({ + selector: "dialog-assignation-referent", + templateUrl: "dialog-assignation-referent.html" +}) +export class DialogAssignationReferentComponent { + constructor(private dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) private data: string, private router: Router) { + } + + + home() { + this.router.navigate(["/home"]); + this.dialogRef.close(); + } + + detailsReferent() { + this.router.navigate(["/referents", this.data]); + this.dialogRef.close(); + } + + nouvelleAssignation() { + location.reload(); + } } \ No newline at end of file diff --git a/src/app/referents/assignation-referent/dialog-assignation-referent.html b/src/app/referents/assignation-referent/dialog-assignation-referent.html new file mode 100644 index 0000000..68c3a1c --- /dev/null +++ b/src/app/referents/assignation-referent/dialog-assignation-referent.html @@ -0,0 +1,4 @@ +

La mise à jour du référent a été effectué avec succès

+ + + \ No newline at end of file diff --git a/src/app/referents/referents.module.ts b/src/app/referents/referents.module.ts index 4aa108e..2879938 100644 --- a/src/app/referents/referents.module.ts +++ b/src/app/referents/referents.module.ts @@ -10,11 +10,12 @@ import { MatTablesModule } from "@shared/mat-tables/mat-tables.module"; import { ReferentsComponent } from './referents.component'; import { DetailsReferentComponent } from './details-referent/details-referent.component'; import { ReferentsRoutingModule } from './referents.routing.module'; -import { AssignationReferentComponent } from "./assignation-referent/assignation-referent.component"; +import { AssignationReferentComponent, DialogAssignationReferentComponent } from "./assignation-referent/assignation-referent.component"; @NgModule({ declarations: [ DetailsReferentComponent, - ReferentsComponent, AssignationReferentComponent + ReferentsComponent, AssignationReferentComponent, + DialogAssignationReferentComponent ], exports: [ ReferentsComponent ], diff --git a/src/app/shared/angular-material/angular-material.module.ts b/src/app/shared/angular-material/angular-material.module.ts index 538300c..ceda0f8 100644 --- a/src/app/shared/angular-material/angular-material.module.ts +++ b/src/app/shared/angular-material/angular-material.module.ts @@ -18,7 +18,7 @@ import {MatCheckboxModule} from '@angular/material/checkbox'; import {MatSelectModule} from '@angular/material/select'; import {MatStepperModule} from '@angular/material/stepper'; import {MatChipsModule} from '@angular/material/chips'; - +import {MatSnackBarModule} from '@angular/material/snack-bar'; import { NgxMatDatetimePickerModule, NgxMatTimepickerModule, NgxMatNativeDateModule } from '@angular-material-components/datetime-picker'; @@ -36,7 +36,7 @@ import { NgxMatDatetimePickerModule, NgxMatTimepickerModule, NgxMatNativeDateMod NgxMatDatetimePickerModule, MatDatepickerModule, NgxMatNativeDateModule, MatNativeDateModule, MatCheckboxModule, MatSelectModule, MatStepperModule, - MatChipsModule + MatChipsModule, MatSnackBarModule ], exports : [MatCardModule, MatButtonModule, MatMenuModule, @@ -47,7 +47,7 @@ import { NgxMatDatetimePickerModule, NgxMatTimepickerModule, NgxMatNativeDateMod NgxMatDatetimePickerModule, MatDatepickerModule, NgxMatNativeDateModule, MatNativeDateModule, MatCheckboxModule, MatSelectModule, MatStepperModule, - MatChipsModule + MatChipsModule, MatSnackBarModule ] }) export class MaterialModule {} diff --git a/src/app/shared/mat-tables/collaborateurs-table/collaborateurs.table.css b/src/app/shared/mat-tables/collaborateurs-table/collaborateurs.table.css index 9191d36..278feb0 100644 --- a/src/app/shared/mat-tables/collaborateurs-table/collaborateurs.table.css +++ b/src/app/shared/mat-tables/collaborateurs-table/collaborateurs.table.css @@ -1,7 +1,7 @@ .collaborateurAjoute { - background-color: dodgerblue; + background-color: #5cb85c; } .dejaCollaborateurEP { - background-color: red; + background-color: #337ab7; } \ No newline at end of file diff --git a/src/app/shared/mat-tables/collaborateurs-table/collaborateurs.table.html b/src/app/shared/mat-tables/collaborateurs-table/collaborateurs.table.html index 79d3352..4073e78 100644 --- a/src/app/shared/mat-tables/collaborateurs-table/collaborateurs.table.html +++ b/src/app/shared/mat-tables/collaborateurs-table/collaborateurs.table.html @@ -16,11 +16,7 @@ -
    -
  • - {{bu.nom}} -
  • -
+ {{bu.nom}}
@@ -72,7 +68,7 @@ - + c.id == collaborateur.id); + } + /** * Mettre à jour la liste des * @param event case cochée ou décochée @@ -306,4 +319,5 @@ export class CollaborateursTableComponent implements OnInit { this.collaborateursDisponiblesCountSubscription.unsubscribe(); } } -} \ No newline at end of file + } + \ No newline at end of file