From 500ba0811afbd4e48ca9e70211c2ea867061bd48 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Fri, 4 Mar 2022 15:21:24 +0100 Subject: [PATCH] ajout categ dans formulaire creation restau --- .../add-restau/add-restau.component.html | 15 ++- .../add-restau/add-restau.component.ts | 109 ++++++++++-------- .../update-del-restau.component.html | 3 + .../update-del-restau.component.ts | 7 +- .../admin-page/admin-page.component.html | 4 +- src/app/pages/models/restaurant.ts | 2 +- src/app/pages/models/user.ts | 2 +- 7 files changed, 91 insertions(+), 51 deletions(-) diff --git a/src/app/admin-component/add-restau/add-restau.component.html b/src/app/admin-component/add-restau/add-restau.component.html index f9a446c..f552562 100644 --- a/src/app/admin-component/add-restau/add-restau.component.html +++ b/src/app/admin-component/add-restau/add-restau.component.html @@ -9,15 +9,28 @@ 'is-invalid': signupForm.controls['nomFc'].touched && !signupForm.controls['nomFc'].valid}"> + + + +
; public expanded = false; - constructor( private router: Router, private apiBackService : ApiBackService) { + constructor(private router: Router, private apiBackService: ApiBackService) { this.signupForm = new FormGroup({}); - this.listCategories = []; + this.listCategories$ = this.getCategories(); } ngOnInit(): void { - - this.getCategories(); - this.signupForm = new FormGroup({ - nomFc : new FormControl('', [Validators.required]), - prixFc : new FormControl(''), - longitudeFc : new FormControl('', [Validators.required,]), // chercher une meilleure regex - latitudeFc : new FormControl('', [Validators.required]), - adresseFc : new FormControl('', [Validators.required]), - telephoneFc : new FormControl(''), - websiteFc : new FormControl('',[Validators.pattern("/^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/")]), - surPlaceFc : new FormControl(''), - aEmporterFc : new FormControl(''), - accesPMRFc : new FormControl(''), - // typerestausFc : new FormControl('') + nomFc: new FormControl('', [Validators.required]), + prixFc: new FormControl(''), + longitudeFc: new FormControl('', [Validators.required,]), // chercher une meilleure regex + latitudeFc: new FormControl('', [Validators.required]), + adresseFc: new FormControl('', [Validators.required]), + telephoneFc: new FormControl(''), + websiteFc: new FormControl('', [Validators.pattern("/^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/")]), + surPlaceFc: new FormControl(''), + aEmporterFc: new FormControl(''), + accesPMRFc: new FormControl(''), + typerestausFc: new FormArray([]) }) } - public getCategories() : void{ - this.apiBackService.getCategories().subscribe((listCategories: any[]) => { - // console.log(listCategories); - - this.listCategories = listCategories; - - }); + public getCategories(): Observable { + return this.apiBackService.getCategories(); } @@ -66,37 +58,64 @@ export class AddRestauComponent implements OnInit { const surPlaceFc = this.signupForm.value['surPlaceFc']; const aEmporterFc = this.signupForm.value['aEmporterFc']; const accesPMRFc = this.signupForm.value['accesPMRFc']; - // const typerestausFc = this.signupForm.value['typerestausFc']; + const typerestausFc = this.signupForm.value['typerestausFc']; + + console.log(typerestausFc); + const restaurant: Restaurant = { latitude: latitudeFc, longitude: longitudeFc, - nom : nomFc, + nom: nomFc, prix: prixFc, - adresse : adresseFc, - telephone : telephoneFc, - website : websiteFc, - surPlace : surPlaceFc, - aEmporter : aEmporterFc, - accesPMR : accesPMRFc, - // typerestaus : typerestausFc + adresse: adresseFc, + telephone: telephoneFc, + website: websiteFc, + surPlace: surPlaceFc, + aEmporter: aEmporterFc, + accesPMR: accesPMRFc, + typerestaus: typerestausFc } - if( restaurant.latitude !== '' && - restaurant.longitude !== '' && - restaurant.nom !== '' && - restaurant.adresse !== '' ) { - this.apiBackService.addRestaurant(restaurant).subscribe( - resp=> - + if (restaurant.latitude !== '' && + restaurant.longitude !== '' && + restaurant.nom !== '' && + restaurant.adresse !== '') { + this.apiBackService.addRestaurant(restaurant).subscribe( + resp => + this.router.navigate(['restaurants']) - ); - }else{ - + ); + } else { + this.errorMessage = "Renseigner les champs obligatoires **"; } - + } + onCheckChange(event : any) { + const formArray: FormArray = this.signupForm.get('typerestausFc') as FormArray; + console.log(FormArray); + + if (event.target.checked) { + + formArray.push(new FormControl({id : event.target.value})); + + }else { + let i: number = 0; + + formArray.controls.forEach((ctrl) => { + + if (ctrl.value['id'] == event.target.value) { + formArray.removeAt(i); + return; + } + + i++; + }); + } + } + + } diff --git a/src/app/admin-component/update-del-restau/update-del-restau.component.html b/src/app/admin-component/update-del-restau/update-del-restau.component.html index 3a81ced..d18c0d9 100644 --- a/src/app/admin-component/update-del-restau/update-del-restau.component.html +++ b/src/app/admin-component/update-del-restau/update-del-restau.component.html @@ -8,5 +8,8 @@
+
+ +
\ No newline at end of file diff --git a/src/app/admin-component/update-del-restau/update-del-restau.component.ts b/src/app/admin-component/update-del-restau/update-del-restau.component.ts index ea7d325..eb41ba8 100644 --- a/src/app/admin-component/update-del-restau/update-del-restau.component.ts +++ b/src/app/admin-component/update-del-restau/update-del-restau.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { Restaurant } from 'src/app/pages/models/restaurant'; import { ApiBackService } from 'src/app/services/api-back.service'; @@ -10,6 +10,7 @@ import { ApiBackService } from 'src/app/services/api-back.service'; export class UpdateDelRestauComponent implements OnInit { restauList : Restaurant[]; + @Output() idRestauAModif = new EventEmitter(); constructor(private apiBackService : ApiBackService) { this.restauList = []; @@ -35,4 +36,8 @@ export class UpdateDelRestauComponent implements OnInit { }); } + modifRestau(idRestau : number | undefined){ + this.idRestauAModif.emit(idRestau); + } + } \ No newline at end of file diff --git a/src/app/pages/admin-page/admin-page.component.html b/src/app/pages/admin-page/admin-page.component.html index 184fccc..fd8ef34 100644 --- a/src/app/pages/admin-page/admin-page.component.html +++ b/src/app/pages/admin-page/admin-page.component.html @@ -1,9 +1,9 @@
- +
\ No newline at end of file diff --git a/src/app/pages/models/restaurant.ts b/src/app/pages/models/restaurant.ts index d8faa52..5bc5060 100644 --- a/src/app/pages/models/restaurant.ts +++ b/src/app/pages/models/restaurant.ts @@ -10,5 +10,5 @@ export interface Restaurant { aEmporter?: boolean; accesPMR?: boolean; surPlace?: boolean; - typerestaus ?: any[]; + typerestaus ?: [{id : number}]; } diff --git a/src/app/pages/models/user.ts b/src/app/pages/models/user.ts index 87c6596..340925f 100644 --- a/src/app/pages/models/user.ts +++ b/src/app/pages/models/user.ts @@ -1,7 +1,7 @@ export interface User { id?:number; prenom: string; - lastName: string; + nom: string; email: string; password?: string; preference ?: object;