commit
03b15210c1
@ -7,7 +7,7 @@
|
||||
<p class="mb-1 fs-5 fw-semibold">Catégories</p>
|
||||
<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}}">
|
||||
{{ category }}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-filter-side-bar',
|
||||
@ -7,17 +7,40 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||
})
|
||||
export class FilterSideBarComponent implements OnInit {
|
||||
@Input() listCategories: string[];
|
||||
@Output() checkCategory = new EventEmitter();
|
||||
@Output() stateNumber = new EventEmitter();
|
||||
@Output() rangeNumber = new EventEmitter();
|
||||
filterStateNumber: number = 0;
|
||||
|
||||
constructor() {
|
||||
public selectedCategory: string[];
|
||||
|
||||
|
||||
constructor() {
|
||||
this.listCategories = [];
|
||||
this.selectedCategory = [];
|
||||
}
|
||||
|
||||
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 {
|
||||
this.filterStateNumber = stateNumber;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<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">
|
||||
<input class="form-control"
|
||||
type="text"
|
||||
|
@ -15,6 +15,8 @@ export class PageAccueilComponent implements OnInit {
|
||||
public listDataGlobal: any[];
|
||||
public listDataFilter: any[];
|
||||
public listCategoriesFilter: string[];
|
||||
public dataFilterCategory : any;
|
||||
|
||||
|
||||
public rangeNumber: number[];
|
||||
public stateNumber: number;
|
||||
@ -59,7 +61,7 @@ export class PageAccueilComponent implements OnInit {
|
||||
this.listDataGlobal = [...listPlant];
|
||||
this.listDataFilter = [...this.listDataGlobal];
|
||||
console.log(this.listDataGlobal);
|
||||
|
||||
|
||||
/**
|
||||
* 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('')
|
||||
}
|
||||
|
||||
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 {
|
||||
this.stateNumber = stateNumber;
|
||||
this.isRatingFilterActive = true;
|
||||
|
Loading…
Reference in New Issue
Block a user