parent
326e9935ac
commit
95ad6f1d20
@ -0,0 +1,33 @@ |
||||
<h3>Ajouter une agence : </h3> |
||||
|
||||
<form (ngSubmit)="onSubmit()" [formGroup]="registerForm"> |
||||
|
||||
<div class="form-group col-12 col-sm-6 col-md-4 col-lg-3 mb-2"> |
||||
<label class="form-label">Nom</label> |
||||
<input [ngClass]="{ 'is-invalid': submitted && f.name.errors }" class="form-control" formControlName="name"> |
||||
<div *ngIf="submitted && f.name.errors" class="invalid-feedback"> |
||||
<div *ngIf="f.name.errors.required">Le nom d'une agence est obligatoire</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="form-group col-12 col-md-6"> |
||||
<label class="form-label">Business Unit</label> |
||||
<select [ngClass]="{ 'is-invalid': submitted && f.businessUnitId.errors }" class="form-select" |
||||
formControlName="businessUnitId" |
||||
id="businessUnit-select"> |
||||
<option disabled selected value="">Choisissez la business unit de cette agence</option> |
||||
<option *ngFor="let businessUnit of businessUnits" [ngValue]="businessUnit.id">{{businessUnit.name}}</option> |
||||
</select> |
||||
<div *ngIf="submitted && f.businessUnitId.errors" class="invalid-feedback"> |
||||
<div *ngIf="f.businessUnitId.errors.required">Vous devez choisir la business unit à laquelle appartient |
||||
l'agence |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
|
||||
<div> |
||||
<button type="submit">Créer l'agence</button> |
||||
<button type="reset">Effacer</button> |
||||
</div> |
||||
</form> |
@ -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'); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<h3>Ajouter une Business Unit : </h3> |
||||
|
||||
<form (ngSubmit)="onSubmit()" [formGroup]="registerForm"> |
||||
|
||||
<div class="form-group col-12 col-sm-6 col-md-4 col-lg-3 mb-2"> |
||||
<label class="form-label">Nom</label> |
||||
<input [ngClass]="{ 'is-invalid': submitted && f.name.errors }" class="form-control" formControlName="name"> |
||||
<div *ngIf="submitted && f.name.errors" class="invalid-feedback"> |
||||
<div *ngIf="f.name.errors.required">Le nom d'une business unit est obligatoire</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<div> |
||||
<button type="submit">Créer la business unit</button> |
||||
<button (click)="onReset()" type="reset">Effacer</button> |
||||
</div> |
||||
</form> |
@ -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'); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue