Skip to content

Commit

Permalink
Keep items in dropped position in assessment mode.
Browse files Browse the repository at this point in the history
Items dropped onto wrong zones in standard mode are immediately removed
from the board and sent back to the bank.

In assessment mode, items should stick in the dropped position until the
entire problem is explicitly submitted by clicking a button.

This commit only implements the "stick" part, but does not implement the
submit button and associated handler.

This commit also fixes an existing bug where the template function
would gett reused between blocks.

The template function (which is slightly different for each block,
depending on block's configuration) was getting assigned to the global
DragAndDropBlock function. Each block would overwrite the previous
value, which caused bugs.
  • Loading branch information
mtyaka committed Jul 30, 2016
1 parent 7fd8c2e commit 5455b50
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 79 deletions.
19 changes: 13 additions & 6 deletions drag_and_drop_v2/drag_and_drop_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def items_without_answers():
return items

return {
"mode": self.mode,
"zones": self._get_zones(),
# SDK doesn't supply url_name.
"url_name": getattr(self, 'url_name', ''),
Expand Down Expand Up @@ -309,12 +310,18 @@ def do_attempt(self, attempt, suffix=''):
'is_correct': is_correct,
})

return {
'correct': is_correct,
'finished': self._is_finished(),
'overall_feedback': overall_feedback,
'feedback': feedback
}
if self.mode == self.ASSESSMENT_MODE:
# In assessment mode we don't send any feedback on drop.
result = {}
else:
result = {
'correct': is_correct,
'finished': self._is_finished(),
'overall_feedback': overall_feedback,
'feedback': feedback
}

return result

@XBlock.json_handler
def reset(self, data, suffix=''):
Expand Down
52 changes: 34 additions & 18 deletions drag_and_drop_v2/public/js/drag_and_drop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function DragNDropTemplates(url_name) {
function DragAndDropTemplates(configuration) {
"use strict";
var h = virtualDom.h;
// Set up a mock for gettext if it isn't available in the client runtime:
Expand Down Expand Up @@ -107,13 +107,22 @@ function DragNDropTemplates(url_name) {
var item_content = h('div', { innerHTML: item_content_html, className: "item-content" });
if (item.is_placed) {
// Insert information about zone in which this item has been placed
var item_description_id = url_name + '-item-' + item.value + '-description';
var item_description_id = configuration.url_name + '-item-' + item.value + '-description';
item_content.properties.attributes = { 'aria-describedby': item_description_id };
var zone_title = (zone.title || "Unknown Zone"); // This "Unknown" text should never be seen, so does not need i18n
var description_content;
if (configuration.mode === DragAndDropBlock.ASSESSMENT_MODE) {
// In assessment mode placed items will "stick" even when not in correct zone.
description_content = gettext('Placed in: {zone_title}').replace('{zone_title}', zone_title);
} else {
// In standard mode item is immediately returned back to the bank if dropped on a wrong zone,
// so all placed items are always in the correct zone.
description_content = gettext('Correctly placed in: {zone_title}').replace('{zone_title}', zone_title);
}
var item_description = h(
'div',
{ id: item_description_id, className: 'sr' },
gettext('Correctly placed in: ') + zone_title
description_content
);
children.splice(1, 0, item_description);
}
Expand Down Expand Up @@ -283,14 +292,17 @@ function DragNDropTemplates(url_name) {
);
};

DragAndDropBlock.renderView = mainTemplate;

return mainTemplate;
}

function DragAndDropBlock(runtime, element, configuration) {
"use strict";

DragNDropTemplates(configuration.url_name);
DragAndDropBlock.STANDARD_MODE = 'standard';
DragAndDropBlock.ASSESSMENT_MODE = 'assessment';

var renderView = DragAndDropTemplates(configuration);

// Set up a mock for gettext if it isn't available in the client runtime:
if (!window.gettext) { window.gettext = function gettext_stub(string) { return string; }; }

Expand Down Expand Up @@ -747,17 +759,21 @@ function DragAndDropBlock(runtime, element, configuration) {

$.post(url, JSON.stringify(data), 'json')
.done(function(data){
state.last_action_correct = data.correct;
if (data.correct) {
state.items[item_id].correct = true;
state.items[item_id].submitting_location = false;
} else {
delete state.items[item_id];
}
state.feedback = data.feedback;
if (data.finished) {
state.finished = true;
state.overall_feedback = data.overall_feedback;
state.items[item_id].submitting_location = false;
// In standard mode we immediately return item to the bank if dropped on wrong zone.
// In assessment mode we leave it in the chosen zone until explicit answer submission.
if (configuration.mode === DragAndDropBlock.STANDARD_MODE) {
state.last_action_correct = data.correct;
if (data.correct) {
state.items[item_id].correct = true;
} else {
delete state.items[item_id];
}
state.feedback = data.feedback;
if (data.finished) {
state.finished = true;
state.overall_feedback = data.overall_feedback;
}
}
applyState();
})
Expand Down Expand Up @@ -866,7 +882,7 @@ function DragAndDropBlock(runtime, element, configuration) {
display_reset_button: Object.keys(state.items).length > 0,
};

return DragAndDropBlock.renderView(context);
return renderView(context);
};

/**
Expand Down
4 changes: 4 additions & 0 deletions drag_and_drop_v2/translations/en/LC_MESSAGES/text.po
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ msgstr ""
msgid "ok"
msgstr ""

#: public/js/drag_and_drop.js
msgid "Placed in: "
msgstr ""

#: public/js/drag_and_drop.js
msgid "Correctly placed in: "
msgstr ""
Expand Down
4 changes: 4 additions & 0 deletions drag_and_drop_v2/translations/eo/LC_MESSAGES/text.po
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ msgstr "Çänçél Ⱡ'σяєм ιρѕυ#"
msgid "ok"
msgstr "ök Ⱡ'σя#"

#: public/js/drag_and_drop.js
msgid "Placed in: "
msgstr "Pläçéd ïn: Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, #"

#: public/js/drag_and_drop.js
msgid "Correctly placed in: "
msgstr "Çörréçtlý pläçéd ïn: Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, #"
Expand Down
Loading

0 comments on commit 5455b50

Please sign in to comment.