Skip to content

Commit b306de2

Browse files
pkulkarkfarhaanbukhsh
authored andcommitted
feat: replace hint settings with reset option
1 parent b199192 commit b306de2

File tree

6 files changed

+59
-12
lines changed

6 files changed

+59
-12
lines changed

branching_xblock/branching_xblock.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ class BranchingXBlock(XBlock):
6565
help="Enable scoring for gradebook integration"
6666
)
6767

68-
enable_hints = Boolean(
68+
enable_reset_activity = Boolean(
6969
default=False,
70-
scope=Scope.settings,
71-
help="Allow learners to reveal hints for each node"
70+
scope=Scope.content,
71+
help="Allow learners to reset the activity"
7272
)
7373

7474
max_score = Float(
@@ -215,7 +215,7 @@ def studio_view(self, context=None):
215215
"start_node_id": self.scenario_data.get("start_node_id"),
216216
"enable_undo": bool(self.enable_undo),
217217
"enable_scoring": bool(self.enable_scoring),
218-
"enable_hints": bool(self.enable_hints),
218+
"enable_reset_activity": bool(self.enable_reset_activity),
219219
"max_score": self.max_score,
220220
"display_name": self.display_name,
221221
"authoring_help_html": authoring_help_html,
@@ -230,7 +230,7 @@ def _get_state(self):
230230
"start_node_id": self.scenario_data.get("start_node_id"),
231231
"enable_undo": bool(self.enable_undo),
232232
"enable_scoring": bool(self.enable_scoring),
233-
"enable_hints": bool(self.enable_hints),
233+
"enable_reset_activity": bool(self.enable_reset_activity),
234234
"max_score": self.max_score,
235235
"display_name": self.display_name,
236236
"current_node": self.get_current_node(),
@@ -294,6 +294,26 @@ def undo_choice(self, data, suffix=''):
294294
self.has_completed = False
295295
return {"success": True, **self._get_state()}
296296

297+
@XBlock.json_handler
298+
def reset_activity(self, data, suffix=''):
299+
"""
300+
Reset learner state to the start node.
301+
"""
302+
if not self.enable_reset_activity:
303+
return {"success": False, "error": "Reset not allowed"}
304+
305+
self.current_node_id = None
306+
self.history = []
307+
self.has_completed = False
308+
309+
if self.enable_scoring:
310+
self.score = 0.0
311+
self.publish_grade()
312+
313+
self.start_node()
314+
self.runtime.publish(self, "completion", {"completion": 0.0})
315+
return {"success": True, **self._get_state()}
316+
297317
@XBlock.json_handler
298318
def studio_submit(self, data, suffix=''):
299319
"""
@@ -370,7 +390,7 @@ def studio_submit(self, data, suffix=''):
370390
}
371391
self.enable_undo = bool(payload.get('enable_undo', self.enable_undo))
372392
self.enable_scoring = bool(payload.get('enable_scoring', self.enable_scoring))
373-
self.enable_hints = bool(payload.get('enable_hints', self.enable_hints))
393+
self.enable_reset_activity = bool(payload.get('enable_reset_activity', self.enable_reset_activity))
374394
self.max_score = float(payload.get('max_score', self.max_score))
375395
self.display_name = payload.get('display_name', self.display_name)
376396

branching_xblock/static/css/branching_xblock.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@
197197
margin-left: 1em;
198198
}
199199

200+
.reset-button {
201+
border: 1px solid #4a5568;
202+
border-radius: 4px;
203+
padding: 0.6em 1.2em;
204+
font-size: 1em;
205+
cursor: pointer;
206+
background: transparent;
207+
color: #1f2a37;
208+
}
209+
200210
.score-display {
201211
padding: 1em 1em;
202212
font-size: small;

branching_xblock/static/handlebars/settings-panel.handlebars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
Enable scoring
1313
</label>
1414
<label>
15-
<input type="checkbox" name="enable_hints" {{#if enable_hints}}checked{{/if}}/>
16-
Allow learners to reveal hints
15+
<input type="checkbox" name="enable_reset_activity" {{#if enable_reset_activity}}checked{{/if}}/>
16+
Enable reset activity
1717
</label>
1818
<label>
1919
Max Score:

branching_xblock/static/html/branching_xblock.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
<div class="choices" data-role="choices"></div>
1515

1616
<button class="undo-button action-secondary btn-secondary" data-role="undo" style="display: none;">
17-
<i class="fa fa-undo" aria-hidden="true"></i>&nbsp;Undo
17+
Go Back
18+
</button>
19+
<button type="button" class="reset-button action-secondary btn-secondary" data-role="reset-activity" style="display: none;">
20+
Reset
1821
</button>
1922

2023
<div class="score-display" data-role="score" style="display: none;"></div>

branching_xblock/static/js/src/branching_xblock.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ function BranchingXBlock(runtime, element) {
133133
const $hintContainer = $el.find('[data-role="hint-container"]');
134134
const $hintDetails = $hintContainer.find('[data-role="hint-collapsible"]');
135135
const $hint = $hintDetails.find('[data-role="hint"]');
136-
if (state.enable_hints && node && node.hint) {
137-
$hint.html(`<strong>Hint:</strong> ${node.hint}`);
136+
const hintText = (node && node.hint ? String(node.hint) : '').trim();
137+
if (node && hintText) {
138+
$hint.html(`<strong>Hint:</strong> ${hintText}`);
138139
$hintDetails.prop('hidden', false);
139140
setHintVisibility(isHintVisible);
140141
} else {
@@ -159,6 +160,9 @@ function BranchingXBlock(runtime, element) {
159160
const canUndo = state.enable_undo && state.history.length > 0;
160161
$el.find('.undo-button').toggle(canUndo);
161162

163+
const showReset = Boolean(state.enable_reset_activity);
164+
$el.find('[data-role="reset-activity"]').toggle(showReset);
165+
162166
const $score = $el.find('[data-role="score"]');
163167
const isLeaf = choices.length === 0;
164168
if (isLeaf && state.enable_scoring) {
@@ -203,6 +207,16 @@ function BranchingXBlock(runtime, element) {
203207
}).done(refreshView);
204208
});
205209

210+
$el.on('click', '[data-role="reset-activity"]', function() {
211+
$.ajax({
212+
url: runtime.handlerUrl(element, 'reset_activity'),
213+
type: 'POST',
214+
data: JSON.stringify({}),
215+
contentType: 'application/json',
216+
dataType: 'json'
217+
}).done(refreshView);
218+
});
219+
206220
// Initial load
207221
refreshView();
208222

branching_xblock/static/js/src/studio_editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function BranchingStudioEditor(runtime, element, data) {
183183
nodes: [],
184184
enable_undo: $settings.find('[name="enable_undo"]').is(':checked'),
185185
enable_scoring: $settings.find('[name="enable_scoring"]').is(':checked'),
186-
enable_hints: $settings.find('[name="enable_hints"]').is(':checked'),
186+
enable_reset_activity: $settings.find('[name="enable_reset_activity"]').is(':checked'),
187187
max_score: parseFloat($settings.find('[name="max_score"]').val()) || 0,
188188
display_name: $settings.find('[name="display_name"]').val()?.trim() || ''
189189
};

0 commit comments

Comments
 (0)