Commit 563f62ceafe1c756f6407cb511249dee5f2142db
1 parent
2285f4a5
Exists in
master
and in
1 other branch
- disabled submit during animations (fixes synchronization problems)
- changed FileHandler to close the file immediately after reading it
Showing
4 changed files
with
17 additions
and
12 deletions
Show diff stats
BUGS.md
1 | 1 | ||
2 | # BUGS | 2 | # BUGS |
3 | 3 | ||
4 | -- botao para mostrar a solução quando se acerta. | ||
5 | - shift-enter não está a funcionar | 4 | - shift-enter não está a funcionar |
6 | - falha intermitent no file handler quando o browser envia 2 GET requests ao mesmo tempo (porquê?) | 5 | - falha intermitent no file handler quando o browser envia 2 GET requests ao mesmo tempo (porquê?) |
7 | - nos topicos learn.yaml, qd falha acrescenta no fim. nao faz sentido. | 6 | - nos topicos learn.yaml, qd falha acrescenta no fim. nao faz sentido. |
@@ -34,6 +33,8 @@ | @@ -34,6 +33,8 @@ | ||
34 | 33 | ||
35 | # FIXED | 34 | # FIXED |
36 | 35 | ||
36 | +- quando se pressiona "responde" rapido (enquanto a animacao dura), a pergunta passa para a seguinte sem haver o correspondente redraw, ou seja a proxima resposta nao é a da pergunta mostrada. | ||
37 | +- botao para mostrar a solução quando se acerta. | ||
37 | - não está a guardar o resultado no final do topico | 38 | - não está a guardar o resultado no final do topico |
38 | - esta a permitir 2 logins em simultaneo do mesmo user. fica tudo baralhado se mxerem em simultaneo... | 39 | - esta a permitir 2 logins em simultaneo do mesmo user. fica tudo baralhado se mxerem em simultaneo... |
39 | - errar no ultimo topico nao mostra solucao? | 40 | - errar no ultimo topico nao mostra solucao? |
serve.py
@@ -178,11 +178,11 @@ class FileHandler(BaseHandler): | @@ -178,11 +178,11 @@ class FileHandler(BaseHandler): | ||
178 | SUPPORTED_METHODS = ['GET'] | 178 | SUPPORTED_METHODS = ['GET'] |
179 | 179 | ||
180 | @tornado.web.authenticated | 180 | @tornado.web.authenticated |
181 | - # async | ||
182 | - def get(self, filename): | 181 | + async def get(self, filename): |
183 | uid = self.current_user | 182 | uid = self.current_user |
184 | public_dir = self.learn.get_current_public_dir(uid) | 183 | public_dir = self.learn.get_current_public_dir(uid) |
185 | filepath = path.expanduser(path.join(public_dir, filename)) | 184 | filepath = path.expanduser(path.join(public_dir, filename)) |
185 | + content_type, encoding = mimetypes.guess_type(filename) | ||
186 | 186 | ||
187 | try: | 187 | try: |
188 | f = open(filepath, 'rb') | 188 | f = open(filepath, 'rb') |
@@ -190,16 +190,16 @@ class FileHandler(BaseHandler): | @@ -190,16 +190,16 @@ class FileHandler(BaseHandler): | ||
190 | logging.error(f'File not found: {filepath}') | 190 | logging.error(f'File not found: {filepath}') |
191 | except PermissionError: | 191 | except PermissionError: |
192 | logging.error(f'No permission: {filepath}') | 192 | logging.error(f'No permission: {filepath}') |
193 | + except Exception as e: | ||
194 | + raise e | ||
193 | else: | 195 | else: |
194 | - content_type = mimetypes.guess_type(filename) | ||
195 | - self.set_header("Content-Type", content_type[0]) | ||
196 | - # divide the file into chunks and write one chunk at a time, so | ||
197 | - # that the write does not block the ioloop for very long. | ||
198 | with f: | 196 | with f: |
199 | data = f.read() | 197 | data = f.read() |
198 | + f.close() | ||
199 | + self.set_header("Content-Type", content_type) | ||
200 | self.write(data) | 200 | self.write(data) |
201 | - # await self.flush() | ||
202 | - self.flush() | 201 | + await self.flush() |
202 | + # self.flush() | ||
203 | 203 | ||
204 | 204 | ||
205 | # ---------------------------------------------------------------------------- | 205 | # ---------------------------------------------------------------------------- |
static/js/topic.js
@@ -3,6 +3,7 @@ $.fn.extend({ | @@ -3,6 +3,7 @@ $.fn.extend({ | ||
3 | var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend'; | 3 | var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend'; |
4 | this.addClass('animated ' + animation).one(animationEnd, function() { | 4 | this.addClass('animated ' + animation).one(animationEnd, function() { |
5 | $(this).removeClass('animated ' + animation); | 5 | $(this).removeClass('animated ' + animation); |
6 | + $("#submit").removeClass("disabled"); | ||
6 | }); | 7 | }); |
7 | } | 8 | } |
8 | }); | 9 | }); |
@@ -27,6 +28,8 @@ function showTriesLeft(tries) { | @@ -27,6 +28,8 @@ function showTriesLeft(tries) { | ||
27 | 28 | ||
28 | // Get current question | 29 | // Get current question |
29 | function getQuestion() { | 30 | function getQuestion() { |
31 | + $("#submit").addClass("disabled"); | ||
32 | + | ||
30 | $.ajax({ | 33 | $.ajax({ |
31 | type: "GET", | 34 | type: "GET", |
32 | url: "/question", | 35 | url: "/question", |
@@ -42,7 +45,7 @@ function updateQuestion(response) { | @@ -42,7 +45,7 @@ function updateQuestion(response) { | ||
42 | var method = response["method"]; | 45 | var method = response["method"]; |
43 | var params = response["params"]; | 46 | var params = response["params"]; |
44 | 47 | ||
45 | - $('#right, #wrong').hide(); | 48 | + $("#right, #wrong").hide(); |
46 | 49 | ||
47 | switch (method) { | 50 | switch (method) { |
48 | case "new_question": | 51 | case "new_question": |
@@ -63,8 +66,8 @@ function new_question(type, question, tries, progress) { | @@ -63,8 +66,8 @@ function new_question(type, question, tries, progress) { | ||
63 | $("#question_div").html(question).animateCSS('bounceInDown'); | 66 | $("#question_div").html(question).animateCSS('bounceInDown'); |
64 | showTriesLeft(tries); | 67 | showTriesLeft(tries); |
65 | $("#comments, #solution").html(""); | 68 | $("#comments, #solution").html(""); |
66 | - var btn_text = (type == "info") ? "Continuar" : "Responder"; | ||
67 | - $("#submit").html(btn_text).off().click(postAnswer); | 69 | + var btntext = (type == "info") ? "Continuar" : "Responder"; |
70 | + $("#submit").html(btntext).off().click(postAnswer); | ||
68 | $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); | 71 | $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); |
69 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); | 72 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); |
70 | 73 |
templates/topic.html
@@ -111,6 +111,7 @@ | @@ -111,6 +111,7 @@ | ||
111 | 111 | ||
112 | <div id="solution"></div> | 112 | <div id="solution"></div> |
113 | 113 | ||
114 | + <!-- reponder / continuar --> | ||
114 | <a class="btn btn-primary btn-lg btn-block my-5" id="submit" data-toggle="tooltip" data-placement="right" href="#solution"></a> | 115 | <a class="btn btn-primary btn-lg btn-block my-5" id="submit" data-toggle="tooltip" data-placement="right" href="#solution"></a> |
115 | <!-- title="Shift-Enter" --> | 116 | <!-- title="Shift-Enter" --> |
116 | </div> | 117 | </div> |