Merge pull request #2025 from dpalou/MOBILE-3064
MOBILE-3064 course: Don't call check_updates after prefetchmain
commit
0139910fe2
|
@ -149,7 +149,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
|
|||
this.prefetchHandler.getDownloadSize(this.module, this.courseId, true).then((size) => {
|
||||
return this.courseHelper.prefetchModule(this.prefetchHandler, this.module, size, this.courseId, refresh);
|
||||
}).then(() => {
|
||||
this.courseHelper.calculateSectionStatus(this.section, this.courseId);
|
||||
this.courseHelper.calculateSectionStatus(this.section, this.courseId, false, false);
|
||||
}).catch((error) => {
|
||||
// Error, hide spinner.
|
||||
this.spinner = false;
|
||||
|
|
|
@ -442,15 +442,7 @@ export class CoreCourseSectionPage implements OnDestroy {
|
|||
*/
|
||||
prefetchCourse(): void {
|
||||
this.courseHelper.confirmAndPrefetchCourse(this.prefetchCourseData, this.course, this.sections,
|
||||
this.courseHandlers, this.courseMenuHandlers)
|
||||
.then(() => {
|
||||
if (this.downloadEnabled) {
|
||||
// Recalculate the status.
|
||||
this.courseHelper.calculateSectionsStatus(this.sections, this.course.id).catch(() => {
|
||||
// Ignore errors (shouldn't happen).
|
||||
});
|
||||
}
|
||||
}).catch((error) => {
|
||||
this.courseHandlers, this.courseMenuHandlers).catch((error) => {
|
||||
if (!this.isDestroyed) {
|
||||
this.domUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true);
|
||||
}
|
||||
|
|
|
@ -187,16 +187,19 @@ export class CoreCourseHelperProvider {
|
|||
* @param {any} section Section to calculate its status. It can't be "All sections".
|
||||
* @param {number} courseId Course ID the section belongs to.
|
||||
* @param {boolean} [refresh] True if it shouldn't use module status cache (slower).
|
||||
* @param {boolean} [checkUpdates=true] Whether to use the WS to check updates. Defaults to true.
|
||||
* @return {Promise<any>} Promise resolved when the status is calculated.
|
||||
*/
|
||||
calculateSectionStatus(section: any, courseId: number, refresh?: boolean): Promise<any> {
|
||||
calculateSectionStatus(section: any, courseId: number, refresh?: boolean, checkUpdates: boolean = true): Promise<any> {
|
||||
|
||||
if (section.id == CoreCourseProvider.ALL_SECTIONS_ID) {
|
||||
return Promise.reject(null);
|
||||
}
|
||||
|
||||
// Get the status of this section.
|
||||
return this.prefetchDelegate.getModulesStatus(section.modules, courseId, section.id, refresh, true).then((result) => {
|
||||
return this.prefetchDelegate.getModulesStatus(section.modules, courseId, section.id, refresh, true, checkUpdates)
|
||||
.then((result) => {
|
||||
|
||||
// Check if it's being downloaded.
|
||||
const downloadId = this.getSectionDownloadId(section);
|
||||
if (this.prefetchDelegate.isBeingDownloaded(downloadId)) {
|
||||
|
@ -228,9 +231,10 @@ export class CoreCourseHelperProvider {
|
|||
* @param {any[]} sections Sections to calculate their status.
|
||||
* @param {number} courseId Course ID the sections belong to.
|
||||
* @param {boolean} [refresh] True if it shouldn't use module status cache (slower).
|
||||
* @param {boolean} [checkUpdates=true] Whether to use the WS to check updates. Defaults to true.
|
||||
* @return {Promise<void>} Promise resolved when the states are calculated.
|
||||
*/
|
||||
calculateSectionsStatus(sections: any[], courseId: number, refresh?: boolean): Promise<void> {
|
||||
calculateSectionsStatus(sections: any[], courseId: number, refresh?: boolean, checkUpdates: boolean = true): Promise<void> {
|
||||
const promises = [];
|
||||
let allSectionsSection,
|
||||
allSectionsStatus;
|
||||
|
@ -242,7 +246,7 @@ export class CoreCourseHelperProvider {
|
|||
section.isCalculating = true;
|
||||
} else {
|
||||
section.isCalculating = true;
|
||||
promises.push(this.calculateSectionStatus(section, courseId, refresh).then((result) => {
|
||||
promises.push(this.calculateSectionStatus(section, courseId, refresh, checkUpdates).then((result) => {
|
||||
// Calculate "All sections" status.
|
||||
allSectionsStatus = this.filepoolProvider.determinePackagesStatus(allSectionsStatus, result.status);
|
||||
}).finally(() => {
|
||||
|
@ -1331,7 +1335,7 @@ export class CoreCourseHelperProvider {
|
|||
// Download only this section.
|
||||
return this.prefetchSingleSectionIfNeeded(section, courseId).finally(() => {
|
||||
// Calculate the status of the section that finished.
|
||||
return this.calculateSectionStatus(section, courseId);
|
||||
return this.calculateSectionStatus(section, courseId, false, false);
|
||||
});
|
||||
} else {
|
||||
// Download all the sections except "All sections".
|
||||
|
@ -1343,7 +1347,7 @@ export class CoreCourseHelperProvider {
|
|||
if (section.id != CoreCourseProvider.ALL_SECTIONS_ID) {
|
||||
promises.push(this.prefetchSingleSectionIfNeeded(section, courseId).finally(() => {
|
||||
// Calculate the status of the section that finished.
|
||||
return this.calculateSectionStatus(section, courseId).then((result) => {
|
||||
return this.calculateSectionStatus(section, courseId, false, false).then((result) => {
|
||||
// Calculate "All sections" status.
|
||||
allSectionsStatus = this.filepoolProvider.determinePackagesStatus(allSectionsStatus, result.status);
|
||||
});
|
||||
|
|
|
@ -795,6 +795,7 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
|
|||
* @param {number} [sectionId] ID of the section the modules belong to.
|
||||
* @param {boolean} [refresh] True if it should always check the DB (slower).
|
||||
* @param {boolean} [onlyToDisplay] True if the status will only be used to determine which button should be displayed.
|
||||
* @param {boolean} [checkUpdates=true] Whether to use the WS to check updates. Defaults to true.
|
||||
* @return {Promise<any>} Promise resolved with an object with the following properties:
|
||||
* - status (string) Status of the module.
|
||||
* - total (number) Number of modules.
|
||||
|
@ -803,12 +804,15 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
|
|||
* - CoreConstants.DOWNLOADING (any[]) Modules with state DOWNLOADING.
|
||||
* - CoreConstants.OUTDATED (any[]) Modules with state OUTDATED.
|
||||
*/
|
||||
getModulesStatus(modules: any[], courseId: number, sectionId?: number, refresh?: boolean, onlyToDisplay?: boolean): any {
|
||||
getModulesStatus(modules: any[], courseId: number, sectionId?: number, refresh?: boolean, onlyToDisplay?: boolean,
|
||||
checkUpdates: boolean = true): any {
|
||||
|
||||
const promises = [],
|
||||
result: any = {
|
||||
total: 0
|
||||
};
|
||||
let status = CoreConstants.NOT_DOWNLOADABLE;
|
||||
let status = CoreConstants.NOT_DOWNLOADABLE,
|
||||
promise;
|
||||
|
||||
// Init result.
|
||||
result[CoreConstants.NOT_DOWNLOADED] = [];
|
||||
|
@ -816,11 +820,17 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
|
|||
result[CoreConstants.DOWNLOADING] = [];
|
||||
result[CoreConstants.OUTDATED] = [];
|
||||
|
||||
// Check updates in course. Don't use getCourseUpdates because the list of modules might not be the whole course list.
|
||||
return this.getCourseUpdatesByCourseId(courseId).catch(() => {
|
||||
// Cannot get updates.
|
||||
return false;
|
||||
}).then((updates) => {
|
||||
if (checkUpdates) {
|
||||
// Check updates in course. Don't use getCourseUpdates because the list of modules might not be the whole course list.
|
||||
promise = this.getCourseUpdatesByCourseId(courseId).catch(() => {
|
||||
// Cannot get updates.
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
promise = Promise.resolve(false);
|
||||
}
|
||||
|
||||
return promise.then((updates) => {
|
||||
|
||||
modules.forEach((module) => {
|
||||
// Check if the module has a prefetch handler.
|
||||
|
|
Loading…
Reference in New Issue