|
|
@ -3,6 +3,8 @@ import {Agence} from "../../interfaces/agence"; |
|
|
|
import {HttpClient} from "@angular/common/http"; |
|
|
|
import {HttpClient} from "@angular/common/http"; |
|
|
|
import {AgenceService} from "../../services/agence.service"; |
|
|
|
import {AgenceService} from "../../services/agence.service"; |
|
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; |
|
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; |
|
|
|
|
|
|
|
import {Businessunit} from "../../interfaces/businessunit"; |
|
|
|
|
|
|
|
import {BusinessunitService} from "../../services/businessunit.service"; |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
@Component({ |
|
|
|
selector: 'app-agence', |
|
|
|
selector: 'app-agence', |
|
|
@ -11,7 +13,9 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms'; |
|
|
|
}) |
|
|
|
}) |
|
|
|
export class AgenceComponent implements OnInit { |
|
|
|
export class AgenceComponent implements OnInit { |
|
|
|
agences : Agence[] = []; |
|
|
|
agences : Agence[] = []; |
|
|
|
agence = {} as Agence ; |
|
|
|
agence = {} as Agence; |
|
|
|
|
|
|
|
businessUnits : Businessunit[] = []; |
|
|
|
|
|
|
|
businessUnit = {} as Businessunit ; |
|
|
|
|
|
|
|
|
|
|
|
registerForm!: FormGroup; |
|
|
|
registerForm!: FormGroup; |
|
|
|
submitted = false; |
|
|
|
submitted = false; |
|
|
@ -19,13 +23,16 @@ export class AgenceComponent implements OnInit { |
|
|
|
constructor( |
|
|
|
constructor( |
|
|
|
private http : HttpClient, |
|
|
|
private http : HttpClient, |
|
|
|
private agenceService: AgenceService, |
|
|
|
private agenceService: AgenceService, |
|
|
|
|
|
|
|
private businessUnitService: BusinessunitService, |
|
|
|
private formBuilder: FormBuilder |
|
|
|
private formBuilder: FormBuilder |
|
|
|
) { } |
|
|
|
) { } |
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
ngOnInit(): void { |
|
|
|
this.getAgences(); |
|
|
|
this.getAgences(); |
|
|
|
|
|
|
|
this.getBusinessUnits(); |
|
|
|
this.registerForm = this.formBuilder.group({ |
|
|
|
this.registerForm = this.formBuilder.group({ |
|
|
|
name: ['', Validators.required] |
|
|
|
name: ['', Validators.required], |
|
|
|
|
|
|
|
businessUnitId: ['',Validators.required] |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -34,6 +41,11 @@ export class AgenceComponent implements OnInit { |
|
|
|
.subscribe(agences => this.agences = agences); |
|
|
|
.subscribe(agences => this.agences = agences); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getBusinessUnits() { |
|
|
|
|
|
|
|
this.businessUnitService.getBusinessunits() |
|
|
|
|
|
|
|
.subscribe(businessunits => this.businessUnits = businessunits); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
add(agence: Agence): void { |
|
|
|
add(agence: Agence): void { |
|
|
|
this.agenceService.addAgence(agence) |
|
|
|
this.agenceService.addAgence(agence) |
|
|
|
.subscribe(agence => { |
|
|
|
.subscribe(agence => { |
|
|
@ -47,7 +59,8 @@ export class AgenceComponent implements OnInit { |
|
|
|
if (this.registerForm.invalid) { |
|
|
|
if (this.registerForm.invalid) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this.agence = this.registerForm.value |
|
|
|
this.agence.name = this.registerForm.value.name |
|
|
|
|
|
|
|
this.agence.businessUnitId = this.registerForm.value.businessUnitId |
|
|
|
this.add(this.agence) |
|
|
|
this.add(this.agence) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -58,4 +71,5 @@ export class AgenceComponent implements OnInit { |
|
|
|
this.registerForm.reset(); |
|
|
|
this.registerForm.reset(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|