aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYingtong Li <runassudo@yingtongli.me>2017-03-28 19:25:17 +1100
committerYingtong Li <runassudo@yingtongli.me>2017-03-28 19:25:17 +1100
commit13308b3f9a9ec85f92b0a2f2a7d93eb4579ea308 (patch)
tree889b8f1e9fee492621a56a81efbc9e9ec7465121
parent16f5bb5834460a9cff32591e1e904a933e195d19 (diff)
Adjustments to speed mode
Figure out server-side time handling Tidy up formatting
-rw-r--r--pblive/__init__.py18
-rw-r--r--pblive/templates/question_mcq.html4
-rw-r--r--pblive/templates/question_speed.html6
-rw-r--r--pblive/templates/question_speed_admin.html8
-rw-r--r--pblive/templates/semantic_base.html1
5 files changed, 21 insertions, 16 deletions
diff --git a/pblive/__init__.py b/pblive/__init__.py
index cc5770a..149a979 100644
--- a/pblive/__init__.py
+++ b/pblive/__init__.py
@@ -157,16 +157,21 @@ def socket_answer(question_num, answer):
user = pblive.data.users[flask.request.sid]
if question_num == user.session.question_num:
+ if isinstance(user.session.questions[user.session.question_num], pblive.data.SpeedQuestion):
+ if question_num in user.answers:
+ # Only one shot!
+ return
+
user.answers[question_num] = answer
if isinstance(user.session.questions[user.session.question_num], pblive.data.MCQQuestion):
flask_socketio.emit('update', render_question(user, user.session, user.session.question_num), room=user.sid)
# Hurry!
- #if isinstance(user.session.questions[user.session.question_num], pblive.data.SpeedQuestion):
- # if user.session.questions[user.session.question_num].timer_thread is None:
- # user.session.questions[user.session.question_num].timer_thread = pblive.data.SpeedQuestionTimerThread(do_goto_question, user.session, user.session.question_num + 1)
- # user.session.questions[user.session.question_num].timer_thread.start()
+ if isinstance(user.session.questions[user.session.question_num], pblive.data.SpeedQuestion):
+ if user.session.questions[user.session.question_num].timer_thread is None:
+ user.session.questions[user.session.question_num].timer_thread = pblive.data.SpeedQuestionTimerThread(flask.copy_current_request_context(do_goto_question), user.session, user.session.question_num + 1)
+ user.session.questions[user.session.question_num].timer_thread.start()
# Relay change
for _, other_user in pblive.data.iterate_users():
@@ -188,6 +193,11 @@ def socket_reveal_answers(question_num):
flask_socketio.emit('update', render_question_admin(user.session, user.session.question_num), room=flask.request.sid)
def do_goto_question(session, question_num):
+ # Cleanup old question
+ if isinstance(session.questions[session.question_num], pblive.data.SpeedQuestion):
+ if session.questions[session.question_num].timer_thread is not None:
+ session.questions[session.question_num].timer_thread.stop()
+
session.question_num = question_num
# Do work for some questions
diff --git a/pblive/templates/question_mcq.html b/pblive/templates/question_mcq.html
index ed612a5..a833a1f 100644
--- a/pblive/templates/question_mcq.html
+++ b/pblive/templates/question_mcq.html
@@ -19,9 +19,9 @@
{% extends 'question.html' %}
{% block base %}
- <div class="ui doubling eight column grid">
+ <div>
{% for answer in session.questions[question_num].answers %}
- <div class="column"><button class="ui button{% if answer == user.answers[question_num] %} primary{% endif %}" onclick="socket.emit('answer', {{ question_num }}, '{{ answer }}');">{{ answer }}</button></div>
+ <button class="ui button{% if answer == user.answers[question_num] %} primary{% endif %}" onclick="socket.emit('answer', {{ question_num }}, '{{ answer }}');">{{ answer }}</button>
{% endfor %}
</div>
{% endblock %}
diff --git a/pblive/templates/question_speed.html b/pblive/templates/question_speed.html
index fb8a687..2a45395 100644
--- a/pblive/templates/question_speed.html
+++ b/pblive/templates/question_speed.html
@@ -19,12 +19,12 @@
{% extends 'question.html' %}
{% block base %}
- <div class="ui doubling eight column grid">
+ <div>
{% for answer in session.questions[question_num].answers %}
- <div class="column"><button class="ui button{% if answer == user.answers[question_num] %} primary{% endif %}" onclick="socket.emit('answer', {{ question_num }}, '{{ answer }}');">{{ answer }}</button></div>
+ <button class="ui button{% if answer == user.answers[question_num] %} primary{% endif %}" onclick="socket.emit('answer', {{ question_num }}, '{{ answer }}');">{{ answer }}</button>
{% endfor %}
{% if data.responses_for_question(session, question_num) > 0 %}
- <div class="column"><button class="ui negative button">Hurry!</button></div>
+ <button class="ui negative basic button">Hurry!</button>
{% endif %}
</div>
{% endblock %}
diff --git a/pblive/templates/question_speed_admin.html b/pblive/templates/question_speed_admin.html
index a43db2e..4b2696a 100644
--- a/pblive/templates/question_speed_admin.html
+++ b/pblive/templates/question_speed_admin.html
@@ -26,13 +26,7 @@
</ul>
{% if data.responses_for_question(session, question_num) > 0 %}
- <div><button class="ui negative button">Hurry!</button></div>
- {# Very dodgy! #}
- <script>
- window.setTimeout(function() {
- socket.emit('goto_question', {{ question_num + 1 }});
- }, 1500);
- </script>
+ <div style="margin-bottom: 0.5em;"><button class="ui negative basic button">Hurry!</button></div>
{% endif %}
{% endblock base %}
diff --git a/pblive/templates/semantic_base.html b/pblive/templates/semantic_base.html
index 00dd0de..fa43fcd 100644
--- a/pblive/templates/semantic_base.html
+++ b/pblive/templates/semantic_base.html
@@ -36,6 +36,7 @@
<div id="pblive-main" style="width: calc(100% - 48px); float: left;">
{% block main %}{% endblock main %}
</div>
+ <div style="clear: both;"></div>
</div>
<script src="{{ url_for('static', filename='vendor/jquery/jquery-3.1.1.min.js') }}"></script>
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.