Skip to content

Commit

Permalink
update for complete question for all the section
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnubansaltarento committed Jul 14, 2024
1 parent 5d0f975 commit f0aee47
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
93 changes: 71 additions & 22 deletions project/ws/viewer/src/lib/plugins/practice/practice.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
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 f0aee47

Please sign in to comment.