File

src/app/manage-learn/shared/components/page-questions/page-questions.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(utils: UtilsService)
Parameters :
Name Type Optional
utils UtilsService No

Inputs

data
Type : any
enableQuestionReadOut
Type : boolean
evidenceId
Type : string
generalQuestion
Type : boolean
hideButton
Type : boolean
imageLocalCopyId
Type : string
inputIndex
Type : any
isFirst
Type : boolean
isLast
Type : boolean
schoolId
Type : any
submissionId
Type : any

Outputs

nextCallBack
Type : EventEmitter
previousCallBack
Type : EventEmitter
updateLocalData
Type : EventEmitter

Methods

checkForVisibility
checkForVisibility(currentQuestionIndex)
Parameters :
Name Optional
currentQuestionIndex No
Returns : boolean
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
updateLocalDataInPageQuestion
updateLocalDataInPageQuestion()
Returns : void

Properties

notNumber
Type : boolean
questionValid
Type : boolean
text
Type : string
import { Component, Input, EventEmitter, Output, OnInit, OnDestroy } from '@angular/core';
import { UtilsService } from '@app/app/manage-learn/core';

@Component({
  selector: 'app-page-questions',
  templateUrl: './page-questions.component.html',
  styleUrls: ['./page-questions.component.scss'],
})
export class PageQuestionsComponent implements OnInit,OnDestroy {

  @Input() inputIndex ;
  @Input() data: any;
  @Input() isLast: boolean;
  @Input() isFirst: boolean;
  @Output() nextCallBack = new EventEmitter();
  @Output() updateLocalData = new EventEmitter();
  @Output() previousCallBack = new EventEmitter()
  @Input() evidenceId: string;
  @Input() hideButton: boolean;
  @Input() submissionId: any;
  @Input() imageLocalCopyId: string;
  @Input() generalQuestion: boolean;
  @Input() schoolId;
  @Input() enableQuestionReadOut: boolean;
  notNumber: boolean;
  questionValid: boolean;
  text: string;

  constructor(private utils: UtilsService) { }


  ngOnDestroy() {
    console.log(JSON.stringify(this.data))
    for (const question of this.data.pageQuestions) {
      // Do check only for questions without visibleif. For visibleIf questions isCompleted property is set in  checkForVisibility()
      if (!question.visibleIf) {
        question.isCompleted = this.utils.isQuestionComplete(question);
      }
    }
  }

  ngOnInit() {
    this.data.startTime = this.data.startTime ? this.data.startTime : Date.now();
  }

  updateLocalDataInPageQuestion(): void {
    this.updateLocalData.emit();
  }

  checkForVisibility(currentQuestionIndex) {
    const currentQuestion = this.data.pageQuestions[currentQuestionIndex];
    let display = true;
    for (const question of this.data.pageQuestions) {
      for (const condition of currentQuestion.visibleIf) {
        if (condition._id === question._id) {
          let expression = [];
          if (condition.operator != "===") {
            if (question.responseType === 'multiselect') {
              for (const parentValue of question.value) {
                for (const value of condition.value) {
                  expression.push("(", "'" + parentValue + "'", "===", "'" + value + "'", ")", condition.operator);
                }
              }
            } else {
              for (const value of condition.value) {
                expression.push("(", "'" + question.value + "'", "===", "'" + value + "'", ")", condition.operator)
              }
            }
            expression.pop();
          } else {
            if (question.responseType === 'multiselect') {
              for (const value of question.value) {
                expression.push("(", "'" + condition.value + "'", "===", "'" + value + "'", ")", "||");
              }
              expression.pop();
            } else {
              expression.push("(", "'" + question.value + "'", condition.operator, "'" + condition.value + "'", ")")
            }
          }
          if (!eval(expression.join(''))) {
            this.data.pageQuestions[currentQuestionIndex].isCompleted = true;
            this.data.pageQuestions[currentQuestionIndex].value = "";
            return false
          } else {
            this.data.pageQuestions[currentQuestionIndex].isCompleted = this.utils.isQuestionComplete(currentQuestion);
          }
        }
      }
    }
    return display
  }


}
<div *ngIf="data?.pageQuestions?.length">
  <ng-container 
    *ngFor="let question of data?.pageQuestions; let j=index" [ngSwitch]="question?.responseType.toLowerCase()">
    <div class="_fullScreenCard" *ngIf="checkForVisibility(j)" >
      <ion-item-divider color="light" *ngIf="question?.sectionHeader">
        <h4 class="bold _flex-box sectionHeader ion-text-wrap" >{{question?.sectionHeader}}</h4>
      </ion-item-divider>
      <app-text-type-input [inputIndex]="start + 1" [evidenceId]="selectedEvidenceId" [submissionId]="submissionId"
        [data]="question" [imageLocalCopyId]="localImageListKey" *ngSwitchCase="'text'"
        [enableQuestionReadOut]="enableQuestionReadOut"></app-text-type-input>
      <app-text-type-input [inputIndex]="start + 1" [evidenceId]="selectedEvidenceId" [submissionId]="submissionId"
        [schoolId]="schoolId" [data]="question" [imageLocalCopyId]="localImageListKey" *ngSwitchCase="'number'"
        [enableQuestionReadOut]="enableQuestionReadOut"></app-text-type-input>
      <app-radio-type-input [inputIndex]="start + 1" [evidenceId]="selectedEvidenceId" [submissionId]="submissionId"
        [schoolId]="schoolId" [data]="question" [imageLocalCopyId]="localImageListKey" *ngSwitchCase="'radio'"
        [enableQuestionReadOut]="enableQuestionReadOut"></app-radio-type-input>
      <app-date-type-input [inputIndex]="start + 1" [evidenceId]="selectedEvidenceId" [submissionId]="submissionId"
        [schoolId]="schoolId" [data]="question" [imageLocalCopyId]="localImageListKey" *ngSwitchCase="'date'"
        [enableQuestionReadOut]="enableQuestionReadOut"></app-date-type-input>
      <app-multiple-type-input [inputIndex]="start + 1" [evidenceId]="selectedEvidenceId" [schoolId]="schoolId"
        [data]="question" [imageLocalCopyId]="localImageListKey" [submissionId]="submissionId"
        *ngSwitchCase="'multiselect'" [enableQuestionReadOut]="enableQuestionReadOut"></app-multiple-type-input>
      <app-matrix-type-input [inputIndex]="start + 1" [evidenceId]="selectedEvidenceId" [schoolId]="schoolId"
      [data]="question" [imageLocalCopyId]="localImageListKey" [submissionId]="submissionId"
      (updateLocalData)="updateLocalDataInPageQuestion()" *ngSwitchCase="'matrix'" [enableGps]="captureGpsLocationAtQuestionLevel"
      [enableQuestionReadOut]="enableQuestionReadOut">
    </app-matrix-type-input>
      <app-slider-type-input [inputIndex]="start + 1" [evidenceId]="selectedEvidenceId" [submissionId]="submissionId"
        [schoolId]="schoolId" [data]="question" [imageLocalCopyId]="localImageListKey" *ngSwitchCase="'slider'"
        [enableQuestionReadOut]="enableQuestionReadOut"></app-slider-type-input>
    </div>
  </ng-container>
</div>

./page-questions.component.scss

.sectionHeader {
    padding: 5px 0;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""