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