MOBILE-3659 course: Change naming of calculated types

main
Dani Palou 2021-01-20 16:13:32 +01:00
parent 031f238117
commit adf8a1f481
20 changed files with 192 additions and 173 deletions

View File

@ -14,8 +14,8 @@
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, Input } from '@angular/core';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreCourse, CoreCourseSection } from '@features/course/services/course'; import { CoreCourse } from '@features/course/services/course';
import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseHelper, CoreCourseSection } from '@features/course/services/course-helper';
import { CoreSiteHome, FrontPageItemNames } from '@features/sitehome/services/sitehome'; import { CoreSiteHome, FrontPageItemNames } from '@features/sitehome/services/sitehome';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { CoreBlockBaseComponent } from '@features/block/classes/base-block-component'; import { CoreBlockBaseComponent } from '@features/block/classes/base-block-component';
@ -77,8 +77,8 @@ export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent impl
protected async fetchContent(): Promise<void> { protected async fetchContent(): Promise<void> {
const sections = await CoreCourse.instance.getSections(this.siteHomeId, false, true); const sections = await CoreCourse.instance.getSections(this.siteHomeId, false, true);
this.mainMenuBlock = sections.find((section) => section.section == 0); const mainMenuBlock = sections.find((section) => section.section == 0);
if (!this.mainMenuBlock) { if (!mainMenuBlock) {
return; return;
} }
@ -91,10 +91,17 @@ export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent impl
const items = config.frontpageloggedin.split(','); const items = config.frontpageloggedin.split(',');
const hasNewsItem = items.find((item) => parseInt(item, 10) == FrontPageItemNames['NEWS_ITEMS']); const hasNewsItem = items.find((item) => parseInt(item, 10) == FrontPageItemNames['NEWS_ITEMS']);
const hasContent = CoreCourseHelper.instance.sectionHasContent(this.mainMenuBlock); const result = await CoreCourseHelper.instance.addHandlerDataForModules(
CoreCourseHelper.instance.addHandlerDataForModules([this.mainMenuBlock], this.siteHomeId, undefined, undefined, true); [mainMenuBlock],
this.siteHomeId,
undefined,
undefined,
true,
);
if (!hasNewsItem || !hasContent) { this.mainMenuBlock = result.sections[0];
if (!hasNewsItem || !this.mainMenuBlock.hasContent) {
return; return;
} }

View File

@ -33,11 +33,15 @@ import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-comp
import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses';
import { import {
CoreCourse, CoreCourse,
CoreCourseModuleCompletionData,
CoreCourseModuleData,
CoreCourseProvider, CoreCourseProvider,
} from '@features/course/services/course'; } 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 { CoreCourseFormatDelegate } from '@features/course/services/format-delegate';
import { CoreEventObserver, CoreEvents, CoreEventSectionStatusChangedData, CoreEventSelectCourseTabData } from '@singletons/events'; import { CoreEventObserver, CoreEvents, CoreEventSectionStatusChangedData, CoreEventSelectCourseTabData } from '@singletons/events';
import { IonContent, IonRefresher } from '@ionic/angular'; import { IonContent, IonRefresher } from '@ionic/angular';
@ -91,9 +95,9 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
displaySectionSelector?: boolean; displaySectionSelector?: boolean;
displayBlocks?: boolean; displayBlocks?: boolean;
selectedSection?: CoreCourseSectionFormatted; selectedSection?: CoreCourseSection;
previousSection?: CoreCourseSectionFormatted; previousSection?: CoreCourseSection;
nextSection?: CoreCourseSectionFormatted; nextSection?: CoreCourseSection;
allSectionsId: number = CoreCourseProvider.ALL_SECTIONS_ID; allSectionsId: number = CoreCourseProvider.ALL_SECTIONS_ID;
stealthModulesSectionId: number = CoreCourseProvider.STEALTH_MODULES_SECTION_ID; stealthModulesSectionId: number = CoreCourseProvider.STEALTH_MODULES_SECTION_ID;
loaded = false; loaded = false;
@ -154,7 +158,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
return; return;
} }
let section: CoreCourseSectionFormatted | undefined; let section: CoreCourseSection | undefined;
if (typeof data.sectionId != 'undefined' && data.sectionId != null && this.sections) { if (typeof data.sectionId != 'undefined' && data.sectionId != null && this.sections) {
section = this.sections.find((section) => section.id == data.sectionId); 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. * @param sections Sections to treat.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async treatSections(sections: CoreCourseSectionFormatted[]): Promise<void> { protected async treatSections(sections: CoreCourseSection[]): Promise<void> {
const hasAllSections = sections[0].id == CoreCourseProvider.ALL_SECTIONS_ID; const hasAllSections = sections[0].id == CoreCourseProvider.ALL_SECTIONS_ID;
this.hasSeveralSections = sections.length > 2 || (sections.length == 2 && !hasAllSections); 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. * @param newSection The new selected section.
*/ */
sectionChanged(newSection: CoreCourseSectionFormatted): void { sectionChanged(newSection: CoreCourseSection): void {
const previousValue = this.selectedSection; const previousValue = this.selectedSection;
this.selectedSection = newSection; this.selectedSection = newSection;
this.data.section = this.selectedSection; this.data.section = this.selectedSection;
@ -419,7 +423,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
* @param section2 Second section. * @param section2 Second section.
* @return Whether they're equal. * @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; 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. * @param section The section to check.
* @return Whether the section can be viewed. * @return Whether the section can be viewed.
*/ */
canViewSection(section: CoreCourseSectionFormatted): boolean { canViewSection(section: CoreCourseSection): boolean {
return section.uservisible !== false && !section.hiddenbynumsections && return section.uservisible !== false && !section.hiddenbynumsections &&
section.id != CoreCourseProvider.STEALTH_MODULES_SECTION_ID; 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. // If the completion value is not used, the page won't be reloaded, so update the progress bar.
const completionModules = (<CoreCourseModuleData[]> []) const completionModules = (<CoreCourseModule[]> [])
.concat(...this.sections!.map((section) => section.modules)) .concat(...this.sections!.map((section) => section.modules))
.map((module) => module.completion && module.completion > 0 ? 1 : module.completion) .map((module) => module.completion && module.completion > 0 ? 1 : module.completion)
.reduce((accumulator, currentValue) => (accumulator || 0) + (currentValue || 0)); .reduce((accumulator, currentValue) => (accumulator || 0) + (currentValue || 0));

View File

@ -18,7 +18,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreCourse, CoreCourseProvider } from '@features/course/services/course'; import { CoreCourse, CoreCourseProvider } from '@features/course/services/course';
import { CoreFilterHelper } from '@features/filter/services/filter-helper'; 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'; import { Translate } from '@singletons';
/** /**
@ -37,10 +37,10 @@ import { Translate } from '@singletons';
}) })
export class CoreCourseModuleCompletionComponent implements OnChanges { 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() moduleId?: number; // The name of the module this completion affects.
@Input() moduleName?: string; // The name of the module this completion affects. @Input() moduleName?: string; // The name of the module this completion affects.
@Output() completionChanged = new EventEmitter<CoreCourseModuleCompletionDataFormatted>(); // Notify when completion changes. @Output() completionChanged = new EventEmitter<CoreCourseModuleCompletionData>(); // Notify when completion changes.
completionImage?: string; completionImage?: string;
completionDescription?: string; completionDescription?: string;

View File

@ -19,10 +19,11 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreEventObserver, CoreEventPackageStatusChanged, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEventPackageStatusChanged, CoreEvents } from '@singletons/events';
import { import {
CoreCourseHelper, CoreCourseHelper,
CoreCourseModuleDataFormatted, CoreCourseModule,
CoreCourseSectionFormatted, CoreCourseModuleCompletionData,
CoreCourseSection,
} from '@features/course/services/course-helper'; } 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 { CoreCourseModuleHandlerButton } from '@features/course/services/module-delegate';
import { import {
CoreCourseModulePrefetchDelegate, CoreCourseModulePrefetchDelegate,
@ -43,9 +44,9 @@ import {
}) })
export class CoreCourseModuleComponent implements OnInit, OnDestroy { 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() 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 // eslint-disable-next-line @angular-eslint/no-input-rename
@Input('downloadEnabled') set enabled(value: boolean) { @Input('downloadEnabled') set enabled(value: boolean) {
this.downloadEnabled = value; this.downloadEnabled = value;

View File

@ -14,7 +14,7 @@
import { Component, Input, OnInit } from '@angular/core'; 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 { CoreCourseProvider } from '@features/course/services/course';
import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -30,7 +30,7 @@ import { ModalController } from '@singletons';
export class CoreCourseSectionSelectorComponent implements OnInit { export class CoreCourseSectionSelectorComponent implements OnInit {
@Input() sections?: SectionWithProgress[]; @Input() sections?: SectionWithProgress[];
@Input() selected?: CoreCourseSectionFormatted; @Input() selected?: CoreCourseSection;
@Input() course?: CoreCourseAnyCourseData; @Input() course?: CoreCourseAnyCourseData;
stealthModulesSectionId = CoreCourseProvider.STEALTH_MODULES_SECTION_ID; stealthModulesSectionId = CoreCourseProvider.STEALTH_MODULES_SECTION_ID;
@ -93,6 +93,6 @@ export class CoreCourseSectionSelectorComponent implements OnInit {
} }
type SectionWithProgress = CoreCourseSectionFormatted & { type SectionWithProgress = CoreCourseSection & {
progress?: number; progress?: number;
}; };

View File

@ -14,7 +14,7 @@
import { Component, Input, OnInit } from '@angular/core'; 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'; 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 { export class CoreCourseUnsupportedModuleComponent implements OnInit {
@Input() courseId?: number; // The course to module belongs to. @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; isDisabledInSite?: boolean;
isSupportedByTheApp?: boolean; isSupportedByTheApp?: boolean;

View File

@ -18,8 +18,8 @@ import { CoreCourseModuleDelegate } from '@features/course/services/module-deleg
import { CoreCourseUnsupportedModuleComponent } from '@features/course/components/unsupported-module/unsupported-module'; import { CoreCourseUnsupportedModuleComponent } from '@features/course/components/unsupported-module/unsupported-module';
import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component'; import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component';
import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses';
import { CoreCourseSection } from '@features/course/services/course';
import { IonRefresher } from '@ionic/angular'; 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. * 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 { export class CoreCourseFormatSingleActivityComponent implements OnChanges {
@Input() course?: CoreCourseAnyCourseData; // The course to render. @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() downloadEnabled?: boolean; // Whether the download of sections and modules is enabled.
@Input() initialSectionId?: number; // The section to load first (by ID). @Input() initialSectionId?: number; // The section to load first (by ID).
@Input() initialSectionNumber?: number; // The section to load first (by number). @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. @Input() moduleId?: number; // The module ID to scroll to. Must be inside the initial selected section.
@Output() completionChanged?: EventEmitter<void>; // Will emit an event when any module completion changes. @Output() completionChanged = new EventEmitter<CoreCourseModuleCompletionData>(); // Notify when any module completion changes.
@ViewChild(CoreDynamicComponent) dynamicComponent?: CoreDynamicComponent; @ViewChild(CoreDynamicComponent) dynamicComponent?: CoreDynamicComponent;

View File

@ -14,7 +14,7 @@
import { Injectable, Type } from '@angular/core'; 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 { CoreCourseFormatHandler } from '@features/course/services/format-delegate';
import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate';
import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses';
@ -69,7 +69,7 @@ export class CoreCourseFormatSingleActivityHandlerService implements CoreCourseF
* @param sections List of sections. * @param sections List of sections.
* @return Title. * @return Title.
*/ */
getCourseTitle(course: CoreCourseAnyCourseData, sections?: CoreCourseSection[]): string { getCourseTitle(course: CoreCourseAnyCourseData, sections?: CoreCourseWSSection[]): string {
if (sections?.[0]?.modules?.[0]) { if (sections?.[0]?.modules?.[0]) {
return sections[0].modules[0].name; return sections[0].modules[0].name;
} }
@ -113,7 +113,7 @@ export class CoreCourseFormatSingleActivityHandlerService implements CoreCourseF
* @param sections List of course sections. * @param sections List of course sections.
* @return Whether the refresher should be displayed. * @return Whether the refresher should be displayed.
*/ */
displayRefresher(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): boolean { displayRefresher(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): boolean {
if (sections?.[0]?.modules?.[0]) { if (sections?.[0]?.modules?.[0]) {
return CoreCourseModuleDelegate.instance.displayRefresherInSingleActivity(sections[0].modules[0].modname); return CoreCourseModuleDelegate.instance.displayRefresherInSingleActivity(sections[0].modules[0].modname);
} else { } else {

View File

@ -18,8 +18,9 @@ import { CoreTimeUtils } from '@services/utils/time';
import { CoreCourseFormatHandler } from '@features/course/services/format-delegate'; import { CoreCourseFormatHandler } from '@features/course/services/format-delegate';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; 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 { CoreConstants } from '@/core/constants';
import { CoreCourseSection } from '@features/course/services/course-helper';
/** /**
* Handler to support weeks course format. * Handler to support weeks course format.
@ -77,7 +78,7 @@ export class CoreCourseFormatWeeksHandlerService implements CoreCourseFormatHand
* @param startDate The course start date (in seconds). * @param startDate The course start date (in seconds).
* @return An object with the start and end date of the section. * @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). // 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; startDate = startDate + 7200;

View File

@ -23,10 +23,14 @@ import { CoreCourses, CoreCourseAnyCourseData } from '@features/courses/services
import { import {
CoreCourse, CoreCourse,
CoreCourseCompletionActivityStatus, CoreCourseCompletionActivityStatus,
CoreCourseModuleCompletionData,
CoreCourseProvider, CoreCourseProvider,
} from '@features/course/services/course'; } 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 { CoreCourseFormatDelegate } from '@features/course/services/format-delegate';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { import {
@ -56,7 +60,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
@ViewChild(CoreCourseFormatComponent) formatComponent?: CoreCourseFormatComponent; @ViewChild(CoreCourseFormatComponent) formatComponent?: CoreCourseFormatComponent;
course!: CoreCourseAnyCourseData; course!: CoreCourseAnyCourseData;
sections?: CoreCourseSectionFormatted[]; sections?: CoreCourseSection[];
sectionId?: number; sectionId?: number;
sectionNumber?: number; sectionNumber?: number;
courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = []; courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = [];

View File

@ -20,7 +20,7 @@ import { CoreCourseFormatDelegate } from '../../services/format-delegate';
import { CoreCourseOptionsDelegate } from '../../services/course-options-delegate'; import { CoreCourseOptionsDelegate } from '../../services/course-options-delegate';
import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses';
import { CoreEventObserver, CoreEvents, CoreEventSelectCourseTabData } from '@singletons/events'; 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 { CoreCourseHelper } from '@features/course/services/course-helper';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -84,7 +84,7 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy {
// Get params. // Get params.
this.course = this.route.snapshot.queryParams['course']; this.course = this.route.snapshot.queryParams['course'];
this.firstTabName = this.route.snapshot.queryParams['selectedTab']; 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']; const modParams: Params | undefined = this.route.snapshot.queryParams['modParams'];
this.currentPagePath = CoreNavHelper.instance.getCurrentPage(); this.currentPagePath = CoreNavHelper.instance.getCurrentPage();

View File

@ -20,11 +20,11 @@ import { CoreSites } from '@services/sites';
import { import {
CoreCourse, CoreCourse,
CoreCourseCompletionActivityStatus, CoreCourseCompletionActivityStatus,
CoreCourseModuleCompletionData, CoreCourseModuleWSCompletionData,
CoreCourseModuleContentFile, CoreCourseModuleContentFile,
CoreCourseModuleData, CoreCourseWSModule,
CoreCourseProvider, CoreCourseProvider,
CoreCourseSection, CoreCourseWSSection,
} from './course'; } from './course';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
@ -158,14 +158,14 @@ export class CoreCourseHelperProvider {
* @return Whether the sections have content. * @return Whether the sections have content.
*/ */
addHandlerDataForModules( addHandlerDataForModules(
sections: CoreCourseSection[], sections: CoreCourseWSSection[],
courseId: number, courseId: number,
completionStatus?: Record<string, CoreCourseCompletionActivityStatus>, completionStatus?: Record<string, CoreCourseCompletionActivityStatus>,
courseName?: string, courseName?: string,
forCoursePage = false, forCoursePage = false,
): { hasContent: boolean; sections: CoreCourseSectionFormatted[] } { ): { hasContent: boolean; sections: CoreCourseSection[] } {
const formattedSections: CoreCourseSectionFormatted[] = sections; const formattedSections: CoreCourseSection[] = sections;
let hasContent = false; let hasContent = false;
formattedSections.forEach((section) => { formattedSections.forEach((section) => {
@ -229,7 +229,7 @@ export class CoreCourseHelperProvider {
* @return Promise resolved when the status is calculated. * @return Promise resolved when the status is calculated.
*/ */
async calculateSectionStatus( async calculateSectionStatus(
section: CoreCourseSectionFormatted, section: CoreCourseSection,
courseId: number, courseId: number,
refresh?: boolean, refresh?: boolean,
checkUpdates: boolean = true, checkUpdates: boolean = true,
@ -285,7 +285,7 @@ export class CoreCourseHelperProvider {
* @return Promise resolved when the states are calculated. * @return Promise resolved when the states are calculated.
*/ */
async calculateSectionsStatus( async calculateSectionsStatus(
sections: CoreCourseSectionFormatted[], sections: CoreCourseSection[],
courseId: number, courseId: number,
refresh?: boolean, refresh?: boolean,
checkUpdates: boolean = true, checkUpdates: boolean = true,
@ -346,7 +346,7 @@ export class CoreCourseHelperProvider {
async confirmAndPrefetchCourse( async confirmAndPrefetchCourse(
data: CorePrefetchStatusInfo, data: CorePrefetchStatusInfo,
course: CoreCourseAnyCourseData, course: CoreCourseAnyCourseData,
sections?: CoreCourseSection[], sections?: CoreCourseWSSection[],
courseHandlers?: CoreCourseOptionsHandlerToDisplay[], courseHandlers?: CoreCourseOptionsHandlerToDisplay[],
menuHandlers?: CoreCourseOptionsMenuHandlerToDisplay[], menuHandlers?: CoreCourseOptionsMenuHandlerToDisplay[],
): Promise<void> { ): Promise<void> {
@ -410,7 +410,7 @@ export class CoreCourseHelperProvider {
const promises = courses.map((course) => { const promises = courses.map((course) => {
const subPromises: Promise<void>[] = []; const subPromises: Promise<void>[] = [];
let sections: CoreCourseSection[]; let sections: CoreCourseWSSection[];
let handlers: CoreCourseOptionsHandlerToDisplay[] = []; let handlers: CoreCourseOptionsHandlerToDisplay[] = [];
let menuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = []; let menuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = [];
let success = true; let success = true;
@ -463,7 +463,7 @@ export class CoreCourseHelperProvider {
* @param done Function to call when done. It will close the context menu. * @param done Function to call when done. It will close the context menu.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
async confirmAndRemoveFiles(module: CoreCourseModuleData, courseId: number, done?: () => void): Promise<void> { async confirmAndRemoveFiles(module: CoreCourseWSModule, courseId: number, done?: () => void): Promise<void> {
let modal: CoreIonLoadingElement | undefined; let modal: CoreIonLoadingElement | undefined;
try { try {
@ -496,8 +496,8 @@ export class CoreCourseHelperProvider {
*/ */
async confirmDownloadSizeSection( async confirmDownloadSizeSection(
courseId: number, courseId: number,
section?: CoreCourseSection, section?: CoreCourseWSSection,
sections?: CoreCourseSection[], sections?: CoreCourseWSSection[],
alwaysConfirm?: boolean, alwaysConfirm?: boolean,
): Promise<void> { ): Promise<void> {
let hasEmbeddedFiles = false; let hasEmbeddedFiles = false;
@ -554,7 +554,7 @@ export class CoreCourseHelperProvider {
*/ */
async contextMenuPrefetch( async contextMenuPrefetch(
instance: ComponentWithContextMenu, instance: ComponentWithContextMenu,
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
done?: () => void, done?: () => void,
): Promise<void> { ): Promise<void> {
@ -585,7 +585,7 @@ export class CoreCourseHelperProvider {
* *
* @return Created section. * @return Created section.
*/ */
createAllSectionsSection(): CoreCourseSectionFormatted { createAllSectionsSection(): CoreCourseSection {
return { return {
id: CoreCourseProvider.ALL_SECTIONS_ID, id: CoreCourseProvider.ALL_SECTIONS_ID,
name: Translate.instance.instant('core.course.allsections'), name: Translate.instance.instant('core.course.allsections'),
@ -636,7 +636,7 @@ export class CoreCourseHelperProvider {
* @return Resolved on success. * @return Resolved on success.
*/ */
async downloadModuleAndOpenFile( async downloadModuleAndOpenFile(
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
@ -720,7 +720,7 @@ export class CoreCourseHelperProvider {
protected async openModuleFileInBrowser( protected async openModuleFileInBrowser(
fileUrl: string, fileUrl: string,
site: CoreSite, site: CoreSite,
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
@ -769,7 +769,7 @@ export class CoreCourseHelperProvider {
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
async downloadModuleWithMainFileIfNeeded( async downloadModuleWithMainFileIfNeeded(
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
component: string, component: string,
componentId?: string | number, componentId?: string | number,
@ -840,7 +840,7 @@ export class CoreCourseHelperProvider {
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async downloadModuleWithMainFile( protected async downloadModuleWithMainFile(
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
fixedUrl: string, fixedUrl: string,
files: CoreCourseModuleContentFile[], files: CoreCourseModuleContentFile[],
@ -904,7 +904,7 @@ export class CoreCourseHelperProvider {
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
async downloadModule( async downloadModule(
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
@ -942,7 +942,7 @@ export class CoreCourseHelperProvider {
*/ */
async fillContextMenu( async fillContextMenu(
instance: ComponentWithContextMenu, instance: ComponentWithContextMenu,
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
invalidateCache?: boolean, invalidateCache?: boolean,
component?: string, component?: string,
@ -1133,7 +1133,7 @@ export class CoreCourseHelperProvider {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
async loadOfflineCompletion(courseId: number, sections: CoreCourseSectionFormatted[], siteId?: string): Promise<void> { async loadOfflineCompletion(courseId: number, sections: CoreCourseSection[], siteId?: string): Promise<void> {
const offlineCompletions = await CoreCourseOffline.instance.getCourseManualCompletions(courseId, siteId); const offlineCompletions = await CoreCourseOffline.instance.getCourseManualCompletions(courseId, siteId);
if (!offlineCompletions || !offlineCompletions.length) { if (!offlineCompletions || !offlineCompletions.length) {
@ -1305,7 +1305,7 @@ export class CoreCourseHelperProvider {
* @return Promise resolved with the info. * @return Promise resolved with the info.
*/ */
async getModulePrefetchInfo( async getModulePrefetchInfo(
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
invalidateCache?: boolean, invalidateCache?: boolean,
component?: string, component?: string,
@ -1425,7 +1425,7 @@ export class CoreCourseHelperProvider {
* @param modParams Params to pass to the module * @param modParams Params to pass to the module
* @param True if module can be opened, false otherwise. * @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) { if (!module.handlerData) {
module.handlerData = CoreCourseModuleDelegate.instance.getModuleDataFor( module.handlerData = CoreCourseModuleDelegate.instance.getModuleDataFor(
module.modname, module.modname,
@ -1457,7 +1457,7 @@ export class CoreCourseHelperProvider {
*/ */
async prefetchCourse( async prefetchCourse(
course: CoreCourseAnyCourseData, course: CoreCourseAnyCourseData,
sections: CoreCourseSection[], sections: CoreCourseWSSection[],
courseHandlers: CoreCourseOptionsHandlerToDisplay[], courseHandlers: CoreCourseOptionsHandlerToDisplay[],
courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[], courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[],
siteId?: string, siteId?: string,
@ -1540,7 +1540,7 @@ export class CoreCourseHelperProvider {
*/ */
async prefetchModule( async prefetchModule(
handler: CoreCourseModulePrefetchHandler, handler: CoreCourseModulePrefetchHandler,
module: CoreCourseModuleData, module: CoreCourseWSModule,
size: CoreFileSizeSum, size: CoreFileSizeSum,
courseId: number, courseId: number,
refresh?: boolean, refresh?: boolean,
@ -1717,7 +1717,7 @@ export class CoreCourseHelperProvider {
* @param section Section to check. * @param section Section to check.
* @return Whether the section has content. * @return Whether the section has content.
*/ */
sectionHasContent(section: CoreCourseSection): boolean { sectionHasContent(section: CoreCourseWSSection): boolean {
if (section.hiddenbynumsections) { if (section.hiddenbynumsections) {
return false; return false;
} }
@ -1778,7 +1778,7 @@ export class CoreCourseHelperProvider {
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
async removeModuleStoredData(module: CoreCourseModuleData, courseId: number): Promise<void> { async removeModuleStoredData(module: CoreCourseWSModule, courseId: number): Promise<void> {
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
promises.push(CoreCourseModulePrefetchDelegate.instance.removeModuleFiles(module, courseId)); promises.push(CoreCourseModulePrefetchDelegate.instance.removeModuleFiles(module, courseId));
@ -1799,15 +1799,15 @@ export class CoreCourseHelper extends makeSingleton(CoreCourseHelperProvider) {}
/** /**
* Section with calculated data. * Section with calculated data.
*/ */
export type CoreCourseSectionFormatted = Omit<CoreCourseSection, 'modules'> & { export type CoreCourseSection = Omit<CoreCourseWSSection, 'modules'> & {
hasContent?: boolean; hasContent?: boolean;
modules: CoreCourseModuleDataFormatted[]; modules: CoreCourseModule[];
}; };
/** /**
* Section with data about prefetch. * Section with data about prefetch.
*/ */
export type CoreCourseSectionWithStatus = CoreCourseSectionFormatted & { export type CoreCourseSectionWithStatus = CoreCourseSection & {
downloadStatus?: string; // Section status. downloadStatus?: string; // Section status.
canCheckUpdates?: boolean; // Whether can check updates. canCheckUpdates?: boolean; // Whether can check updates.
isDownloading?: boolean; // Whether section is being downloaded. isDownloading?: boolean; // Whether section is being downloaded.
@ -1819,16 +1819,16 @@ export type CoreCourseSectionWithStatus = CoreCourseSectionFormatted & {
/** /**
* Module with calculated data. * Module with calculated data.
*/ */
export type CoreCourseModuleDataFormatted = Omit<CoreCourseModuleData, 'completiondata'> & { export type CoreCourseModule = Omit<CoreCourseWSModule, 'completiondata'> & {
isStealth?: boolean; isStealth?: boolean;
handlerData?: CoreCourseModuleHandlerData; handlerData?: CoreCourseModuleHandlerData;
completiondata?: CoreCourseModuleCompletionDataFormatted; completiondata?: CoreCourseModuleCompletionData;
}; };
/** /**
* Module completion with calculated data. * Module completion with calculated data.
*/ */
export type CoreCourseModuleCompletionDataFormatted = CoreCourseModuleCompletionData & { export type CoreCourseModuleCompletionData = CoreCourseModuleWSCompletionData & {
courseId?: number; courseId?: number;
courseName?: string; courseName?: string;
tracking?: number; tracking?: number;

View File

@ -37,7 +37,7 @@ import {
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreWSError } from '@classes/errors/wserror'; import { CoreWSError } from '@classes/errors/wserror';
import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications';
import { CoreCourseHelper, CoreCourseModuleCompletionDataFormatted } from './course-helper'; import { CoreCourseHelper, CoreCourseModuleCompletionData } from './course-helper';
import { CoreCourseFormatDelegate } from './format-delegate'; import { CoreCourseFormatDelegate } from './format-delegate';
const ROOT_CACHE_KEY = 'mmCourse:'; const ROOT_CACHE_KEY = 'mmCourse:';
@ -110,7 +110,7 @@ export class CoreCourseProvider {
* @param courseId Course ID. * @param courseId Course ID.
* @param completion Completion status of the module. * @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) { if (completion && completion.tracking === 2 && completion.state === 0) {
this.invalidateSections(courseId).finally(() => { this.invalidateSections(courseId).finally(() => {
CoreEvents.trigger(CoreEvents.COMPLETION_MODULE_VIEWED, { courseId: courseId }); CoreEvents.trigger(CoreEvents.COMPLETION_MODULE_VIEWED, { courseId: courseId });
@ -345,7 +345,7 @@ export class CoreCourseProvider {
ignoreCache: boolean = false, ignoreCache: boolean = false,
siteId?: string, siteId?: string,
modName?: string, modName?: string,
): Promise<CoreCourseModuleData> { ): Promise<CoreCourseWSModule> {
siteId = siteId || CoreSites.instance.getCurrentSiteId(); siteId = siteId || CoreSites.instance.getCurrentSiteId();
// Helper function to do the WS request without processing the result. // Helper function to do the WS request without processing the result.
@ -355,7 +355,7 @@ export class CoreCourseProvider {
modName: string | undefined, modName: string | undefined,
includeStealth: boolean, includeStealth: boolean,
preferCache: boolean, preferCache: boolean,
): Promise<CoreCourseSection[]> => { ): Promise<CoreCourseWSSection[]> => {
const params: CoreCourseGetContentsParams = { const params: CoreCourseGetContentsParams = {
courseid: courseId!, courseid: courseId!,
options: [], options: [],
@ -393,7 +393,7 @@ export class CoreCourseProvider {
} }
try { try {
const sections: CoreCourseSection[] = await site.read('core_course_get_contents', params, preSets); const sections = await site.read<CoreCourseWSSection[]>('core_course_get_contents', params, preSets);
return sections; return sections;
} catch { } catch {
@ -418,7 +418,7 @@ export class CoreCourseProvider {
courseId = module.course; courseId = module.course;
} }
let sections: CoreCourseSection[]; let sections: CoreCourseWSSection[];
try { try {
const site = await CoreSites.instance.getSite(siteId); const site = await CoreSites.instance.getSite(siteId);
// We have courseId, we can use core_course_get_contents for compatibility. // 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); sections = await this.getSections(courseId, false, false, preSets, siteId);
} }
let foundModule: CoreCourseModuleData | undefined; let foundModule: CoreCourseWSModule | undefined;
const foundSection = sections.some((section) => { const foundSection = sections.some((section) => {
if (sectionId != null && if (sectionId != null &&
@ -636,7 +636,7 @@ export class CoreCourseProvider {
excludeModules?: boolean, excludeModules?: boolean,
excludeContents?: boolean, excludeContents?: boolean,
siteId?: string, siteId?: string,
): Promise<CoreCourseSection> { ): Promise<CoreCourseWSSection> {
if (sectionId < 0) { if (sectionId < 0) {
throw new CoreError('Invalid section ID'); throw new CoreError('Invalid section ID');
@ -670,7 +670,7 @@ export class CoreCourseProvider {
preSets?: CoreSiteWSPreSets, preSets?: CoreSiteWSPreSets,
siteId?: string, siteId?: string,
includeStealthModules: boolean = true, includeStealthModules: boolean = true,
): Promise<CoreCourseSection[]> { ): Promise<CoreCourseWSSection[]> {
const site = await CoreSites.instance.getSite(siteId); const site = await CoreSites.instance.getSite(siteId);
preSets = preSets || {}; preSets = preSets || {};
@ -697,7 +697,7 @@ export class CoreCourseProvider {
}); });
} }
let sections: CoreCourseSection[]; let sections: CoreCourseWSSection[];
try { try {
sections = await site.read('core_course_get_contents', params, preSets); sections = await site.read('core_course_get_contents', params, preSets);
} catch { } catch {
@ -739,12 +739,12 @@ export class CoreCourseProvider {
* @param sections Sections. * @param sections Sections.
* @return Modules. * @return Modules.
*/ */
getSectionsModules(sections: CoreCourseSection[]): CoreCourseModuleData[] { getSectionsModules(sections: CoreCourseWSSection[]): CoreCourseWSModule[] {
if (!sections || !sections.length) { if (!sections || !sections.length) {
return []; 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. * @return Promise resolved when loaded.
*/ */
async loadModuleContents( async loadModuleContents(
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId?: number, courseId?: number,
sectionId?: number, sectionId?: number,
preferCache?: boolean, preferCache?: boolean,
@ -974,7 +974,7 @@ export class CoreCourseProvider {
* @param module The module object. * @param module The module object.
* @return Whether the module has a view page. * @return Whether the module has a view page.
*/ */
moduleHasView(module: CoreCourseModuleSummary | CoreCourseModuleData): boolean { moduleHasView(module: CoreCourseModuleSummary | CoreCourseWSModule): boolean {
return !!module.url; return !!module.url;
} }
@ -1324,7 +1324,7 @@ export type CoreCourseGetContentsParams = {
/** /**
* Data returned by core_course_get_contents WS. * Data returned by core_course_get_contents WS.
*/ */
export type CoreCourseSection = { export type CoreCourseWSSection = {
id: number; // Section ID. id: number; // Section ID.
name: string; // Section name. name: string; // Section name.
visible?: number; // Is the section visible. visible?: number; // Is the section visible.
@ -1334,7 +1334,7 @@ export type CoreCourseSection = {
hiddenbynumsections?: number; // Whether is a section hidden in the course format. hiddenbynumsections?: number; // Whether is a section hidden in the course format.
uservisible?: boolean; // Is the section visible for the user?. uservisible?: boolean; // Is the section visible for the user?.
availabilityinfo?: string; // Availability information. 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. id: number; // Activity id.
course?: number; // The course id. course?: number; // The course id.
url?: string; // Activity url. url?: string; // Activity url.
@ -1385,7 +1385,7 @@ export type CoreCourseModuleData = {
customdata?: string; // Custom data (JSON encoded). customdata?: string; // Custom data (JSON encoded).
noviewlink?: boolean; // Whether the module has no view page. noviewlink?: boolean; // Whether the module has no view page.
completion?: number; // Type of completion tracking: 0 means none, 1 manual, 2 automatic. 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[]; contents: CoreCourseModuleContentFile[];
contentsinfo?: { // Contents summary information. contentsinfo?: { // Contents summary information.
filescount: number; // Total number of files. filescount: number; // Total number of files.
@ -1399,7 +1399,7 @@ export type CoreCourseModuleData = {
/** /**
* Module completion data. * 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. state: number; // Completion state value: 0 means incomplete, 1 complete, 2 complete pass, 3 complete fail.
timecompleted: number; // Timestamp for completion status. timecompleted: number; // Timestamp for completion status.
overrideby: number; // The user id who has overriden the status. overrideby: number; // The user id who has overriden the status.

View File

@ -18,7 +18,8 @@ import { Params } from '@angular/router';
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreCourseSection } from './course'; import { CoreCourseWSSection } from './course';
import { CoreCourseSection } from './course-helper';
import { CoreCourseFormatDefaultHandler } from './handlers/default-format'; import { CoreCourseFormatDefaultHandler } from './handlers/default-format';
/** /**
@ -38,7 +39,7 @@ export interface CoreCourseFormatHandler extends CoreDelegateHandler {
* @param sections List of sections. * @param sections List of sections.
* @return Title. * @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. * 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. * @param sections List of course sections.
* @return Whether the refresher should be displayed. * @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. * 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. * @param sections List of sections.
* @return Promise resolved when the data is invalidated. * @return Promise resolved when the data is invalidated.
*/ */
invalidateData?(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): Promise<void>; invalidateData?(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): Promise<void>;
/** /**
* Whether the view should be refreshed when completion changes. If your course format doesn't display * 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<CoreCourseForm
* @param sections List of course sections. * @param sections List of course sections.
* @return Whether the refresher should be displayed. * @return Whether the refresher should be displayed.
*/ */
displayRefresher(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): boolean { displayRefresher(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): boolean {
return !!this.executeFunctionOnEnabled<boolean>(course.format || '', 'displayRefresher', [course, sections]); return !!this.executeFunctionOnEnabled<boolean>(course.format || '', 'displayRefresher', [course, sections]);
} }
@ -284,7 +285,7 @@ export class CoreCourseFormatDelegateService extends CoreDelegate<CoreCourseForm
* @param sections List of sections. * @param sections List of sections.
* @return Course title. * @return Course title.
*/ */
getCourseTitle(course: CoreCourseAnyCourseData, sections?: CoreCourseSection[]): string | undefined { getCourseTitle(course: CoreCourseAnyCourseData, sections?: CoreCourseWSSection[]): string | undefined {
return this.executeFunctionOnEnabled(course.format || '', 'getCourseTitle', [course, sections]); return this.executeFunctionOnEnabled(course.format || '', 'getCourseTitle', [course, sections]);
} }
@ -346,7 +347,7 @@ export class CoreCourseFormatDelegateService extends CoreDelegate<CoreCourseForm
* @param sections List of sections. * @param sections List of sections.
* @return Promise resolved when the data is invalidated. * @return Promise resolved when the data is invalidated.
*/ */
async invalidateData(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): Promise<void> { async invalidateData(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): Promise<void> {
await this.executeFunctionOnEnabled(course.format || '', 'invalidateData', [course, sections]); await this.executeFunctionOnEnabled(course.format || '', 'invalidateData', [course, sections]);
} }

View File

@ -18,7 +18,8 @@ import { Params } from '@angular/router';
import { CoreCourseAnyCourseData, CoreCourses } from '@features/courses/services/courses'; import { CoreCourseAnyCourseData, CoreCourses } from '@features/courses/services/courses';
import { CoreNavHelper } from '@services/nav-helper'; import { CoreNavHelper } from '@services/nav-helper';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreCourseSection } from '../course'; import { CoreCourseWSSection } from '../course';
import { CoreCourseSection } from '../course-helper';
import { CoreCourseFormatHandler } from '../format-delegate'; import { CoreCourseFormatHandler } from '../format-delegate';
/** /**
@ -108,7 +109,7 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler {
* @return Whether the refresher should be displayed. * @return Whether the refresher should be displayed.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
displayRefresher?(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): boolean { displayRefresher?(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): boolean {
return true; return true;
} }
@ -157,7 +158,7 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler {
* @return Promise resolved when the data is invalidated. * @return Promise resolved when the data is invalidated.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
async invalidateData(course: CoreCourseAnyCourseData, sections: CoreCourseSection[]): Promise<void> { async invalidateData(course: CoreCourseAnyCourseData, sections: CoreCourseWSSection[]): Promise<void> {
await CoreCourses.instance.invalidateCoursesByField('id', course.id); await CoreCourses.instance.invalidateCoursesByField('id', course.id);
} }

View File

@ -17,8 +17,10 @@ import { NavigationOptions } from '@ionic/angular/providers/nav-controller';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../module-delegate'; 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 { 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. * 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. * @return Data to render the module.
*/ */
getData( getData(
module: CoreCourseModuleData | CoreCourseModuleBasicInfo, module: CoreCourseWSModule | CoreCourseModuleBasicInfo,
courseId: number, // eslint-disable-line @typescript-eslint/no-unused-vars courseId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
sectionId?: 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 forCoursePage?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars
@ -58,7 +60,7 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler {
title: module.name, title: module.name,
class: 'core-course-default-handler core-course-module-' + module.modname + '-handler', class: 'core-course-default-handler core-course-module-' + module.modname + '-handler',
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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.preventDefault();
event.stopPropagation(); 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. * @return The component (or promise resolved with component) to use, undefined if not found.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
async getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseModuleData): Promise<Type<unknown> | undefined> { async getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseWSModule): Promise<Type<unknown> | undefined> {
// We can't inject CoreCourseUnsupportedModuleComponent here due to circular dependencies. return CoreCourseUnsupportedModuleComponent;
// Don't return anything, by default it will use CoreCourseUnsupportedModuleComponent.
return;
} }
/** /**

View File

@ -21,10 +21,11 @@ import { CoreSite } from '@classes/site';
import { CoreCourseModuleDefaultHandler } from './handlers/default-module'; import { CoreCourseModuleDefaultHandler } from './handlers/default-module';
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; 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 { CoreSites } from '@services/sites';
import { NavigationOptions } from '@ionic/angular/providers/nav-controller'; import { NavigationOptions } from '@ionic/angular/providers/nav-controller';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreCourseModule } from './course-helper';
/** /**
* Interface that all course module handlers must implement. * Interface that all course module handlers must implement.
@ -52,7 +53,7 @@ export interface CoreCourseModuleHandler extends CoreDelegateHandler {
* @return Data to render the module. * @return Data to render the module.
*/ */
getData( getData(
module: CoreCourseModuleData | CoreCourseModuleBasicInfo, module: CoreCourseWSModule | CoreCourseModuleBasicInfo,
courseId: number, courseId: number,
sectionId?: number, sectionId?: number,
forCoursePage?: boolean, forCoursePage?: boolean,
@ -67,7 +68,7 @@ export interface CoreCourseModuleHandler extends CoreDelegateHandler {
* @param module The module object. * @param module The module object.
* @return Promise resolved with component to use, undefined if not found. * @return Promise resolved with component to use, undefined if not found.
*/ */
getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseModuleData): Promise<Type<unknown> | undefined>; getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseWSModule): Promise<Type<unknown> | undefined>;
/** /**
* Whether to display the course refresher in single activity course format. If it returns false, a refresher must be * 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 options Options for the navigation.
* @param params Params for the new page. * @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. * Updates the status of the module.
@ -229,7 +230,7 @@ export interface CoreCourseModuleHandlerButton {
* @param module The module object. * @param module The module object.
* @param courseId The course ID. * @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<CoreCourseModu
* @param module The module object. * @param module The module object.
* @return Promise resolved with component to use, undefined if not found. * @return Promise resolved with component to use, undefined if not found.
*/ */
async getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseModuleData): Promise<Type<unknown> | undefined> { async getMainComponent(course: CoreCourseAnyCourseData, module: CoreCourseWSModule): Promise<Type<unknown> | undefined> {
try { try {
return await this.executeFunctionOnEnabled<Type<unknown>>(module.modname, 'getMainComponent', [course, module]); return await this.executeFunctionOnEnabled<Type<unknown>>(module.modname, 'getMainComponent', [course, module]);
} catch (error) { } catch (error) {
@ -272,7 +273,7 @@ export class CoreCourseModuleDelegateService extends CoreDelegate<CoreCourseModu
*/ */
getModuleDataFor( getModuleDataFor(
modname: string, modname: string,
module: CoreCourseModuleData | CoreCourseModuleBasicInfo, module: CoreCourseWSModule | CoreCourseModuleBasicInfo,
courseId: number, courseId: number,
sectionId?: number, sectionId?: number,
forCoursePage?: boolean, forCoursePage?: boolean,

View File

@ -22,7 +22,7 @@ import { CoreFilepool, CoreFilepoolComponentFileEventData } from '@services/file
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreCourse, CoreCourseModuleContentFile, CoreCourseModuleData } from './course'; import { CoreCourse, CoreCourseModuleContentFile, CoreCourseWSModule } from './course';
import { CoreCache } from '@classes/cache'; import { CoreCache } from '@classes/cache';
import { CoreSiteWSPreSets } from '@classes/site'; import { CoreSiteWSPreSets } from '@classes/site';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
@ -92,7 +92,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @return Promise resolved with boolean: whether the module can use check updates WS. * @return Promise resolved with boolean: whether the module can use check updates WS.
*/ */
async canModuleUseCheckUpdates(module: CoreCourseModuleData, courseId: number): Promise<boolean> { async canModuleUseCheckUpdates(module: CoreCourseWSModule, courseId: number): Promise<boolean> {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
if (!handler) { if (!handler) {
@ -122,7 +122,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID the modules belong to. * @param courseId Course ID the modules belong to.
* @return Promise resolved with the lists. * @return Promise resolved with the lists.
*/ */
protected async createToCheckList(modules: CoreCourseModuleData[], courseId: number): Promise<ToCheckList> { protected async createToCheckList(modules: CoreCourseWSModule[], courseId: number): Promise<ToCheckList> {
const result: ToCheckList = { const result: ToCheckList = {
toCheck: [], toCheck: [],
cannotUse: [], cannotUse: [],
@ -169,7 +169,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param canCheck True if updates can be checked using core_course_check_updates. * @param canCheck True if updates can be checked using core_course_check_updates.
* @return Module status. * @return Module status.
*/ */
determineModuleStatus(module: CoreCourseModuleData, status: string, canCheck?: boolean): string { determineModuleStatus(module: CoreCourseWSModule, status: string, canCheck?: boolean): string {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
const siteId = CoreSites.instance.getCurrentSiteId(); 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. * @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when finished. * @return Promise resolved when finished.
*/ */
async downloadModule(module: CoreCourseModuleData, courseId: number, dirPath?: string): Promise<void> { async downloadModule(module: CoreCourseWSModule, courseId: number, dirPath?: string): Promise<void> {
// Check if the module has a prefetch handler. // Check if the module has a prefetch handler.
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
@ -223,7 +223,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @return Promise resolved with the updates. If a module is set to false, it means updates cannot be * @return Promise resolved with the updates. If a module is set to false, it means updates cannot be
* checked for that module in the current site. * checked for that module in the current site.
*/ */
async getCourseUpdates(modules: CoreCourseModuleData[], courseId: number): Promise<CourseUpdates> { async getCourseUpdates(modules: CoreCourseWSModule[], courseId: number): Promise<CourseUpdates> {
if (!this.canCheckUpdates()) { if (!this.canCheckUpdates()) {
throw new CoreError('Cannot check course updates.'); throw new CoreError('Cannot check course updates.');
} }
@ -259,7 +259,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* checked for that module in the site. * checked for that module in the site.
*/ */
protected async fetchCourseUpdates( protected async fetchCourseUpdates(
modules: CoreCourseModuleData[], modules: CoreCourseWSModule[],
courseId: number, courseId: number,
siteId: string, siteId: string,
): Promise<CourseUpdates> { ): Promise<CourseUpdates> {
@ -361,7 +361,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID the modules belong to. * @param courseId Course ID the modules belong to.
* @return Promise resolved with the size. * @return Promise resolved with the size.
*/ */
async getDownloadSize(modules: CoreCourseModuleData[], courseId: number): Promise<CoreFileSizeSum> { async getDownloadSize(modules: CoreCourseWSModule[], courseId: number): Promise<CoreFileSizeSum> {
// Get the status of each module. // Get the status of each module.
const data = await this.getModulesStatus(modules, courseId); const data = await this.getModulesStatus(modules, courseId);
@ -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. * @param single True if we're downloading a single module, false if we're downloading a whole section.
* @return Promise resolved with the size. * @return Promise resolved with the size.
*/ */
async getModuleDownloadSize(module: CoreCourseModuleData, courseId: number, single?: boolean): Promise<CoreFileSizeSum> { async getModuleDownloadSize(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise<CoreFileSizeSum> {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
if (!handler) { if (!handler) {
@ -427,7 +427,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @return Promise resolved with the size. * @return Promise resolved with the size.
*/ */
async getModuleDownloadedSize(module: CoreCourseModuleData, courseId: number): Promise<number> { async getModuleDownloadedSize(module: CoreCourseWSModule, courseId: number): Promise<number> {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
if (!handler) { if (!handler) {
return 0; return 0;
@ -493,7 +493,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @return Promise resolved with the total size (0 if unknown) * @return Promise resolved with the total size (0 if unknown)
*/ */
async getModuleStoredSize(module: CoreCourseModuleData, courseId: number): Promise<number> { async getModuleStoredSize(module: CoreCourseWSModule, courseId: number): Promise<number> {
let downloadedSize = await this.getModuleDownloadedSize(module, courseId); let downloadedSize = await this.getModuleDownloadedSize(module, courseId);
if (isNaN(downloadedSize)) { if (isNaN(downloadedSize)) {
@ -522,7 +522,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @return Promise resolved with the list of files. * @return Promise resolved with the list of files.
*/ */
async getModuleFiles( async getModuleFiles(
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
): Promise<(CoreWSExternalFile | CoreCourseModuleContentFile)[]> { ): Promise<(CoreWSExternalFile | CoreCourseModuleContentFile)[]> {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
@ -552,7 +552,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @return Promise resolved with the status. * @return Promise resolved with the status.
*/ */
async getModuleStatus( async getModuleStatus(
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
updates?: CourseUpdates | false, updates?: CourseUpdates | false,
refresh?: boolean, refresh?: boolean,
@ -597,7 +597,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
*/ */
protected async calculateModuleStatus( protected async calculateModuleStatus(
handler: CoreCourseModulePrefetchHandler, handler: CoreCourseModulePrefetchHandler,
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
updates?: CourseUpdates | false, updates?: CourseUpdates | false,
sectionId?: number, sectionId?: number,
@ -696,7 +696,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @return Promise resolved with the data. * @return Promise resolved with the data.
*/ */
async getModulesStatus( async getModulesStatus(
modules: CoreCourseModuleData[], modules: CoreCourseWSModule[],
courseId: number, courseId: number,
sectionId?: number, sectionId?: number,
refresh?: boolean, refresh?: boolean,
@ -767,7 +767,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @return Promise resolved with the data. * @return Promise resolved with the data.
*/ */
protected async getModuleStatusAndDownloadTime( protected async getModuleStatusAndDownloadTime(
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
): Promise<{ status: string; downloadTime?: number }> { ): Promise<{ status: string; downloadTime?: number }> {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
@ -813,7 +813,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @return Promise resolved with the updates. * @return Promise resolved with the updates.
*/ */
async getModuleUpdates( async getModuleUpdates(
module: CoreCourseModuleData, module: CoreCourseWSModule,
courseId: number, courseId: number,
ignoreCache?: boolean, ignoreCache?: boolean,
siteId?: string, siteId?: string,
@ -878,7 +878,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param module The module to work on. * @param module The module to work on.
* @return Prefetch handler. * @return Prefetch handler.
*/ */
getPrefetchHandlerFor(module: CoreCourseModuleData): CoreCourseModulePrefetchHandler | undefined { getPrefetchHandlerFor(module: CoreCourseWSModule): CoreCourseModulePrefetchHandler | undefined {
return this.getHandler(module.modname, true); return this.getHandler(module.modname, true);
} }
@ -904,7 +904,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID. * @param courseId Course ID.
* @return Promise resolved when modules are invalidated. * @return Promise resolved when modules are invalidated.
*/ */
async invalidateModules(modules: CoreCourseModuleData[], courseId: number): Promise<void> { async invalidateModules(modules: CoreCourseWSModule[], courseId: number): Promise<void> {
const promises = modules.map(async (module) => { const promises = modules.map(async (module) => {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
@ -930,7 +930,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* *
* @param module Module to be invalidated. * @param module Module to be invalidated.
*/ */
invalidateModuleStatusCache(module: CoreCourseModuleData): void { invalidateModuleStatusCache(module: CoreCourseWSModule): void {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
if (handler) { if (handler) {
this.statusCache.invalidate(CoreFilepool.instance.getPackageId(handler.component, module.id)); this.statusCache.invalidate(CoreFilepool.instance.getPackageId(handler.component, module.id));
@ -970,7 +970,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @return Promise resolved with true if downloadable, false otherwise. * @return Promise resolved with true if downloadable, false otherwise.
*/ */
async isModuleDownloadable(module: CoreCourseModuleData, courseId: number): Promise<boolean> { async isModuleDownloadable(module: CoreCourseWSModule, courseId: number): Promise<boolean> {
if (module.uservisible === false) { if (module.uservisible === false) {
// Module isn't visible by the user, cannot be downloaded. // Module isn't visible by the user, cannot be downloaded.
return false; return false;
@ -1011,7 +1011,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param updates Result of getCourseUpdates. * @param updates Result of getCourseUpdates.
* @return Promise resolved with boolean: whether the module has updates. * @return Promise resolved with boolean: whether the module has updates.
*/ */
async moduleHasUpdates(module: CoreCourseModuleData, courseId: number, updates: CourseUpdates): Promise<boolean> { async moduleHasUpdates(module: CoreCourseWSModule, courseId: number, updates: CourseUpdates): Promise<boolean> {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
const moduleUpdates = updates[module.id]; 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. * @param single True if we're downloading a single module, false if we're downloading a whole section.
* @return Promise resolved when finished. * @return Promise resolved when finished.
*/ */
async prefetchModule(module: CoreCourseModuleData, courseId: number, single?: boolean): Promise<void> { async prefetchModule(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise<void> {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
if (!handler) { if (!handler) {
return; return;
@ -1062,7 +1062,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @return Promise resolved when finished. * @return Promise resolved when finished.
*/ */
syncModules(modules: CoreCourseModuleData[], courseId: number): Promise<unknown> { syncModules(modules: CoreCourseWSModule[], courseId: number): Promise<unknown> {
return Promise.all(modules.map(async (module) => { return Promise.all(modules.map(async (module) => {
await this.syncModule(module, courseId); await this.syncModule(module, courseId);
@ -1078,7 +1078,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @return Promise resolved when finished. * @return Promise resolved when finished.
*/ */
async syncModule<T = unknown>(module: CoreCourseModuleData, courseId: number): Promise<T | undefined> { async syncModule<T = unknown>(module: CoreCourseWSModule, courseId: number): Promise<T | undefined> {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
if (!handler?.sync) { if (!handler?.sync) {
return; return;
@ -1104,7 +1104,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
*/ */
async prefetchModules( async prefetchModules(
id: string, id: string,
modules: CoreCourseModuleData[], modules: CoreCourseWSModule[],
courseId: number, courseId: number,
onProgress?: CoreCourseModulesProgressFunction, onProgress?: CoreCourseModulesProgressFunction,
): Promise<void> { ): Promise<void> {
@ -1181,7 +1181,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
async removeModuleFiles(module: CoreCourseModuleData, courseId: number): Promise<void> { async removeModuleFiles(module: CoreCourseWSModule, courseId: number): Promise<void> {
const handler = this.getPrefetchHandlerFor(module); const handler = this.getPrefetchHandlerFor(module);
const siteId = CoreSites.instance.getCurrentSiteId(); 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. * @param single True if we're downloading a single module, false if we're downloading a whole section.
* @return Promise resolved with the size. * @return Promise resolved with the size.
*/ */
getDownloadSize(module: CoreCourseModuleData, courseId: number, single?: boolean): Promise<CoreFileSizeSum>; getDownloadSize(module: CoreCourseWSModule, courseId: number, single?: boolean): Promise<CoreFileSizeSum>;
/** /**
* Prefetch a module. * 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. * @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
prefetch(module: CoreCourseModuleData, courseId?: number, single?: boolean, dirPath?: string): Promise<void>; prefetch(module: CoreCourseWSModule, courseId?: number, single?: boolean, dirPath?: string): Promise<void>;
/** /**
* Download the module. * 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. * @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when all content is downloaded. * @return Promise resolved when all content is downloaded.
*/ */
download(module: CoreCourseModuleData, courseId: number, dirPath?: string): Promise<void>; download(module: CoreCourseWSModule, courseId: number, dirPath?: string): Promise<void>;
/** /**
* Invalidate the prefetched content. * Invalidate the prefetched content.
@ -1434,7 +1434,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @return Whether the module can use check_updates. The promise should never be rejected. * @return Whether the module can use check_updates. The promise should never be rejected.
*/ */
canUseCheckUpdates?(module: CoreCourseModuleData, courseId: number): Promise<boolean>; canUseCheckUpdates?(module: CoreCourseWSModule, 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. * 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. * @param canCheck Whether the site allows checking for updates.
* @return Status to display. * @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). * 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. * @param courseId Course ID the module belongs to.
* @return Size, or promise resolved with the size. * @return Size, or promise resolved with the size.
*/ */
getDownloadedSize?(module: CoreCourseModuleData, courseId: number): Promise<number>; getDownloadedSize?(module: CoreCourseWSModule, courseId: number): Promise<number>;
/** /**
* Get the list of files of the module. If not defined, we'll assume they are in module.contents. * 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. * @param courseId Course ID the module belongs to.
* @return List of files, or promise resolved with the files. * @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. * 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. * @param moduleUpdates List of updates for the module.
* @return Whether the module has updates. The promise should never be rejected. * @return Whether the module has updates. The promise should never be rejected.
*/ */
hasUpdates?(module: CoreCourseModuleData, courseId: number, moduleUpdates: false | CheckUpdatesWSInstance): Promise<boolean>; hasUpdates?(module: CoreCourseWSModule, courseId: number, moduleUpdates: false | CheckUpdatesWSInstance): Promise<boolean>;
/** /**
* Invalidate WS calls needed to determine module status (usually, to check if module is downloadable). * 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. * @param courseId Course ID the module belongs to.
* @return Promise resolved when invalidated. * @return Promise resolved when invalidated.
*/ */
invalidateModule?(module: CoreCourseModuleData, courseId: number): Promise<void>; invalidateModule?(module: CoreCourseWSModule, courseId: number): Promise<void>;
/** /**
* Check if a module can be downloaded. If the function is not defined, we assume that all modules are downloadable. * 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. * @param courseId Course ID the module belongs to.
* @return Whether the module can be downloaded. The promise should never be rejected. * @return Whether the module can be downloaded. The promise should never be rejected.
*/ */
isDownloadable?(module: CoreCourseModuleData, courseId: number): Promise<boolean>; isDownloadable?(module: CoreCourseWSModule, courseId: number): Promise<boolean>;
/** /**
* Load module contents in module.contents if they aren't loaded already. This is meant for resources. * 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. * @param courseId Course ID the module belongs to.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
loadContents?(module: CoreCourseModuleData, courseId: number): Promise<void>; loadContents?(module: CoreCourseWSModule, courseId: number): Promise<void>;
/** /**
* Remove module downloaded files. If not defined, we'll use getFiles to remove them (slow). * 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. * @param courseId Course ID the module belongs to.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
removeFiles?(module: CoreCourseModuleData, courseId: number): Promise<void>; removeFiles?(module: CoreCourseWSModule, courseId: number): Promise<void>;
/** /**
* Sync a module. * Sync a module.
@ -1520,12 +1520,12 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
sync?<T = unknown>(module: CoreCourseModuleData, courseId: number, siteId?: string): Promise<T>; sync?<T = unknown>(module: CoreCourseWSModule, courseId: number, siteId?: string): Promise<T>;
} }
type ToCheckList = { type ToCheckList = {
toCheck: CheckUpdatesToCheckWSParam[]; toCheck: CheckUpdatesToCheckWSParam[];
cannotUse: CoreCourseModuleData[]; cannotUse: CoreCourseWSModule[];
}; };
/** /**
@ -1539,10 +1539,10 @@ type CourseUpdates = Record<number, false | CheckUpdatesWSInstance>;
export type CoreCourseModulesStatus = { export type CoreCourseModulesStatus = {
total: number; // Number of modules. total: number; // Number of modules.
status: string; // Status of the list of modules. status: string; // Status of the list of modules.
[CoreConstants.NOT_DOWNLOADED]: CoreCourseModuleData[]; // Modules with state NOT_DOWNLOADED. [CoreConstants.NOT_DOWNLOADED]: CoreCourseWSModule[]; // Modules with state NOT_DOWNLOADED.
[CoreConstants.DOWNLOADED]: CoreCourseModuleData[]; // Modules with state DOWNLOADED. [CoreConstants.DOWNLOADED]: CoreCourseWSModule[]; // Modules with state DOWNLOADED.
[CoreConstants.DOWNLOADING]: CoreCourseModuleData[]; // Modules with state DOWNLOADING. [CoreConstants.DOWNLOADING]: CoreCourseWSModule[]; // Modules with state DOWNLOADING.
[CoreConstants.OUTDATED]: CoreCourseModuleData[]; // Modules with state OUTDATED. [CoreConstants.OUTDATED]: CoreCourseWSModule[]; // Modules with state OUTDATED.
}; };
/** /**

View File

@ -17,7 +17,7 @@ import { ActivatedRoute } from '@angular/router';
import { IonRefresher, NavController } from '@ionic/angular'; import { IonRefresher, NavController } from '@ionic/angular';
import { CoreSite, CoreSiteConfig } from '@classes/site'; 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 { CoreDomUtils } from '@services/utils/dom';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSiteHome } from '@features/sitehome/services/sitehome'; import { CoreSiteHome } from '@features/sitehome/services/sitehome';
@ -40,7 +40,7 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy {
@ViewChild(CoreBlockCourseBlocksComponent) courseBlocksComponent?: CoreBlockCourseBlocksComponent; @ViewChild(CoreBlockCourseBlocksComponent) courseBlocksComponent?: CoreBlockCourseBlocksComponent;
dataLoaded = false; dataLoaded = false;
section?: CoreCourseSection & { section?: CoreCourseWSSection & {
hasContent?: boolean; hasContent?: boolean;
}; };

View File

@ -17,7 +17,7 @@ import { Injectable } from '@angular/core';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreCourse, CoreCourseSection } from '../../course/services/course'; import { CoreCourse } from '../../course/services/course';
import { CoreCourses } from '../../courses/services/courses'; import { CoreCourses } from '../../courses/services/courses';
import { AddonModForum, AddonModForumData } from '@/addons/mod/forum/services/forum'; import { AddonModForum, AddonModForumData } from '@/addons/mod/forum/services/forum';
@ -90,8 +90,7 @@ export class CoreSiteHomeProvider {
const preSets: CoreSiteWSPreSets = { emergencyCache: false }; const preSets: CoreSiteWSPreSets = { emergencyCache: false };
try { try {
const sections: CoreCourseSection[] = const sections = await CoreCourse.instance.getSections(siteHomeId, false, true, preSets, site.id);
await CoreCourse.instance.getSections(siteHomeId, false, true, preSets, site.id);
if (!sections || !sections.length) { if (!sections || !sections.length) {
throw Error('No sections found'); throw Error('No sections found');