|
|
@ -1,14 +1,21 @@ |
|
|
|
import { Component, OnInit } from "@angular/core"; |
|
|
|
import { Component, Inject } from "@angular/core"; |
|
|
|
import { CollaborateurDTO, CollaborateursService } from "@shared/api-swagger"; |
|
|
|
import { CollaborateurDTO, CollaborateursService, ReferentsEPService, ReferentEPDTO } from "@shared/api-swagger"; |
|
|
|
import { collaborateurTypeRecherche } from "@shared/utils/cles"; |
|
|
|
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 { Subscription } from "rxjs"; |
|
|
|
|
|
|
|
import { Router } from "@angular/router"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
@Component({ |
|
|
|
selector: 'assignation-referent', |
|
|
|
selector: 'assignation-referent', |
|
|
|
templateUrl: './assignation-referent.component.html' |
|
|
|
templateUrl: './assignation-referent.component.html' |
|
|
|
}) |
|
|
|
}) |
|
|
|
export class AssignationReferentComponent implements OnInit { |
|
|
|
export class AssignationReferentComponent { |
|
|
|
|
|
|
|
|
|
|
|
rechercherParDate: boolean = false; |
|
|
|
rechercherParDate: boolean = false; |
|
|
|
|
|
|
|
|
|
|
|
rechercherParBu: boolean = true; |
|
|
|
rechercherParBu: boolean = true; |
|
|
@ -40,13 +47,13 @@ export class AssignationReferentComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
|
|
collaborateurSubscription: Subscription; |
|
|
|
collaborateurSubscription: Subscription; |
|
|
|
|
|
|
|
|
|
|
|
constructor(private collaborateurService: CollaborateursService) {} |
|
|
|
referentEPSubscription: Subscription; |
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private collaborateurService: CollaborateursService, private referentEPService: ReferentsEPService, private dialog: MatDialog, |
|
|
|
|
|
|
|
private snackBar: MatSnackBar) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
choixReferent(event) { |
|
|
|
choixReferent(event: any) { |
|
|
|
this.referentChoisi = event.collaborateur; |
|
|
|
this.referentChoisi = event.collaborateur; |
|
|
|
this.setCollaborateurEP(); |
|
|
|
this.setCollaborateurEP(); |
|
|
|
} |
|
|
|
} |
|
|
@ -55,21 +62,101 @@ export class AssignationReferentComponent implements OnInit { |
|
|
|
this.collaborateurSubscription = this.collaborateurService.getCollaborateursByReferent(this.referentChoisi.id).subscribe( |
|
|
|
this.collaborateurSubscription = this.collaborateurService.getCollaborateursByReferent(this.referentChoisi.id).subscribe( |
|
|
|
collaborateurs => { |
|
|
|
collaborateurs => { |
|
|
|
this.collaborateursEP = collaborateurs; |
|
|
|
this.collaborateursEP = collaborateurs; |
|
|
|
|
|
|
|
this.collaborateursSelectionnes = this.collaborateursSelectionnes.filter(c => !this.contientCollaborateur(this.collaborateursEP, c)); |
|
|
|
}, |
|
|
|
}, |
|
|
|
error => console.log(error) |
|
|
|
error => console.log(error) |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ajoutCollaborateur(event:any) { |
|
|
|
ajoutCollaborateur(event:any) { |
|
|
|
console.log(event); |
|
|
|
if(event.type != "collaborateur") |
|
|
|
if(!this.collaborateursSelectionnes.includes(event.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); |
|
|
|
this.collaborateursSelectionnes.push(event.collaborateur); |
|
|
|
console.log(this.collaborateursSelectionnes); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
enleverCollaborateur(collaborateur: CollaborateurDTO) { |
|
|
|
this.collaborateursSelectionnes = this.collaborateursSelectionnes.filter(c => c.id != collaborateur.id); |
|
|
|
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<DialogAssignationReferentComponent>, @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(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |