Commit 308ab901 by Sola Committed by Piotr Mitros

flagged hint moderation functional

parent b0c13118
...@@ -215,12 +215,15 @@ class CrowdXBlock(XBlock): ...@@ -215,12 +215,15 @@ class CrowdXBlock(XBlock):
for answer_keys in self.hint_database: for answer_keys in self.hint_database:
if str(len(self.hint_database[str(answer_keys)])) != str(0): if str(len(self.hint_database[str(answer_keys)])) != str(0):
for hints in self.hint_database[str(answer_keys)]: for hints in self.hint_database[str(answer_keys)]:
if list(self.Flagged) != 0:
for flagged_hints in self.Flagged: for flagged_hints in self.Flagged:
if str(hints) != self.Flagged[flagged_hints]: if str(hints) != self.Flagged[flagged_hints]:
feedback_data[str(hints)] = str(answer_keys) feedback_data[str(hints)] = str(answer_keys)
else: else:
feedback_data[str(hints)] = str("Flagged") feedback_data[str(hints)] = str("Flagged")
else: else:
feedback_data[str(hints)] = str(answer_keys)
else:
feedback_data[str("There are no hints for" + " " + str(answer_keys))] = str(answer_keys) feedback_data[str("There are no hints for" + " " + str(answer_keys))] = str(answer_keys)
elif len(self.WrongAnswers) == 0: elif len(self.WrongAnswers) == 0:
return return
...@@ -313,21 +316,34 @@ class CrowdXBlock(XBlock): ...@@ -313,21 +316,34 @@ class CrowdXBlock(XBlock):
# might arise due to certain symbols. I don't think I have this fully working but am not sure. # might arise due to certain symbols. I don't think I have this fully working but am not sure.
data_rating = data['student_rating'] data_rating = data['student_rating']
data_hint = data['used_hint'] data_hint = data['used_hint']
answer_data = self.remove_symbols(answer_data) if str(data['student_rating']) == str(2):
for flagged_hints in self.Flagged:
if self.Flagged[str(flagged_hints)] == data_hint:
del self.Flagged[flagged_hints]
return {'rating': 'unflagged'}
if str(data['student_rating']) == str(-2):
for flagged_answer in self.Flagged:
if self.Flagged[flagged_answer] == data_hint:
temporary_dict = str(self.hint_database[str(flagged_answer)])
temporary_dict = (ast.literal_eval(temporary_dict))
temporary_dict.pop(data_hint, None)
self.hint_database[str(flagged_answer)] = temporary_dict
del self.Flagged[flagged_answer]
return {'rating': 'removed'}
if str(data['student_rating']) == str(0): if str(data['student_rating']) == str(0):
# if student flagged hint # if student flagged hint
self.hint_flagged(data['used_hint'], answer_data) self.hint_flagged(data['used_hint'], answer_data)
return {"rating": 'thiswasflagged', 'used_hint': data_hint} return {"rating": 'thiswasflagged', 'used_hint': data_hint}
if str(answer_data) not in self.Voted: if str(data_hint) not in self.Voted:
self.Voted.append(str(answer_data)) # add data to Voted to prevent multiple votes self.Voted.append(str(data_hint)) # add data to Voted to prevent multiple votes
rating = self.change_rating(data_hint, int(data_rating), answer_data) # change hint rating rating = self.change_rating(data_hint, int(data_rating), answer_data) # change hint rating
if str(rating) == str(0): if str(rating) == str(0):
# if the rating is "0", return "zzeerroo" instead. "0" showed up as "null" in JS # if the rating is "0", return "zzeerroo" instead. "0" showed up as "null" in JS
return {"rating": str('zzeerroo'), 'used_hint': data_hint} return {"rating": str(0), 'used_hint': data_hint}
else: else:
return {"rating": str(rating), 'used_hint': data_hint} return {"rating": str(rating), 'used_hint': data_hint}
else: else:
return {"rating": str('You have already voted on this hint!'), 'used_hint': data_hint} return {"rating": str('voted'), 'used_hint': data_hint}
def hint_flagged(self, data_hint, answer_data): def hint_flagged(self, data_hint, answer_data):
""" """
......
...@@ -99,21 +99,20 @@ function CrowdXBlock(runtime, element){ ...@@ -99,21 +99,20 @@ function CrowdXBlock(runtime, element){
$(".student_answer", element).each(function(){ $(".student_answer", element).each(function(){
if ($(this).find("span").text() == result.student_answer){ if ($(this).find("span").text() == result.student_answer){
$(this).append("<div class=\"hint_value\" value = \"" + result.hint_used + "\">" + $(this).append("<div class=\"hint_value\" value = \"" + result.hint_used + "\">" +
"<div role=\"button\" class=\"upvote_hint\" data-rate=\"1\" data-icon=\"arrow-u\" aria-label=\"upvote\"><b>↑</b></div>" + "<div role=\"button\" class=\"rate_hint\" data-rate=\"1\" data-icon=\"arrow-u\" aria-label=\"upvote\"><b>↑</b></div>" +
"<div class = \"rating\">" + result.rating + "</div><div class=\"hint_used\">" + ""+result.hint_used+"</div>" + "<div class = \"rating\">" + result.rating + "</div><div class=\"hint_used\">" + ""+result.hint_used+"</div>" +
"<div role=\"button\" class=\"downvote_hint\" data-rate=\"-1\" aria-label=\"downvote\"><b>↓</b></div> </div>"); "<div role=\"button\" class=\"rate_hint\" data-rate=\"-1\" aria-label=\"downvote\"><b>↓</b></div> </div>");
} }
}); });
} }
function appendFlagged(result){ function appendFlagged(result){
$(".flagged_hints", element).append("<div class=\"hint_value\" value = \"" + result.hint_used + "\">" + $(".flagged_hints", element).append("<div class=\"hint_value\" value = \"" + result.hint_used + "\">" +
"<div role=\"button\" class=\"upvote_hint\" data-rate=\"1\" data-icon=\"arrow-u\" aria-label=\"upvote\"><b>↑</b></div>" + "<div role=\"button\" class=\"staff_rate\" data-rate=\"2\" aria-label=\"unflag\"><b>O</b></div>" +
"<div class = \"rating\">" + result.rating + "</div><div class=\"hint_used\">" + ""+result.hint_used+"</div>" + "<div class=\"hint_used\">" + ""+result.hint_used+"</div>" +
"<div role=\"button\" class=\"downvote_hint\" data-rate=\"-1\" aria-label=\"downvote\"><b>↓</b></div> </div>"); "<div role=\"button\" class=\"staff_rate\" data-rate=\"-2\" aria-label=\"remove\"><b>X</b></div> </div>");
} }
function getFeedback(result){ function getFeedback(result){
if(isStaff){ if(isStaff){
$('.feedback', element).append("<div class=\"flagged_hints\"><span>Flagged</span></div>"); $('.feedback', element).append("<div class=\"flagged_hints\"><span>Flagged</span></div>");
...@@ -125,11 +124,34 @@ function CrowdXBlock(runtime, element){ ...@@ -125,11 +124,34 @@ function CrowdXBlock(runtime, element){
hint_used = index; hint_used = index;
//check if div for a student answer already exists (if length = 0, it doesn't) //check if div for a student answer already exists (if length = 0, it doesn't)
if(student_answer != "Flagged"){ if(student_answer != "Flagged"){
if($(".student_answer", element).find("span").text() != student_answer){ if($('.student_answer', element).length == 0){
$('.feedback', element).append("<div class=\"student_answer\"><span>"+student_answer+"</span></div>"); $('.feedback', element).append("<div class=\"student_answer\"><span><b>"+student_answer+"</b></span>"+
"<div><input type =\"button\" class=\"submit_hint\" value=\"Submit a new hint for this answer.\" </input></div></div>");
} }
else {
//cycle through each .student_answer to check if this answer has been accounted for
answerShown = false;
$(".student_answer", element).each(function(){
console.log($(this).find("span").text());
if($(this).find("span").text() == student_answer){
answerShown = true;
} }
if(student_answer != "Flagged"){ });
if (answerShown == false){
$('.feedback', element).append("<div class=\"student_answer\"><span><b>"+student_answer+"</b></span>"+
"<div><input type =\"button\" class=\"submit_hint\"value=\"Submit a new hint for this answer.\" </input></div></div>");
}
}
}
//check first part of the hint to see if a hint was actually used
if(hint_used.substring(0, 22) == "There are no hints for"){
$(".student_answer", element).each(function(){
if ($(this).find("span").text() == student_answer){
$(this).append("<div class=\"hint_value\" value=\"There are no answer-specific hints for this answer.\"></div>");
}
});
}
else if(student_answer != "Flagged"){
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'get_ratings'), url: runtime.handlerUrl(element, 'get_ratings'),
...@@ -148,28 +170,13 @@ function CrowdXBlock(runtime, element){ ...@@ -148,28 +170,13 @@ function CrowdXBlock(runtime, element){
}); });
} }
function show_ratings(result) { $(document).on('click', '.submit_hint', function(){
$.each(result, function(index, value) { student_answer = $(this).parent().parent().find("span").text();
$("."+index+"rating").append(value + " " + index); $(".student_answer", element).each(function(){
}) if ($(this).find("span").text() == student_answer){
} $(this).prepend("<p><input type=\"text\" name=\"studentinput\" class=\"math\" size=\"40\"><input type=\"button\" class=\"button\" value=\"Submit Hint\"> </p>");
$(document).on('click', '.submitbutton', function(){ //upvote
issubmittinghint = 0;
issubmitting += 1;
if(issubmitting == repeatcounter){
id = this.id;
//the id of the button is "submitbuttonfor"+student_answer
//slice to determine which answer for which a submission is being made
//this should be made more dynamic
id = id.slice(15);
//value = document.getElementById(id).getAttribute('data-value');
$('.submitbutton').show();
$('.math').remove();
$('#submit').remove();
$(this).hide();
$('.showHintsFor'+id, element).prepend("<p><input type=\"text\" name=\"studentinput\" id=\"" + id + "\" class=\"math\" size=\"40\"><input id=\"submit\" type=\"button\" data-is=\"" + id + "\" class=\"button\" value=\"Submit Hint\"> </p>");
} }
});
}) })
$(document).on('click', '#submit', function(){ $(document).on('click', '#submit', function(){
...@@ -199,25 +206,39 @@ function CrowdXBlock(runtime, element){ ...@@ -199,25 +206,39 @@ function CrowdXBlock(runtime, element){
} }
}) })
$(document).on('click', '.upvote_hint', function(){ $(document).on('click', '.rate_hint', function(){
used_hint = $(this).parent().find(".hint_used").text(); used_hint = $(this).parent().find(".hint_used").text();
student_answer = $(this).parent().parent().find("span").text(); student_answer = $(this).parent().parent().find("span").text();
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'), url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"student_rating": $(this).attr('data-rate'), "used_hint": used_hint, "student_answer": student_answer}), data: JSON.stringify({"student_rating": $(this).attr('data-rate'), "used_hint": used_hint, "student_answer": student_answer}),
success: finish success: function (result){
if(result.rating != "voted"){
$(".hint_used", element).each(function(){
if ($(this).parent().find(".hint_used").text() == used_hint && $(this).parent().parent().find("span").text() == student_answer){
$(this).parent().find('.rating').text(result.rating);
}
})
}
}
}); });
}) })
$(document).on('click', '.downvote_hint', function(){ $(document).on('click', '.staff_rate', function(){
canhint = 0; used_hint = $(this).parent().find(".hint_used").text();
id = this.id; student_answer = $(this).parent().parent().find("span").text();
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'), url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"student_rating": $(this).attr('data-rate'), "used_hint": $(this).attr('id'), "student_answer": $(this).attr('data-value')}), data: JSON.stringify({"student_rating": $(this).attr('data-rate'), "used_hint": used_hint, "student_answer": student_answer}),
success: finish success: function (result){
$('.hint_value', element).each(function(){
if($(this).attr('value') == used_hint){
$(this).remove();
}
});
}
}); });
}) })
...@@ -237,7 +258,6 @@ function CrowdXBlock(runtime, element){ ...@@ -237,7 +258,6 @@ function CrowdXBlock(runtime, element){
}); });
}) })
function finish(result){ function finish(result){
if(canhint == 0){ if(canhint == 0){
canhint = 1; canhint = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment