Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions www/addons/mod/lesson/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"emptypassword": "Password cannot be empty",
"enterpassword": "Please enter the password:",
"eolstudentoutoftimenoanswers": "You did not answer any questions. You have received a 0 for this lesson.",
"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.",
"errorreviewretakenotlast": "This attempt can no longer be reviewed because another attempt has been finished.",
"finish": "Finish",
"finishretakeoffline": "This attempt was finished offline.",
Expand Down
4 changes: 2 additions & 2 deletions www/addons/mod/lesson/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ angular.module('mm.addons.mod_lesson')

$mmaModLessonPrefetchHandler.getDownloadSize(module, courseId).then(function(size) {
$mmUtil.confirmDownloadSize(size).then(function() {
$mmaModLessonPrefetchHandler.prefetch(module, courseId).catch(function() {
$mmaModLessonPrefetchHandler.prefetch(module, courseId).catch(function(error) {
if (!$scope.$$destroyed) {
$mmUtil.showErrorModal('mm.core.errordownloading', true);
$mmUtil.showErrorModalDefault(error, 'mm.core.errordownloading', true);
}
});
}).catch(function() {
Expand Down
2 changes: 2 additions & 0 deletions www/addons/mod/lesson/services/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ angular.module('mm.addons.mod_lesson')
self.LESSON_UNSEENBRANCHPAGE = -50;
// Jump to a random page within a branch and end of branch or end of lesson.
self.LESSON_RANDOMPAGE = -60;
// Jump to a random Branch.
self.LESSON_RANDOMBRANCH = -70;
// Cluster Jump.
self.LESSON_CLUSTERJUMP = -80;

Expand Down
25 changes: 21 additions & 4 deletions www/addons/mod/lesson/services/prefetch_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ angular.module('mm.addons.mod_lesson')
* @name $mmaModLessonPrefetchHandler
*/
.factory('$mmaModLessonPrefetchHandler', function($mmaModLesson, $q, $mmPrefetchFactory, mmaModLessonComponent, $mmUtil, $mmGroups,
$mmSite, $mmFilepool, $rootScope, $timeout, $ionicModal, mmCoreDontShowError, $mmCourse) {
$mmSite, $mmFilepool, $rootScope, $timeout, $ionicModal, mmCoreDontShowError, $mmCourse, $mmLang) {

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

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

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

// Get the data for each page.
angular.forEach(pages, function(data) {
// Check if any page has a RANDOMBRANCH jump.
angular.forEach(data.jumps, function(jump) {
if (jump == $mmaModLesson.LESSON_RANDOMBRANCH) {
hasRandomBranch = true;
}
});

// Get the page data.
subPromises.push($mmaModLesson.getPageData(lesson, data.page.id, password, false, true, false,
true, undefined, undefined, siteId).then(function(pageData) {

Expand All @@ -449,6 +458,16 @@ angular.module('mm.addons.mod_lesson')
}));
});

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

return $q.all(subPromises);
}));

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

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

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