modification onApplyFilters
This commit is contained in:
parent
23746f21cd
commit
6e2598537a
1 changed files with 51 additions and 44 deletions
|
@ -13,14 +13,23 @@ export class PageAccueilComponent implements OnInit {
|
||||||
public listDataFilter: any[];
|
public listDataFilter: any[];
|
||||||
public listCategoriesFilter: string[];
|
public listCategoriesFilter: string[];
|
||||||
|
|
||||||
public indexFilter: number;
|
public rangeNumber: number[];
|
||||||
|
public stateNumber: number;
|
||||||
|
|
||||||
|
public isPricingFilterActive: boolean;
|
||||||
|
public isRatingFilterActive: boolean;
|
||||||
|
|
||||||
constructor(private plantouneService: PlantouneService) {
|
constructor(private plantouneService: PlantouneService) {
|
||||||
this.listData = [];
|
this.listData = [];
|
||||||
this.listDataGlobal = [];
|
this.listDataGlobal = [];
|
||||||
this.listDataFilter = [];
|
this.listDataFilter = [];
|
||||||
this.listCategoriesFilter = [];
|
this.listCategoriesFilter = [];
|
||||||
this.indexFilter = 0;
|
|
||||||
|
this.rangeNumber = [];
|
||||||
|
this.stateNumber = 0;
|
||||||
|
|
||||||
|
this.isPricingFilterActive = false;
|
||||||
|
this.isRatingFilterActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,57 +83,55 @@ export class PageAccueilComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
onRatingFilter(stateNumber: number): void {
|
onRatingFilter(stateNumber: number): void {
|
||||||
let listRate: any[] = [];
|
this.stateNumber = stateNumber;
|
||||||
if(this.indexFilter == 0) {
|
this.isRatingFilterActive = true;
|
||||||
this.indexFilter++;
|
|
||||||
this.listDataGlobal.forEach(product => {
|
|
||||||
if(product.product_rating >= stateNumber) {
|
|
||||||
listRate.push(product);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.listData.forEach(product => {
|
|
||||||
if(product.product_rating >= stateNumber) {
|
|
||||||
listRate.push(product);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.onApplyFilters(listRate);
|
this.onApplyFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
onPriceFilter(rangeNumber: number[]) {
|
onPriceFilter(rangeNumber: number[]) {
|
||||||
console.log(rangeNumber);
|
this.rangeNumber = [...rangeNumber];
|
||||||
let listRangedProduct: any[] = [];
|
this.isPricingFilterActive = true;
|
||||||
if(this.indexFilter == 0) {
|
|
||||||
this.indexFilter++;
|
|
||||||
this.listDataGlobal.forEach(product => {
|
|
||||||
if(parseFloat(product.product_unitprice_ati) >= rangeNumber[0] && parseFloat(product.product_unitprice_ati) <= rangeNumber[1]) {
|
|
||||||
listRangedProduct.push(product);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} 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);
|
this.onApplyFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
onApplyFilters(DataFilter: any[]): void {
|
onApplyFilters(): void {
|
||||||
/*if(this.indexFilter == 0) {
|
|
||||||
this.listData = [...DataFilter];
|
|
||||||
this.indexFilter++;
|
|
||||||
} else {
|
|
||||||
this.listDataFilter = [...this.listData];
|
|
||||||
}*/
|
|
||||||
|
|
||||||
this.listData = [...DataFilter];
|
if(this.isPricingFilterActive) {
|
||||||
|
let listDataFinal: any = [];
|
||||||
|
this.listDataGlobal.forEach(product => {
|
||||||
|
if(parseFloat(product.product_unitprice_ati) >= this.rangeNumber[0] && parseFloat(product.product_unitprice_ati) <= this.rangeNumber[1]) {
|
||||||
|
listDataFinal.push(product);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.listData = [...listDataFinal];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.isRatingFilterActive) {
|
||||||
|
let listDataFinal: any = [];
|
||||||
|
this.listDataGlobal.forEach(product => {
|
||||||
|
if(product.product_rating >= this.stateNumber) {
|
||||||
|
listDataFinal.push(product);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.listData = [...listDataFinal];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.isPricingFilterActive && this.isRatingFilterActive) {
|
||||||
|
let listDataFinal: any = [];
|
||||||
|
this.listDataGlobal.forEach(product => {
|
||||||
|
if(parseFloat(product.product_unitprice_ati) >= this.rangeNumber[0]
|
||||||
|
&& parseFloat(product.product_unitprice_ati) <= this.rangeNumber[1]
|
||||||
|
&& product.product_rating >= this.stateNumber) {
|
||||||
|
listDataFinal.push(product);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.listData = [...listDataFinal];
|
||||||
|
console.log(this.listData);
|
||||||
|
}
|
||||||
|
|
||||||
//if(this.listData.length >= 9) this.listData.length = 9;
|
if(this.listData.length >= 9) this.listData.length = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue