Add a quiz editing page

This commit is contained in:
Oliver Akins 2022-01-19 23:37:27 -06:00
parent dd6e4ef0de
commit 9320fae179
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99
3 changed files with 188 additions and 0 deletions

47
docs/config/config.js Normal file
View file

@ -0,0 +1,47 @@
var app = new Vue({
el: '#app',
data: {
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
quiz: []
},
computed: {
config_preview() {
let data = [];
for (var i in this.quiz) {
let question = this.quiz[i];
if (!this.verify_question_options(question)) {
data.push(`# ERROR: Question ${parseInt(i) + 1} has an invalid option.\n#\tThe question has been excluded from the quiz,\n#\tthis can cause your questions not to line up\n#\twith the answers!`);
continue;
};
// Valid options, create the actual TOML structure
let section = `[[quiz.questions]] # question ${parseInt(i) + 1}`;
section += `\nanswer="${question.answer.toUpperCase()}"`;
if (question.highest_letter == "A") {
section += `\nrange="[A]"`;
} else {
section += `\nrange="[A-${question.highest_letter}]"`
};
section += `\ncan_change=${question.changeable}`;
data.push(section);
}
return data.join(`\n\n`);
},
},
methods: {
verify_question_options(question) {
return question.answer.length === 1;
},
add_question() {
this.quiz.push(JSON.parse(`{"answer": "A", "highest_letter": "A", "changeable": false}`));
},
delete_question(i) {
document.getElementById(`question-${i}-options`).open = false;
this.quiz.splice(i, 1);
alert(`Deleted Question ${parseInt(i) + 1}`);
},
},
});