src/app/manage-learn/questionnaire/matrix-modal/matrix-modal.component.ts
selector | app-matrix-modal |
styleUrls | ./matrix-modal.component.scss |
templateUrl | ./matrix-modal.component.html |
Properties |
Methods |
Inputs |
constructor(modal: ModalController, utils: UtilsService)
|
|||||||||
Parameters :
|
data | |
Type : any
|
|
enableQuestionReadOut | |
Type : boolean
|
|
evidenceId | |
Type : string
|
|
generalQuestion | |
Type : boolean
|
|
inputIndex | |
Type : any
|
|
schoolId | |
Type : string
|
|
selectedIndex | |
Type : any
|
|
submissionId | |
Type : string
|
|
cancel |
cancel()
|
Returns :
void
|
checkForDependentVisibility | ||||||
checkForDependentVisibility(qst, allQuestion)
|
||||||
Parameters :
Returns :
boolean
|
checkForVisibility | ||||
checkForVisibility(currentQuestionIndex)
|
||||
Parameters :
Returns :
boolean
|
update |
update()
|
Returns :
void
|
instanceDetails |
Type : any
|
import { Component, Input } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { UtilsService } from '../../core';
@Component({
selector: 'app-matrix-modal',
templateUrl: './matrix-modal.component.html',
styleUrls: ['./matrix-modal.component.scss'],
})
export class MatrixModalComponent {
@Input() inputIndex: any;
instanceDetails: any;
@Input() selectedIndex: any;
@Input() data: any;
@Input() schoolId: string;
@Input() evidenceId: string;
@Input() generalQuestion: boolean;
@Input() submissionId: string;
@Input() enableQuestionReadOut: boolean;
constructor(
private modal: ModalController,
private utils: UtilsService
) {
}
update(): void {
for (const question of this.data.value[this.selectedIndex]) {
// 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);
}
}
const instanceValue = JSON.parse(JSON.stringify(this.data.value[this.selectedIndex]))
this.modal.dismiss(instanceValue)
}
cancel(): void {
this.modal.dismiss();
}
checkForVisibility(currentQuestionIndex) {
let visibility = false;
const currentQuestion = this.data.value[this.selectedIndex][currentQuestionIndex];
let display = true;
for (const question of this.data.value[this.selectedIndex]) {
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.value[this.selectedIndex][currentQuestionIndex].isCompleted = true;
return false
} else {
this.data.value[this.selectedIndex][currentQuestionIndex].isCompleted = this.utils.isQuestionComplete(currentQuestion);
}
}
}
}
return display
}
checkForDependentVisibility(qst, allQuestion): boolean {
let display = true;
for (const question of allQuestion) {
for (const condition of qst.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(''))) {
return false
}
}
}
}
return display
}
}
<ion-content>
<div class="container">
<ion-col class="_flex-box _justify-content-center _flex-direction-column ion-padding">
<h4 *ngFor="let question of data.question">{{question}}</h4>
</ion-col>
<div *ngFor="let instance of data?.value; let i = index">
<ng-container *ngIf="selectedIndex ===i">
<ng-container [ngSwitch]="question?.responseType" *ngFor="let question of instance; let j=index" class="ion-margin-bottom">
<ion-item-divider color="light" *ngIf="question?.sectionHeader">
<h4 class="bold _flex-box sectionHeader ion-text-wrap" >{{question?.sectionHeader}}</h4>
</ion-item-divider>
<div class="_fullScreenCard" *ngIf="checkForVisibility(j)">
<app-text-type-input [inputIndex]="j+1" [data]="question" [generalQuestion]="generalQuestion"
[evidenceId]="evidenceId" [schoolId]="schoolId" *ngSwitchCase="'text'" [hideButton]="true"
[submissionId]="submissionId" [enableQuestionReadOut]="enableQuestionReadOut"></app-text-type-input>
<app-text-type-input [inputIndex]="j+1" [data]="question" [generalQuestion]="generalQuestion"
[evidenceId]="evidenceId" [schoolId]="schoolId" *ngSwitchCase="'number'" [submissionId]="submissionId"
[hideButton]="true" [enableQuestionReadOut]="enableQuestionReadOut"></app-text-type-input>
<app-radio-type-input [inputIndex]="j+1" [data]="question" [generalQuestion]="generalQuestion"
[evidenceId]="evidenceId" [schoolId]="schoolId" *ngSwitchCase="'radio'" [submissionId]="submissionId"
[hideButton]="true" [enableQuestionReadOut]="enableQuestionReadOut"></app-radio-type-input>
<app-date-type-input [inputIndex]="j+1" [data]="question" [generalQuestion]="generalQuestion"
[evidenceId]="evidenceId" [schoolId]="schoolId" *ngSwitchCase="'date'" [submissionId]="submissionId"
[hideButton]="true" [enableQuestionReadOut]="enableQuestionReadOut"></app-date-type-input>
<app-multiple-type-input [inputIndex]="j+1" [data]="question" [generalQuestion]="generalQuestion"
[evidenceId]="evidenceId" [schoolId]="schoolId" *ngSwitchCase="'multiselect'"
[submissionId]="submissionId" [hideButton]="true" [enableQuestionReadOut]="enableQuestionReadOut">
</app-multiple-type-input>
<app-slider-type-input [inputIndex]="j+1" [evidenceId]="selectedEvidenceId" [schoolId]="schoolId"
[data]="question" [imageLocalCopyId]="localImageListKey" [submissionId]="submissionId"
*ngSwitchCase="'slider'" [enableQuestionReadOut]="enableQuestionReadOut"></app-slider-type-input>
</div>
</ng-container>
</ng-container>
</div>
</div>
</ion-content>
<div class="_footer customFooter">
<ion-row>
<ion-col>
<ion-button icon-start size="full" color="light" (click)="cancel()" class="custom-btn-txt-transform-none">
{{'CANCEL'|translate}}
</ion-button>
</ion-col>
<ion-col>
<ion-button size="full" (click)="update()" class="custom-btn-txt-transform-none">
{{'SAVE'|translate}}
</ion-button>
</ion-col>
</ion-row>
</div>
./matrix-modal.component.scss
.container {
margin-bottom: 60px;
}
.closeBtn {
color: white !important;
font-size: 1.5rem;
padding-right: 10px
}
.customFooter {
padding: 0;
}
.hideElement {
border: red !important
}
.sectionHeader {
padding-top: 10px;
}
.flexbox {
display: flex;
align-items: baseline;
flex-wrap: nowrap;
}
.noWrap {
white-space: nowrap;
width: fit-content;
}
.wrapText {
white-space: wrap;
}