Meilleures erreurs
This commit is contained in:
parent
0ca8ea7408
commit
b22b514574
@ -9,7 +9,9 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.bernard.misael.model.Quizz;
|
||||
import com.bernard.misael.model.User;
|
||||
import com.bernard.misael.repository.QuizzRepository;
|
||||
import com.bernard.misael.repository.UserRepository;
|
||||
import com.bernard.misael.service.QuizzManager;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
@ -32,6 +34,9 @@ public class QuestionsController {
|
||||
@Autowired
|
||||
QuizzManager qm;
|
||||
|
||||
@Autowired
|
||||
QuizzRepository qrepo;
|
||||
|
||||
@GetMapping("/quizz")
|
||||
/*
|
||||
* List all quizz
|
||||
@ -63,6 +68,8 @@ public class QuestionsController {
|
||||
u = ur.findByName(p.getName());
|
||||
//XXX test that user can answer quizz
|
||||
m.addAttribute("formid", quizzId);
|
||||
Quizz q = qrepo.getById(quizzId);
|
||||
m.addAttribute("quizzLength",q.getQuestionCount());
|
||||
|
||||
return "form";
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
<script th:src="@{/webjars/jquery/1.9.1/jquery.min.js}"></script>
|
||||
<main>
|
||||
<span id="question-text"></span>
|
||||
<span id="question-counter">0/0</span>
|
||||
<div id="answer-select">
|
||||
<button id="answer-select-duo">Duo</button>
|
||||
<button id="answer-select-carre">Carré</button>
|
||||
@ -29,13 +30,21 @@
|
||||
<button id="answer-carre-button-4"></button>
|
||||
</div>
|
||||
|
||||
<span id="error-textbox" style="color: red"></span>
|
||||
<button id="question-button">Poser la question</button>
|
||||
<script th:inline="javascript">
|
||||
/*<![CDATA[*/
|
||||
var qid = /*[[${formid}]]*/ -1;
|
||||
var qlength = /*[[${quizzLength}]]*/ -1;
|
||||
/*]]>*/
|
||||
</script>
|
||||
<script>
|
||||
e = new RegExp("/([0-9]+)$")
|
||||
e.test(window.location.href)
|
||||
qid = Number(RegExp.lastMatch.substring(1))
|
||||
qindex = 0
|
||||
qstep = 0
|
||||
function error(txt) {
|
||||
console.log(txt)
|
||||
$("#error-textbox").text(txt)
|
||||
}
|
||||
function next() {
|
||||
$.ajax({
|
||||
url: "/questions/question/"+qid,
|
||||
@ -46,9 +55,11 @@
|
||||
qindex=res["index"]
|
||||
qstep=res["step"]
|
||||
if(!res["success"]) {
|
||||
alert(res["message"])
|
||||
console.log(res["message"])
|
||||
error(res["message"])
|
||||
return
|
||||
}
|
||||
$("#question-counter").text((res["index"]+1)+"/"+qlength)
|
||||
$("#question-text").text(res["data"]["text"])
|
||||
if(qstep==0){
|
||||
$("#answer-select").show()
|
||||
@ -64,7 +75,7 @@
|
||||
$("#answer-cache").hide()
|
||||
if(typeof awrs === 'undefined'){
|
||||
$("#answer-cache").show()
|
||||
$("#answer-cache-input").text("")
|
||||
$("#answer-cache-input").val("")
|
||||
} else if (awrs.length == 2) {
|
||||
$("#answer-duo").show()
|
||||
$("#answer-duo-button-1").text(res.data.answers[0])
|
||||
@ -97,7 +108,7 @@
|
||||
if(res["success"]){
|
||||
next()
|
||||
} else {
|
||||
alert(res["message"])
|
||||
error(res["message"])
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -117,9 +128,19 @@
|
||||
success: function(res) {
|
||||
console.log(res)
|
||||
if(res["success"]){
|
||||
next()
|
||||
if(qindex+1 >= qlength) {
|
||||
$("#question-text").text("Plus de questions !")
|
||||
$("#answer-select").hide()
|
||||
$("#answer-duo").hide()
|
||||
$("#answer-carre").hide()
|
||||
$("#answer-cache").hide()
|
||||
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
alert(res["message"])
|
||||
isdone = false
|
||||
error(res["message"])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user