Showing answer

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

View file

@ -223,11 +223,34 @@
// ---------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------
function handleQuiz() { function handleQuiz() {
// TODO: dropdown in question getQuizData().then(res => {
// TODO: multiple selects, img in question const promises = []
// TODO:
res.forEach(question => {
promises.push(
GetXHRQuestionAnswer({
q: question.question,
data: question.data,
subj: getCurrentSubjectName(),
})
)
})
Promise.all(promises).then(res => {
const answers = res.map(result => {
return PrepareAnswers(result)
})
// TODO: new lines in answers
ShowAnswers(answers, res[0].question)
})
})
}
function getQuizData() {
return new Promise(resolve => {
// TODO: dropdown in question
const promises = [] const promises = []
const subjName = getCurrentSubjectName()
const questionNodes = Array.from( const questionNodes = Array.from(
document.getElementsByTagName('form')[0].childNodes[0].childNodes document.getElementsByTagName('form')[0].childNodes[0].childNodes
) )
@ -244,12 +267,13 @@
Promise.all(promises) Promise.all(promises)
.then(res => { .then(res => {
console.log(res) resolve(res)
}) })
.catch(err => { .catch(err => {
console.warn('Error in handleQuiz()') console.warn('Error in handleQuiz()')
console.warn(err) 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 })
} }
} }