diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts
index 0cd2e35..8327538 100644
--- a/src/app/app-routing.module.ts
+++ b/src/app/app-routing.module.ts
@@ -10,6 +10,9 @@ import {BusinessunitEditComponent} from "./components/businessunit/businessunit-
import {PeriodeEssaiComponent} from "./components/periode-essai/periode-essai.component";
import {PeriodeEssaiEditComponent} from "./components/periode-essai/periode-essai-edit/periode-essai-edit.component";
import {CollaborateurAddComponent} from "./components/collaborateur/collaborateur-add/collaborateur-add.component";
+import {ReferencementComponent} from "./components/referencement/referencement.component";
+import {ReferencementAddComponent} from "./components/referencement/referencement-add/referencement-add.component";
+import {ReferencementEditComponent} from "./components/referencement/referencement-edit/referencement-edit.component";
const routes : Routes = [
{path:'', redirectTo:'/home', pathMatch:'full'},
@@ -17,6 +20,9 @@ const routes : Routes = [
{ path:'collaborateurs',component:CollaborateurComponent, data:{title:'Collaborateurs'} },
{ path:'collaborateurs/add',component:CollaborateurAddComponent, data:{title:'Collaborateurs'} },
{ path: 'collaborateurs/:id', component: CollaborateurEditComponent, data:{title:'Collaborateurs'} },
+ { path:'referencements',component:ReferencementComponent, data:{title:'Referencements'} },
+ { path:'referencements/add',component:ReferencementAddComponent, data:{title:'Referencements'} },
+ { path: 'referencements/:id', component: ReferencementEditComponent, data:{title:'Referencements'} },
{ path:'agences',component:AgenceComponent, data:{title:'Agences'} },
{ path: 'agences/:id', component: AgenceEditComponent, data:{title:'Agences'} },
{ path:'businessunits',component:BusinessunitComponent, data:{title:'BusinessUnits'} },
diff --git a/src/app/app.component.html b/src/app/app.component.html
index 0155050..3890464 100644
--- a/src/app/app.component.html
+++ b/src/app/app.component.html
@@ -9,12 +9,21 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/components/referencement/referencement-add/referencement-add.component.html b/src/app/components/referencement/referencement-add/referencement-add.component.html
index 2e0db90..3293fc0 100644
--- a/src/app/components/referencement/referencement-add/referencement-add.component.html
+++ b/src/app/components/referencement/referencement-add/referencement-add.component.html
@@ -1 +1,55 @@
-
referencement-add works!
+
Ajouter un collaborateur :
+
+
diff --git a/src/app/components/referencement/referencement-add/referencement-add.component.ts b/src/app/components/referencement/referencement-add/referencement-add.component.ts
index 264ea43..75502f3 100644
--- a/src/app/components/referencement/referencement-add/referencement-add.component.ts
+++ b/src/app/components/referencement/referencement-add/referencement-add.component.ts
@@ -1,4 +1,11 @@
import { Component, OnInit } from '@angular/core';
+import {Collaborateur} from "../../../interfaces/collaborateur";
+import {FormBuilder, FormGroup, Validators} from "@angular/forms";
+import {HttpClient} from "@angular/common/http";
+import {CollaborateurService} from "../../../services/collaborateur.service";
+import {ToastrService} from "ngx-toastr";
+import {ReferencementService} from "../../../services/referencement.service";
+import {Referencement} from "../../../interfaces/referencement";
@Component({
selector: 'app-referencement-add',
@@ -7,9 +14,94 @@ import { Component, OnInit } from '@angular/core';
})
export class ReferencementAddComponent implements OnInit {
- constructor() { }
+ collaborateurs: Collaborateur[] = [];
+ collaborateur = {} as Collaborateur;
+ referencements: Referencement[] = [];
+ referencement = {} as Referencement;
+
+ errorValue: number = 0;
+ rDate: String = "";
+ bDate: String = "";
+
+ registerForm!: FormGroup;
+ submitted = false;
+
+ constructor(private http: HttpClient,
+ private referencementService: ReferencementService,
+ private collaborateurService: CollaborateurService,
+ private formBuilder: FormBuilder,
+ private toastr: ToastrService) {
+ }
ngOnInit(): void {
+ this.getCollaborateurs();
+ this.getReferencements();
+ this.registerForm = this.formBuilder.group({
+ referredId: ['', Validators.required],
+ referrerId: ['', Validators.required],
+ startingDate: ['', Validators.required],
+ endingDate: [],
+ });
+ if (this.referencement.startingDate) {
+ this.rDate = new Date(this.collaborateur.resignationDate).toISOString().split('T')[0];
+ }
+ if (this.referencement.endingDate) {
+ this.bDate = new Date(this.collaborateur.birthDate).toISOString().split('T')[0];
+ }
+ }
+
+ getCollaborateurs(): void {
+ this.collaborateurService.getCollaborateurs()
+ .subscribe(collaborateurs => this.collaborateurs = collaborateurs);
+ }
+
+ getReferencements(): void {
+ this.referencementService.getReferencements()
+ .subscribe(referencement => this.referencements = referencement);
+ }
+
+ onSubmit() {
+ this.submitted = true;
+ if (this.registerForm.invalid) {
+ return;
+ }
+ this.referencement = this.registerForm.value
+ if (this.referencement) {
+ this.referencementService.addReferencement(this.referencement).subscribe(referencement => {
+ this.referencements.push(referencement);
+ this.showSuccess();
+ },
+ () => {
+ this.showError()
+ })
+
+ }
+ }
+
+ get form() {
+ return this.registerForm.controls;
+ }
+
+ onReset() {
+ this.submitted = false;
+ this.registerForm.reset();
+ }
+
+ onStartingDateChange($event: any): void {
+ this.collaborateur.resignationDate = new Date($event.target.value);
+ }
+
+ onEndingDateChange($event: any): void {
+ this.collaborateur.birthDate = new Date($event.target.value);
+ }
+
+ showSuccess() {
+ this.toastr.success('Création réussie', 'Référencement');
+ }
+
+ showError() {
+ this.toastr.error('Création échouée', 'Référencement');
}
}
+
diff --git a/src/app/services/agence.service.ts b/src/app/services/agence.service.ts
index a92030f..64c87e0 100644
--- a/src/app/services/agence.service.ts
+++ b/src/app/services/agence.service.ts
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {Observable} from "rxjs";
import {Agence} from "../interfaces/agence";
-import {agencesUrl} from "../../ressources/routes/routesPreprod";
+import {agencesUrl} from "../../ressources/routes/routes";
@Injectable({
providedIn: 'root'
diff --git a/src/app/services/businessunit.service.ts b/src/app/services/businessunit.service.ts
index dbf35fb..7d10aea 100644
--- a/src/app/services/businessunit.service.ts
+++ b/src/app/services/businessunit.service.ts
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {Observable} from "rxjs";
import {Businessunit} from "../interfaces/businessunit";
-import {businessunitsUrl} from "../../ressources/routes/routesPreprod";
+import {businessunitsUrl} from "../../ressources/routes/routes";
@Injectable({
providedIn: 'root'
diff --git a/src/app/services/collaborateur.service.ts b/src/app/services/collaborateur.service.ts
index 773ab7d..2515717 100644
--- a/src/app/services/collaborateur.service.ts
+++ b/src/app/services/collaborateur.service.ts
@@ -2,7 +2,7 @@ import {Collaborateur} from "../interfaces/collaborateur";
import {Injectable} from '@angular/core';
import {Observable} from "rxjs";
import {HttpClient, HttpHeaders} from "@angular/common/http";
-import {collaborateursUrl} from "../../ressources/routes/routesPreprod";
+import {collaborateursUrl} from "../../ressources/routes/routes";
@Injectable({providedIn: 'root'})
diff --git a/src/app/services/periode-essai.service.ts b/src/app/services/periode-essai.service.ts
index 4bea51f..53984c0 100644
--- a/src/app/services/periode-essai.service.ts
+++ b/src/app/services/periode-essai.service.ts
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {Observable} from "rxjs";
-import {periodeessaisUrl} from "../../ressources/routes/routesPreprod";
+import {periodeessaisUrl} from "../../ressources/routes/routes";
import {PeriodeEssai} from "../interfaces/periode-essai";
diff --git a/src/app/services/referencement.service.ts b/src/app/services/referencement.service.ts
new file mode 100644
index 0000000..3df6a4a
--- /dev/null
+++ b/src/app/services/referencement.service.ts
@@ -0,0 +1,43 @@
+import {Referencement} from "../interfaces/referencement";
+import {Injectable} from '@angular/core';
+import {Observable} from "rxjs";
+import {HttpClient, HttpHeaders} from "@angular/common/http";
+import {referencementsUrl} from "../../ressources/routes/routes";
+
+
+@Injectable({providedIn: 'root'})
+
+export class ReferencementService {
+
+ private referencementsUrl = referencementsUrl;
+
+ httpOptions = {
+ headers: new HttpHeaders({ 'Content-Type': 'application/json' })
+ };
+
+ constructor(private http: HttpClient) { }
+
+ getReferencements():Observable
{
+ return this.http.get(this.referencementsUrl);
+ }
+
+ getReferencement(id : number):Observable{
+ return this.http.get(this.referencementsUrl+"/"+id);
+ }
+
+ updateReferencement(referencement : Referencement):Observable{
+ let body = JSON.stringify(referencement);
+ return this.http.put(this.referencementsUrl + "/" + referencement.id, body, this.httpOptions);
+
+ }
+
+ deleteReferencement(referencement: Referencement) {
+ return this.http.delete(this.referencementsUrl + "/" + referencement.id);
+ }
+
+ addReferencement(referencement: Referencement): Observable {
+ let body = JSON.stringify(referencement);
+ return this.http.post(this.referencementsUrl, body, this.httpOptions);
+
+ }
+}
diff --git a/src/ressources/routes/routes.ts b/src/ressources/routes/routes.ts
index a4645f5..82743c1 100644
--- a/src/ressources/routes/routes.ts
+++ b/src/ressources/routes/routes.ts
@@ -1,3 +1,5 @@
export const collaborateursUrl = 'https://localhost:5001/api/collaborateurs';
export const agencesUrl = 'https://localhost:5001/api/agences';
export const businessunitsUrl = 'https://localhost:5001/api/businessunits';
+export const periodeessaisUrl = 'https://localhost:5001/api/periodeessais';
+export const referencementsUrl = 'https://localhost:5001/api/referencements';
diff --git a/src/ressources/routes/routesPreprod.ts b/src/ressources/routes/routesPreprod.ts
index a611105..b1a3c3b 100644
--- a/src/ressources/routes/routesPreprod.ts
+++ b/src/ressources/routes/routesPreprod.ts
@@ -2,3 +2,4 @@ export const collaborateursUrl = 'https://collaborateur-epa.apsdigit.lan/api/col
export const agencesUrl = 'https://collaborateur-epa.apsdigit.lan/api/agences';
export const businessunitsUrl = 'https://collaborateur-epa.apsdigit.lan/api/businessunits';
export const periodeessaisUrl = 'https://collaborateur-epa.apsdigit.lan/api/periodeessais';
+export const referencementsUrl = 'https://collaborateur-epa.apsdigit.lan/api/referencements';