|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
|
import {Component, OnInit} from '@angular/core'; |
|
|
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; |
|
|
|
|
import {PeriodeEssai} from "../../../interfaces/periode-essai"; |
|
|
|
|
import {Collaborateur} from "../../../interfaces/collaborateur"; |
|
|
|
@ -17,13 +17,13 @@ import {ToastrService} from "ngx-toastr"; |
|
|
|
|
}) |
|
|
|
|
export class PeriodeEssaiEditComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
periodeEssaiObservable! : Observable<PeriodeEssai>; |
|
|
|
|
periodeEssaiObservable!: Observable<PeriodeEssai>; |
|
|
|
|
id: number; |
|
|
|
|
|
|
|
|
|
collaborateurs : Collaborateur[] = []; |
|
|
|
|
collaborateurs: Collaborateur[] = []; |
|
|
|
|
collaborateur = {} as Collaborateur; |
|
|
|
|
|
|
|
|
|
periodeEssais : PeriodeEssai[] = []; |
|
|
|
|
periodeEssais: PeriodeEssai[] = []; |
|
|
|
|
periodeEssai = {} as PeriodeEssai; |
|
|
|
|
|
|
|
|
|
registerForm!: FormGroup; |
|
|
|
@ -40,22 +40,26 @@ export class PeriodeEssaiEditComponent implements OnInit { |
|
|
|
|
this.id = Number(this.route.snapshot.paramMap.get('id')) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
get f() { |
|
|
|
|
return this.registerForm.controls; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async ngOnInit() { |
|
|
|
|
this.getCollaborateurs(); |
|
|
|
|
this.getPeriodeEssais(); |
|
|
|
|
this.registerForm = this.formBuilder.group({ |
|
|
|
|
comment: ['', Validators.required], |
|
|
|
|
collaborateurId: ['',Validators.required], |
|
|
|
|
issue: ['',Validators.required], |
|
|
|
|
plannedEndingDate: ['',Validators.required], |
|
|
|
|
realEndingDate: ['',Validators.required], |
|
|
|
|
startingDate: ['',Validators.required] |
|
|
|
|
comment: [], |
|
|
|
|
collaborateurId: ['', Validators.required], |
|
|
|
|
issue: [], |
|
|
|
|
plannedEndingDate: ['', Validators.required], |
|
|
|
|
realEndingDate: [], |
|
|
|
|
startingDate: ['', Validators.required] |
|
|
|
|
}); |
|
|
|
|
this.periodeEssaiObservable = this.periodeEssaiService.getPeriodeEssai(this.id).pipe(tap(pe => this.registerForm.patchValue(pe))) |
|
|
|
|
this.periodeEssai = await this.periodeEssaiObservable.pipe(take(1)).toPromise() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getCollaborateurs():void { |
|
|
|
|
getCollaborateurs(): void { |
|
|
|
|
this.collaborateurService.getCollaborateurs() |
|
|
|
|
.subscribe(collaborateurs => this.collaborateurs = collaborateurs); |
|
|
|
|
} |
|
|
|
@ -69,10 +73,10 @@ export class PeriodeEssaiEditComponent implements OnInit { |
|
|
|
|
this.location.back(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
delete():void { |
|
|
|
|
if (this.periodeEssai){ |
|
|
|
|
delete(): void { |
|
|
|
|
if (this.periodeEssai) { |
|
|
|
|
this.periodeEssaiService.deletePeriodeEssai(this.periodeEssai) |
|
|
|
|
.subscribe(()=>this.goBack()); |
|
|
|
|
.subscribe(() => this.goBack()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -82,17 +86,23 @@ export class PeriodeEssaiEditComponent implements OnInit { |
|
|
|
|
if (this.registerForm.invalid) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.periodeEssai.comment = this.registerForm.value.comment |
|
|
|
|
this.periodeEssai.collaborateurId = this.registerForm.value.collaborateurId |
|
|
|
|
this.periodeEssai.issue = this.registerForm.value.issue |
|
|
|
|
this.periodeEssai.realEndingDate = this.registerForm.value.realEndingDate |
|
|
|
|
this.periodeEssai.startingDate = this.registerForm.value.startingDate |
|
|
|
|
|
|
|
|
|
if (this.registerForm.value.plannedEndingDate == undefined) { |
|
|
|
|
this.periodeEssai.plannedEndingDate = new Date(); |
|
|
|
|
this.periodeEssai.comment = this.registerForm.value.comment; |
|
|
|
|
this.periodeEssai.collaborateurId = this.registerForm.value.collaborateurId; |
|
|
|
|
if (this.registerForm.value.issue == undefined) { |
|
|
|
|
this.periodeEssai.issue = "INDETERMINEE"; |
|
|
|
|
} else { |
|
|
|
|
this.periodeEssai.issue = this.registerForm.value.issue; |
|
|
|
|
} |
|
|
|
|
if (this.registerForm.value.realEndingDate == undefined || this.registerForm.value.realEndingDate == '') { |
|
|
|
|
this.periodeEssai.realEndingDate = null; |
|
|
|
|
} else { |
|
|
|
|
this.periodeEssai.realEndingDate = this.registerForm.value.realEndingDate; |
|
|
|
|
} |
|
|
|
|
this.periodeEssai.plannedEndingDate = this.registerForm.value.plannedEndingDate; |
|
|
|
|
this.periodeEssai.startingDate = this.registerForm.value.startingDate; |
|
|
|
|
|
|
|
|
|
if (this.periodeEssai){ |
|
|
|
|
if (this.periodeEssai) { |
|
|
|
|
this.periodeEssaiService.updatePeriodeEssai(this.periodeEssai) |
|
|
|
|
.subscribe(() => { |
|
|
|
|
this.showSuccess(); |
|
|
|
@ -103,22 +113,20 @@ export class PeriodeEssaiEditComponent implements OnInit { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
get f() { return this.registerForm.controls; } |
|
|
|
|
|
|
|
|
|
onReset() { |
|
|
|
|
this.submitted = false; |
|
|
|
|
this.registerForm.reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onStartingDateChange($event: any):void { |
|
|
|
|
onStartingDateChange($event: any): void { |
|
|
|
|
this.periodeEssai.startingDate = new Date($event.target.value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onPlannedEndingDateChange($event: any):void { |
|
|
|
|
onPlannedEndingDateChange($event: any): void { |
|
|
|
|
this.periodeEssai.plannedEndingDate = new Date($event.target.value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onRealEndingDateChange($event: any):void { |
|
|
|
|
onRealEndingDateChange($event: any): void { |
|
|
|
|
this.periodeEssai.realEndingDate = new Date($event.target.value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|