diff --git a/project/ws/viewer/src/lib/plugins/practice/components/overview/overview.component.ts b/project/ws/viewer/src/lib/plugins/practice/components/overview/overview.component.ts index 221bb656c..b5b13b051 100755 --- a/project/ws/viewer/src/lib/plugins/practice/components/overview/overview.component.ts +++ b/project/ws/viewer/src/lib/plugins/practice/components/overview/overview.component.ts @@ -62,8 +62,8 @@ export class OverviewComponent implements OnInit, OnChanges, OnDestroy { ngOnChanges() { if (!this.forPreview) { - if (this.canAttempt && (this.canAttempt.attemptsMade >= this.canAttempt.attemptsAllowed) && - this.questionTYP.FINAL_ASSESSMENT === this.primaryCategory) { + if (this.canAttempt && (this.canAttempt.attemptsMade >= this.canAttempt.attemptsAllowed) && + this.questionTYP.FINAL_ASSESSMENT === this.primaryCategory) { if (!this.maxAttempPopup) { this.showAssessmentPopup() } diff --git a/project/ws/viewer/src/lib/plugins/practice/practice.component.ts b/project/ws/viewer/src/lib/plugins/practice/practice.component.ts index 3c59fb517..fd6cbeca5 100644 --- a/project/ws/viewer/src/lib/plugins/practice/practice.component.ts +++ b/project/ws/viewer/src/lib/plugins/practice/practice.component.ts @@ -1351,7 +1351,7 @@ export class PracticeComponent implements OnInit, OnChanges, OnDestroy { timeTaken: timeSpent.toString(), timeSpent: timeSpent.toString(), editorState: { - options: optionAll, + options: optionAll.filter((o:any) => { return o.hasOwnProperty('index'); }).length > 0 ? optionAll : [], }, } responseQ.push(mtf) @@ -1405,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( @@ -1459,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() diff --git a/project/ws/viewer/src/lib/plugins/practice/practice.service.ts b/project/ws/viewer/src/lib/plugins/practice/practice.service.ts index 40ba37612..43a4df6f2 100755 --- a/project/ws/viewer/src/lib/plugins/practice/practice.service.ts +++ b/project/ws/viewer/src/lib/plugins/practice/practice.service.ts @@ -163,11 +163,16 @@ export class PracticeService { const stringRemoveSlashN = this.extractContent(question.options[i].text.replace(/\n/g, '').replace(/\</g, '<').replace(/\>/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 {