From 8b2b130e14d8f237e76df1e4b896859ec6ff2475 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 2 Apr 2024 14:36:02 +0200 Subject: [PATCH] MOBILE-4470 core: Make DownloadStatus types match const names --- .../mod/lesson/components/index/index.ts | 4 +-- src/addons/mod/quiz/components/index/index.ts | 4 +-- .../resource/services/handlers/prefetch.ts | 4 +-- .../mod/scorm/components/index/index.ts | 4 +-- .../pages/course-storage/course-storage.ts | 8 ++--- .../pages/courses-storage/courses-storage.ts | 4 +-- .../download-refresh/download-refresh.ts | 4 +-- src/core/components/file/file.ts | 4 +-- src/core/constants.ts | 12 +++---- .../course/classes/main-resource-component.ts | 6 ++-- .../course/components/module/module.ts | 4 +-- .../features/course/services/course-helper.ts | 26 +++++++-------- src/core/features/course/services/course.ts | 14 ++++---- .../course/services/database/course.ts | 6 ++-- .../course/services/module-delegate.ts | 4 +-- .../services/module-prefetch-delegate.ts | 32 +++++++++---------- .../course-list-item/course-list-item.ts | 6 ++-- .../h5p/components/h5p-iframe/h5p-iframe.ts | 4 +-- src/core/services/database/filepool.ts | 6 ++-- src/core/services/file-helper.ts | 8 ++--- src/core/services/filepool.ts | 18 +++++------ src/core/singletons/events.ts | 6 ++-- 22 files changed, 93 insertions(+), 95 deletions(-) diff --git a/src/addons/mod/lesson/components/index/index.ts b/src/addons/mod/lesson/components/index/index.ts index c81cf96af..13eb4b2d0 100644 --- a/src/addons/mod/lesson/components/index/index.ts +++ b/src/addons/mod/lesson/components/index/index.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { Component, Input, ViewChild, ElementRef, OnInit, OnDestroy, Optional } from '@angular/core'; import { CoreTabsComponent } from '@components/tabs/tabs'; @@ -575,7 +575,7 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo /** * @inheritdoc */ - protected showStatus(status: TDownloadStatus): void { + protected showStatus(status: DownloadStatus): void { this.showSpinner = status === DownloadStatus.DOWNLOADING; } diff --git a/src/addons/mod/quiz/components/index/index.ts b/src/addons/mod/quiz/components/index/index.ts index 04a2d16e5..cef7514ad 100644 --- a/src/addons/mod/quiz/components/index/index.ts +++ b/src/addons/mod/quiz/components/index/index.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { safeNumber, SafeNumber } from '@/core/utils/types'; import { Component, OnDestroy, OnInit, Optional } from '@angular/core'; @@ -543,7 +543,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp * @param status The current status. * @param previousStatus The previous status. If not defined, there is no previous status. */ - protected showStatus(status: TDownloadStatus, previousStatus?: TDownloadStatus): void { + protected showStatus(status: DownloadStatus, previousStatus?: DownloadStatus): void { this.showStatusSpinner = status === DownloadStatus.DOWNLOADING; if (status === DownloadStatus.DOWNLOADED && previousStatus === DownloadStatus.DOWNLOADING) { diff --git a/src/addons/mod/resource/services/handlers/prefetch.ts b/src/addons/mod/resource/services/handlers/prefetch.ts index 8fe22dbed..86c588bdf 100644 --- a/src/addons/mod/resource/services/handlers/prefetch.ts +++ b/src/addons/mod/resource/services/handlers/prefetch.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { Injectable } from '@angular/core'; import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; @@ -36,7 +36,7 @@ export class AddonModResourcePrefetchHandlerService extends CoreCourseResourcePr /** * @inheritdoc */ - determineStatus(module: CoreCourseAnyModuleData, status: TDownloadStatus): TDownloadStatus { + determineStatus(module: CoreCourseAnyModuleData, status: DownloadStatus): DownloadStatus { if (status === DownloadStatus.DOWNLOADED && module) { // If the main file is an external file, always display the module as outdated. if ('contentsinfo' in module && module.contentsinfo) { diff --git a/src/addons/mod/scorm/components/index/index.ts b/src/addons/mod/scorm/components/index/index.ts index 31bd6a394..81154f711 100644 --- a/src/addons/mod/scorm/components/index/index.ts +++ b/src/addons/mod/scorm/components/index/index.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { Component, Input, OnInit, Optional } from '@angular/core'; import { CoreError } from '@classes/errors/error'; import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component'; @@ -578,7 +578,7 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom /** * @inheritdoc */ - protected async showStatus(status: TDownloadStatus): Promise { + protected async showStatus(status: DownloadStatus): Promise { if (status === DownloadStatus.OUTDATED && this.scorm) { // Only show the outdated message if the file should be downloaded. diff --git a/src/addons/storagemanager/pages/course-storage/course-storage.ts b/src/addons/storagemanager/pages/course-storage/course-storage.ts index 7fd54e1c7..7c7ee9f1a 100644 --- a/src/addons/storagemanager/pages/course-storage/course-storage.ts +++ b/src/addons/storagemanager/pages/course-storage/course-storage.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { CoreConstants, DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { CoreConstants, DownloadStatus } from '@/core/constants'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit } from '@angular/core'; import { CoreCourse, CoreCourseProvider } from '@features/course/services/course'; import { @@ -607,7 +607,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { * @param module Module to update. * @param status Module status. */ - protected updateModuleStatus(module: AddonStorageManagerModule, status: TDownloadStatus): void { + protected updateModuleStatus(module: AddonStorageManagerModule, status: DownloadStatus): void { if (!status) { return; } @@ -649,7 +649,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { * * @param status Status to show. */ - protected updateCourseStatus(status: TDownloadStatus): void { + protected updateCourseStatus(status: DownloadStatus): void { const statusData = CoreCourseHelper.getCoursePrefetchStatusInfo(status); this.prefetchCourseData.status = statusData.status; @@ -758,5 +758,5 @@ type AddonStorageManagerModule = CoreCourseModuleData & { calculatingSize: boolean; prefetchHandler?: CoreCourseModulePrefetchHandler; spinner?: boolean; - downloadStatus?: TDownloadStatus; + downloadStatus?: DownloadStatus; }; diff --git a/src/addons/storagemanager/pages/courses-storage/courses-storage.ts b/src/addons/storagemanager/pages/courses-storage/courses-storage.ts index ccf2f599a..e118ab127 100644 --- a/src/addons/storagemanager/pages/courses-storage/courses-storage.ts +++ b/src/addons/storagemanager/pages/courses-storage/courses-storage.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { Component, OnDestroy, OnInit } from '@angular/core'; import { CoreCourse, CoreCourseProvider } from '@features/course/services/course'; import { CoreCourseHelper } from '@features/course/services/course-helper'; @@ -175,7 +175,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy * * @param courseId Updated course id. */ - private async onCourseUpdated(courseId: number, status: TDownloadStatus): Promise { + private async onCourseUpdated(courseId: number, status: DownloadStatus): Promise { if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { this.setDownloadedCourses([]); diff --git a/src/core/components/download-refresh/download-refresh.ts b/src/core/components/download-refresh/download-refresh.ts index f4c35a050..13f67a5a8 100644 --- a/src/core/components/download-refresh/download-refresh.ts +++ b/src/core/components/download-refresh/download-refresh.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Component, Input, Output, EventEmitter } from '@angular/core'; -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { CoreAnimations } from '@components/animations'; /** @@ -31,7 +31,7 @@ import { CoreAnimations } from '@components/animations'; }) export class CoreDownloadRefreshComponent { - @Input() status?: TDownloadStatus; // Download status. + @Input() status?: DownloadStatus; // Download status. @Input() statusTranslatable?: string; // Download status translatable string. @Input() enabled = false; // Whether the download is enabled. @Input() loading = true; // Force loading status when is not downloading. diff --git a/src/core/components/file/file.ts b/src/core/components/file/file.ts index a347c42ec..46dc1917d 100644 --- a/src/core/components/file/file.ts +++ b/src/core/components/file/file.ts @@ -23,7 +23,7 @@ import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreUrlUtils } from '@services/utils/url'; import { CoreUtils, CoreUtilsOpenFileOptions, OpenFileAction } from '@services/utils/utils'; import { CoreTextUtils } from '@services/utils/text'; -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreWSFile } from '@services/ws'; import { CorePlatform } from '@services/platform'; @@ -53,7 +53,7 @@ export class CoreFileComponent implements OnInit, OnDestroy { fileIcon?: string; fileName!: string; fileSizeReadable?: string; - state?: TDownloadStatus; + state?: DownloadStatus; timemodified!: number; isIOS = false; openButtonIcon = ''; diff --git a/src/core/constants.ts b/src/core/constants.ts index 1188338b6..96706ea39 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -46,7 +46,7 @@ export const enum ModPurpose { MOD_PURPOSE_OTHER = 'other', } -/* eslint-disable @typescript-eslint/naming-convention */ +/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-redeclare */ /** * Possible statuses for downloaded modules/files. */ @@ -55,6 +55,7 @@ export const DownloadedStatus = { DOWNLOADING: 'downloading', OUTDATED: 'outdated', } as const; +export type DownloadedStatus = typeof DownloadedStatus[keyof typeof DownloadedStatus]; /** * Possible statuses for not downloaded modules/files. @@ -63,6 +64,7 @@ export const NotDownloadedStatus = { DOWNLOADABLE_NOT_DOWNLOADED: 'notdownloaded', NOT_DOWNLOADABLE: 'notdownloadable', } as const; +export type NotDownloadedStatus = typeof NotDownloadedStatus[keyof typeof NotDownloadedStatus]; /** * Possible statuses for modules regarding download. @@ -71,12 +73,8 @@ export const DownloadStatus = { ...DownloadedStatus, ...NotDownloadedStatus, } as const; - -export type TDownloadedStatus = typeof DownloadedStatus[keyof typeof DownloadedStatus]; -export type TNotDownloadedStatus = typeof NotDownloadedStatus[keyof typeof NotDownloadedStatus]; -export type TDownloadStatus = typeof DownloadStatus[keyof typeof DownloadStatus]; - -/* eslint-enable @typescript-eslint/naming-convention */ +export type DownloadStatus = typeof DownloadStatus[keyof typeof DownloadStatus]; +/* eslint-enable @typescript-eslint/naming-convention, @typescript-eslint/no-redeclare */ /** * Static class to contain all the core constants. diff --git a/src/core/features/course/classes/main-resource-component.ts b/src/core/features/course/classes/main-resource-component.ts index 2ea85942b..27fd778b0 100644 --- a/src/core/features/course/classes/main-resource-component.ts +++ b/src/core/features/course/classes/main-resource-component.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { OnInit, OnDestroy, Input, Output, EventEmitter, Component, Optional, Inject } from '@angular/core'; import { CoreAnyError } from '@classes/errors/error'; import { CoreNetwork } from '@services/network'; @@ -65,7 +65,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, protected isCurrentView = false; // Whether the component is in the current view. protected siteId?: string; // Current Site ID. protected statusObserver?: CoreEventObserver; // Observer of package status. Only if setStatusListener is called. - currentStatus?: TDownloadStatus; // The current status of the module. Only if setStatusListener is called. + currentStatus?: DownloadStatus; // The current status of the module. Only if setStatusListener is called. downloadTimeReadable?: string; // Last download time in a readable format. Only if setStatusListener is called. protected completionObserver?: CoreEventObserver; @@ -282,7 +282,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, * @param previousStatus The previous status. If not defined, there is no previous status. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - protected showStatus(status: TDownloadStatus, previousStatus?: TDownloadStatus): void { + protected showStatus(status: DownloadStatus, previousStatus?: DownloadStatus): void { // To be overridden. } diff --git a/src/core/features/course/components/module/module.ts b/src/core/features/course/components/module/module.ts index 3f02e900d..f8c867751 100644 --- a/src/core/features/course/components/module/module.ts +++ b/src/core/features/course/components/module/module.ts @@ -27,7 +27,7 @@ import { CoreCourseModulePrefetchDelegate, CoreCourseModulePrefetchHandler, } from '@features/course/services/module-prefetch-delegate'; -import { CoreConstants, DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { CoreConstants, DownloadStatus } from '@/core/constants'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { BehaviorSubject } from 'rxjs'; @@ -146,7 +146,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { * * @param prefetchStatus Module status. */ - protected updateModuleStatus(prefetchStatus: TDownloadStatus | null): void { + protected updateModuleStatus(prefetchStatus: DownloadStatus | null): void { if (!prefetchStatus) { return; } diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index 13d903779..a20f2b735 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -28,7 +28,7 @@ import { CoreCourseModuleCompletionStatus, CoreCourseGetContentsWSModule, } from './course'; -import { CoreConstants, DownloadStatus, TDownloadStatus, ContextLevel } from '@/core/constants'; +import { CoreConstants, DownloadStatus, ContextLevel } from '@/core/constants'; import { CoreLogger } from '@singletons/logger'; import { ApplicationInit, makeSingleton, Translate } from '@singletons'; import { CoreFilepool } from '@services/filepool'; @@ -82,7 +82,7 @@ import { LazyRoutesModule } from '@/app/app-routing.module'; export type CoreCourseModulePrefetchInfo = CoreCourseModulePackageLastDownloaded & { size: number; // Downloaded size. sizeReadable: string; // Downloadable size in a readable format. - status: TDownloadStatus; // Module status. + status: DownloadStatus; // Module status. statusIcon?: string; // Icon's name of the module status. }; @@ -120,7 +120,7 @@ export type CoreCourseCoursesProgress = { }; export type CorePrefetchStatusInfo = { - status: TDownloadStatus; // Status of the prefetch. + status: DownloadStatus; // Status of the prefetch. statusTranslatable: string; // Status translatable string. icon: string; // Icon based on the status. loading: boolean; // If it's a loading status. @@ -328,7 +328,7 @@ export class CoreCourseHelperProvider { checkUpdates: boolean = true, ): Promise { let allSectionsSection: CoreCourseSectionWithStatus | undefined; - let allSectionsStatus = DownloadStatus.NOT_DOWNLOADABLE as TDownloadStatus; + let allSectionsStatus = DownloadStatus.NOT_DOWNLOADABLE as DownloadStatus; const promises = sections.map(async (section: CoreCourseSectionWithStatus) => { section.isCalculating = true; @@ -632,9 +632,9 @@ export class CoreCourseHelperProvider { * @param courses Courses * @returns Promise resolved with the status. */ - async determineCoursesStatus(courses: CoreCourseBasicData[]): Promise { + async determineCoursesStatus(courses: CoreCourseBasicData[]): Promise { // Get the status of each course. - const promises: Promise[] = []; + const promises: Promise[] = []; const siteId = CoreSites.getCurrentSiteId(); courses.forEach((course) => { @@ -817,7 +817,7 @@ export class CoreCourseHelperProvider { files?: CoreCourseModuleContentFile[], siteId?: string, options: CoreUtilsOpenFileOptions = {}, - ): Promise<{ fixedUrl: string; path: string; status?: TDownloadStatus }> { + ): Promise<{ fixedUrl: string; path: string; status?: DownloadStatus }> { siteId = siteId || CoreSites.getCurrentSiteId(); @@ -910,7 +910,7 @@ export class CoreCourseHelperProvider { courseId: number, fixedUrl: string, files: CoreCourseModuleContentFile[], - status: TDownloadStatus, + status: DownloadStatus, component?: string, componentId?: string | number, siteId?: string, @@ -1239,7 +1239,7 @@ export class CoreCourseHelperProvider { * @param status Course status. * @returns Prefetch status info. */ - getCoursePrefetchStatusInfo(status: TDownloadStatus): CorePrefetchStatusInfo { + getCoursePrefetchStatusInfo(status: DownloadStatus): CorePrefetchStatusInfo { const prefetchStatus: CorePrefetchStatusInfo = { status: status, icon: this.getPrefetchStatusIcon(status, false), @@ -1266,7 +1266,7 @@ export class CoreCourseHelperProvider { * @param status Courses status. * @returns Prefetch status info. */ - getCoursesPrefetchStatusInfo(status: TDownloadStatus): CorePrefetchStatusInfo { + getCoursesPrefetchStatusInfo(status: DownloadStatus): CorePrefetchStatusInfo { const prefetchStatus: CorePrefetchStatusInfo = { status: status, icon: this.getPrefetchStatusIcon(status, false), @@ -1294,7 +1294,7 @@ export class CoreCourseHelperProvider { * @param trustDownload True to show download success, false to show an outdated status when downloaded. * @returns Icon name. */ - getPrefetchStatusIcon(status: TDownloadStatus, trustDownload: boolean = false): string { + getPrefetchStatusIcon(status: DownloadStatus, trustDownload: boolean = false): string { if (status === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) { return CoreConstants.ICON_NOT_DOWNLOADED; } @@ -1714,7 +1714,7 @@ export class CoreCourseHelperProvider { } // Download all the sections except "All sections". - let allSectionsStatus = DownloadStatus.NOT_DOWNLOADABLE as TDownloadStatus; + let allSectionsStatus = DownloadStatus.NOT_DOWNLOADABLE as DownloadStatus; section.isDownloading = true; const promises = sections.map(async (section) => { @@ -2073,7 +2073,7 @@ export type CoreCourseSection = CoreCourseWSSection & { * Section with data about prefetch. */ export type CoreCourseSectionWithStatus = CoreCourseSection & { - downloadStatus?: TDownloadStatus; // Section status. + downloadStatus?: DownloadStatus; // Section status. isDownloading?: boolean; // Whether section is being downloaded. total?: number; // Total of modules being downloaded. count?: number; // Number of downloaded modules. diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 0451da80f..ad0ef1cbe 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -22,7 +22,7 @@ import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@ import { CoreTimeUtils } from '@services/utils/time'; import { CoreUtils } from '@services/utils/utils'; import { CoreSite } from '@classes/sites/site'; -import { CoreConstants, DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { CoreConstants, DownloadStatus } from '@/core/constants'; import { makeSingleton, Translate } from '@singletons'; import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; @@ -477,7 +477,7 @@ export class CoreCourseProvider { * @param siteId Site ID. If not defined, current site. * @returns Promise resolved with the status. */ - async getCourseStatus(courseId: number, siteId?: string): Promise { + async getCourseStatus(courseId: number, siteId?: string): Promise { try { const entry = await this.getCourseStatusData(courseId, siteId); @@ -494,7 +494,7 @@ export class CoreCourseProvider { * @returns Resolves with an array containing downloaded course ids. */ async getDownloadedCourseIds(siteId?: string): Promise { - const downloadedStatuses: TDownloadStatus[] = + const downloadedStatuses: DownloadStatus[] = [DownloadStatus.DOWNLOADED, DownloadStatus.DOWNLOADING, DownloadStatus.OUTDATED]; const site = await CoreSites.getSite(siteId); const entries = await this.statusTables[site.getId()].getManyWhere({ @@ -1403,7 +1403,7 @@ export class CoreCourseProvider { * @param siteId Site ID. If not defined, current site. * @returns Promise resolved when the status is changed. Resolve param: new status. */ - async setCoursePreviousStatus(courseId: number, siteId?: string): Promise { + async setCoursePreviousStatus(courseId: number, siteId?: string): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); this.logger.debug(`Set previous status for course ${courseId} in site ${siteId}`); @@ -1436,7 +1436,7 @@ export class CoreCourseProvider { * @param siteId Site ID. If not defined, current site. * @returns Promise resolved when the status is stored. */ - async setCourseStatus(courseId: number, status: TDownloadStatus, siteId?: string): Promise { + async setCourseStatus(courseId: number, status: DownloadStatus, siteId?: string): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); this.logger.debug(`Set status '${status}' for course ${courseId} in site ${siteId}`); @@ -1444,7 +1444,7 @@ export class CoreCourseProvider { const site = await CoreSites.getSite(siteId); let downloadTime = 0; let previousDownloadTime = 0; - let previousStatus: TDownloadStatus | undefined; + let previousStatus: DownloadStatus | undefined; if (status === DownloadStatus.DOWNLOADING) { // Set download time if course is now downloading. @@ -1534,7 +1534,7 @@ export class CoreCourseProvider { * @param status New course status. * @param siteId Site ID. If not defined, current site. */ - protected triggerCourseStatusChanged(courseId: number, status: TDownloadStatus, siteId?: string): void { + protected triggerCourseStatusChanged(courseId: number, status: DownloadStatus, siteId?: string): void { CoreEvents.trigger(CoreEvents.COURSE_STATUS_CHANGED, { courseId: courseId, status: status, diff --git a/src/core/features/course/services/database/course.ts b/src/core/features/course/services/database/course.ts index 32d04abb6..aceb71b98 100644 --- a/src/core/features/course/services/database/course.ts +++ b/src/core/features/course/services/database/course.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { CoreSiteSchema } from '@services/sites'; /** @@ -121,8 +121,8 @@ export const OFFLINE_SITE_SCHEMA: CoreSiteSchema = { export type CoreCourseStatusDBRecord = { id: number; - status: TDownloadStatus; - previous: TDownloadStatus | undefined; + status: DownloadStatus; + previous: DownloadStatus | undefined; updated: number; downloadTime: number; previousDownloadTime: number; diff --git a/src/core/features/course/services/module-delegate.ts b/src/core/features/course/services/module-delegate.ts index 9e3328bb4..d38b65111 100644 --- a/src/core/features/course/services/module-delegate.ts +++ b/src/core/features/course/services/module-delegate.ts @@ -25,7 +25,7 @@ import { makeSingleton } from '@singletons'; import { CoreCourseModuleData } from './course-helper'; import { CoreNavigationOptions } from '@services/navigator'; import { CoreIonicColorNames } from '@singletons/colors'; -import { TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; /** * Interface that all course module handlers must implement. @@ -223,7 +223,7 @@ export interface CoreCourseModuleHandlerData { * * @param status Module status. */ - updateStatus?(status: TDownloadStatus): void; + updateStatus?(status: DownloadStatus): void; /** * On Destroy function in case it's needed. diff --git a/src/core/features/course/services/module-prefetch-delegate.ts b/src/core/features/course/services/module-prefetch-delegate.ts index 094b444bd..bad90946d 100644 --- a/src/core/features/course/services/module-prefetch-delegate.ts +++ b/src/core/features/course/services/module-prefetch-delegate.ts @@ -25,7 +25,7 @@ import { CoreUtils } from '@services/utils/utils'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseModuleContentFile } from './course'; import { CoreCache } from '@classes/cache'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; -import { DownloadStatus, TDownloadStatus, TDownloadedStatus, ContextLevel } from '@/core/constants'; +import { DownloadStatus, DownloadedStatus, ContextLevel } from '@/core/constants'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { makeSingleton } from '@singletons'; import { CoreEvents, CoreEventSectionStatusChangedData } from '@singletons/events'; @@ -160,7 +160,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + ): Promise { const handler = this.getPrefetchHandlerFor(module.modname); if (!handler) { @@ -538,7 +538,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'status'); + const status = this.statusCache.getValue(packageId, 'status'); if (!refresh && status !== undefined) { this.storeCourseAndSection(packageId, courseId, sectionId); @@ -573,7 +573,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + ): Promise { const handler = this.getPrefetchHandlerFor(module.modname); if (!handler) { // No handler found, module not downloadable. @@ -582,7 +582,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'status'); + const status = this.statusCache.getValue(packageId, 'status'); if (!refresh && status !== undefined) { this.storeCourseAndSection(packageId, courseId, sectionId); @@ -617,7 +617,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + ): Promise<{status: DownloadStatus; updateStatus: boolean}> { // Check if the module is downloadable. const downloadable = await this.isModuleDownloadable(module, courseId); if (!downloadable) { @@ -654,7 +654,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate { + ): Promise<{status: DownloadedStatus | null; updateStatus: boolean}> { // Get the saved package status. const siteId = CoreSites.getCurrentSiteId(); const currentStatus = await CoreFilepool.getPackageStatus(siteId, handler.component, module.id); @@ -718,7 +718,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'status', true); + const status = this.statusCache.getValue(packageId, 'status', true); return { status: status ? this.filterDownloadedStatus(status) : null, @@ -733,7 +733,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'status', true); + const cacheStatus = this.statusCache.getValue(packageId, 'status', true); if (cacheStatus === undefined) { throw error; } @@ -833,7 +833,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'status'); + const status = this.statusCache.getValue(packageId, 'status'); if (status !== undefined && !CoreFileHelper.isStateDownloaded(status)) { return {}; @@ -1343,14 +1343,14 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate(packageId, 'status', true); + const cachedStatus = this.statusCache.getValue(packageId, 'status', true); // If courseId/sectionId is set, store it. this.storeCourseAndSection(packageId, courseId, sectionId); @@ -1489,7 +1489,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler { * @param canCheck Whether the site allows checking for updates. This parameter was deprecated since app 4.0. * @returns Status to display. */ - determineStatus?(module: CoreCourseAnyModuleData, status: TDownloadStatus, canCheck: true): TDownloadStatus; + determineStatus?(module: CoreCourseAnyModuleData, status: DownloadStatus, canCheck: true): DownloadStatus; /** * Get the downloaded size of a module. If not defined, we'll use getFiles to calculate it (it can be slow). @@ -1582,7 +1582,7 @@ type CourseUpdates = Record; */ export type CoreCourseModulesStatus = { total: number; // Number of modules. - status: TDownloadStatus; // Status of the list of modules. + status: DownloadStatus; // Status of the list of modules. [DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED]: CoreCourseModuleData[]; // Modules with state NOT_DOWNLOADED. [DownloadStatus.DOWNLOADED]: CoreCourseModuleData[]; // Modules with state DOWNLOADED. [DownloadStatus.DOWNLOADING]: CoreCourseModuleData[]; // Modules with state DOWNLOADING. diff --git a/src/core/features/courses/components/course-list-item/course-list-item.ts b/src/core/features/courses/components/course-list-item/course-list-item.ts index 5a110359f..50dfd1ef1 100644 --- a/src/core/features/courses/components/course-list-item/course-list-item.ts +++ b/src/core/features/courses/components/course-list-item/course-list-item.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { Component, ElementRef, Input, OnChanges, OnDestroy, OnInit } from '@angular/core'; import { CoreCourseProvider, CoreCourse } from '@features/course/services/course'; import { CoreCourseHelper, CorePrefetchStatusInfo } from '@features/course/services/course-helper'; @@ -60,7 +60,7 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On progress = -1; completionUserTracked: boolean | undefined = false; - protected courseStatus: TDownloadStatus = DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED; + protected courseStatus: DownloadStatus = DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED; protected isDestroyed = false; protected courseStatusObserver?: CoreEventObserver; @@ -211,7 +211,7 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On * * @param status Status to show. */ - protected updateCourseStatus(status: TDownloadStatus): void { + protected updateCourseStatus(status: DownloadStatus): void { const statusData = CoreCourseHelper.getCoursePrefetchStatusInfo(status); this.courseStatus = status; diff --git a/src/core/features/h5p/components/h5p-iframe/h5p-iframe.ts b/src/core/features/h5p/components/h5p-iframe/h5p-iframe.ts index 577eb9d66..1aef7bcd9 100644 --- a/src/core/features/h5p/components/h5p-iframe/h5p-iframe.ts +++ b/src/core/features/h5p/components/h5p-iframe/h5p-iframe.ts @@ -24,7 +24,7 @@ import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUrlUtils } from '@services/utils/url'; import { CoreH5P } from '@features/h5p/services/h5p'; -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { CoreSite } from '@classes/sites/site'; import { CoreLogger } from '@singletons/logger'; import { CoreH5PCore, CoreH5PDisplayOptions } from '../../classes/core'; @@ -100,7 +100,7 @@ export class CoreH5PIframeComponent implements OnChanges, OnDestroy { */ protected async play(): Promise { let localUrl: string | undefined; - let state: TDownloadStatus; + let state: DownloadStatus; this.onlinePlayerUrl = this.onlinePlayerUrl || CoreH5P.h5pPlayer.calculateOnlinePlayerUrl( this.site.getURL(), this.fileUrl || '', diff --git a/src/core/services/database/filepool.ts b/src/core/services/database/filepool.ts index 7346d7a25..52c701e4b 100644 --- a/src/core/services/database/filepool.ts +++ b/src/core/services/database/filepool.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { CoreAppSchema } from '@services/app'; import { CoreSiteSchema } from '@services/sites'; @@ -315,12 +315,12 @@ export type CoreFilepoolPackageEntry = { /** * Package status. */ - status?: TDownloadStatus; + status?: DownloadStatus; /** * Package previous status. */ - previous?: TDownloadStatus; + previous?: DownloadStatus; /** * Timestamp when this package was updated. diff --git a/src/core/services/file-helper.ts b/src/core/services/file-helper.ts index 9e9b026d0..6ddc63aef 100644 --- a/src/core/services/file-helper.ts +++ b/src/core/services/file-helper.ts @@ -23,7 +23,7 @@ import { CoreWS, CoreWSFile } from '@services/ws'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUrlUtils } from '@services/utils/url'; import { CoreUtils, CoreUtilsOpenFileOptions, OpenFileAction } from '@services/utils/utils'; -import { CoreConstants, DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { CoreConstants, DownloadStatus } from '@/core/constants'; import { CoreError } from '@classes/errors/error'; import { makeSingleton, Translate } from '@singletons'; import { CoreNetworkError } from '@classes/errors/network-error'; @@ -63,7 +63,7 @@ export class CoreFileHelperProvider { file: CoreWSFile, component?: string, componentId?: string | number, - state?: TDownloadStatus, + state?: DownloadStatus, onProgress?: CoreFileHelperOnProgress, siteId?: string, options: CoreUtilsOpenFileOptions = {}, @@ -150,7 +150,7 @@ export class CoreFileHelperProvider { component?: string, componentId?: string | number, timemodified?: number, - state?: TDownloadStatus, + state?: DownloadStatus, onProgress?: CoreFileHelperOnProgress, siteId?: string, options: CoreUtilsOpenFileOptions = {}, @@ -304,7 +304,7 @@ export class CoreFileHelperProvider { * @param state The state to check. * @returns If file has been downloaded (or outdated). */ - isStateDownloaded(state: TDownloadStatus): boolean { + isStateDownloaded(state: DownloadStatus): boolean { return state === DownloadStatus.DOWNLOADED || state === DownloadStatus.OUTDATED; } diff --git a/src/core/services/filepool.ts b/src/core/services/filepool.ts index 438211b3a..af8b9ab44 100644 --- a/src/core/services/filepool.ts +++ b/src/core/services/filepool.ts @@ -29,7 +29,7 @@ import { CoreTimeUtils } from '@services/utils/time'; import { CoreUrlUtils } from '@services/utils/url'; import { CoreUtils, CoreUtilsOpenFileOptions } from '@services/utils/utils'; import { CoreError } from '@classes/errors/error'; -import { DownloadStatus, TDownloadStatus } from '@/core/constants'; +import { DownloadStatus } from '@/core/constants'; import { ApplicationInit, makeSingleton, NgZone, Translate } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { @@ -686,7 +686,7 @@ export class CoreFilepoolProvider { * @param packageStatus Status of one of the packages. * @returns New status for the list of packages; */ - determinePackagesStatus(current: TDownloadStatus, packageStatus: TDownloadStatus): TDownloadStatus { + determinePackagesStatus(current: DownloadStatus, packageStatus: DownloadStatus): DownloadStatus { if (!current) { current = DownloadStatus.NOT_DOWNLOADABLE; } @@ -1525,7 +1525,7 @@ export class CoreFilepoolProvider { timemodified: number = 0, filePath?: string, revision?: number, - ): Promise { + ): Promise { let file: CoreWSFile; try { @@ -1878,7 +1878,7 @@ export class CoreFilepoolProvider { * @param componentId An ID to use in conjunction with the component. * @returns Promise resolved with the status. */ - async getPackagePreviousStatus(siteId: string, component: string, componentId?: string | number): Promise { + async getPackagePreviousStatus(siteId: string, component: string, componentId?: string | number): Promise { try { const entry = await this.getPackageData(siteId, component, componentId); @@ -1896,7 +1896,7 @@ export class CoreFilepoolProvider { * @param componentId An ID to use in conjunction with the component. * @returns Promise resolved with the status. */ - async getPackageStatus(siteId: string, component: string, componentId?: string | number): Promise { + async getPackageStatus(siteId: string, component: string, componentId?: string | number): Promise { try { const entry = await this.getPackageData(siteId, component, componentId); @@ -2830,7 +2830,7 @@ export class CoreFilepoolProvider { * @param componentId An ID to use in conjunction with the component. * @returns Promise resolved when the status is changed. Resolve param: new status. */ - async setPackagePreviousStatus(siteId: string, component: string, componentId?: string | number): Promise { + async setPackagePreviousStatus(siteId: string, component: string, componentId?: string | number): Promise { componentId = this.fixComponentId(componentId); this.logger.debug(`Set previous status for package ${component} ${componentId}`); @@ -2909,7 +2909,7 @@ export class CoreFilepoolProvider { */ async storePackageStatus( siteId: string, - status: TDownloadStatus, + status: DownloadStatus, component: string, componentId?: string | number, extra?: string, @@ -2926,7 +2926,7 @@ export class CoreFilepoolProvider { downloadTime = CoreTimeUtils.timestamp(); } - let previousStatus: TDownloadStatus | undefined; + let previousStatus: DownloadStatus | undefined; // Search current status to set it as previous status. try { const entry = await this.packagesTables[siteId].getOneByPrimaryKey({ id: packageId }); @@ -3075,7 +3075,7 @@ export class CoreFilepoolProvider { */ protected triggerPackageStatusChanged( siteId: string, - status: TDownloadStatus, + status: DownloadStatus, component: string, componentId?: string | number, ): void { diff --git a/src/core/singletons/events.ts b/src/core/singletons/events.ts index 9026c7616..cc8eab779 100644 --- a/src/core/singletons/events.ts +++ b/src/core/singletons/events.ts @@ -21,7 +21,7 @@ import { CoreRedirectPayload } from '@services/navigator'; import { CoreCourseModuleCompletionData } from '@features/course/services/course-helper'; import { CoreScreenOrientation } from '@services/screen'; import { CoreSiteInfoResponse, CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site'; -import { TDownloadStatus } from '../constants'; +import { DownloadStatus } from '../constants'; /** * Observer instance to stop listening to an event. @@ -327,7 +327,7 @@ export type CoreEventLoadingChangedData = { */ export type CoreEventCourseStatusChanged = { courseId: number; // Course Id. - status: TDownloadStatus; + status: DownloadStatus; }; /** @@ -336,7 +336,7 @@ export type CoreEventCourseStatusChanged = { export type CoreEventPackageStatusChanged = { component: string; componentId: string | number; - status: TDownloadStatus; + status: DownloadStatus; }; /**