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
4 changes: 4 additions & 0 deletions upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
This files describes API changes in the Moodle Mobile app,
information provided here is intended especially for developers.

=== 3.4.1 ===

* Some modules implemented a siteId param in the getDownloadSize of their prefetch handler. This param was never sent, so it has been replaced by a "single" param.

=== 3.4 ===

* For performance reasons, $mmCoursesDelegate has changed a bit:
Expand Down
15 changes: 15 additions & 0 deletions www/addons/competency/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,21 @@ angular.module('mm.addons.competency')
});
};

/**
* Prefetch the addon for a certain course.
*
* @param {Object} course Course to prefetch.
* @return {Promise} Promise resolved when the prefetch is finished.
*/
self.prefetch = function(course) {
// Invalidate data to be sure to get the latest info.
return $mmaCompetency.invalidateCourseCompetencies(course.id).catch(function() {
// Ignore errors.
}).then(function() {
return $mmaCompetency.getCourseCompetencies(course.id);
});
};

return self;
};

Expand Down
15 changes: 15 additions & 0 deletions www/addons/coursecompletion/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,21 @@ angular.module('mm.addons.coursecompletion')
});
};

/**
* Prefetch the addon for a certain course.
*
* @param {Object} course Course to prefetch.
* @return {Promise} Promise resolved when the prefetch is finished.
*/
self.prefetch = function(course) {
// Invalidate data to be sure to get the latest info.
return $mmaCourseCompletion.invalidateCourseCompletion(course.id).catch(function() {
// Ignore errors.
}).then(function() {
return $mmaCourseCompletion.getCompletion(course.id);
});
};

return self;
};

Expand Down
15 changes: 15 additions & 0 deletions www/addons/grades/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ angular.module('mm.addons.grades')
};
};

/**
* Prefetch the addon for a certain course.
*
* @param {Object} course Course to prefetch.
* @return {Promise} Promise resolved when the prefetch is finished.
*/
self.prefetch = function(course) {
// Invalidate data to be sure to get the latest info.
return $mmGrades.invalidateGradesTableData(course.id).catch(function() {
// Ignore errors.
}).then(function() {
return $mmGrades.getGradesTable(course.id);
});
};

return self;
};

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 @@ -96,9 +96,9 @@ angular.module('mm.addons.mod_lesson')
downloadBtn.hidden = true;
refreshBtn.hidden = true;

$mmaModLessonPrefetchHandler.getDownloadSize(module, courseId).then(function(size) {
$mmaModLessonPrefetchHandler.getDownloadSize(module, courseId, true).then(function(size) {
$mmUtil.confirmDownloadSize(size).then(function() {
return $mmaModLessonPrefetchHandler.prefetch(module, courseId).catch(function(error) {
return $mmaModLessonPrefetchHandler.prefetch(module, courseId, true).catch(function(error) {
if (!$scope.$$destroyed) {
$mmUtil.showErrorModalDefault(error, 'mm.core.errordownloading', true);
return $q.reject();
Expand Down
13 changes: 6 additions & 7 deletions www/addons/mod/lesson/services/prefetch_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,20 @@ angular.module('mm.addons.mod_lesson')
* @name $mmaModLessonPrefetchHandler#getDownloadSize
* @param {Object} module Module to get the size.
* @param {Number} courseId Course ID the module belongs to.
* @param {String} [siteId] Site ID. If not defined, current site.
* @return {Object} With the file size and a boolean to indicate if it is the total size or only partial.
* @param {Boolean} single True if we're downloading a single module, false if we're downloading a whole section.
* @return {Promise} Resolved With the file size and a boolean to indicate if it is the total size or only partial.
*/
self.getDownloadSize = function(module, courseId, siteId) {
siteId = siteId || $mmSite.getId();

self.getDownloadSize = function(module, courseId, single) {
var lesson,
password,
result;
result,
siteId = $mmSite.getId();

return $mmaModLesson.getLesson(courseId, module.id, siteId).then(function(lessonData) {
lesson = lessonData;

// Get the lesson password if it's needed.
return self.gatherLessonPassword(lesson.id, false, true, true, siteId);
return self.gatherLessonPassword(lesson.id, false, true, single, siteId);
}).then(function(data) {
password = data.password;
lesson = data.lesson || lesson;
Expand Down
4 changes: 2 additions & 2 deletions www/addons/mod/quiz/services/prefetch_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ angular.module('mm.addons.mod_quiz')
* @name $mmaModQuizPrefetchHandler#getDownloadSize
* @param {Object} module Module to get the size.
* @param {Number} courseId Course ID the module belongs to.
* @param {String} [siteId] Site ID. If not defined, current site.
* @param {Boolean} single True if we're downloading a single module, false if we're downloading a whole section.
* @return {Object} With the file size and a boolean to indicate if it is the total size or only partial.
*/
self.getDownloadSize = function(module, courseId, siteId) {
self.getDownloadSize = function(module, courseId, single) {
return {size: -1, total: false};
};

Expand Down
8 changes: 4 additions & 4 deletions www/addons/mod/wiki/services/prefetch_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ angular.module('mm.addons.mod_wiki')
* @name $mmaModWikiPrefetchHandler#getDownloadSize
* @param {Object} module Module to get the size.
* @param {Number} courseId Course ID the module belongs to.
* @param {String} [siteId] Site ID. If not defined, current site.
* @param {Boolean} single True if we're downloading a single module, false if we're downloading a whole section.
* @return {Promise} With the file size and a boolean to indicate if it is the total size or only partial.
*/
self.getDownloadSize = function(module, courseId, siteId) {
var promises = [];
siteId = siteId || $mmSite.getId();
self.getDownloadSize = function(module, courseId, single) {
var promises = [],
siteId = $mmSite.getId();

promises.push(self.getFiles(module, courseId, siteId).then(function(files) {
return $mmUtil.sumFileSizes(files);
Expand Down
61 changes: 60 additions & 1 deletion www/addons/myoverview/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ angular.module('mm.addons.myoverview')
* @ngdoc controller
* @name mmaMyOverviewCtrl
*/
.controller('mmaMyOverviewCtrl', function($scope, $mmaMyOverview, $mmUtil, $q, $mmCourses, $mmCoursesDelegate) {
.controller('mmaMyOverviewCtrl', function($scope, $mmaMyOverview, $mmUtil, $q, $mmCourses, $mmCoursesDelegate, $mmCourseHelper) {
var prefetchIconsInitialized = false;

$scope.tabShown = 'courses';
$scope.timeline = {
Expand All @@ -44,6 +45,11 @@ angular.module('mm.addons.myoverview')
$scope.showFilter = false;

$scope.searchEnabled = $mmCourses.isSearchCoursesAvailable() && !$mmCourses.isSearchCoursesDisabledInSite();
$scope.prefetchCoursesData = {
inprogress: {},
past: {},
future: {}
};

function fetchMyOverviewTimeline(afterEventId, refresh) {
return $mmaMyOverview.getActionEventsByTimesort(afterEventId).then(function(events) {
Expand Down Expand Up @@ -104,6 +110,8 @@ angular.module('mm.addons.myoverview')
$scope.courses.inprogress.push(course);
}
});

initPrefetchCoursesIcons();
}).catch(function(message) {
$mmUtil.showErrorModalDefault(message, 'Error getting my overview data.');
return $q.reject();
Expand Down Expand Up @@ -137,6 +145,34 @@ angular.module('mm.addons.myoverview')
});
}

// Initialize the prefetch icon for selected courses.
function initPrefetchCoursesIcons() {
if (prefetchIconsInitialized) {
// Already initialized.
return;
}

prefetchIconsInitialized = true;

Object.keys($scope.prefetchCoursesData).forEach(function(filter) {
if (!$scope.courses[filter] || $scope.courses[filter].length < 2) {
// Not enough courses.
$scope.prefetchCoursesData[filter].icon = '';
return;
}

$mmCourseHelper.determineCoursesStatus($scope.courses[filter]).then(function(status) {
var icon = $mmCourseHelper.getCourseStatusIconFromStatus(status);
if (icon == 'spinner') {
// It seems all courses are being downloaded, show a download button instead.
icon = 'ion-ios-cloud-download-outline';
}
$scope.prefetchCoursesData[filter].icon = icon;
});

});
}

$scope.switchFilter = function() {
$scope.showFilter = !$scope.showFilter;
if (!$scope.showFilter) {
Expand Down Expand Up @@ -175,6 +211,7 @@ angular.module('mm.addons.myoverview')
}
break;
case 'courses':
prefetchIconsInitialized = false;
promise = fetchMyOverviewCourses();
break;
}
Expand Down Expand Up @@ -238,4 +275,26 @@ angular.module('mm.addons.myoverview')
course.canLoadMore = courseEvents.canLoadMore;
});
};

// Download all the shown courses.
$scope.downloadCourses = function() {
var selected = $scope.courses.selected,
selectedData = $scope.prefetchCoursesData[selected],
initialIcon = selectedData.icon;

selectedData.icon = 'spinner';
selectedData.badge = '';
return $mmCourseHelper.confirmAndPrefetchCourses($scope.courses[selected]).then(function(downloaded) {
selectedData.icon = downloaded ? 'ion-android-refresh' : initialIcon;
}, function(error) {
if (!$scope.$$destroyed) {
$mmUtil.showErrorModalDefault(error, 'mm.course.errordownloadingcourse', true);
selectedData.icon = initialIcon;
}
}, function(progress) {
selectedData.badge = progress.count + ' / ' + progress.total;
}).finally(function() {
selectedData.badge = '';
});
};
});
14 changes: 8 additions & 6 deletions www/addons/myoverview/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
</mm-loading>
<mm-loading hide-until="courses.loaded" ng-show="tabShown == 'courses'" class="mm-loading-center">
<div class="row row-no-padding padding-bottom" ng-show="!showFilter">
<div class="col-10 text-left">
<a ng-if="courses[courses.selected] && courses[courses.selected].length > 5" class="button button-dark button-icon icon ion-funnel" ng-click="switchFilter()"></a>
</div>
<div class="col text-center">
<div class="col">
<div class="item-select mm-full-width-centered">
<select ng-model="courses.selected">
<option value="inprogress">{{ 'mma.myoverview.inprogress' | translate }}</option>
Expand All @@ -41,8 +38,13 @@
</select>
</div>
</div>
<div class="col-10 text-right">
<a ng-class="{'ion-android-apps': !showGrid, 'ion-ios-list-outline': showGrid}" class="button button-dark button-icon icon" ng-click="switchGrid()"></a>
<div class="col-10 text-right" ng-show="courses[courses.selected] && courses[courses.selected].length">
<mm-context-menu>
<mm-context-menu-item ng-show="courses[courses.selected] && courses[courses.selected].length > 1" priority="800" content="'mm.courses.downloadcourses' | translate" action="downloadCourses()" icon-action="prefetchCoursesData[courses.selected].icon" close-on-click="false" badge="prefetchCoursesData[courses.selected].badge"></mm-context-menu-item>
<mm-context-menu-item ng-show="courses[courses.selected] && courses[courses.selected].length > 5" priority="700" content="'mm.courses.filtermycourses' | translate" action="switchFilter()" icon-action="'ion-funnel'"></mm-context-menu-item>
<mm-context-menu-item ng-show="!showGrid" priority="601" content="'mm.core.layoutgrid' | translate" action="switchGrid()" icon-action="'ion-android-apps'"></mm-context-menu-item>
<mm-context-menu-item ng-show="showGrid" priority="600" content="'mm.core.list' | translate" action="switchGrid()" icon-action="'ion-ios-list-outline'"></mm-context-menu-item>
</mm-context-menu>
</div>
</div>
<div ng-show="showFilter" class="item mm-filter-box item-input-inset">
Expand Down
21 changes: 21 additions & 0 deletions www/addons/notes/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,27 @@ angular.module('mm.addons.notes')
});
};

/**
* Prefetch the addon for a certain course.
*
* @param {Object} course Course to prefetch.
* @return {Promise} Promise resolved when the prefetch is finished.
*/
self.prefetch = function(course) {
// Invalidate data to be sure to get the latest info.
return $mmaNotes.invalidateNotes(course.id).catch(function() {
// Ignore errors.
}).then(function() {
return $mmaNotes.getNotes(course.id, false, true);
}).then(function(notesTypes) {
var promises = [];
angular.forEach(notesTypes, function(notes) {
promises.push($mmaNotes.getNotesUserData(notes, course.id));
});
return $mmUtil.allPromises(promises);
});
};

return self;
};

Expand Down
15 changes: 15 additions & 0 deletions www/addons/participants/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ angular.module('mm.addons.participants')
return $mmaParticipants.isPluginEnabledForCourse(courseId);
};

/**
* Prefetch the addon for a certain course.
*
* @param {Object} course Course to prefetch.
* @return {Promise} Promise resolved when the prefetch is finished.
*/
self.prefetch = function(course) {
// Invalidate data to be sure to get the latest info.
return $mmaParticipants.invalidateParticipantsList(course.id).catch(function() {
// Ignore errors.
}).then(function() {
return $mmaParticipants.getAllParticipants(course.id);
});
};

return self;
};

Expand Down
30 changes: 29 additions & 1 deletion www/addons/participants/services/participants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ angular.module('mm.addons.participants')

var self = {};

/**
* Get all the participants for a certain course, performing 1 request per page until there are no more participants.
*
* @module mm.addons.participants
* @ngdoc method
* @name $mmaParticipants#getAllParticipants
* @param {Number} courseId ID of the course.
* @param {Number} [limitFrom] Position of the first participant to get.
* @param {Number} [limitNumber] Number of participants to get in each request.
* @param {String} [siteId] Site Id. If not defined, use current site.
* @return {Promise} Promise to be resolved when the participants are retrieved.
*/
self.getAllParticipants = function(courseId, limitFrom, limitNumber, siteId) {
siteId = siteId || $mmSite.getId();
limitFrom = limitFrom || 0;

return self.getParticipants(courseId, limitFrom, limitNumber, siteId).then(function(data) {
if (data.canLoadMore) {
// Load the next "page".
limitFrom = limitFrom + data.participants.length;
return self.getAllParticipants(courseId, limitFrom, limitNumber, siteId).then(function(nextParts) {
return data.participants.concat(nextParts);
});
}
return data.participants;
});
};

/**
* Get cache key for participant list WS calls.
*
Expand All @@ -43,7 +71,7 @@ angular.module('mm.addons.participants')
* @module mm.addons.participants
* @ngdoc method
* @name $mmaParticipants#getParticipants
* @param {String} courseId ID of the course.
* @param {Number} courseId ID of the course.
* @param {Number} limitFrom Position of the first participant to get.
* @param {Number} limitNumber Number of participants to get.
* @param {String} [siteId] Site Id. If not defined, use current site.
Expand Down
Loading