import { Component, OnInit } from '@angular/core'; import { DynamicDialogRef, DynamicDialogConfig, DialogService } from 'primeng/api'; import { SharedBehaviorSubjectService } from '../../../shared/services/shared-behavior-subject.service'; @Component({ selector: 'app-add-conditional-jump', templateUrl: './add-conditional-jump.component.html', styleUrls: ['./add-conditional-jump.component.css'] }) export class AddConditionalJumpComponent implements OnInit { // Answer condition values answerConditionTypes: any; // To hold the passed params rowIndex: number; colIndex: number; // Holding the multiple questions allMultipleQuestions: any; // Selected question selectedQuestion: any; // Condition list conditionList: any = []; conditionIndex = 1; // Jump to questions jumpToQuestionsList = []; allAnswerTypes = []; selectedAnswerType; yesnovalues = []; constructor(public ref: DynamicDialogRef, public config: DynamicDialogConfig, private sharedService: SharedBehaviorSubjectService, public dialogService: DialogService) { } ngOnInit() { this.answerConditionTypes = [{ label: 'is equal to', value: 'ISEQUALTO' }, { label: 'is not equal to', value: 'ISNOTEQUALTO' }]; this.yesnovalues = [ { label: 'Yes', value: 'Yes' }, { label: 'No', value: 'No' }, { label: 'N/A', value: 'N/A' } ]; this.conditionList.push({ conditionNumber: this.conditionIndex }); // Getting the params this.rowIndex = +this.config.data['rowIndex']; this.colIndex = +this.config.data['colIndex']; if (this.config.data['allQuestions']) { this.allMultipleQuestions = this.config.data['allQuestions']; } if (this.config.data['allAnswerTypes']) { this.allAnswerTypes = this.config.data['allAnswerTypes']; } // tslint:disable-next-line: prefer-for-of for (let i = 0; i < this.allMultipleQuestions.length; i++) { if (i !== this.rowIndex && this.allMultipleQuestions[i]['Question'] !== '') { this.jumpToQuestionsList.push({ label: this.allMultipleQuestions[i]['Question'], value: this.allMultipleQuestions[i]['Question'] }); } } // tslint:disable-next-line: prefer-for-of for (let i = 0; i < this.allAnswerTypes.length; i++) { if (this.allAnswerTypes[i]['colNumber'] === this.colIndex && this.allAnswerTypes[i]['rowNumber'] === this.rowIndex) { this.selectedAnswerType = this.allAnswerTypes[i]['answerType']; } } // tslint:disable-next-line: prefer-for-of this.selectedQuestion = [{ label: this.allMultipleQuestions[this.rowIndex]['Question'], value: this.allMultipleQuestions[this.rowIndex]['Question'] }]; } // Adding the condition addCondition() { this.conditionList.push({ conditionNumber: this.conditionIndex++ }); } // Closing the add condition cancelAddCondition() { this.dialogService.dialogComponentRef.instance.close(); } // Delete condtion deleteCondition(condition) { if (this.conditionList.length > 1) { const index = this.conditionList.findIndex(order => order['conditionNumber'] === condition['conditionNumber']); this.conditionList.splice(index, 1); } } }