File

src/app/manage-learn/shared/components/matrix-type-input/matrix-type-input.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(modalCtrl: ModalController, translate: TranslateService, alertCtrl: AlertController, utils: UtilsService)
Parameters :
Name Type Optional
modalCtrl ModalController No
translate TranslateService No
alertCtrl AlertController No
utils UtilsService No

Inputs

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

Outputs

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

Methods

addInstances
addInstances()
Returns : void
back
back()
Returns : void
checkCompletionOfInstance
checkCompletionOfInstance(data, gpsLocation)
Parameters :
Name Optional
data No
gpsLocation No
Returns : boolean
checkForValidation
checkForValidation()
Returns : void
deleteInstance
deleteInstance(instanceIndex)
Parameters :
Name Optional
instanceIndex No
Returns : void
Async deleteInstanceAlert
deleteInstanceAlert(index)
Parameters :
Name Optional
index No
Returns : any
getLastModified
getLastModified(instance)
Parameters :
Name Optional
instance No
Returns : number
next
next(status?: any)
Parameters :
Name Type Optional
status any Yes
Returns : void
ngOnInit
ngOnInit()
Returns : void
updateInstance
updateInstance(instanceIndex, instanceValue, gpsLocation?: any)
Parameters :
Name Type Optional
instanceIndex No
instanceValue No
gpsLocation any Yes
Returns : void
Async viewInstance
viewInstance(i)
Parameters :
Name Optional
i No
Returns : any

Properties

initilaData
mainInstance
Type : any
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { UtilsService } from '@app/app/manage-learn/core';
import { MatrixModalComponent } from '@app/app/manage-learn/questionnaire/matrix-modal/matrix-modal.component';
import { AlertController, ModalController } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';

@Component({
  selector: 'app-matrix-type-input',
  templateUrl: './matrix-type-input.component.html',
  styleUrls: ['./matrix-type-input.component.scss'],
})
export class MatrixTypeInputComponent implements OnInit {

  @Input() data: any;
  @Input() isLast: boolean;
  @Input() isFirst: boolean;
  @Output() nextCallBack = new EventEmitter();
  @Output() previousCallBack = new EventEmitter();
  @Output() updateLocalData = new EventEmitter();
  @Input() evidenceId: string;
  @Input() schoolId: string;
  @Input() imageLocalCopyId: string;
  @Input() generalQuestion: boolean;
  @Input() submissionId: string;
  @Input() inputIndex;
  @Input() enableGps;
  @Input() enableQuestionReadOut: boolean;
  mainInstance: any;
  initilaData;

  constructor(
    private modalCtrl: ModalController,
    private translate: TranslateService,
    private alertCtrl: AlertController,
    private utils: UtilsService) { }

  ngOnInit() {
    this.data.startTime = this.data.startTime ? this.data.startTime : Date.now();
    this.initilaData = JSON.parse(JSON.stringify(this.data));
  }

  next(status?: any) {
    this.data.isCompleted = this.utils.isMatrixQuestionComplete(this.data);
    this.nextCallBack.emit(status);
  }

  back() {
    this.data.isCompleted = this.utils.isMatrixQuestionComplete(this.data);
    this.previousCallBack.emit('previous');
  }

  addInstances(): void {
    this.data.value = this.data.value ? this.data.value : [];
    this.data.value.push(JSON.parse(JSON.stringify(this.data.instanceQuestions)));
    this.checkForValidation();
  }

  async viewInstance(i) {
    const obj = {
      selectedIndex: i,
      data: JSON.parse(JSON.stringify(this.data)),
      evidenceId: this.evidenceId,
      schoolId: this.schoolId,
      generalQuestion: this.generalQuestion,
      submissionId: this.submissionId,
      questionIndex: this.inputIndex,
      enableQuestionReadOut: this.enableQuestionReadOut
    }
    let matrixModal = await this.modalCtrl.create({
      component: MatrixModalComponent,
      componentProps: obj
    });

    await matrixModal.present();

    const { data } = await matrixModal.onDidDismiss()
    this.updateInstance(i, data)
    // matrixModal.onDidDismiss(instanceValue => {
    //   if (this.enableGps) {
    //     this.checkForGpsLocation(i, instanceValue)
    //   } else {
    //     this.updateInstance(i, instanceValue)
    //   }
    // })
  }

  // checkForGpsLocation(instanceIndex, instanceValue) {
  //   if (JSON.stringify(instanceValue) !== JSON.stringify(this.data.value[instanceIndex]) && this.checkCompletionOfInstance(instanceValue, null)) {
  //     this.utils.startLoader();
  //     this.ngps.getGpsStatus().then(success => {
  //       this.utils.stopLoader();
  //       this.updateInstance(instanceIndex, instanceValue, success)
  //     }).catch(error => {
  //       this.utils.stopLoader();
  //       this.utils.openToast("Please try again.");
  //     })
  //   } else {
  //     this.updateInstance(instanceIndex, instanceValue)
  //   }
  // }

  updateInstance(instanceIndex, instanceValue, gpsLocation?: any) {
    if (instanceValue) {
      this.data.completedInstance = this.data.completedInstance ? this.data.completedInstance : [];
      this.data.value[instanceIndex] = instanceValue;
      let instanceCompletion = this.checkCompletionOfInstance(this.data.value[instanceIndex], gpsLocation);
      if (instanceCompletion) {
        this.data.value[instanceIndex].isInstanceCompleted = true
        if (this.data.completedInstance.indexOf(instanceIndex) < 0) {
          this.data.completedInstance.push(instanceIndex);
        }
      } else {
       this.data.value[instanceIndex].isInstanceCompleted = false
        const index = this.data.completedInstance.indexOf(instanceIndex);
        if (index >= 0) {
          this.data.completedInstance.splice(index, 1);
        }
      }
      this.checkForValidation();
    }
  }

  checkCompletionOfInstance(data, gpsLocation): boolean {
    let isCompleted = true;
    if (data) {
      for (const question of data) {
        question.gpsLocation = gpsLocation ? gpsLocation : "";
        if (!question.isCompleted) {
          isCompleted = false;
          return false
        }
      }
    } else {
      isCompleted = false
    }

    return isCompleted

  }

  deleteInstance(instanceIndex): void {
    this.data.value.splice(instanceIndex, 1);
    if (this.data.completedInstance && this.data.completedInstance.length && this.data.completedInstance.indexOf(instanceIndex) >= 0) {
      this.data.completedInstance.splice(instanceIndex, 1);
    }
    this.checkForValidation();

    // }
  }

  checkForValidation(): void {
    this.data.isCompleted = this.utils.isMatrixQuestionComplete(this.data);
    this.data.endTime = this.data.isCompleted ? Date.now() : "";
    this.updateLocalData.emit();
  }


  async deleteInstanceAlert(index) {
    let translateObject;
    this.translate.get(['FRMELEMNTS_LBL_COFIRMATION_DELETE', 'FRMELEMNTS_LBL_COFIRMATION_DELETE_INSTANCE', 'NO', 'YES']).subscribe(translations => {
      translateObject = translations;
    })
    let alert = await this.alertCtrl.create({
      header: translateObject['FRMELEMNTS_LBL_COFIRMATION_DELETE'],
      message: translateObject['FRMELEMNTS_LBL_COFIRMATION_DELETE_INSTANCE'],
      cssClass:'attachment-delete-alert',
      buttons: [
        {
          text: translateObject['NO'],
          role: 'cancel',
          handler: () => {
          }
        },
        {
          text: translateObject['YES'],
          handler: () => {
            this.deleteInstance(index);
          }
        }
      ]
    });
    await alert.present();
  }

  getLastModified(instance) {
    let lastModifiedAt = 0;
    for (const question of instance) {
      if (question.startTime > lastModifiedAt) {
        lastModifiedAt = question.startTime;
      }
    }
    return lastModifiedAt
  }

}
<ion-card class="_cardBg ion-padding">
  <ion-col class="_flex-box _justify-content-center _flex-direction-column ">
    <h4
      [ngClass]="{'_validQuestion': data?.completedInstance?.length && (data?.completedInstance?.length === data?.value?.length)}">
      <app-question-heading [inputIndex]="inputIndex" [data]="data" [enableQuestionReadOut]="enableQuestionReadOut">
      </app-question-heading>
    </h4>
  </ion-col>
  <div class="_tip _flex-box "> {{data?.tip}}</div>
  <div class="_flex-box alignBtn">
    <button class="btn-block px-10 sb-bg-color-primary" (click)="addInstances()">{{'FRMELEMENTS_BTN_ADD'|
      translate}} {{data.instanceIdentifier | lowercase}}</button>
  </div>
  <ion-list class="ion-margin-top ion-text-wrap" *ngIf="data?.value?.length">
    <ion-item text-capitalize class="_flex-box" *ngFor="let instance of data?.value; let i = index">
      <div class="_flex-box conatiner" (click)="viewInstance(i)">
          <span [ngClass]="{'_validQuestion': instance?.isInstanceCompleted}" style="flex:1">
          {{data?.instanceIdentifier}} {{i+1}}</span>
        <span class="modified" *ngIf="getLastModified(instance)">Last Modified
          {{getLastModified(instance)|date:'shortTime'}} {{getLastModified(instance)|date:'mediumDate'}} </span>
      </div>
      <ion-icon name="trash" class="deletOption ion-margin-right" item-end (click)="deleteInstanceAlert(i)"></ion-icon>
    </ion-item>
  </ion-list>
  <app-image-upload
    [submissionId]="submissionId"
    [data]="data"
    [generalQuestion]="generalQuestion"
    [imageLocalCopyId]="imageLocalCopyId"
    [evidenceId]="evidenceId"
    [schoolId]="schoolId"
  ></app-image-upload>
</ion-card>

./matrix-type-input.component.scss

ion-fab {
    bottom: 5rem !important;
    position: fixed;
    z-index: 1;
}
.deletOption {
    color:  #808080;
}
.modified {
    color:  #808080;
    font-size: 0.813rem;
    margin-top: 5px;
}
.conatiner{
    flex-direction: column; 
    align-items:flex-start; 
    flex:1
}

.alignBtn {
    justify-content: flex-end;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""