Commit 9fbd3fd8 by solashirai Committed by Piotr Mitros

studio view/hint creation added

parent 5f8189e7
...@@ -53,6 +53,9 @@ class CrowdsourceHinter(XBlock): ...@@ -53,6 +53,9 @@ class CrowdsourceHinter(XBlock):
# This String represents the xblock element for which the hinter is running. It is necessary to manually # 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" . # set this value in the XML file under the format "hinting_element": "i4x://edX/DemoX/problem/Text_Input" .
# 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.
#
# TODO: probably should change the name from Element (problem_element? hinting_element?). Trying to
# just change the name didn't seem to operate properly, check carefully what is changed
Element = String(default="", scope=Scope.content) Element = String(default="", scope=Scope.content)
def studio_view(self, context=None): def studio_view(self, context=None):
...@@ -62,13 +65,28 @@ class CrowdsourceHinter(XBlock): ...@@ -62,13 +65,28 @@ class CrowdsourceHinter(XBlock):
work. work.
""" """
html = self.resource_string("static/html/crowdsourcehinterstudio.html") html = self.resource_string("static/html/crowdsourcehinterstudio.html")
frag = Fragment(html.format(self=self)) frag = Fragment(html.format(initial_hints = self.initial_hints, generic_hints = self.generic_hints, Element = self.Element))
frag.add_javascript_url('//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js') 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_studio.js"))
frag.add_javascript(self.resource_string("static/js/src/crowdsourcehinter.js")) frag.initialize_js('CrowdsourceHinterStudio', {'initial': str(self.initial_hints), 'generic': str(self.generic_hints), 'element': str(self.Element)})
frag.initialize_js('CrowdsourceHinter')
return frag return frag
@XBlock.json_handler
def set_initial_settings(self, data, suffix=''):
"""
Set intial hints, generic hints, and problem element from the studio view.
"""
self.initial_hints = ast.literal_eval(str(data['initial_hints']))
self.generic_hints = ast.literal_eval(str(data['generic_hints']))
self.Element = str(data['element'])
print data['generic_hints']
print str(self.generic_hints)
print data['initial_hints']
print str(self.initial_hints)
print str(data['element'])
print ast.literal_eval(str(data['initial_hints']))
return
def resource_string(self, path): def resource_string(self, path):
""" """
This function is used to get the path of static resources. This function is used to get the path of static resources.
...@@ -113,6 +131,7 @@ class CrowdsourceHinter(XBlock): ...@@ -113,6 +131,7 @@ class CrowdsourceHinter(XBlock):
""" """
# populate hint_database with hints from initial_hints if there are no hints in hint_database. # populate hint_database with hints from initial_hints if there are no hints in hint_database.
# this probably will occur only on the very first run of a unit containing this block. # this probably will occur only on the very first run of a unit containing this block.
print self.hint_database
if not bool(self.hint_database): if not bool(self.hint_database):
self.hint_database = copy.copy(self.initial_hints) self.hint_database = copy.copy(self.initial_hints)
answer = str(data["submittedanswer"]) answer = str(data["submittedanswer"])
...@@ -123,7 +142,9 @@ class CrowdsourceHinter(XBlock): ...@@ -123,7 +142,9 @@ class CrowdsourceHinter(XBlock):
# the string returned by the event problem_graded is very messy and is different # the string returned by the event problem_graded is very messy and is different
# for each problem, but after all of the numbers/letters there is an equal sign, after which the # for each problem, but after all of the numbers/letters there is an equal sign, after which the
# student's input is shown. I use the function below to remove everything before the first equal # student's input is shown. I use the function below to remove everything before the first equal
# sign and only take the student's actual input. This is not very clean. # sign and only take the student's actual input.
#
# TODO: figure out better way to directly get text of student's answer
if "=" in answer: if "=" in answer:
if found_equal_sign == 0: if found_equal_sign == 0:
found_equal_sign = 1 found_equal_sign = 1
......
<script type='x-tmpl/mustache' id='show_settings_UX'>
<p>
Generic Hints: <input type="text" class="csh_generic_hints" value = "{{generic}}">
</p>
<p>
Initial Hints: <input type="text" class="csh_initial_hints" value = "{{initial}}">
</p>
<p>
Problem Element: <input type="text" class="csh_hinting_element" value = "{{hinting_element}}">
</p>
<p>
<input type="button" class="csh_apply_settings" value="Apply Settings">
</p>
</script>
<div class="crowdsourcehinter_block"> <div class="crowdsourcehinter_edit_block">
<p id="hint_purge"> <p>
The following hints have been reported by students. Select "dismiss" to return the hint for usage in the course, and select "remove" to remove it permanently from the course. Generic Hints: <input type="text" class="csh_generic_hints" value = "{{generic}}">
</p> </p>
<p>
Initial Hints: <input type="text" class="csh_initial_hints" value = "{{initial}}">
</p>
<p>
Problem Element: <input type="text" class="csh_hinting_element" value = "{{hinting_element}}">
</p>
<p>
<input type="button" class="csh_apply_settings" value="Apply Settings">
</p>
</div> </div>
function CrowdsourceHinterStudio(runtime, element, data){
/**
//:TODO for self, figure out why Mustache isn't working (anonymous funciton (what?) Mustache Not Defined (why?))
//Initialize html with current generic hints, initial hints, and problem element
//var showSettingsUX = $(Mustache.render($('#show_settings_UX').html(), {generic: data.generic, initial: data.initial, problem_element: data.problem_element}));
//$('.crowdsourcehinter_edit_block', element).append(showSettingsUX);
**/
//set text area values to be what is currently in the hinter. to be replaced by above code.
$('.csh_initial_hints', element).val(data.initial);
$('.csh_generic_hints', element).val(data.generic);
$('.csh_hinting_element', element).val(data.element);
/**
* Apply settings for initial hints, generic hints, and the element for which the hinter is
* working.
*/
function apply_settings(){ return function(apply_settings_button){
var initial = unescape($('.csh_initial_hints').val());
var generic = unescape($('.csh_generic_hints').val());
var hinting_element = unescape($('.csh_hinting_element').val());
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'set_initial_settings'),
data: JSON.stringify({"initial_hints": initial, "generic_hints": generic, "element": hinting_element}),
success: function(){
console.log("success");
}
});
}}
$(element).on('click', '.csh_apply_settings', apply_settings($(this)));
}
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