/** * @Component Name: SurveyComponent * @Module: Home * @Module Functionality : Survey from user * @Creation Date: Oct 29,2018 * @Author: akumar150 * @Version: 1.0 */ import { Component, ViewChild, Input, OnInit, OnChanges, OnDestroy } from '@angular/core'; import { NgForm } from '@angular/forms'; import { Router } from '@angular/router'; import Utils from '../utils'; import * as Constants from '../constants'; import * as FormConstants from '../form.constants'; import { User } from '..//modal/user'; import { SharedService } from '..//shared.service'; import { UserService } from '../../services/user.service'; import { MarketingService } from '../../services/marketing.service'; import { RatingComponent } from '../rating/rating.component'; import { CartService } from '../../services/cart.service'; import CartUtils from '../../shared/cart.utils'; import {Cart} from '../modal/cart'; @Component( { moduleId: module.id, selector: 'survey-cmp', templateUrl: 'survey.component.html', styleUrls: ['survey.component.css'], }) export class SurveyComponent implements OnInit, OnDestroy, OnChanges { private COMPONENT_NAME: string = 'SurveyComponent'; visible: boolean = false; visibleAnimate: boolean = false; storeId: number; user: User; surveyForm: NgForm; errorMessage: string; surveyModal: any = { comments: ''}; ratingClicked: number; disableSubmit: boolean = true; cart: Cart; @ViewChild('ratingCmp') ratingCmp: any; constructor( public router: Router, public sharedService: SharedService, public userService: UserService, public cartService: CartService, public marketingService: MarketingService) { } /** * 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. * @return void */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; } /** * This function is called whenever one or more data-bound input properties change * @returns void */ ngOnChanges(): void { const METHOD_NAME: string = 'ngOnChanges()'; } /** * 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.user = null; this.surveyForm = null; this.surveyModal = null; this.cart = null; } /** * This function used to display the object. * @return void */ public show(cart: Cart): void { const METHOD_NAME: string = 'show()'; this.visible = true; setTimeout(() => this.visibleAnimate = true, 100); // this.surveyForm.reset(); this.user = this.userService.getUser(); this.sharedService.storeId.subscribe((val: number) => {this.storeId = val; }); this.surveyModal = {comments: ''}; // this.cart = this.cartService.getCart(); // this.sharedService.clearSessionStorage(false); this.cart = cart; } /** * This function is used to hide the object. * @returns void */ public hide(): void { const METHOD_NAME: string = 'hide()'; this.visibleAnimate = false; this.ratingCmp.rating=0; this.disableSubmit = true; 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(); } } ratingComponentClick(clickObj: any): void { this.ratingClicked = clickObj.rating; this.disableSubmit = false; console.log(this.ratingClicked); } /** * This function is used to send survey data. * @returns void */ sendSurvey(status: string): void { if (status === 'cancelled' || status === 'declined') { this.surveyModal.starRating = 0; this.surveyModal.comments = 'Agent declined the survey'; } else { this.surveyModal.starRating = this.ratingClicked; } this.surveyModal.status = status; this.surveyModal.storeEntId = this.storeId; // this.surveyModal.orderId = this.cart.orderId; // this.surveyModal.location = this.cart.dealerCode; if(this.cart){ this.surveyModal.orderId = this.cart.orderId; this.surveyModal.location = this.cart.dealerCode; } const inputData: any = CartUtils.validateSurveyInput(this.surveyModal); this.sharedService.showSpinner(true); // spinner this.cartService.sendSurvery(this.storeId, this.user.userId, inputData).subscribe(result => { this.sharedService.showSpinner(false); // spinner if (result.serviceStatus.message = 'Success') { this.hide(); } this.router.navigate(['home/search']); }, error => { this.sharedService.showSpinner(false); // spinner console.error('error=>' + error); this.sharedService.showErrorMessage(error, true); }); } }