Showing answer

This commit is contained in:
mrfry 2020-11-19 18:12:17 +01:00
parent e7871a5ba9
commit 566321eed8

View file

@ -223,33 +223,57 @@
// ---------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------
function handleQuiz() { function handleQuiz() {
// TODO: dropdown in question getQuizData().then(res => {
// TODO: multiple selects, img in question const promises = []
// TODO:
const promises = []
const subjName = getCurrentSubjectName()
const questionNodes = Array.from(
document.getElementsByTagName('form')[0].childNodes[0].childNodes
)
let i = 0 res.forEach(question => {
while ( promises.push(
i < questionNodes.length && GetXHRQuestionAnswer({
questionNodes[i].tagName === 'DIV' && q: question.question,
questionNodes[i].className !== 'submitbtns' data: question.data,
) { subj: getCurrentSubjectName(),
promises.push(getQuestionPromiseForSingleQuestion(questionNodes[i])) })
i++ )
} })
Promise.all(promises) Promise.all(promises).then(res => {
.then(res => { const answers = res.map(result => {
console.log(res) return PrepareAnswers(result)
}) })
.catch(err => {
console.warn('Error in handleQuiz()') // TODO: new lines in answers
console.warn(err) ShowAnswers(answers, res[0].question)
}) })
})
}
function getQuizData() {
return new Promise(resolve => {
// TODO: dropdown in question
const promises = []
const questionNodes = Array.from(
document.getElementsByTagName('form')[0].childNodes[0].childNodes
)
let i = 0
while (
i < questionNodes.length &&
questionNodes[i].tagName === 'DIV' &&
questionNodes[i].className !== 'submitbtns'
) {
promises.push(getQuestionPromiseForSingleQuestion(questionNodes[i]))
i++
}
Promise.all(promises)
.then(res => {
resolve(res)
})
.catch(err => {
console.warn('Error in handleQuiz()')
console.warn(err)
})
})
} }
function getPossibleAnswersFromTest(node) { function getPossibleAnswersFromTest(node) {
@ -1158,34 +1182,29 @@
// : Answering stuffs {{{ // : Answering stuffs {{{
// TODO // TODO
function PrepareAnswers(result, j) { function PrepareAnswers(result) {
assert(result) assert(result)
if (result.length > 0) { if (result.length > 0) {
var allMessages = [] // preparing all messages return result.map(res => {
for (var k = 0; k < result.length; k++) { let msg = res.q.Q + '\n'
var msg = '' // the current message
if (getVal('showQuestions') === undefined || getVal('showQuestions')) { // TODO: remove this maybe?
msg += result[k].q.Q + '\n' // adding the question if yes msg += res.q.A.replace(/, /g, '\n') // adding answer
}
msg += result[k].q.A.replace(/, /g, '\n') // adding answer if (res.q.data.type === 'image') {
if (result[k].q.data.type === 'image') {
msg += msg +=
'\n\nKépek fenti válaszok sorrendjében: ' + '\n\nKépek fenti válaszok sorrendjében: ' +
result[k].q.data.images.join(', ') // if it has image part, adding that too res.q.data.images.join(', ') // if it has image part, adding that too
} }
if (
result[k].detailedMatch && msg += '\n(Tárgy: ' + res.detailedMatch.matchedSubjName + ')'
result[k].detailedMatch.matchedSubjName
) { return {
msg += '\n(Tárgy: ' + result[k].detailedMatch.matchedSubjName + ')'
}
allMessages.push({
m: msg, m: msg,
p: result[k].match, p: res.match,
}) }
} })
return allMessages
} }
} }