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,
|
UpdateDelRestauComponent,
|
||||||
HeaderLogoComponent,
|
HeaderLogoComponent,
|
||||||
FavorisUserComponent
|
FavorisUserComponent
|
||||||
|
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<img class="card-img-top " src="assets/ImagesRestos/photo.jpg" alt="Card image cap">
|
<img class="card-img-top " src="assets/ImagesRestos/photo.jpg" alt="Card image cap">
|
||||||
<div class="rond position-absolute">
|
<div class="rond position-absolute">
|
||||||
<app-icon class="heart"
|
<app-icon class="heart"
|
||||||
[iconName]="isLiked ? 'heart-fill' : 'heart'"
|
[iconName]="restaurant.restauLike ? 'heart-fill' : 'heart'"
|
||||||
[iconColor]="'#e35d6a'"
|
[iconColor]="'#e35d6a'"
|
||||||
(click)="onClickLike()"></app-icon></div>
|
(click)="onClickLike()"></app-icon></div>
|
||||||
<div class="card-body rounded-bottom">
|
<div class="card-body rounded-bottom">
|
||||||
|
|
|
@ -29,11 +29,13 @@ export class CardRestoComponent implements OnInit {
|
||||||
this.restaurant.latitude,
|
this.restaurant.latitude,
|
||||||
this.restaurant.longitude)
|
this.restaurant.longitude)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
onClickLike() {
|
onClickLike() {
|
||||||
console.log('click');
|
console.log('click');
|
||||||
this.isLiked = !this.isLiked;
|
//this.isLiked = !this.isLiked;
|
||||||
this.clickLike.emit(this.isLiked);
|
this.clickLike.emit(this.isLiked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,3 @@
|
||||||
<app-card-resto [restaurant]= "pref"></app-card-resto>
|
<app-card-resto [restaurant]= "pref"></app-card-resto>
|
||||||
</div>
|
</div>
|
||||||
</app-template-page>
|
</app-template-page>
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { forkJoin } from 'rxjs';
|
||||||
import { ApiBackService } from 'src/app/services/api-back.service';
|
import { ApiBackService } from 'src/app/services/api-back.service';
|
||||||
import { TokenService } from 'src/app/services/token.service';
|
import { TokenService } from 'src/app/services/token.service';
|
||||||
|
|
||||||
|
@ -11,8 +12,10 @@ export class FavorisUserComponent implements OnInit {
|
||||||
|
|
||||||
|
|
||||||
personneConnectee : any;
|
personneConnectee : any;
|
||||||
listPref: any;
|
|
||||||
restaurantData : any[];
|
restaurantData : any[];
|
||||||
|
public listRestaurants : any;
|
||||||
|
public listPref : any;
|
||||||
|
public restaurantPref : any;
|
||||||
|
|
||||||
constructor(private apiBackService : ApiBackService, private tokenService : TokenService) {
|
constructor(private apiBackService : ApiBackService, private tokenService : TokenService) {
|
||||||
|
|
||||||
|
@ -21,18 +24,27 @@ this.restaurantData = []
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
||||||
|
|
||||||
this.apiBackService.getPersonneById(this.tokenService.getCurrentUserId()).subscribe(
|
this.apiBackService.getPersonneById(this.tokenService.getCurrentUserId()).subscribe(
|
||||||
user =>{
|
user =>{
|
||||||
|
|
||||||
this.listPref = user.preference;
|
this.listPref = user.preference;
|
||||||
|
|
||||||
console.log(this.listPref);
|
console.log(this.listPref);
|
||||||
|
|
||||||
for (let i = 0; i < this.listPref.length; i++) {
|
for (let i = 0; i < this.listPref.length; i++) {
|
||||||
this.restaurantData.push(this.listPref[i]['preferencePK']['restau']);
|
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;
|
lastName: string;
|
||||||
email: string;
|
email: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
|
preference ?: object;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<app-template-page [title]="'Restaurants :'">
|
<app-template-page [title]="'Restaurants :'">
|
||||||
<div *ngFor="let restaurantData of listRestaurants">
|
<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>
|
</div>
|
||||||
</app-template-page>
|
</app-template-page>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { forkJoin } from 'rxjs';
|
||||||
import { ApiBackService } from 'src/app/services/api-back.service';
|
import { ApiBackService } from 'src/app/services/api-back.service';
|
||||||
|
import { TokenService } from 'src/app/services/token.service';
|
||||||
|
import { Restaurant } from '../models/restaurant';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-resto-page',
|
selector: 'app-resto-page',
|
||||||
|
@ -8,35 +11,85 @@ import { ApiBackService } from 'src/app/services/api-back.service';
|
||||||
})
|
})
|
||||||
export class RestoPageComponent implements OnInit {
|
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.listRestaurants = [];
|
||||||
|
this.restaurantPref = [];
|
||||||
|
this.beforeRoute = this.apiBackService.routeParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
|
||||||
|
this.restauLiked();
|
||||||
|
|
||||||
// arrivée sur la restau-page depuis filtres ou home(catégories) : appel a une méthode différente du service
|
// // 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"){
|
// if(this.apiBackService.routeParam === "filtres"){
|
||||||
this.listRestaurants = this.apiBackService.restoFilter;
|
// this.listRestaurants = this.apiBackService.restoFilter;
|
||||||
|
|
||||||
}else if(this.apiBackService.routeParam === "categories"){
|
// }else if(this.apiBackService.routeParam === "categories"){
|
||||||
this.apiBackService.restoByCat.subscribe((restaurants: any[]) => {
|
// this.apiBackService.restoByCat.subscribe((restaurants: any[]) => {
|
||||||
this.listRestaurants = restaurants;
|
// this.listRestaurants = restaurants;
|
||||||
});
|
// });
|
||||||
}else{ // si on arrive sur l'url /restaurants directement = tous les restau affichés
|
// }else{ // si on arrive sur l'url /restaurants directement = tous les restau affichés
|
||||||
|
|
||||||
this.apiBackService.getRestaurants().subscribe((restaurants: any[]) => {
|
|
||||||
this.listRestaurants = restaurants;
|
|
||||||
|
|
||||||
})
|
// 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 { HttpClient } from '@angular/common/http';
|
||||||
import { environment } from 'src/environments/environment';
|
import { environment } from 'src/environments/environment';
|
||||||
import { Restaurant } from '../pages/models/restaurant';
|
import { Restaurant } from '../pages/models/restaurant';
|
||||||
|
import { User } from '../pages/models/user';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@ -66,6 +67,6 @@ export class ApiBackService {
|
||||||
}
|
}
|
||||||
|
|
||||||
getPersonneById(id: any) {
|
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