src/app/manage-learn/observation/observation-submission/observation-submission.component.ts
OnInit
selector | app-observation-submission |
styleUrls | ./observation-submission.component.scss |
templateUrl | ./observation-submission.component.html |
Properties |
|
Methods |
|
constructor(headerService: AppHeaderService, observationService: ObservationService, router: Router, localStorage: LocalStorageService, utils: UtilsService, evdnsServ: EvidenceService, popoverCtrl: PopoverController, loader: LoaderService, translate: TranslateService, alertCntrl: AlertController, routerParam: ActivatedRoute, assessmentService: AssessmentApiService, modalCtrl: ModalController, commonUtilService: CommonUtilService, storage: Storage, toast: ToastService, genericPopup: GenericPopUpService)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters :
|
Async deleteSubmission | ||||
deleteSubmission(submissionId)
|
||||
Parameters :
Returns :
any
|
Async ediSubmissionName | ||||||
ediSubmissionName(data, i)
|
||||||
Parameters :
Returns :
any
|
entityActions | ||||
entityActions(e)
|
||||
Parameters :
Returns :
void
|
Async fetchDownloaded |
fetchDownloaded()
|
Returns :
any
|
getAssessmentDetails | ||||
getAssessmentDetails(submission)
|
||||
Parameters :
Returns :
void
|
getAssessmentDetailsApi | ||||
getAssessmentDetailsApi(submission)
|
||||
Parameters :
Returns :
void
|
getLocalData |
getLocalData()
|
Returns :
void
|
Async getProgramFromStorage | ||||||
getProgramFromStorage(isDeleted)
|
||||||
Parameters :
Returns :
any
|
goToEcm | ||||
goToEcm(submission)
|
||||
Parameters :
Returns :
void
|
ionViewWillEnter |
ionViewWillEnter()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
Async observeAgain |
observeAgain()
|
Returns :
any
|
Async openAction | ||||||||
openAction(assessment, aseessmemtData, evidenceIndex)
|
||||||||
Parameters :
Returns :
any
|
Async openActionMenu | ||||||||
openActionMenu(event, submission, index)
|
||||||||
Parameters :
Returns :
any
|
Async openEntityReportMenu | ||||
openEntityReportMenu(event)
|
||||
Parameters :
Returns :
any
|
Async openInfo | ||||
openInfo(submission)
|
||||
Parameters :
Returns :
any
|
Async openMenu | ||||||||
openMenu(event, submission, index)
|
||||||||
Parameters :
Returns :
any
|
Async pushToLocal | ||||
pushToLocal(submission)
|
||||
Parameters :
Returns :
any
|
splitCompletedAndInprogressObservations |
splitCompletedAndInprogressObservations()
|
Returns :
void
|
tabChange | ||||
tabChange(value)
|
||||
Parameters :
Returns :
void
|
viewEntityReports |
viewEntityReports()
|
Returns :
void
|
Private Optional _networkSubscription |
Type : Subscription
|
Public commonUtilService |
Type : CommonUtilService
|
completedObservations |
Type : []
|
Default value : []
|
currentTab |
Type : string
|
Default value : "all"
|
disableObserveAgain |
Type : boolean
|
Default value : false
|
downloadedSubmissionList |
Type : any
|
Default value : []
|
entityId |
Type : any
|
entityName |
Type : any
|
generatedKey |
Public genericPopup |
Type : GenericPopUpService
|
headerConfig |
Type : object
|
Default value : {
showHeader: true,
showBurgerMenu: false,
actionButtons: []
}
|
inProgressObservations |
Type : []
|
Default value : []
|
msgs |
Type : any
|
networkFlag |
observationId |
Type : any
|
programId |
Type : any
|
showActionsheet |
Type : boolean
|
showEntityActionsheet |
Type : boolean
|
solutionId |
Type : any
|
Public storage |
Type : Storage
|
submissionIdArr |
Type : any
|
submissionList |
Type : any
|
submissions |
Type : any[]
|
Public toast |
Type : ToastService
|
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { AppHeaderService, CommonUtilService } from "@app/services";
import {
AlertController,
ModalController,
PopoverController
} from "@ionic/angular";
import { ObservationService } from "../observation.service";
import { RouterLinks } from "@app/app/app.constant";
import {
LoaderService,
LocalStorageService,
UtilsService,
ToastService
} from "../../core";
import { storageKeys } from "../../storageKeys";
import { EvidenceService } from "../../core/services/evidence.service";
import { SubmissionActionsComponent } from "../../shared/components/submission-actions/submission-actions.component";
import { TranslateService } from "@ngx-translate/core";
import { urlConstants } from "../../core/constants/urlConstants";
import { AssessmentApiService } from "../../core/services/assessment-api.service";
import { ViewDetailComponent } from "../../shared/components/view-detail/view-detail.component";
import { Subscription } from "rxjs";
import { Storage } from "@ionic/storage";
import { GenericPopUpService } from "../../shared";
@Component({
selector: "app-observation-submission",
templateUrl: "./observation-submission.component.html",
styleUrls: ["./observation-submission.component.scss"]
})
export class ObservationSubmissionComponent implements OnInit {
headerConfig = {
showHeader: true,
showBurgerMenu: false,
actionButtons: []
};
submissionList: any;
inProgressObservations = [];
completedObservations = [];
submissions: any[];
currentTab = "all";
showEntityActionsheet: boolean;
showActionsheet: boolean;
submissionIdArr: any;
observationId: any;
solutionId: any;
programId: any;
entityId: any;
entityName: any;
disableObserveAgain: boolean = false;
private _networkSubscription?: Subscription;
networkFlag;
generatedKey;
downloadedSubmissionList: any = [];
msgs:any
constructor(
private headerService: AppHeaderService,
private observationService: ObservationService,
private router: Router,
private localStorage: LocalStorageService,
private utils: UtilsService,
private evdnsServ: EvidenceService,
private popoverCtrl: PopoverController,
private loader: LoaderService,
private translate: TranslateService,
private alertCntrl: AlertController,
private routerParam: ActivatedRoute,
private assessmentService: AssessmentApiService,
private modalCtrl: ModalController,
public commonUtilService: CommonUtilService,
public storage: Storage,
public toast: ToastService,
public genericPopup: GenericPopUpService
) {
this.routerParam.queryParams.subscribe(params => {
this.observationId = params.observationId;
this.solutionId = params.solutionId;
this.programId = params.programId;
this.entityId = params.entityId;
this.entityName = params.entityName;
this.disableObserveAgain = params.disableObserveAgain == "true";
let data = {
observationId: this.observationId,
entityId: this.entityId
};
this.generatedKey = this.utils.getUniqueKey(data,storageKeys.submissionsList);
});
}
ngOnInit() {
this._networkSubscription = this.commonUtilService.networkAvailability$.subscribe(
async (available: boolean) => {
this.networkFlag = available;
this.networkFlag ? this.getProgramFromStorage() : this.getLocalData();
}
);
this.fetchDownloaded();
this.translate.get(['FRMELEMENTS_MSG_FORM_DOWNLOADING']).subscribe(data => {
this.msgs = data;
})
}
getLocalData() {
this.storage.get(this.generatedKey).then(data => {
this.submissionList = data;
this.splitCompletedAndInprogressObservations();
this.tabChange(this.currentTab ? this.currentTab : "all");
});
}
ionViewWillEnter() {
this.headerConfig = this.headerService.getDefaultPageConfig();
this.headerConfig.actionButtons = [];
this.headerConfig.showHeader = true;
this.headerConfig.showBurgerMenu = false;
this.headerService.updatePageConfig(this.headerConfig);
this.networkFlag = this.commonUtilService.networkInfo.isNetworkAvailable;
this.networkFlag ? this.getProgramFromStorage() : this.getLocalData();
}
async getProgramFromStorage(isDeleted = false) {
let payload = await this.utils.getProfileInfo();
const config = {
url:
urlConstants.API_URLS.GET_OBSERVATION_SUBMISSIONS +
`${this.observationId}?entityId=${this.entityId}`,
payload: payload
};
this.loader.startLoader();
this.assessmentService.post(config).subscribe(
async success => {
if (success.result && success.result.length == 0) {
if (isDeleted) {
this.loader.stopLoader();
history.go(-1);
return;
}
let event = {
entityId: this.entityId,
observationId: this.observationId,
submission: {
submissionNumber: 1
}
};
await this.observationService
.getAssessmentDetailsForObservation(event)
.then(
res => {
this.loader.stopLoader();
this.getProgramFromStorage();
},
err => {
this.loader.stopLoader();
}
);
}
this.loader.stopLoader();
this.submissionList = success.result;
this.storage.set(this.generatedKey, this.submissionList);
this.splitCompletedAndInprogressObservations();
this.tabChange(this.currentTab ? this.currentTab : "all");
},
error => {
console.log(error);
}
);
}
async fetchDownloaded() {
this.downloadedSubmissionList = await this.observationService.fetchDownloaded();
}
splitCompletedAndInprogressObservations() {
this.completedObservations = [];
this.inProgressObservations = [];
for (const submission of this.submissionList) {
submission.status === "completed"
? this.completedObservations.push(submission)
: this.inProgressObservations.push(submission);
}
}
tabChange(value) {
this.submissions = [];
this.currentTab = value;
switch (value) {
case "inProgress":
this.submissions = this.inProgressObservations;
break;
case "completed":
this.submissions = this.completedObservations;
break;
case "all":
this.submissions = this.submissions.concat(
this.inProgressObservations,
this.completedObservations
);
break;
default:
this.submissions = this.submissions.concat(
this.inProgressObservations,
this.completedObservations
);
}
}
getAssessmentDetails(submission) {
if (this.networkFlag) {
this.showActionsheet = false;
this.showEntityActionsheet = false;
this.localStorage
.getLocalStorage(
this.utils.getAssessmentLocalStorageKey(submission._id)
)
.then(data => {
if (!data) {
this.getAssessmentDetailsApi(submission);
} else {
this.goToEcm(submission);
}
})
.catch(error => {
this.getAssessmentDetailsApi(submission);
});
} else {
this.toast.showMessage("FRMELEMENTS_MSG_FEATURE_USING_OFFLINE", "danger");
}
}
getAssessmentDetailsApi(submission) {
let event = {
submission: submission,
entityId: this.entityId,
observationId: this.observationId
};
this.observationService
.getAssessmentDetailsForObservation(event)
.then(async programList => {
await this.getProgramFromStorage();
this.goToEcm(submission);
})
.catch(error => {});
}
async pushToLocal(submission) {
if (!this.networkFlag) {
this.toast.showMessage("FRMELEMENTS_MSG_FEATURE_USING_OFFLINE", "danger");
return
}
try {
let args = {
title: 'DOWNLOAD_FORM',
yes: 'YES',
no: 'NO',
};
const confirmed = await this.genericPopup.confirmBox(args);
if (!confirmed) return;
this.loader.startLoader(this.msgs['FRMELEMENTS_MSG_FORM_DOWNLOADING'])
let event = {
submission: submission,
entityId: this.entityId,
observationId: this.observationId,
};
let submissionId = await this.observationService.getAssessmentDetailsForObservation(event);
await this.observationService.pushToDownloads(submissionId);
this.fetchDownloaded();
let argsForSuccess = {
title: 'FRMELEMENTS_MSG_FORM_DOWNLOADED',
yes: 'OKAY',
autoDissmiss: true,
};
this.loader.stopLoader()
await this.genericPopup.confirmBox(argsForSuccess);
} catch {
this.loader.stopLoader()
}
}
goToEcm(submission) {
let submissionId = submission._id;
let heading = this.entityName;
this.localStorage
.getLocalStorage(this.utils.getAssessmentLocalStorageKey(submissionId))
.then(successData => {
if (
successData.assessment.evidences.length > 1 ||
successData.assessment.evidences[0].sections.length > 1 ||
(submission.criteriaLevelReport && submission.isRubricDriven)
) {
this.router.navigate([RouterLinks.DOMAIN_ECM_LISTING], {
queryParams: {
submisssionId: submissionId,
schoolName: heading,
allowMultipleAssessemts:true
}
});
} else {
if (successData.assessment.evidences[0].startTime) {
this.utils.setCurrentimageFolderName(
successData.assessment.evidences[0].externalId,
submissionId
);
this.router.navigate([RouterLinks.QUESTIONNAIRE], {
queryParams: {
submisssionId: submissionId,
evidenceIndex: 0,
sectionIndex: 0,
schoolName: this.entityName
}
});
} else {
const assessment = { _id: submissionId, name: heading };
this.openAction(assessment, successData, 0);
}
}
})
.catch(error => {
this.getAssessmentDetailsApi(submission);
});
}
async openAction(assessment, aseessmemtData, evidenceIndex) {
this.utils.setCurrentimageFolderName(
aseessmemtData.assessment.evidences[evidenceIndex].externalId,
assessment._id
);
this.router.navigate([RouterLinks.QUESTIONNAIRE], {
queryParams: {
submisssionId: assessment._id,
evidenceIndex: 0,
sectionIndex: 0,
schoolName: this.entityName
}
});
}
async openMenu(event, submission, index) {
if (!this.networkFlag) {
this.toast.showMessage("FRMELEMENTS_MSG_FEATURE_USING_OFFLINE", "danger");
} else {
if (submission.criteriaLevelReport && submission.isRubricDriven) {
this.router.navigate([RouterLinks.GENERIC_REPORT], {
state: {
scores: true,
observation: true,
entityId: submission.entityId,
entityType: submission.entityType,
observationId: submission.observationId,
submissionId: submission._id
}
});
return;
}
if (submission.ratingCompletedAt) {
/* no need to show menu now directly show the score report */
this.router.navigate([RouterLinks.GENERIC_REPORT], {
state: {
scores: true,
observation: true,
criteriaWise: false,
submissionId: submission._id,
entityType: submission.entityType,
filter: { questionId: [] }
}
});
} else {
this.router.navigate([RouterLinks.GENERIC_REPORT], {
state: {
scores: false,
observation: true,
criteriaWise: false,
submissionId: submission._id,
entityType: submission.entityType,
filter: { questionId: [] }
}
});
}
}
}
// entity actions
entityActions(e) {
if (!this.networkFlag) {
this.toast.showMessage("FRMELEMENTS_MSG_FEATURE_USING_OFFLINE", "danger");
} else {
let submission = this.submissions[0];
if (submission.criteriaLevelReport && submission.isRubricDriven) {
this.router.navigate([RouterLinks.GENERIC_REPORT], {
state: {
scores: true,
observation: true,
entityId: submission.entityId,
entityType: submission.entityType,
observationId: submission.observationId
}
});
return;
}
let noScore: boolean = true;
this.submissions.forEach(submission => {
submission.showActionsheet = false;
if (submission.ratingCompletedAt) {
noScore = false;
}
});
if (noScore) {
this.viewEntityReports();
} else {
this.openEntityReportMenu(e);
}
}
}
// Menu for Entity reports
async openEntityReportMenu(event) {
let submission = this.submissions[0];
/* no need to show menu now directly show the score report */
this.router.navigate([RouterLinks.GENERIC_REPORT], {
state: {
scores: true,
observation: true,
criteriaWise: false,
entityId: submission.entityId,
entityType: submission.entityType,
observationId: submission.observationId,
filter: { questionId: [] }
}
});
}
viewEntityReports() {
let submission = this.submissions[0];
this.showEntityActionsheet = false;
this.showActionsheet = false;
this.router.navigate([RouterLinks.GENERIC_REPORT], {
state: {
scores: false,
observation: true,
criteriaWise: false,
entityId: submission.entityId,
entityType: submission.entityType,
observationId: submission.observationId,
filter: { questionId: [] }
}
});
}
// Actions on submissions
async openActionMenu(event, submission, index) {
submission.entityName = this.entityName;
let popover = await this.popoverCtrl.create({
cssClass:'central-alert',
component: SubmissionActionsComponent,
componentProps: {
submission: submission
},
event: event
});
popover.onDidDismiss().then((data: any) => {
if (data.data && data.data.action === "update") {
const payload = {
submissionId: submission._id,
title: data.data.name
};
this.ediSubmissionName(payload, index);
} else if (data.data && data.data.action === "delete") {
this.deleteSubmission(submission._id);
}
});
await popover.present();
}
async deleteSubmission(submissionId) {
if (!this.networkFlag) {
this.toast.showMessage("FRMELEMENTS_MSG_FEATURE_USING_OFFLINE", "danger");
return
}
let translateObject;
this.translate
.get([
"FRMELEMNTS_LBL_CONFIRM",
"FRMELEMNTS_MSG_DELETE_SUBMISSION",
"FRMELEMNTS_LBL_YES",
"FRMELEMNTS_LBL_NO"
])
.subscribe(translations => {
translateObject = translations;
});
let alert = await this.alertCntrl.create({
header: translateObject["FRMELEMNTS_LBL_CONFIRM"],
message: translateObject["FRMELEMNTS_MSG_DELETE_SUBMISSION"],
cssClass:'central-alert',
buttons: [
{
text: translateObject["FRMELEMNTS_LBL_NO"],
role: "cancel",
handler: () => {}
},
{
text: translateObject["FRMELEMNTS_LBL_YES"],
handler: async () => {
let payload = await this.utils.getProfileInfo();
const config = {
url:
urlConstants.API_URLS.OBSERVATION_SUBMISSION_UPDATE +
`${submissionId}`,
payload: payload
};
this.loader.startLoader();
this.assessmentService.delete(config).subscribe(
success => {
this.loader.stopLoader();
if (success && success.status == 200) {
this.getProgramFromStorage(true);
}
},
error => {
this.loader.stopLoader();
}
);
}
}
]
});
alert.present();
}
async ediSubmissionName(data, i) {
let payload = await this.utils.getProfileInfo();
payload.title = data.title;
const config = {
url:
urlConstants.API_URLS.OBSERVATION_SUBMISSION_UPDATE +
`${data.submissionId}`,
payload: payload
};
this.assessmentService.post(config).subscribe(
success => {
if (success && success.status == 200) {
this.getProgramFromStorage();
}
},
error => {}
);
}
async observeAgain() {
if (!this.networkFlag) {
this.toast.showMessage("FRMELEMENTS_MSG_FEATURE_USING_OFFLINE", "danger");
} else {
this.loader.startLoader("Creating an Observation");
const entityId = this.entityId;
const observationId = this.observationId;
let payload = await this.utils.getProfileInfo();
const config = {
url:
urlConstants.API_URLS.OBSERVATION_SUBMISSION_CREATE +
`${observationId}?entityId=${entityId}`,
payload: payload
};
this.assessmentService.post(config).subscribe(
success => {
this.loader.stopLoader();
if (success && success.status == 200) {
this.getProgramFromStorage();
}
},
error => {
this.loader.stopLoader();
}
);
}
}
//open info menu
async openInfo(submission) {
submission.entityName = this.entityName;
const modal = await this.modalCtrl.create({
component: ViewDetailComponent,
componentProps: {
submission: submission
}
});
await modal.present();
}
ngOnDestroy() {
if (this._networkSubscription) {
this._networkSubscription.unsubscribe();
}
}
}
<ion-content fullscreen>
<ion-card class="card-box-shadow">
<ion-card-content class="card-content-bottom-0 card-content-top-0">
<ion-segment class="d-flex" [(ngModel)]="currentTab" (ionChange)="tabChange($event.detail.value)">
<ion-segment-button value="all" class="flex-5">
<ion-label class="font-12 text-transform-none title">{{ 'ALL' | translate }}</ion-label>
</ion-segment-button>
<div class="hr-div">
<hr class="hr-height" />
</div>
<ion-segment-button value="inProgress" class="flex-5">
<ion-label class="font-12 text-transform-none title">{{
'FRMELEMNTS_LBL_IN_PROGRESS' | translate
}}</ion-label>
</ion-segment-button>
<div class="hr-div">
<hr class="hr-height" />
</div>
<ion-segment-button value="completed" class="flex-5">
<ion-label class="font-12 text-transform-none title">{{ 'COMPLETED' | translate }}</ion-label>
</ion-segment-button>
</ion-segment>
</ion-card-content>
</ion-card>
<div
*ngFor="let submission of submissions"
(click)="goToEcm(submission)"
>
<app-item-list-card [title]="submission?.title" subTitle="{{ submission?.createdAt | date }}" [ellipsis]="true">
<div arrow *ngIf="!downloadedSubmissionList?.includes(submission._id)" class="d-flex flex-dc margin-r-10"
(click)="$event.stopPropagation(); pushToLocal(submission)">
<ion-icon class="mg-popup-btn-icon" name="arrow-down"></ion-icon>
<span>{{'FRMELEMNTS_LBL_DOWNLOAD' | translate}}</span>
</div>
<div arrow *ngIf="downloadedSubmissionList?.includes(submission._id)" class="d-flex flex-dc margin-r-10">
<ion-icon class="mg-popup-btn-icon" style="color:green" name="checkmark"></ion-icon>
<span>{{'FRMELEMNTS_LBL_DOWNLOADED' | translate}}</span>
</div>
<ion-icon
class="mg-popup-btn-icon fs-1-143"
name="ellipsis-vertical-outline"
arrow
*ngIf="submission.status !== 'completed' && submission?.status !== 'ratingPending'"
(click)="$event.stopPropagation(); openActionMenu($event, submission, i)"
></ion-icon>
<ion-button
report
round class="custom-btn-txt-transform-none"
*ngIf="submission?.status === 'completed' || submission?.status === 'ratingPending'"
(click)="$event.stopPropagation(); openMenu($event, submission, i)"
>
{{ 'FRMELEMNTS_LBL_REPORTS' | translate }}
</ion-button>
<ion-icon
padding-left
info
name="information-circle"
*ngIf="submission?.status === 'completed' || submission?.status === 'ratingPending'"
(click)="$event.stopPropagation(); openInfo(submission)"
></ion-icon>
</app-item-list-card>
</div>
<app-no-data *ngIf="!submissions?.length"></app-no-data>
</ion-content>
<ion-footer no-shadow>
<ion-toolbar position="bottom">
<ion-row>
<ion-col *ngIf="!disableObserveAgain">
<ion-button ion-button full (click)="observeAgain()" class="footerButton w-100 custom-btn-txt-transform-none">
{{ 'FRMELEMNTS_LBL_OBSERVE_AGAIN' | translate }}
</ion-button>
</ion-col>
<ion-col>
<ion-button
ion-button
full
(click)="entityActions($event)"
class="footerButton w-100 custom-btn-txt-transform-none"
[disabled]="!submissions?.length"
>
{{ 'FRMELEMNTS_LBL_VIEW_ENTITY_REPORT' | translate }}
</ion-button>
</ion-col>
</ion-row>
</ion-toolbar>
</ion-footer>
./observation-submission.component.scss
@import "src/assets/styles/_custom-mixins";
@import "src/assets/styles/variables";
@import "src/assets/styles/_variables.scss";
:host {
.card-content-bottom-0 {
padding-bottom: 0px !important;
}
.card-content-top-0 {
padding-top: 0px !important;
}
.font-12 {
font-size: 0.75rem !important;
}
.text-transform-none {
text-transform: none !important;
}
}
.card-box-shadow {
box-shadow: 0px 5px 5px 3px map-get($colors, light_gray_dd);
}
.title {
font-size: 1rem;
font-weight: bold;
color: #{$blue};
}
.margin-r-10{
margin-right:10px;
}
.mg-popup-btn-icon{
font-size: $font-size-base;
margin: auto;
color: $primary-800;
}