diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 88b80fd..f1d256a 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -14,6 +14,8 @@ import {ReferencementComponent} from "./components/referencement/referencement.c import {ReferencementAddComponent} from "./components/referencement/referencement-add/referencement-add.component"; import {ReferencementEditComponent} from "./components/referencement/referencement-edit/referencement-edit.component"; import {PeriodeEssaiAddComponent} from "./components/periode-essai/periode-essai-add/periode-essai-add.component"; +import {AgenceAddComponent} from "./components/agence/agence-add/agence-add.component"; +import {BusinessunitAddComponent} from "./components/businessunit/businessunit-add/businessunit-add.component"; const routes: Routes = [ {path: '', redirectTo: '/home', pathMatch: 'full'}, @@ -25,8 +27,10 @@ const routes: Routes = [ {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/add', component: AgenceAddComponent, data: {title: 'Agences'}}, {path: 'agences/:id', component: AgenceEditComponent, data: {title: 'Agences'}}, {path: 'businessunits', component: BusinessunitComponent, data: {title: 'BusinessUnits'}}, + {path: 'businessunits/add', component: BusinessunitAddComponent, data: {title: 'BusinessUnits'}}, {path: 'businessunits/:id', component: BusinessunitEditComponent, data: {title: 'BusinessUnits'}}, {path: 'periodeessais', component: PeriodeEssaiComponent, data: {title: 'Periodes d\'Essai'}}, {path: 'periodeessais/add', component: PeriodeEssaiAddComponent, data: {title: 'Periodes d\'Essai'}}, diff --git a/src/app/app.component.html b/src/app/app.component.html index ce9d844..a9b3a09 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -2,12 +2,25 @@ - - +
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ diff --git a/src/app/components/agence/agence-add/agence-add.component.scss b/src/app/components/agence/agence-add/agence-add.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/agence/agence-add/agence-add.component.ts b/src/app/components/agence/agence-add/agence-add.component.ts new file mode 100644 index 0000000..75064e2 --- /dev/null +++ b/src/app/components/agence/agence-add/agence-add.component.ts @@ -0,0 +1,91 @@ +import { Component, OnInit } from '@angular/core'; +import {Agence} from "../../../interfaces/agence"; +import {Businessunit} from "../../../interfaces/businessunit"; +import {FormBuilder, FormGroup, Validators} from "@angular/forms"; +import {HttpClient} from "@angular/common/http"; +import {AgenceService} from "../../../services/agence.service"; +import {BusinessunitService} from "../../../services/businessunit.service"; +import {ToastrService} from "ngx-toastr"; + +@Component({ + selector: 'app-agence-add', + templateUrl: './agence-add.component.html', + styleUrls: ['./agence-add.component.scss'] +}) +export class AgenceAddComponent implements OnInit { + + agences: Agence[] = []; + agence = {} as Agence; + businessUnits: Businessunit[] = []; + businessUnit = {} as Businessunit; + + registerForm!: FormGroup; + submitted = false; + + constructor( + private http: HttpClient, + private agenceService: AgenceService, + private businessUnitService: BusinessunitService, + private formBuilder: FormBuilder, + private toastr: ToastrService + ) { + } + + get f() { + return this.registerForm.controls; + } + + ngOnInit(): void { + this.getAgences(); + this.getBusinessUnits(); + this.registerForm = this.formBuilder.group({ + name: ['', Validators.required], + businessUnitId: ['', Validators.required] + }); + } + + getAgences(): void { + this.agenceService.getAgences() + .subscribe(agences => this.agences = agences); + } + + getBusinessUnits() { + this.businessUnitService.getBusinessunits() + .subscribe(businessunits => this.businessUnits = businessunits); + } + + add(agence: Agence): void { + this.agenceService.addAgence(agence) + .subscribe(agence => { + this.agences.push(agence); + this.showSuccess(); + }, + () => { + this.showError() + }); + } + + onSubmit() { + this.submitted = true; + + if (this.registerForm.invalid) { + return; + } + this.agence.name = this.registerForm.value.name + this.agence.businessUnitId = this.registerForm.value.businessUnitId + this.add(this.agence) + } + + onReset() { + this.submitted = false; + this.registerForm.reset(); + } + + showSuccess() { + this.toastr.success('Création réussie', 'Agence'); + } + + showError() { + this.toastr.error('Création échouée', 'Agence'); + } +} diff --git a/src/app/components/agence/agence-edit/agence-edit.component.html b/src/app/components/agence/agence-edit/agence-edit.component.html index 24ae14d..48a5449 100644 --- a/src/app/components/agence/agence-edit/agence-edit.component.html +++ b/src/app/components/agence/agence-edit/agence-edit.component.html @@ -1,7 +1,6 @@

{{agence.name | uppercase}}

-
id : {{agence.id}}
-
diff --git a/src/app/components/agence/agence.component.html b/src/app/components/agence/agence.component.html index 7f13c37..2354236 100644 --- a/src/app/components/agence/agence.component.html +++ b/src/app/components/agence/agence.component.html @@ -1,41 +1,12 @@
-

Ajouter une agence :

- - - -
- - -
-
Le nom d'une agence est obligatoire
-
-
- -
- - -
-
Vous devez choisir la business unit à laquelle appartient - l'agence -
-
-
- - -
- - -
- -

Agences

+
+

Pour ajouter une nouvelle agence, cliquez ici :

+ +
+
@@ -46,13 +17,12 @@ - - + +
{{agence.name}}{{getBusinessUnitById(agence.businessUnitId).name}}{{agence.name}}{{getBusinessUnitById(agence.businessUnitId).name}} Modifier
-
diff --git a/src/app/components/agence/agence.component.ts b/src/app/components/agence/agence.component.ts index 59cf0fe..c19d9d1 100644 --- a/src/app/components/agence/agence.component.ts +++ b/src/app/components/agence/agence.component.ts @@ -2,10 +2,8 @@ import {Component, OnInit} from '@angular/core'; import {Agence} from "../../interfaces/agence"; import {HttpClient} from "@angular/common/http"; import {AgenceService} from "../../services/agence.service"; -import {FormBuilder, FormGroup, Validators} from '@angular/forms'; import {Businessunit} from "../../interfaces/businessunit"; import {BusinessunitService} from "../../services/businessunit.service"; -import {ToastrService} from "ngx-toastr"; @Component({ selector: 'app-agence', @@ -18,29 +16,18 @@ export class AgenceComponent implements OnInit { businessUnits: Businessunit[] = []; businessUnit = {} as Businessunit; - registerForm!: FormGroup; - submitted = false; constructor( private http: HttpClient, private agenceService: AgenceService, private businessUnitService: BusinessunitService, - private formBuilder: FormBuilder, - private toastr: ToastrService ) { } - get f() { - return this.registerForm.controls; - } ngOnInit(): void { this.getAgences(); this.getBusinessUnits(); - this.registerForm = this.formBuilder.group({ - name: ['', Validators.required], - businessUnitId: ['', Validators.required] - }); } getAgences(): void { @@ -48,9 +35,9 @@ export class AgenceComponent implements OnInit { .subscribe(agences => this.agences = agences); } - getBusinessUnits() { + getBusinessUnits(): void { this.businessUnitService.getBusinessunits() - .subscribe(businessunits => this.businessUnits = businessunits); + .subscribe(bus => this.businessUnits = bus); } getBusinessUnitById(id: number): Businessunit { @@ -64,39 +51,6 @@ export class AgenceComponent implements OnInit { return bu; } - add(agence: Agence): void { - this.agenceService.addAgence(agence) - .subscribe(agence => { - this.agences.push(agence); - this.showSuccess(); - }, - () => { - this.showError() - }); - } - - onSubmit() { - this.submitted = true; - - if (this.registerForm.invalid) { - return; - } - this.agence.name = this.registerForm.value.name - this.agence.businessUnitId = this.registerForm.value.businessUnitId - this.add(this.agence) - } - onReset() { - this.submitted = false; - this.registerForm.reset(); - } - - showSuccess() { - this.toastr.success('Création réussie', 'Agence'); - } - - showError() { - this.toastr.error('Création échouée', 'Agence'); - } } diff --git a/src/app/components/businessunit/businessunit-add/businessunit-add.component.html b/src/app/components/businessunit/businessunit-add/businessunit-add.component.html new file mode 100644 index 0000000..4aecfd7 --- /dev/null +++ b/src/app/components/businessunit/businessunit-add/businessunit-add.component.html @@ -0,0 +1,17 @@ +

Ajouter une Business Unit :

+ +
+ +
+ + +
+
Le nom d'une business unit est obligatoire
+
+
+ +
+ + +
+
diff --git a/src/app/components/businessunit/businessunit-add/businessunit-add.component.scss b/src/app/components/businessunit/businessunit-add/businessunit-add.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/businessunit/businessunit-add/businessunit-add.component.ts b/src/app/components/businessunit/businessunit-add/businessunit-add.component.ts new file mode 100644 index 0000000..4f37c3d --- /dev/null +++ b/src/app/components/businessunit/businessunit-add/businessunit-add.component.ts @@ -0,0 +1,80 @@ +import { Component, OnInit } from '@angular/core'; +import {Businessunit} from "../../../interfaces/businessunit"; +import {FormBuilder, FormGroup, Validators} from "@angular/forms"; +import {HttpClient} from "@angular/common/http"; +import {BusinessunitService} from "../../../services/businessunit.service"; +import {ToastrService} from "ngx-toastr"; + +@Component({ + selector: 'app-businessunit-add', + templateUrl: './businessunit-add.component.html', + styleUrls: ['./businessunit-add.component.scss'] +}) +export class BusinessunitAddComponent implements OnInit { + + businessunits: Businessunit[] = []; + businessunit = {} as Businessunit; + + registerForm!: FormGroup; + submitted = false; + + constructor( + private http: HttpClient, + private businessunitService: BusinessunitService, + private formBuilder: FormBuilder, + private toastr: ToastrService + ) { + } + + get f() { + return this.registerForm.controls; + } + + ngOnInit(): void { + this.getBusinessunits(); + this.registerForm = this.formBuilder.group({ + name: ['', Validators.required], + }); + } + + getBusinessunits(): void { + this.businessunitService.getBusinessunits() + .subscribe(businessunits => this.businessunits = businessunits); + } + + add(businessunit: Businessunit): void { + this.businessunitService.addBusinessunit(businessunit) + .subscribe(businessunit => { + this.businessunits.push(businessunit); + this.showSuccess(); + }, + () => { + this.showError() + }); + + } + + onSubmit() { + this.submitted = true; + + if (this.registerForm.invalid) { + return; + } + this.businessunit = this.registerForm.value + this.add(this.businessunit) + } + + onReset() { + this.submitted = false; + this.registerForm.reset(); + } + + showSuccess() { + this.toastr.success('Création réussie', 'Business Unit'); + } + + showError() { + this.toastr.error('Création échouée', 'Business Unit'); + } + +} diff --git a/src/app/components/businessunit/businessunit.component.html b/src/app/components/businessunit/businessunit.component.html index a27ec9f..2b003cc 100644 --- a/src/app/components/businessunit/businessunit.component.html +++ b/src/app/components/businessunit/businessunit.component.html @@ -1,23 +1,5 @@
-

Ajouter une Business Unit :

- -
- -
- - -
-
Le nom d'une business unit est obligatoire
-
-
- -
- - -
-
-

Business Units

diff --git a/src/app/components/businessunit/businessunit.component.ts b/src/app/components/businessunit/businessunit.component.ts index c0469b2..2de451e 100644 --- a/src/app/components/businessunit/businessunit.component.ts +++ b/src/app/components/businessunit/businessunit.component.ts @@ -2,8 +2,7 @@ import {Component, OnInit} from '@angular/core'; import {Businessunit} from "../../interfaces/businessunit"; import {HttpClient} from "@angular/common/http"; import {BusinessunitService} from "../../services/businessunit.service"; -import {FormBuilder, FormGroup, Validators} from "@angular/forms"; -import {ToastrService} from "ngx-toastr"; +import {FormGroup} from "@angular/forms"; @Component({ @@ -22,20 +21,12 @@ export class BusinessunitComponent implements OnInit { constructor( private http: HttpClient, private businessunitService: BusinessunitService, - private formBuilder: FormBuilder, - private toastr: ToastrService ) { } - get f() { - return this.registerForm.controls; - } ngOnInit(): void { this.getBusinessunits(); - this.registerForm = this.formBuilder.group({ - name: ['', Validators.required], - }); } getBusinessunits(): void { @@ -43,39 +34,6 @@ export class BusinessunitComponent implements OnInit { .subscribe(businessunits => this.businessunits = businessunits); } - add(businessunit: Businessunit): void { - this.businessunitService.addBusinessunit(businessunit) - .subscribe(businessunit => { - this.businessunits.push(businessunit); - this.showSuccess(); - }, - error => { - this.showError() - }); - - } - - onSubmit() { - this.submitted = true; - - if (this.registerForm.invalid) { - return; - } - this.businessunit = this.registerForm.value - this.add(this.businessunit) - } - onReset() { - this.submitted = false; - this.registerForm.reset(); - } - - showSuccess() { - this.toastr.success('Création réussie', 'Business Unit'); - } - - showError() { - this.toastr.error('Création échouée', 'Business Unit'); - } }