Commit 7b6ee71b by solashirai Committed by Piotr Mitros

small improvements

parent 6a50de30
user@olduser-VPCEB3NFX.4809:1424514334
\ No newline at end of file
...@@ -63,19 +63,6 @@ class CrowdsourceHinter(XBlock): ...@@ -63,19 +63,6 @@ class CrowdsourceHinter(XBlock):
# Setting the element in the XML file is critical for the hinter to work. # Setting the element in the XML file is critical for the hinter to work.
Element = String(default="", scope=Scope.content) Element = String(default="", scope=Scope.content)
def student_view(self, context=None):
"""
This view renders the hint view to the students. The HTML has the hints templated
in, and most of the remaining functionality is in the JavaScript.
"""
html = self.resource_string("static/html/crowdsourcehinter.html")
frag = Fragment(html)
frag.add_javascript_url('//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js')
frag.add_css(self.resource_string("static/css/crowdsourcehinter.css"))
frag.add_javascript(self.resource_string("static/js/src/crowdsourcehinter.js"))
frag.initialize_js('CrowdsourceHinter', {'hinting_element': self.Element})
return frag
def studio_view(self, context=None): def studio_view(self, context=None):
""" """
This function defines a view for editing the XBlock when embedding it in a course. It will allow This function defines a view for editing the XBlock when embedding it in a course. It will allow
...@@ -105,15 +92,18 @@ class CrowdsourceHinter(XBlock): ...@@ -105,15 +92,18 @@ class CrowdsourceHinter(XBlock):
""" """
return self.xmodule_runtime.user_is_staff return self.xmodule_runtime.user_is_staff
@XBlock.json_handler def student_view(self, context=None):
def is_user_staff(self, _data, _suffix=''):
""" """
Return whether the user is staff. This view renders the hint view to the students. The HTML has the hints templated
Returns: in, and most of the remaining functionality is in the JavaScript.
is_user_staff: indicator for whether the user is staff
""" """
result = {'is_user_staff': self.get_user_is_staff()} html = self.resource_string("static/html/crowdsourcehinter.html")
return result frag = Fragment(html)
frag.add_javascript_url('//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js')
frag.add_css(self.resource_string("static/css/crowdsourcehinter.css"))
frag.add_javascript(self.resource_string("static/js/src/crowdsourcehinter.js"))
frag.initialize_js('CrowdsourceHinter', {'hinting_element': self.Element, 'isStaff': self.Element})
return frag
@XBlock.json_handler @XBlock.json_handler
def get_hint(self, data, suffix=''): def get_hint(self, data, suffix=''):
...@@ -226,7 +216,7 @@ class CrowdsourceHinter(XBlock): ...@@ -226,7 +216,7 @@ class CrowdsourceHinter(XBlock):
# that were not used. The keys are the used hints, the values are the # that were not used. The keys are the used hints, the values are the
# corresponding incorrect answer # corresponding incorrect answer
feedback_data = {} feedback_data = {}
if data['isStaff'] == 'true': if self.get_user_is_staff():
if len(self.Reported) != 0: if len(self.Reported) != 0:
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):
...@@ -255,14 +245,6 @@ class CrowdsourceHinter(XBlock): ...@@ -255,14 +245,6 @@ class CrowdsourceHinter(XBlock):
self.Used=[] self.Used=[]
return feedback_data return feedback_data
def no_hints(self, index):
"""
This function is used when no hints exist for an answer. The feedback_data within
get_feedback is set to "there are no hints for" + " " + str(self.WrongAnswers[index])
"""
self.WrongAnswers.append(str(self.WrongAnswers[index]))
self.Used.append(str("There are no hints for" + " " + str(self.WrongAnswers[index])))
@XBlock.json_handler @XBlock.json_handler
def get_ratings(self, data, suffix=''): def get_ratings(self, data, suffix=''):
""" """
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="csh_hint"><b>{{hint}}</b></div> <div class="csh_hint"><b>{{hint}}</b></div>
</div> </div>
<div class='csh_rating_data'> <div class='csh_rating_data'>
<div role="button" class="csh_rate_hint" data-rate="upvote" data-icon="arrow-u"> <div role="button" class="csh_rate_hint" data-rate="upvote">
<b>Rate as Helpful</b> <b>Rate as Helpful</b>
</div> </div>
<div role="button" class="csh_rate_hint" data-rate="downvote"> <div role="button" class="csh_rate_hint" data-rate="downvote">
......
function CrowdsourceHinter(runtime, element, data){ function CrowdsourceHinter(runtime, element, data){
//executeHinter is used to disable the hinter after switching units in an edX course //switching units back to a previous question will make a second hinter start up.
//If the code is not made to stop running, the hinter will act up after switching from and back to //executeHinter is used to disable the hinter after switching units in an edX course.
//a certain unit.
var executeHinter = true; var executeHinter = true;
$(".crowdsourcehinter_block", element).hide(); $(".crowdsourcehinter_block", element).hide();
if(executeHinter){ if(executeHinter){
var isShowingHintFeedback = false; var isShowingHintFeedback = false;
var hinting_element; var hinting_element;
var isStaff = false; var isStaff;
var voted = false;
$(".csh_HintsToUse", element).text(""); $(".csh_HintsToUse", element).text("");
function stopScript(){ function stopScript(){
...@@ -45,26 +44,9 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -45,26 +44,9 @@ function CrowdsourceHinter(runtime, element, data){
//send empty data for ajax call because not having a data field causes error //send empty data for ajax call because not having a data field causes error
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'is_user_staff'), url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify({}), data: JSON.stringify({}),
success: function(result) { success: getFeedback
if (result['is_user_staff']) {
isStaff = true;
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify({"isStaff":"true"}),
success: getFeedback
});
} else {
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify({"isStaff":"false"}),
success: getFeedback
});
}
}
}); });
} }
} }
...@@ -114,8 +96,9 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -114,8 +96,9 @@ function CrowdsourceHinter(runtime, element, data){
} }
function setStudentAnswers(student_answers){ function setStudentAnswers(student_answers){
//Append divs for each answer the student submitted before correctly answering the question. //Append new divisions into html for each answer the student submitted before correctly
//showHintFeedback appends new hints into these divs. //answering the question. showHintFeedback appends new hints into these divs.
//When the hinter is set to show best, only one div will be created
var html = ""; var html = "";
var template = $('#show_answer_feedback').html(); var template = $('#show_answer_feedback').html();
var data = { var data = {
...@@ -128,7 +111,7 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -128,7 +111,7 @@ function CrowdsourceHinter(runtime, element, data){
function getFeedback(result){ function getFeedback(result){
//Set up the student feedback stage. Each student answer and all answer-specific hints for that answer are shown //Set up the student feedback stage. Each student answer and all answer-specific hints for that answer are shown
//to the student, as well as an option to create a new hint for an answer. //to the student, as well as an option to create a new hint for an answer.
if(isStaff){ if(data.isStaff){
$('.crowdsourcehinter_block', element).attr('class', 'crowdsourcehinter_block_is_staff'); $('.crowdsourcehinter_block', element).attr('class', 'crowdsourcehinter_block_is_staff');
$.each(result, function(index, value) { $.each(result, function(index, value) {
if(value == "Reported") { if(value == "Reported") {
...@@ -169,9 +152,9 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -169,9 +152,9 @@ function CrowdsourceHinter(runtime, element, data){
isShowingHintFeedback = true; isShowingHintFeedback = true;
} }
} }
$(element).on('click', '.csh_student_hint_creation', function(){ $(element).on('click', '.csh_student_hint_creation', function(){
//Click event for the creation of a new hint. This button will bring up the text input. //create text input area for contributing a new hint
$('.csh_student_hint_creation', element).each(function(){ $('.csh_student_hint_creation', element).each(function(){
$(this).show(); $(this).show();
}); });
...@@ -193,24 +176,16 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -193,24 +176,16 @@ function CrowdsourceHinter(runtime, element, data){
}) })
$(element).on('click', '.csh_submit_new', function(){ $(element).on('click', '.csh_submit_new', function(){
//Click event to submit a new hint for an answer. //add the newly created hint to the hinter's pool of hints
if($(this).parent().parent().find('.csh_student_text_input').val().length > 0){ if($(this).parent().parent().find('.csh_student_text_input').val().length > 0){
var answerdata = unescape($(this).attr('answer')); var answerdata = unescape($(this).attr('answer'));
var newhint = unescape($('.csh_student_text_input').val()); var newhint = unescape($('.csh_student_text_input').val());
Logger.log('crowd_hinter.submit_new.click.event', {"student_answer": answerdata, "new_hint_submission": newhint});
$('.csh_submitbutton', element).show(); $('.csh_submitbutton', element).show();
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'add_new_hint'), url: runtime.handlerUrl(element, 'add_new_hint'),
data: JSON.stringify({"submission": newhint, "answer": answerdata}), data: JSON.stringify({"submission": newhint, "answer": answerdata}),
success: function(result){ success: Logger.log('crowd_hinter.submit_new.click.event', {"student_answer": answerdata, "new_hint_submission": newhint})
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_ratings'),
data: JSON.stringify({"student_answer": answerdata, "hint": newhint}),
success: showHintFeedback(newhint, answerdata)
});
}
}); });
$(this).parent().parent().find('.csh_student_text_input').remove(); $(this).parent().parent().find('.csh_student_text_input').remove();
$(this).remove(); $(this).remove();
...@@ -218,22 +193,35 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -218,22 +193,35 @@ function CrowdsourceHinter(runtime, element, data){
}) })
$(element).on('click', '.csh_rate_hint', function(){ $(element).on('click', '.csh_rate_hint', function(){
//send info to hinter indicating whether the hint was upvoted, downvoted, or reported
if(!voted || $(this).attr('data-rate')=="report"){
if ($(this).attr('data-rate') == "report"){ if ($(this).attr('data-rate') == "report"){
alert("This hint has been reported for review."); alert("This hint has been reported for review.");
} }
hint = $('.csh_HintsToUse', element).attr('hint_received'); hint = $('.csh_HintsToUse', element).attr('hint_received');
student_answer = $('.csh_HintsToUse', element).attr('student_answer'); student_answer = $('.csh_HintsToUse', element).attr('student_answer');
Logger.log('crowd_hinter.rate_hint.click.event', {"hint": hint, "student_answer": student_answer, "rating": $(this).attr('data-rate')});
$.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'), "hint": hint, "student_answer": student_answer}) data: JSON.stringify({"student_rating": $(this).attr('data-rate'), "hint": hint, "student_answer": student_answer}),
success: Logger.log('crowd_hinter.rate_hint.click.event', {"hint": hint, "student_answer": student_answer, "rating": $(this).attr('data-rate')})
}); });
voted = true;
}
}); });
function removeFeedback(){
//remove a hint from the staff feedback area after a staff member has
//returned the hint to the hint pool or removed it permanently
$('.csh_hint_value', element).each(function(){
if($(this).attr('value') == hint){
$(this).remove();
}
});
}
$(element).on('click', '.csh_staff_rate', function(){ $(element).on('click', '.csh_staff_rate', function(){
//Staff ratings are the removal or unreporting of reported hints from the database. The attribute 'data-rate' is used //Staff "rating" removes or returns a reported hint from/to the hinter's pool of hints
//to determine whether to unreport or delete the hint.
hint = $(this).parent().find(".csh_hint").text(); hint = $(this).parent().find(".csh_hint").text();
student_answer = "Reported"; student_answer = "Reported";
Logger.log('crowd_hinter.staff_rate_hint.click.event', {"hint": hint, "student_answer": student_answer, "rating": $(this).attr('data-rate')}); Logger.log('crowd_hinter.staff_rate_hint.click.event', {"hint": hint, "student_answer": student_answer, "rating": $(this).attr('data-rate')});
...@@ -241,13 +229,8 @@ function CrowdsourceHinter(runtime, element, data){ ...@@ -241,13 +229,8 @@ function CrowdsourceHinter(runtime, element, data){
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'), "hint": hint, "student_answer": student_answer}), data: JSON.stringify({"student_rating": $(this).attr('data-rate'), "hint": hint, "student_answer": student_answer}),
success: function (result){ success: removeFeedback()
$('.csh_hint_value', element).each(function(){
if($(this).attr('value') == hint){
$(this).remove();
}
});
}
}); });
}) })
}} }}
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