Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-activetable
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-activetable
Commits
d14ad362
Commit
d14ad362
authored
Oct 20, 2015
by
Sven Marnach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add status message indicating the number of correct cells.
parent
43193a7d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
4 deletions
+34
-4
activetable/activetable.py
+14
-2
activetable/static/js/src/activetable.js
+20
-2
No files found.
activetable/activetable.py
View file @
d14ad362
...
...
@@ -5,7 +5,7 @@ from __future__ import absolute_import, division, unicode_literals
import
textwrap
from
xblock.core
import
XBlock
from
xblock.fields
import
Dict
,
Float
,
Scope
,
String
from
xblock.fields
import
Dict
,
Float
,
Integer
,
Scope
,
String
from
xblock.fragment
import
Fragment
from
xblock.validation
import
ValidationMessage
from
xblockutils.resources
import
ResourceLoader
...
...
@@ -69,7 +69,10 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
'table_definition'
,
'help_text'
,
'column_widths'
,
'row_heights'
,
'default_tolerance'
]
# Dictionary mapping cell ids to the student answers.
answers
=
Dict
(
scope
=
Scope
.
user_state
)
# Number of correct answers.
num_correct_answers
=
Integer
(
scope
=
Scope
.
user_state
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
ActiveTableXBlock
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
...
...
@@ -132,7 +135,10 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
frag
=
Fragment
(
html
)
frag
.
add_css
(
loader
.
load_unicode
(
'static/css/activetable.css'
))
frag
.
add_javascript
(
loader
.
load_unicode
(
'static/js/src/activetable.js'
))
frag
.
initialize_js
(
'ActiveTableXBlock'
)
frag
.
initialize_js
(
'ActiveTableXBlock'
,
dict
(
num_correct_answers
=
self
.
num_correct_answers
,
num_total_answers
=
len
(
self
.
answers
)
if
self
.
answers
is
not
None
else
None
,
))
return
frag
@XBlock.json_handler
...
...
@@ -149,9 +155,15 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
# Since the previous statement executed without error, the data is well-formed enough to be
# stored. We now know it's a dictionary and all the keys are valid cell ids.
self
.
answers
=
data
self
.
num_correct_answers
=
sum
(
correct_dict
.
itervalues
())
return
correct_dict
def
validate_field_data
(
self
,
validation
,
data
):
"""Validate the data entered by the user.
This handler is called when the "Save" button is clicked in Studio after editing the
properties of this XBlock.
"""
def
add_error
(
msg
):
validation
.
add
(
ValidationMessage
(
ValidationMessage
.
ERROR
,
msg
))
try
:
...
...
activetable/static/js/src/activetable.js
View file @
d14ad362
/* Javascript for ActiveTableXBlock. */
function
ActiveTableXBlock
(
runtime
,
element
)
{
function
ActiveTableXBlock
(
runtime
,
element
,
init_args
)
{
var
checkHandlerUrl
=
runtime
.
handlerUrl
(
element
,
'check_answers'
);
function
updateStatusMessage
(
num_total
,
num_correct
)
{
var
$status_message
=
$
(
'.status-message'
,
element
);
if
(
num_total
==
num_correct
)
{
$status_message
.
text
(
'Great job!'
);
}
else
{
$status_message
.
text
(
'You have '
+
num_correct
+
' out of '
+
num_total
+
' cells correct.'
);
}
}
function
markResponseCells
(
correct_dict
)
{
var
num_total
=
0
,
num_correct
=
0
;
$
.
each
(
correct_dict
,
function
(
cell_id
,
correct
)
{
var
$cell
=
$
(
'#'
+
cell_id
,
element
);
$cell
.
removeClass
(
'right-answer wrong-answer unchecked'
);
if
(
correct
)
$cell
.
addClass
(
'right-answer'
)
else
$cell
.
addClass
(
'wrong-answer'
);
})
num_total
+=
1
;
num_correct
+=
correct
;
});
updateStatusMessage
(
num_total
,
num_correct
);
}
function
checkAnswers
(
e
)
{
...
...
@@ -33,4 +48,7 @@ function ActiveTableXBlock(runtime, element) {
$
(
'#activetable-help-button'
,
element
).
click
(
toggleHelp
);
$
(
'.action .check'
,
element
).
click
(
checkAnswers
);
if
(
init_args
.
num_total_answers
)
{
updateStatusMessage
(
init_args
.
num_total_answers
,
init_args
.
num_correct_answers
);
}
}
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