diff --git a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html index b54af61..71d8250 100644 --- a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html +++ b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.html @@ -4,9 +4,32 @@

{{businessunit.name | uppercase}}

id : {{businessunit.id}}
- +
- - - +
+ + +
+
Le nom d'une business unit est obligatoire
+
+
+ +
+ + +
+
Vous devez choisir l'agence à laquelle appartient la business unit
+
+
+ +
+ + + + +
+
diff --git a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts index 00e2320..22d4d31 100644 --- a/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts +++ b/src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts @@ -3,6 +3,9 @@ import {Businessunit} from "../../../interfaces/businessunit"; import {ActivatedRoute} from "@angular/router"; import {BusinessunitService} from "../../../services/businessunit.service"; import {Location} from "@angular/common"; +import {FormBuilder, FormGroup, Validators} from "@angular/forms"; +import {Agence} from "../../../interfaces/agence"; +import {AgenceService} from "../../../services/agence.service"; @Component({ selector: 'app-businessunit-edit', @@ -11,16 +14,34 @@ import {Location} from "@angular/common"; }) export class BusinessunitEditComponent implements OnInit { - businessunit : Businessunit | undefined; + businessunit = {} as Businessunit ; + agences : Agence[] = []; + agence = {} as Agence ; + + + registerForm!: FormGroup; + submitted = false; constructor( private route: ActivatedRoute, private businessunitService: BusinessunitService, - private location: Location + private agenceService: AgenceService, + private location: Location, + private formBuilder: FormBuilder ) { } ngOnInit(): void { - this.getBusinessunit() + this.getBusinessunit(); + this.getAgences(); + this.registerForm = this.formBuilder.group({ + name: ['', Validators.required], + agenceId: ['',Validators.required] + }); + } + + getAgences():void { + this.agenceService.getAgences() + .subscribe(agences => this.agences = agences); } getBusinessunit(): void { @@ -47,4 +68,22 @@ export class BusinessunitEditComponent implements OnInit { } } + onSubmit() { + this.submitted = true; + + if (this.registerForm.invalid) { + return; + } + this.businessunit.name = this.registerForm.value.name + this.businessunit.agenceId = this.registerForm.value.agenceId + this.save() + } + + get f() { return this.registerForm.controls; } + + onReset() { + this.submitted = false; + this.registerForm.reset(); + } + } diff --git a/src/app/components/businessunit/businessunit.component.html b/src/app/components/businessunit/businessunit.component.html index ee4c686..99227cb 100644 --- a/src/app/components/businessunit/businessunit.component.html +++ b/src/app/components/businessunit/businessunit.component.html @@ -20,9 +20,30 @@

Ajouter une Business Unit :

- +
- +
+ + +
+
Le nom d'une business unit est obligatoire
+
+
+ +
+ + +
+
Vous devez choisir l'agence à laquelle appartient la business unit
+
+
+ +
+ + +
+
diff --git a/src/app/components/businessunit/businessunit.component.ts b/src/app/components/businessunit/businessunit.component.ts index f11d8de..9dc86f0 100644 --- a/src/app/components/businessunit/businessunit.component.ts +++ b/src/app/components/businessunit/businessunit.component.ts @@ -4,6 +4,7 @@ import {HttpClient} from "@angular/common/http"; import {BusinessunitService} from "../../services/businessunit.service"; import {Agence} from "../../interfaces/agence"; import {AgenceService} from "../../services/agence.service"; +import {FormBuilder, FormGroup, Validators} from "@angular/forms"; @Component({ selector: 'app-businessunit', @@ -17,15 +18,23 @@ export class BusinessunitComponent implements OnInit { agences : Agence[] = []; agence = {} as Agence ; + registerForm!: FormGroup; + submitted = false; + constructor( private http : HttpClient, private businessunitService: BusinessunitService, private agenceService: AgenceService, + private formBuilder: FormBuilder ) { } ngOnInit(): void { this.getBusinessunits(); this.getAgences(); + this.registerForm = this.formBuilder.group({ + name: ['', Validators.required], + agenceId: ['',Validators.required] + }); } getBusinessunits():void { @@ -45,4 +54,21 @@ export class BusinessunitComponent implements OnInit { }); } + onSubmit() { + this.submitted = true; + + if (this.registerForm.invalid) { + return; + } + this.businessunit = this.registerForm.value + this.add(this.businessunit) + } + + get f() { return this.registerForm.controls; } + + onReset() { + this.submitted = false; + this.registerForm.reset(); + } + }