Merge pull request #2667 from dpalou/MOBILE-3565
MOBILE-3565 course: Change course type in prefetch functionsmain
commit
2b450d7d33
|
@ -18,7 +18,7 @@ import { CoreFilterHelper } from '@features/filter/services/filter-helper';
|
|||
import { CoreApp } from '@services/app';
|
||||
import { CoreFilepool } from '@services/filepool';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreCourse, CoreCourseWSModule } from '../services/course';
|
||||
import { CoreCourse, CoreCourseAnyModuleData } from '../services/course';
|
||||
import { CoreCourseModulePrefetchHandlerBase } from './module-prefetch-handler';
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ export class CoreCourseActivityPrefetchHandlerBase extends CoreCourseModulePrefe
|
|||
* @param dirPath Path of the directory where to store all the content files.
|
||||
* @return Promise resolved when all content is downloaded.
|
||||
*/
|
||||
download(module: CoreCourseWSModule, courseId: number, dirPath?: string): Promise<void> {
|
||||
download(module: CoreCourseAnyModuleData, courseId: number, dirPath?: string): Promise<void> {
|
||||
// Same implementation for download and prefetch.
|
||||
return this.prefetch(module, courseId, false, dirPath);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ export class CoreCourseActivityPrefetchHandlerBase extends CoreCourseModulePrefe
|
|||
* @return Promise resolved when done.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async prefetch(module: CoreCourseWSModule, courseId?: number, single?: boolean, dirPath?: string): Promise<void> {
|
||||
async prefetch(module: CoreCourseAnyModuleData, courseId?: number, single?: boolean, dirPath?: string): Promise<void> {
|
||||
// To be overridden. It should call prefetchPackage
|
||||
return;
|
||||
}
|
||||
|
@ -77,8 +77,8 @@ export class CoreCourseActivityPrefetchHandlerBase extends CoreCourseModulePrefe
|
|||
* @return Promise resolved when the module has been downloaded. Data returned is not reliable.
|
||||
*/
|
||||
async prefetchPackage(
|
||||
module: CoreCourseWSModule,
|
||||
courseId: number,
|
||||
module: CoreCourseAnyModuleData,
|
||||
courseId: number | undefined,
|
||||
downloadFunction: () => Promise<string>,
|
||||
siteId?: string,
|
||||
): Promise<void> {
|
||||
|
@ -99,9 +99,18 @@ export class CoreCourseActivityPrefetchHandlerBase extends CoreCourseModulePrefe
|
|||
return this.addOngoingDownload(module.id, prefetchPromise, siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change module status and call the prefetch function.
|
||||
*
|
||||
* @param module Module.
|
||||
* @param courseId Course ID the module belongs to.
|
||||
* @param downloadFn Function to perform the prefetch. Please check the documentation of prefetchFunction.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved when the module has been downloaded. Data returned is not reliable.
|
||||
*/
|
||||
protected async changeStatusAndPrefetch(
|
||||
module: CoreCourseWSModule,
|
||||
courseId: number,
|
||||
module: CoreCourseAnyModuleData,
|
||||
courseId: number | undefined,
|
||||
downloadFunction: () => Promise<string>,
|
||||
siteId?: string,
|
||||
): Promise<void> {
|
||||
|
|
|
@ -13,14 +13,14 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { CoreSyncBaseProvider } from '@classes/base-sync';
|
||||
import { CoreCourseWSModule } from '../services/course';
|
||||
import { CoreCourseAnyModuleData } from '../services/course';
|
||||
import { CoreCourseModulePrefetchDelegate } from '../services/module-prefetch-delegate';
|
||||
import { CoreCourseModulePrefetchHandlerBase } from './module-prefetch-handler';
|
||||
|
||||
/**
|
||||
* Base class to create activity sync providers. It provides some common functions.
|
||||
*/
|
||||
export class CoreCourseActivitySyncBaseProvider extends CoreSyncBaseProvider {
|
||||
export class CoreCourseActivitySyncBaseProvider<T> extends CoreSyncBaseProvider<T> {
|
||||
|
||||
/**
|
||||
* Conveniece function to prefetch data after an update.
|
||||
|
@ -33,7 +33,7 @@ export class CoreCourseActivitySyncBaseProvider extends CoreSyncBaseProvider {
|
|||
*/
|
||||
async prefetchAfterUpdate(
|
||||
prefetchHandler: CoreCourseModulePrefetchHandlerBase,
|
||||
module: CoreCourseWSModule,
|
||||
module: CoreCourseAnyModuleData,
|
||||
courseId: number,
|
||||
preventDownloadRegex?: RegExp,
|
||||
siteId?: string,
|
||||
|
|
|
@ -16,7 +16,7 @@ import { CoreFilepool } from '@services/filepool';
|
|||
import { CoreFileSizeSum, CorePluginFileDelegate } from '@services/plugin-file-delegate';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreWSExternalFile } from '@services/ws';
|
||||
import { CoreCourse, CoreCourseModuleContentFile, CoreCourseWSModule } from '../services/course';
|
||||
import { CoreCourse, CoreCourseAnyModuleData, CoreCourseModuleContentFile } from '../services/course';
|
||||
import { CoreCourseModulePrefetchHandler } from '../services/module-prefetch-delegate';
|
||||
|
||||
/**
|
||||
|
@ -93,7 +93,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @return Promise resolved when all content is downloaded.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async download(module: CoreCourseWSModule, courseId: number, dirPath?: string): Promise<void> {
|
||||
async download(module: CoreCourseAnyModuleData, courseId: number, dirPath?: string): Promise<void> {
|
||||
// To be overridden.
|
||||
return;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @param module The module object returned by WS.
|
||||
* @return List of files.
|
||||
*/
|
||||
getContentDownloadableFiles(module: CoreCourseWSModule): CoreCourseModuleContentFile[] {
|
||||
getContentDownloadableFiles(module: CoreCourseAnyModuleData): CoreCourseModuleContentFile[] {
|
||||
if (!module.contents?.length) {
|
||||
return [];
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @return Promise resolved with the size.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async getDownloadSize(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise<CoreFileSizeSum> {
|
||||
async getDownloadSize(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<CoreFileSizeSum> {
|
||||
try {
|
||||
const files = await this.getFiles(module, courseId);
|
||||
|
||||
|
@ -139,7 +139,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @return Size, or promise resolved with the size.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async getDownloadedSize(module: CoreCourseWSModule, courseId: number): Promise<number> {
|
||||
async getDownloadedSize(module: CoreCourseAnyModuleData, courseId: number): Promise<number> {
|
||||
const siteId = CoreSites.instance.getCurrentSiteId();
|
||||
|
||||
return CoreFilepool.instance.getFilesSizeByComponent(siteId, this.component, module.id);
|
||||
|
@ -154,7 +154,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @return Promise resolved with the list of files.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async getFiles(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise<CoreWSExternalFile[]> {
|
||||
async getFiles(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<CoreWSExternalFile[]> {
|
||||
// To be overridden.
|
||||
return [];
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @return Promise resolved with list of intro files.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async getIntroFiles(module: CoreCourseWSModule, courseId: number, ignoreCache?: boolean): Promise<CoreWSExternalFile[]> {
|
||||
async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number, ignoreCache?: boolean): Promise<CoreWSExternalFile[]> {
|
||||
return this.getIntroFilesFromInstance(module);
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @param instance The instance to get the intro files (book, assign, ...). If not defined, module will be used.
|
||||
* @return List of intro files.
|
||||
*/
|
||||
getIntroFilesFromInstance(module: CoreCourseWSModule, instance?: ModuleInstance): CoreWSExternalFile[] {
|
||||
getIntroFilesFromInstance(module: CoreCourseAnyModuleData, instance?: ModuleInstance): CoreWSExternalFile[] {
|
||||
if (instance) {
|
||||
if (typeof instance.introfiles != 'undefined') {
|
||||
return instance.introfiles;
|
||||
|
@ -188,7 +188,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
}
|
||||
}
|
||||
|
||||
if (module.description) {
|
||||
if ('description' in module && module.description) {
|
||||
return CoreFilepool.instance.extractDownloadableFilesFromHtmlAsFakeFileObjects(module.description);
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @return Promise resolved when invalidated.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
invalidateModule(module: CoreCourseWSModule, courseId: number): Promise<void> {
|
||||
invalidateModule(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
|
||||
return CoreCourse.instance.invalidateModule(module.id);
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @return Whether the module can be downloaded. The promise should never be rejected.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async isDownloadable(module: CoreCourseWSModule, courseId: number): Promise<boolean> {
|
||||
async isDownloadable(module: CoreCourseAnyModuleData, courseId: number): Promise<boolean> {
|
||||
// By default, mark all instances as downloadable.
|
||||
return true;
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @return Promise resolved when loaded.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async loadContents(module: CoreCourseWSModule, courseId: number, ignoreCache?: boolean): Promise<void> {
|
||||
async loadContents(module: CoreCourseAnyModuleData, courseId: number, ignoreCache?: boolean): Promise<void> {
|
||||
// To be overridden.
|
||||
return;
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @return Promise resolved when done.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async prefetch(module: CoreCourseWSModule, courseId?: number, single?: boolean, dirPath?: string): Promise<void> {
|
||||
async prefetch(module: CoreCourseAnyModuleData, courseId?: number, single?: boolean, dirPath?: string): Promise<void> {
|
||||
// To be overridden.
|
||||
return;
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePref
|
|||
* @return Promise resolved when done.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
removeFiles(module: CoreCourseWSModule, courseId: number): Promise<void> {
|
||||
removeFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
|
||||
return CoreFilepool.instance.removeFilesByComponent(CoreSites.instance.getCurrentSiteId(), this.component, module.id);
|
||||
}
|
||||
|
||||
|
|
|
@ -851,7 +851,7 @@ export class CoreCourseProvider {
|
|||
* @return Promise resolved when loaded.
|
||||
*/
|
||||
async loadModuleContents(
|
||||
module: CoreCourseWSModule,
|
||||
module: CoreCourseAnyModuleData,
|
||||
courseId?: number,
|
||||
sectionId?: number,
|
||||
preferCache?: boolean,
|
||||
|
@ -1199,6 +1199,8 @@ export class CoreCourseProvider {
|
|||
|
||||
}
|
||||
|
||||
export class CoreCourse extends makeSingleton(CoreCourseProvider) {}
|
||||
|
||||
/**
|
||||
* Common options used by modules when calling a WS through CoreSite.
|
||||
*/
|
||||
|
@ -1522,4 +1524,9 @@ type CoreCompletionUpdateActivityCompletionStatusManuallyWSParams = {
|
|||
completed: boolean; // Activity completed or not.
|
||||
};
|
||||
|
||||
export class CoreCourse extends makeSingleton(CoreCourseProvider) {}
|
||||
/**
|
||||
* Any of the possible module WS data.
|
||||
*/
|
||||
export type CoreCourseAnyModuleData = CoreCourseWSModule | CoreCourseModuleBasicInfo & {
|
||||
contents?: CoreCourseModuleContentFile[]; // Calculated in the app in loadModuleContents.
|
||||
};
|
||||
|
|
|
@ -304,6 +304,19 @@ export class CoreCourseLogHelperProvider {
|
|||
return this.syncLogs(unique, siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync the offline saved activity logs.
|
||||
*
|
||||
* @param component Component name.
|
||||
* @param componentId Component ID.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved when done.
|
||||
* @deprecated since 3.9.5. Please use syncActivity instead.
|
||||
*/
|
||||
syncIfNeeded(component: string, componentId: number, siteId?: string): Promise<void> {
|
||||
return this.syncActivity(component, componentId, siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync the offline saved activity logs.
|
||||
*
|
||||
|
|
|
@ -22,7 +22,7 @@ import { CoreFilepool, CoreFilepoolComponentFileEventData } from '@services/file
|
|||
import { CoreSites } from '@services/sites';
|
||||
import { CoreTimeUtils } from '@services/utils/time';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreCourse, CoreCourseModuleContentFile, CoreCourseWSModule } from './course';
|
||||
import { CoreCourse, CoreCourseAnyModuleData, CoreCourseModuleContentFile, CoreCourseWSModule } from './course';
|
||||
import { CoreCache } from '@classes/cache';
|
||||
import { CoreSiteWSPreSets } from '@classes/site';
|
||||
import { CoreConstants } from '@/core/constants';
|
||||
|
@ -92,7 +92,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Promise resolved with boolean: whether the module can use check updates WS.
|
||||
*/
|
||||
async canModuleUseCheckUpdates(module: CoreCourseWSModule, courseId: number): Promise<boolean> {
|
||||
async canModuleUseCheckUpdates(module: CoreCourseAnyModuleData, courseId: number): Promise<boolean> {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
|
||||
if (!handler) {
|
||||
|
@ -169,7 +169,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param canCheck True if updates can be checked using core_course_check_updates.
|
||||
* @return Module status.
|
||||
*/
|
||||
determineModuleStatus(module: CoreCourseWSModule, status: string, canCheck?: boolean): string {
|
||||
determineModuleStatus(module: CoreCourseAnyModuleData, status: string, canCheck?: boolean): string {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
const siteId = CoreSites.instance.getCurrentSiteId();
|
||||
|
||||
|
@ -202,7 +202,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param dirPath Path of the directory where to store all the content files.
|
||||
* @return Promise resolved when finished.
|
||||
*/
|
||||
async downloadModule(module: CoreCourseWSModule, courseId: number, dirPath?: string): Promise<void> {
|
||||
async downloadModule(module: CoreCourseAnyModuleData, courseId: number, dirPath?: string): Promise<void> {
|
||||
// Check if the module has a prefetch handler.
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
|
||||
|
@ -389,7 +389,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param single True if we're downloading a single module, false if we're downloading a whole section.
|
||||
* @return Promise resolved with the size.
|
||||
*/
|
||||
async getModuleDownloadSize(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise<CoreFileSizeSum> {
|
||||
async getModuleDownloadSize(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<CoreFileSizeSum> {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
|
||||
if (!handler) {
|
||||
|
@ -427,7 +427,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Promise resolved with the size.
|
||||
*/
|
||||
async getModuleDownloadedSize(module: CoreCourseWSModule, courseId: number): Promise<number> {
|
||||
async getModuleDownloadedSize(module: CoreCourseAnyModuleData, courseId: number): Promise<number> {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
if (!handler) {
|
||||
return 0;
|
||||
|
@ -493,7 +493,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Promise resolved with the total size (0 if unknown)
|
||||
*/
|
||||
async getModuleStoredSize(module: CoreCourseWSModule, courseId: number): Promise<number> {
|
||||
async getModuleStoredSize(module: CoreCourseAnyModuleData, courseId: number): Promise<number> {
|
||||
let downloadedSize = await this.getModuleDownloadedSize(module, courseId);
|
||||
|
||||
if (isNaN(downloadedSize)) {
|
||||
|
@ -522,7 +522,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @return Promise resolved with the list of files.
|
||||
*/
|
||||
async getModuleFiles(
|
||||
module: CoreCourseWSModule,
|
||||
module: CoreCourseAnyModuleData,
|
||||
courseId: number,
|
||||
): Promise<(CoreWSExternalFile | CoreCourseModuleContentFile)[]> {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
|
@ -534,7 +534,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
// The handler defines a function to load contents, use it before returning module contents.
|
||||
await handler.loadContents(module, courseId);
|
||||
|
||||
return module.contents;
|
||||
return module.contents || [];
|
||||
} else {
|
||||
return module.contents || [];
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @return Promise resolved with the status.
|
||||
*/
|
||||
async getModuleStatus(
|
||||
module: CoreCourseWSModule,
|
||||
module: CoreCourseAnyModuleData,
|
||||
courseId: number,
|
||||
updates?: CourseUpdates | false,
|
||||
refresh?: boolean,
|
||||
|
@ -597,7 +597,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
*/
|
||||
protected async calculateModuleStatus(
|
||||
handler: CoreCourseModulePrefetchHandler,
|
||||
module: CoreCourseWSModule,
|
||||
module: CoreCourseAnyModuleData,
|
||||
courseId: number,
|
||||
updates?: CourseUpdates | false,
|
||||
sectionId?: number,
|
||||
|
@ -767,7 +767,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @return Promise resolved with the data.
|
||||
*/
|
||||
protected async getModuleStatusAndDownloadTime(
|
||||
module: CoreCourseWSModule,
|
||||
module: CoreCourseAnyModuleData,
|
||||
courseId: number,
|
||||
): Promise<{ status: string; downloadTime?: number }> {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
|
@ -813,7 +813,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @return Promise resolved with the updates.
|
||||
*/
|
||||
async getModuleUpdates(
|
||||
module: CoreCourseWSModule,
|
||||
module: CoreCourseAnyModuleData,
|
||||
courseId: number,
|
||||
ignoreCache?: boolean,
|
||||
siteId?: string,
|
||||
|
@ -878,7 +878,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param module The module to work on.
|
||||
* @return Prefetch handler.
|
||||
*/
|
||||
getPrefetchHandlerFor(module: CoreCourseWSModule): CoreCourseModulePrefetchHandler | undefined {
|
||||
getPrefetchHandlerFor(module: CoreCourseAnyModuleData): CoreCourseModulePrefetchHandler | undefined {
|
||||
return this.getHandler(module.modname, true);
|
||||
}
|
||||
|
||||
|
@ -930,7 +930,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
*
|
||||
* @param module Module to be invalidated.
|
||||
*/
|
||||
invalidateModuleStatusCache(module: CoreCourseWSModule): void {
|
||||
invalidateModuleStatusCache(module: CoreCourseAnyModuleData): void {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
if (handler) {
|
||||
this.statusCache.invalidate(CoreFilepool.instance.getPackageId(handler.component, module.id));
|
||||
|
@ -970,8 +970,8 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Promise resolved with true if downloadable, false otherwise.
|
||||
*/
|
||||
async isModuleDownloadable(module: CoreCourseWSModule, courseId: number): Promise<boolean> {
|
||||
if (module.uservisible === false) {
|
||||
async isModuleDownloadable(module: CoreCourseAnyModuleData, courseId: number): Promise<boolean> {
|
||||
if ('uservisible' in module && module.uservisible === false) {
|
||||
// Module isn't visible by the user, cannot be downloaded.
|
||||
return false;
|
||||
}
|
||||
|
@ -1011,7 +1011,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param updates Result of getCourseUpdates.
|
||||
* @return Promise resolved with boolean: whether the module has updates.
|
||||
*/
|
||||
async moduleHasUpdates(module: CoreCourseWSModule, courseId: number, updates: CourseUpdates): Promise<boolean> {
|
||||
async moduleHasUpdates(module: CoreCourseAnyModuleData, courseId: number, updates: CourseUpdates): Promise<boolean> {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
const moduleUpdates = updates[module.id];
|
||||
|
||||
|
@ -1044,7 +1044,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param single True if we're downloading a single module, false if we're downloading a whole section.
|
||||
* @return Promise resolved when finished.
|
||||
*/
|
||||
async prefetchModule(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise<void> {
|
||||
async prefetchModule(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<void> {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
if (!handler) {
|
||||
return;
|
||||
|
@ -1078,18 +1078,18 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Promise resolved when finished.
|
||||
*/
|
||||
async syncModule<T = unknown>(module: CoreCourseWSModule, courseId: number): Promise<T | undefined> {
|
||||
async syncModule<T = unknown>(module: CoreCourseAnyModuleData, courseId: number): Promise<T | undefined> {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
if (!handler?.sync) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await CoreUtils.instance.ignoreErrors(handler.sync<T>(module, courseId));
|
||||
const result = await CoreUtils.instance.ignoreErrors(handler.sync(module, courseId));
|
||||
|
||||
// Always invalidate status cache for this module. We cannot know if data was sent to server or not.
|
||||
this.invalidateModuleStatusCache(module);
|
||||
|
||||
return result;
|
||||
return <T> result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1181,7 +1181,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
async removeModuleFiles(module: CoreCourseWSModule, courseId: number): Promise<void> {
|
||||
async removeModuleFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
|
||||
const handler = this.getPrefetchHandlerFor(module);
|
||||
const siteId = CoreSites.instance.getCurrentSiteId();
|
||||
|
||||
|
@ -1393,7 +1393,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param single True if we're downloading a single module, false if we're downloading a whole section.
|
||||
* @return Promise resolved with the size.
|
||||
*/
|
||||
getDownloadSize(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise<CoreFileSizeSum>;
|
||||
getDownloadSize(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<CoreFileSizeSum>;
|
||||
|
||||
/**
|
||||
* Prefetch a module.
|
||||
|
@ -1404,7 +1404,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param dirPath Path of the directory where to store all the content files.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
prefetch(module: CoreCourseWSModule, courseId?: number, single?: boolean, dirPath?: string): Promise<void>;
|
||||
prefetch(module: CoreCourseAnyModuleData, courseId?: number, single?: boolean, dirPath?: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Download the module.
|
||||
|
@ -1414,7 +1414,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param dirPath Path of the directory where to store all the content files.
|
||||
* @return Promise resolved when all content is downloaded.
|
||||
*/
|
||||
download(module: CoreCourseWSModule, courseId: number, dirPath?: string): Promise<void>;
|
||||
download(module: CoreCourseAnyModuleData, courseId: number, dirPath?: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Invalidate the prefetched content.
|
||||
|
@ -1434,7 +1434,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Whether the module can use check_updates. The promise should never be rejected.
|
||||
*/
|
||||
canUseCheckUpdates?(module: CoreCourseWSModule, courseId: number): Promise<boolean>;
|
||||
canUseCheckUpdates?(module: CoreCourseAnyModuleData, courseId: number): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Return the status to show based on current status. E.g. a module might want to show outdated instead of downloaded.
|
||||
|
@ -1445,7 +1445,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param canCheck Whether the site allows checking for updates.
|
||||
* @return Status to display.
|
||||
*/
|
||||
determineStatus?(module: CoreCourseWSModule, status: string, canCheck: boolean): string;
|
||||
determineStatus?(module: CoreCourseAnyModuleData, status: string, canCheck: boolean): string;
|
||||
|
||||
/**
|
||||
* Get the downloaded size of a module. If not defined, we'll use getFiles to calculate it (it can be slow).
|
||||
|
@ -1454,7 +1454,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Size, or promise resolved with the size.
|
||||
*/
|
||||
getDownloadedSize?(module: CoreCourseWSModule, courseId: number): Promise<number>;
|
||||
getDownloadedSize?(module: CoreCourseAnyModuleData, courseId: number): Promise<number>;
|
||||
|
||||
/**
|
||||
* Get the list of files of the module. If not defined, we'll assume they are in module.contents.
|
||||
|
@ -1463,7 +1463,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return List of files, or promise resolved with the files.
|
||||
*/
|
||||
getFiles?(module: CoreCourseWSModule, courseId: number): Promise<(CoreWSExternalFile | CoreCourseModuleContentFile)[]>;
|
||||
getFiles?(module: CoreCourseAnyModuleData, courseId: number): Promise<(CoreWSExternalFile | CoreCourseModuleContentFile)[]>;
|
||||
|
||||
/**
|
||||
* Check if a certain module has updates based on the result of check updates.
|
||||
|
@ -1473,7 +1473,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param moduleUpdates List of updates for the module.
|
||||
* @return Whether the module has updates. The promise should never be rejected.
|
||||
*/
|
||||
hasUpdates?(module: CoreCourseWSModule, courseId: number, moduleUpdates: false | CheckUpdatesWSInstance): Promise<boolean>;
|
||||
hasUpdates?(module: CoreCourseAnyModuleData, courseId: number, moduleUpdates: false | CheckUpdatesWSInstance): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Invalidate WS calls needed to determine module status (usually, to check if module is downloadable).
|
||||
|
@ -1483,7 +1483,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Promise resolved when invalidated.
|
||||
*/
|
||||
invalidateModule?(module: CoreCourseWSModule, courseId: number): Promise<void>;
|
||||
invalidateModule?(module: CoreCourseAnyModuleData, courseId: number): Promise<void>;
|
||||
|
||||
/**
|
||||
* Check if a module can be downloaded. If the function is not defined, we assume that all modules are downloadable.
|
||||
|
@ -1492,7 +1492,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Whether the module can be downloaded. The promise should never be rejected.
|
||||
*/
|
||||
isDownloadable?(module: CoreCourseWSModule, courseId: number): Promise<boolean>;
|
||||
isDownloadable?(module: CoreCourseAnyModuleData, courseId: number): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Load module contents in module.contents if they aren't loaded already. This is meant for resources.
|
||||
|
@ -1501,7 +1501,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
loadContents?(module: CoreCourseWSModule, courseId: number): Promise<void>;
|
||||
loadContents?(module: CoreCourseAnyModuleData, courseId: number): Promise<void>;
|
||||
|
||||
/**
|
||||
* Remove module downloaded files. If not defined, we'll use getFiles to remove them (slow).
|
||||
|
@ -1510,7 +1510,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param courseId Course ID the module belongs to.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
removeFiles?(module: CoreCourseWSModule, courseId: number): Promise<void>;
|
||||
removeFiles?(module: CoreCourseAnyModuleData, courseId: number): Promise<void>;
|
||||
|
||||
/**
|
||||
* Sync a module.
|
||||
|
@ -1520,7 +1520,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
|
|||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
sync?<T = unknown>(module: CoreCourseWSModule, courseId: number, siteId?: string): Promise<T>;
|
||||
sync?(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise<unknown>;
|
||||
}
|
||||
|
||||
type ToCheckList = {
|
||||
|
|
|
@ -1726,7 +1726,7 @@ export class CoreDomUtilsProvider {
|
|||
* @param form Form element.
|
||||
* @param siteId The site affected. If not provided, no site affected.
|
||||
*/
|
||||
triggerFormCancelledEvent(formRef: ElementRef, siteId?: string): void {
|
||||
triggerFormCancelledEvent(formRef: ElementRef | HTMLFormElement | undefined, siteId?: string): void {
|
||||
if (!formRef) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue