offers and discount
parent
ea93212ad1
commit
6f4f998700
@ -1,19 +1,80 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { AfterViewInit, Component, OnInit } from '@angular/core';
|
||||||
|
import { connectableObservableDescriptor } from 'rxjs/internal/observable/ConnectableObservable';
|
||||||
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
|
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
|
||||||
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
|
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
|
||||||
|
import { OfferDiscountService } from '../services/service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-home',
|
selector: 'app-home',
|
||||||
templateUrl: './home.component.html',
|
templateUrl: './home.component.html',
|
||||||
styleUrls: ['./home.component.scss'],
|
styleUrls: ['./home.component.scss'],
|
||||||
})
|
})
|
||||||
export class HomeComponent implements OnInit {
|
export class HomeComponent implements AfterViewInit {
|
||||||
segment: any = '1';
|
segment: any = '1';
|
||||||
constructor(public ts: TranslatorService, public cs: CommonService,) { }
|
categoriesObj: any;
|
||||||
ngOnInit() { }
|
categories: any = [];
|
||||||
|
offersData: any = [];
|
||||||
|
activeClass: any;
|
||||||
|
tempSearch: any = [];
|
||||||
|
searchText: String;
|
||||||
|
constructor(public ts: TranslatorService, public cs: CommonService, public offersService: OfferDiscountService) { }
|
||||||
|
|
||||||
|
ngAfterViewInit(): void {
|
||||||
|
|
||||||
|
this.getOfferDiscount();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
openDetails(offer) {
|
||||||
|
this.cs.sharedService.setSharedData(offer, OfferDiscountService.selected_offers);
|
||||||
|
|
||||||
|
var related = this.offersData.filter((res) => res.rowID != offer.rowID);
|
||||||
|
this.cs.sharedService.setSharedData(related, OfferDiscountService.related_offers);
|
||||||
|
|
||||||
openDetails() {
|
|
||||||
this.cs.navigateForward('/offersdiscount/offer-details');
|
this.cs.navigateForward('/offersdiscount/offer-details');
|
||||||
}
|
}
|
||||||
|
getOfferDiscount() {
|
||||||
|
this.cs.startLoading();
|
||||||
|
this.offersService.getOffers({}, () => { }, this.ts.trPK('general', 'retry')).subscribe((res) => {
|
||||||
|
var data = JSON.parse(res['Mohemm_ITG_ResponseItem']);
|
||||||
|
this.cs.stopLoading();
|
||||||
|
if (data['result'])
|
||||||
|
this.displayOffers(data['result']);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
displayOffers(data) {
|
||||||
|
if (data['data']) {
|
||||||
|
var parseJSON = data['data'];
|
||||||
|
var offers = JSON.parse(parseJSON)
|
||||||
|
this.categoriesObj = this.groupBy(offers, 'categoryName');
|
||||||
|
this.categories = Object.keys(this.categoriesObj);
|
||||||
|
this.filterOffers(this.categories[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
groupBy(xs, key) {
|
||||||
|
return xs.reduce((rv, x) => {
|
||||||
|
(rv[x[key]] = rv[x[key]] || []).push(x);
|
||||||
|
return rv;
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
|
filterOffers(key) {
|
||||||
|
this.activeClass = key;
|
||||||
|
this.offersData = this.categoriesObj[key];
|
||||||
|
this.tempSearch = JSON.parse(JSON.stringify(this.offersData));
|
||||||
|
}
|
||||||
|
checkDate(date) {
|
||||||
|
return new Date(date) >= new Date()
|
||||||
|
}
|
||||||
|
getDotted(temp) {
|
||||||
|
return temp.substring(0, 60) + " ...";
|
||||||
|
}
|
||||||
|
search(t) {
|
||||||
|
|
||||||
|
this.offersData = this.tempSearch.filter((post, index) => {
|
||||||
|
if (post.Title.toLowerCase().indexOf(t.toLowerCase()) > -1)
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,30 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { ConnectorService } from 'src/app/hmg-common/services/connector/connector.service';
|
||||||
|
import { AuthenticationService } from "src/app/hmg-common/services/authentication/authentication.service";
|
||||||
|
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class OfferDiscountService {
|
||||||
|
|
||||||
|
public static offersDiscountData = 'Services/COCWS.svc/REST/GetOfferDiscountsConfigData';
|
||||||
|
public static getSuborinateStatus = 'Services/ERP.svc/REST/GET_SUBORDINATES_ATTD_STATUS';
|
||||||
|
public static selected_offers = 'selected-offers';
|
||||||
|
public static related_offers = 'related-offers';
|
||||||
|
constructor(
|
||||||
|
public con: ConnectorService,
|
||||||
|
private authService: AuthenticationService,
|
||||||
|
public cs: CommonService
|
||||||
|
) {
|
||||||
|
this.cs.sharedService.getSharedData(OfferDiscountService.selected_offers, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
getOffers(offer_request, onError, errorLabel) {
|
||||||
|
var request = this.authService.getAuthenticatedRequest();
|
||||||
|
request['EmployeeNumber'] = request.UserName;
|
||||||
|
|
||||||
|
return this.con.postNoLoad(OfferDiscountService.offersDiscountData, request, onError, errorLabel);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue