commit
aaa98793aa
|
@ -51,7 +51,7 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv
|
||||||
courseId: number,
|
courseId: number,
|
||||||
regex?: RegExp,
|
regex?: RegExp,
|
||||||
siteId?: string,
|
siteId?: string,
|
||||||
): Promise<void> {
|
): Promise<boolean> {
|
||||||
regex = regex || /^.*files$|^timers/;
|
regex = regex || /^.*files$|^timers/;
|
||||||
|
|
||||||
return super.prefetchAfterUpdate(prefetchHandler, module, courseId, regex, siteId);
|
return super.prefetchAfterUpdate(prefetchHandler, module, courseId, regex, siteId);
|
||||||
|
|
|
@ -205,21 +205,23 @@ export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityCo
|
||||||
if (online && this.isPrefetched()) {
|
if (online && this.isPrefetched()) {
|
||||||
// The survey is downloaded, update the data.
|
// The survey is downloaded, update the data.
|
||||||
try {
|
try {
|
||||||
await AddonModSurveySync.prefetchAfterUpdate(
|
const prefetched = await AddonModSurveySync.prefetchAfterUpdate(
|
||||||
AddonModSurveyPrefetchHandler.instance,
|
AddonModSurveyPrefetchHandler.instance,
|
||||||
this.module,
|
this.module,
|
||||||
this.courseId,
|
this.courseId,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update the view.
|
// Update the view.
|
||||||
this.showLoadingAndFetch(false, false);
|
prefetched ?
|
||||||
|
this.showLoadingAndFetch(false, false) :
|
||||||
|
this.showLoadingAndRefresh(false);;
|
||||||
} catch {
|
} catch {
|
||||||
// Prefetch failed, refresh the data.
|
// Prefetch failed, refresh the data.
|
||||||
await this.showLoadingAndRefresh(false);
|
this.showLoadingAndRefresh(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Not downloaded, refresh the data.
|
// Not downloaded, refresh the data.
|
||||||
await this.showLoadingAndRefresh(false);
|
this.showLoadingAndRefresh(false);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_survey.cannotsubmitsurvey', true);
|
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_survey.cannotsubmitsurvey', true);
|
||||||
|
|
|
@ -31,7 +31,7 @@ export class CoreCourseActivitySyncBaseProvider<T = void> extends CoreSyncBasePr
|
||||||
* @param courseId Course ID.
|
* @param courseId Course ID.
|
||||||
* @param preventDownloadRegex If regex matches, don't download the data. Defaults to check files.
|
* @param preventDownloadRegex If regex matches, don't download the data. Defaults to check files.
|
||||||
* @param siteId Site ID. If not defined, current site.
|
* @param siteId Site ID. If not defined, current site.
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved with boolean: true if prefetched, false if no need to prefetch.
|
||||||
*/
|
*/
|
||||||
async prefetchAfterUpdate(
|
async prefetchAfterUpdate(
|
||||||
prefetchHandler: CoreCourseModulePrefetchHandlerBase,
|
prefetchHandler: CoreCourseModulePrefetchHandlerBase,
|
||||||
|
@ -39,12 +39,12 @@ export class CoreCourseActivitySyncBaseProvider<T = void> extends CoreSyncBasePr
|
||||||
courseId: number,
|
courseId: number,
|
||||||
preventDownloadRegex?: RegExp,
|
preventDownloadRegex?: RegExp,
|
||||||
siteId?: string,
|
siteId?: string,
|
||||||
): Promise<void> {
|
): Promise<boolean> {
|
||||||
// Get the module updates to check if the data was updated or not.
|
// Get the module updates to check if the data was updated or not.
|
||||||
const result = await CoreCourseModulePrefetchDelegate.getModuleUpdates(module, courseId, true, siteId);
|
const result = await CoreCourseModulePrefetchDelegate.getModuleUpdates(module, courseId, true, siteId);
|
||||||
|
|
||||||
if (!result?.updates.length) {
|
if (!result?.updates.length) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only prefetch if files haven't changed, to prevent downloading too much data automatically.
|
// Only prefetch if files haven't changed, to prevent downloading too much data automatically.
|
||||||
|
@ -52,8 +52,12 @@ export class CoreCourseActivitySyncBaseProvider<T = void> extends CoreSyncBasePr
|
||||||
const shouldDownload = !result.updates.find((entry) => entry.name.match(regex));
|
const shouldDownload = !result.updates.find((entry) => entry.name.match(regex));
|
||||||
|
|
||||||
if (shouldDownload) {
|
if (shouldDownload) {
|
||||||
return prefetchHandler.download(module, courseId);
|
await prefetchHandler.download(module, courseId);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -772,6 +772,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
||||||
return { status: CoreConstants.NOT_DOWNLOADABLE };
|
return { status: CoreConstants.NOT_DOWNLOADABLE };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// Get the stored data to get the status and downloadTime.
|
// Get the stored data to get the status and downloadTime.
|
||||||
const data = await CoreFilepool.getPackageData(siteId, handler.component, module.id);
|
const data = await CoreFilepool.getPackageData(siteId, handler.component, module.id);
|
||||||
|
|
||||||
|
@ -779,6 +780,9 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
||||||
status: data.status || CoreConstants.NOT_DOWNLOADED,
|
status: data.status || CoreConstants.NOT_DOWNLOADED,
|
||||||
downloadTime: data.downloadTime || 0,
|
downloadTime: data.downloadTime || 0,
|
||||||
};
|
};
|
||||||
|
} catch {
|
||||||
|
return { status: CoreConstants.NOT_DOWNLOADED };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue