Commit 0129994e by Vasyl Nakvasiuk

Merge branch 'feature/alex/poll-storage-model' of github.com:MITx/mitx into…

Merge branch 'feature/alex/poll-storage-model' of github.com:MITx/mitx into feature/alex/poll-storage-model
parents 3ced4bee 863dae7e
...@@ -42,7 +42,7 @@ setup( ...@@ -42,7 +42,7 @@ setup(
"static_tab = xmodule.html_module:StaticTabDescriptor", "static_tab = xmodule.html_module:StaticTabDescriptor",
"custom_tag_template = xmodule.raw_module:RawDescriptor", "custom_tag_template = xmodule.raw_module:RawDescriptor",
"about = xmodule.html_module:AboutDescriptor", "about = xmodule.html_module:AboutDescriptor",
"wrapper = xmodule.vertical_module:VerticalDescriptor", "wrapper = xmodule.wrapper_module:WrapperDescriptor",
], ],
} }
) )
...@@ -67,25 +67,28 @@ class ConditionalModule(XModule): ...@@ -67,25 +67,28 @@ class ConditionalModule(XModule):
descriptor in self.descriptor.get_required_module_descriptors()] descriptor in self.descriptor.get_required_module_descriptors()]
xml_value, attr_name = self._get_condition() xml_value, attr_name = self._get_condition()
if xml_value: if xml_value and self.required_modules:
for module in self.required_modules: for module in self.required_modules:
if not hasattr(module, attr_name): if not hasattr(module, attr_name):
raise Exception('Error in conditional module: \ raise Exception('Error in conditional module: \
required module %s has no .is_completed() method' required module {module} has no {module_attr}'.format(
% module) module=module, module_attr=attr_name))
attr = getattr(module, attr_name) attr = getattr(module, attr_name)
if callable(attr): if callable(attr):
attr = attr() attr = attr()
return xml_value == str(attr) if xml_value != str(attr):
break
else:
return True
return False return False
def get_html(self): def get_html(self):
return self.system.render_template('conditional_ajax.html', { return self.system.render_template('conditional_ajax.html', {
'element_id': self.location.html_id(), 'element_id': self.location.html_id(),
'id': self.id, 'id': self.id,
'ajax_url': self.system.ajax_url, 'ajax_url': self.system.ajax_url
}) })
def handle_ajax(self, dispatch, post): def handle_ajax(self, dispatch, post):
...@@ -97,7 +100,7 @@ class ConditionalModule(XModule): ...@@ -97,7 +100,7 @@ class ConditionalModule(XModule):
'message': self.descriptor.xml_attributes.get('message')} 'message': self.descriptor.xml_attributes.get('message')}
html = self.system.render_template('conditional_module.html', html = self.system.render_template('conditional_module.html',
context) context)
return json.dumps({'html': [html]}) return json.dumps({'html': [html], 'passed': False})
if self.contents is None: if self.contents is None:
self.contents = [self.system.get_module(child_descriptor.location self.contents = [self.system.get_module(child_descriptor.location
...@@ -105,7 +108,7 @@ class ConditionalModule(XModule): ...@@ -105,7 +108,7 @@ class ConditionalModule(XModule):
for child_descriptor in self.descriptor.get_children()] for child_descriptor in self.descriptor.get_children()]
html = self.contents html = self.contents
return json.dumps({'html': html}) return json.dumps({'html': html, 'passed': True})
class ConditionalDescriptor(SequenceDescriptor): class ConditionalDescriptor(SequenceDescriptor):
......
.vert-mod > li {
border-bottom: none;
margin-bottom: 0px;
padding: 0 0 0px; }
...@@ -2,25 +2,23 @@ class @Conditional ...@@ -2,25 +2,23 @@ class @Conditional
constructor: (element) -> constructor: (element) ->
@el = $(element).find('.conditional-wrapper') @el = $(element).find('.conditional-wrapper')
@id = @el.data('problem-id')
@element_id = @el.attr('id')
@url = @el.data('url')
@render()
$: (selector) ->
$(selector, @el)
updateProgress: (response) => if @el.data('passed') is true
if response.progress_changed @passed = true
@el.attr progress: response.progress_status
@el.trigger('progressChanged')
render: (content) -> return
if content else if @el.data('passed') is false
@el.append(i) for i in content @passed = false
XModule.loadModules(@el)
else else
@passed = null
@url = @el.data('url')
@render()
render: () ->
$.postWithPrefix "#{@url}/conditional_get", (response) => $.postWithPrefix "#{@url}/conditional_get", (response) =>
@el.append(i) for i in response.html if (((response.passed is true) && (@passed is false)) || (@passed is null))
XModule.loadModules(@el) @el.data 'passed', response.passed
@el.append(i) for i in response.html
XModule.loadModules @el
window.Poll = function (el) { window.Poll = function (el) {
RequireJS.require(['PollMain'], function (PollMain) { RequireJS.require(['PollMain'], function (PollMain) {
(new PollMain(el)); new PollMain(el);
}); });
}; };
...@@ -4,7 +4,7 @@ define('PollMain', ['logme'], function (logme) { ...@@ -4,7 +4,7 @@ define('PollMain', ['logme'], function (logme) {
debugMode = false; debugMode = false;
if (debugMode === true) { if (debugMode === true) {
logme('We are in debug mode.'); logme('MESSAGE: We are in debug mode.');
} }
PollMain.prototype = { PollMain.prototype = {
...@@ -26,8 +26,6 @@ PollMain.prototype = { ...@@ -26,8 +26,6 @@ PollMain.prototype = {
tickSets = {}; tickSets = {};
c1 = 0; c1 = 0;
logme('poll_answers: ', poll_answers, '_this.jsonConfig.answers: ', _this.jsonConfig.answers);
$.each(poll_answers, function (index, value) { $.each(poll_answers, function (index, value) {
var numValue, text; var numValue, text;
...@@ -115,7 +113,6 @@ PollMain.prototype = { ...@@ -115,7 +113,6 @@ PollMain.prototype = {
'total': '10' 'total': '10'
}; };
logme('One.');
_this.showAnswerGraph(response.poll_answers, response.total); _this.showAnswerGraph(response.poll_answers, response.total);
}()); }());
} else { } else {
...@@ -124,32 +121,13 @@ PollMain.prototype = { ...@@ -124,32 +121,13 @@ PollMain.prototype = {
$.postWithPrefix( $.postWithPrefix(
_this.ajax_url + '/' + answer, {}, _this.ajax_url + '/' + answer, {},
function (response) { function (response) {
logme('response:', response);
logme('Two.');
_this.showAnswerGraph(response.poll_answers, response.total); _this.showAnswerGraph(response.poll_answers, response.total);
if (_this.verticalSectionEl !== null) { if (_this.verticalSectionEl !== null) {
console.log('Looking for conditional modules');
$(_this.verticalSectionEl).find('.xmodule_ConditionalModule').each(function (index, value) { $(_this.verticalSectionEl).find('.xmodule_ConditionalModule').each(function (index, value) {
console.log('Found conditional element. index = '); new window.Conditional(value);
console.log(index);
console.log('value = ');
console.log(value);
(new window.Conditional(value));
}); });
} else {
console.log('Did not find any conditional modules');
}
/*
_this.vertModEl.find('.xmodule_ConditionalModule').each(
function (index, value) {
(new window[response.className]($(value)));
} }
);
*/
} }
); );
} }
...@@ -185,9 +163,6 @@ PollMain.prototype = { ...@@ -185,9 +163,6 @@ PollMain.prototype = {
// When the user selects and answer, we will set this flag to true. // When the user selects and answer, we will set this flag to true.
this.questionAnswered = false; this.questionAnswered = false;
logme('this.jsonConfig.answers: ', this.jsonConfig.answers);
logme('this.jsonConfig.poll_answer: ', this.jsonConfig.poll_answer);
$.each(this.jsonConfig.answers, function (index, value) { $.each(this.jsonConfig.answers, function (index, value) {
var answerEl; var answerEl;
...@@ -208,11 +183,8 @@ PollMain.prototype = { ...@@ -208,11 +183,8 @@ PollMain.prototype = {
this.graphAnswerEl.hide(); this.graphAnswerEl.hide();
this.graphAnswerEl.appendTo(this.questionEl); this.graphAnswerEl.appendTo(this.questionEl);
logme('PollMain object: ', this);
// If it turns out that the user already answered the question, show the answers graph. // If it turns out that the user already answered the question, show the answers graph.
if (this.questionAnswered === true) { if (this.questionAnswered === true) {
logme('Three');
this.showAnswerGraph(this.jsonConfig.poll_answers, this.jsonConfig.total); this.showAnswerGraph(this.jsonConfig.poll_answers, this.jsonConfig.total);
} }
} // End-of: 'postInit': function () { } // End-of: 'postInit': function () {
...@@ -223,43 +195,6 @@ return PollMain; ...@@ -223,43 +195,6 @@ return PollMain;
function PollMain(el) { function PollMain(el) {
var _this; var _this;
var tel, c1;
tel = $(el)[0];
c1 = 0;
console.log(tel);
this.verticalSectionEl = null;
while (tel.tagName.toLowerCase() !== 'body') {
tel = $(tel).parent()[0];
c1 += 1;
console.log('' + c1 + ': parent = ');
console.log(tel);
if ((tel.tagName.toLowerCase() === 'section') && ($(tel).hasClass('xmodule_VerticalModule') === true)) {
console.log('Found vertical section. Saving element for future use.');
this.verticalSectionEl = tel;
break;
} else if (c1 > 50) {
console.log('ERROR: HTML hierarchy is very large.');
break;
}
}
console.log('this.verticalSectionEl = ');
console.log(this.verticalSectionEl);
this.vertModEl = $(el).parent().parent();
if (this.vertModEl.length !== 1) {
// We will work with a single DOM element that contains one question, and zero or more conditionals.
return;
}
this.questionEl = $(el).find('.poll_question'); this.questionEl = $(el).find('.poll_question');
if (this.questionEl.length !== 1) { if (this.questionEl.length !== 1) {
// We require one question DOM element. // We require one question DOM element.
...@@ -285,6 +220,31 @@ function PollMain(el) { ...@@ -285,6 +220,31 @@ function PollMain(el) {
// Access this object inside inner functions. // Access this object inside inner functions.
_this = this; _this = this;
// DOM element which contains the current poll along with any conditionals. By default we assume that such
// element is not present. We will try to find it.
this.verticalSectionEl = null;
(function (tempEl, c1) {
while (tempEl.tagName.toLowerCase() !== 'body') {
tempEl = $(tempEl).parent()[0];
c1 += 1;
if (
(tempEl.tagName.toLowerCase() === 'section') &&
($(tempEl).hasClass('xmodule_VerticalModule') === true)
) {
_this.verticalSectionEl = tempEl;
break;
} else if (c1 > 50) {
// In case something breaks, and we enter an endless loop, a sane
// limit for loop iterations.
break;
}
}
}($(el)[0], 0));
// Test case for when the server part is still not ready. Change to 'false' so you can test actual server // Test case for when the server part is still not ready. Change to 'false' so you can test actual server
// generated JSON config. // generated JSON config.
if (debugMode === true) { if (debugMode === true) {
...@@ -350,9 +310,6 @@ function PollMain(el) { ...@@ -350,9 +310,6 @@ function PollMain(el) {
$.postWithPrefix( $.postWithPrefix(
'' + this.questionEl.data('ajax-url') + '/' + 'get_state', {}, '' + this.questionEl.data('ajax-url') + '/' + 'get_state', {},
function (response) { function (response) {
logme('Get pre init state.');
logme('response:', response);
_this.jsonConfig.poll_answer = response.poll_answer; _this.jsonConfig.poll_answer = response.poll_answer;
_this.jsonConfig.total = response.total; _this.jsonConfig.total = response.total;
...@@ -360,11 +317,7 @@ function PollMain(el) { ...@@ -360,11 +317,7 @@ function PollMain(el) {
_this.jsonConfig.poll_answers[index] = value; _this.jsonConfig.poll_answers[index] = value;
}); });
logme('Current "jsonConfig": ');
logme(_this.jsonConfig);
_this.questionEl.children('.poll_question_div').html(JSON.stringify(_this.jsonConfig)); _this.questionEl.children('.poll_question_div').html(JSON.stringify(_this.jsonConfig));
_this.postInit(); _this.postInit();
} }
); );
......
# Same as vertical,
# But w/o css delimiters between children
from xmodule.vertical_module import VerticalModule, VerticalDescriptor
from pkg_resources import resource_string
# HACK: This shouldn't be hard-coded to two types
# OBSOLETE: This obsoletes 'type'
class_priority = ['video', 'problem']
class WrapperModule(VerticalModule):
''' Layout module for laying out submodules vertically w/o css delimiters'''
has_children = True
css = {'scss': [resource_string(__name__, 'css/wrapper/display.scss')]}
class WrapperDescriptor(VerticalDescriptor):
module_class = WrapperModule
has_children = True
js = {'coffee': [resource_string(__name__, 'js/src/vertical/edit.coffee')]}
js_module_name = "VerticalDescriptor"
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