/** * @Component Name: AdditionalsComponent * @Module: Checkout * @Module Functionality : To display the full cart section * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, Input, OnChanges, OnInit, OnDestroy } from '@angular/core'; import * as Constants from '../../../shared/constants' import { IPackage } from '../../../shared/modal/common'; import { Cart } from '../../../shared/modal/cart'; import { SharedService } from '../../../shared/shared.service'; import { CheckoutService } from '../../../services/checkout.service'; @Component({ selector: 'additionals-cmp', moduleId: module.id, templateUrl: 'additionals.component.html', styleUrls: ['./additionals.component.css'] }) export class AdditionalsComponent implements OnInit, OnChanges, OnDestroy { private COMPONENT_NAME: string = 'AdditionalsComponent'; packageTypes: string[] = [ Constants.PACKAGE_TYPE_VOICE, Constants.PACKAGE_TYPE_DATA, Constants.PACKAGE_TYPE_PREPAID, Constants.PACKAGE_TYPE_ACCESSORY ]; imageBaseUrl: string = Constants.IMAGE_BASE_URL; storeId: number; @Input() cart: any; @Input() npaNxxList: any; customerInfo: any; zipCode: number; billingAddressId: number; constructor(public sharedService: SharedService, public checkoutService: CheckoutService) { } /** * 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.Here it is initializing all the states, payment methods and card types * @returns void */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); // getting the customer info updates this.customerInfo = this.checkoutService.getCustomerInfo(); } /** * This function is called whenever one or more data-bound input properties change * @returns void */ ngOnChanges(): void { const METHOD_NAME: string = 'ngOnChanges()'; this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); if (this.cart && this.cart.customer && this.cart.customer.addressId) { this.zipCode = this.cart.customer.zipCode; this.billingAddressId = this.cart.customer.addressId; } } /** * 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.cart = null; this.npaNxxList = null; this.customerInfo = null; this.packageTypes = null; } /** * This function is used to get the list of package based on the package type. * @param {string} type contains valid package type. * @returns IPackage */ getPackages(type: string): IPackage[] { const METHOD_NAME: string = 'getPackages()'; return this.cart.packages.filter((pkg) => { return (pkg.packageType === type) }); } /** * This function is used to confirm whether package needs to displayed or not. * @param {any} packagee contains valid flag to to display the package. * @returns boolean */ expandPackage(packagee: any): boolean { const METHOD_NAME: string = 'expandPackage()'; return packagee.showPackage !== packagee.showPackage; } }