Skip to content

Commit b467acc

Browse files
committed
Merge pull request #285 from dpalou/MOBILE-1316
MOBILE-1316 courses: Fix repeated addons in courses delegate
2 parents 0b4289c + 5e7323c commit b467acc

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

www/core/components/courses/services/delegate.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,14 @@ angular.module('mm.core.courses')
176176
* @protected
177177
*/
178178
self.updateNavHandlersForCourse = function(courseId) {
179-
var promises = [];
180-
181-
$mmUtil.emptyArray(coursesHandlers[courseId]);
179+
var promises = [],
180+
enabledForCourse = [];
182181

183182
angular.forEach(enabledNavHandlers, function(handler) {
184183
// Checks if the handler is enabled for the user.
185184
var promise = $q.when(handler.instance.isEnabledForCourse(courseId)).then(function(enabled) {
186185
if (enabled) {
187-
coursesHandlers[courseId].push({
188-
controller: handler.instance.getController(courseId),
189-
priority: handler.priority
190-
});
186+
enabledForCourse.push(handler);
191187
} else {
192188
return $q.reject();
193189
}
@@ -202,6 +198,15 @@ angular.module('mm.core.courses')
202198
}).catch(function() {
203199
// Never fails.
204200
return true;
201+
}).finally(function() {
202+
// Update the coursesHandlers array with the new enabled addons.
203+
$mmUtil.emptyArray(coursesHandlers[courseId]);
204+
angular.forEach(enabledForCourse, function(handler) {
205+
coursesHandlers[courseId].push({
206+
controller: handler.instance.getController(courseId),
207+
priority: handler.priority
208+
});
209+
});
205210
});
206211
};
207212

0 commit comments

Comments
 (0)