Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-vectordraw
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
xblock-vectordraw
Commits
6c1b897a
Commit
6c1b897a
authored
Oct 30, 2015
by
Tim Krones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up.
parent
c19b0e41
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
48 deletions
+25
-48
.gitignore
+1
-0
vectordraw/static/README.txt
+0
-19
vectordraw/static/css/vectordraw.css
+1
-1
vectordraw/static/js/src/vectordraw.js
+19
-10
vectordraw/vectordraw.py
+4
-18
No files found.
.gitignore
View file @
6c1b897a
__pycache__/
*.py[cod]
vectordraw_xblock.egg-info/
vectordraw/static/README.txt
deleted
100644 → 0
View file @
c19b0e41
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"))
vectordraw/static/css/vectordraw.css
View file @
6c1b897a
...
...
@@ -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
;
...
...
vectordraw/static/js/src/vectordraw.js
View file @
6c1b897a
...
...
@@ -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
checkAnswer
s
(
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
);
});
});
}
vectordraw/vectordraw.py
View file @
6c1b897a
"""
TO-DO: Write a description of what this XBlock i
s."""
"""
An XBlock that allows course authors to define vector drawing exercise
s."""
import
json
import
logging
...
...
@@ -20,18 +20,9 @@ log = logging.getLogger(__name__)
class
VectorDrawXBlock
(
StudioEditableXBlockMixin
,
XBlock
):
"""
TO-DO: document what your XBlock do
es.
An XBlock that allows course authors to define vector drawing exercis
es.
"""
# 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_answer
s
(
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
,
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment