From 32523cdcd9eaa4ad9363d79ebe82d5de4b852676 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 22 Nov 2017 21:23:14 +0100 Subject: Add module 'zelfoverhoor' Beta stage --- modules/zelfoverhoor/.gitignore | 4 + modules/zelfoverhoor/docent.html | 57 +++++++++++ modules/zelfoverhoor/docent.js | 173 ++++++++++++++++++++++++++++++++ modules/zelfoverhoor/index.html | 15 +++ modules/zelfoverhoor/notfound.html | 12 +++ modules/zelfoverhoor/qs.html | 64 ++++++++++++ modules/zelfoverhoor/qs.js | 76 ++++++++++++++ modules/zelfoverhoor/style.css | 3 + modules/zelfoverhoor/zelfoverhoor.js | 189 +++++++++++++++++++++++++++++++++++ 9 files changed, 593 insertions(+) create mode 100644 modules/zelfoverhoor/.gitignore create mode 100644 modules/zelfoverhoor/docent.html create mode 100644 modules/zelfoverhoor/docent.js create mode 100644 modules/zelfoverhoor/index.html create mode 100644 modules/zelfoverhoor/notfound.html create mode 100644 modules/zelfoverhoor/qs.html create mode 100644 modules/zelfoverhoor/qs.js create mode 100644 modules/zelfoverhoor/style.css create mode 100644 modules/zelfoverhoor/zelfoverhoor.js diff --git a/modules/zelfoverhoor/.gitignore b/modules/zelfoverhoor/.gitignore new file mode 100644 index 0000000..948b29c --- /dev/null +++ b/modules/zelfoverhoor/.gitignore @@ -0,0 +1,4 @@ +accounts.json +questiondb.json +questionsets.json +userlists.json diff --git a/modules/zelfoverhoor/docent.html b/modules/zelfoverhoor/docent.html new file mode 100644 index 0000000..224384d --- /dev/null +++ b/modules/zelfoverhoor/docent.html @@ -0,0 +1,57 @@ + + + + +Zelfoverhoor: Docent (<!--###NAME###-->) + + + + + +

Zelfoverhoor: Docent ()

+

Vragensets

+ + + +
IDNaamBeschrijving#vragen
+
+ +
+ + + diff --git a/modules/zelfoverhoor/docent.js b/modules/zelfoverhoor/docent.js new file mode 100644 index 0000000..7987351 --- /dev/null +++ b/modules/zelfoverhoor/docent.js @@ -0,0 +1,173 @@ +var questionsets=null; + +function getQuestionSets(){ + var xhr=new XMLHttpRequest(); + xhr.onreadystatechange=function(){ + if(xhr.readyState==4){ + questionsets=JSON.parse(xhr.responseText); + updateQuestionSetsList(); + } + }; + xhr.responseType="text"; + xhr.open("GET","/zelfoverhoor/docent/sets"); + xhr.send(); +} + +function updateQuestionSetsList(){ + var tbody=document.getElementById("qsets"); + clearElement(tbody); + if(questionsets.length==0){ + var tr=document.createElement("tr"); + var td=document.createElement("td"); + td.appendChild(document.createTextNode("Nog geen vragensets...")); + td.setAttribute("colspan","4"); + tr.appendChild(td); + tbody.appendChild(tr); + } + for(var i=0;i + + + +Zelfoverhoor + + + +
+ (docent) +
+

Zelfoverhoor

+

Welkom bij Zelfoverhoor! Als het goed is heb je van de docent een link van de vorm https://tomsmeding.com/zelfoverhoor/qs/abcdef gekregen. Daarmee kom je op de juiste pagina terecht. Hier is dus verder weinig te vinden. ;)

+ + diff --git a/modules/zelfoverhoor/notfound.html b/modules/zelfoverhoor/notfound.html new file mode 100644 index 0000000..8d79c10 --- /dev/null +++ b/modules/zelfoverhoor/notfound.html @@ -0,0 +1,12 @@ + + + + +Zelfoverhoor: niet gevonden + + + +

Zelfoverhoor

+Die vragenset kon niet worden gevonden. Misschien heb je de link niet goed gekopieerd? + + diff --git a/modules/zelfoverhoor/qs.html b/modules/zelfoverhoor/qs.html new file mode 100644 index 0000000..32c9099 --- /dev/null +++ b/modules/zelfoverhoor/qs.html @@ -0,0 +1,64 @@ + + + + +Zelfoverhoor: <!--###ID###--> + + + + + + +

Zelfoverhoor: vragenset ""

+Beschrijving:
+

+

+
+ Vraag:
+

+
+ + +
+
+ Je hebt alle vragen gehad!
+

Je had vragen goed van de in totaal vragen.

+

Gefeliciteerd met je prestatie! :D

+ +
+ + diff --git a/modules/zelfoverhoor/qs.js b/modules/zelfoverhoor/qs.js new file mode 100644 index 0000000..cc68af9 --- /dev/null +++ b/modules/zelfoverhoor/qs.js @@ -0,0 +1,76 @@ +var setname=questionset.name; +var setdescription=questionset.description; +var questions=questionset.questions; + +var currentidx=0; +var numcorrect=0; + +function clearElement(el){ + while(el.lastChild)el.removeChild(el.lastChild); +} + +function shuffle(a){ + var j,v,i; + for(var i=a.length-1;i>0;i--){ + j=Math.floor(Math.random()*(i+1)); + v=a[i]; a[i]=a[j]; a[j]=v; + } +} + +function startQuiz(){ + currentidx=0; + numcorrect=0; + showCurrent(); +} + +function showCurrent(){ + document.getElementById("qcontainer").classList.remove("invisible"); + document.getElementById("rescontainer").classList.add("invisible"); + document.getElementById("answercontainer").classList.add("invisible"); + document.getElementById("showAnswerButton").classList.remove("invisible"); + + var qdiv=document.getElementById("question"); + clearElement(qdiv); + qdiv.appendChild(document.createTextNode(questions[currentidx].q)); +} + +function showAnswer(){ + document.getElementById("answercontainer").classList.remove("invisible"); + document.getElementById("showAnswerButton").classList.add("invisible"); + + var adiv=document.getElementById("answer"); + clearElement(adiv); + adiv.appendChild(document.createTextNode(questions[currentidx].a)); +} + +function finishQuiz(){ + document.getElementById("qcontainer").classList.add("invisible"); + document.getElementById("rescontainer").classList.remove("invisible"); + document.getElementById("numcorrect").innerHTML=numcorrect; + document.getElementById("numtotal").innerHTML=questions.length; + if(numcorrect==questions.length){ + document.getElementById("allcorrectp").classList.remove("invisible"); + } else { + document.getElementById("allcorrectp").classList.add("invisible"); + } +} + +function advance(corr){ + if(corr)numcorrect++; + currentidx++; + if(currentidx: {q: "question", a: "answer"}} +var questiondb={}; +// {: {id, name, description, questions: []}} +var questionsets={}; +// {: []} +var userlists={}; + +function uniqidstr(validp){ + for(var len=6;;len++){ + var str=""; + for(var i=0;i0;i--){ + j=Math.floor(Math.random()*(i+1)); + v=a[i]; a[i]=a[j]; a[j]=v; + } +} + +module.exports=function(app,io,_moddir){ + moddir=_moddir; + + try { + questiondb=JSON.parse(fs.readFileSync(moddir+"/questiondb.json")); + questionsets=JSON.parse(fs.readFileSync(moddir+"/questionsets.json")); + userlists=JSON.parse(fs.readFileSync(moddir+"/userlists.json")); + } catch(e){ + console.log("error on reading zelfoverhoor db"); + questiondb={}; + questionsets={}; + userlists={}; + persistDB(); + } + + app.get("/zelfoverhoor",function(req,res){ + res.sendFile(moddir+"/index.html"); + }); + + app.get("/zelfoverhoor/qs/:id",function(req,res){ + var qset=questionsets[req.params.id]; + if(qset==null){ + res.status(404).sendFile(moddir+"/notfound.html"); + return; + } + var list=[]; + for(var i=0;i",req.params.id) + .replace("/*###QUESTIONSET###*/",JSON.stringify(resset))); + }); + }); + + app.use(["/zelfoverhoor/docent","/zelfoverhoor/docent/*"],cmn.authgen(accounts)); + app.get("/zelfoverhoor/docent",function(req,res){ + fs.readFile(moddir+"/docent.html",function(err,data){ + if(err)throw err; + res.send(String(data) + .replace(//g,req.authuser)); + }); + }); + app.get("/zelfoverhoor/docent/sets",function(req,res){ + if(userlists[req.authuser]==null){ + userlists[req.authuser]=[]; + } + var ul=userlists[req.authuser]; + var list=[]; + for(var i=0;i