Commit 2e5d58ed99e087697719be5341b3e2154deb38dd

Authored by Miguel Barão
1 parent 2006012e
Exists in master and in 1 other branch dev

- link to show solution both when right and wrong.

- solution in bootstrap card instead of alert
1 1
2 # BUGS 2 # BUGS
3 3
  4 +- botao para mostrar a solução quando se acerta.
4 - shift-enter não está a funcionar 5 - shift-enter não está a funcionar
5 - falha intermitent no file handler quando o browser envia 2 GET requests ao mesmo tempo (porquê?) 6 - falha intermitent no file handler quando o browser envia 2 GET requests ao mesmo tempo (porquê?)
6 - nos topicos learn.yaml, qd falha acrescenta no fim. nao faz sentido. 7 - nos topicos learn.yaml, qd falha acrescenta no fim. nao faz sentido.
@@ -276,11 +276,14 @@ class QuestionHandler(BaseHandler): @@ -276,11 +276,14 @@ class QuestionHandler(BaseHandler):
276 if action == 'right': # get next question in the topic 276 if action == 'right': # get next question in the topic
277 comments_html = self.render_string('comments-right.html', 277 comments_html = self.render_string('comments-right.html',
278 comments=q['comments'], md=md_to_html) 278 comments=q['comments'], md=md_to_html)
  279 + solution_html = to_unicode(self.render_string('solution.html',
  280 + solution=q['solution'], md=md_to_html))
279 281
280 response['params'] = { 282 response['params'] = {
281 'type': q['type'], 283 'type': q['type'],
282 'progress': self.learn.get_student_progress(user), 284 'progress': self.learn.get_student_progress(user),
283 'comments': to_unicode(comments_html), 285 'comments': to_unicode(comments_html),
  286 + 'solution': solution_html,
284 'tries': q['tries'], 287 'tries': q['tries'],
285 } 288 }
286 289
@@ -289,11 +292,11 @@ class QuestionHandler(BaseHandler): @@ -289,11 +292,11 @@ class QuestionHandler(BaseHandler):
289 comments=q['comments'], md=md_to_html) 292 comments=q['comments'], md=md_to_html)
290 293
291 response['params'] = { 294 response['params'] = {
292 - 'type': q['type'],  
293 - 'progress': self.learn.get_student_progress(user),  
294 - 'comments': to_unicode(comments_html),  
295 - 'tries': q['tries'],  
296 - } 295 + 'type': q['type'],
  296 + 'progress': self.learn.get_student_progress(user),
  297 + 'comments': to_unicode(comments_html),
  298 + 'tries': q['tries'],
  299 + }
297 300
298 elif action == 'wrong': # no more tries 301 elif action == 'wrong': # no more tries
299 comments_html = to_unicode(self.render_string('comments.html', 302 comments_html = to_unicode(self.render_string('comments.html',
static/js/topic.js
@@ -24,8 +24,7 @@ function updateQuestion(response) { @@ -24,8 +24,7 @@ function updateQuestion(response) {
24 var method = response["method"]; 24 var method = response["method"];
25 var params = response["params"]; 25 var params = response["params"];
26 26
27 - $('#right').hide();  
28 - $('#wrong').hide(); 27 + $('#right, #wrong').hide();
29 28
30 switch (method) { 29 switch (method) {
31 case "new_question": 30 case "new_question":
@@ -44,8 +43,7 @@ function updateQuestion(response) { @@ -44,8 +43,7 @@ function updateQuestion(response) {
44 43
45 function new_question(type, question, tries, progress) { 44 function new_question(type, question, tries, progress) {
46 $("#question_div").html(question); 45 $("#question_div").html(question);
47 - $("#comments").html("");  
48 - $("#solution").html(""); 46 + $("#comments, #solution").html("");
49 if (type == "info") { 47 if (type == "info") {
50 $("#submit").html("Continuar"); 48 $("#submit").html("Continuar");
51 } 49 }
@@ -55,7 +53,6 @@ function new_question(type, question, tries, progress) { @@ -55,7 +53,6 @@ function new_question(type, question, tries, progress) {
55 $("#submit").off(); 53 $("#submit").off();
56 $("#submit").click(postAnswer); 54 $("#submit").click(postAnswer);
57 $("#tries").html(tries); 55 $("#tries").html(tries);
58 -  
59 $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); 56 $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress);
60 MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); 57 MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]);
61 58
@@ -72,6 +69,7 @@ function new_question(type, question, tries, progress) { @@ -72,6 +69,7 @@ function new_question(type, question, tries, progress) {
72 // }}); 69 // }});
73 } 70 }
74 71
  72 +
75 // =========================================================================== 73 // ===========================================================================
76 // Send answer and receive a response with the result of the correction. 74 // Send answer and receive a response with the result of the correction.
77 // The response can be right, try_again or wrong. 75 // The response can be right, try_again or wrong.
@@ -108,6 +106,12 @@ function getFeedback(response) { @@ -108,6 +106,12 @@ function getFeedback(response) {
108 $("#submit").html("Continuar"); 106 $("#submit").html("Continuar");
109 $("#submit").off(); 107 $("#submit").off();
110 $("#submit").click(getQuestion); 108 $("#submit").click(getQuestion);
  109 + $("#link_solution_on_right").click(function(){
  110 + $("#right").hide();
  111 + $('#solution').html(params['solution']);
  112 + MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]);
  113 + $('#solution').animateCSS('flipInX');
  114 + });
111 break; 115 break;
112 116
113 case "try_again": 117 case "try_again":
@@ -121,14 +125,16 @@ function getFeedback(response) { @@ -121,14 +125,16 @@ function getFeedback(response) {
121 case "wrong": 125 case "wrong":
122 $('#right').hide(); 126 $('#right').hide();
123 $('#wrong').show(); 127 $('#wrong').show();
124 - // $('#question_div').animateCSS('shake');  
125 $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); 128 $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]);
126 $("#tries").html(params["tries"]); 129 $("#tries").html(params["tries"]);
127 $('#comments').html(params['comments']); 130 $('#comments').html(params['comments']);
128 MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); 131 MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]);
129 - $('#solution').html(params['solution']);  
130 - MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]);  
131 - $('#solution').animateCSS('flipInX'); 132 + $("#link_solution_on_wrong").click(function () {
  133 + $("#wrong").hide();
  134 + $('#solution').html(params['solution']);
  135 + MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]);
  136 + $('#solution').animateCSS('flipInX');
  137 + });
132 $("fieldset").attr("disabled", "disabled"); 138 $("fieldset").attr("disabled", "disabled");
133 $("#submit").html("Continuar"); 139 $("#submit").html("Continuar");
134 $("#submit").off(); 140 $("#submit").off();
templates/solution.html
1 {% autoescape %} 1 {% autoescape %}
2 2
3 {% if solution %} 3 {% if solution %}
4 -<div class="alert alert-secondary"> 4 +<div class="card">
  5 + <div class="card-body">
5 <h4 class="alert-heading">Solução</h4> 6 <h4 class="alert-heading">Solução</h4>
6 {{ md(solution) }} 7 {{ md(solution) }}
  8 + </div>
7 </div> 9 </div>
8 {% end %} 10 {% end %}
templates/topic.html
@@ -76,46 +76,43 @@ @@ -76,46 +76,43 @@
76 76
77 <div id="notifications"></div> 77 <div id="notifications"></div>
78 78
79 - <!-- <div class="container"> -->  
80 - <!-- <div class="row"> -->  
81 - <!-- <div class="col col-lg-9"> -->  
82 - <div class="my-5" id="content">  
83 - <form action="/question" method="post" id="question_form" autocomplete="off">  
84 - {% module xsrf_form_html() %}  
85 - <div id="question_div"></div>  
86 - </form>  
87 -  
88 - <div id="comments"></div>  
89 - </div> 79 + <div class="my-5" id="content">
  80 + <form action="/question" method="post" id="question_form" autocomplete="off">
  81 + {% module xsrf_form_html() %}
  82 + <div id="question_div"></div>
  83 + </form>
  84 +
  85 + <div id="comments"></div>
  86 + </div>
90 87
91 - <!-- </div> col -->  
92 - <!-- <div class="col col-lg-3"> -->  
93 - <button class="btn btn-primary btn-lg btn-block my-5" id="submit" data-toggle="tooltip" data-placement="right" title="Shift-Enter">Responder</button>  
94 -  
95 - <div id="wrong" style="display: none">  
96 - <div class="alert alert-danger">  
97 - <i class="fas fa-thumbs-down fa-3x"></i>  
98 - <br><br>  
99 - Desta vez não acertou,  
100 - <br>  
101 - mas também se aprende com os erros... 88 + <div id="wrong" style="display: none">
  89 + <div class="alert alert-danger">
  90 + <i class="fas fa-thumbs-down fa-3x"></i>
  91 + <br><br>
  92 + Desta vez não acertou, mas também se aprende com os erros...
  93 + <br>
  94 + <div id="show_solution_on_right">
  95 + <a href="#solution" id="link_solution_on_wrong">Ver solução</a>
102 </div> 96 </div>
103 </div> 97 </div>
  98 + </div>
104 99
105 - <div id="right" style="display: none">  
106 - <div class="alert alert-success">  
107 - <i class="fas fa-thumbs-up fa-3x"></i>  
108 - <br><br>  
109 - Excelente resposta! 100 + <div id="right" style="display: none">
  101 + <div class="alert alert-success">
  102 + <i class="fas fa-thumbs-up fa-3x"></i>
  103 + <br><br>
  104 + Excelente resposta!
  105 + <br>
  106 + <div id="show_solution_on_right">
  107 + <a href="#solution" id="link_solution_on_right">Ver solução</a>
110 </div> 108 </div>
111 </div> 109 </div>
  110 + </div>
112 111
113 - <div id="solution"></div> 112 + <div id="solution"></div>
114 113
  114 + <a class="btn btn-primary btn-lg btn-block my-5" id="submit" data-toggle="tooltip" data-placement="right" title="Shift-Enter" href="#solution"></a>
115 115
116 - <!-- </div> col -->  
117 - <!-- </div> row -->  
118 - <!-- </div> --> <!-- container -->  
119 </div> 116 </div>
120 117
121 </body> 118 </body>