updates
Browse files- app.py +27 -3
- static/script.js +14 -0
app.py
CHANGED
@@ -65,21 +65,34 @@ def load_quiz_old(data):
|
|
65 |
else:
|
66 |
emit('quiz_loaded', {"success": False}, room=request.sid)
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
@socketio.on('load_quiz')
|
69 |
def load_quiz(data):
|
70 |
-
global selected_questions
|
71 |
exam_name = data['exam_name']
|
|
|
72 |
selected_questions = backend.select_exam(exam_name)
|
73 |
if selected_questions:
|
74 |
num_questions = len(selected_questions)
|
|
|
75 |
emit('quiz_loaded', {"success": True, "num_questions": num_questions}, room=request.sid)
|
76 |
else:
|
77 |
emit('quiz_loaded', {"success": False}, room=request.sid)
|
78 |
|
79 |
|
80 |
|
81 |
-
|
82 |
-
def
|
83 |
if participants and selected_questions:
|
84 |
current_question['started'] = True
|
85 |
emit('new_question', selected_questions[current_question['index']], room='quiz')
|
@@ -87,6 +100,17 @@ def start_quiz():
|
|
87 |
emit('new_question', selected_questions[current_question['index']], room=request.sid)
|
88 |
emit('enable_end_quiz', room=request.sid) # Enable "End Quiz" for the host
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
@socketio.on('restart_quiz')
|
91 |
def restart_quiz():
|
92 |
reset_quiz()
|
|
|
65 |
else:
|
66 |
emit('quiz_loaded', {"success": False}, room=request.sid)
|
67 |
|
68 |
+
#@socketio.on('load_quiz')
|
69 |
+
def load_quiz_new1(data):
|
70 |
+
global selected_questions
|
71 |
+
exam_name = data['exam_name']
|
72 |
+
selected_questions = backend.select_exam(exam_name)
|
73 |
+
if selected_questions:
|
74 |
+
num_questions = len(selected_questions)
|
75 |
+
emit('quiz_loaded', {"success": True, "num_questions": num_questions}, room=request.sid)
|
76 |
+
else:
|
77 |
+
emit('quiz_loaded', {"success": False}, room=request.sid)
|
78 |
+
|
79 |
@socketio.on('load_quiz')
|
80 |
def load_quiz(data):
|
81 |
+
global selected_questions, current_question
|
82 |
exam_name = data['exam_name']
|
83 |
+
start_question = data.get('start_question', 1) - 1 # Default to question 1 if not provided
|
84 |
selected_questions = backend.select_exam(exam_name)
|
85 |
if selected_questions:
|
86 |
num_questions = len(selected_questions)
|
87 |
+
current_question['index'] = start_question # Set the starting question index
|
88 |
emit('quiz_loaded', {"success": True, "num_questions": num_questions}, room=request.sid)
|
89 |
else:
|
90 |
emit('quiz_loaded', {"success": False}, room=request.sid)
|
91 |
|
92 |
|
93 |
|
94 |
+
#@socketio.on('start_quiz')
|
95 |
+
def start_quiz_old():
|
96 |
if participants and selected_questions:
|
97 |
current_question['started'] = True
|
98 |
emit('new_question', selected_questions[current_question['index']], room='quiz')
|
|
|
100 |
emit('new_question', selected_questions[current_question['index']], room=request.sid)
|
101 |
emit('enable_end_quiz', room=request.sid) # Enable "End Quiz" for the host
|
102 |
|
103 |
+
@socketio.on('start_quiz')
|
104 |
+
def start_quiz():
|
105 |
+
if participants and selected_questions:
|
106 |
+
current_question['started'] = True
|
107 |
+
index = current_question['index']
|
108 |
+
emit('new_question', selected_questions[index], room='quiz')
|
109 |
+
# Also emit the question to the host
|
110 |
+
emit('new_question', selected_questions[index], room=request.sid)
|
111 |
+
emit('enable_end_quiz', room=request.sid) # Enable "End Quiz" for the host
|
112 |
+
|
113 |
+
|
114 |
@socketio.on('restart_quiz')
|
115 |
def restart_quiz():
|
116 |
reset_quiz()
|
static/script.js
CHANGED
@@ -29,6 +29,17 @@ function selectExam() {
|
|
29 |
document.getElementById('question-start-display').textContent = `Starting from question ${startQuestion}.`;
|
30 |
}
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
function loadQuiz() {
|
33 |
const examName = document.getElementById('exam-selector').value;
|
34 |
const startQuestion = parseInt(document.getElementById('start-question-number').value, 10);
|
@@ -40,6 +51,9 @@ function loadQuiz() {
|
|
40 |
|
41 |
socket.emit('load_quiz', { exam_name: examName, start_question: startQuestion });
|
42 |
}
|
|
|
|
|
|
|
43 |
function updateSliderValue(value) {
|
44 |
document.getElementById('start-question').value = value;
|
45 |
document.getElementById('start-question-number').value = value;
|
|
|
29 |
document.getElementById('question-start-display').textContent = `Starting from question ${startQuestion}.`;
|
30 |
}
|
31 |
|
32 |
+
function loadQuiz_old() {
|
33 |
+
const examName = document.getElementById('exam-selector').value;
|
34 |
+
const startQuestion = parseInt(document.getElementById('start-question-number').value, 10);
|
35 |
+
|
36 |
+
if (!examName) {
|
37 |
+
alert("Please select an exam first.");
|
38 |
+
return;
|
39 |
+
}
|
40 |
+
|
41 |
+
socket.emit('load_quiz', { exam_name: examName, start_question: startQuestion });
|
42 |
+
}
|
43 |
function loadQuiz() {
|
44 |
const examName = document.getElementById('exam-selector').value;
|
45 |
const startQuestion = parseInt(document.getElementById('start-question-number').value, 10);
|
|
|
51 |
|
52 |
socket.emit('load_quiz', { exam_name: examName, start_question: startQuestion });
|
53 |
}
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
function updateSliderValue(value) {
|
58 |
document.getElementById('start-question').value = value;
|
59 |
document.getElementById('start-question-number').value = value;
|