modif restau manque checkbox

This commit is contained in:
Thomas Cardon 2022-03-07 16:17:44 +01:00
parent 500ba0811a
commit 9fe71c85d9
12 changed files with 77 additions and 25 deletions

View File

@ -78,17 +78,17 @@
<div class="form-control">
<p class="text-left"> Sur Place :</p>
<div class="form-check form-check-inline">
<input type="radio" class="form-check-input" id="checkboxSurPlaceTrue" name="surPlaceFc" value=true
<input type="radio" class="form-check-input" id="checkboxSurPlaceTrue" name="surPlaceFc" [value]="true"
formControlName="surPlaceFc">
<label class="form-check-label" for="checkboxSurPlaceTrue">Oui</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" class="form-check-input" id="checkboxSurPlaceFalse" name="surPlaceFc"
value=false formControlName="surPlaceFc">
[value]="false" formControlName="surPlaceFc">
<label class="form-check-label" for="checkboxSurPlaceFalse">Non</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" class="form-check-input" id="checkboxSurPlaceNull" name="surPlaceFc" value=null
<input type="radio" class="form-check-input" id="checkboxSurPlaceNull" name="surPlaceFc" [value]="null"
formControlName="surPlaceFc">
<label class="form-check-label" for="checkboxSurPlaceNull">Pas d'infos</label>
</div>
@ -98,17 +98,17 @@
<p class="text-left"> A Emporter :</p>
<div class="form-check form-check-inline">
<input type="radio" class="form-check-input" id="checkboxAEmporterTrue" name="aEmporterFc"
value=true formControlName="aEmporterFc">
[value]="true" formControlName="aEmporterFc">
<label class="form-check-label" for="checkboxAEmporterTrue">Oui</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" class="form-check-input" id="checkboxAEmporterFalse" name="aEmporterFc"
value=false formControlName="aEmporterFc">
[value]="false" formControlName="aEmporterFc">
<label class="form-check-label" for="checkboxAEmporterFalse">Non</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" class="form-check-input" id="checkboxAEmporterNull" name="aEmporterFc"
value=null formControlName="aEmporterFc">
[value]="null" formControlName="aEmporterFc">
<label class="form-check-label" for="checkboxAEmporterNull">Pas d'infos</label>
</div>
</div>
@ -116,17 +116,17 @@
<div class="form-control">
<p class="text-left"> Accès PMR :</p>
<div class="form-check form-check-inline">
<input type="radio" class="form-check-input" id="checkboxAccesPMRTrue" name="accesPMRFc" value=true
<input type="radio" class="form-check-input" id="checkboxAccesPMRTrue" name="accesPMRFc" [value]="true"
formControlName="accesPMRFc">
<label class="form-check-label" for="checkboxAccesPMRTrue">Oui</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" class="form-check-input" id="checkboxAccesPMRFalse" name="accesPMRFc"
value=false formControlName="accesPMRFc">
[value]="false" formControlName="accesPMRFc">
<label class="form-check-label" for="checkboxAccesPMRFalse">Non</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" class="form-check-input" id="checkboxAccesPMRNull" name="accesPMRFc" value=null
<input type="radio" class="form-check-input" id="checkboxAccesPMRNull" name="accesPMRFc" [value]="null"
formControlName="accesPMRFc">
<label class="form-check-label" for="checkboxAccesPMRNull">Pas d'infos</label>
</div>

View File

@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { Restaurant } from 'src/app/pages/models/restaurant';
import { ApiBackService } from 'src/app/services/api-back.service';
@ -18,6 +18,7 @@ export class AddRestauComponent implements OnInit {
public errorMessage?: string;
public listCategories$: Observable<any[]>;
public expanded = false;
public idRestau : Subscription | undefined;
constructor(private router: Router, private apiBackService: ApiBackService) {
this.signupForm = new FormGroup({});
@ -38,6 +39,36 @@ export class AddRestauComponent implements OnInit {
accesPMRFc: new FormControl(''),
typerestausFc: new FormArray([])
})
this.idRestau = this.apiBackService.restauAModif.subscribe(restau => {
// const formArray: FormArray = this.signupForm.get('typerestausFc') as FormArray;
// if(restau.typerestaus != undefined){
// for (let index = 0; index < restau.typerestaus.length; index++) {
// //listCategories.filter(categorie => categorie.id == restau.typerestaus[index]['id'])
// this.signupForm.patchValue({typerestausFc : {restau.typerestaus[index]['id'] : true}});
// formArray.push(new FormControl(restau.typerestaus[index]['id'] : true));
// }
// }
// console.log(formArray);
this.signupForm = new FormGroup({
nomFc: new FormControl(restau.nom, [Validators.required]),
prixFc: new FormControl(restau.prix),
longitudeFc: new FormControl(restau.longitude, [Validators.required,]), // chercher une meilleure regex
latitudeFc: new FormControl(restau.latitude, [Validators.required]),
adresseFc: new FormControl(restau.adresse, [Validators.required]),
telephoneFc: new FormControl(restau.telephone),
websiteFc: new FormControl(restau.website, [Validators.pattern("/^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/")]),
surPlaceFc: new FormControl(restau.surPlace),
aEmporterFc: new FormControl(restau.aEmporter),
accesPMRFc: new FormControl(restau.accesPMR),
typerestausFc: new FormArray([])
})
}
)
}
public getCategories(): Observable<any[]> {
@ -117,5 +148,12 @@ export class AddRestauComponent implements OnInit {
}
ngOnDestroy() {
if (this.idRestau) {
this.idRestau.unsubscribe();
this.idRestau = undefined;
}
}
}

View File

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

View File

@ -10,7 +10,6 @@ import { ApiBackService } from 'src/app/services/api-back.service';
export class UpdateDelRestauComponent implements OnInit {
restauList : Restaurant[];
@Output() idRestauAModif = new EventEmitter<number>();
constructor(private apiBackService : ApiBackService) {
this.restauList = [];
@ -36,8 +35,8 @@ export class UpdateDelRestauComponent implements OnInit {
});
}
modifRestau(idRestau : number | undefined){
this.idRestauAModif.emit(idRestau);
modifRestau(restau : Restaurant){
this.apiBackService.idRestauAModifier(restau);
}
}

View File

@ -18,7 +18,7 @@ const routes: Routes = [
{ path: 'favoris', component: FavorisUserComponent },
{ path: 'filtres', component: FiltersPageComponent },
{ path: 'Deconnexion', redirectTo: 'home'},
{path: 'restaurants', canActivate: [AuthGuard], component: RestoPageComponent},
{path: 'restaurants', canActivate: [AuthGuard], /*data : {ROLE : "ROLE_ADMIN"},*/ component: RestoPageComponent},
{path: 'page-not-found',component: PageNotFoundComponent},
{path: 'admin', component: AdminPageComponent},
{path: '**', redirectTo: 'page-not-found' }

View File

@ -17,7 +17,7 @@ export class NavBarComponent implements OnInit {
}
onCloseSession() : void {
this.tokenService.destroyToken();
this.tokenService.destroyToken(this.tokenKey);
this.route.navigate(['signin']);
}

View File

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

View File

@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, EventEmitter, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { ApiBackService } from 'src/app/services/api-back.service';
@ -11,6 +11,7 @@ import { Restaurant } from '../models/restaurant';
})
export class AdminPageComponent implements OnInit {
sendId = new EventEmitter<number>();
constructor( ) {
@ -18,6 +19,9 @@ export class AdminPageComponent implements OnInit {
ngOnInit(): void {
}
sendIdRestau(idRestau : number){
this.sendId.emit(idRestau);
}
}

View File

@ -1,4 +1,4 @@
import { Injectable, Input } from '@angular/core';
import { EventEmitter, Injectable, Input } from '@angular/core';
import { Observable, of, Subject } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
@ -15,6 +15,7 @@ export class ApiBackService {
public restoFilter: any[];
public routeParam?: string;
@Input() restaurant: any;
public restauAModif = new EventEmitter<Restaurant>();
constructor(private httpClient: HttpClient) {
this.restoFilter = [];
@ -70,4 +71,10 @@ export class ApiBackService {
return this.httpClient.get<User>(`${environment.apiUrl}/user/${id}`);
}
public idRestauAModifier(restau:Restaurant): void {
this.restauAModif.emit(restau);
}
}

View File

@ -11,6 +11,7 @@ import { TokenService } from './token.service';
})
export class AuthGuard implements CanActivate {
private tokenKey: string;
constructor(private router: Router, private tokenService : TokenService){
this.tokenKey = environment.tokenKey;
}
@ -23,6 +24,9 @@ export class AuthGuard implements CanActivate {
if(token) {
const decodedToken = jwt_decode<any>(token);
// TODO boucle sur le ['auth'] pour controler le role et en fonction de ca renvoyer true ou false ac redirection page403
console.log('decodedToken : ', decodedToken);
@ -31,7 +35,7 @@ export class AuthGuard implements CanActivate {
const dateExp = new Date(decodedToken.exp * 1000);
if(new Date() >= dateExp) {
// le token a expiré, je n'autorise pas l'accès
this.tokenService.destroyToken();
this.tokenService.destroyToken(this.tokenKey);
this.router.navigate(['signin']);
return false;
}

View File

@ -50,6 +50,7 @@ export class AuthService {
console.log('Service : ', x.token);
// Modification à faire ici
localStorage.setItem(this.tokenKey, x.token);
//localStorage.setItem('ROLE', "ROLE_READER");
return x; // permet de renvoyer la réponse à l'initiateur (page Signin) après le traitement du map
})
);

View File

@ -33,7 +33,8 @@ export class TokenService {
}
public destroyToken(): void {
localStorage.removeItem(this.tokenKey);
public destroyToken(tokenKey : string): void {
localStorage.removeItem(tokenKey);
localStorage.removeItem('ROLE');
}
}