import { EligibilityStatus, Trinary } from '../common/entities/Enums'; import { PropertyQuestion, PropertyQuestionTree, PropertyQuestionsService, isQuestion } from '../common/services/PropertyQuestionsService'; import { AnalyticsService } from '../common/services/AnalyticsService'; import { LayoutState } from '../common/state/LayoutState'; import { UserDataState } from '../common/state/UserDataState'; export class PropertyQuestionsController implements ng.IController { question: PropertyQuestion; constructor(private propertyQuestionsService: PropertyQuestionsService, private $state: ng.ui.IStateService, analyticsService: AnalyticsService, userDataState: UserDataState, layoutState: LayoutState, $window: ng.IWindowService) { layoutState.title = "Can we install?"; layoutState.back = () => $window.history.back(); if (!userDataState.fuel) $state.go('^.get-quote'); analyticsService.push({ event: 'ViewPropertyQuestions' }); this.handleTree(propertyQuestionsService.getFirstUnansweredQuestion()); } setAnswer(answer: Trinary) { this.handleTree(this.propertyQuestionsService.setAnswer(this.question, answer)); } private handleTree(tree: PropertyQuestionTree) { if (isQuestion(tree)) this.question = tree; else this.$state.go('^.plan-payg'); } }