From adf8a1f4816ec46aeb83f52f8c02db3b99e01662 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 20 Jan 2021 16:13:32 +0100 Subject: [PATCH] MOBILE-3659 course: Change naming of calculated types --- .../components/sitemainmenu/sitemainmenu.ts | 21 +++-- .../course/components/format/format.ts | 28 +++--- .../module-completion/module-completion.ts | 6 +- .../course/components/module/module.ts | 11 +-- .../section-selector/section-selector.ts | 6 +- .../unsupported-module/unsupported-module.ts | 4 +- .../components/singleactivity.ts | 6 +- .../handlers/singleactivity-format.ts | 6 +- .../weeks/services/handlers/weeks-format.ts | 5 +- .../course/pages/contents/contents.ts | 10 ++- src/core/features/course/pages/index/index.ts | 4 +- .../features/course/services/course-helper.ts | 68 +++++++------- src/core/features/course/services/course.ts | 40 ++++----- .../course/services/format-delegate.ts | 15 ++-- .../services/handlers/default-format.ts | 7 +- .../services/handlers/default-module.ts | 14 +-- .../course/services/module-delegate.ts | 15 ++-- .../services/module-prefetch-delegate.ts | 90 +++++++++---------- .../features/sitehome/pages/index/index.ts | 4 +- .../features/sitehome/services/sitehome.ts | 5 +- 20 files changed, 192 insertions(+), 173 deletions(-) diff --git a/src/addons/block/sitemainmenu/components/sitemainmenu/sitemainmenu.ts b/src/addons/block/sitemainmenu/components/sitemainmenu/sitemainmenu.ts index 2c82d7576..f572b5067 100644 --- a/src/addons/block/sitemainmenu/components/sitemainmenu/sitemainmenu.ts +++ b/src/addons/block/sitemainmenu/components/sitemainmenu/sitemainmenu.ts @@ -14,8 +14,8 @@ import { Component, OnInit, Input } from '@angular/core'; import { CoreSites } from '@services/sites'; -import { CoreCourse, CoreCourseSection } from '@features/course/services/course'; -import { CoreCourseHelper } from '@features/course/services/course-helper'; +import { CoreCourse } from '@features/course/services/course'; +import { CoreCourseHelper, CoreCourseSection } from '@features/course/services/course-helper'; import { CoreSiteHome, FrontPageItemNames } from '@features/sitehome/services/sitehome'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreBlockBaseComponent } from '@features/block/classes/base-block-component'; @@ -77,8 +77,8 @@ export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent impl protected async fetchContent(): Promise { const sections = await CoreCourse.instance.getSections(this.siteHomeId, false, true); - this.mainMenuBlock = sections.find((section) => section.section == 0); - if (!this.mainMenuBlock) { + const mainMenuBlock = sections.find((section) => section.section == 0); + if (!mainMenuBlock) { return; } @@ -91,10 +91,17 @@ export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent impl const items = config.frontpageloggedin.split(','); const hasNewsItem = items.find((item) => parseInt(item, 10) == FrontPageItemNames['NEWS_ITEMS']); - const hasContent = CoreCourseHelper.instance.sectionHasContent(this.mainMenuBlock); - CoreCourseHelper.instance.addHandlerDataForModules([this.mainMenuBlock], this.siteHomeId, undefined, undefined, true); + const result = await CoreCourseHelper.instance.addHandlerDataForModules( + [mainMenuBlock], + this.siteHomeId, + undefined, + undefined, + true, + ); - if (!hasNewsItem || !hasContent) { + this.mainMenuBlock = result.sections[0]; + + if (!hasNewsItem || !this.mainMenuBlock.hasContent) { return; } diff --git a/src/core/features/course/components/format/format.ts b/src/core/features/course/components/format/format.ts index 83f073d9c..59e5c6d85 100644 --- a/src/core/features/course/components/format/format.ts +++ b/src/core/features/course/components/format/format.ts @@ -33,11 +33,15 @@ import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-comp import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourse, - CoreCourseModuleCompletionData, - CoreCourseModuleData, CoreCourseProvider, } from '@features/course/services/course'; -import { CoreCourseHelper, CoreCourseSectionFormatted, CoreCourseSectionWithStatus } from '@features/course/services/course-helper'; +import { + CoreCourseHelper, + CoreCourseModule, + CoreCourseModuleCompletionData, + CoreCourseSection, + CoreCourseSectionWithStatus, +} from '@features/course/services/course-helper'; import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate'; import { CoreEventObserver, CoreEvents, CoreEventSectionStatusChangedData, CoreEventSelectCourseTabData } from '@singletons/events'; import { IonContent, IonRefresher } from '@ionic/angular'; @@ -91,9 +95,9 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { displaySectionSelector?: boolean; displayBlocks?: boolean; - selectedSection?: CoreCourseSectionFormatted; - previousSection?: CoreCourseSectionFormatted; - nextSection?: CoreCourseSectionFormatted; + selectedSection?: CoreCourseSection; + previousSection?: CoreCourseSection; + nextSection?: CoreCourseSection; allSectionsId: number = CoreCourseProvider.ALL_SECTIONS_ID; stealthModulesSectionId: number = CoreCourseProvider.STEALTH_MODULES_SECTION_ID; loaded = false; @@ -154,7 +158,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { return; } - let section: CoreCourseSectionFormatted | undefined; + let section: CoreCourseSection | undefined; if (typeof data.sectionId != 'undefined' && data.sectionId != null && this.sections) { section = this.sections.find((section) => section.id == data.sectionId); @@ -280,7 +284,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { * @param sections Sections to treat. * @return Promise resolved when done. */ - protected async treatSections(sections: CoreCourseSectionFormatted[]): Promise { + protected async treatSections(sections: CoreCourseSection[]): Promise { const hasAllSections = sections[0].id == CoreCourseProvider.ALL_SECTIONS_ID; this.hasSeveralSections = sections.length > 2 || (sections.length == 2 && !hasAllSections); @@ -362,7 +366,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { * * @param newSection The new selected section. */ - sectionChanged(newSection: CoreCourseSectionFormatted): void { + sectionChanged(newSection: CoreCourseSection): void { const previousValue = this.selectedSection; this.selectedSection = newSection; this.data.section = this.selectedSection; @@ -419,7 +423,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { * @param section2 Second section. * @return Whether they're equal. */ - compareSections(section1: CoreCourseSectionFormatted, section2: CoreCourseSectionFormatted): boolean { + compareSections(section1: CoreCourseSection, section2: CoreCourseSection): boolean { return section1 && section2 ? section1.id === section2.id : section1 === section2; } @@ -583,7 +587,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { * @param section The section to check. * @return Whether the section can be viewed. */ - canViewSection(section: CoreCourseSectionFormatted): boolean { + canViewSection(section: CoreCourseSection): boolean { return section.uservisible !== false && !section.hiddenbynumsections && section.id != CoreCourseProvider.STEALTH_MODULES_SECTION_ID; } @@ -601,7 +605,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { } // If the completion value is not used, the page won't be reloaded, so update the progress bar. - const completionModules = ( []) + const completionModules = ( []) .concat(...this.sections!.map((section) => section.modules)) .map((module) => module.completion && module.completion > 0 ? 1 : module.completion) .reduce((accumulator, currentValue) => (accumulator || 0) + (currentValue || 0)); diff --git a/src/core/features/course/components/module-completion/module-completion.ts b/src/core/features/course/components/module-completion/module-completion.ts index f3e97205b..8f195d0f0 100644 --- a/src/core/features/course/components/module-completion/module-completion.ts +++ b/src/core/features/course/components/module-completion/module-completion.ts @@ -18,7 +18,7 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreUser } from '@features/user/services/user'; import { CoreCourse, CoreCourseProvider } from '@features/course/services/course'; import { CoreFilterHelper } from '@features/filter/services/filter-helper'; -import { CoreCourseModuleCompletionDataFormatted } from '@features/course/services/course-helper'; +import { CoreCourseModuleCompletionData } from '@features/course/services/course-helper'; import { Translate } from '@singletons'; /** @@ -37,10 +37,10 @@ import { Translate } from '@singletons'; }) export class CoreCourseModuleCompletionComponent implements OnChanges { - @Input() completion?: CoreCourseModuleCompletionDataFormatted; // The completion status. + @Input() completion?: CoreCourseModuleCompletionData; // The completion status. @Input() moduleId?: number; // The name of the module this completion affects. @Input() moduleName?: string; // The name of the module this completion affects. - @Output() completionChanged = new EventEmitter(); // Notify when completion changes. + @Output() completionChanged = new EventEmitter(); // Notify when completion changes. completionImage?: string; completionDescription?: string; diff --git a/src/core/features/course/components/module/module.ts b/src/core/features/course/components/module/module.ts index 3f42a7930..d3450472b 100644 --- a/src/core/features/course/components/module/module.ts +++ b/src/core/features/course/components/module/module.ts @@ -19,10 +19,11 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreEventObserver, CoreEventPackageStatusChanged, CoreEvents } from '@singletons/events'; import { CoreCourseHelper, - CoreCourseModuleDataFormatted, - CoreCourseSectionFormatted, + CoreCourseModule, + CoreCourseModuleCompletionData, + CoreCourseSection, } from '@features/course/services/course-helper'; -import { CoreCourse, CoreCourseModuleCompletionData } from '@features/course/services/course'; +import { CoreCourse } from '@features/course/services/course'; import { CoreCourseModuleHandlerButton } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate, @@ -43,9 +44,9 @@ import { }) export class CoreCourseModuleComponent implements OnInit, OnDestroy { - @Input() module?: CoreCourseModuleDataFormatted; // The module to render. + @Input() module?: CoreCourseModule; // The module to render. @Input() courseId?: number; // The course the module belongs to. - @Input() section?: CoreCourseSectionFormatted; // The section the module belongs to. + @Input() section?: CoreCourseSection; // The section the module belongs to. // eslint-disable-next-line @angular-eslint/no-input-rename @Input('downloadEnabled') set enabled(value: boolean) { this.downloadEnabled = value; diff --git a/src/core/features/course/components/section-selector/section-selector.ts b/src/core/features/course/components/section-selector/section-selector.ts index 0edc88144..623d4473b 100644 --- a/src/core/features/course/components/section-selector/section-selector.ts +++ b/src/core/features/course/components/section-selector/section-selector.ts @@ -14,7 +14,7 @@ import { Component, Input, OnInit } from '@angular/core'; -import { CoreCourseSectionFormatted } from '@features/course/services/course-helper'; +import { CoreCourseSection } from '@features/course/services/course-helper'; import { CoreCourseProvider } from '@features/course/services/course'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreUtils } from '@services/utils/utils'; @@ -30,7 +30,7 @@ import { ModalController } from '@singletons'; export class CoreCourseSectionSelectorComponent implements OnInit { @Input() sections?: SectionWithProgress[]; - @Input() selected?: CoreCourseSectionFormatted; + @Input() selected?: CoreCourseSection; @Input() course?: CoreCourseAnyCourseData; stealthModulesSectionId = CoreCourseProvider.STEALTH_MODULES_SECTION_ID; @@ -93,6 +93,6 @@ export class CoreCourseSectionSelectorComponent implements OnInit { } -type SectionWithProgress = CoreCourseSectionFormatted & { +type SectionWithProgress = CoreCourseSection & { progress?: number; }; diff --git a/src/core/features/course/components/unsupported-module/unsupported-module.ts b/src/core/features/course/components/unsupported-module/unsupported-module.ts index 46f2136cb..b03e6709b 100644 --- a/src/core/features/course/components/unsupported-module/unsupported-module.ts +++ b/src/core/features/course/components/unsupported-module/unsupported-module.ts @@ -14,7 +14,7 @@ import { Component, Input, OnInit } from '@angular/core'; -import { CoreCourse, CoreCourseModuleData } from '@features/course/services/course'; +import { CoreCourse, CoreCourseWSModule } from '@features/course/services/course'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; /** @@ -27,7 +27,7 @@ import { CoreCourseModuleDelegate } from '@features/course/services/module-deleg export class CoreCourseUnsupportedModuleComponent implements OnInit { @Input() courseId?: number; // The course to module belongs to. - @Input() module?: CoreCourseModuleData; // The module to render. + @Input() module?: CoreCourseWSModule; // The module to render. isDisabledInSite?: boolean; isSupportedByTheApp?: boolean; diff --git a/src/core/features/course/format/singleactivity/components/singleactivity.ts b/src/core/features/course/format/singleactivity/components/singleactivity.ts index 379cff7ef..3cb1f4e42 100644 --- a/src/core/features/course/format/singleactivity/components/singleactivity.ts +++ b/src/core/features/course/format/singleactivity/components/singleactivity.ts @@ -18,8 +18,8 @@ import { CoreCourseModuleDelegate } from '@features/course/services/module-deleg import { CoreCourseUnsupportedModuleComponent } from '@features/course/components/unsupported-module/unsupported-module'; import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; -import { CoreCourseSection } from '@features/course/services/course'; import { IonRefresher } from '@ionic/angular'; +import { CoreCourseModuleCompletionData, CoreCourseSectionWithStatus } from '@features/course/services/course-helper'; /** * Component to display single activity format. It will determine the right component to use and instantiate it. @@ -33,12 +33,12 @@ import { IonRefresher } from '@ionic/angular'; export class CoreCourseFormatSingleActivityComponent implements OnChanges { @Input() course?: CoreCourseAnyCourseData; // The course to render. - @Input() sections?: CoreCourseSection[]; // List of course sections. + @Input() sections?: CoreCourseSectionWithStatus[]; // List of course sections. @Input() downloadEnabled?: boolean; // Whether the download of sections and modules is enabled. @Input() initialSectionId?: number; // The section to load first (by ID). @Input() initialSectionNumber?: number; // The section to load first (by number). @Input() moduleId?: number; // The module ID to scroll to. Must be inside the initial selected section. - @Output() completionChanged?: EventEmitter; // Will emit an event when any module completion changes. + @Output() completionChanged = new EventEmitter(); // Notify when any module completion changes. @ViewChild(CoreDynamicComponent) dynamicComponent?: CoreDynamicComponent; diff --git a/src/core/features/course/format/singleactivity/services/handlers/singleactivity-format.ts b/src/core/features/course/format/singleactivity/services/handlers/singleactivity-format.ts index 203d4910f..4cc6d6189 100644 --- a/src/core/features/course/format/singleactivity/services/handlers/singleactivity-format.ts +++ b/src/core/features/course/format/singleactivity/services/handlers/singleactivity-format.ts @@ -14,7 +14,7 @@ import { Injectable, Type } from '@angular/core'; -import { CoreCourseSection } from '@features/course/services/course'; +import { CoreCourseWSSection } from '@features/course/services/course'; import { CoreCourseFormatHandler } from '@features/course/services/format-delegate'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; @@ -69,7 +69,7 @@ export class CoreCourseFormatSingleActivityHandlerService implements CoreCourseF * @param sections List of sections. * @return Title. */ - getCourseTitle(course: CoreCourseAnyCourseData, sections?: CoreCourseSection[]): string { + getCourseTitle(course: CoreCourseAnyCourseData, sections?: CoreCourseWSSection[]): string { if (sections?.[0]?.modules?.[0]) { return sections[0].modules[0].name; } @@ -113,7 +113,7 @@ export class CoreCourseFormatSingleActivityHandlerService implements CoreCourseF * @param sections List of course sections. * @return Whether the refresher should be displayed. */ - displayRefresher(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): boolean { + displayRefresher(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): boolean { if (sections?.[0]?.modules?.[0]) { return CoreCourseModuleDelegate.instance.displayRefresherInSingleActivity(sections[0].modules[0].modname); } else { diff --git a/src/core/features/course/format/weeks/services/handlers/weeks-format.ts b/src/core/features/course/format/weeks/services/handlers/weeks-format.ts index e668a96d8..6f6b96752 100644 --- a/src/core/features/course/format/weeks/services/handlers/weeks-format.ts +++ b/src/core/features/course/format/weeks/services/handlers/weeks-format.ts @@ -18,8 +18,9 @@ import { CoreTimeUtils } from '@services/utils/time'; import { CoreCourseFormatHandler } from '@features/course/services/format-delegate'; import { makeSingleton } from '@singletons'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; -import { CoreCourseSection } from '@features/course/services/course'; +import { CoreCourseWSSection } from '@features/course/services/course'; import { CoreConstants } from '@/core/constants'; +import { CoreCourseSection } from '@features/course/services/course-helper'; /** * Handler to support weeks course format. @@ -77,7 +78,7 @@ export class CoreCourseFormatWeeksHandlerService implements CoreCourseFormatHand * @param startDate The course start date (in seconds). * @return An object with the start and end date of the section. */ - protected getSectionDates(section: CoreCourseSection, startDate: number): { start: number; end: number } { + protected getSectionDates(section: CoreCourseWSSection, startDate: number): { start: number; end: number } { // Hack alert. We add 2 hours to avoid possible DST problems. (e.g. we go into daylight savings and the date changes). startDate = startDate + 7200; diff --git a/src/core/features/course/pages/contents/contents.ts b/src/core/features/course/pages/contents/contents.ts index a6c632816..1c5d2f9dc 100644 --- a/src/core/features/course/pages/contents/contents.ts +++ b/src/core/features/course/pages/contents/contents.ts @@ -23,10 +23,14 @@ import { CoreCourses, CoreCourseAnyCourseData } from '@features/courses/services import { CoreCourse, CoreCourseCompletionActivityStatus, - CoreCourseModuleCompletionData, CoreCourseProvider, } from '@features/course/services/course'; -import { CoreCourseHelper, CoreCourseSectionFormatted, CorePrefetchStatusInfo } from '@features/course/services/course-helper'; +import { + CoreCourseHelper, + CoreCourseModuleCompletionData, + CoreCourseSection, + CorePrefetchStatusInfo, +} from '@features/course/services/course-helper'; import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { @@ -56,7 +60,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { @ViewChild(CoreCourseFormatComponent) formatComponent?: CoreCourseFormatComponent; course!: CoreCourseAnyCourseData; - sections?: CoreCourseSectionFormatted[]; + sections?: CoreCourseSection[]; sectionId?: number; sectionNumber?: number; courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = []; diff --git a/src/core/features/course/pages/index/index.ts b/src/core/features/course/pages/index/index.ts index b74859f77..8c2a4e525 100644 --- a/src/core/features/course/pages/index/index.ts +++ b/src/core/features/course/pages/index/index.ts @@ -20,7 +20,7 @@ import { CoreCourseFormatDelegate } from '../../services/format-delegate'; import { CoreCourseOptionsDelegate } from '../../services/course-options-delegate'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreEventObserver, CoreEvents, CoreEventSelectCourseTabData } from '@singletons/events'; -import { CoreCourse, CoreCourseModuleData } from '@features/course/services/course'; +import { CoreCourse, CoreCourseWSModule } from '@features/course/services/course'; import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreUtils } from '@services/utils/utils'; import { CoreTextUtils } from '@services/utils/text'; @@ -84,7 +84,7 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy { // Get params. this.course = this.route.snapshot.queryParams['course']; this.firstTabName = this.route.snapshot.queryParams['selectedTab']; - const module: CoreCourseModuleData | undefined = this.route.snapshot.queryParams['module']; + const module: CoreCourseWSModule | undefined = this.route.snapshot.queryParams['module']; const modParams: Params | undefined = this.route.snapshot.queryParams['modParams']; this.currentPagePath = CoreNavHelper.instance.getCurrentPage(); diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index fa67a14b3..59b891e57 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -20,11 +20,11 @@ import { CoreSites } from '@services/sites'; import { CoreCourse, CoreCourseCompletionActivityStatus, - CoreCourseModuleCompletionData, + CoreCourseModuleWSCompletionData, CoreCourseModuleContentFile, - CoreCourseModuleData, + CoreCourseWSModule, CoreCourseProvider, - CoreCourseSection, + CoreCourseWSSection, } from './course'; import { CoreConstants } from '@/core/constants'; import { CoreLogger } from '@singletons/logger'; @@ -158,14 +158,14 @@ export class CoreCourseHelperProvider { * @return Whether the sections have content. */ addHandlerDataForModules( - sections: CoreCourseSection[], + sections: CoreCourseWSSection[], courseId: number, completionStatus?: Record, courseName?: string, forCoursePage = false, - ): { hasContent: boolean; sections: CoreCourseSectionFormatted[] } { + ): { hasContent: boolean; sections: CoreCourseSection[] } { - const formattedSections: CoreCourseSectionFormatted[] = sections; + const formattedSections: CoreCourseSection[] = sections; let hasContent = false; formattedSections.forEach((section) => { @@ -229,7 +229,7 @@ export class CoreCourseHelperProvider { * @return Promise resolved when the status is calculated. */ async calculateSectionStatus( - section: CoreCourseSectionFormatted, + section: CoreCourseSection, courseId: number, refresh?: boolean, checkUpdates: boolean = true, @@ -285,7 +285,7 @@ export class CoreCourseHelperProvider { * @return Promise resolved when the states are calculated. */ async calculateSectionsStatus( - sections: CoreCourseSectionFormatted[], + sections: CoreCourseSection[], courseId: number, refresh?: boolean, checkUpdates: boolean = true, @@ -346,7 +346,7 @@ export class CoreCourseHelperProvider { async confirmAndPrefetchCourse( data: CorePrefetchStatusInfo, course: CoreCourseAnyCourseData, - sections?: CoreCourseSection[], + sections?: CoreCourseWSSection[], courseHandlers?: CoreCourseOptionsHandlerToDisplay[], menuHandlers?: CoreCourseOptionsMenuHandlerToDisplay[], ): Promise { @@ -410,7 +410,7 @@ export class CoreCourseHelperProvider { const promises = courses.map((course) => { const subPromises: Promise[] = []; - let sections: CoreCourseSection[]; + let sections: CoreCourseWSSection[]; let handlers: CoreCourseOptionsHandlerToDisplay[] = []; let menuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = []; let success = true; @@ -463,7 +463,7 @@ export class CoreCourseHelperProvider { * @param done Function to call when done. It will close the context menu. * @return Promise resolved when done. */ - async confirmAndRemoveFiles(module: CoreCourseModuleData, courseId: number, done?: () => void): Promise { + async confirmAndRemoveFiles(module: CoreCourseWSModule, courseId: number, done?: () => void): Promise { let modal: CoreIonLoadingElement | undefined; try { @@ -496,8 +496,8 @@ export class CoreCourseHelperProvider { */ async confirmDownloadSizeSection( courseId: number, - section?: CoreCourseSection, - sections?: CoreCourseSection[], + section?: CoreCourseWSSection, + sections?: CoreCourseWSSection[], alwaysConfirm?: boolean, ): Promise { let hasEmbeddedFiles = false; @@ -554,7 +554,7 @@ export class CoreCourseHelperProvider { */ async contextMenuPrefetch( instance: ComponentWithContextMenu, - module: CoreCourseModuleData, + module: CoreCourseWSModule, courseId: number, done?: () => void, ): Promise { @@ -585,7 +585,7 @@ export class CoreCourseHelperProvider { * * @return Created section. */ - createAllSectionsSection(): CoreCourseSectionFormatted { + createAllSectionsSection(): CoreCourseSection { return { id: CoreCourseProvider.ALL_SECTIONS_ID, name: Translate.instance.instant('core.course.allsections'), @@ -636,7 +636,7 @@ export class CoreCourseHelperProvider { * @return Resolved on success. */ async downloadModuleAndOpenFile( - module: CoreCourseModuleData, + module: CoreCourseWSModule, courseId: number, component?: string, componentId?: string | number, @@ -720,7 +720,7 @@ export class CoreCourseHelperProvider { protected async openModuleFileInBrowser( fileUrl: string, site: CoreSite, - module: CoreCourseModuleData, + module: CoreCourseWSModule, courseId: number, component?: string, componentId?: string | number, @@ -769,7 +769,7 @@ export class CoreCourseHelperProvider { * @return Promise resolved when done. */ async downloadModuleWithMainFileIfNeeded( - module: CoreCourseModuleData, + module: CoreCourseWSModule, courseId: number, component: string, componentId?: string | number, @@ -840,7 +840,7 @@ export class CoreCourseHelperProvider { * @return Promise resolved when done. */ protected async downloadModuleWithMainFile( - module: CoreCourseModuleData, + module: CoreCourseWSModule, courseId: number, fixedUrl: string, files: CoreCourseModuleContentFile[], @@ -904,7 +904,7 @@ export class CoreCourseHelperProvider { * @return Promise resolved when done. */ async downloadModule( - module: CoreCourseModuleData, + module: CoreCourseWSModule, courseId: number, component?: string, componentId?: string | number, @@ -942,7 +942,7 @@ export class CoreCourseHelperProvider { */ async fillContextMenu( instance: ComponentWithContextMenu, - module: CoreCourseModuleData, + module: CoreCourseWSModule, courseId: number, invalidateCache?: boolean, component?: string, @@ -1133,7 +1133,7 @@ export class CoreCourseHelperProvider { * @param siteId Site ID. If not defined, current site. * @return Promise resolved when done. */ - async loadOfflineCompletion(courseId: number, sections: CoreCourseSectionFormatted[], siteId?: string): Promise { + async loadOfflineCompletion(courseId: number, sections: CoreCourseSection[], siteId?: string): Promise { const offlineCompletions = await CoreCourseOffline.instance.getCourseManualCompletions(courseId, siteId); if (!offlineCompletions || !offlineCompletions.length) { @@ -1305,7 +1305,7 @@ export class CoreCourseHelperProvider { * @return Promise resolved with the info. */ async getModulePrefetchInfo( - module: CoreCourseModuleData, + module: CoreCourseWSModule, courseId: number, invalidateCache?: boolean, component?: string, @@ -1425,7 +1425,7 @@ export class CoreCourseHelperProvider { * @param modParams Params to pass to the module * @param True if module can be opened, false otherwise. */ - openModule(module: CoreCourseModuleDataFormatted, courseId: number, sectionId?: number, modParams?: Params): boolean { + openModule(module: CoreCourseModule, courseId: number, sectionId?: number, modParams?: Params): boolean { if (!module.handlerData) { module.handlerData = CoreCourseModuleDelegate.instance.getModuleDataFor( module.modname, @@ -1457,7 +1457,7 @@ export class CoreCourseHelperProvider { */ async prefetchCourse( course: CoreCourseAnyCourseData, - sections: CoreCourseSection[], + sections: CoreCourseWSSection[], courseHandlers: CoreCourseOptionsHandlerToDisplay[], courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[], siteId?: string, @@ -1540,7 +1540,7 @@ export class CoreCourseHelperProvider { */ async prefetchModule( handler: CoreCourseModulePrefetchHandler, - module: CoreCourseModuleData, + module: CoreCourseWSModule, size: CoreFileSizeSum, courseId: number, refresh?: boolean, @@ -1717,7 +1717,7 @@ export class CoreCourseHelperProvider { * @param section Section to check. * @return Whether the section has content. */ - sectionHasContent(section: CoreCourseSection): boolean { + sectionHasContent(section: CoreCourseWSSection): boolean { if (section.hiddenbynumsections) { return false; } @@ -1778,7 +1778,7 @@ export class CoreCourseHelperProvider { * @param courseId Course ID the module belongs to. * @return Promise resolved when done. */ - async removeModuleStoredData(module: CoreCourseModuleData, courseId: number): Promise { + async removeModuleStoredData(module: CoreCourseWSModule, courseId: number): Promise { const promises: Promise[] = []; promises.push(CoreCourseModulePrefetchDelegate.instance.removeModuleFiles(module, courseId)); @@ -1799,15 +1799,15 @@ export class CoreCourseHelper extends makeSingleton(CoreCourseHelperProvider) {} /** * Section with calculated data. */ -export type CoreCourseSectionFormatted = Omit & { +export type CoreCourseSection = Omit & { hasContent?: boolean; - modules: CoreCourseModuleDataFormatted[]; + modules: CoreCourseModule[]; }; /** * Section with data about prefetch. */ -export type CoreCourseSectionWithStatus = CoreCourseSectionFormatted & { +export type CoreCourseSectionWithStatus = CoreCourseSection & { downloadStatus?: string; // Section status. canCheckUpdates?: boolean; // Whether can check updates. isDownloading?: boolean; // Whether section is being downloaded. @@ -1819,16 +1819,16 @@ export type CoreCourseSectionWithStatus = CoreCourseSectionFormatted & { /** * Module with calculated data. */ -export type CoreCourseModuleDataFormatted = Omit & { +export type CoreCourseModule = Omit & { isStealth?: boolean; handlerData?: CoreCourseModuleHandlerData; - completiondata?: CoreCourseModuleCompletionDataFormatted; + completiondata?: CoreCourseModuleCompletionData; }; /** * Module completion with calculated data. */ -export type CoreCourseModuleCompletionDataFormatted = CoreCourseModuleCompletionData & { +export type CoreCourseModuleCompletionData = CoreCourseModuleWSCompletionData & { courseId?: number; courseName?: string; tracking?: number; diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 6aff7c7d7..0d8abe2eb 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -37,7 +37,7 @@ import { import { CoreDomUtils } from '@services/utils/dom'; import { CoreWSError } from '@classes/errors/wserror'; import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; -import { CoreCourseHelper, CoreCourseModuleCompletionDataFormatted } from './course-helper'; +import { CoreCourseHelper, CoreCourseModuleCompletionData } from './course-helper'; import { CoreCourseFormatDelegate } from './format-delegate'; const ROOT_CACHE_KEY = 'mmCourse:'; @@ -110,7 +110,7 @@ export class CoreCourseProvider { * @param courseId Course ID. * @param completion Completion status of the module. */ - checkModuleCompletion(courseId: number, completion: CoreCourseModuleCompletionDataFormatted): void { + checkModuleCompletion(courseId: number, completion: CoreCourseModuleCompletionData): void { if (completion && completion.tracking === 2 && completion.state === 0) { this.invalidateSections(courseId).finally(() => { CoreEvents.trigger(CoreEvents.COMPLETION_MODULE_VIEWED, { courseId: courseId }); @@ -345,7 +345,7 @@ export class CoreCourseProvider { ignoreCache: boolean = false, siteId?: string, modName?: string, - ): Promise { + ): Promise { siteId = siteId || CoreSites.instance.getCurrentSiteId(); // Helper function to do the WS request without processing the result. @@ -355,7 +355,7 @@ export class CoreCourseProvider { modName: string | undefined, includeStealth: boolean, preferCache: boolean, - ): Promise => { + ): Promise => { const params: CoreCourseGetContentsParams = { courseid: courseId!, options: [], @@ -393,7 +393,7 @@ export class CoreCourseProvider { } try { - const sections: CoreCourseSection[] = await site.read('core_course_get_contents', params, preSets); + const sections = await site.read('core_course_get_contents', params, preSets); return sections; } catch { @@ -418,7 +418,7 @@ export class CoreCourseProvider { courseId = module.course; } - let sections: CoreCourseSection[]; + let sections: CoreCourseWSSection[]; try { const site = await CoreSites.instance.getSite(siteId); // We have courseId, we can use core_course_get_contents for compatibility. @@ -439,7 +439,7 @@ export class CoreCourseProvider { sections = await this.getSections(courseId, false, false, preSets, siteId); } - let foundModule: CoreCourseModuleData | undefined; + let foundModule: CoreCourseWSModule | undefined; const foundSection = sections.some((section) => { if (sectionId != null && @@ -636,7 +636,7 @@ export class CoreCourseProvider { excludeModules?: boolean, excludeContents?: boolean, siteId?: string, - ): Promise { + ): Promise { if (sectionId < 0) { throw new CoreError('Invalid section ID'); @@ -670,7 +670,7 @@ export class CoreCourseProvider { preSets?: CoreSiteWSPreSets, siteId?: string, includeStealthModules: boolean = true, - ): Promise { + ): Promise { const site = await CoreSites.instance.getSite(siteId); preSets = preSets || {}; @@ -697,7 +697,7 @@ export class CoreCourseProvider { }); } - let sections: CoreCourseSection[]; + let sections: CoreCourseWSSection[]; try { sections = await site.read('core_course_get_contents', params, preSets); } catch { @@ -739,12 +739,12 @@ export class CoreCourseProvider { * @param sections Sections. * @return Modules. */ - getSectionsModules(sections: CoreCourseSection[]): CoreCourseModuleData[] { + getSectionsModules(sections: CoreCourseWSSection[]): CoreCourseWSModule[] { if (!sections || !sections.length) { return []; } - return sections.reduce((previous: CoreCourseModuleData[], section) => previous.concat(section.modules || []), []); + return sections.reduce((previous: CoreCourseWSModule[], section) => previous.concat(section.modules || []), []); } /** @@ -829,7 +829,7 @@ export class CoreCourseProvider { * @return Promise resolved when loaded. */ async loadModuleContents( - module: CoreCourseModuleData, + module: CoreCourseWSModule, courseId?: number, sectionId?: number, preferCache?: boolean, @@ -974,7 +974,7 @@ export class CoreCourseProvider { * @param module The module object. * @return Whether the module has a view page. */ - moduleHasView(module: CoreCourseModuleSummary | CoreCourseModuleData): boolean { + moduleHasView(module: CoreCourseModuleSummary | CoreCourseWSModule): boolean { return !!module.url; } @@ -1324,7 +1324,7 @@ export type CoreCourseGetContentsParams = { /** * Data returned by core_course_get_contents WS. */ -export type CoreCourseSection = { +export type CoreCourseWSSection = { id: number; // Section ID. name: string; // Section name. visible?: number; // Is the section visible. @@ -1334,7 +1334,7 @@ export type CoreCourseSection = { hiddenbynumsections?: number; // Whether is a section hidden in the course format. uservisible?: boolean; // Is the section visible for the user?. availabilityinfo?: string; // Availability information. - modules: CoreCourseModuleData[]; + modules: CoreCourseWSModule[]; }; /** @@ -1361,9 +1361,9 @@ export type CoreCourseGetCourseModuleWSResponse = { }; /** - * Course module type. + * Course module data returned by the WS. */ -export type CoreCourseModuleData = { +export type CoreCourseWSModule = { id: number; // Activity id. course?: number; // The course id. url?: string; // Activity url. @@ -1385,7 +1385,7 @@ export type CoreCourseModuleData = { customdata?: string; // Custom data (JSON encoded). noviewlink?: boolean; // Whether the module has no view page. completion?: number; // Type of completion tracking: 0 means none, 1 manual, 2 automatic. - completiondata?: CoreCourseModuleCompletionData; // Module completion data. + completiondata?: CoreCourseModuleWSCompletionData; // Module completion data. contents: CoreCourseModuleContentFile[]; contentsinfo?: { // Contents summary information. filescount: number; // Total number of files. @@ -1399,7 +1399,7 @@ export type CoreCourseModuleData = { /** * Module completion data. */ -export type CoreCourseModuleCompletionData = { +export type CoreCourseModuleWSCompletionData = { state: number; // Completion state value: 0 means incomplete, 1 complete, 2 complete pass, 3 complete fail. timecompleted: number; // Timestamp for completion status. overrideby: number; // The user id who has overriden the status. diff --git a/src/core/features/course/services/format-delegate.ts b/src/core/features/course/services/format-delegate.ts index be1e4cbdf..effa5d9a2 100644 --- a/src/core/features/course/services/format-delegate.ts +++ b/src/core/features/course/services/format-delegate.ts @@ -18,7 +18,8 @@ import { Params } from '@angular/router'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { makeSingleton } from '@singletons'; -import { CoreCourseSection } from './course'; +import { CoreCourseWSSection } from './course'; +import { CoreCourseSection } from './course-helper'; import { CoreCourseFormatDefaultHandler } from './handlers/default-format'; /** @@ -38,7 +39,7 @@ export interface CoreCourseFormatHandler extends CoreDelegateHandler { * @param sections List of sections. * @return Title. */ - getCourseTitle?(course: CoreCourseAnyCourseData, sections?: CoreCourseSection[]): string; + getCourseTitle?(course: CoreCourseAnyCourseData, sections?: CoreCourseWSSection[]): string; /** * Whether it allows seeing all sections at the same time. Defaults to true. @@ -80,7 +81,7 @@ export interface CoreCourseFormatHandler extends CoreDelegateHandler { * @param sections List of course sections. * @return Whether the refresher should be displayed. */ - displayRefresher?(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): boolean; + displayRefresher?(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): boolean; /** * Given a list of sections, get the "current" section that should be displayed first. Defaults to first section. @@ -158,7 +159,7 @@ export interface CoreCourseFormatHandler extends CoreDelegateHandler { * @param sections List of sections. * @return Promise resolved when the data is invalidated. */ - invalidateData?(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): Promise; + invalidateData?(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): Promise; /** * Whether the view should be refreshed when completion changes. If your course format doesn't display @@ -221,7 +222,7 @@ export class CoreCourseFormatDelegateService extends CoreDelegate(course.format || '', 'displayRefresher', [course, sections]); } @@ -284,7 +285,7 @@ export class CoreCourseFormatDelegateService extends CoreDelegate { + async invalidateData(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): Promise { await this.executeFunctionOnEnabled(course.format || '', 'invalidateData', [course, sections]); } diff --git a/src/core/features/course/services/handlers/default-format.ts b/src/core/features/course/services/handlers/default-format.ts index 194f584ae..bd1c287b8 100644 --- a/src/core/features/course/services/handlers/default-format.ts +++ b/src/core/features/course/services/handlers/default-format.ts @@ -18,7 +18,8 @@ import { Params } from '@angular/router'; import { CoreCourseAnyCourseData, CoreCourses } from '@features/courses/services/courses'; import { CoreNavHelper } from '@services/nav-helper'; import { CoreUtils } from '@services/utils/utils'; -import { CoreCourseSection } from '../course'; +import { CoreCourseWSSection } from '../course'; +import { CoreCourseSection } from '../course-helper'; import { CoreCourseFormatHandler } from '../format-delegate'; /** @@ -108,7 +109,7 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler { * @return Whether the refresher should be displayed. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - displayRefresher?(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): boolean { + displayRefresher?(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): boolean { return true; } @@ -157,7 +158,7 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler { * @return Promise resolved when the data is invalidated. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - async invalidateData(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): Promise { + async invalidateData(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): Promise { await CoreCourses.instance.invalidateCoursesByField('id', course.id); } diff --git a/src/core/features/course/services/handlers/default-module.ts b/src/core/features/course/services/handlers/default-module.ts index 10c272e9c..313ae3f70 100644 --- a/src/core/features/course/services/handlers/default-module.ts +++ b/src/core/features/course/services/handlers/default-module.ts @@ -17,8 +17,10 @@ import { NavigationOptions } from '@ionic/angular/providers/nav-controller'; import { CoreSites } from '@services/sites'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../module-delegate'; -import { CoreCourse, CoreCourseModuleBasicInfo, CoreCourseModuleData } from '../course'; +import { CoreCourse, CoreCourseModuleBasicInfo, CoreCourseWSModule } from '../course'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; +import { CoreCourseModule } from '../course-helper'; +import { CoreCourseUnsupportedModuleComponent } from '@features/course/components/unsupported-module/unsupported-module'; /** * Default handler used when the module doesn't have a specific implementation. @@ -47,7 +49,7 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler { * @return Data to render the module. */ getData( - module: CoreCourseModuleData | CoreCourseModuleBasicInfo, + module: CoreCourseWSModule | CoreCourseModuleBasicInfo, courseId: number, // eslint-disable-line @typescript-eslint/no-unused-vars sectionId?: number, // eslint-disable-line @typescript-eslint/no-unused-vars forCoursePage?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars @@ -58,7 +60,7 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler { title: module.name, class: 'core-course-default-handler core-course-module-' + module.modname + '-handler', // eslint-disable-next-line @typescript-eslint/no-unused-vars - action: (event: Event, module: CoreCourseModuleData, courseId: number, options?: NavigationOptions): void => { + action: (event: Event, module: CoreCourseModule, courseId: number, options?: NavigationOptions): void => { event.preventDefault(); event.stopPropagation(); @@ -92,10 +94,8 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler { * @return The component (or promise resolved with component) to use, undefined if not found. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - async getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseModuleData): Promise | undefined> { - // We can't inject CoreCourseUnsupportedModuleComponent here due to circular dependencies. - // Don't return anything, by default it will use CoreCourseUnsupportedModuleComponent. - return; + async getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseWSModule): Promise | undefined> { + return CoreCourseUnsupportedModuleComponent; } /** diff --git a/src/core/features/course/services/module-delegate.ts b/src/core/features/course/services/module-delegate.ts index 60b3e0e9c..0a333258b 100644 --- a/src/core/features/course/services/module-delegate.ts +++ b/src/core/features/course/services/module-delegate.ts @@ -21,10 +21,11 @@ import { CoreSite } from '@classes/site'; import { CoreCourseModuleDefaultHandler } from './handlers/default-module'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; -import { CoreCourse, CoreCourseModuleBasicInfo, CoreCourseModuleData } from './course'; +import { CoreCourse, CoreCourseModuleBasicInfo, CoreCourseWSModule } from './course'; import { CoreSites } from '@services/sites'; import { NavigationOptions } from '@ionic/angular/providers/nav-controller'; import { makeSingleton } from '@singletons'; +import { CoreCourseModule } from './course-helper'; /** * Interface that all course module handlers must implement. @@ -52,7 +53,7 @@ export interface CoreCourseModuleHandler extends CoreDelegateHandler { * @return Data to render the module. */ getData( - module: CoreCourseModuleData | CoreCourseModuleBasicInfo, + module: CoreCourseWSModule | CoreCourseModuleBasicInfo, courseId: number, sectionId?: number, forCoursePage?: boolean, @@ -67,7 +68,7 @@ export interface CoreCourseModuleHandler extends CoreDelegateHandler { * @param module The module object. * @return Promise resolved with component to use, undefined if not found. */ - getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseModuleData): Promise | undefined>; + getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseWSModule): Promise | undefined>; /** * Whether to display the course refresher in single activity course format. If it returns false, a refresher must be @@ -159,7 +160,7 @@ export interface CoreCourseModuleHandlerData { * @param options Options for the navigation. * @param params Params for the new page. */ - action?(event: Event, module: CoreCourseModuleData, courseId: number, options?: NavigationOptions, params?: Params): void; + action?(event: Event, module: CoreCourseModule, courseId: number, options?: NavigationOptions, params?: Params): void; /** * Updates the status of the module. @@ -229,7 +230,7 @@ export interface CoreCourseModuleHandlerButton { * @param module The module object. * @param courseId The course ID. */ - action(event: Event, module: CoreCourseModuleData, courseId: number): void; + action(event: Event, module: CoreCourseModule, courseId: number): void; } /** @@ -252,7 +253,7 @@ export class CoreCourseModuleDelegateService extends CoreDelegate | undefined> { + async getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseWSModule): Promise | undefined> { try { return await this.executeFunctionOnEnabled>(module.modname, 'getMainComponent', [course, module]); } catch (error) { @@ -272,7 +273,7 @@ export class CoreCourseModuleDelegateService extends CoreDelegate { + async canModuleUseCheckUpdates(module: CoreCourseWSModule, courseId: number): Promise { const handler = this.getPrefetchHandlerFor(module); if (!handler) { @@ -122,7 +122,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + protected async createToCheckList(modules: CoreCourseWSModule[], courseId: number): Promise { const result: ToCheckList = { toCheck: [], cannotUse: [], @@ -169,7 +169,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async downloadModule(module: CoreCourseWSModule, courseId: number, dirPath?: string): Promise { // Check if the module has a prefetch handler. const handler = this.getPrefetchHandlerFor(module); @@ -223,7 +223,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async getCourseUpdates(modules: CoreCourseWSModule[], courseId: number): Promise { if (!this.canCheckUpdates()) { throw new CoreError('Cannot check course updates.'); } @@ -259,7 +259,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { @@ -361,7 +361,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async getDownloadSize(modules: CoreCourseWSModule[], courseId: number): Promise { // Get the status of each module. const data = await this.getModulesStatus(modules, courseId); @@ -389,7 +389,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async getModuleDownloadSize(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise { const handler = this.getPrefetchHandlerFor(module); if (!handler) { @@ -427,7 +427,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async getModuleDownloadedSize(module: CoreCourseWSModule, courseId: number): Promise { const handler = this.getPrefetchHandlerFor(module); if (!handler) { return 0; @@ -493,7 +493,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async getModuleStoredSize(module: CoreCourseWSModule, courseId: number): Promise { let downloadedSize = await this.getModuleDownloadedSize(module, courseId); if (isNaN(downloadedSize)) { @@ -522,7 +522,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { const handler = this.getPrefetchHandlerFor(module); @@ -552,7 +552,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { const handler = this.getPrefetchHandlerFor(module); @@ -813,7 +813,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async invalidateModules(modules: CoreCourseWSModule[], courseId: number): Promise { const promises = modules.map(async (module) => { const handler = this.getPrefetchHandlerFor(module); @@ -930,7 +930,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async isModuleDownloadable(module: CoreCourseWSModule, courseId: number): Promise { if (module.uservisible === false) { // Module isn't visible by the user, cannot be downloaded. return false; @@ -1011,7 +1011,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async moduleHasUpdates(module: CoreCourseWSModule, courseId: number, updates: CourseUpdates): Promise { const handler = this.getPrefetchHandlerFor(module); const moduleUpdates = updates[module.id]; @@ -1044,7 +1044,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async prefetchModule(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise { const handler = this.getPrefetchHandlerFor(module); if (!handler) { return; @@ -1062,7 +1062,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + syncModules(modules: CoreCourseWSModule[], courseId: number): Promise { return Promise.all(modules.map(async (module) => { await this.syncModule(module, courseId); @@ -1078,7 +1078,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(module: CoreCourseModuleData, courseId: number): Promise { + async syncModule(module: CoreCourseWSModule, courseId: number): Promise { const handler = this.getPrefetchHandlerFor(module); if (!handler?.sync) { return; @@ -1104,7 +1104,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { @@ -1181,7 +1181,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + async removeModuleFiles(module: CoreCourseWSModule, courseId: number): Promise { 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: CoreCourseModuleData, courseId: number, single?: boolean): Promise; + getDownloadSize(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise; /** * 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: CoreCourseModuleData, courseId?: number, single?: boolean, dirPath?: string): Promise; + prefetch(module: CoreCourseWSModule, courseId?: number, single?: boolean, dirPath?: string): Promise; /** * 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: CoreCourseModuleData, courseId: number, dirPath?: string): Promise; + download(module: CoreCourseWSModule, courseId: number, dirPath?: string): Promise; /** * 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: CoreCourseModuleData, courseId: number): Promise; + canUseCheckUpdates?(module: CoreCourseWSModule, courseId: number): Promise; /** * 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: CoreCourseModuleData, status: string, canCheck: boolean): string; + determineStatus?(module: CoreCourseWSModule, 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: CoreCourseModuleData, courseId: number): Promise; + getDownloadedSize?(module: CoreCourseWSModule, courseId: number): Promise; /** * 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: CoreCourseModuleData, courseId: number): Promise<(CoreWSExternalFile | CoreCourseModuleContentFile)[]>; + getFiles?(module: CoreCourseWSModule, 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: CoreCourseModuleData, courseId: number, moduleUpdates: false | CheckUpdatesWSInstance): Promise; + hasUpdates?(module: CoreCourseWSModule, courseId: number, moduleUpdates: false | CheckUpdatesWSInstance): Promise; /** * 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: CoreCourseModuleData, courseId: number): Promise; + invalidateModule?(module: CoreCourseWSModule, courseId: number): Promise; /** * 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: CoreCourseModuleData, courseId: number): Promise; + isDownloadable?(module: CoreCourseWSModule, courseId: number): Promise; /** * 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: CoreCourseModuleData, courseId: number): Promise; + loadContents?(module: CoreCourseWSModule, courseId: number): Promise; /** * 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: CoreCourseModuleData, courseId: number): Promise; + removeFiles?(module: CoreCourseWSModule, courseId: number): Promise; /** * Sync a module. @@ -1520,12 +1520,12 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler { * @param siteId Site ID. If not defined, current site. * @return Promise resolved when done. */ - sync?(module: CoreCourseModuleData, courseId: number, siteId?: string): Promise; + sync?(module: CoreCourseWSModule, courseId: number, siteId?: string): Promise; } type ToCheckList = { toCheck: CheckUpdatesToCheckWSParam[]; - cannotUse: CoreCourseModuleData[]; + cannotUse: CoreCourseWSModule[]; }; /** @@ -1539,10 +1539,10 @@ type CourseUpdates = Record; export type CoreCourseModulesStatus = { total: number; // Number of modules. status: string; // Status of the list of modules. - [CoreConstants.NOT_DOWNLOADED]: CoreCourseModuleData[]; // Modules with state NOT_DOWNLOADED. - [CoreConstants.DOWNLOADED]: CoreCourseModuleData[]; // Modules with state DOWNLOADED. - [CoreConstants.DOWNLOADING]: CoreCourseModuleData[]; // Modules with state DOWNLOADING. - [CoreConstants.OUTDATED]: CoreCourseModuleData[]; // Modules with state OUTDATED. + [CoreConstants.NOT_DOWNLOADED]: CoreCourseWSModule[]; // Modules with state NOT_DOWNLOADED. + [CoreConstants.DOWNLOADED]: CoreCourseWSModule[]; // Modules with state DOWNLOADED. + [CoreConstants.DOWNLOADING]: CoreCourseWSModule[]; // Modules with state DOWNLOADING. + [CoreConstants.OUTDATED]: CoreCourseWSModule[]; // Modules with state OUTDATED. }; /** diff --git a/src/core/features/sitehome/pages/index/index.ts b/src/core/features/sitehome/pages/index/index.ts index 548f77d87..0f3a7b29d 100644 --- a/src/core/features/sitehome/pages/index/index.ts +++ b/src/core/features/sitehome/pages/index/index.ts @@ -17,7 +17,7 @@ import { ActivatedRoute } from '@angular/router'; import { IonRefresher, NavController } from '@ionic/angular'; import { CoreSite, CoreSiteConfig } from '@classes/site'; -import { CoreCourse, CoreCourseModuleBasicInfo, CoreCourseSection } from '@features/course/services/course'; +import { CoreCourse, CoreCourseModuleBasicInfo, CoreCourseWSSection } from '@features/course/services/course'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreSites } from '@services/sites'; import { CoreSiteHome } from '@features/sitehome/services/sitehome'; @@ -40,7 +40,7 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy { @ViewChild(CoreBlockCourseBlocksComponent) courseBlocksComponent?: CoreBlockCourseBlocksComponent; dataLoaded = false; - section?: CoreCourseSection & { + section?: CoreCourseWSSection & { hasContent?: boolean; }; diff --git a/src/core/features/sitehome/services/sitehome.ts b/src/core/features/sitehome/services/sitehome.ts index 668891af7..e6a852aae 100644 --- a/src/core/features/sitehome/services/sitehome.ts +++ b/src/core/features/sitehome/services/sitehome.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { CoreSites } from '@services/sites'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { makeSingleton } from '@singletons'; -import { CoreCourse, CoreCourseSection } from '../../course/services/course'; +import { CoreCourse } from '../../course/services/course'; import { CoreCourses } from '../../courses/services/courses'; import { AddonModForum, AddonModForumData } from '@/addons/mod/forum/services/forum'; @@ -90,8 +90,7 @@ export class CoreSiteHomeProvider { const preSets: CoreSiteWSPreSets = { emergencyCache: false }; try { - const sections: CoreCourseSection[] = - await CoreCourse.instance.getSections(siteHomeId, false, true, preSets, site.id); + const sections = await CoreCourse.instance.getSections(siteHomeId, false, true, preSets, site.id); if (!sections || !sections.length) { throw Error('No sections found');