Merge branch 'dev' into Romain
This commit is contained in:
commit
7aa95ef99a
|
@ -47,7 +47,6 @@ import { FavorisUserComponent } from './pages/favoris-user/favoris-user.componen
|
|||
UpdateDelRestauComponent,
|
||||
HeaderLogoComponent,
|
||||
FavorisUserComponent
|
||||
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<img class="card-img-top " src="assets/ImagesRestos/photo.jpg" alt="Card image cap">
|
||||
<div class="rond position-absolute">
|
||||
<app-icon class="heart"
|
||||
[iconName]="isLiked ? 'heart-fill' : 'heart'"
|
||||
[iconName]="restaurant.restauLike ? 'heart-fill' : 'heart'"
|
||||
[iconColor]="'#e35d6a'"
|
||||
(click)="onClickLike()"></app-icon></div>
|
||||
<div class="card-body rounded-bottom">
|
||||
|
|
|
@ -30,10 +30,12 @@ export class CardRestoComponent implements OnInit {
|
|||
this.restaurant.longitude)
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
onClickLike() {
|
||||
console.log('click');
|
||||
this.isLiked = !this.isLiked;
|
||||
//this.isLiked = !this.isLiked;
|
||||
this.clickLike.emit(this.isLiked);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,4 +3,3 @@
|
|||
<app-card-resto [restaurant]= "pref"></app-card-resto>
|
||||
</div>
|
||||
</app-template-page>
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { forkJoin } from 'rxjs';
|
||||
import { ApiBackService } from 'src/app/services/api-back.service';
|
||||
import { TokenService } from 'src/app/services/token.service';
|
||||
|
||||
|
@ -11,8 +12,10 @@ export class FavorisUserComponent implements OnInit {
|
|||
|
||||
|
||||
personneConnectee : any;
|
||||
listPref: any;
|
||||
restaurantData : any[];
|
||||
public listRestaurants : any;
|
||||
public listPref : any;
|
||||
public restaurantPref : any;
|
||||
|
||||
constructor(private apiBackService : ApiBackService, private tokenService : TokenService) {
|
||||
|
||||
|
@ -21,18 +24,27 @@ this.restaurantData = []
|
|||
|
||||
ngOnInit(): void {
|
||||
|
||||
|
||||
this.apiBackService.getPersonneById(this.tokenService.getCurrentUserId()).subscribe(
|
||||
user =>{
|
||||
|
||||
this.listPref = user.preference;
|
||||
|
||||
console.log(this.listPref);
|
||||
|
||||
for (let i = 0; i < this.listPref.length; i++) {
|
||||
this.restaurantData.push(this.listPref[i]['preferencePK']['restau']);
|
||||
|
||||
}
|
||||
|
||||
this.restaurantData.forEach((restau: any) => {
|
||||
//console.log(restau);
|
||||
restau.restauLike = true;
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,4 +4,5 @@ export interface User {
|
|||
lastName: string;
|
||||
email: string;
|
||||
password?: string;
|
||||
preference ?: object;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<app-template-page [title]="'Restaurants :'">
|
||||
<div *ngFor="let restaurantData of listRestaurants">
|
||||
<app-card-resto [restaurant]= "restaurantData"></app-card-resto>
|
||||
<app-card-resto [restaurant]= "restaurantData" (clickLike)="onEventLike()"></app-card-resto>
|
||||
</div>
|
||||
</app-template-page>
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { forkJoin } from 'rxjs';
|
||||
import { ApiBackService } from 'src/app/services/api-back.service';
|
||||
import { TokenService } from 'src/app/services/token.service';
|
||||
import { Restaurant } from '../models/restaurant';
|
||||
|
||||
@Component({
|
||||
selector: 'app-resto-page',
|
||||
|
@ -8,34 +11,84 @@ import { ApiBackService } from 'src/app/services/api-back.service';
|
|||
})
|
||||
export class RestoPageComponent implements OnInit {
|
||||
|
||||
public listRestaurants : any[];
|
||||
public listRestaurants : any;
|
||||
public listPref : any;
|
||||
public restaurantPref : any;
|
||||
public beforeRoute ?: string ;
|
||||
|
||||
constructor(private apiBackService : ApiBackService) {
|
||||
constructor(private apiBackService : ApiBackService,
|
||||
private tokenService : TokenService) {
|
||||
this.listRestaurants = [];
|
||||
this.restaurantPref = [];
|
||||
this.beforeRoute = this.apiBackService.routeParam;
|
||||
}
|
||||
|
||||
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;
|
||||
this.restauLiked();
|
||||
|
||||
}else if(this.apiBackService.routeParam === "categories"){
|
||||
this.apiBackService.restoByCat.subscribe((restaurants: any[]) => {
|
||||
this.listRestaurants = restaurants;
|
||||
});
|
||||
}else{ // si on arrive sur l'url /restaurants directement = tous les restau affichés
|
||||
// // 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;
|
||||
|
||||
this.apiBackService.getRestaurants().subscribe((restaurants: any[]) => {
|
||||
this.listRestaurants = restaurants;
|
||||
// }else if(this.apiBackService.routeParam === "categories"){
|
||||
// this.apiBackService.restoByCat.subscribe((restaurants: any[]) => {
|
||||
// this.listRestaurants = restaurants;
|
||||
// });
|
||||
// }else{ // si on arrive sur l'url /restaurants directement = tous les restau affichés
|
||||
|
||||
|
||||
// this.restauLiked();
|
||||
|
||||
// }
|
||||
|
||||
})
|
||||
}
|
||||
console.log(this.apiBackService);
|
||||
|
||||
onEventLike(){
|
||||
this.apiBackService.restoLiked$.next('');
|
||||
console.log(this.apiBackService.restoLiked$);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
restauLiked(){
|
||||
|
||||
forkJoin({
|
||||
restaurants: this.apiBackService.getRestaurants(),
|
||||
user: this.apiBackService.getPersonneById(this.tokenService.getCurrentUserId()),
|
||||
restauByCat : this.apiBackService.restoByCat
|
||||
}).subscribe(({restaurants, user, restauByCat}) => {
|
||||
|
||||
|
||||
if(this.beforeRoute === "filtres"){
|
||||
this.listRestaurants = this.apiBackService.restoFilter;
|
||||
}else if(this.beforeRoute === "categories" ){
|
||||
this.listRestaurants = restauByCat
|
||||
}else{
|
||||
this.listRestaurants = restaurants;
|
||||
}
|
||||
|
||||
this.listPref = user.preference;
|
||||
|
||||
for (let i = 0; i < this.listPref.length; i++) {
|
||||
this.restaurantPref.push(this.listPref[i]['preferencePK']['restau']);
|
||||
}
|
||||
|
||||
const listRestauIdLike = this.restaurantPref.map((x: any) => x.id);
|
||||
|
||||
this.listRestaurants.forEach((restau: any) => {
|
||||
|
||||
|
||||
if(listRestauIdLike.includes(restau.id))
|
||||
|
||||
//console.log(restau);
|
||||
restau.restauLike = true;
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Observable, of, Subject } from 'rxjs';
|
|||
import { HttpClient } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { Restaurant } from '../pages/models/restaurant';
|
||||
import { User } from '../pages/models/user';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@ -66,6 +67,6 @@ export class ApiBackService {
|
|||
}
|
||||
|
||||
getPersonneById(id: any) {
|
||||
return this.httpClient.get<any>(`${environment.apiUrl}/user/${id}`);
|
||||
return this.httpClient.get<User>(`${environment.apiUrl}/user/${id}`);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue