Skip to content

Commit 0847172

Browse files
committed
add release after class PI button on final question of sync PI
1 parent f6e1af6 commit 0847172

2 files changed

Lines changed: 56 additions & 2 deletions

File tree

bases/rsptx/web2py_server/applications/runestone/controllers/peer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,25 @@ def dashboard():
143143
is_last=done,
144144
lti=is_lti,
145145
has_vote1=has_vote1,
146+
peer_async_visible=assignment.peer_async_visible or False,
146147
**course_attrs,
147148
)
148149

149150

151+
@auth.requires(
152+
lambda: verifyInstructorStatus(auth.user.course_id, auth.user),
153+
requires_login=True,
154+
)
155+
def toggle_async():
156+
response.headers["content-type"] = "application/json"
157+
assignment_id = request.vars.assignment_id
158+
assignment = db(db.assignments.id == assignment_id).select().first()
159+
new_value = not (assignment.peer_async_visible or False)
160+
db(db.assignments.id == assignment_id).update(peer_async_visible=new_value)
161+
db.commit()
162+
return json.dumps({"peer_async_visible": new_value})
163+
164+
150165
def extra():
151166
assignment_id = request.vars.assignment_id
152167
current_question, done, idx = _get_current_question(assignment_id, False)

bases/rsptx/web2py_server/applications/runestone/views/peer/dashboard.html

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ <h3>Question {{ =current_qnum }} of {{ =num_questions }}</h3>
6161
</div>
6262

6363
<div id="pi-assignment-navigation">
64+
{{ if current_qnum < num_questions: }}
6465
<button
6566
type="submit"
6667
id="nextq"
@@ -70,6 +71,19 @@ <h3>Question {{ =current_qnum }} of {{ =num_questions }}</h3>
7071
>
7172
Next Question
7273
</button>
74+
{{ else: }}
75+
<div id="asyncBtnArea" style="display:inline-block;">
76+
<button
77+
type="button"
78+
id="toggleAsyncBtn"
79+
class="btn btn-info" {{ if peer_async_visible: }}style="background-color:#a3d4ec; border-color:#a3d4ec; color:#fff;"{{ pass }}
80+
onclick="showAsyncConfirm()"
81+
style="margin-right: 4px;"
82+
>
83+
{{ if peer_async_visible: }}Undo After-Class Release{{ else: }}Release After-Class PI{{ pass }}
84+
</button>
85+
</div>
86+
{{ pass }}
7387
<button
7488
type="submit"
7589
id="restart"
@@ -349,8 +363,33 @@ <h3>Question {{ =current_qnum }} of {{ =num_questions }}</h3>
349363
var mess_count = 0;
350364
var answerCount = 0;
351365
var done = {{=is_last }}
352-
if (done) {
353-
document.getElementById("nextq").disabled = true;
366+
367+
var asyncReleased = {{=peer_async_visible}};
368+
369+
function showAsyncConfirm() {
370+
var area = document.getElementById("asyncBtnArea");
371+
var msg = asyncReleased
372+
? "Undo the after-class PI release?"
373+
: "Release after-class PI questions to students?";
374+
area.innerHTML = `
375+
<span style="margin-right:6px; font-weight:bold;">${msg}</span>
376+
<button type="button" class="btn btn-sm btn-default" onclick="confirmToggleAsync()" style="margin-right:4px;">Yes</button>
377+
<button type="button" class="btn btn-sm btn-default" onclick="cancelAsyncConfirm()">Cancel</button>
378+
`;
379+
}
380+
381+
function cancelAsyncConfirm() {
382+
var area = document.getElementById("asyncBtnArea");
383+
var label = asyncReleased ? "Undo After-Class Release" : "Release After-Class PI";
384+
var extraStyle = asyncReleased ? 'style="background-color:#a3d4ec; border-color:#a3d4ec; color:#fff; margin-right:4px;"' : 'style="margin-right:4px;"';
385+
area.innerHTML = `<button type="button" id="toggleAsyncBtn" class="btn btn-info" onclick="showAsyncConfirm()" ${extraStyle}>${label}</button>`;
386+
}
387+
388+
async function confirmToggleAsync() {
389+
var resp = await fetch("/runestone/peer/toggle_async?assignment_id={{=assignment_id}}", { method: "POST" });
390+
var data = await resp.json();
391+
asyncReleased = data.peer_async_visible;
392+
cancelAsyncConfirm();
354393
}
355394
</script>
356395
{{ end }}

0 commit comments

Comments
 (0)