|
|
|
@ -18,11 +18,15 @@ export class FilterComponent implements AfterViewInit {
|
|
|
|
tempSearch: any = [];
|
|
|
|
tempSearch: any = [];
|
|
|
|
searchText: String;
|
|
|
|
searchText: String;
|
|
|
|
public activeKey = {}
|
|
|
|
public activeKey = {}
|
|
|
|
|
|
|
|
direction: any;
|
|
|
|
constructor(public ts: TranslatorService, public modalController: ModalController, public cs: CommonService, public offersService: OfferDiscountService) { }
|
|
|
|
constructor(public ts: TranslatorService, public modalController: ModalController, public cs: CommonService, public offersService: OfferDiscountService) { }
|
|
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
|
|
|
|
this.direction = TranslatorService.getCurrentDirection();
|
|
|
|
|
|
|
|
this.categories = this.cs.sharedService.getSharedData(OfferDiscountService.categories, false);
|
|
|
|
|
|
|
|
|
|
|
|
this.getOfferDiscount();
|
|
|
|
|
|
|
|
|
|
|
|
// this.getOfferDiscount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -34,52 +38,52 @@ export class FilterComponent implements AfterViewInit {
|
|
|
|
|
|
|
|
|
|
|
|
this.cs.navigateForward('/offersdiscount/offer-details');
|
|
|
|
this.cs.navigateForward('/offersdiscount/offer-details');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getOfferDiscount() {
|
|
|
|
// getOfferDiscount() {
|
|
|
|
this.cs.startLoading();
|
|
|
|
// this.cs.startLoading();
|
|
|
|
this.offersService.getOffers({}, () => { }, this.ts.trPK('general', 'retry')).subscribe((res) => {
|
|
|
|
// this.offersService.getOffers({}, () => { }, this.ts.trPK('general', 'retry')).subscribe((res) => {
|
|
|
|
var data = JSON.parse(res['Mohemm_ITG_ResponseItem']);
|
|
|
|
// var data = JSON.parse(res['Mohemm_ITG_ResponseItem']);
|
|
|
|
this.cs.stopLoading();
|
|
|
|
// this.cs.stopLoading();
|
|
|
|
if (data['result'])
|
|
|
|
// if (data['result'])
|
|
|
|
this.displayOffers(data['result']);
|
|
|
|
// this.displayOffers(data['result']);
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
displayOffers(data) {
|
|
|
|
// displayOffers(data) {
|
|
|
|
if (data['data']) {
|
|
|
|
// if (data['data']) {
|
|
|
|
var parseJSON = data['data'];
|
|
|
|
// var parseJSON = data['data'];
|
|
|
|
var offers = JSON.parse(parseJSON)
|
|
|
|
// var offers = JSON.parse(parseJSON)
|
|
|
|
this.categoriesObj = this.groupBy(offers, TranslatorService.getCurrentDirection() == 'ltr' ? 'categoryName_en' : 'categoryName_ar');
|
|
|
|
// this.categoriesObj = this.groupBy(offers, TranslatorService.getCurrentDirection() == 'ltr' ? 'categoryName_en' : 'categoryName_ar');
|
|
|
|
// = Object.keys(this.categoriesObj);
|
|
|
|
// // = Object.keys(this.categoriesObj);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var x in this.categoriesObj) {
|
|
|
|
// for (var x in this.categoriesObj) {
|
|
|
|
for (var y in offers) {
|
|
|
|
// for (var y in offers) {
|
|
|
|
if (x == offers[y].categoryName_en && this.categories.filter(item => item.name.includes(x)) == false) {
|
|
|
|
// if (x == offers[y].categoryName_en && this.categories.filter(item => item.name.includes(x)) == false) {
|
|
|
|
this.categories.push({
|
|
|
|
// this.categories.push({
|
|
|
|
name: x,
|
|
|
|
// name: x,
|
|
|
|
icon: offers[y].icon
|
|
|
|
// icon: offers[y].icon
|
|
|
|
})
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
this.filterOffers(this.categories[0]);
|
|
|
|
// this.filterOffers(this.categories[0]);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
groupBy(xs, key) {
|
|
|
|
// groupBy(xs, key) {
|
|
|
|
return xs.reduce((rv, x) => {
|
|
|
|
// return xs.reduce((rv, x) => {
|
|
|
|
|
|
|
|
|
|
|
|
(rv[x[key.trim()]] = rv[x[key]] || []).push(x);
|
|
|
|
// (rv[x[key.trim()]] = rv[x[key]] || []).push(x);
|
|
|
|
return rv
|
|
|
|
// return rv
|
|
|
|
}, {});
|
|
|
|
// }, {});
|
|
|
|
};
|
|
|
|
// };
|
|
|
|
filterOffers(key) {
|
|
|
|
filterOffers(key) {
|
|
|
|
this.activeKey = key;
|
|
|
|
this.activeKey = key
|
|
|
|
this.activeClass = key.name;
|
|
|
|
this.activeClass = key.categoryName_en;
|
|
|
|
this.offersData = this.categoriesObj[key.name];
|
|
|
|
// this.offersData = this.categoriesObj[key.name];
|
|
|
|
this.tempSearch = JSON.parse(JSON.stringify(this.offersData));
|
|
|
|
// this.tempSearch = JSON.parse(JSON.stringify(this.offersData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkDate(date) {
|
|
|
|
checkDate(date) {
|
|
|
|
return new Date(date) >= new Date()
|
|
|
|
return new Date(date) >= new Date()
|
|
|
|
|