Commit f5e015ff 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 96d81bce 527fe0ac
...@@ -26,6 +26,8 @@ PollMain.prototype = { ...@@ -26,6 +26,8 @@ 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;
...@@ -113,6 +115,7 @@ PollMain.prototype = { ...@@ -113,6 +115,7 @@ PollMain.prototype = {
'total': '10' 'total': '10'
}; };
logme('One.');
_this.showAnswerGraph(response.poll_answers, response.total); _this.showAnswerGraph(response.poll_answers, response.total);
}()); }());
} else { } else {
...@@ -123,6 +126,7 @@ PollMain.prototype = { ...@@ -123,6 +126,7 @@ PollMain.prototype = {
function (response) { function (response) {
logme('response:', response); logme('response:', response);
logme('Two.');
_this.showAnswerGraph(response.poll_answers, response.total); _this.showAnswerGraph(response.poll_answers, response.total);
/* /*
...@@ -135,7 +139,69 @@ PollMain.prototype = { ...@@ -135,7 +139,69 @@ PollMain.prototype = {
} }
); );
} }
} // End-of: 'submitAnswer': function (answer, answerEl) { }, // End-of: 'submitAnswer': function (answer, answerEl) {
'postInit': function () {
var _this;
// Access this object inside inner functions.
_this = this;
if (
(this.jsonConfig.poll_answer.length > 0) &&
(this.jsonConfig.answers.hasOwnProperty(this.jsonConfig.poll_answer) === false)
) {
this.questionEl.append(
'<h3>Error!</h3>' +
'<p>XML data format changed. List of answers was modified, but poll data was not updated.</p>'
);
return;
}
// Get the DOM id of the question.
this.id = this.questionEl.attr('id');
// Get the URL to which we will post the users answer to the question.
this.ajax_url = this.questionEl.data('ajax-url');
this.questionHtmlMarkup = $('<div />').html(this.jsonConfig.question).text();
this.questionEl.append(this.questionHtmlMarkup);
// When the user selects and answer, we will set this flag to true.
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) {
var answerEl;
answerEl = $('<div class="poll_answer">' + value + '</li>');
answerEl.on('click', function () {
_this.submitAnswer(index, answerEl);
});
if (index === _this.jsonConfig.poll_answer) {
answerEl.addClass('answered');
_this.questionAnswered = true;
}
answerEl.appendTo(_this.questionEl);
});
this.graphAnswerEl = $('<div class="graph_answer"></div>');
this.graphAnswerEl.hide();
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 (this.questionAnswered === true) {
logme('Three');
this.showAnswerGraph(this.jsonConfig.poll_answers, this.jsonConfig.total);
}
} // End-of: 'postInit': function () {
}; // End-of: PollMain.prototype = { }; // End-of: PollMain.prototype = {
return PollMain; return PollMain;
...@@ -227,72 +293,46 @@ function PollMain(el) { ...@@ -227,72 +293,46 @@ function PollMain(el) {
"three of them to kill and eat the cabin boy, in order to save their own lives?&lt;/p&gt;" "three of them to kill and eat the cabin boy, in order to save their own lives?&lt;/p&gt;"
}; };
} }
_this.postInit();
}()); }());
return;
} else { } else {
try { try {
this.jsonConfig = JSON.parse(this.questionEl.children('.poll_question_div').html()); this.jsonConfig = JSON.parse(this.questionEl.children('.poll_question_div').html());
} catch (err) {
logme(
'ERROR: Invalid JSON config for poll ID "' + this.id + '".',
'Error messsage: "' + err.message + '".'
);
return;
}
}
if (
(this.jsonConfig.poll_answer.length > 0) &&
(this.jsonConfig.answers.hasOwnProperty(this.jsonConfig.poll_answer) === false)
) {
this.questionEl.append(
'<h3>Error!</h3>' +
'<p>XML data format changed. List of answers was modified, but poll data was not updated.</p>'
);
return; $.postWithPrefix(
} '' + this.questionEl.data('ajax-url') + '/' + 'get_state', {},
function (response) {
// Get the DOM id of the question. logme('Get pre init state.');
this.id = this.questionEl.attr('id'); logme('response:', response);
// Get the URL to which we will post the users answer to the question.
this.ajax_url = this.questionEl.data('ajax-url');
this.questionHtmlMarkup = $('<div />').html(this.jsonConfig.question).text();
this.questionEl.append(this.questionHtmlMarkup);
// When the user selects and answer, we will set this flag to true.
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) { _this.jsonConfig.poll_answer = response.poll_answer;
var answerEl; _this.jsonConfig.total = response.total;
answerEl = $('<div class="poll_answer">' + value + '</li>'); $.each(response.poll_answers, function (index, value) {
answerEl.on('click', function () { _this.jsonConfig.poll_answers[index] = value;
_this.submitAnswer(index, answerEl);
}); });
if (index === _this.jsonConfig.poll_answer) { logme('Current "jsonConfig": ');
answerEl.addClass('answered'); logme(_this.jsonConfig);
_this.questionAnswered = true;
}
answerEl.appendTo(_this.questionEl); _this.questionEl.children('.poll_question_div').html(JSON.stringify(_this.jsonConfig));
});
this.graphAnswerEl = $('<div class="graph_answer"></div>'); _this.postInit();
this.graphAnswerEl.hide(); }
this.graphAnswerEl.appendTo(this.questionEl); );
logme('PollMain object: ', this); return;
} catch (err) {
logme(
'ERROR: Invalid JSON config for poll ID "' + this.id + '".',
'Error messsage: "' + err.message + '".'
);
// If it turns out that the user already answered the question, show the answers graph. return;
if (this.questionAnswered === true) { }
this.showAnswerGraph(this.jsonConfig.poll_answers, this.jsonConfig.total);
} }
} // End-of: function PollMain(el) { } // End-of: function PollMain(el) {
......
...@@ -69,7 +69,12 @@ class PollModule(XModule): ...@@ -69,7 +69,12 @@ class PollModule(XModule):
'total': sum(self.poll_answers.values()), 'total': sum(self.poll_answers.values()),
'callback': {'objectName': 'Conditional'} 'callback': {'objectName': 'Conditional'}
}) })
# return error message elif dispatch == 'get_state':
return json.dumps({'poll_answer': self.poll_answer,
'poll_answers': self.poll_answers,
'total': sum(self.poll_answers.values())
})
else: # return error message
return json.dumps({'error': 'Unknown Command!'}) return json.dumps({'error': 'Unknown Command!'})
def get_html(self): def get_html(self):
......
...@@ -179,6 +179,12 @@ end ...@@ -179,6 +179,12 @@ end
TEST_TASK_DIRS = [] TEST_TASK_DIRS = []
task :fastlms do
# this is >2 times faster that rake [lms], and does not need web, good for local dev
django_admin = ENV['DJANGO_ADMIN_PATH'] || select_executable('django-admin.py', 'django-admin')
sh("#{django_admin} runserver --traceback --settings=lms.envs.dev --pythonpath=.")
end
[:lms, :cms].each do |system| [:lms, :cms].each do |system|
report_dir = report_dir_path(system) report_dir = report_dir_path(system)
......
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