/** * @Component Name: ManualReviewComponent * @Module: Home * @Module Functionality : To display the manual review * @Creation Date: November 29,2017 * @Author: sbaireddy * @Version: 1.0 */ import {Component, Input, OnInit, Output, EventEmitter, OnDestroy } from '@angular/core'; import {Router } from '@angular/router'; import Utils from '../../shared/utils'; import * as Constants from '../../shared/constants'; import {IKeyValue } from '../../shared/modal/key.value'; import {ITabInfo, IMoreInfoList, IMoreInfo } from '../../shared/modal/common'; import {Cart } from '../../shared/modal/cart'; import {SharedService } from '../../shared/shared.service'; import {CustomerService } from '../../services/customer.service'; import {CartService } from '../../services/cart.service'; import {LookupService } from '../../services/lookup.service'; declare var jQuery: any; @Component( { moduleId: module.id, selector: 'manual-review-cmp', templateUrl: 'manual-review.component.html', styleUrls: ['manual-review.component.css'] }) export class ManualReviewComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'ManualReviewComponent'; visible: boolean = false; visibleAnimate: boolean = false; karmaTestResult: any = {}; storeId: number = Constants.STORE_ID_CD; reviewNotes: string; @Input() cart: Cart; @Input() source: string; @Output() canRefreshCart: EventEmitter = new EventEmitter(); constructor( public router: Router, public sharedService: SharedService, public customerService: CustomerService, public cartService: CartService, public lookupService: LookupService) {} /** * This function is used to initialize the directive/component after Angular * first displays the data-bound properties.It is invoked only once when the * directive is instantiated. * @returns void */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; console.log('[start]-MoreDetailsComponent.ngOnInit()'); // Start-Switch Channel-Store id update this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; console.log('updated storeid' + this.storeId); }); // End-Switch Channel-Store id update console.log('[end]-MoreDetailsComponent.ngOnInit()'); } /** * Cleanup just before Angular destroys the directive/component. * Unsubscribe Observables and detach event handlers to avoid memory leaks. * @returns void */ ngOnDestroy(): void { const METHOD_NAME: string = 'ngOnDestroy()'; } /** * This function is used to display the object. * @return {void} */ public show(): void { const METHOD_NAME: string = 'show()'; this.visible = true; console.log('source:' + this.source); setTimeout(() => this.visibleAnimate = true, 100); } /** * This function is used to hide the object. * @returns void */ public hide(): void { const METHOD_NAME: string = 'hide()'; this.visibleAnimate = false; setTimeout(() => this.visible = false, 300); } /** * This function is used to hide the object when nouse event performed * @param {MouseEvent} event - contains valid mouse event * @returns void */ public onContainerClicked(event: MouseEvent): void { const METHOD_NAME: string = 'onContainerClicked()'; if ((event.target).classList.contains('modal')) { this.hide(); } } refreshCreditClass() { const METHOD_NAME: string = 'refreshCreditClass()'; const inputData: any = {'note': this.reviewNotes }; this.sharedService.showSpinner(true); // spinner this.customerService.refreshCreditClass(this.storeId, this.cart.orderId, inputData).subscribe(result => { this.karmaTestResult = result; this.sharedService.showSpinner(false); // spinner if (result) { this.cart.customer = Object.assign(this.cart.customer, result); this.sharedService.showSpinner(true); // spinner // tslint:disable-next-line:no-shadowed-variable this.cartService.getCartSummary(this.storeId, this.cart.orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.cart = Object.assign(this.cart, result); if (this.source === 'customer-detail') { if (this.cartService.getCart()) { this.cartService.setCart(this.cart); } } else if (this.source === 'order-detail') { if (this.lookupService.getOrder()) { this.lookupService.setOrder(this.cart); } } this.canRefreshCart.emit(true); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); console.error('error=>' + error) }); } else { this.sharedService.showErrorMessage('_ERR_MANUAL_REVIEW_SERVER', false); } this.hide(); }, error => { this.sharedService.showSpinner(false); // spinner console.error('error=>' + error); this.sharedService.showErrorMessage(error, true); this.hide(); }); } }