Skip to content

Commit 95bbb1e

Browse files
authored
Merge pull request #1056 from dpalou/MOBILE-2103
MOBILE-2103 lesson: Show warning when prefetch lesson with RANDOMBRANCH
2 parents cb64404 + 4f03f8a commit 95bbb1e

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

www/addons/mod/lesson/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"emptypassword": "Password cannot be empty",
2222
"enterpassword": "Please enter the password:",
2323
"eolstudentoutoftimenoanswers": "You did not answer any questions. You have received a 0 for this lesson.",
24+
"errorprefetchrandombranch": "This lesson contains a jump to a random content page, it cannot be attempted in the app until it has been started in web.",
2425
"errorreviewretakenotlast": "This attempt can no longer be reviewed because another attempt has been finished.",
2526
"finish": "Finish",
2627
"finishretakeoffline": "This attempt was finished offline.",

www/addons/mod/lesson/services/handlers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ angular.module('mm.addons.mod_lesson')
9898

9999
$mmaModLessonPrefetchHandler.getDownloadSize(module, courseId).then(function(size) {
100100
$mmUtil.confirmDownloadSize(size).then(function() {
101-
$mmaModLessonPrefetchHandler.prefetch(module, courseId).catch(function() {
101+
$mmaModLessonPrefetchHandler.prefetch(module, courseId).catch(function(error) {
102102
if (!$scope.$$destroyed) {
103-
$mmUtil.showErrorModal('mm.core.errordownloading', true);
103+
$mmUtil.showErrorModalDefault(error, 'mm.core.errordownloading', true);
104104
}
105105
});
106106
}).catch(function() {

www/addons/mod/lesson/services/lesson.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ angular.module('mm.addons.mod_lesson')
6464
self.LESSON_UNSEENBRANCHPAGE = -50;
6565
// Jump to a random page within a branch and end of branch or end of lesson.
6666
self.LESSON_RANDOMPAGE = -60;
67+
// Jump to a random Branch.
68+
self.LESSON_RANDOMBRANCH = -70;
6769
// Cluster Jump.
6870
self.LESSON_CLUSTERJUMP = -80;
6971

www/addons/mod/lesson/services/prefetch_handler.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ angular.module('mm.addons.mod_lesson')
2222
* @name $mmaModLessonPrefetchHandler
2323
*/
2424
.factory('$mmaModLessonPrefetchHandler', function($mmaModLesson, $q, $mmPrefetchFactory, mmaModLessonComponent, $mmUtil, $mmGroups,
25-
$mmSite, $mmFilepool, $rootScope, $timeout, $ionicModal, mmCoreDontShowError, $mmCourse) {
25+
$mmSite, $mmFilepool, $rootScope, $timeout, $ionicModal, mmCoreDontShowError, $mmCourse, $mmLang) {
2626

2727
var self = $mmPrefetchFactory.createPrefetchHandler(mmaModLessonComponent, false);
2828

@@ -426,10 +426,19 @@ angular.module('mm.addons.mod_lesson')
426426

427427
// Get the list of pages.
428428
promises.push($mmaModLesson.getPages(lesson.id, password, false, true, siteId).then(function(pages) {
429-
var subPromises = [];
429+
var subPromises = [],
430+
hasRandomBranch = false;
430431

431432
// Get the data for each page.
432433
angular.forEach(pages, function(data) {
434+
// Check if any page has a RANDOMBRANCH jump.
435+
angular.forEach(data.jumps, function(jump) {
436+
if (jump == $mmaModLesson.LESSON_RANDOMBRANCH) {
437+
hasRandomBranch = true;
438+
}
439+
});
440+
441+
// Get the page data.
433442
subPromises.push($mmaModLesson.getPageData(lesson, data.page.id, password, false, true, false,
434443
true, undefined, undefined, siteId).then(function(pageData) {
435444

@@ -449,6 +458,16 @@ angular.module('mm.addons.mod_lesson')
449458
}));
450459
});
451460

461+
// Prefetch the list of possible jumps for offline navigation. Do it here so we know hasRandomBranch.
462+
subPromises.push($mmaModLesson.getPagesPossibleJumps(lesson.id, false, true, siteId).catch(function(error) {
463+
if (hasRandomBranch) {
464+
// The WebSevice probably failed because RANDOMBRANCH aren't supported if the user hasn't seen any page.
465+
return $mmLang.translateAndReject('mma.mod_lesson.errorprefetchrandombranch');
466+
} else {
467+
return $q.reject(error);
468+
}
469+
}));
470+
452471
return $q.all(subPromises);
453472
}));
454473

@@ -457,8 +476,6 @@ angular.module('mm.addons.mod_lesson')
457476
// Ignore errors.
458477
}));
459478

460-
// Prefetch the list of possible jumps for offline navigation.
461-
promises.push($mmaModLesson.getPagesPossibleJumps(lesson.id, false, true, siteId));
462479

463480
// Prefetch viewed pages in last retake to calculate progress.
464481
promises.push($mmaModLesson.getContentPagesViewedOnline(lesson.id, retake, false, true, siteId));

0 commit comments

Comments
 (0)