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
c19b0e41
Commit
c19b0e41
authored
Oct 30, 2015
by
Tim Krones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save and restore state.
parent
aa7c1340
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
20 deletions
+45
-20
vectordraw/static/js/src/vectordraw.js
+6
-1
vectordraw/vectordraw.py
+39
-19
No files found.
vectordraw/static/js/src/vectordraw.js
View file @
c19b0e41
...
...
@@ -611,7 +611,12 @@ function VectorDrawXBlock(runtime, element, init_args) {
$
(
function
(
$
)
{
/* Here's where you'd do things on page load. */
var
vectordraw
=
new
VectorDraw
(
'vectordraw'
,
init_args
);
var
vectordraw
=
new
VectorDraw
(
'vectordraw'
,
init_args
.
settings
);
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
);
});
...
...
vectordraw/vectordraw.py
View file @
c19b0e41
...
...
@@ -5,7 +5,7 @@ import logging
import
pkg_resources
from
xblock.core
import
XBlock
from
xblock.fields
import
Scope
,
Boolean
,
Float
,
Integer
,
String
from
xblock.fields
import
Scope
,
Boolean
,
Dict
,
Float
,
Integer
,
String
from
xblock.fragment
import
Fragment
from
xblockutils.resources
import
ResourceLoader
from
xblockutils.studio_editable
import
StudioEditableXBlockMixin
...
...
@@ -191,6 +191,10 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
enforce_type
=
True
)
# User state
answer
=
Dict
(
scope
=
Scope
.
user_state
)
result
=
Dict
(
scope
=
Scope
.
user_state
)
editable_fields
=
(
'display_name'
,
'description'
,
...
...
@@ -215,6 +219,31 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
has_score
=
True
@property
def
settings
(
self
):
return
{
'width'
:
self
.
width
,
'height'
:
self
.
height
,
'bounding_box_size'
:
self
.
bounding_box_size
,
'axis'
:
self
.
axis
,
'show_navigation'
:
self
.
show_navigation
,
'show_vector_properties'
:
self
.
show_vector_properties
,
'show_slope_for_lines'
:
self
.
show_slope_for_lines
,
'add_vector_label'
:
self
.
add_vector_label
,
'vector_properties_label'
:
self
.
vector_properties_label
,
'background'
:
self
.
background
,
'vectors'
:
self
.
vectors_json
,
'points'
:
self
.
points_json
,
'expected_result'
:
self
.
expected_result_json
}
@property
def
user_state
(
self
):
user_state
=
self
.
answer
if
self
.
result
:
user_state
[
'result'
]
=
self
.
result
return
user_state
@property
def
background
(
self
):
return
{
'src'
:
self
.
background_url
,
...
...
@@ -252,24 +281,7 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
fragment
.
add_css
(
self
.
resource_string
(
'static/css/vectordraw.css'
))
fragment
.
add_javascript_url
(
"//cdnjs.cloudflare.com/ajax/libs/jsxgraph/0.98/jsxgraphcore.js"
)
fragment
.
add_javascript
(
self
.
resource_string
(
"static/js/src/vectordraw.js"
))
fragment
.
initialize_js
(
'VectorDrawXBlock'
,
{
'width'
:
self
.
width
,
'height'
:
self
.
height
,
'bounding_box_size'
:
self
.
bounding_box_size
,
'axis'
:
self
.
axis
,
'show_navigation'
:
self
.
show_navigation
,
'show_vector_properties'
:
self
.
show_vector_properties
,
'show_slope_for_lines'
:
self
.
show_slope_for_lines
,
'add_vector_label'
:
self
.
add_vector_label
,
'vector_properties_label'
:
self
.
vector_properties_label
,
'background'
:
self
.
background
,
'vectors'
:
self
.
vectors_json
,
'points'
:
self
.
points_json
,
'expected_result'
:
self
.
expected_result_json
}
)
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
...
...
@@ -279,8 +291,16 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
"""
Check student's answers
"""
# Save answer
self
.
answer
=
dict
(
vectors
=
data
[
"vectors"
],
points
=
data
[
"points"
]
)
# Compute result
grader
=
Grader
()
result
=
grader
.
grade
(
data
)
# Save result
self
.
result
=
result
# Publish grade data
score
=
1
if
result
[
"ok"
]
else
0
self
.
runtime
.
publish
(
self
,
'grade'
,
dict
(
value
=
score
,
max_value
=
1
))
...
...
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