Commit 0845dbdf by solashirai Committed by Piotr Mitros

improved studio hint editing (descriptions in UX, check that new hints are valid)

parent a72bda49
......@@ -65,8 +65,9 @@ class CrowdsourceHinter(XBlock):
work.
"""
html = self.resource_string("static/html/crowdsourcehinterstudio.html")
frag = Fragment(html.format(initial_hints = self.initial_hints, generic_hints = self.generic_hints, Element = self.Element))
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_studio.js"))
frag.initialize_js('CrowdsourceHinterStudio', {'initial': str(self.initial_hints), 'generic': str(self.generic_hints), 'element': str(self.Element)})
return frag
......@@ -76,10 +77,34 @@ class CrowdsourceHinter(XBlock):
"""
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'])
return
initial = ast.literal_eval(str(data['initial_hints']))
generic = ast.literal_eval(str(data['generic_hints']))
if self.check_valid_settings(initial, generic):
self.initial_hints = initial
self.generic_hints = generic
self.Element = str(data['element'])
return {'success': True}
return {'success': False}
def check_valid_settings(self, initial, generic):
"""
Check the settings being applied to the hinter by the staff to make sure they are
in the correct format.
Args:
initial: the hints attempted to be set for self.initial_hints
generic: the hints attempted to be set for self.generic_hints
returns:
True if generic is a list and initial is a dict and contains proper
answer-hint-rating format
"""
if(type(generic) is list and type(initial) is dict):
for answer in initial:
if (type(initial[answer]) is not dict):
return False
return True
return False
def resource_string(self, path):
"""
......
<!--
<script type='x-tmpl/mustache' id='show_settings_UX'>
<p>
Generic Hints: <input type="text" class="csh_generic_hints" value = "{{generic}}">
......@@ -12,18 +13,29 @@
<input type="button" class="csh_apply_settings" value="Apply Settings">
</p>
</script>
-->
<div class="crowdsourcehinter_edit_block">
<p>
Generic Hints: <input type="text" class="csh_generic_hints" value = "{{generic}}">
Generic hints should be in the form of a python list. e.x. ['generic hint text']
</p>
<p>
Initial Hints: <input type="text" class="csh_initial_hints" value = "{{initial}}">
Generic Hints: <textarea type="text" class="csh_generic_hints" value = "{{generic}}"/>
</p>
<p>
Problem Element: <input type="text" class="csh_hinting_element" value = "{{hinting_element}}">
Initial hints should be a python dictionary, with further dictionaries for each key. The format should be as follows: { "incorrect answer example": {"hint text" : rating}, "incorrect answer example 2": {"hint text": rating} } New hints that are student made will start off with a rating of 0, so set your hint's rating accordingly.
</p>
<p>
Initial Hints: <textarea type="text" class="csh_initial_hints" value = "{{initial}}"/>
</p>
<p>
This is the element of the problem for which the hinter is working. This is the "data-usage-id" of the problem block. e.x. i4x://edX/DemoX/problem/Text_Input
</p>
<p>
Problem Element: <textarea type="text" class="csh_hinting_element" value = "{{hinting_element}}"/>
</p>
<p>
<input type="button" class="csh_apply_settings" value="Apply Settings">
</p>
<div class='csh_check_success'/>
</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);
......@@ -22,8 +22,13 @@ function CrowdsourceHinterStudio(runtime, element, data){
type: "POST",
url: runtime.handlerUrl(element, 'set_initial_settings'),
data: JSON.stringify({"initial_hints": initial, "generic_hints": generic, "element": hinting_element}),
success: function(){
Logger.log('crowd_hinter.staff_edit_hinter', {"generic_hints": initial, "initial_hint": generic, "element": hinting_element});
success: function(result){
if(result.success){
$('.csh_check_success', element).text('hints successfully added to the database');
} else {
$('.csh_check_success', element).text('there was a problem adding your hints to the database. check the format on your hints.');
}
Logger.log('crowd_hinter.staff_edit_hinter', {"generic_hints": initial, "initial_hint": generic, "element": hinting_element, "successfully_set_hints": result.success});
}
});
}}
......
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