Commit 76f5ee71 by solashirai Committed by Piotr Mitros

issues with logger.listen

parent f716196e
......@@ -8,9 +8,11 @@ import copy
from copy import deepcopy
from xblock.core import XBlock
from xblock.fields import Scope, Dict, List, Boolean
from xblock.fields import Scope, Dict, List, Boolean, String
from xblock.fragment import Fragment
from eventtracking import tracker
log = logging.getLogger(__name__)
class CrowdsourceHinter(XBlock):
......@@ -59,6 +61,10 @@ class CrowdsourceHinter(XBlock):
# When set to 'True' only the best hint will be shown to the student.
# Details on operation when set to 'False' are to be finalized.
show_best = Boolean(default = True, scope=Scope.user_state_summary)
# This String represents the xblock element for which the hinter is running. It is necessary to manually
# set this value in the XML file under the format "hinting_element": "i4x://edX/DemoX/problem/Text_Input" .
# Without properly setting this String, the hinter will not correctly be able to use the Logger listen for problem_graded.
Element = String(default="", scope=Scope.content)
def student_view(self, context=None):
"""
......@@ -103,6 +109,13 @@ class CrowdsourceHinter(XBlock):
return self.xmodule_runtime.user_is_staff
@XBlock.json_handler
def get_element(self, data, suffix=''):
"""
Returns the self.element so that the javascript Logger.listen will be using the correct element.
"""
return str(self.Element);
@XBlock.json_handler
def is_user_staff(self, _data, _suffix=''):
"""
Return whether the user is staff.
......@@ -404,4 +417,5 @@ class CrowdsourceHinter(XBlock):
xmlText = ast.literal_eval((node.text).encode('utf-8'))
block.generic_hints.append(xmlText["generic_hints"])
block.initial_hints = copy.copy(xmlText["initial_hints"])
block.Element = xmlText["hinting_element"]
return block
......@@ -8,13 +8,24 @@ function CrowdsourceHinter(runtime, element){
if(executeHinter){
var isShowingHintFeedback = false;
var hinting_element;
var isStaff = false;
$(".csh_HintsToUse", element).text("");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_element'),
data: JSON.stringify("helloworld"),
success: function(result){
console.log("hinting_element being set", result);
hinting_element = result;
}
});
function stopScript(){
//This function is used to prevent a particular instance of the hinter from acting after
//switching between edX course's units.
executeHinter = false;
console.log("executeHinter set to false");
}
Logger.listen('seq_next', null, stopScript);
Logger.listen('seq_prev', null, stopScript);
......@@ -23,14 +34,18 @@ function CrowdsourceHinter(runtime, element){
//data about the problem obtained from Logger.listen('problem_graded') is passed on to the onStudentSubmission.
//directly passing data to onStudentSubmission does not appear to work
function get_event_data(event_type, data, element){
onStudentSubmission(data);
console.log(data);
//onStudentSubmission(data);
console.log("gradedevent listen");
}
Logger.listen('problem_check', null, get_event_data);
function print_info(event_type, data, element){
console.log(data);
Logger.listen('problem_graded', hinting_element, function(){console.log("test")});
Logger.listen('problem_graded', 'i4x://edX/DemoX/problem/Text_Input', function(){console.log("test2")});
function get_event_data_temp(event_type, data, element){
console.log("checkevent listen");
console.log(hinting_element);
console.log(typeof('i4x://edX/DemoX/problem/Text_Input'));
}
Logger.listen('problem_graded', null, print_info);
Logger.listen('problem_check', null, get_event_data_temp);
function onStudentSubmission(problem_graded_event_data){
//This function will determine whether or not the student correctly answered the question.
......
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