|
|
|
@ -6,6 +6,8 @@ import { CollaborateurService} from "../../../services/collaborateur.service"; |
|
|
|
|
import {BusinessunitService} from "../../../services/businessunit.service"; |
|
|
|
|
import {FormBuilder, FormGroup, Validators} from "@angular/forms"; |
|
|
|
|
import {Businessunit} from "../../../interfaces/businessunit"; |
|
|
|
|
import {Observable} from "rxjs"; |
|
|
|
|
import {take, tap} from "rxjs/operators"; |
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-collaborateur-edit', |
|
|
|
@ -13,10 +15,14 @@ import {Businessunit} from "../../../interfaces/businessunit"; |
|
|
|
|
styleUrls: ['./collaborateur-edit.component.scss'] |
|
|
|
|
}) |
|
|
|
|
export class CollaborateurEditComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
collaborateurObservable! : Observable<Collaborateur>; |
|
|
|
|
id: number; |
|
|
|
|
|
|
|
|
|
collaborateur = {} as Collaborateur; |
|
|
|
|
businessUnit = {} as Businessunit ; |
|
|
|
|
collaborateurs : Collaborateur[] = []; |
|
|
|
|
businessUnits : Businessunit[] = []; |
|
|
|
|
businessUnit = {} as Businessunit ; |
|
|
|
|
|
|
|
|
|
rDate : String = ""; |
|
|
|
|
bDate : String = ""; |
|
|
|
@ -30,11 +36,12 @@ export class CollaborateurEditComponent implements OnInit { |
|
|
|
|
private businessunitService: BusinessunitService, |
|
|
|
|
private location: Location, |
|
|
|
|
private formBuilder: FormBuilder |
|
|
|
|
) { } |
|
|
|
|
) { |
|
|
|
|
this.id = Number(this.route.snapshot.paramMap.get('id')) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
async ngOnInit() { |
|
|
|
|
this.getCollaborateurs() |
|
|
|
|
this.getCollaborateur(); |
|
|
|
|
this.getBusinessunits(); |
|
|
|
|
this.registerForm = this.formBuilder.group({ |
|
|
|
|
name: ['', Validators.required], |
|
|
|
@ -51,6 +58,8 @@ export class CollaborateurEditComponent implements OnInit { |
|
|
|
|
referrerId: ['', Validators.required], |
|
|
|
|
businessUnitId: ['', Validators.required], |
|
|
|
|
}); |
|
|
|
|
this.collaborateurObservable = this.collaborateurService.getCollaborateur(this.id).pipe(tap(collaborateur => this.registerForm.patchValue(collaborateur))) |
|
|
|
|
this.collaborateur = await this.collaborateurObservable.pipe(take(1)).toPromise() |
|
|
|
|
if (this.collaborateur.resignationDate) { |
|
|
|
|
this.rDate = new Date(this.collaborateur.resignationDate).toISOString().split('T')[0]; |
|
|
|
|
} |
|
|
|
@ -64,12 +73,6 @@ export class CollaborateurEditComponent implements OnInit { |
|
|
|
|
.subscribe(collaborateurs => this.collaborateurs = collaborateurs); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getCollaborateur(): void { |
|
|
|
|
const id = Number(this.route.snapshot.paramMap.get('id')) |
|
|
|
|
this.collaborateurService.getCollaborateur(id) |
|
|
|
|
.subscribe(collaborateur => this.collaborateur = collaborateur); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getBusinessunits():void { |
|
|
|
|
this.businessunitService.getBusinessunits() |
|
|
|
|
.subscribe(businessunits => this.businessUnits = businessunits); |
|
|
|
@ -79,13 +82,6 @@ export class CollaborateurEditComponent implements OnInit { |
|
|
|
|
this.location.back(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
save():void{ |
|
|
|
|
if (this.collaborateur){ |
|
|
|
|
this.collaborateurService.updateCollaborateur(this.collaborateur) |
|
|
|
|
.subscribe(()=>this.goBack()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
delete():void { |
|
|
|
|
if (this.collaborateur){ |
|
|
|
|
this.collaborateurService.deleteCollaborateur(this.collaborateur) |
|
|
|
@ -99,8 +95,25 @@ export class CollaborateurEditComponent implements OnInit { |
|
|
|
|
if (this.registerForm.invalid) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.collaborateur = this.registerForm.value |
|
|
|
|
this.save() |
|
|
|
|
|
|
|
|
|
this.collaborateur.name = this.registerForm.value.name |
|
|
|
|
this.collaborateur.firstName = this.registerForm.value.firstName |
|
|
|
|
this.collaborateur.birthDate = this.registerForm.value.birthDate |
|
|
|
|
this.collaborateur.gender = this.registerForm.value.gender |
|
|
|
|
this.collaborateur.resignationDate = this.registerForm.value.resignationDate |
|
|
|
|
this.collaborateur.businessUnitId = this.registerForm.value.businessUnitId |
|
|
|
|
this.collaborateur.referrerId = this.registerForm.value.referrerId |
|
|
|
|
this.collaborateur.apsideMail = this.registerForm.value.apsideMail |
|
|
|
|
this.collaborateur.personalMail = this.registerForm.value.personalMail |
|
|
|
|
this.collaborateur.telephone = this.registerForm.value.telephone |
|
|
|
|
this.collaborateur.address = this.registerForm.value.address |
|
|
|
|
this.collaborateur.childrenNumber = this.registerForm.value.childrenNumber |
|
|
|
|
this.collaborateur.status = this.registerForm.value.status |
|
|
|
|
|
|
|
|
|
if (this.collaborateur){ |
|
|
|
|
this.collaborateurService.updateCollaborateur(this.collaborateur) |
|
|
|
|
.subscribe(()=>this.goBack()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
get f() { return this.registerForm.controls; } |
|
|
|
|