rework_referencement #17
Merged
AlexandreRuiz
merged 8 commits from rework_referencement
into develop
3 years ago
@ -0,0 +1,55 @@ |
||||
<h3>Ajouter un collaborateur : </h3> |
||||
|
||||
<form [formGroup]="registerForm" (ngSubmit)="onSubmit()"> |
||||
|
||||
<div class="row mb-2"> |
||||
|
||||
<div class="form-group col-12 col-sm-6 col-md-4 col-lg-3"> |
||||
<label class="form-label">Date de début</label> |
||||
<input type="date" class="form-control" formControlName="startingDate" |
||||
(change)="onStartingDateChange($event)" |
||||
[ngClass]="{ 'is-invalid': submitted && form.startingDate.errors }"> |
||||
</div> |
||||
|
||||
<div class="form-group col-12 col-sm-6 col-md-4 col-lg-3"> |
||||
<label class="form-label">Date de fin</label> |
||||
<input type="date" class="form-control" formControlName="endingDate" |
||||
(change)="onEndingDateChange($event)" |
||||
[ngClass]="{ 'is-invalid': submitted && form.endingDate.errors }"> |
||||
</div> |
||||
|
||||
</div> |
||||
|
||||
<div class="row mb-2"> |
||||
|
||||
<div class="form-group col-12 col-md-6"> |
||||
<label class="form-label">Référent</label> |
||||
<select class="form-select" formControlName="referrerId" |
||||
[ngClass]="{ 'is-invalid': submitted && form.referrerId.errors }"> |
||||
<option value="" disabled selected>Choisissez le référent du référencement</option> |
||||
<option *ngFor="let collaborateur of collaborateurs" [ngValue]="collaborateur.id">{{collaborateur.name}} {{collaborateur.firstName}}</option> |
||||
</select> |
||||
<div *ngIf="submitted && form.referrerId.errors" class="invalid-feedback"> |
||||
<div *ngIf="form.referrerId.errors.required">Vous devez préciser le référent du référencement</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="form-group col-12 col-md-6"> |
||||
<label class="form-label">Référé</label> |
||||
<select class="form-select" formControlName="referredId" |
||||
[ngClass]="{ 'is-invalid': submitted && form.referredId.errors }"> |
||||
<option value="" disabled selected>Choisissez le référé du référencement</option> |
||||
<option *ngFor="let collaborateur of collaborateurs" [ngValue]="collaborateur.id">{{collaborateur.name}} {{collaborateur.firstName}}</option> |
||||
</select> |
||||
<div *ngIf="submitted && form.referredId.errors" class="invalid-feedback"> |
||||
<div *ngIf="form.referredId.errors.required">Vous devez préciser le référent du référencement</div> |
||||
</div> |
||||
</div> |
||||
|
||||
</div> |
||||
|
||||
<div> |
||||
<button type="submit">Ajouter le référencement</button> |
||||
<button type="reset" (click)="onReset()">Effacer</button> |
||||
</div> |
||||
</form> |
@ -0,0 +1,107 @@ |
||||
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', |
||||
templateUrl: './referencement-add.component.html', |
||||
styleUrls: ['./referencement-add.component.scss'] |
||||
}) |
||||
export class ReferencementAddComponent implements OnInit { |
||||
|
||||
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'); |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,57 @@ |
||||
<h3>Modifier un collaborateur : </h3> |
||||
|
||||
<form [formGroup]="registerForm" (ngSubmit)="onSubmit()"> |
||||
|
||||
<div class="row mb-2"> |
||||
|
||||
<div class="form-group col-12 col-sm-6 col-md-4 col-lg-3"> |
||||
<label class="form-label">Date de début</label> |
||||
<input type="date" class="form-control" formControlName="startingDate" |
||||
(change)="onStartingDateChange($event)" |
||||
[ngClass]="{ 'is-invalid': submitted && form.startingDate.errors }"> |
||||
</div> |
||||
|
||||
<div class="form-group col-12 col-sm-6 col-md-4 col-lg-3"> |
||||
<label class="form-label">Date de fin</label> |
||||
<input type="date" class="form-control" formControlName="endingDate" |
||||
(change)="onEndingDateChange($event)" |
||||
[ngClass]="{ 'is-invalid': submitted && form.endingDate.errors }"> |
||||
</div> |
||||
|
||||
</div> |
||||
|
||||
<div class="row mb-2"> |
||||
|
||||
<div class="form-group col-12 col-md-6"> |
||||
<label class="form-label">Référent</label> |
||||
<select class="form-select" formControlName="referrerId" |
||||
[ngClass]="{ 'is-invalid': submitted && form.referrerId.errors }"> |
||||
<option value="" disabled selected>Choisissez le référent du référencement</option> |
||||
<option *ngFor="let collaborateur of collaborateurs" [ngValue]="collaborateur.id">{{collaborateur.name}} {{collaborateur.firstName}}</option> |
||||
</select> |
||||
<div *ngIf="submitted && form.referrerId.errors" class="invalid-feedback"> |
||||
<div *ngIf="form.referrerId.errors.required">Vous devez préciser le référent du référencement</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="form-group col-12 col-md-6"> |
||||
<label class="form-label">Référé</label> |
||||
<select class="form-select" formControlName="referredId" |
||||
[ngClass]="{ 'is-invalid': submitted && form.referredId.errors }"> |
||||
<option value="" disabled selected>Choisissez le référé du référencement</option> |
||||
<option *ngFor="let collaborateur of collaborateurs" [ngValue]="collaborateur.id">{{collaborateur.name}} {{collaborateur.firstName}}</option> |
||||
</select> |
||||
<div *ngIf="submitted && form.referredId.errors" class="invalid-feedback"> |
||||
<div *ngIf="form.referredId.errors.required">Vous devez préciser le référent du référencement</div> |
||||
</div> |
||||
</div> |
||||
|
||||
</div> |
||||
|
||||
<div> |
||||
<button type="submit" (click)="onSubmit()">Sauvegarder les changements</button> |
||||
<button type="button" (click)="delete()">Supprimer le référencement</button> |
||||
<button type="reset" (click)="onReset()">Effacer</button> |
||||
<button (click)="goBack()">Retour</button> |
||||
</div> |
||||
</form> |
@ -0,0 +1,137 @@ |
||||
import { Component, OnInit } from '@angular/core'; |
||||
import {Collaborateur} from "../../../interfaces/collaborateur"; |
||||
import {Referencement} from "../../../interfaces/referencement"; |
||||
import {FormBuilder, FormGroup, Validators} from "@angular/forms"; |
||||
import {HttpClient} from "@angular/common/http"; |
||||
import {ReferencementService} from "../../../services/referencement.service"; |
||||
import {CollaborateurService} from "../../../services/collaborateur.service"; |
||||
import {ToastrService} from "ngx-toastr"; |
||||
import {Location} from "@angular/common"; |
||||
import {ActivatedRoute} from "@angular/router"; |
||||
import {Observable} from "rxjs"; |
||||
import {take, tap} from "rxjs/operators"; |
||||
|
||||
@Component({ |
||||
selector: 'app-referencement-edit', |
||||
templateUrl: './referencement-edit.component.html', |
||||
styleUrls: ['./referencement-edit.component.scss'] |
||||
}) |
||||
export class ReferencementEditComponent implements OnInit { |
||||
|
||||
referencementObservable! : Observable<Referencement>; |
||||
id: number; |
||||
|
||||
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 location: Location, |
||||
private route: ActivatedRoute, |
||||
private toastr: ToastrService) { |
||||
this.id = Number(this.route.snapshot.paramMap.get('id')) |
||||
} |
||||
|
||||
async ngOnInit() { |
||||
this.getCollaborateurs(); |
||||
this.getReferencements(); |
||||
this.registerForm = this.formBuilder.group({ |
||||
referredId: ['', Validators.required], |
||||
referrerId: ['', Validators.required], |
||||
startingDate: ['', Validators.required], |
||||
endingDate: [], |
||||
}); |
||||
|
||||
this.referencementObservable = this.referencementService.getReferencement(this.id).pipe(tap(ref => this.registerForm.patchValue(ref))) |
||||
this.referencement = await this.referencementObservable.pipe(take(1)).toPromise() |
||||
|
||||
if (this.referencement.startingDate) { |
||||
this.rDate = new Date(this.referencement.startingDate).toISOString().split('T')[0]; |
||||
} |
||||
if (this.referencement.endingDate) { |
||||
this.bDate = new Date(this.referencement.endingDate).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.referredId = this.registerForm.value.referredId |
||||
this.referencement.referrerId = this.registerForm.value.referrerId |
||||
this.referencement.startingDate = this.registerForm.value.startingDate |
||||
|
||||
if(this.registerForm.value.endingDate != undefined){ |
||||
this.referencement.referredId = this.registerForm.value.referredId |
||||
} |
||||
|
||||
if (this.referencement) { |
||||
this.referencementService.updateReferencement(this.referencement).subscribe(() => { |
||||
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('Modification réussie', 'Référencement'); |
||||
} |
||||
|
||||
showError() { |
||||
this.toastr.error('Modification échouée', 'Référencement'); |
||||
} |
||||
|
||||
goBack(): void { |
||||
this.location.back(); |
||||
} |
||||
|
||||
delete():void { |
||||
if (this.referencement){ |
||||
this.referencementService.deleteReferencement(this.referencement) |
||||
.subscribe(()=>this.goBack()); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@ |
||||
<div> |
||||
|
||||
<h2 class=mb-4>Référencements</h2> |
||||
|
||||
<div style="display: flex"> |
||||
<p style="margin: 10px 0 10px 0">Pour ajouter un nouveau référencement, cliquez ici : </p> |
||||
<button routerLink="/referencements/add">Ajouter</button> |
||||
</div> |
||||
|
||||
|
||||
<div style="overflow-x:auto;" class="mb-5 col-12"> |
||||
<table class="table"> |
||||
<thead> |
||||
<tr> |
||||
<th scope="col">Référent</th> |
||||
<th scope="col">Référé</th> |
||||
<th scope="col">Date de début</th> |
||||
<th scope="col">Date de fin</th> |
||||
</tr> |
||||
</thead> |
||||
|
||||
<tbody> |
||||
<tr *ngFor="let referencement of referencements"> |
||||
<td> {{getCollaborateurById(referencement.referrerId).name}} {{getCollaborateurById(referencement.referrerId).firstName}}</td> |
||||
<td> {{getCollaborateurById(referencement.referredId).name}} {{getCollaborateurById(referencement.referredId).firstName}} </td> |
||||
<td> {{getSplitDate(referencement.startingDate.toString())}} </td> |
||||
<td> {{getSplitDate(referencement.endingDate?.toString())}} </td> |
||||
<td><a routerLink="{{referencement.id}}"> Modifier </a></td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
|
||||
|
||||
</div> |
@ -0,0 +1,59 @@ |
||||
import { Component, OnInit } from '@angular/core'; |
||||
import {HttpClient} from "@angular/common/http"; |
||||
import {ReferencementService} from "../../services/referencement.service"; |
||||
import {Referencement} from "../../interfaces/referencement"; |
||||
import {CollaborateurService} from "../../services/collaborateur.service"; |
||||
import {Collaborateur} from "../../interfaces/collaborateur"; |
||||
|
||||
@Component({ |
||||
selector: 'app-referencement', |
||||
templateUrl: './referencement.component.html', |
||||
styleUrls: ['./referencement.component.scss'] |
||||
}) |
||||
export class ReferencementComponent implements OnInit { |
||||
|
||||
referencements: Referencement[] = []; |
||||
collaborateurs: Collaborateur[]= []; |
||||
|
||||
constructor( |
||||
private http: HttpClient, |
||||
private referencementService: ReferencementService, |
||||
private collaborateurService: CollaborateurService, |
||||
) { |
||||
} |
||||
|
||||
ngOnInit(): void { |
||||
this.getReferencements(); |
||||
this.getCollaborateurs(); |
||||
} |
||||
|
||||
getCollaborateurs(): void { |
||||
this.collaborateurService.getCollaborateurs() |
||||
.subscribe(collaborateurs => this.collaborateurs = collaborateurs); |
||||
} |
||||
|
||||
getCollaborateurById(id : number) : Collaborateur{ |
||||
let collab = {} as Collaborateur; |
||||
this.collaborateurs.forEach(c => { |
||||
if (c.id==id){ |
||||
collab= c; |
||||
return; |
||||
} |
||||
}); |
||||
|
||||
return collab; |
||||
} |
||||
|
||||
getReferencements(): void { |
||||
this.referencementService.getReferencements() |
||||
.subscribe(referencements => this.referencements = referencements); |
||||
} |
||||
|
||||
getSplitDate(date: string | undefined) : string{ |
||||
if (date == undefined){ |
||||
return ""; |
||||
} |
||||
return date.split('T')[0]; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,7 @@ |
||||
export interface Referencement { |
||||
id: number; |
||||
startingDate : Date; |
||||
endingDate? : Date; |
||||
referredId : number; |
||||
referrerId : number; |
||||
} |
@ -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/routesPreprod"; |
||||
|
||||
|
||||
@Injectable({providedIn: 'root'}) |
||||
|
||||
export class ReferencementService { |
||||
|
||||
private referencementsUrl = referencementsUrl; |
||||
|
||||
httpOptions = { |
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }) |
||||
}; |
||||
|
||||
constructor(private http: HttpClient) { } |
||||
|
||||
getReferencements():Observable<Referencement[]> { |
||||
return this.http.get<Referencement[]>(this.referencementsUrl); |
||||
} |
||||
|
||||
getReferencement(id : number):Observable<Referencement>{ |
||||
return this.http.get<Referencement>(this.referencementsUrl+"/"+id); |
||||
} |
||||
|
||||
updateReferencement(referencement : Referencement):Observable<Referencement>{ |
||||
let body = JSON.stringify(referencement); |
||||
return this.http.put<Referencement>(this.referencementsUrl + "/" + referencement.id, body, this.httpOptions); |
||||
|
||||
} |
||||
|
||||
deleteReferencement(referencement: Referencement) { |
||||
return this.http.delete(this.referencementsUrl + "/" + referencement.id); |
||||
} |
||||
|
||||
addReferencement(referencement: Referencement): Observable<Referencement> { |
||||
let body = JSON.stringify(referencement); |
||||
return this.http.post<Referencement>(this.referencementsUrl, body, this.httpOptions); |
||||
|
||||
} |
||||
} |
@ -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'; |
||||
|
Loading…
Reference in new issue