Commit 6c1b897a by Tim Krones

Clean up.

parent c19b0e41
__pycache__/
*.py[cod]
vectordraw_xblock.egg-info/
This static directory is for files that should be included in your kit as plain
static files.
You can ask the runtime for a URL that will retrieve these files with:
url = self.runtime.local_resource_url(self, "static/js/lib.js")
The default implementation is very strict though, and will not serve files from
the static directory. It will serve files from a directory named "public".
Create a directory alongside this one named "public", and put files there.
Then you can get a url with code like this:
url = self.runtime.local_resource_url(self, "public/js/lib.js")
The sample code includes a function you can use to read the content of files
in the static directory, like this:
frag.add_javascript(self.resource_string("static/js/my_block.js"))
......@@ -42,7 +42,7 @@
background-color: #3498db;
border-radius: 5px;
box-shadow: 0 1px 3px #666;
color: #fff;
color: #1f628d;
font-size: 14px;
padding: 5px 10px 5px 10px;
margin: 4px 0;
......
......@@ -2,6 +2,8 @@
function VectorDrawXBlock(runtime, element, init_args) {
'use strict';
// Logic for rendering and interacting with vector drawing exercise
var VectorDraw = function(element_id, settings) {
this.board = null;
this.dragged_vector = null;
......@@ -545,7 +547,9 @@ function VectorDrawXBlock(runtime, element, init_args) {
this.board.update();
};
var checkHandlerUrl = runtime.handlerUrl(element, 'check_answers');
// Logic for checking answers
var checkHandlerUrl = runtime.handlerUrl(element, 'check_answer');
var checkXHR;
......@@ -585,40 +589,45 @@ function VectorDrawXBlock(runtime, element, init_args) {
}
function updateStatus(data) {
var correctness = $('.correctness', element);
var correctness = $('.correctness', element),
correctClass = 'checkmark-correct fa fa-check',
incorrectClass = 'checkmark-incorrect fa fa-times';
if (data.result.ok) {
correctness.removeClass('checkmark-incorrect fa fa-times');
correctness.addClass('checkmark-correct fa fa-check');
correctness.removeClass(incorrectClass);
correctness.addClass(correctClass);
} else {
correctness.removeClass('checkmark-correct fa fa-check');
correctness.addClass('checkmark-incorrect fa fa-times');
correctness.removeClass(correctClass);
correctness.addClass(incorrectClass);
}
$('.status-message', element).text(data.result.msg);
}
function checkAnswers(vectordraw) {
function checkAnswer(vectordraw) {
if (checkXHR) {
checkXHR.abort();
}
var state = getInput(vectordraw);
checkXHR = $.post(checkHandlerUrl, JSON.stringify(state))
.success(function(response) {
console.log(JSON.stringify(response));
updateStatus(response);
});
}
// Initialization logic
$(function ($) {
/* Here's where you'd do things on page load. */
// Initialize exercise
var vectordraw = new VectorDraw('vectordraw', init_args.settings);
// Load user state
if (!_.isEmpty(init_args.user_state)) {
vectordraw.setState(init_args.user_state);
updateStatus(init_args.user_state);
}
$('.action .check', element).on('click', function(e) { checkAnswers(vectordraw); });
// Set up click handlers
$('.action .check', element).on('click', function(e) { checkAnswer(vectordraw); });
});
}
"""TO-DO: Write a description of what this XBlock is."""
"""An XBlock that allows course authors to define vector drawing exercises."""
import json
import logging
......@@ -20,18 +20,9 @@ log = logging.getLogger(__name__)
class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
"""
TO-DO: document what your XBlock does.
An XBlock that allows course authors to define vector drawing exercises.
"""
# Fields are defined on the class. You can access them in your code as
# self.<fieldname>.
# TO-DO: delete count, and define your own fields.
count = Integer(
default=0, scope=Scope.user_state,
help="A simple counter, to show something happening",
)
# Content
display_name = String(
display_name="Title (display name)",
......@@ -268,7 +259,6 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8")
# TO-DO: change this view to display your data your own way.
def student_view(self, context=None):
"""
The primary view of the VectorDrawXBlock, shown to students
......@@ -284,12 +274,10 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
fragment.initialize_js('VectorDrawXBlock', {"settings": self.settings, "user_state": self.user_state})
return fragment
# TO-DO: change this handler to perform your own actions. You may need more
# than one handler, or you may not need any handlers at all.
@XBlock.json_handler
def check_answers(self, data, suffix=''):
def check_answer(self, data, suffix=''):
"""
Check student's answers
Check and persist student's answer to this vector drawing problem.
"""
# Save answer
self.answer = dict(
......@@ -305,8 +293,6 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
score = 1 if result["ok"] else 0
self.runtime.publish(self, 'grade', dict(value=score, max_value=1))
return {
"message": "Success!",
"data": data,
"result": result,
}
......
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