Added basic rule system

This commit is contained in:
Oskar Winkels 2021-01-05 23:31:58 +01:00
parent 83544a28be
commit 71095cd5b8
4 changed files with 68 additions and 16 deletions

View File

@ -28,15 +28,25 @@
<main> <main>
<div id="spreadsheet" class="view"> <div id="spreadsheet" class="view">
<form> <form onsubmit="createQuiz(event)">
Title:<br> Title:<br>
<input type="text" id="titleField" required> <input type="text" id="titleField" required>
Style:<br>
<select type="select" id="styleField" required>
<option value="FSG" >FSG </option>
<option value="FSA" >FSA </option>
<option value="FSN" >FSN </option>
<option value="FSEast" >FSEast </option>
<option value="FSCzech" >FSCzech </option>
<option value="FSSpain" >FSSpain </option>
<option value="FSSwitzerland">FSSwitzerland </option>
</select>
Paste your questions from a spreadsheet here:<br> Paste your questions from a spreadsheet here:<br>
<textarea rows="16" id="questions" required></textarea> <textarea rows="16" id="questions" required></textarea>
<br> <br>
<input type="button" value="Create Quiz" onclick="createQuiz()"> <input type="submit" value="Create Quiz">
</form> </form>
</div> </div>

View File

@ -51,7 +51,9 @@ function updateSubmitTimer() {
function startSubmitTimer(time) { function startSubmitTimer(time) {
state.submitTimer = time || 30 state.submitTimer = time || state.submitTime
if (state.submitTimer == null)
return
console.log('Setting submitTimer to ' + state.submitTimer + ' seconds.') console.log('Setting submitTimer to ' + state.submitTimer + ' seconds.')
@ -139,21 +141,20 @@ function reStartQuiz() {
} }
function createQuiz() { function createQuiz(e) {
e.preventDefault()
console.log('Creating new quiz') console.log('Creating new quiz')
state.title = document.getElementById('titleField').value
if (state.title == '') {
alert('Please enter a title')
return
}
clearState() clearState()
removeLink() removeLink()
state.title = document.getElementById('titleField').value
state.style = document.getElementById('styleField').value
if (parseSpreadsheet().success == false) { if (parseSpreadsheet().success == false) {
console.log('Quiz creation failed.') alert('Quiz creation failed.')
return return
} }
@ -165,6 +166,8 @@ function createQuiz() {
console.log('Quiz created') console.log('Quiz created')
return false
} }

View File

@ -63,12 +63,12 @@ form {
text-align: left !important; text-align: left !important;
} }
textarea, input { textarea, input, select {
margin-top: 8px; margin-top: 8px;
border-radius: 3px; border-radius: 3px;
} }
input[type="button"] { input[type="button"], input[type="submit"] {
float: right; float: right;
cursor: pointer; cursor: pointer;
margin: 16px 0 16px 16px; margin: 16px 0 16px 16px;
@ -80,16 +80,16 @@ input[type="button"] {
font-weight: bold; font-weight: bold;
} }
input[type="button"].center { input[type="button"].center, input[type="submit"].center {
float: none; float: none;
} }
input[type="button"]:disabled { input[type="button"]:disabled, input[type="submit"]:disabled {
cursor: auto; cursor: auto;
background: #888 !important; background: #888 !important;
} }
textarea, input[type="text"] { textarea, input[type="text"], select {
background: #ddd; background: #ddd;
margin-bottom: 16px; margin-bottom: 16px;
padding: .5em; padding: .5em;

View File

@ -4,10 +4,14 @@ const defaultState = {
title: null, title: null,
questions: [], questions: [],
success: 0, success: 0,
submitTime: null,
submitTimer: 0, submitTimer: 0,
submitInterval: null, submitInterval: null,
totalTimer: 0, totalTimer: 0,
totalInterval: null, totalInterval: null,
questionTime: null,
questionTimer: 0,
questionInterval: null,
} }
var state var state
@ -28,6 +32,41 @@ function updateTitles() {
} }
const rules = {
__default__: {
sequential: false,
submitTries: 1,
submitTimeout: null,
timedQs: false,
allowQOvertime: false
},
'FSG' : { sequential: true, timedQs: true },
'FSA' : { sequential: true, timedQs: true, allowQOvertime: true },
'FSN' : { sequential: true },
'FSEast' : { sequential: false },
'FSCzech' : { sequential: false, submitTries: Infinity, submitTimeout: 30 },
'FSSpain' : { sequential: true, submitTries: 3 },
'FSSwitzerland' : { sequential: true },
}
function getRule(name) {
var r = rules[state.style]
if (r.hasOwnProperty(name))
return r[name]
var d = rules.__default__
if (d.hasOwnProperty(name))
return d[name]
console.error('No such rule:', name);
return undefined
}
function changeView(view) { function changeView(view) {
for (el of document.querySelectorAll('.view')) for (el of document.querySelectorAll('.view'))