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 :
-
-
-
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 :
+
+
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 :
-
-
-
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');
- }
}