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
06d0cbbf
Commit
06d0cbbf
authored
Nov 03, 2015
by
Tim Krones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render template for board and menu on the server.
parent
273232bc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
46 deletions
+77
-46
vectordraw/static/html/vectordraw.html
+45
-1
vectordraw/static/js/src/vectordraw.js
+23
-44
vectordraw/vectordraw.py
+9
-1
No files found.
vectordraw/static/html/vectordraw.html
View file @
06d0cbbf
...
@@ -8,7 +8,51 @@
...
@@ -8,7 +8,51 @@
</div>
</div>
{% endif %}
{% endif %}
<div
id=
"vectordraw"
/>
<div
id=
"vectordraw"
>
<div
class=
"jxgboard"
style=
"width: {{ self.width }}px; height: {{ self.height }}px;"
/>
<div
class=
"menu"
>
<div
class=
"controls"
>
<select>
{% for vector in self.get_vectors %}
<option
value=
"vector-{{ forloop.counter0 }}"
>
{{ vector.description }}
</option>
{% endfor %}
{% for point in self.get_points %}
{% if not point.fixed %}
<option
value=
"point-{{ forloop.counter0 }}"
>
{{ point.description }}
</option>
{% endif %}
{% endfor %}
</select>
<button
class=
"add-vector"
>
{{ self.add_vector_label }}
</button>
<button
class=
"reset"
>
Reset
</button>
<button
class=
"undo"
title=
"Undo"
><span
class=
"fa fa-undo"
/></button>
<button
class=
"redo"
title=
"redo"
><span
class=
"fa fa-repeat"
/></button>
</div>
{% if self.show_vector_properties %}
<div
class=
"vector-properties"
>
<h3>
{{ self.vector_properties_label }}
</h3>
<div
class=
"vector-prop-name"
>
name:
<span
class=
"value vector-prop-bold"
>
-
</span>
</div>
<div
class=
"vector-prop-length"
>
length:
<span
class=
"value"
>
-
</span>
</div>
<div
class=
"vector-prop-angle"
>
angle:
<span
class=
"value"
>
-
</span>
°
</div>
<div
class=
"vector-prop-slope"
>
slope:
<span
class=
"value"
>
-
</span>
</div>
</div>
{% endif %}
</div>
</div>
<div
class=
"vectordraw-status"
>
<div
class=
"vectordraw-status"
>
<span
class=
"correctness icon-2x"
></span>
<span
class=
"correctness icon-2x"
></span>
...
...
vectordraw/static/js/src/vectordraw.js
View file @
06d0cbbf
...
@@ -92,45 +92,7 @@ function VectorDrawXBlock(runtime, element, init_args) {
...
@@ -92,45 +92,7 @@ function VectorDrawXBlock(runtime, element, init_args) {
return
settings
;
return
settings
;
};
};
VectorDraw
.
prototype
.
template
=
_
.
template
([
'<div class="jxgboard" style="width:<%= width %>px; height:<%= height %>px;" />'
,
'<div class="menu">'
,
' <div class="controls">'
,
' <select>'
,
' <% vectors.forEach(function(vec, idx) { %>'
,
' <option value="vector-<%= idx %>"><%= vec.description %></option>'
,
' <% }) %>'
,
' <% points.forEach(function(point, idx) { if (!point.fixed) { %>'
,
' <option value="point-<%= idx %>"><%= point.description %></option>'
,
' <% }}) %>'
,
' </select>'
,
' <button class="add-vector"><%= add_vector_label %></button>'
,
' <button class="reset">Reset</button>'
,
' <button class="undo" title="Undo"><span class="fa fa-undo" /></button>'
,
' <button class="redo" title="redo"><span class="fa fa-repeat" /></button>'
,
' </div>'
,
' <% if (show_vector_properties) { %>'
,
' <div class="vector-properties">'
,
' <h3><%= vector_properties_label %></h3>'
,
' <div class="vector-prop-name">'
,
' name: <span class="value vector-prop-bold">-</span>'
,
' </div>'
,
' <div class="vector-prop-length">'
,
' length: <span class="value">-</span>'
,
' </div>'
,
' <div class="vector-prop-angle">'
,
' angle: <span class="value">-</span>°'
,
' </div>'
,
' <div class="vector-prop-slope">'
,
' slope: <span class="value">-</span>'
,
' </div>'
,
' </div>'
,
' <% } %>'
,
'</div>'
].
join
(
'
\
n'
));
VectorDraw
.
prototype
.
render
=
function
()
{
VectorDraw
.
prototype
.
render
=
function
()
{
this
.
element
.
html
(
this
.
template
(
this
.
settings
));
// Assign the jxgboard element a random unique ID,
// Assign the jxgboard element a random unique ID,
// because JXG.JSXGraph.initBoard needs it.
// because JXG.JSXGraph.initBoard needs it.
this
.
element
.
find
(
'.jxgboard'
).
prop
(
'id'
,
_
.
uniqueId
(
'jxgboard'
));
this
.
element
.
find
(
'.jxgboard'
).
prop
(
'id'
,
_
.
uniqueId
(
'jxgboard'
));
...
@@ -172,16 +134,33 @@ function VectorDrawXBlock(runtime, element, init_args) {
...
@@ -172,16 +134,33 @@ function VectorDrawXBlock(runtime, element, init_args) {
}
}
}
}
this
.
settings
.
points
.
forEach
(
function
(
point
,
idx
)
{
var
noOptionSelected
=
true
;
if
(
point
.
render
)
{
this
.
renderPoint
(
idx
);
function
renderOrEnableOption
(
element
,
idx
,
type
,
board
)
{
if
(
element
.
render
)
{
if
(
type
===
'point'
)
{
board
.
renderPoint
(
idx
);
}
else
{
board
.
renderVector
(
idx
);
}
}
else
{
// Enable corresponding option in menu ...
var
option
=
board
.
getMenuOption
(
type
,
idx
);
option
.
prop
(
'disabled'
,
false
);
// ... and select it if no option is currently selected
if
(
noOptionSelected
)
{
option
.
prop
(
'selected'
,
true
);
noOptionSelected
=
false
;
}
}
}
}
this
.
settings
.
points
.
forEach
(
function
(
point
,
idx
)
{
renderOrEnableOption
(
point
,
idx
,
'point'
,
this
);
},
this
);
},
this
);
this
.
settings
.
vectors
.
forEach
(
function
(
vec
,
idx
)
{
this
.
settings
.
vectors
.
forEach
(
function
(
vec
,
idx
)
{
if
(
vec
.
render
)
{
renderOrEnableOption
(
vec
,
idx
,
'vector'
,
this
);
this
.
renderVector
(
idx
);
}
},
this
);
},
this
);
this
.
board
.
on
(
'down'
,
this
.
onBoardDown
.
bind
(
this
));
this
.
board
.
on
(
'down'
,
this
.
onBoardDown
.
bind
(
this
));
...
...
vectordraw/vectordraw.py
View file @
06d0cbbf
...
@@ -271,7 +271,15 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
...
@@ -271,7 +271,15 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
"""
"""
Load info about points for this exercise from JSON string specified by course author.
Load info about points for this exercise from JSON string specified by course author.
"""
"""
return
json
.
loads
(
self
.
points
)
points
=
json
.
loads
(
self
.
points
)
for
point
in
points
:
# If author did not specify whether point should be drawn in fixed location (True)
# or placed by student (False), we default to True;
# template needs this info to determine whether it should add option
# for selecting point to dropdown menu:
if
'fixed'
not
in
point
:
point
[
'fixed'
]
=
True
return
points
@property
@property
def
get_expected_result
(
self
):
def
get_expected_result
(
self
):
...
...
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