Commit e831c259b6512c1f24f6f3c231a86f35408ce227

Authored by Miguel Barão
1 parent 065611f7
Exists in master and in 1 other branch dev

- links in the sidebar start new topic

1 1
2 BUGS: 2 BUGS:
3 3
4 -- topicos no sidebar devem ser links para iniciar um topico acessivel. os inacessiveis devem estar inactivos.  
5 - tabs em textarea nao funcionam correctamente (insere 1 espaco em vez de 4) 4 - tabs em textarea nao funcionam correctamente (insere 1 espaco em vez de 4)
6 - reportar comentarios após submeter. 5 - reportar comentarios após submeter.
  6 +- os topicos locked devem estar inactivos no sidebar.
7 - textarea deve mostrar no html os valores iniciais de ans, se existir 7 - textarea deve mostrar no html os valores iniciais de ans, se existir
8 - detect questions in questions.yaml without ref -> error ou generate default. 8 - detect questions in questions.yaml without ref -> error ou generate default.
9 - error if demo.yaml has no topics 9 - error if demo.yaml has no topics
@@ -21,6 +21,7 @@ TODO: @@ -21,6 +21,7 @@ TODO:
21 21
22 FIXED: 22 FIXED:
23 23
  24 +- topicos no sidebar devem ser links para iniciar um topico acessivel.
24 - logs inicio de topico 25 - logs inicio de topico
25 - indicar o topico actual no sidebar 26 - indicar o topico actual no sidebar
26 - reload da página rebenta o estado. 27 - reload da página rebenta o estado.
@@ -141,6 +141,11 @@ class LearnApp(object): @@ -141,6 +141,11 @@ class LearnApp(object):
141 141
142 return q['grade'] 142 return q['grade']
143 143
  144 + # ------------------------------------------------------------------------
  145 + # Start new topic
  146 + # ------------------------------------------------------------------------
  147 + def start_topic(self, uid, topic):
  148 + self.online[uid]['state'].start_topic(topic)
144 149
145 # ------------------------------------------------------------------------ 150 # ------------------------------------------------------------------------
146 # Fill db table 'Topic' with topics from the graph if not already there. 151 # Fill db table 'Topic' with topics from the graph if not already there.
@@ -39,13 +39,15 @@ class Knowledge(object): @@ -39,13 +39,15 @@ class Knowledge(object):
39 # Start a new topic. If not provided, selects the first with level < 0.8 39 # Start a new topic. If not provided, selects the first with level < 0.8
40 # If all levels > 0.8, will stay in the last one forever... 40 # If all levels > 0.8, will stay in the last one forever...
41 # ------------------------------------------------------------------------ 41 # ------------------------------------------------------------------------
42 - def start_topic(self, topic=None):  
43 - if topic is None: 42 + def start_topic(self, topic=''):
  43 + print(f'knowledge.start_topic "{topic}"')
  44 + if not topic:
44 for topic in self.topic_sequence: 45 for topic in self.topic_sequence:
45 unlocked = topic in self.state 46 unlocked = topic in self.state
46 needs_work = unlocked and self.state[topic]['level'] < 0.8 47 needs_work = unlocked and self.state[topic]['level'] < 0.8
47 factory = self.depgraph.node[topic]['factory'] 48 factory = self.depgraph.node[topic]['factory']
48 - if needs_work and factory: 49 + print(f'{topic}, unlocked={unlocked}, needs_work={needs_work}')
  50 + if factory and (not unlocked or needs_work):
49 break 51 break
50 # logger.info(f'{self.student} skipped topic "{topic}"') 52 # logger.info(f'{self.student} skipped topic "{topic}"')
51 else: 53 else:
@@ -53,7 +55,7 @@ class Knowledge(object): @@ -53,7 +55,7 @@ class Knowledge(object):
53 # FIXME if factory is empty??? 55 # FIXME if factory is empty???
54 56
55 self.current_topic = topic 57 self.current_topic = topic
56 - logger.info(f'User "{self.student}" topic set to "{topic}"') 58 + logger.info(f'User "{self.student}" topic = "{topic}"')
57 59
58 # generate question instances for current topic 60 # generate question instances for current topic
59 questionlist = self.depgraph.node[topic]['questions'] 61 questionlist = self.depgraph.node[topic]['questions']
@@ -120,6 +120,8 @@ class LearnHandler(BaseHandler): @@ -120,6 +120,8 @@ class LearnHandler(BaseHandler):
120 @tornado.web.authenticated 120 @tornado.web.authenticated
121 def get(self): 121 def get(self):
122 uid = self.current_user 122 uid = self.current_user
  123 + topic = self.get_query_argument('topic', default='')
  124 + self.learn.start_topic(uid, topic)
123 self.render('learn.html', 125 self.render('learn.html',
124 uid=uid, 126 uid=uid,
125 name=self.learn.get_student_name(uid), 127 name=self.learn.get_student_name(uid),
@@ -204,7 +206,7 @@ class QuestionHandler(BaseHandler): @@ -204,7 +206,7 @@ class QuestionHandler(BaseHandler):
204 } 206 }
205 207
206 @tornado.web.authenticated 208 @tornado.web.authenticated
207 - def get(self): 209 + def get(self, topic=''):
208 self.write(self.new_question(self.current_user)) 210 self.write(self.new_question(self.current_user))
209 211
210 # handles answer posted 212 # handles answer posted
templates/topics.html
@@ -8,14 +8,14 @@ @@ -8,14 +8,14 @@
8 {% if t[0] == current_topic %} 8 {% if t[0] == current_topic %}
9 <li class="active"> <!-- class="active" class="disabled" --> 9 <li class="active"> <!-- class="active" class="disabled" -->
10 10
11 - <a> {{ gettopicname(t[0]) }}<br> 11 + <a href="#"> {{ gettopicname(t[0]) }}<br>
12 {{ round(t[1]*5)*'<i class="fa fa-star text-success" aria-hidden="true"></i>' + round(5-t[1]*5)*'<i class="fa fa-star-o" aria-hidden="true"></i>' }} 12 {{ round(t[1]*5)*'<i class="fa fa-star text-success" aria-hidden="true"></i>' + round(5-t[1]*5)*'<i class="fa fa-star-o" aria-hidden="true"></i>' }}
13 </a> 13 </a>
14 14
15 {% else %} 15 {% else %}
16 <li> <!-- class="active" class="disabled" --> 16 <li> <!-- class="active" class="disabled" -->
17 17
18 - <a href="#"> {{ gettopicname(t[0]) }}<br> 18 + <a href="/?topic={{ t[0] }}"> {{ gettopicname(t[0]) }}<br>
19 {{ round(t[1]*5)*'<i class="fa fa-star text-success" aria-hidden="true"></i>' + round(5-t[1]*5)*'<i class="fa fa-star-o" aria-hidden="true"></i>' }} 19 {{ round(t[1]*5)*'<i class="fa fa-star text-success" aria-hidden="true"></i>' + round(5-t[1]*5)*'<i class="fa fa-star-o" aria-hidden="true"></i>' }}
20 </a> 20 </a>
21 21