Merge pull request #3 from Julian30520/Isa

Isa Recherche par categorie
This commit is contained in:
Julian 2022-01-11 20:45:40 +01:00 committed by GitHub
commit 03b15210c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 6 deletions

View File

@ -7,7 +7,7 @@
<p class="mb-1 fs-5 fw-semibold">Catégories</p> <p class="mb-1 fs-5 fw-semibold">Catégories</p>
<div *ngFor="let category of listCategories; let indexCat = index" class="form-check"> <div *ngFor="let category of listCategories; let indexCat = index" class="form-check">
<input class="form-check-input" type="checkbox" value="testcategory" id="checkBoxCategory{{indexCat}}"> <input class="form-check-input" type="checkbox" value="testcategory" id="checkBoxCategory{{indexCat}}" (click)="onCheckCategory(category,$event)">
<label class="form-check-label" for="checkBoxCategory{{indexCat}}"> <label class="form-check-label" for="checkBoxCategory{{indexCat}}">
{{ category }} {{ category }}

View File

@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
@Component({ @Component({
selector: 'app-filter-side-bar', selector: 'app-filter-side-bar',
@ -7,17 +7,40 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
}) })
export class FilterSideBarComponent implements OnInit { export class FilterSideBarComponent implements OnInit {
@Input() listCategories: string[]; @Input() listCategories: string[];
@Output() checkCategory = new EventEmitter();
@Output() stateNumber = new EventEmitter(); @Output() stateNumber = new EventEmitter();
@Output() rangeNumber = new EventEmitter(); @Output() rangeNumber = new EventEmitter();
filterStateNumber: number = 0; filterStateNumber: number = 0;
public selectedCategory: string[];
constructor() {
constructor() {
this.listCategories = []; this.listCategories = [];
this.selectedCategory = [];
} }
ngOnInit(): void { ngOnInit(): void {
} }
onCheckCategory(category: string, event: any) {
console.log(event)
if (event.target.checked == true) {
//console.log("true")
this.selectedCategory.push(category);
}
if (event.target.checked == false) {
//console.log("false")
this.selectedCategory = this.selectedCategory.filter(product => product !== category);
}
this.checkCategory.emit(this.selectedCategory);
//console.log("romain" , this.selectedCategory)
}
onStateNumberChange(stateNumber: number): void { onStateNumberChange(stateNumber: number): void {
this.filterStateNumber = stateNumber; this.filterStateNumber = stateNumber;
} }

View File

@ -1,5 +1,5 @@
<div class="d-flex align-items-stretch"> <div class="d-flex align-items-stretch">
<app-filter-side-bar [listCategories]="listCategoriesFilter" (stateNumber)="onRatingFilter($event)" (rangeNumber)="onPriceFilter($event)"></app-filter-side-bar> <app-filter-side-bar [listCategories]="listCategoriesFilter" (stateNumber)="onRatingFilter($event)" (rangeNumber)="onPriceFilter($event)" (checkCategory)="onListCategory($event)"></app-filter-side-bar>
<div class="custom-main container p-3"> <div class="custom-main container p-3">
<input class="form-control" <input class="form-control"
type="text" type="text"

View File

@ -15,6 +15,8 @@ export class PageAccueilComponent implements OnInit {
public listDataGlobal: any[]; public listDataGlobal: any[];
public listDataFilter: any[]; public listDataFilter: any[];
public listCategoriesFilter: string[]; public listCategoriesFilter: string[];
public dataFilterCategory : any;
public rangeNumber: number[]; public rangeNumber: number[];
public stateNumber: number; public stateNumber: number;
@ -59,7 +61,7 @@ export class PageAccueilComponent implements OnInit {
this.listDataGlobal = [...listPlant]; this.listDataGlobal = [...listPlant];
this.listDataFilter = [...this.listDataGlobal]; this.listDataFilter = [...this.listDataGlobal];
console.log(this.listDataGlobal); console.log(this.listDataGlobal);
/** /**
* Technique avec Underscore JS pour recupérer les catégories uniques de nos plantes * Technique avec Underscore JS pour recupérer les catégories uniques de nos plantes
*/ */
@ -91,6 +93,31 @@ export class PageAccueilComponent implements OnInit {
this.plantouneService.plantLiked$.next('') this.plantouneService.plantLiked$.next('')
} }
onListCategory(categoryArray: string[]) {
// this.listData=listData;
//console.log(typeof(valueText));
if(categoryArray.length == 0) {
this.listData = [...this.listDataGlobal];
} else if(categoryArray.length > 0) {
let listProductsByCategory:string[] = [];
this.listDataGlobal.forEach(product => {
categoryArray.forEach(categorySelected => {
if (product.product_breadcrumb_label == categorySelected){
listProductsByCategory.push(product);
}
});
});
this.listData= [...listProductsByCategory];
}
if(this.listData.length>=9){
this.listData.length=9;
}
}
onRatingFilter(stateNumber: number): void { onRatingFilter(stateNumber: number): void {
this.stateNumber = stateNumber; this.stateNumber = stateNumber;
this.isRatingFilterActive = true; this.isRatingFilterActive = true;