/** * @Component Name: CoverageComponent * @Module: Home * @Module Functionality : To display the customer t-mobile coverage * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, OnInit, OnDestroy } from '@angular/core'; import * as Constants from '../../shared/constants'; import { Cart } from '../../shared/modal/cart'; import { Customer } from '../../shared/modal/customer'; import { SharedService } from '../../shared/shared.service'; import { CartService } from '../../services/cart.service'; import { CustomerService } from '../../services/customer.service'; declare var $: any; @Component({ moduleId: module.id, selector: 'coverage-cmp', templateUrl: 'coverage.component.html' }) export class CoverageComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'CoverageComponent'; mapsUrl: string = Constants.MAPS_BASE_URL; storeLocationUrl: string = Constants.STORE_LOCATOR_URL; mapsComparisonUrl: string = Constants.MAPS_COMPARISON_URL; cart: Cart; customer: Customer; showStores: boolean = false; constructor( public sharedService: SharedService, public cartService: CartService, public customerService: CustomerService) { } /** * 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.It is invoked only once when the * directive is instantiated.Here it is initializing the cart & customer informations * @return void */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; // this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Loading coverage map'); console.log('CoverageComponent.ngOnInit()'); // getting current cart/customer this.sharedService.showCoverage(true); this.cart = this.cartService.getCart(); this.customer = this.customerService.getCustomer(); if (this.customer) { this.mapsUrl += '&search=' + this.searchText(this.customer); this.mapsComparisonUrl += '&search=' + this.searchText(this.customer); } else if (this.cart && this.cart.customer) { this.mapsUrl += '&search=' + this.searchText(this.cart.customer); this.mapsComparisonUrl += '&search=' + this.searchText(this.cart.customer); this.cartService.setCart(this.cart); } else if (this.customerService.getCustomerModel()) { const customerModel: any = this.customerService.getCustomerModel(); this.mapsUrl += '&search=' + this.searchText(customerModel); this.mapsComparisonUrl += '&search=' + this.searchText(customerModel); } } /** * Cleanup just before Angular destroys the directive/component. * Unsubscribe Observables and detach event handlers to avoid memory leaks. * @return void */ ngOnDestroy(): void { const METHOD_NAME: string = 'ngOnDestroy()'; } /** * This function is used to display messages * @param {any} customer - customer * @returns string */ searchText(customer: any): string { let address: string = ''; if (customer) { if (customer.address1) { address += customer.address1 + ' '; } if (customer.address2) { address += customer.address2 + ' '; } if (customer.city) { address += customer.city + ' '; } if (customer.state) { address += customer.state + ' '; } if (customer.zipCode) { address += customer.zipCode; } } return address; } /** * This function is used to display messages * @returns void */ selectMarker(): void { const METHOD_NAME: string = 'selectMarker()'; if (this.showStores) { const message: any = {'event': 'selectMarker', 'data': {'index': 0, 'selected': false, 'centerInView': false, 'html': null}}; const json = JSON.stringify(message); console.log('json: ' + json); $('#pccIFrame').contentWindow.postMessage(json, '*'); } } }