From 911caff9f537b4b665577f4c5882327705d12d88 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Mon, 2 May 2022 15:57:02 +0200 Subject: [PATCH] =?UTF-8?q?gestion=20de=20la=20p=C3=A9riode=20d'essai=20et?= =?UTF-8?q?=20des=20=C3=A9ditions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../periode-essai-edit.component.html | 70 ++++++++++- .../periode-essai-edit.component.ts | 113 +++++++++++++++++- .../periode-essai.component.html | 2 +- .../periode-essai/periode-essai.component.ts | 6 +- src/app/services/periode-essai.service.ts | 4 + src/ressources/routes/routesPreprod.ts | 2 +- 6 files changed, 191 insertions(+), 6 deletions(-) diff --git a/src/app/components/periode-essai/periode-essai-edit/periode-essai-edit.component.html b/src/app/components/periode-essai/periode-essai-edit/periode-essai-edit.component.html index 59a58c9..22adbc5 100644 --- a/src/app/components/periode-essai/periode-essai-edit/periode-essai-edit.component.html +++ b/src/app/components/periode-essai/periode-essai-edit/periode-essai-edit.component.html @@ -1 +1,69 @@ -

periode-essai-edit works!

+
+ +

Ajouter une Période d'Essai :

+ +
+ +
+ + +
+
Vous devez choisir le collaborateur concerné par cette période d'essai
+
+
+ +
+ + +
+
La date de début d'une période d'essai est obligatoire
+
+
+ +
+ + +
+
La date de fin prévue d'une période d'essai est obligatoire
+
+
+ +
+ + +
+
La date de fin réelle d'une période d'essai est obligatoire
+
+
+ +
+ + +
+
Le commentaire d'une période d'essai est obligatoire
+
+
+ +
+ + +
+
L'issue d'une période d'essai est obligatoire
+
+
+ +
+ + + + +
+ +
+ +
diff --git a/src/app/components/periode-essai/periode-essai-edit/periode-essai-edit.component.ts b/src/app/components/periode-essai/periode-essai-edit/periode-essai-edit.component.ts index ec7064a..39ec86a 100644 --- a/src/app/components/periode-essai/periode-essai-edit/periode-essai-edit.component.ts +++ b/src/app/components/periode-essai/periode-essai-edit/periode-essai-edit.component.ts @@ -1,4 +1,13 @@ import { Component, OnInit } from '@angular/core'; +import {FormBuilder, FormGroup, Validators} from '@angular/forms'; +import {PeriodeEssai} from "../../../interfaces/periode-essai"; +import {Collaborateur} from "../../../interfaces/collaborateur"; +import {CollaborateurService} from "../../../services/collaborateur.service"; +import {PeriodeEssaiService} from "../../../services/periode-essai.service"; +import {Observable} from "rxjs"; +import {ActivatedRoute} from "@angular/router"; +import {take, tap} from "rxjs/operators"; +import {Location} from "@angular/common"; @Component({ selector: 'app-periode-essai-edit', @@ -7,9 +16,109 @@ import { Component, OnInit } from '@angular/core'; }) export class PeriodeEssaiEditComponent implements OnInit { - constructor() { } + periodeEssaiObservable! : Observable; + id: number; - ngOnInit(): void { + collaborateurs : Collaborateur[] = []; + collaborateur = {} as Collaborateur; + + periodeEssais : PeriodeEssai[] = []; + periodeEssai = {} as PeriodeEssai; + + registerForm!: FormGroup; + submitted = false; + + startingDate : String = ""; + plannedEndingDate : String = ""; + realEndingDate : String = ""; + + constructor( + private route: ActivatedRoute, + private location: Location, + private collaborateurService: CollaborateurService, + private periodeEssaiService: PeriodeEssaiService, + private formBuilder: FormBuilder + ) { + this.id = Number(this.route.snapshot.paramMap.get('id')) + } + + async ngOnInit() { + this.getCollaborateurs(); + this.registerForm = this.formBuilder.group({ + comment: ['', Validators.required], + collaborateurId: ['',Validators.required], + issue: ['',Validators.required], + plannedEndingDate: ['',Validators.required], + realEndingDate: ['',Validators.required], + startingDate: ['',Validators.required] + }); + this.periodeEssaiObservable = this.periodeEssaiService.getPeriodeEssai(this.id).pipe(tap(periodeEssai => this.registerForm.patchValue(periodeEssai))) + this.periodeEssai = await this.periodeEssaiObservable.pipe(take(1)).toPromise() + if (this.periodeEssai.startingDate) { + this.startingDate = new Date(this.periodeEssai.startingDate).toISOString().split('T')[0]; + } + if (this.periodeEssai.plannedEndingDate) { + this.plannedEndingDate = new Date(this.periodeEssai.plannedEndingDate).toISOString().split('T')[0]; + } + if (this.periodeEssai.realEndingDate) { + this.realEndingDate = new Date(this.periodeEssai.realEndingDate).toISOString().split('T')[0]; + } + } + + getCollaborateurs():void { + this.collaborateurService.getCollaborateurs() + .subscribe(collaborateurs => this.collaborateurs = collaborateurs); + } + + goBack(): void { + this.location.back(); + } + + delete():void { + if (this.periodeEssai){ + this.periodeEssaiService.deletePeriodeEssai(this.periodeEssai) + .subscribe(()=>this.goBack()); + } + } + + onSubmit() { + this.submitted = true; + + 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.plannedEndingDate = this.registerForm.value.plannedEndingDate + this.periodeEssai.realEndingDate = this.registerForm.value.realEndingDate + this.periodeEssai.startingDate = this.registerForm.value.startingDate + + if (this.periodeEssai){ + this.periodeEssaiService.updatePeriodeEssai(this.periodeEssai) + .subscribe(()=>this.goBack()); + } + } + + get f() { return this.registerForm.controls; } + + onReset() { + this.submitted = false; + this.registerForm.reset(); + } + + onStartingDateChange($event: any):void { + this.periodeEssai.startingDate = new Date($event.target.value); + } + + onPlannedEndingDateChange($event: any):void { + this.periodeEssai.plannedEndingDate = new Date($event.target.value); + } + + onRealEndingDateChange($event: any):void { + this.periodeEssai.realEndingDate = new Date($event.target.value); } } + + diff --git a/src/app/components/periode-essai/periode-essai.component.html b/src/app/components/periode-essai/periode-essai.component.html index 97e5388..ab4f869 100644 --- a/src/app/components/periode-essai/periode-essai.component.html +++ b/src/app/components/periode-essai/periode-essai.component.html @@ -79,7 +79,7 @@ {{periodeEssai.id}} {{periodeEssai.collaborateurId}} - + {{periodeEssai.issue}} Modifier diff --git a/src/app/components/periode-essai/periode-essai.component.ts b/src/app/components/periode-essai/periode-essai.component.ts index 22ec458..7a84d53 100644 --- a/src/app/components/periode-essai/periode-essai.component.ts +++ b/src/app/components/periode-essai/periode-essai.component.ts @@ -35,6 +35,7 @@ export class PeriodeEssaiComponent implements OnInit { ngOnInit(): void { this.getCollaborateurs(); + this.getPeriodeEssais(); this.registerForm = this.formBuilder.group({ comment: ['', Validators.required], collaborateurId: ['',Validators.required], @@ -68,7 +69,6 @@ export class PeriodeEssaiComponent implements OnInit { onSubmit() { this.submitted = true; - if (this.registerForm.invalid) { return; } @@ -100,4 +100,8 @@ export class PeriodeEssaiComponent implements OnInit { this.periodeEssai.realEndingDate = new Date($event.target.value); } + getPeriodeEssais() { + this.periodeEssaiService.getPeriodeEssais() + .subscribe(periodeEssais => this.periodeEssais = periodeEssais); + } } diff --git a/src/app/services/periode-essai.service.ts b/src/app/services/periode-essai.service.ts index eb177e4..4bea51f 100644 --- a/src/app/services/periode-essai.service.ts +++ b/src/app/services/periode-essai.service.ts @@ -30,6 +30,10 @@ export class PeriodeEssaiService{ return this.http.put(this.periodeessaisUrl + "/" + periodeEssai.id, body, this.httpOptions); } + deletePeriodeEssai(periodeEssai: PeriodeEssai) { + return this.http.delete(this.periodeessaisUrl + "/" + periodeEssai.id); + } + addPeriodeEssai(periodeEssai: PeriodeEssai): Observable { let body = JSON.stringify(periodeEssai); return this.http.post(this.periodeessaisUrl, body, this.httpOptions); diff --git a/src/ressources/routes/routesPreprod.ts b/src/ressources/routes/routesPreprod.ts index 6eba4df..a611105 100644 --- a/src/ressources/routes/routesPreprod.ts +++ b/src/ressources/routes/routesPreprod.ts @@ -1,4 +1,4 @@ export const collaborateursUrl = 'https://collaborateur-epa.apsdigit.lan/api/collaborateurs'; export const agencesUrl = 'https://collaborateur-epa.apsdigit.lan/api/agences'; export const businessunitsUrl = 'https://collaborateur-epa.apsdigit.lan/api/businessunits'; -export const periodeessaisUrl = 'https://collaboratuer-epa.apsdigit.lan/api/periodeessais'; +export const periodeessaisUrl = 'https://collaborateur-epa.apsdigit.lan/api/periodeessais';