Skip to content

Commit 2e31303

Browse files
committed
fix: remove 'redirect to another unit in the same subsection' and repair the rest of the actions
1 parent bc0a4e9 commit 2e31303

File tree

7 files changed

+31
-107
lines changed

7 files changed

+31
-107
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Unreleased
1414

1515
*
1616

17-
[1.2.0] - 2025-01-23
17+
[2.0.0] - 2025-01-23
1818
**********************************************
1919

2020
Added
@@ -28,6 +28,7 @@ _______
2828

2929
* **BREAKING CHANGE**: Dropped support for Python 3.5
3030
* Drop CircleCI support
31+
* Remove support to "redirect to another unit in the same subsection" action
3132

3233
Changed
3334
=======
@@ -41,6 +42,7 @@ Fixed
4142
_____
4243

4344
* Python3 and Juniper issues
45+
* Fix applyFlowControl in injection to applied correctly the actions of flow-control
4446

4547

4648
[1.0.0] - 2020-06-18

README.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Compatibility Notes
1313
+------------------+--------------+
1414
| Open edX Release | Version |
1515
+==================+==============+
16-
| Redwood | >= 1.2.0 |
16+
| Redwood | >= 2.0.0 |
1717
+------------------+--------------+
18-
| Sumac | >= 1.2.0 |
18+
| Sumac | >= 2.0.0 |
1919
+------------------+--------------+
2020

2121
Installing on Open edX Devstack
@@ -29,8 +29,6 @@ However, if you want to further develop this XBlock, you might want to instead c
2929

3030
pip install -e path/to/flow-control
3131

32-
⚠️ Since the Open edX Olive release, some features could fail because of the integration of [Learning MFE](https://github.com/eduNEXT/frontend-app-learning).
33-
3432

3533
Enabling in Studio
3634
------------------
@@ -94,7 +92,7 @@ Features include
9492
**Actions:** This actions can be applied when a condition is met:
9593

9694
* Display a message
97-
* Redirect to another unit in the same subsection (without reloading the page)
95+
* Redirect to another unit in the same subsection (without reloading the page) :warning:[DEPRECATED: Since version 2.0.0 and not working with MFE Learning]
9896
* Redirect to another unit using jump_to_id (reloading the page)
9997
* Redirect to a given url
10098

flow_control/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Init for main Flow-Control XBlock
33
"""
44
from .flow import FlowCheckPointXblock
5-
__version__ = '1.2.0'
5+
__version__ = '2.0.0'

flow_control/flow.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ def _actions_generator(block): # pylint: disable=unused-argument
3737
"value": "display_message"},
3838
{"display_name": "Redirect using jump_to_id",
3939
"value": "to_jump"},
40-
{"display_name": "Redirect to a given unit in the same subsection",
41-
"value": "to_unit"},
4240
{"display_name": "Redirect to a given URL",
4341
"value": "to_url"}
4442
]
@@ -128,17 +126,13 @@ class FlowCheckPointXblock(StudioEditableXBlockMixin, XBlock):
128126
scope=Scope.content,
129127
display_name="Score percentage")
130128

131-
tab_to = Integer(help="Number of unit tab to redirect to. (1, 2, 3...)",
132-
default=1,
133-
scope=Scope.content,
134-
display_name="Tab to redirect to")
135-
136129
target_url = String(help="URL to redirect to, supports relative "
137130
"or absolute urls",
138131
scope=Scope.content,
139132
display_name="URL to redirect to")
140133

141-
target_id = String(help="Unit identifier to redirect to (Location id)",
134+
target_id = String(help="Unit identifier to redirect to (Location id). "
135+
"Use this action when you want to redirect any of the course units.",
142136
scope=Scope.content,
143137
display_name="Unit identifier to redirect to")
144138

@@ -174,27 +168,10 @@ class FlowCheckPointXblock(StudioEditableXBlockMixin, XBlock):
174168
'operator',
175169
'ref_value',
176170
'action',
177-
'tab_to',
178171
'target_url',
179172
'target_id',
180173
'message')
181174

182-
def validate_field_data(self, validation, data):
183-
"""
184-
Validate this block's field data
185-
"""
186-
187-
if data.tab_to <= 0:
188-
validation.add(ValidationMessage(
189-
ValidationMessage.ERROR,
190-
u"Tab to redirect to must be greater than zero"))
191-
192-
if data.ref_value < 0 or data.ref_value > 100:
193-
validation.add(ValidationMessage(
194-
ValidationMessage.ERROR,
195-
u"Score percentage field must "
196-
u"be an integer number between 0 and 100"))
197-
198175
def get_location_string(self, locator, is_draft=False):
199176
""" Returns the location string for one problem, given its id """
200177
# pylint: disable=no-member
@@ -252,13 +229,10 @@ def student_view(self, context=None): # pylint: disable=unused-argument
252229
# pylint: disable=no-member
253230
in_studio_runtime = hasattr(self.xmodule_runtime, 'is_author_mode')
254231
index_base = 1
255-
default_tab = 'tab_{}'.format(self.tab_to - index_base)
256232

257233
fragment.initialize_js(
258234
'FlowControlGoto',
259235
json_args={"display_name": self.display_name,
260-
"default": default_tab,
261-
"default_tab_id": self.tab_to,
262236
"action": self.action,
263237
"target_url": self.target_url,
264238
"target_id": self.target_id,

flow_control/static/js/injection.js

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11

22
var settings = {
3-
timeToCheck: 1,
4-
tabTogo: null,
5-
defaulTabId: null,
63
defaultAction: 1,
74
targetUrl: null,
85
targetId: null,
9-
lmsBaseJumpUrl: '../../../jump_to_id/',
106
message: null,
117
conditionReached: null,
128
inStudioRuntime: false
139
};
1410

1511
var actions = {
1612
noAct: 'No action',
17-
redirectTab: 'to_unit',
1813
redirectUrl: 'to_url',
1914
redirectJump: 'to_jump',
2015
show_message: 'display_message'
@@ -44,17 +39,15 @@ var uiSelectors = {
4439
};
4540

4641
var viewblocks = {
47-
seqContent: $('#seq_content'),
42+
seqContent: $('#course-content'),
43+
loadingMessageHtml: "<div><p>Loading, please wait...</p></div>",
4844
hideNotAllowedOption: function hideNotAllowedOption() {
4945
$(uiSelectors.settingsFields).hide();
5046
$(uiSelectors.settingsFields).filter('[data-field-name="condition"]').show();
5147
$(uiSelectors.settingsFields).filter('[data-field-name="action"]').show();
5248
$(uiSelectors.settingsFields).filter('[data-field-name="operator"]').show();
5349

5450
switch ($(uiSelectors.action).val()) {
55-
case actions.redirectTab:
56-
$(uiSelectors.settingsFields).filter('[data-field-name="tab_to"]').show();
57-
break;
5851
case actions.redirectUrl:
5952
$(uiSelectors.settingsFields).filter('[data-field-name="target_url"]').show();
6053
break;
@@ -89,81 +82,27 @@ var viewblocks = {
8982
switch (settings.defaultAction) {
9083
case actions.noAct:
9184
break;
92-
case actions.redirectTab:
93-
viewblocks.seqContent.empty();
94-
window.flowControlTimeoutID = window.setTimeout(redirectToTab,
95-
settings.timeToCheck,
96-
settings.tabTogo);
97-
break;
9885
case actions.redirectUrl:
99-
viewblocks.seqContent.empty();
100-
location.href = settings.targetUrl;
86+
viewblocks.seqContent.html(viewblocks.loadingMessageHtml);
87+
window.parent.location.href = settings.targetUrl;
10188
break;
10289
case actions.redirectJump:
103-
viewblocks.seqContent.empty();
104-
location.href = settings.targetId;
90+
viewblocks.seqContent.html(viewblocks.loadingMessageHtml);
91+
window.parent.location.href = getJumpToIdUrl(settings.targetId);
10592
break;
10693
case actions.show_message:
107-
$('#course-content').html(settings.message);
94+
viewblocks.seqContent.html(settings.message);
10895
break;
10996
}
11097
}
11198
}
11299
};
113100

114-
var getActiveTab = function getActiveTab() {
115-
// return the active sequential button
116-
$tab = $('#course-content #sequence-list button.active')[0];
117-
118-
return $tab;
119-
};
120-
121-
var execControl = function execControl(arg) {
122-
// Find the target tab
123-
var $target = $('#sequence-list button').filter(function filterFunc() {
124-
return $(this).attr('id') === arg;
125-
});
126-
127-
// Do the action
128-
$target.click();
129-
// TODO: can we make this silent. E.g. that it does not post to /handler/xmodule_handler/goto_position
130-
};
131-
132-
var redirectToTab = function redirectToTab(arg) {
133-
var $activeTab = getActiveTab();
134-
var currentID = $activeTab.id;
135-
var allTabs = $('#sequence-list button');
136-
var firstTabIndex = 0;
137-
var firstTab = 'tab_' + firstTabIndex;
138-
var lastTabIndex = allTabs.length - 1;
139-
var lastTab = 'tab_' + lastTabIndex;
140-
141-
if (currentID === arg) {
142-
window.clearTimeout(window.flowControlTimeoutID);
143-
} else {
144-
var whereTo = null;
145-
if (settings.defaulTabId > lastTabIndex) {
146-
whereTo = lastTab;
147-
}
148-
if (settings.defaulTabId < firstTabIndex) {
149-
whereTo = firstTab;
150-
}
151-
if (firstTabIndex <= settings.defaulTabId && settings.defaulTabId <= lastTabIndex) {
152-
whereTo = arg;
153-
}
154-
155-
execControl(whereTo);
156-
window.flowControlTimeoutID = window.setTimeout(redirectToTab, settings.timeToCheck, whereTo);
157-
}
158-
};
159-
160101
function FlowControlGoto(runtime, element, options) {
161102
// Getting settings varibales to apply flow control
162-
settings.tabTogo = options.default;
163103
settings.defaultAction = options.action;
164104
settings.targetUrl = options.target_url;
165-
settings.targetId = settings.lmsBaseJumpUrl + options.target_id;
166-
settings.defaulTabId = options.default_tab_id;
105+
settings.targetId = options.target_id;
167106
settings.message = options.message;
168107
settings.inStudioRuntime = options.in_studio_runtime;
169108

@@ -202,3 +141,16 @@ function StudioFlowControl(runtime, element) {
202141
$(uiSelectors.visibility).hide();
203142
$(uiSelectors.duplicate).hide();
204143
}
144+
145+
function getCourseIdByUrl() {
146+
const regex = /(?:block-v1:)(.+)(?:\+type)/;
147+
const result = window.location.href.match(regex);
148+
if (result) {
149+
return result[1];
150+
}
151+
return null;
152+
}
153+
154+
function getJumpToIdUrl(id) {
155+
return `${window.location.origin}/courses/course-v1:${getCourseIdByUrl()}/jump_to_id/${id}`;
156+
}

flow_control/tests/test_flowcontrol.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ def test_actions_generator(self):
3939
"value": "display_message"},
4040
{"display_name": "Redirect using jump_to_id",
4141
"value": "to_jump"},
42-
{"display_name": "Redirect to a given unit in the same subsection",
43-
"value": "to_unit"},
4442
{"display_name": "Redirect to a given URL",
4543
"value": "to_url"}
4644
]

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.2.0
2+
current_version = 2.0.0
33
commit = True
44
tag = True
55

0 commit comments

Comments
 (0)