src/app/manage-learn/domain-ecm-listing/domain-ecm-lsiting/domain-ecm-lsiting.component.ts
selector | app-domain-ecm-lsiting |
styleUrls | ./domain-ecm-lsiting.component.scss |
templateUrl | ./domain-ecm-lsiting.component.html |
Properties |
|
Methods |
constructor(updateTracker: UpdateTrackerService, utils: UtilsService, localStorage: LocalStorageService, evdnsServ: EvidenceService, platform: Platform, headerService: AppHeaderService, routerParam: ActivatedRoute, router: Router, observationService: ObservationService, genericPopup: GenericPopUpService, loader: LoaderService, commonUtilService: CommonUtilService, toast: ToastService, translate: TranslateService)
|
|||||||||||||||||||||||||||||||||||||||||||||
Parameters :
|
checkForEvidenceCompletion |
checkForEvidenceCompletion()
|
Returns :
void
|
checkForProgressStatus |
checkForProgressStatus()
|
Returns :
void
|
Async fetchDownloaded |
fetchDownloaded()
|
Returns :
any
|
getAssessmentDetails | ||||
getAssessmentDetails(successData)
|
||||
Parameters :
Returns :
void
|
Async goToQuestioner | ||||
goToQuestioner(selectedSection)
|
||||
Parameters :
Returns :
any
|
ionViewWillEnter |
ionViewWillEnter()
|
Returns :
void
|
mapCompletedAndTotalQuestions |
mapCompletedAndTotalQuestions()
|
Returns :
void
|
navigateToEvidence | ||||
navigateToEvidence(index)
|
||||
Parameters :
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
notApplicableClick | ||||
notApplicableClick(selectedSectionIndex)
|
||||
Parameters :
Returns :
void
|
Async openAction | ||||||
openAction(assessment, evidenceIndex)
|
||||||
Parameters :
Returns :
unknown
|
Async openEvidence | ||||
openEvidence(evidenceIndex)
|
||||
Parameters :
Returns :
any
|
Async pushToLocal |
pushToLocal()
|
Returns :
any
|
Private Optional _networkSubscription |
Type : Subscription
|
allAnsweredForEvidence |
Type : boolean
|
allowMultipleAssessemts |
Type : any
|
Public commonUtilService |
Type : CommonUtilService
|
currentEvidence |
Type : any
|
downloadedSubmissionList |
Type : any
|
entityData |
Type : any
|
entityEvidences |
Type : any
|
entityName |
Type : any
|
evidenceSections |
Type : any
|
extrasState |
Type : any
|
generalQuestions |
Type : any
|
Public genericPopup |
Type : GenericPopUpService
|
headerConfig |
Type : object
|
Default value : {
showHeader: true,
showBurgerMenu: false,
actionButtons: [],
}
|
Public loader |
Type : LoaderService
|
msgs |
Type : any
|
networkFlag |
Type : boolean
|
recentlyUpdatedEntity |
Type : any
|
selectedEvidenceIndex |
Type : any
|
submissionId |
Type : any
|
Public toast |
Type : ToastService
|
import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterLinks } from '@app/app/app.constant';
import { CommonUtilService,AppHeaderService } from '@app/services';
import { Platform } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { UtilsService, LocalStorageService, LoaderService, ToastService } from '../../core';
import { EvidenceService } from '../../core/services/evidence.service';
import { UpdateTrackerService } from '../../core/services/update-tracker.service';
import { ObservationService } from '../../observation/observation.service';
import { GenericPopUpService } from '../../shared';
@Component({
selector: 'app-domain-ecm-lsiting',
templateUrl: './domain-ecm-lsiting.component.html',
styleUrls: ['./domain-ecm-lsiting.component.scss'],
})
export class DomainEcmLsitingComponent {
entityName: any;
entityData: any;
entityEvidences: any;
generalQuestions: any;
recentlyUpdatedEntity: any;
selectedEvidenceIndex: any;
currentEvidence: any;
evidenceSections: any;
allAnsweredForEvidence: boolean;
submissionId: any;
downloadedSubmissionList: any;
allowMultipleAssessemts: any;
private _networkSubscription?: Subscription;
networkFlag: boolean;
msgs:any
extrasState:any;
headerConfig = {
showHeader: true,
showBurgerMenu: false,
actionButtons: [],
};
constructor(
private updateTracker: UpdateTrackerService,
private utils: UtilsService,
private localStorage: LocalStorageService,
private evdnsServ: EvidenceService,
private platform: Platform,
private headerService: AppHeaderService,
private routerParam: ActivatedRoute,
private router: Router,
private observationService: ObservationService,
public genericPopup: GenericPopUpService,
public loader: LoaderService,
public commonUtilService: CommonUtilService,
public toast: ToastService,
private translate: TranslateService,
) {
this.routerParam.queryParams.subscribe((params) => {
this.submissionId = params.submisssionId;
this.entityName = params.schoolName;
this.allowMultipleAssessemts = params.allowMultipleAssessemts;
});
this.extrasState = this.router.getCurrentNavigation().extras.state;
}
ngOnInit() {
this.networkFlag = this.commonUtilService.networkInfo.isNetworkAvailable;
this._networkSubscription = this.commonUtilService.networkAvailability$.subscribe(
async (available: boolean) => {
this.networkFlag = available;
}
);
this.translate.get(['FRMELEMENTS_MSG_FORM_DOWNLOADING']).subscribe(data => {
this.msgs = data;
})
}
ionViewWillEnter() {
if(this.extrasState){
this.getAssessmentDetails(this.extrasState);
}else{
this.localStorage
.getLocalStorage(this.utils.getAssessmentLocalStorageKey(this.submissionId))
.then((successData) => {
this.getAssessmentDetails(successData);
});
}
this.headerConfig = this.headerService.getDefaultPageConfig();
this.headerConfig.actionButtons = [];
this.headerConfig.showHeader = true;
this.headerConfig.showBurgerMenu = false;
this.headerService.updatePageConfig(this.headerConfig);
}
getAssessmentDetails(successData){
this.entityData = successData;
if(this.submissionId){
this.entityEvidences = this.updateTracker.getLastModifiedInEvidences(
this.entityData['assessment']['evidences'],
this.recentlyUpdatedEntity
);
this.mapCompletedAndTotalQuestions();
this.checkForProgressStatus();
this.localStorage
.getLocalStorage('generalQuestions_' + this.submissionId)
.then((successData) => {
this.generalQuestions = successData;
});
this.fetchDownloaded();
}else{
this.entityEvidences = this.entityData['assessment']['evidences'];
}
}
mapCompletedAndTotalQuestions() {
for (const evidence of this.entityEvidences) {
let totalQuestions = 0;
let completedQuestions = 0;
let sectionLength = evidence.sections.length
let completedSections = 0;
for (const section of evidence.sections) {
totalQuestions = totalQuestions + section.totalQuestions;
completedQuestions = completedQuestions + section.completedQuestions;
if(section.progressStatus === "completed"){
completedSections += 1;
}
}
let percentage = totalQuestions ? (completedQuestions / totalQuestions) * 100 : completedSections ? (completedSections/sectionLength) * 100 : 0;
if (!completedQuestions && !completedSections) {
percentage = 0;
}
evidence.completePercentage = Math.trunc(percentage);
}
}
checkForProgressStatus() {
for (const evidence of this.entityEvidences) {
if (evidence.isSubmitted) {
evidence.progressStatus = 'submitted';
} else if (!evidence.startTime) {
evidence.progressStatus = '';
} else {
evidence.progressStatus = 'completed';
for (const section of evidence.sections) {
if (section.progressStatus === 'inProgress' || !section.progressStatus) {
evidence.progressStatus = 'inProgress';
}
}
}
}
}
navigateToEvidence(index): void {
if (this.entityEvidences[index].startTime) {
this.utils.setCurrentimageFolderName(this.entityEvidences[index].externalId, this.submissionId);
this.router.navigate([RouterLinks.SECTION_LISTING], {
queryParams: {
submisssionId: this.submissionId,
evidenceIndex: index,
schoolName: this.entityName,
},
});
} else {
const entity = { _id: this.submissionId, name: this.entityName };
this.openAction(entity, index);
}
}
async openAction(assessment, evidenceIndex) {
this.utils.setCurrentimageFolderName(this.entityEvidences[evidenceIndex].externalId, assessment._id);
return 'view'
}
async openEvidence(evidenceIndex) {
this.utils.setCurrentimageFolderName(this.entityEvidences[evidenceIndex].externalId, this.submissionId);
this.currentEvidence = this.entityData['assessment']['evidences'][evidenceIndex];
this.evidenceSections = this.currentEvidence['sections'];
this.checkForEvidenceCompletion();
if (this.entityEvidences[evidenceIndex].startTime) {
this.utils.setCurrentimageFolderName(this.entityEvidences[evidenceIndex].externalId, this.submissionId);
this.selectedEvidenceIndex = evidenceIndex;
this.currentEvidence = this.entityData['assessment']['evidences'][this.selectedEvidenceIndex];
this.evidenceSections = this.currentEvidence['sections'];
this.checkForEvidenceCompletion();
} else {
this.selectedEvidenceIndex = evidenceIndex;
this.currentEvidence = this.entityData['assessment']['evidences'][this.selectedEvidenceIndex];
this.evidenceSections = this.currentEvidence['sections'];
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;
}
}
if (this.submissionId) {
this.localStorage.setLocalStorage(this.utils.getAssessmentLocalStorageKey(this.submissionId), this.entityData);
}
}
async goToQuestioner(selectedSection) {
if (!this.evidenceSections[selectedSection].progressStatus && this.submissionId) {
this.evidenceSections[selectedSection].progressStatus = this.currentEvidence.startTime ? 'inProgress' : '';
this.localStorage.setLocalStorage(this.utils.getAssessmentLocalStorageKey(this.submissionId), this.entityData);
}
this.router.navigate([RouterLinks.QUESTIONNAIRE], {
queryParams: {
submisssionId: this.submissionId,
evidenceIndex: this.selectedEvidenceIndex,
sectionIndex: selectedSection,
schoolName: this.entityName,
}, state: this.extrasState //State is using for Template view for Deeplink.
});
}
async fetchDownloaded() {
this.downloadedSubmissionList = await this.observationService.fetchDownloaded();
}
async pushToLocal() {
if (!this.networkFlag) {
this.toast.showMessage("FRMELEMENTS_MSG_FEATURE_USING_OFFLINE", "danger");
return
}
let args = {
title: 'DOWNLOAD_FORM',
yes: 'YES',
no: 'NO',
};
try {
const confirmed = await this.genericPopup.confirmBox(args);
if (!confirmed) return;
this.loader.startLoader(this.msgs['FRMELEMENTS_MSG_FORM_DOWNLOADING'])
await this.observationService.pushToDownloads(this.submissionId);
this.fetchDownloaded();
let successArgs = {
title: 'FRMELEMENTS_MSG_FORM_DOWNLOADED',
yes: 'OKAY',
autoDissmiss: true,
};
this.loader.stopLoader()
await this.genericPopup.confirmBox(successArgs);
} catch {
this.loader.stopLoader()
}
}
notApplicableClick(selectedSectionIndex){
this.evdnsServ.openConfirmation(this.entityData,selectedSectionIndex,this.submissionId)
}
ngOnDestroy() {
if (this._networkSubscription) {
this._networkSubscription.unsubscribe();
}
}
}
<ion-content>
<div class="d-flex flex-ai-center flex-jc-space-between">
<ion-text>
<h4 class="p-15" *ngIf="entityData?.assessment?.pageHeading">
{{ entityData?.assessment?.pageHeading }}
</h4>
<h4 class="p-15" *ngIf="!entityData?.assessment?.pageHeading">Domains</h4>
</ion-text>
<div arrow *ngIf="!downloadedSubmissionList?.includes(submissionId) && !allowMultipleAssessemts && submissionId" class="d-flex flex-ai-center flex-dc mr-15 clr-primary" (click)="$event.stopPropagation(); pushToLocal(submission)">
<ion-icon class="clr-primary" name="arrow-down"></ion-icon>
<span>{{ 'FRMELEMNTS_LBL_DOWNLOAD' | translate }}</span>
</div>
<div arrow *ngIf="downloadedSubmissionList?.includes(submissionId)" class="d-flex flex-ai-center flex-dc mr-15 clr-primary">
<ion-icon class="clr-downloaded-btn" style="color: green" name="checkmark"></ion-icon>
<span>{{ 'FRMELEMNTS_LBL_DOWNLOADED' | translate }}</span>
</div>
</div>
<!-- for Domain/ecm -->
<div *ngFor="let evidence of entityEvidences; let arrIndex = index"
[ngClass]="{ 'restrict': evidence?.notApplicable === true }">
<app-item-list-card [title]="evidence?.name" (click)="openEvidence(arrIndex)" [selectedEvidenceIndex]="selectedEvidenceIndex" [arrIndex]="arrIndex">
<div arrow *ngIf="evidence.progressStatus === 'completed' && !evidence?.notApplicable" class="_completed _flex-box progressWidth ion-float-right">
<progress-bar [progress]="100" class="_full-width"></progress-bar>
</div>
<div arrow *ngIf="!evidence.progressStatus && !evidence?.notApplicable && !isIos" class="_flex-box">
<ion-icon size="small" name="caret-down-circle" class="_progressIcon ion-float-right ion-margin-right">
</ion-icon>
</div>
<div arrow *ngIf="evidence.progressStatus === 'inProgress' && !evidence?.notApplicable" class="_inProgress _flex-box progressWidth ion-float-right">
<progress-bar [progress]="evidence?.completePercentage" class="_full-width"></progress-bar>
</div>
<div arrow *ngIf="evidence.progressStatus === 'submitted' && !evidence?.notApplicable" class="_submitted _flex-box flex-dc">
<div>
<progress-bar [progress]="100" class="_full-width"></progress-bar>
</div>
<div class="f11">Completed</div>
</div>
<div arrow *ngIf="evidence?.notApplicable" class="_na _flex-box _float-right">
{{ 'FRMELEMNTS_LBL_NOT_APPLICABLE' | translate }}
<ion-icon name="alert" class="_progressIcon ion-margin-left"></ion-icon>
</div>
</app-item-list-card>
<!-- for section/critera -->
<ion-card *ngIf="!evidence?.notApplicable" style="border-radius: initial !important; margin-top: 0px;">
<div *ngIf="selectedEvidenceIndex == arrIndex">
<div *ngIf="!evidence.progressStatus && !evidence?.notApplicable" class="naBtnDiv">
<ion-button class="naBtn" (click)="notApplicableClick(arrIndex)" fill="outline" size="small" shape="round">
<span>{{ 'FRMELEMNTS_LBL_NOT_APPLICABLE' | translate | titlecase }}</span>
</ion-button>
</div>
<div *ngFor="let section of evidence.sections; let selectedSection = index">
<ion-item lines="none" class="p-12" style="--background: var(--app-white-background);" (click)="goToQuestioner(selectedSection)" *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="document-text" class="margin-right mr-5"></ion-icon>
<span>
{{ section?.name }}
</span>
</div>
<span *ngIf="section.progressStatus === 'completed'" class="_completed _flex-box">
{{ 'COMPLETED' | translate }}
<ion-icon name="checkmark-circle" class="_progressIcon" margin-left> </ion-icon>
</span>
<span *ngIf="!section.progressStatus && !isIos" class="_flex-box">
<ion-icon name="arrow-forward" class="_progressIcon" margin-left></ion-icon>
</span>
<span *ngIf="section.progressStatus === 'inProgress'" class="_inProgress _flex-box" style="font-size: 11">
{{ 'FRMELEMNTS_LBL_IN_PROGRESS' | translate }}
<ion-icon name="contrast" class="_progressIcon" margin-left></ion-icon>
</span>
<span *ngIf="section.progressStatus === 'submitted'" class="_submitted _flex-box">
{{ 'FRMELEMNTS_LBL_SUBMITTTED' | translate }}
<ion-icon name="cloud-done" class="_progressIcon" margin-left></ion-icon>
</span>
</div>
</ion-item>
</div>
</div>
</ion-card>
</div>
</ion-content>
./domain-ecm-lsiting.component.scss
._completed,
._inProgress,
._submitted,
._na {
font-size: 0.688rem !important;
}
._progressIcon {
font-size: 0.688rem !important;
padding-left: 3px;
}
.restrict {
pointer-events: none;
}
.naBtnDiv {
display: flex;
justify-content: flex-end;
margin-right: 15px;
}
.naBtn {
--background: var(--app-white) !important;
--color: var(--app-primary) !important;
--border-color: var(--app-white) !important;
--box-shadow: var(--button-style-shadow) !important;
margin-top: 10px;
text-transform: none;
}