/** * @Component Name: TitleComponent * @Module: Home * @Module Functionality : To display the top side header icons * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, OnInit, EventEmitter, Output, OnDestroy } from '@angular/core'; import { Router } from '@angular/router'; import { STORE_ID_RT } from '../../shared/constants'; import { SIDEBAR_ROUTES, TOPBAR_ROUTER } from '../../shared/form.constants'; import { Cart } from '../../shared/modal/cart'; import { Customer } from '../../shared/modal/customer'; import { User } from '../../shared/modal/user'; import { SharedService } from '../../shared/shared.service'; import { CartService } from '../../services/cart.service'; import { UserService } from '../../services/user.service'; import { CustomerService } from '../../services/customer.service'; import { LookupService } from '../../services/lookup.service'; declare var $: any; @Component({ // changeDetection: ChangeDetectionStrategy.OnPush, // please don't add these events bcz its tittle is not changing //when we navigate to each different page. moduleId: module.id, selector: 'title-cmp', templateUrl: 'title.component.html', styleUrls: ['./title.component.css'] }) export class TitleComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'TitleComponent'; storeId: number; // storeId rtStoreId: number = STORE_ID_RT; private listTitles: any[]; private menuItems: any[]; isCheckoutPage: boolean = false; showMinicart: boolean = false; totalNonFootprintOrderNotes: number; // cart element for binding Order Id. user: User; cart: Cart; customer: Customer; subscription: any; isOrderNotesVisible: boolean; // Popup elements for modal toggle @Output() onTitleAction: EventEmitter = new EventEmitter(); constructor( public router: Router, public sharedService: SharedService, public cartService: CartService, public userService: UserService, public customerService: CustomerService, 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('TitleComponent.ngOnInit()>>start.'); this.listTitles = SIDEBAR_ROUTES.filter(listTitle => listTitle); this.menuItems = TOPBAR_ROUTER.filter(menuItem => menuItem); this.listTitles = this.listTitles.concat(this.menuItems); // Start-Switch Channel-Store id update this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); this.sharedService.showMincartStatus.subscribe((val: boolean) => { this.showMinicart = val; }); this.user = this.userService.getUser(); // getting cart changes... this.cart = this.cartService.getCart(); this.subscription = this.cartService.hasUpdate.subscribe((item) => { if (item) { this.cart = this.cartService.getCart(); } }); console.log('TitleComponent.ngOnInit()>>end.'); this.lookupService.orderNotesIndicator.subscribe(orderNotesIndicatorData=> { if(orderNotesIndicatorData) { this.isOrderNotesVisible = orderNotesIndicatorData.isOrderNotesVisible; this.totalNonFootprintOrderNotes = orderNotesIndicatorData.totalNonFootprintOrderNotes; } else { this.isOrderNotesVisible = false; this.totalNonFootprintOrderNotes = 0; } }); } /** * 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.user = null; this.customer = null; this.listTitles = null; this.menuItems = null; this.subscription.unsubscribe(); } /** * This function is used to get the title * @returns any */ getTitle(): any { const METHOD_NAME: string = 'getTitle()'; let item1 = 0; let titlee = window.location.pathname; // console.log('title>>>>>>:'+ titlee); titlee = titlee.substring(1); for (; item1 < this.listTitles.length; item1++) { if (this.listTitles[item1].path.indexOf(titlee) > -1) { if (titlee.includes('checkout') || titlee.includes('estimate')) { this.isCheckoutPage = true; } if(this.storeId == this.rtStoreId && this.listTitles[item1].title === 'Shopping Cart'){ return "Review Cart"; }else{ return this.listTitles[item1].title; } } else { this.isCheckoutPage = false; } } return 'Search'; } /** * This function is used to navigate to path provided as parameter. * @param {string} path - contains route to which routing has to carry out. * @returns void */ routerToLink(path: string): void { const METHOD_NAME: string = 'routerToLink()'; this.router.navigate([path]); } /** * This function is used to Open the modal popup with its name as parameter. * @param {} modalName */ triggerModal(modalName) { const METHOD_NAME: string = 'triggerModal()'; this.onTitleAction.emit(modalName); } /** * This function is used to show/hide the minicart. * @returns void */ displayMinicart(): void { const METHOD_NAME: string = 'displayMinicart()'; this.sharedService.showMinicart(this.showMinicart = !this.showMinicart); // if(this.cart && this.cart.packages){ // this.sharedService.showMinicart(this.showMinicart = !this.showMinicart); // } else{ // this.sharedService.showMinicart(false); // } } }