Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: aggregated vote value is not updated till refresh #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions feedback/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,7 @@ def student_view(self, context=None): # pylint: disable=unused-argument
self.prompt_choice = random.randint(0, len(self.prompts) - 1)
prompt = self.get_prompt()

# Staff see vote totals, so we have slightly different HTML here.
if self.vote_aggregate and (self.show_aggregate_to_students or self.is_staff()):
item_templates_file = "templates/html/staff_item.html"
else:
item_templates_file = "templates/html/scale_item.html"
item_templates_file = "templates/html/scale_item.html"

# We have five Likert fields right now, but we'd like this to
# be dynamic
Expand Down Expand Up @@ -238,6 +234,7 @@ def get_url(icon_type, i):
'vote_cnt': vote_cnt,
'ina_icon': ina_icon,
'act_icon': act_icon,
'is_display_vote_cnt': self.vote_aggregate and (self.show_aggregate_to_students or self.is_staff()),
},
i18n_service=self.runtime.service(self, 'i18n'),
) for
Expand Down Expand Up @@ -411,7 +408,7 @@ def feedback(self, data, suffix=''): # pylint: disable=unused-argument
"vote": self.user_vote
})

if self.is_staff():
if self.show_aggregate_to_students or self.is_staff():
response['aggregate'] = self.vote_aggregate

return response
Expand Down
92 changes: 49 additions & 43 deletions feedback/static/js/src/feedback.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
/* Javascript for FeedbackXBlock. */
// Work-around so we can log in edx-platform, but not fail in Workbench
if (typeof Logger === 'undefined') {
var Logger = {
log: function(a, b) {
console.log(JSON.stringify(a)+"/"+JSON.stringify(a));
}
};
var Logger = {
log: function (a) {
console.log(JSON.stringify(a) + '/' + JSON.stringify(a));
}
};
}

function FeedbackXBlock(runtime, element) {
function likert_vote() {
var vote = 0;
if ($(".feedback_radio:checked", element).length === 0) {
vote = -1;
} else {
vote = parseInt($(".feedback_radio:checked", element).attr("data-id").split("_")[1]);
}
return vote;
function getLikedVote() {
if ($('.feedback_radio:checked', element).length === 0) {
return -1;
}

function feedback() {
return $(".feedback_freeform_area", element).val();
return parseInt($('.feedback_radio:checked', element).attr('data-id').split('_')[1]);
}

function getFeedbackMessage() {
return $('.feedback_freeform_area', element).val();
}

function updateVoteCount(data) {
if (data.success && data.aggregate && $('.feedback_vote_count', element).length) {
$('.feedback_vote_count', element).each(function (idx) {
$(this).text('(' + data.aggregate[idx] + ')');
});
}
}

function submit_feedback(freeform, vote) {
var feedback = {};
if(freeform) {
feedback['freeform'] = freeform;
}
if(vote != -1) {
feedback['vote'] = vote;
}

Logger.log("edx.feedbackxblock.submitted", feedback);
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'feedback'),
data: JSON.stringify(feedback),
success: function(data) {
$('.feedback_thank_you', element).text("");
$('.feedback_thank_you', element).text(data.response);
}
});
function submit_feedback(freeform, vote) {
var feedback = {};
if (freeform) {
feedback['freeform'] = freeform;
}
if (vote !== -1) {
feedback['vote'] = vote;
}

$(".feedback_submit_feedback", element).click(function(eventObject) {
submit_feedback(feedback(), -1);
Logger.log('edx.feedbackxblock.submitted', feedback);
$.ajax({
type: 'POST',
url: runtime.handlerUrl(element, 'feedback'),
data: JSON.stringify(feedback),
success: function (data) {
$('.feedback_thank_you', element).text(data.response || '');
updateVoteCount(data);
}
});
}

$('.feedback_radio', element).change(function(eventObject) {
Logger.log("edx.feedbackxblock.likert_changed", {"vote":likert_vote()});
submit_feedback(false, likert_vote());
});
$('.feedback_submit_feedback', element).click(function () {
submit_feedback(getFeedbackMessage(), -1);
});

$('.feedback_freeform_area', element).change(function(eventObject) {
Logger.log("edx.feedbackxblock.freeform_changed", {"freeform":feedback()});
});
$('.feedback_radio', element).change(function () {
Logger.log('edx.feedbackxblock.likert_changed', { vote: getLikedVote() });
submit_feedback(false, getLikedVote());
});

$('.feedback_freeform_area', element).change(function () {
Logger.log('edx.feedbackxblock.freeform_changed', { freeform: getFeedbackMessage() });
});
}
2 changes: 1 addition & 1 deletion feedback/templates/html/feedback.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<label class="feedback_header" for="feedback_freeform_textarea">{% trans freeform_prompt %}</label>
</div>
<div class="feedback_freeform_input">
<textarea name="feedback_freeform_textarea" class="feedback_freeform_area" rows="6" cols="45" placeholder="{% trans placeholder %}">{% trans self.user_freeform %}</textarea>
<textarea id="feedback_freeform_textarea" name="feedback_freeform_textarea" class="feedback_freeform_area" rows="6" cols="45" placeholder="{% trans placeholder %}">{% trans self.user_freeform %}</textarea>
<div class="feedback_thank_you" aria-live=polite>{{response}}</div>
</div>
<button type="submit" class="feedback_submit_feedback">{% trans "Submit Feedback" %}</button>
Expand Down
4 changes: 4 additions & 0 deletions feedback/templates/html/scale_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
</span>
<br/>
<span>{% trans scale_text %}</span>
{% if is_display_vote_cnt %}
<br/>
<span class="feedback_vote_count">({{vote_cnt}})</span>
{% endif %}
</label>
</div>
17 changes: 0 additions & 17 deletions feedback/templates/html/staff_item.html

This file was deleted.

Loading