Commit 205ca5d1 by Sola Committed by Piotr Mitros

adding staff un-flag capabilities

parent b933c8b3
...@@ -47,10 +47,6 @@ class CrowdXBlock(XBlock): ...@@ -47,10 +47,6 @@ class CrowdXBlock(XBlock):
# Details on operation when set to 'False' are to be finalized. # Details on operation when set to 'False' are to be finalized.
# TODO: make this into a boolean instead of a dict # TODO: make this into a boolean instead of a dict
show_best = Dict(default={'showbest': 'True'}, scope=Scope.user_state_summary) show_best = Dict(default={'showbest': 'True'}, scope=Scope.user_state_summary)
# This Dict determine whether or not the user is staff. This in turn will influence whether or not flagged hints
# will be shown. The method to actually determine whether or not the user is staff is not currently implemented.
# TODO: make this into a boolean instead of a dict
isStaff = Dict(default={'isStaff': 'true'}, scope=Scope.user_state_summary)
def student_view(self, context=None): def student_view(self, context=None):
""" """
...@@ -84,6 +80,24 @@ class CrowdXBlock(XBlock): ...@@ -84,6 +80,24 @@ class CrowdXBlock(XBlock):
data = pkg_resources.resource_string(__name__, path) data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8") return data.decode("utf8")
def get_user_is_staff(self):
"""
Return self.xmodule_runtime.user_is_staff
This is not a supported part of the XBlocks API. User data is still
being defined. However, It's the only way to get the data right now.
"""
return self.xmodule_runtime.user_is_staff
@XBlock.json_handler
def is_user_staff(self, _data, _suffix=''):
"""
Return whether the user is staff.
Returns:
is_user_staff: indicator for whether the user is staff
"""
result = {'is_user_staff': self.get_user_is_staff()}
return result
@XBlock.json_handler @XBlock.json_handler
def get_hint(self, data, suffix=''): def get_hint(self, data, suffix=''):
""" """
...@@ -197,7 +211,7 @@ class CrowdXBlock(XBlock): ...@@ -197,7 +211,7 @@ class CrowdXBlock(XBlock):
feedback_data = {} feedback_data = {}
number_of_hints = 0 number_of_hints = 0
# TODO: possibly simply check here whether or not user is staff # TODO: possibly simply check here whether or not user is staff
if self.isStaff['isStaff'] == 'true': if data['isStaff'] == 'true':
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)]:
......
...@@ -12,6 +12,7 @@ function CrowdXBlock(runtime, element){ ...@@ -12,6 +12,7 @@ function CrowdXBlock(runtime, element){
repeatcounter += 1; repeatcounter += 1;
//use to determine whether or not to initialize hint feedback //use to determine whether or not to initialize hint feedback
var hasReceivedHint = false; var hasReceivedHint = false;
var isStaff = false;
Logger.listen('seq_next', null, clearingvariables); Logger.listen('seq_next', null, clearingvariables);
Logger.listen('seq_goto', null, clearingvariables); Logger.listen('seq_goto', null, clearingvariables);
...@@ -65,11 +66,27 @@ function CrowdXBlock(runtime, element){ ...@@ -65,11 +66,27 @@ function CrowdXBlock(runtime, element){
//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, 'get_feedback'), url: runtime.handlerUrl(element, 'is_user_staff'),
//possibly send here if user is staff? data: JSON.stringify({}),
//doing so would be helpful to set up a "flagged" seciton for hints success: function(result) {
data: JSON.stringify(""), console.log(result);
success: getFeedback if (result['is_user_staff']) {
ifStaff = 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
});
}
}
}); });
} }
} }
...@@ -85,6 +102,14 @@ function CrowdXBlock(runtime, element){ ...@@ -85,6 +102,14 @@ function CrowdXBlock(runtime, element){
//so that when a button is clicked, the answer and hint can be sent to the python script //so that when a button is clicked, the answer and hint can be sent to the python script
student_answer = value; student_answer = value;
hint_used = index; hint_used = index;
if (isStaff == true) {
$('.feedback', element).append("<p class=\"flagged_hints"\"</p>");
if (student_answer == "Flagged") {
$(".flagged_hints", element).append("<p class=" + hint_used + "><div role=\"button\" class=\"return_hint\"" +
" aria-label=\"return\"><b>O</b></div><div>" + hint_used +
"</div> <div role=\"button\" class=\"purge_hint\" aria-label=\"purge\"><b>X</b></div></p>
}
}
if($(".submit"+student_answer).length == 0){ if($(".submit"+student_answer).length == 0){
$('.feedback', element).append("<p class=\"submit" + student_answer + "\"</p>"); $('.feedback', element).append("<p class=\"submit" + student_answer + "\"</p>");
$(".submit"+student_answer, element).append("<b>Answer-specific hints for \b" + " " + student_answer + "<p><input id=\"submitbuttonfor" + student_answer + "\" style=\"float: right; float: top;\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint\"><p class=\"showHintsFor" + student_answer + "\"> </p></div>"); $(".submit"+student_answer, element).append("<b>Answer-specific hints for \b" + " " + student_answer + "<p><input id=\"submitbuttonfor" + student_answer + "\" style=\"float: right; float: top;\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint\"><p class=\"showHintsFor" + student_answer + "\"> </p></div>");
......
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