From a6d96e2280945e37ee206ef8fd435d56d9cb4a0b Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Tue, 15 Feb 2022 15:18:16 +0100 Subject: [PATCH 1/2] template-page in appModule --- src/app/app.module.ts | 3 ++- src/app/card-resto/card-resto.component.html | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 01922e4..d7a4ae2 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -34,7 +34,8 @@ import { TemplatePageComponent } from './components/template-page/template-page. FiltersPageComponent, AvisBarComponent, IconComponent, - SigninComponent + SigninComponent, + TemplatePageComponent ], imports: [ BrowserModule, diff --git a/src/app/card-resto/card-resto.component.html b/src/app/card-resto/card-resto.component.html index 48b327f..daadf18 100644 --- a/src/app/card-resto/card-resto.component.html +++ b/src/app/card-resto/card-resto.component.html @@ -48,7 +48,11 @@

- Pas de site Web + +
+

Pas de site Web

+
+
From 2170ef0f6542944cd07b48f54fdaa0295eb191eb Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Wed, 16 Feb 2022 12:03:15 +0100 Subject: [PATCH 2/2] filtres prix = ok --- .../card-category/card-category.component.ts | 10 +- .../filters-page/filters-page.component.html | 206 ++++++++++-------- .../filters-page/filters-page.component.ts | 41 ++-- .../pages/home-page/home-page.component.ts | 9 +- .../pages/resto-page/resto-page.component.ts | 16 +- src/app/services/api-back.service.ts | 12 +- 6 files changed, 165 insertions(+), 129 deletions(-) diff --git a/src/app/card-category/card-category.component.ts b/src/app/card-category/card-category.component.ts index 1d495b8..1bac8cd 100644 --- a/src/app/card-category/card-category.component.ts +++ b/src/app/card-category/card-category.component.ts @@ -1,5 +1,5 @@ import { Component, Input, OnInit } from '@angular/core'; -import { Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { ApiBackService } from '../services/api-back.service'; @Component({ @@ -11,19 +11,17 @@ export class CardCategoryComponent implements OnInit { @Input() categoryData : any; - constructor(private apiBackService : ApiBackService, private route : Router) { } + constructor(private apiBackService : ApiBackService, private route : Router, private activatedRoute : ActivatedRoute) { } ngOnInit(): void { } onClickCateg(id : number){ - - this.apiBackService.getRestaurantsByCateg(id); + this.apiBackService.getRestaurantsByCateg(id , this.activatedRoute.snapshot.routeConfig?.path); + // on fait passer en second parametre le path de la route c'est a dire "home"(pour l'instant) this.route.navigate(['restaurants']); - - //console.log('salut les copains'); } diff --git a/src/app/pages/filters-page/filters-page.component.html b/src/app/pages/filters-page/filters-page.component.html index a220eb3..960485c 100644 --- a/src/app/pages/filters-page/filters-page.component.html +++ b/src/app/pages/filters-page/filters-page.component.html @@ -4,119 +4,133 @@
- + -
-

- -

-
-
-
- Veuillez sélectionner la distance souhaitée -
- -
- 0 KM - 2 KM - 4 KM -
-
+
+

+ +

+
+
+
+ Veuillez sélectionner la distance souhaitée
-
- - - -
-

- -

-
-
- -
- Veuillez sélectionner le prix souhaité -
- -
- 0€ - 10€ - 20€ -
-
-
-
- - - -
-

- -

-
-
- -
- Sur Place - A Emporter -
-
- - -
+ +
+ 0 KM + 2 KM + 4 KM
+
- + -
-

- -

-
-
+
+

+ +

+
+
-
- Accès PMR -
-
- -
+
+ Veuillez sélectionner le prix souhaité +
+ +
+ 1 + 2 + 3 + 4
+
- + -
-

- -

-
-
-
- Choisissez parmi les avis déjà donnés -
- +
+

+ +

+
+
+ +
+ Sur Place + A Emporter +
+
+ +
+
+ + + +
+

+ +

+
+
+ +
+ Accès PMR +
+
+ +
+
+
+
+ + + +
+

+ +

+
+
+
+ Choisissez parmi les avis déjà donnés +
+ +
+
+
- - + \ No newline at end of file diff --git a/src/app/pages/filters-page/filters-page.component.ts b/src/app/pages/filters-page/filters-page.component.ts index d714295..2fac799 100644 --- a/src/app/pages/filters-page/filters-page.component.ts +++ b/src/app/pages/filters-page/filters-page.component.ts @@ -1,5 +1,5 @@ import { Component, EventEmitter, OnInit, Output } from '@angular/core'; -import { Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { ApiBackService } from 'src/app/services/api-back.service'; @Component({ @@ -14,7 +14,7 @@ export class FiltersPageComponent implements OnInit { public minPrice : any; public maxPrice: any; - public selectPrice : any; + public selectPrice : number; public selectDistance : any; public selectPmr :any; public selectSurPlace : any; @@ -24,18 +24,18 @@ export class FiltersPageComponent implements OnInit { @Output() rangeNumber = new EventEmitter(); public selectRating: number; - public listRestau: string[]; + public listRestau: any[]; - constructor(private apiBackService : ApiBackService, private route : Router) { + constructor(private apiBackService : ApiBackService, private route : Router, private activatedRoute : ActivatedRoute) { this.minDistance = 0; this.maxDistance = 4; this.selectDistance = null; - this.minPrice = 0; - this.maxPrice = 20; - this.selectPrice = null; + this.minPrice = 1; + this.maxPrice = 4; + this.selectPrice = 0; this.selectPmr = false; this.selectEmporter = false; @@ -51,8 +51,10 @@ export class FiltersPageComponent implements OnInit { ngOnInit(): void { this.apiBackService.getRestaurants().subscribe((restaurants: any[]) => { this.listRestau = restaurants; - console.log(this.listRestau); }); + + console.log(this.listRestau); + } @@ -85,13 +87,22 @@ onSendRating() { } -onSendFilters(){ - console.log("Distance :" ,this.selectDistance); - console.log("Prix :" ,this.selectPrice); - console.log("Sur Place :" ,this.selectSurPlace); - console.log("A emporter :" ,this.selectEmporter); - console.log("PMR :" ,this.selectPmr); - console.log("avis :" ,this.selectRating); +onSendFilters() : void{ + let restaus = this.listRestau; + + restaus = restaus.filter((restau)=> + + this.selectPrice == restau.prix + + ), + console.log( this.activatedRoute.snapshot.routeConfig?.path); + + + this.apiBackService.setListRestau(restaus, this.activatedRoute.snapshot.routeConfig?.path); + // on fait passer en second parametre le path de la route c'est a dire "filtres" + + this.route.navigate(['restaurants']); + } } diff --git a/src/app/pages/home-page/home-page.component.ts b/src/app/pages/home-page/home-page.component.ts index ebb39f4..ffc4d14 100644 --- a/src/app/pages/home-page/home-page.component.ts +++ b/src/app/pages/home-page/home-page.component.ts @@ -18,16 +18,9 @@ export class HomePageComponent implements OnInit { this.apiBackService.getCategories().subscribe((listCategories: any[]) => { console.log(listCategories); - // const listCategoriesLibelle = listCategories.map( - // (category) => category.libelle - // ); - this.listCategories = listCategories; - }); - console.log(this.apiBackService); - - + }); } diff --git a/src/app/pages/resto-page/resto-page.component.ts b/src/app/pages/resto-page/resto-page.component.ts index 848c180..38a2ac5 100644 --- a/src/app/pages/resto-page/resto-page.component.ts +++ b/src/app/pages/resto-page/resto-page.component.ts @@ -16,12 +16,22 @@ export class RestoPageComponent implements OnInit { ngOnInit(): void { + // arrivée sur la restau-page depuis filtres ou home(catégories) : appel a une méthode différente du service + if(this.apiBackService.routeParam === "filtres"){ + this.listRestaurants = this.apiBackService.restoFilter; + + }else if(this.apiBackService.routeParam === "home"){ this.apiBackService.restoByCat.subscribe((restaurants: any[]) => { - this.listRestaurants = restaurants; - - }); + }else{ // si on arrive sur l'url /restaurants directement = tous les restau affichés + + this.apiBackService.getRestaurants().subscribe((restaurants: any[]) => { + this.listRestaurants = restaurants; + + }) + } + } diff --git a/src/app/services/api-back.service.ts b/src/app/services/api-back.service.ts index 31c9dce..e38b7fb 100644 --- a/src/app/services/api-back.service.ts +++ b/src/app/services/api-back.service.ts @@ -9,22 +9,32 @@ import { environment } from 'src/environments/environment'; export class ApiBackService { public restoByCat : Observable = of([]); + public restoFilter : any[]; + public routeParam ?: string; constructor(private httpClient: HttpClient) { + this.restoFilter = []; + this.routeParam = ""; } getRestaurants(): Observable { return this.httpClient.get(`${environment.apiUrl}/restaurants`); } - getRestaurantsByCateg(id : number): void { + getRestaurantsByCateg(id : number, routeParam ?: string ): void { this.restoByCat = this.httpClient.get(`${environment.apiUrl}/restaurantbytype/${id}`); + this.routeParam = routeParam; } getCategories(): Observable{ return this.httpClient.get(`${environment.apiUrl}/types`); } + setListRestau(listRestau : any[], routeParam ?: string ) : void{ + this.restoFilter = listRestau; + this.routeParam = routeParam; + + } }