Merge branch 'dev' into Vincent

modif thomas 04/03/2022
This commit is contained in:
Vincent Ramiere 2022-03-04 15:23:42 +01:00
commit d4530c3e1e
6 changed files with 90 additions and 50 deletions

View File

@ -9,15 +9,28 @@
'is-invalid': signupForm.controls['nomFc'].touched && !signupForm.controls['nomFc'].valid}"> 'is-invalid': signupForm.controls['nomFc'].touched && !signupForm.controls['nomFc'].valid}">
<label for="floatingInputNom">Nom **</label> <label for="floatingInputNom">Nom **</label>
</div> </div>
<!-- <div class="form-floating"> <!-- <div class="form-floating">
<select type="number" class="form-control" id="floatingInputCategories" placeholder="" name="categories" <select type="number" class="form-control" id="floatingInputCategories" placeholder="" name="categories"
formControlName="typerestausFc"> formControlName="typerestausFc">
<option value=null></option> <option value=null></option>
<option *ngFor="let category of listCategories" value={{category.id}}>{{category.libelle}}</option> <option *ngFor="let category of listCategories" value={{category.id}}>{{category.libelle}}</option>
</select> </select>
<label for="floatingInputlastName">Categorie</label> <label for="floatingInputlastName">Categorie</label>
</div> --> </div> -->
<ul>
<div class="form-floating">
<li *ngFor="let category of listCategories$ | async ">
<input type="checkbox" (change)="onCheckChange($event)" [value]="category.id"> {{
category.libelle }}
</li>
</div>
</ul>
<!-- <div class="form-group form-check" *ngFor="let category of listCategories$ | async">
<input type="checkbox" formControlName="typerestausFc" id="acceptTerms" class="form-check-input" />
<label for="acceptTerms" class="form-check-label">{{ category.libelle }}</label>
</div> -->
<div class="form-floating"> <div class="form-floating">
<input type="text" class="form-control" id="floatingInputAdresse" placeholder="" name="adresse" <input type="text" class="form-control" id="floatingInputAdresse" placeholder="" name="adresse"
formControlName="adresseFc" formControlName="adresseFc"

View File

@ -15,41 +15,33 @@ export class AddRestauComponent implements OnInit {
public signupForm: FormGroup; public signupForm: FormGroup;
public errorMessage ?: string; public errorMessage?: string;
public listCategories : any[]; public listCategories$: Observable<any[]>;
public expanded = false; public expanded = false;
constructor( private router: Router, private apiBackService : ApiBackService) { constructor(private router: Router, private apiBackService: ApiBackService) {
this.signupForm = new FormGroup({}); this.signupForm = new FormGroup({});
this.listCategories = []; this.listCategories$ = this.getCategories();
} }
ngOnInit(): void { ngOnInit(): void {
this.getCategories();
this.signupForm = new FormGroup({ this.signupForm = new FormGroup({
nomFc : new FormControl('', [Validators.required]), nomFc: new FormControl('', [Validators.required]),
prixFc : new FormControl(''), prixFc: new FormControl(''),
longitudeFc : new FormControl('', [Validators.required,]), // chercher une meilleure regex longitudeFc: new FormControl('', [Validators.required,]), // chercher une meilleure regex
latitudeFc : new FormControl('', [Validators.required]), latitudeFc: new FormControl('', [Validators.required]),
adresseFc : new FormControl('', [Validators.required]), adresseFc: new FormControl('', [Validators.required]),
telephoneFc : new FormControl(''), 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}/")]), 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(''), surPlaceFc: new FormControl(''),
aEmporterFc : new FormControl(''), aEmporterFc: new FormControl(''),
accesPMRFc : new FormControl(''), accesPMRFc: new FormControl(''),
// typerestausFc : new FormControl('') typerestausFc: new FormArray([])
}) })
} }
public getCategories() : void{ public getCategories(): Observable<any[]> {
this.apiBackService.getCategories().subscribe((listCategories: any[]) => { return this.apiBackService.getCategories();
// console.log(listCategories);
this.listCategories = listCategories;
});
} }
@ -66,37 +58,64 @@ export class AddRestauComponent implements OnInit {
const surPlaceFc = this.signupForm.value['surPlaceFc']; const surPlaceFc = this.signupForm.value['surPlaceFc'];
const aEmporterFc = this.signupForm.value['aEmporterFc']; const aEmporterFc = this.signupForm.value['aEmporterFc'];
const accesPMRFc = this.signupForm.value['accesPMRFc']; const accesPMRFc = this.signupForm.value['accesPMRFc'];
// const typerestausFc = this.signupForm.value['typerestausFc']; const typerestausFc = this.signupForm.value['typerestausFc'];
console.log(typerestausFc);
const restaurant: Restaurant = { const restaurant: Restaurant = {
latitude: latitudeFc, latitude: latitudeFc,
longitude: longitudeFc, longitude: longitudeFc,
nom : nomFc, nom: nomFc,
prix: prixFc, prix: prixFc,
adresse : adresseFc, adresse: adresseFc,
telephone : telephoneFc, telephone: telephoneFc,
website : websiteFc, website: websiteFc,
surPlace : surPlaceFc, surPlace: surPlaceFc,
aEmporter : aEmporterFc, aEmporter: aEmporterFc,
accesPMR : accesPMRFc, accesPMR: accesPMRFc,
// typerestaus : typerestausFc typerestaus: typerestausFc
} }
if( restaurant.latitude !== '' && if (restaurant.latitude !== '' &&
restaurant.longitude !== '' && restaurant.longitude !== '' &&
restaurant.nom !== '' && restaurant.nom !== '' &&
restaurant.adresse !== '' ) { restaurant.adresse !== '') {
this.apiBackService.addRestaurant(restaurant).subscribe( this.apiBackService.addRestaurant(restaurant).subscribe(
resp=> resp =>
this.router.navigate(['restaurants']) this.router.navigate(['restaurants'])
); );
}else{ } else {
this.errorMessage = "Renseigner les champs obligatoires **"; 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++;
});
}
}
} }

View File

@ -8,5 +8,8 @@
<div> <div>
<button class="btn btn-danger" type="button" (click)="deleteRestau(restau.id)"><i class="bi bi-trash"></i></button> <button class="btn btn-danger" type="button" (click)="deleteRestau(restau.id)"><i class="bi bi-trash"></i></button>
</div> </div>
<div>
<button class="btn btn-warn" type="button" (click)="modifRestau(restau.id)"><i class="bi bi-gear"></i></button>
</div>
</li> </li>
</ul> </ul>

View File

@ -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 { Restaurant } from 'src/app/pages/models/restaurant';
import { ApiBackService } from 'src/app/services/api-back.service'; 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 { export class UpdateDelRestauComponent implements OnInit {
restauList : Restaurant[]; restauList : Restaurant[];
@Output() idRestauAModif = new EventEmitter<number>();
constructor(private apiBackService : ApiBackService) { constructor(private apiBackService : ApiBackService) {
this.restauList = []; this.restauList = [];
@ -30,4 +31,8 @@ export class UpdateDelRestauComponent implements OnInit {
}); });
} }
modifRestau(idRestau : number | undefined){
this.idRestauAModif.emit(idRestau);
}
} }

View File

@ -1,9 +1,9 @@
<div class="container"> <div class="container">
<div class="d-flex flex-row justify-content-around"><div> <div class="d-flex flex-row justify-content-around"><div>
<app-add-restau></app-add-restau> <app-add-restau ></app-add-restau>
</div> </div>
<div class="search-bar"> <div class="search-bar">
<app-update-del-restau></app-update-del-restau> <app-update-del-restau ></app-update-del-restau>
</div> </div>
</div> </div>
</div> </div>

View File

@ -10,5 +10,5 @@ export interface Restaurant {
aEmporter?: boolean; aEmporter?: boolean;
accesPMR?: boolean; accesPMR?: boolean;
surPlace?: boolean; surPlace?: boolean;
typerestaus ?: any[]; typerestaus ?: [{id : number}];
} }