src/app/manage-learn/section-listing/section-listing.page.ts
selector | app-section-listing |
styleUrls | ./section-listing.page.scss |
templateUrl | ./section-listing.page.html |
Properties |
Methods |
constructor(localStorage: LocalStorageService, utils: UtilsService, updateTracker: UpdateTrackerService, router: Router, routerParam: ActivatedRoute, network: Network, translate: TranslateService, alertCtrl: AlertController, commonUtils: CommonUtilService, toast: ToastService)
|
|||||||||||||||||||||||||||||||||
Parameters :
|
checkForEvidenceCompletion |
checkForEvidenceCompletion()
|
Returns :
void
|
Async checkForNetworkTypeAlert |
checkForNetworkTypeAlert()
|
Returns :
any
|
goToImageListing |
goToImageListing()
|
Returns :
void
|
goToQuestioner | ||||
goToQuestioner(selectedSection)
|
||||
Parameters :
Returns :
void
|
ionViewWillEnter |
ionViewWillEnter()
|
Returns :
void
|
previewSubmission |
previewSubmission()
|
Returns :
void
|
viewReport |
viewReport()
|
Returns :
void
|
allAnsweredForEvidence |
Type : boolean
|
currentEvidence |
Type : any
|
data |
entityName |
Type : any
|
evidenceSections |
Type : any
|
networkAvailable |
Type : boolean
|
recentlyUpdatedEntity |
Type : any
|
sectionData |
Type : any
|
selectedEvidenceIndex |
Type : any
|
selectedEvidenceName |
Type : any
|
submissionId |
Type : any
|
import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterLinks } from '@app/app/app.constant';
import { LocalStorageService, ToastService, UtilsService } from '@app/app/manage-learn/core';
import { UpdateTrackerService } from '@app/app/manage-learn/core/services/update-tracker.service';
import { CommonUtilService } from '@app/services';
import { Network } from '@ionic-native/network/ngx';
import { AlertController } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'app-section-listing',
templateUrl: './section-listing.page.html',
styleUrls: ['./section-listing.page.scss'],
})
export class SectionListingPage {
sectionData: any;
currentEvidence: any;
evidenceSections: any;
selectedEvidenceName: any;
data;
submissionId: any;
entityName: any;
selectedEvidenceIndex: any;
recentlyUpdatedEntity: any;
allAnsweredForEvidence: boolean;
networkAvailable: boolean;
constructor(
private localStorage: LocalStorageService,
private utils: UtilsService,
private updateTracker: UpdateTrackerService,
private router: Router,
private routerParam: ActivatedRoute,
private network: Network,
private translate: TranslateService,
private alertCtrl: AlertController,
private commonUtils: CommonUtilService,
private toast: ToastService
) {
this.networkAvailable = this.commonUtils.networkInfo.isNetworkAvailable;
this.routerParam.queryParams.subscribe((params) => {
this.submissionId = params.submisssionId;
this.selectedEvidenceIndex = params.evidenceIndex;
this.entityName = params.schoolName;
});
}
ionViewWillEnter() {
this.localStorage
.getLocalStorage(this.utils.getAssessmentLocalStorageKey(this.submissionId))
.then((data) => {
this.sectionData = data;
let assessmentDetails = this.updateTracker.getLastModifiedInSection(
data,
this.selectedEvidenceIndex,
this.submissionId,
this.recentlyUpdatedEntity
);
this.currentEvidence = assessmentDetails['assessment']['evidences'][this.selectedEvidenceIndex];
this.evidenceSections = this.currentEvidence['sections'];
this.selectedEvidenceName = this.currentEvidence['name'];
this.checkForEvidenceCompletion();
});
}
checkForEvidenceCompletion(): void {
let allAnswered;
for (const section of this.evidenceSections) {
allAnswered = true;
for (const question of section.questions) {
if (!question.isCompleted) {
allAnswered = false;
break;
}
}
if (this.currentEvidence.isSubmitted) {
section.progressStatus = 'submitted';
} else if (!this.currentEvidence.startTime) {
section.progressStatus = '';
} else if (allAnswered) {
section.progressStatus = 'completed';
} else if (!allAnswered && section.progressStatus) {
section.progressStatus = 'inProgress';
} else if (!section.progressStatus) {
section.progressStatus = '';
}
}
this.allAnsweredForEvidence = true;
for (const section of this.evidenceSections) {
if (section.progressStatus !== 'completed') {
this.allAnsweredForEvidence = false;
break;
}
}
this.localStorage.setLocalStorage(this.utils.getAssessmentLocalStorageKey(this.submissionId), this.sectionData);
}
goToQuestioner(selectedSection): void {
const params = {
_id: this.submissionId,
name: this.entityName,
selectedEvidence: this.selectedEvidenceIndex,
selectedSection: selectedSection,
};
if (!this.evidenceSections[selectedSection].progressStatus) {
this.evidenceSections[selectedSection].progressStatus = this.currentEvidence.startTime ? 'inProgress' : '';
this.localStorage.setLocalStorage(this.utils.getAssessmentLocalStorageKey(this.submissionId), this.sectionData);
}
this.router.navigate([RouterLinks.QUESTIONNAIRE], {
queryParams: {
submisssionId: this.submissionId,
evidenceIndex: this.selectedEvidenceIndex,
sectionIndex: selectedSection,
schoolName: this.entityName,
},
});
}
async checkForNetworkTypeAlert() {
if (this.network.type !== ('3g' || '4g' || 'wifi')) {
let translateObject;
this.translate
.get(['FRMELEMNTS_LBL_CONFIRM', 'FRMELEMNTS_LBL_YES', 'FRMELEMNTS_LBL_NO', 'FRMELEMNTS_MSG_SLOW_INTERNET'])
.subscribe((translations) => {
translateObject = translations;
// console.log(JSON.stringify(translations))
});
let alert = await this.alertCtrl.create({
header: translateObject['FRMELEMNTS_LBL_CONFIRM'],
message: translateObject['FRMELEMNTS_MSG_SLOW_INTERNET'],
buttons: [
{
text: translateObject['FRMELEMNTS_LBL_NO'],
role: 'cancel',
handler: () => {
},
},
{
text: translateObject['FRMELEMNTS_LBL_YES'],
handler: () => {
this.goToImageListing();
},
},
],
});
alert.present();
}
}
goToImageListing() {
if (this.networkAvailable) {
const params = {
// selectedEvidenceId: this.currentEvidence._id,
submissionId: this.submissionId,
name: this.entityName,
selectedEvidenceIndex: this.selectedEvidenceIndex,
};
this.router.navigate([RouterLinks.IMAGE_LISTING], { queryParams: params });
} else {
this.translate.get('toastMessage.connectToInternet').subscribe((translations) => {
this.toast.openToast(translations);
});
}
}
viewReport() {
// this.navCtrl.push(ObservationReportsPage, { submissionId: this.submissionId })
this.router.navigate([RouterLinks.OBSERVATION_REPORTS], {
queryParams: {
submissionId: this.submissionId,
},
});
}
previewSubmission() {
this.router.navigate([RouterLinks.SUBMISSION_PREVIEW], {
queryParams: {
submissionId: this.submissionId,
name: this.entityName,
selectedEvidenceIndex: this.selectedEvidenceIndex,
goBackNum :-1
},
});
}
}
<ion-content>
<ion-item-group>
<ion-item-divider color="light">
<h3 class="headerText">
<ion-icon name="book" class="margin-right"></ion-icon>
<span class="ml-5">{{ entityName }}</span>
</h3>
</ion-item-divider>
<ng-container *ngFor="let section of evidenceSections; let i = index">
<ion-item (click)="goToQuestioner(i)" *ngIf="section?.questions?.length">
<div class="d-flex flex-ai-center flex-jc-space-between w-100">
<div class="d-flex flex-ai-center">
<ion-icon name="list" class="margin-right mr-5"></ion-icon>
<span>
{{ section?.name }}
</span>
</div>
<span class="float-right" *ngIf="section.progressStatus === 'completed'" class="_completed _flex-box">
{{ 'COMPLETED' | translate }}
<ion-icon name="checkmark-circle" class="_progressIcon ion-margin-start"> </ion-icon>
</span>
<span class="float-right" *ngIf="!section.progressStatus && !isIos" class="_flex-box">
<ion-icon name="arrow-forward" class="_progressIcon ion-margin-start"></ion-icon>
</span>
<span class="float-right" *ngIf="section.progressStatus === 'inProgress'" class="_inProgress _flex-box">
{{ 'FRMELEMNTS_LBL_IN_PROGRESS' | translate }}
<ion-icon name="contrast" class="_progressIcon ion-margin-start" ></ion-icon>
</span>
<span class="float-right" *ngIf="section.progressStatus === 'submitted'" class="_submitted _flex-box">
{{ 'FRMELEMNTS_LBL_SUBMITTTED' | translate }}
<ion-icon name="cloud-done" class="_progressIcon ion-margin-start" ></ion-icon>
</span>
</div>
</ion-item>
</ng-container>
</ion-item-group>
<div class="border-radius ion-margin" *ngIf="currentEvidence?.description">
<h2 class="ion-padding-start">{{'FRMELEMNTS_LBL_DESCRIPTION' | translate}}</h2>
<div class="ion-padding-horizontal ion-padding-bottom">
{{currentEvidence?.description}}
</div>
</div>
</ion-content>
<ion-footer no-shadow
*ngIf="((allAnsweredForEvidence && !currentEvidence?.isSubmitted) || currentEvidence?.enableSubmit) && !sectionData?.observation">
<ion-toolbar position="bottom">
<ion-row>
<ion-button class="w-100 custom-btn-txt-transform-none" ion-button full (click)="checkForNetworkTypeAlert()">{{'FRMELEMNTS_BTN_UPLOAD_AND_SUBMIT'|translate}}
</ion-button>
</ion-row>
</ion-toolbar>
</ion-footer>
<ion-footer no-shadow *ngIf="((allAnsweredForEvidence && !currentEvidence.isSubmitted && sectionData?.observation) || currentEvidence?.enableSubmit)">
<ion-toolbar position="bottom">
<ion-row>
<ion-button class="w-100 custom-btn-txt-transform-none" ion-button full (click)="previewSubmission()">
{{'FRMELEMNTS_BTN_PREVIEW'|translate}}</ion-button>
</ion-row>
</ion-toolbar>
</ion-footer>
<ion-footer no-shadow *ngIf="sectionData?.observation && currentEvidence?.isSubmitted">
<ion-toolbar position="bottom">
<ion-row>
<ion-button class="w-100 custom-btn-txt-transform-none" ion-button full (click)="viewReport()">
{{'FRMELEMNTS_LBL_VIEW_REPORT'|translate}} </ion-button>
</ion-row>
</ion-toolbar>
</ion-footer>
./section-listing.page.scss
.headerText {
font-weight: 500 !important;
font-size: 1.5rem !important;
display: flex;
align-items: center;
}