Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit c59d186

Browse files
committed
Clean - respond to group suggestions
* change button text and add feedback after answering * make countdown more obvious * fix duplicate peers * reset question for vote 2
1 parent cbfe623 commit c59d186

File tree

3 files changed

+59
-30
lines changed

3 files changed

+59
-30
lines changed

controllers/peer.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _get_current_question(assignment_id, get_next):
9191
idx = assignment.current_index
9292

9393
a_qs = db(db.assignment_questions.assignment_id == assignment_id).select(
94-
orderby=db.assignment_questions.sorting_priority
94+
orderby=[db.assignment_questions.sorting_priority, db.assignment_questions.id]
9595
)
9696
logger.debug(f"idx = {idx} len of qs = {len(a_qs)}")
9797
if idx > len(a_qs) - 1:
@@ -310,21 +310,24 @@ def _broadcast_peer_answers(correct, incorrect):
310310
for p1, p2 in r.hgetall(f"partnerdb_{auth.user.course_name}").items():
311311
p1 = p1.decode("utf8")
312312
partner_list = json.loads(p2)
313+
pdict = {}
313314
for p2 in partner_list:
314315
ans = answers.get(p2, None)
315-
# create a message to p1 to put into the publisher queue
316-
# it seems odd to not have a to field in the message...
317-
# but it is not necessary as the client can figure out how it is to
318-
# based on who it is from.
319-
mess = {
320-
"type": "control",
321-
"from": p2,
322-
"message": "enableChat",
323-
"broadcast": False,
324-
"answer": ans,
325-
"course_name": auth.user.course_name,
326-
}
327-
r.publish("peermessages", json.dumps(mess))
316+
pdict[p2] = ans
317+
# create a message from p1 to put into the publisher queue
318+
# it seems odd to not have a to field in the message...
319+
# but it is not necessary as the client can figure out how it is to
320+
# based on who it is from.
321+
mess = {
322+
"type": "control",
323+
"from": p1,
324+
"to": p1,
325+
"message": "enableChat",
326+
"broadcast": False,
327+
"answer": json.dumps(pdict),
328+
"course_name": auth.user.course_name,
329+
}
330+
r.publish("peermessages", json.dumps(mess))
328331

329332

330333
def clear_pairs():

static/js/peer.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ function connect(event) {
4141
let count = 10;
4242
let itimerid = setInterval(async function () {
4343
if (count > 0) {
44+
messarea.style.color = "red";
4445
messarea.innerHTML = `<h3>Finish Up only ${count} seconds remaining</h3>`;
4546
count = count - 1;
4647
} else {
47-
messarea.innerHTML = `<h3>Please Give an explanation for your answer</h3><p>Then discuss your answer with your partner</p>`;
48+
messarea.style.color = "black";
49+
// hide the discussion
50+
let discPanel = document.getElementById("discussion_panel");
51+
if (discPanel) {
52+
discPanel.style.display = "none";
53+
}
54+
messarea.innerHTML = `<h3>Please Give an explanation for your answer</h3><p>Then discuss your answer with your group members</p>`;
4855
window.mcList[currentQuestion].submitButton.disabled = true;
4956
window.mcList[currentQuestion].disableInteraction();
5057
clearInterval(itimerid);
@@ -65,9 +72,11 @@ function connect(event) {
6572
break;
6673
case "enableVote":
6774
window.mcList[currentQuestion].submitButton.disabled = false;
75+
window.mcList[currentQuestion].submitButton.innerHTML = "Submit";
6876
window.mcList[currentQuestion].enableInteraction();
6977
messarea = document.getElementById("imessage");
7078
messarea.innerHTML = `<h3>Time to make your 2nd vote</h3>`;
79+
$("[type=radio]").prop("checked", false);
7180
break;
7281
case "enableNext":
7382
let butt = document.getElementById("nextqbutton");
@@ -81,16 +90,22 @@ function connect(event) {
8190
discPanel.style.display = "block";
8291
}
8392
let peerlist = document.getElementById("peerlist");
84-
let newpeer = document.createElement("p");
8593
const ordA = 65;
86-
let currAnswer = String.fromCharCode(ordA + parseInt(mess.answer));
87-
newpeer.innerHTML = `Your partner, ${mess.from}, answered ${currAnswer}`;
88-
peerlist.appendChild(newpeer);
94+
adict = JSON.parse(mess.answer);
8995
let peersel = document.getElementById("peersel");
90-
let peeropt = document.createElement("option");
91-
peeropt.value = mess.from;
92-
peeropt.innerHTML = mess.from;
93-
peersel.appendChild(peeropt);
96+
for (const key in adict) {
97+
let currAnswer = String.fromCharCode(ordA + adict[key]);
98+
let newpeer = document.createElement("p");
99+
newpeer.innerHTML = `${key} answered ${currAnswer}`;
100+
peerlist.appendChild(newpeer);
101+
let peeropt = document.createElement("option");
102+
peeropt.value = key;
103+
peeropt.innerHTML = key;
104+
peersel.appendChild(peeropt);
105+
peersel.addEventListener("change", function () {
106+
$(".ratingradio").prop("checked", false);
107+
});
108+
}
94109
break;
95110
default:
96111
console.log("unknown control message");

views/peer/peer_question.html

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ <h2>Peer Instruction Question</h2>
2727
{{=XML(current_question['htmlsrc'])}}
2828
</div>
2929
<div id="discussion_panel" class='col-md-6' style="display: none">
30-
<p>Your first answer <span id="first_answer"></span></p>
30+
<p>Your answer <span id="first_answer"></span></p>
3131
<div id="peerlist">
3232
</div>
33-
<p>Please explain your answer to your partner(s)</p>
34-
<textarea id="messageText" rows="2" cols="33">
33+
<p>Please discuss the answers with your group members</p>
34+
<textarea id="messageText" rows="2" cols="40">
3535
</textarea>
3636
<button id="sendpeermsg" type="button" onclick="sendMessage()">Send</button>
3737
<div>
@@ -43,13 +43,13 @@ <h2>Peer Instruction Question</h2>
4343
<div class="form-group">
4444
Please provide a confidential rating of <select id="peersel" name="peercel"></select>
4545
peer's explanation<br />
46-
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="poor"
46+
<input class="form-check-input ratingradio" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="poor"
4747
onclick="ratePeer(this)">
4848
<label class="form-check-label" for="inlineRadio1">Poor</label>
49-
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="good"
49+
<input class="form-check-input ratingradio" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="good"
5050
onclick="ratePeer(this)">
5151
<label class="form-check-label" for="inlineRadio2">Good</label>
52-
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio3"
52+
<input class="form-check-input ratingradio" type="radio" name="inlineRadioOptions" id="inlineRadio3"
5353
value="excellent" onclick="ratePeer(this)">
5454
<label class="form-check-label" for="inlineRadio3">Excellent</label>
5555
</div>
@@ -64,7 +64,18 @@ <h2>Peer Instruction Question</h2>
6464
document.addEventListener("DOMContentLoaded", function (event) {
6565
setTimeout(connect, 1000);
6666
});
67-
67+
$(document).bind("runestone:login-complete", function () {
68+
setTimeout(function() {
69+
$("[name='do answer']").text("Submit")
70+
$("[name='do answer']").click(function() {
71+
let currentText = $(this).text();
72+
if (currentText.indexOf("Thanks") > 0 ) {
73+
$(this).text("Submit")
74+
} else {
75+
$(this).text("Thanks, your answer is recorded.")}
76+
})
77+
}, 1000);
78+
})
6879
</script>
6980

7081
{{ end }}

0 commit comments

Comments
 (0)