|
|
|
@ -1,8 +1,10 @@ |
|
|
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
|
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"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-businessunit', |
|
|
|
@ -11,17 +13,19 @@ import {FormBuilder, FormGroup, Validators} from "@angular/forms"; |
|
|
|
|
}) |
|
|
|
|
export class BusinessunitComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
businessunits : Businessunit[] = []; |
|
|
|
|
businessunit = {} as Businessunit ; |
|
|
|
|
businessunits: Businessunit[] = []; |
|
|
|
|
businessunit = {} as Businessunit; |
|
|
|
|
|
|
|
|
|
registerForm!: FormGroup; |
|
|
|
|
submitted = false; |
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
private http : HttpClient, |
|
|
|
|
private http: HttpClient, |
|
|
|
|
private businessunitService: BusinessunitService, |
|
|
|
|
private formBuilder: FormBuilder |
|
|
|
|
) { } |
|
|
|
|
private formBuilder: FormBuilder, |
|
|
|
|
private toastr: ToastrService |
|
|
|
|
) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.getBusinessunits(); |
|
|
|
@ -30,19 +34,21 @@ export class BusinessunitComponent implements OnInit { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getBusinessunits():void { |
|
|
|
|
getBusinessunits(): void { |
|
|
|
|
this.businessunitService.getBusinessunits() |
|
|
|
|
.subscribe(businessunits => this.businessunits = businessunits); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
add(businessunit: Businessunit): void { |
|
|
|
|
// let test = this.businessunitService.addBusinessunit(businessunit)
|
|
|
|
|
// .subscribe(businessunit => {
|
|
|
|
|
// this.businessunits.push(businessunit);
|
|
|
|
|
// });
|
|
|
|
|
let test = this.businessunitService.addBusinessunit(businessunit) |
|
|
|
|
this.businessunitService.addBusinessunit(businessunit) |
|
|
|
|
.subscribe(businessunit => { |
|
|
|
|
this.businessunits.push(businessunit); |
|
|
|
|
this.showSuccess(); |
|
|
|
|
}, |
|
|
|
|
error => { |
|
|
|
|
this.showError() |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
console.log(test.toPromise()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onSubmit() { |
|
|
|
@ -55,11 +61,21 @@ export class BusinessunitComponent implements OnInit { |
|
|
|
|
this.add(this.businessunit) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
get f() { return this.registerForm.controls; } |
|
|
|
|
get f() { |
|
|
|
|
return this.registerForm.controls; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|