|
|
|
@ -3,6 +3,8 @@ 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', |
|
|
|
@ -20,8 +22,10 @@ export class BusinessunitComponent implements OnInit { |
|
|
|
|
constructor( |
|
|
|
|
private http: HttpClient, |
|
|
|
|
private businessunitService: BusinessunitService, |
|
|
|
|
private formBuilder: FormBuilder |
|
|
|
|
) { } |
|
|
|
|
private formBuilder: FormBuilder, |
|
|
|
|
private toastr: ToastrService |
|
|
|
|
) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.getBusinessunits(); |
|
|
|
@ -36,13 +40,15 @@ export class BusinessunitComponent implements OnInit { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|