onapplyfilter method

This commit is contained in:
Julian30520 2022-01-11 19:33:15 +01:00
parent 08d05a41d4
commit 23746f21cd

View File

@ -10,12 +10,17 @@ import * as _ from 'underscore';
export class PageAccueilComponent implements OnInit { export class PageAccueilComponent implements OnInit {
public listData: any[]; public listData: any[];
public listDataGlobal: any[]; public listDataGlobal: any[];
public listDataFilter: any[];
public listCategoriesFilter: string[]; public listCategoriesFilter: string[];
public indexFilter: number;
constructor(private plantouneService: PlantouneService) { constructor(private plantouneService: PlantouneService) {
this.listData = []; this.listData = [];
this.listDataGlobal = []; this.listDataGlobal = [];
this.listDataFilter = [];
this.listCategoriesFilter = []; this.listCategoriesFilter = [];
this.indexFilter = 0;
} }
/** /**
@ -36,6 +41,7 @@ export class PageAccueilComponent implements OnInit {
(listPlant: any[]) => { (listPlant: any[]) => {
console.log(listPlant); console.log(listPlant);
this.listDataGlobal = [...listPlant]; this.listDataGlobal = [...listPlant];
this.listDataFilter = [...this.listDataGlobal];
console.log(this.listDataGlobal); console.log(this.listDataGlobal);
/** /**
@ -69,25 +75,56 @@ export class PageAccueilComponent implements OnInit {
onRatingFilter(stateNumber: number): void { onRatingFilter(stateNumber: number): void {
let listRate: any[] = []; let listRate: any[] = [];
this.listDataGlobal.forEach(product => { if(this.indexFilter == 0) {
if(product.product_rating >= stateNumber) { this.indexFilter++;
listRate.push(product); this.listDataGlobal.forEach(product => {
} if(product.product_rating >= stateNumber) {
}); listRate.push(product);
this.listData = [...listRate]; }
if(this.listData.length >= 9) this.listData.length = 9; });
} else {
this.listData.forEach(product => {
if(product.product_rating >= stateNumber) {
listRate.push(product);
}
});
}
this.onApplyFilters(listRate);
} }
onPriceFilter(rangeNumber: number[]) { onPriceFilter(rangeNumber: number[]) {
console.log(rangeNumber); console.log(rangeNumber);
let listRangedProduct: any[] = []; let listRangedProduct: any[] = [];
this.listDataGlobal.forEach(product => { if(this.indexFilter == 0) {
if(parseFloat(product.product_unitprice_ati) >= rangeNumber[0] && parseFloat(product.product_unitprice_ati) <= rangeNumber[1]) { this.indexFilter++;
listRangedProduct.push(product); this.listDataGlobal.forEach(product => {
} if(parseFloat(product.product_unitprice_ati) >= rangeNumber[0] && parseFloat(product.product_unitprice_ati) <= rangeNumber[1]) {
}); listRangedProduct.push(product);
this.listData = [...listRangedProduct]; }
if(this.listData.length >= 9) this.listData.length = 9; });
} else {
this.listData.forEach(product => {
if(parseFloat(product.product_unitprice_ati) >= rangeNumber[0] && parseFloat(product.product_unitprice_ati) <= rangeNumber[1]) {
listRangedProduct.push(product);
}
});
}
this.onApplyFilters(listRangedProduct);
}
onApplyFilters(DataFilter: any[]): void {
/*if(this.indexFilter == 0) {
this.listData = [...DataFilter];
this.indexFilter++;
} else {
this.listDataFilter = [...this.listData];
}*/
this.listData = [...DataFilter];
//if(this.listData.length >= 9) this.listData.length = 9;
} }
} }