Skip to content

Commit

Permalink
Merge pull request #2310 from vishnubansaltarento/mtf-issue-fix
Browse files Browse the repository at this point in the history
Mtf issue fix
  • Loading branch information
vishnubansaltarento authored Jul 14, 2024
2 parents deb4b65 + f0aee47 commit f34c58f
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,24 @@
</div>
<div>
<div class="ml-5 start-assessment-cta-standalone block md:hidden" *ngIf="selectedAssessmentCompatibilityLevel >= 6">
<button [disabled]="!consentGiven ? 'disabled': null" *ngIf="canAttempt?.attemptsMade < canAttempt?.attemptsAllowed || forPreview" [class.spinner]="loading" (click)="overviewed('start')" [ngClass]="consentGiven ? 'bg-blue-800 text-white' : 'secondary-standalone text-standalone-black'" class=" text-sm font-semibold py-3 px-5 rounded-full border-none cursor-pointer tracking-wide">
<button [disabled]="!consentGiven ? 'disabled': null" *ngIf="canAttempt?.attemptsMade < canAttempt?.attemptsAllowed || forPreview || questionTYP.PRACTICE_RESOURCE == primaryCategory" [class.spinner]="loading" (click)="overviewed('start')" [ngClass]="consentGiven ? 'bg-blue-800 text-white' : 'secondary-standalone text-standalone-black'" class=" text-sm font-semibold py-3 px-5 rounded-full border-none cursor-pointer tracking-wide">
<span class="padding-xs" i18n>{{'playerbrief.startAssessment' | translate}}</span>
</button>
<mat-hint class="mat-title" *ngIf="canAttempt?.attemptsMade >= canAttempt?.attemptsAllowed && !forPreview">{{'playerbrief.maxAllowedRetake' | translate}}</mat-hint>
<mat-hint class="mat-title" *ngIf="canAttempt?.attemptsMade >= canAttempt?.attemptsAllowed && !forPreview && questionTYP.FINAL_ASSESSMENT === primaryCategory">{{'playerbrief.maxAllowedRetake' | translate}}</mat-hint>
</div>
</div>
</div>
<div class="start-assessment-cta hidden md:block" *ngIf="selectedAssessmentCompatibilityLevel >= 6">
<button [disabled]="!consentGiven ? 'disabled': null" *ngIf="canAttempt?.attemptsMade < canAttempt?.attemptsAllowed || forPreview" [class.spinner]="loading" (click)="overviewed('start')" [ngClass]="consentGiven ? 'bg-blue-800 text-white' : 'secondary-standalone text-standalone-black'" class="text-sm font-semibold py-3 px-5 rounded-full border-none cursor-pointer tracking-wide">
<button [disabled]="!consentGiven ? 'disabled': null" *ngIf="canAttempt?.attemptsMade < canAttempt?.attemptsAllowed || forPreview || questionTYP.PRACTICE_RESOURCE == primaryCategory" [class.spinner]="loading" (click)="overviewed('start')" [ngClass]="consentGiven ? 'bg-blue-800 text-white' : 'secondary-standalone text-standalone-black'" class="text-sm font-semibold py-3 px-5 rounded-full border-none cursor-pointer tracking-wide">
<span class="padding-xs" i18n>{{'playerbrief.startAssessment' | translate}}</span>
</button>
<mat-hint class="mat-title" *ngIf="canAttempt?.attemptsMade >= canAttempt?.attemptsAllowed && !forPreview">{{'playerbrief.maxAllowedRetake' | translate}}</mat-hint>
<mat-hint class="mat-title" *ngIf="canAttempt?.attemptsMade >= canAttempt?.attemptsAllowed && !forPreview && questionTYP.FINAL_ASSESSMENT === primaryCategory">{{'playerbrief.maxAllowedRetake' | translate}}</mat-hint>
</div>
<div class="start-assessment-cta hidden md:block" *ngIf="selectedAssessmentCompatibilityLevel < 6">
<button *ngIf="canAttempt?.attemptsMade < canAttempt?.attemptsAllowed || forPreview" [class.spinner]="loading" [disabled]="loading" (click)="overviewed('start')" class="bg-blue-800 text-white text-sm font-semibold py-3 px-5 rounded-full border-none cursor-pointer tracking-wide">
<button *ngIf="canAttempt?.attemptsMade < canAttempt?.attemptsAllowed || forPreview || questionTYP.PRACTICE_RESOURCE == primaryCategory" [class.spinner]="loading" [disabled]="loading" (click)="overviewed('start')" class="bg-blue-800 text-white text-sm font-semibold py-3 px-5 rounded-full border-none cursor-pointer tracking-wide">
<span class="padding-xs" i18n>{{'playerbrief.startAssessment' | translate}}</span>
</button>
<mat-hint class="mat-title" *ngIf="canAttempt?.attemptsMade >= canAttempt?.attemptsAllowed && !forPreview">{{'playerbrief.maxAllowedRetake' | translate}}</mat-hint>
<mat-hint class="mat-title" *ngIf="canAttempt?.attemptsMade >= canAttempt?.attemptsAllowed && !forPreview && questionTYP.FINAL_ASSESSMENT === primaryCategory">{{'playerbrief.maxAllowedRetake' | translate}}</mat-hint>
</div>

</div>
Expand Down Expand Up @@ -162,10 +162,10 @@ <h2 class="summary-label">{{ 'practiceoverview.summary' | translate }}</h2>

</div>
<div class="start-assessment-cta block md:hidden" *ngIf="selectedAssessmentCompatibilityLevel < 6">
<button *ngIf="canAttempt?.attemptsMade < canAttempt?.attemptsAllowed" [class.spinner]="loading" [disabled]="loading" (click)="overviewed('start')" class="bg-blue-800 text-sm font-semibold text-white py-3 px-5 rounded-full border-none cursor-pointer tracking-wide">
<button *ngIf="canAttempt?.attemptsMade < canAttempt?.attemptsAllowed || questionTYP.PRACTICE_RESOURCE == primaryCategory" [class.spinner]="loading" [disabled]="loading" (click)="overviewed('start')" class="bg-blue-800 text-sm font-semibold text-white py-3 px-5 rounded-full border-none cursor-pointer tracking-wide">
<span class="padding-xs" i18n>{{'playerbrief.startAssessment' | translate}}</span>
</button>
<mat-hint class="mat-title" *ngIf="canAttempt?.attemptsMade >= canAttempt?.attemptsAllowed">{{'playerbrief.maxAllowedRetake' | translate}}</mat-hint>
<mat-hint class="mat-title" *ngIf="canAttempt?.attemptsMade >= canAttempt?.attemptsAllowed && questionTYP.FINAL_ASSESSMENT === primaryCategory">{{'playerbrief.maxAllowedRetake' | translate}}</mat-hint>
</div>

<ng-template #detail let-icon="icon" let-text="text">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ export class OverviewComponent implements OnInit, OnChanges, OnDestroy {

ngOnChanges() {
if (!this.forPreview) {
if (this.canAttempt && (this.canAttempt.attemptsMade >= this.canAttempt.attemptsAllowed)) {
if (this.canAttempt && (this.canAttempt.attemptsMade >= this.canAttempt.attemptsAllowed) &&
this.questionTYP.FINAL_ASSESSMENT === this.primaryCategory) {
if (!this.maxAttempPopup) {
this.showAssessmentPopup()
}

}
}

Expand Down
136 changes: 93 additions & 43 deletions project/ws/viewer/src/lib/plugins/practice/practice.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,17 @@ export class PracticeComponent implements OnInit, OnChanges, OnDestroy {
responseQ.push(ftb)
break
case 'mtf':
let optionAll:any = []
optionAll = _.compact(_.map(sq.options, (_o: any) => {
if (_o.userSelected && this.questionAnswerHash[sq.questionId]) {
return {
index: (_o.optionId).toString(),
selectedAnswer: _o.response,
} as NSPractice.IResponseOptions
}
return {}

}))
const mtf: NSPractice.IMCQ_MTF = {
identifier: sq.questionId,
mimeType: NsContent.EMimeTypes.QUESTION,
Expand All @@ -1340,19 +1351,7 @@ export class PracticeComponent implements OnInit, OnChanges, OnDestroy {
timeTaken: timeSpent.toString(),
timeSpent: timeSpent.toString(),
editorState: {
options: _.compact(_.map(sq.options, (_o: NSPractice.IOption) => {
if (_o.userSelected) {
return {
index: (_o.optionId).toString(),
selectedAnswer: _o.response,
} as NSPractice.IResponseOptions
}
return {
index: (_o.optionId).toString(),
selectedAnswer: _o.response,
} as NSPractice.IResponseOptions

})),
options: optionAll.filter((o:any) => { return o.hasOwnProperty('index'); }).length > 0 ? optionAll : [],
},
}
responseQ.push(mtf)
Expand Down Expand Up @@ -1406,28 +1405,51 @@ export class PracticeComponent implements OnInit, OnChanges, OnDestroy {
} else {
this.viewState = 'answer'
}
if (this.selectedAssessmentCompatibilityLevel < 6) {
const quizV4Res: any = await this.quizSvc.submitQuizV4(this.generateRequest).toPromise().catch(_error => {})
if (quizV4Res && quizV4Res.params && quizV4Res.params.status.toLowerCase() === 'success') {
if (quizV4Res.result.primaryCategory === 'Course Assessment') {
setTimeout(() => {
this.getQuizResult()
}, environment.quizResultTimeout)
} else if (quizV4Res.result.primaryCategory === 'Practice Question Set') {
this.assignQuizResult(quizV4Res.result)
}
}
} else {
const quizV4Res: any = await this.quizSvc.submitQuizV5(this.generateRequest).toPromise().catch(_error => {})
if (quizV4Res && quizV4Res.params && quizV4Res.params.status.toLowerCase() === 'success') {
if (quizV4Res.result.primaryCategory === 'Course Assessment') {
setTimeout(() => {
this.getQuizResult()
}, environment.quizResultTimeout)
} else if (quizV4Res.result.primaryCategory === 'Practice Question Set') {
this.assignQuizResult(quizV4Res.result)
}

let allPromiseResolvedCount = 0
if(this.paperSections && this.paperSections.length) {
for(let i =0 ; i< this.paperSections.length;i++) {
let section = this.paperSections[i];
const lst = _.chunk(section.childNodes || [], 1000)
const prom: any[] = []
_.each(lst, l => {
prom.push(this.getMultiQuestions(l))
})
Promise.all(prom).then(qqr => {
console.log('qqr', qqr)
allPromiseResolvedCount++;
const question = { questions: _.flatten(_.map(qqr, 'result.questions')) }
const codes = _.compact(_.map(this.quizJson.questions, 'section') || [])
// console.log(this.quizSvc.secAttempted.value)
_.eachRight(question.questions, q => {
// const qHtml = document.createElement('div')
// qHtml.innerHTML = q.editorState.question
if (codes.indexOf(section.identifier) === -1) {
this.quizJson.questions.push({
section: section.identifier,
question: q.body, // qHtml.textContent || qHtml.innerText || '',
multiSelection: ((q.qType || '').toLowerCase() === 'mcq-mca' ? true : false),
questionType: (q.qType || '').toLowerCase(),
questionId: q.identifier,
instructions: null,
options: this.getOptions(q),
editorState: q.editorState,
questionLevel: q.questionLevel,
marks: q.totalMarks,
rhsChoices: this.getRhsValue(q),
})
}
})


if(this.paperSections && this.paperSections.length === allPromiseResolvedCount) {
// console.log('this.quizJson',this.quizJson)
// console.log('this.generateRequest',this.generateRequest)
this.submitAfterAllPromiseResolved();
}
})
}

}

// this.quizSvc.submitQuizV3(this.generateRequest).subscribe(
Expand Down Expand Up @@ -1460,6 +1482,32 @@ export class PracticeComponent implements OnInit, OnChanges, OnDestroy {
// },
// )
}

async submitAfterAllPromiseResolved() {
if (this.selectedAssessmentCompatibilityLevel < 6) {
const quizV4Res: any = await this.quizSvc.submitQuizV4(this.generateRequest).toPromise().catch(_error => {})
if (quizV4Res && quizV4Res.params && quizV4Res.params.status.toLowerCase() === 'success') {
if (quizV4Res.result.primaryCategory === 'Course Assessment') {
setTimeout(() => {
this.getQuizResult()
}, environment.quizResultTimeout)
} else if (quizV4Res.result.primaryCategory === 'Practice Question Set') {
this.assignQuizResult(quizV4Res.result)
}
}
} else {
const quizV4Res: any = await this.quizSvc.submitQuizV5(this.generateRequest).toPromise().catch(_error => {})
if (quizV4Res && quizV4Res.params && quizV4Res.params.status.toLowerCase() === 'success') {
if (quizV4Res.result.primaryCategory === 'Course Assessment') {
setTimeout(() => {
this.getQuizResult()
}, environment.quizResultTimeout)
} else if (quizV4Res.result.primaryCategory === 'Practice Question Set') {
this.assignQuizResult(quizV4Res.result)
}
}
}
}
showAnswers() {
this.showMtfAnswers()
this.showFitbAnswers()
Expand Down Expand Up @@ -1639,15 +1687,17 @@ export class PracticeComponent implements OnInit, OnChanges, OnDestroy {
if(this.selectedAssessmentCompatibilityLevel < 6) {
this.init()
} else {
this.quizSvc.canAttendV5(this.identifier).subscribe(response => {
if (response) {
this.canAttempt = response
// this.canAttempt = {
// attemptsAllowed: 1,
// attemptsMade: 0,
// }
}
})
if(this.ePrimaryCategory.FINAL_ASSESSMENT == this.primaryCategory) {
this.quizSvc.canAttendV5(this.identifier).subscribe(response => {
if (response) {
this.canAttempt = response
// this.canAttempt = {
// attemptsAllowed: 1,
// attemptsMade: 0,
// }
}
})
}
this.retakeAssessment()
}

Expand Down
13 changes: 9 additions & 4 deletions project/ws/viewer/src/lib/plugins/practice/practice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,16 @@ export class PracticeService {
const stringRemoveSlashN = this.extractContent(question.options[i].text.replace(/\n/g, '').replace(/\&lt;/g, '<').replace(/\&gt;/g, '>'))
const idxOfSource = _.indexOf(mtfSrc[question.questionId].source, stringRemoveSlashN.replace(/<(.|\n)*?>/g, ''))
const targetId = mtfSrc[question.questionId].target[idxOfSource]
const lastChar = targetId.slice(-1)
if (question) {
question.options[i].response = question.rhsChoices && question.rhsChoices[Number(lastChar) - 1]
if (targetId) {
const lastChar = targetId.slice(-1)
if (question && lastChar) {
question.options[i].response = question.rhsChoices && question.rhsChoices[Number(lastChar) - 1]
}
question.options[i].userSelected = true
} else {
question.options[i].userSelected = false
}
question.options[i].userSelected = true

// }
// }
} else {
Expand Down

0 comments on commit f34c58f

Please sign in to comment.