Skip to content

Commit

Permalink
Show Peer Responses on page load if q answered
Browse files Browse the repository at this point in the history
- Hide responses if feature turned off
- Hide responses on page load if NOT answered
- Display responses is student answer valid
  • Loading branch information
Giulio Gratta committed Dec 4, 2018
1 parent a1ea7a7 commit 16430dc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
14 changes: 10 additions & 4 deletions freetextresponse/freetextresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def student_view(self, context={}):
(Fragment): The HTML Fragment for this XBlock, which determines the
general frame of the FreeTextResponse Question.
"""

self.runtime.service(self, 'i18n')
context.update(
{
Expand All @@ -294,7 +293,7 @@ def student_view(self, context={}):
'visibility_class': self._get_indicator_visibility_class(),
'word_count_message': self._get_word_count_message(),
'display_other_responses': self.display_other_student_responses,
'other_responses': [],
'other_responses': self.get_other_answers(),
}
)
template = get_template('freetextresponse_view.html')
Expand Down Expand Up @@ -602,7 +601,7 @@ def submit(self, data, suffix=''):
'user_alert': self._get_user_alert(
ignore_attempts=True,
),
'other_responses': self.get_other_answers(self.get_student_id()),
'other_responses': self.get_other_answers(),
'display_other_responses': self.display_other_student_responses,
'visibility_class': self._get_indicator_visibility_class(),
}
Expand Down Expand Up @@ -654,12 +653,19 @@ def store_student_response(self):
# MAX_RESPONSES answers if their answer is in the pool.
self.displayable_answers = self.displayable_answers[-(MAX_RESPONSES+1):]

def get_other_answers(self, student_id):
def get_other_answers(self):
"""
Returns at most MAX_RESPONSES answers from the pool.
Does not return answers the student had submitted.
"""
student_id = self.get_student_id()
display_other_responses = self.display_other_student_responses
shouldnt_show_other_responses = not display_other_responses
student_answer_incorrect = self._determine_credit() == Credit.zero
if student_answer_incorrect or shouldnt_show_other_responses:
return []

return_list = [
response
for response in self.displayable_answers
Expand Down
4 changes: 3 additions & 1 deletion freetextresponse/public/view.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@
}

.freetextresponse .responses-box {
display: none;
margin-top: 10px;
padding: 10px;
background: #fbfbfb;
border: 1px solid #ddd;
}
.freetextresponse .responses-box.hidden {
display: none;
}

.freetextresponse .responses-title {
margin-left: 15px;
Expand Down
22 changes: 14 additions & 8 deletions freetextresponse/public/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ function FreeTextResponseView(runtime, element) {
userAlertMessage.text(response.user_alert);
buttonSave.addClass(response.nodisplay_class);
setClassForTextAreaParent(response.indicator_class);
if (!response.user_alert && response.display_other_responses) {
var responseHTML = get_student_responses_html(response.other_responses);
if (responseHTML) {
responseList.html(responseHTML);
}
$element.find('.responses-box').show();
}
displayResponsesIfAnswered(response);

$xblocksContainer.data(cachedAnswerId, $element.find('.student_answer').val());
$xblocksContainer.data(problemProgressId, response.problem_progress);
Expand All @@ -91,17 +85,29 @@ function FreeTextResponseView(runtime, element) {
return false;
});

function get_student_responses_html(responses) {
function getStudentResponsesHtml(responses) {
/*
Convert list of responses to a html string to add to the page
*/
var html = '';
var noResponsesText = responseList.data('noresponse');
responses.forEach(function(item) {
html += '<li class="other-student-responses">' + item.answer + '</li>';
});
html = html || '<li class="no-response">' + noResponsesText + '</li>';
return html;
}

function displayResponsesIfAnswered(response) {
if (!response.display_other_responses) {
$element.find('.responses-box').addClass('hidden');
return;
}
var responseHTML = getStudentResponsesHtml(response.other_responses);
responseList.html(responseHTML);
$element.find('.responses-box').removeClass('hidden');
}

buttonSave.on('click', function () {
buttonSave.text(buttonSave[0].dataset.checking);
runtime.notify('save', {
Expand Down
8 changes: 6 additions & 2 deletions freetextresponse/templates/freetextresponse_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ <h2 class="problem-header">{{ display_name }}</h2>
</div>
<div class="capa_alert user_alert">{{ user_alert }}</div>
{% if display_other_responses %}
<div class="responses-box">
<div class="responses-box {% if not student_answer %}hidden{% endif %}">
<button class="hide-button">
<span class="hide">Hide</span>
<span class="show">Show</span>
<span class="sr">peer responses</span>
</button>
<p class="responses-title">Submissions by others</p>
<ul class="response-list">
<li class="no-response">No responses to show at this time</li>
{% for response in other_responses %}
<li class="other-student-responses">{{ response.answer }}</li>
{% empty %}
<li class="no-response">No responses to show at this time</li>
{% endfor %}
</ul>
</div>
{% endif %}
Expand Down

0 comments on commit 16430dc

Please sign in to comment.