Merge pull request #3959 from dpalou/MOBILE-4539

Mobile 4539
main
Pau Ferrer Ocaña 2024-03-11 11:53:29 +01:00 committed by GitHub
commit ebbfe039c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
38 changed files with 442 additions and 286 deletions

View File

@ -35,6 +35,7 @@ import { IonSearchbar } from '@ionic/angular';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { PageLoadWatcher } from '@classes/page-load-watcher'; import { PageLoadWatcher } from '@classes/page-load-watcher';
import { PageLoadsManager } from '@classes/page-loads-manager'; import { PageLoadsManager } from '@classes/page-loads-manager';
import { DownloadStatus } from '@/core/constants';
const FILTER_PRIORITY: AddonBlockMyOverviewTimeFilters[] = const FILTER_PRIORITY: AddonBlockMyOverviewTimeFilters[] =
['all', 'inprogress', 'future', 'past', 'favourite', 'allincludinghidden', 'hidden']; ['all', 'inprogress', 'future', 'past', 'favourite', 'allincludinghidden', 'hidden'];
@ -54,7 +55,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
prefetchCoursesData: CorePrefetchStatusInfo = { prefetchCoursesData: CorePrefetchStatusInfo = {
icon: '', icon: '',
statusTranslatable: 'core.loading', statusTranslatable: 'core.loading',
status: '', status: DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED,
loading: true, loading: true,
}; };

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreSwipeSlidesItemsManager } from '@classes/items-management/swipe-slides-items-manager'; import { CoreSwipeSlidesItemsManager } from '@classes/items-management/swipe-slides-items-manager';
@ -180,7 +180,7 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy {
// Get module status to determine if it needs to be downloaded. // Get module status to determine if it needs to be downloaded.
const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(module, this.courseId, undefined, refresh); const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(module, this.courseId, undefined, refresh);
if (status !== CoreConstants.DOWNLOADED) { if (status !== DownloadStatus.DOWNLOADED) {
// Download content. This function also loads module contents if needed. // Download content. This function also loads module contents if needed.
try { try {
await CoreCourseModulePrefetchDelegate.downloadModule(module, this.courseId); await CoreCourseModulePrefetchDelegate.downloadModule(module, this.courseId);

View File

@ -15,7 +15,7 @@
import { Component, Optional, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core'; import { Component, Optional, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core';
import { IonContent } from '@ionic/angular'; import { IonContent } from '@ionic/angular';
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { CoreSite } from '@classes/sites/site'; import { CoreSite } from '@classes/sites/site';
import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component'; import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component';
import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { CoreCourseContentsPage } from '@features/course/pages/contents/contents';
@ -161,12 +161,16 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
); );
} }
if (!this.siteCanDownload || this.state == CoreConstants.DOWNLOADED) { if (!this.siteCanDownload || this.state === DownloadStatus.DOWNLOADED) {
// Cannot download the file or already downloaded, play the package directly. // Cannot download the file or already downloaded, play the package directly.
this.play(); this.play();
} else if ((this.state == CoreConstants.NOT_DOWNLOADED || this.state == CoreConstants.OUTDATED) && CoreNetwork.isOnline() && } else if (
this.deployedFile?.filesize && CoreFilepool.shouldDownload(this.deployedFile.filesize)) { (this.state == DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED || this.state == DownloadStatus.OUTDATED) &&
CoreNetwork.isOnline() &&
this.deployedFile?.filesize &&
CoreFilepool.shouldDownload(this.deployedFile.filesize)
) {
// Package is small, download it automatically. Don't block this function for this. // Package is small, download it automatically. Don't block this function for this.
this.downloadAutomatically(); this.downloadAutomatically();
} }
@ -295,13 +299,13 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
* Displays some data based on the state of the main file. * Displays some data based on the state of the main file.
*/ */
protected async showFileState(): Promise<void> { protected async showFileState(): Promise<void> {
if (this.state == CoreConstants.OUTDATED) { if (this.state === DownloadStatus.OUTDATED) {
this.stateMessage = 'addon.mod_h5pactivity.filestateoutdated'; this.stateMessage = 'addon.mod_h5pactivity.filestateoutdated';
this.needsDownload = true; this.needsDownload = true;
} else if (this.state == CoreConstants.NOT_DOWNLOADED) { } else if (this.state === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
this.stateMessage = 'addon.mod_h5pactivity.filestatenotdownloaded'; this.stateMessage = 'addon.mod_h5pactivity.filestatenotdownloaded';
this.needsDownload = true; this.needsDownload = true;
} else if (this.state == CoreConstants.DOWNLOADING) { } else if (this.state === DownloadStatus.DOWNLOADING) {
this.stateMessage = ''; this.stateMessage = '';
if (!this.downloading) { if (!this.downloading) {

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler'; import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler';
@ -144,7 +144,7 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit
// If the file needs to be downloaded, delete the states because it means the package has changed or user deleted it. // If the file needs to be downloaded, delete the states because it means the package has changed or user deleted it.
const fileState = await CoreFilepool.getFileStateByUrl(siteId, CoreFileHelper.getFileUrl(deployedFile)); const fileState = await CoreFilepool.getFileStateByUrl(siteId, CoreFileHelper.getFileUrl(deployedFile));
if (fileState !== CoreConstants.DOWNLOADED) { if (fileState !== DownloadStatus.DOWNLOADED) {
await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(AddonModH5PActivityProvider.TRACK_COMPONENT, { await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(AddonModH5PActivityProvider.TRACK_COMPONENT, {
itemId: h5pActivity.context, itemId: h5pActivity.context,
siteId, siteId,

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreNavigationBarItem } from '@components/navigation-bar/navigation-bar'; import { CoreNavigationBarItem } from '@components/navigation-bar/navigation-bar';
@ -173,7 +173,7 @@ export class AddonModImscpViewPage implements OnInit {
// Get module status to determine if it needs to be downloaded. // Get module status to determine if it needs to be downloaded.
const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(module, this.courseId, undefined, refresh); const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(module, this.courseId, undefined, refresh);
if (status !== CoreConstants.DOWNLOADED) { if (status !== DownloadStatus.DOWNLOADED) {
// Download content. This function also loads module contents if needed. // Download content. This function also loads module contents if needed.
try { try {
await CoreCourseModulePrefetchDelegate.downloadModule(module, this.courseId); await CoreCourseModulePrefetchDelegate.downloadModule(module, this.courseId);

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { Component, Input, ViewChild, ElementRef, OnInit, OnDestroy, Optional } from '@angular/core'; import { Component, Input, ViewChild, ElementRef, OnInit, OnDestroy, Optional } from '@angular/core';
import { CoreTabsComponent } from '@components/tabs/tabs'; import { CoreTabsComponent } from '@components/tabs/tabs';
@ -575,8 +575,8 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected showStatus(status: string): void { protected showStatus(status: TDownloadStatus): void {
this.showSpinner = status == CoreConstants.DOWNLOADING; this.showSpinner = status === DownloadStatus.DOWNLOADING;
} }
/** /**
@ -590,7 +590,7 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo
return; return;
} }
if (!AddonModLesson.isLessonOffline(this.lesson) || this.currentStatus == CoreConstants.DOWNLOADED) { if (!AddonModLesson.isLessonOffline(this.lesson) || this.currentStatus == DownloadStatus.DOWNLOADED) {
// Not downloadable or already downloaded, open it. // Not downloadable or already downloaded, open it.
this.playLesson(continueLast); this.playLesson(continueLast);

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { safeNumber, SafeNumber } from '@/core/utils/types'; import { safeNumber, SafeNumber } from '@/core/utils/types';
import { Component, OnDestroy, OnInit, Optional } from '@angular/core'; import { Component, OnDestroy, OnInit, Optional } from '@angular/core';
@ -141,7 +141,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
// Quiz supports offline, check if it needs to be downloaded. // Quiz supports offline, check if it needs to be downloaded.
// If the site doesn't support check updates, always prefetch it because we cannot tell if there's something new. // If the site doesn't support check updates, always prefetch it because we cannot tell if there's something new.
const isDownloaded = this.currentStatus == CoreConstants.DOWNLOADED; const isDownloaded = this.currentStatus === DownloadStatus.DOWNLOADED;
if (isDownloaded) { if (isDownloaded) {
// Already downloaded, open it. // Already downloaded, open it.
@ -543,10 +543,10 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
* @param status The current status. * @param status The current status.
* @param previousStatus The previous status. If not defined, there is no previous status. * @param previousStatus The previous status. If not defined, there is no previous status.
*/ */
protected showStatus(status: string, previousStatus?: string): void { protected showStatus(status: TDownloadStatus, previousStatus?: TDownloadStatus): void {
this.showStatusSpinner = status == CoreConstants.DOWNLOADING; this.showStatusSpinner = status === DownloadStatus.DOWNLOADING;
if (status == CoreConstants.DOWNLOADED && previousStatus == CoreConstants.DOWNLOADING) { if (status === DownloadStatus.DOWNLOADED && previousStatus === DownloadStatus.DOWNLOADING) {
// Quiz downloaded now, maybe a new attempt was created. Load content again. // Quiz downloaded now, maybe a new attempt was created. Load content again.
this.showLoadingAndFetch(); this.showLoadingAndFetch();
} }

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { isSafeNumber } from '@/core/utils/types'; import { isSafeNumber } from '@/core/utils/types';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
@ -604,7 +604,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
// Check the current status of the quiz. // Check the current status of the quiz.
const status = await CoreFilepool.getPackageStatus(options.siteId, this.component, quiz.coursemodule); const status = await CoreFilepool.getPackageStatus(options.siteId, this.component, quiz.coursemodule);
if (status === CoreConstants.NOT_DOWNLOADED) { if (status === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
return; return;
} }
@ -612,7 +612,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
// If no attempts or last is finished we'll mark it as not downloaded to show download icon. // If no attempts or last is finished we'll mark it as not downloaded to show download icon.
const lastAttempt = attempts[attempts.length - 1]; const lastAttempt = attempts[attempts.length - 1];
const isLastFinished = !lastAttempt || AddonModQuiz.isAttemptFinished(lastAttempt.state); const isLastFinished = !lastAttempt || AddonModQuiz.isAttemptFinished(lastAttempt.state);
const newStatus = isLastFinished ? CoreConstants.NOT_DOWNLOADED : CoreConstants.DOWNLOADED; const newStatus = isLastFinished ? DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED : DownloadStatus.DOWNLOADED;
await CoreFilepool.storePackageStatus(options.siteId, newStatus, this.component, quiz.coursemodule); await CoreFilepool.storePackageStatus(options.siteId, newStatus, this.component, quiz.coursemodule);
} }

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { Component, OnDestroy, OnInit, Optional } from '@angular/core'; import { Component, OnDestroy, OnInit, Optional } from '@angular/core';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreCourseModuleMainResourceComponent } from '@features/course/classes/main-resource-component'; import { CoreCourseModuleMainResourceComponent } from '@features/course/classes/main-resource-component';
@ -66,7 +66,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
timecreated = -1; timecreated = -1;
timemodified = -1; timemodified = -1;
isExternalFile = false; isExternalFile = false;
outdatedStatus = CoreConstants.OUTDATED; outdatedStatus = DownloadStatus.OUTDATED;
protected onlineObserver?: Subscription; protected onlineObserver?: Subscription;
@ -211,7 +211,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
downloadable = await AddonModResourceHelper.isMainFileDownloadable(this.module); downloadable = await AddonModResourceHelper.isMainFileDownloadable(this.module);
if (downloadable) { if (downloadable) {
if (this.currentStatus === CoreConstants.OUTDATED && !this.isOnline && !this.isExternalFile) { if (this.currentStatus === DownloadStatus.OUTDATED && !this.isOnline && !this.isExternalFile) {
// Warn the user that the file isn't updated. // Warn the user that the file isn't updated.
const alert = await CoreDomUtils.showAlert( const alert = await CoreDomUtils.showAlert(
undefined, undefined,

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants, ModPurpose } from '@/core/constants'; import { CoreConstants, DownloadStatus, ModPurpose } from '@/core/constants';
import { Injectable, Type } from '@angular/core'; import { Injectable, Type } from '@angular/core';
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler'; import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
import { CoreCourse } from '@features/course/services/course'; import { CoreCourse } from '@features/course/services/course';
@ -76,7 +76,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
return; return;
} }
handlerData.button.hidden = status !== CoreConstants.DOWNLOADED || handlerData.button.hidden = status !== DownloadStatus.DOWNLOADED ||
AddonModResourceHelper.isDisplayedInIframe(module); AddonModResourceHelper.isDisplayedInIframe(module);
}; };
handlerData.button = { handlerData.button = {
@ -124,7 +124,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(module, module.course); const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(module, module.course);
return status !== CoreConstants.DOWNLOADED || AddonModResourceHelper.isDisplayedInIframe(module); return status !== DownloadStatus.DOWNLOADED || AddonModResourceHelper.isDisplayedInIframe(module);
} }
/** /**

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler'; import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/resource-prefetch-handler';
import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course';
@ -36,18 +36,18 @@ export class AddonModResourcePrefetchHandlerService extends CoreCourseResourcePr
/** /**
* @inheritdoc * @inheritdoc
*/ */
determineStatus(module: CoreCourseAnyModuleData, status: string): string { determineStatus(module: CoreCourseAnyModuleData, status: TDownloadStatus): TDownloadStatus {
if (status == CoreConstants.DOWNLOADED && module) { if (status === DownloadStatus.DOWNLOADED && module) {
// If the main file is an external file, always display the module as outdated. // If the main file is an external file, always display the module as outdated.
if ('contentsinfo' in module && module.contentsinfo) { if ('contentsinfo' in module && module.contentsinfo) {
if (module.contentsinfo.repositorytype) { if (module.contentsinfo.repositorytype) {
// It's an external file. // It's an external file.
return CoreConstants.OUTDATED; return DownloadStatus.OUTDATED;
} }
} else if (module.contents) { } else if (module.contents) {
const mainFile = module.contents[0]; const mainFile = module.contents[0];
if (mainFile && mainFile.isexternalfile) { if (mainFile && mainFile.isexternalfile) {
return CoreConstants.OUTDATED; return DownloadStatus.OUTDATED;
} }
} }
} }

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { Component, Input, OnInit, Optional } from '@angular/core'; import { Component, Input, OnInit, Optional } from '@angular/core';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component'; import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component';
@ -495,10 +495,10 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom
return; return;
} }
const isOutdated = this.currentStatus === CoreConstants.OUTDATED; const isOutdated = this.currentStatus === DownloadStatus.OUTDATED;
const scorm = this.scorm; const scorm = this.scorm;
if (!isOutdated && this.currentStatus !== CoreConstants.NOT_DOWNLOADED) { if (!isOutdated && this.currentStatus !== DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
// Already downloaded, open it. // Already downloaded, open it.
this.openScorm(scoId, preview); this.openScorm(scoId, preview);
@ -578,16 +578,16 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected async showStatus(status: string): Promise<void> { protected async showStatus(status: TDownloadStatus): Promise<void> {
if (status === CoreConstants.OUTDATED && this.scorm) { if (status === DownloadStatus.OUTDATED && this.scorm) {
// Only show the outdated message if the file should be downloaded. // Only show the outdated message if the file should be downloaded.
const download = await AddonModScorm.shouldDownloadMainFile(this.scorm, true); const download = await AddonModScorm.shouldDownloadMainFile(this.scorm, true);
this.statusMessage = download ? 'addon.mod_scorm.scormstatusoutdated' : ''; this.statusMessage = download ? 'addon.mod_scorm.scormstatusoutdated' : '';
} else if (status === CoreConstants.NOT_DOWNLOADED) { } else if (status === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
this.statusMessage = 'addon.mod_scorm.scormstatusnotdownloaded'; this.statusMessage = 'addon.mod_scorm.scormstatusnotdownloaded';
} else if (status === CoreConstants.DOWNLOADING) { } else if (status === DownloadStatus.DOWNLOADING) {
if (!this.downloading) { if (!this.downloading) {
// It's being downloaded right now but the view isn't tracking it. "Restore" the download. // It's being downloaded right now but the view isn't tracking it. "Restore" the download.
this.downloadScormPackage(); this.downloadScormPackage();

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreSite } from '@classes/sites/site'; import { CoreSite } from '@classes/sites/site';
@ -1669,8 +1669,8 @@ export class AddonModScormProvider {
return false; return false;
} }
const isOutdated = data.status == CoreConstants.OUTDATED || const isOutdated = data.status === DownloadStatus.OUTDATED ||
(data.status == CoreConstants.DOWNLOADING && data.previous == CoreConstants.OUTDATED); (data.status === DownloadStatus.DOWNLOADING && data.previous === DownloadStatus.OUTDATED);
// Package needs to be downloaded if it's not outdated (not downloaded) or if the hash has changed. // Package needs to be downloaded if it's not outdated (not downloaded) or if the hash has changed.
return !isOutdated || data.extra != scorm.sha1hash; return !isOutdated || data.extra != scorm.sha1hash;

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site'; import { CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
@ -124,7 +124,7 @@ export class AddonRemoteThemesHandlerService implements CoreStyleHandler {
// Check if the file is downloaded. // Check if the file is downloaded.
const state = await CoreFilepool.getFileStateByUrl(siteId, url); const state = await CoreFilepool.getFileStateByUrl(siteId, url);
if (state == CoreConstants.NOT_DOWNLOADED) { if (state === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
// File not downloaded, URL has changed or first time. Delete downloaded CSS files. // File not downloaded, URL has changed or first time. Delete downloaded CSS files.
await CoreFilepool.removeFilesByComponent(siteId, COMPONENT, 1); await CoreFilepool.removeFilesByComponent(siteId, COMPONENT, 1);
} }

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { CoreConstants, DownloadStatus, TDownloadStatus } from '@/core/constants';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit } from '@angular/core'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit } from '@angular/core';
import { CoreCourse, CoreCourseProvider } from '@features/course/services/course'; import { CoreCourse, CoreCourseProvider } from '@features/course/services/course';
import { import {
@ -58,11 +58,11 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
prefetchCourseData: CorePrefetchStatusInfo = { prefetchCourseData: CorePrefetchStatusInfo = {
icon: CoreConstants.ICON_LOADING, icon: CoreConstants.ICON_LOADING,
statusTranslatable: 'core.course.downloadcourse', statusTranslatable: 'core.course.downloadcourse',
status: '', status: DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED,
loading: true, loading: true,
}; };
statusDownloaded = CoreConstants.DOWNLOADED; statusDownloaded = DownloadStatus.DOWNLOADED;
protected initialSectionId?: number; protected initialSectionId?: number;
protected siteUpdatedObserver?: CoreEventObserver; protected siteUpdatedObserver?: CoreEventObserver;
@ -511,7 +511,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
// We are currently marking as not downloaded if size is 0 but we should take into account that // We are currently marking as not downloaded if size is 0 but we should take into account that
// resources without files can be downloaded and cached. // resources without files can be downloaded and cached.
CoreCourse.setCourseStatus(this.courseId, CoreConstants.NOT_DOWNLOADED); CoreCourse.setCourseStatus(this.courseId, DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED);
} }
/** /**
@ -607,7 +607,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
* @param module Module to update. * @param module Module to update.
* @param status Module status. * @param status Module status.
*/ */
protected updateModuleStatus(module: AddonStorageManagerModule, status: string): void { protected updateModuleStatus(module: AddonStorageManagerModule, status: TDownloadStatus): void {
if (!status) { if (!status) {
return; return;
} }
@ -649,7 +649,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
* *
* @param status Status to show. * @param status Status to show.
*/ */
protected updateCourseStatus(status: string): void { protected updateCourseStatus(status: TDownloadStatus): void {
const statusData = CoreCourseHelper.getCoursePrefetchStatusInfo(status); const statusData = CoreCourseHelper.getCoursePrefetchStatusInfo(status);
this.prefetchCourseData.status = statusData.status; this.prefetchCourseData.status = statusData.status;
@ -758,5 +758,5 @@ type AddonStorageManagerModule = CoreCourseModuleData & {
calculatingSize: boolean; calculatingSize: boolean;
prefetchHandler?: CoreCourseModulePrefetchHandler; prefetchHandler?: CoreCourseModulePrefetchHandler;
spinner?: boolean; spinner?: boolean;
downloadStatus?: string; downloadStatus?: TDownloadStatus;
}; };

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { Component, OnDestroy, OnInit } from '@angular/core'; import { Component, OnDestroy, OnInit } from '@angular/core';
import { CoreCourse, CoreCourseProvider } from '@features/course/services/course'; import { CoreCourse, CoreCourseProvider } from '@features/course/services/course';
import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseHelper } from '@features/course/services/course-helper';
@ -82,7 +82,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
id: siteHomeId, id: siteHomeId,
title: Translate.instant('core.sitehome.sitehome'), title: Translate.instant('core.sitehome.sitehome'),
totalSize: size, totalSize: size,
isDownloading: status === CoreConstants.DOWNLOADING, isDownloading: status === DownloadStatus.DOWNLOADING,
}); });
} }
} }
@ -175,7 +175,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
* *
* @param courseId Updated course id. * @param courseId Updated course id.
*/ */
private async onCourseUpdated(courseId: number, status: string): Promise<void> { private async onCourseUpdated(courseId: number, status: TDownloadStatus): Promise<void> {
if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) {
this.setDownloadedCourses([]); this.setDownloadedCourses([]);
@ -188,7 +188,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
return; return;
} }
course.isDownloading = status === CoreConstants.DOWNLOADING; course.isDownloading = status === DownloadStatus.DOWNLOADING;
course.totalSize = await this.calculateDownloadedCourseSize(course.id); course.totalSize = await this.calculateDownloadedCourseSize(course.id);
this.setDownloadedCourses(this.downloadedCourses); this.setDownloadedCourses(this.downloadedCourses);
@ -219,7 +219,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy
id: course.id, id: course.id,
title: course.displayname || course.fullname, title: course.displayname || course.fullname,
totalSize, totalSize,
isDownloading: status === CoreConstants.DOWNLOADING, isDownloading: status === DownloadStatus.DOWNLOADING,
}; };
} }

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Component, Input, Output, EventEmitter } from '@angular/core'; import { Component, Input, Output, EventEmitter } from '@angular/core';
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { CoreAnimations } from '@components/animations'; import { CoreAnimations } from '@components/animations';
/** /**
@ -31,17 +31,17 @@ import { CoreAnimations } from '@components/animations';
}) })
export class CoreDownloadRefreshComponent { export class CoreDownloadRefreshComponent {
@Input() status?: string; // Download status. @Input() status?: TDownloadStatus; // Download status.
@Input() statusTranslatable?: string; // Download status translatable string. @Input() statusTranslatable?: string; // Download status translatable string.
@Input() enabled = false; // Whether the download is enabled. @Input() enabled = false; // Whether the download is enabled.
@Input() loading = true; // Force loading status when is not downloading. @Input() loading = true; // Force loading status when is not downloading.
@Input() canTrustDownload = false; // If false, refresh will be shown if downloaded. @Input() canTrustDownload = false; // If false, refresh will be shown if downloaded.
@Output() action: EventEmitter<boolean>; // Will emit an event when the item clicked. @Output() action: EventEmitter<boolean>; // Will emit an event when the item clicked.
statusDownloaded = CoreConstants.DOWNLOADED; statusDownloaded = DownloadStatus.DOWNLOADED;
statusNotDownloaded = CoreConstants.NOT_DOWNLOADED; statusNotDownloaded = DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
statusOutdated = CoreConstants.OUTDATED; statusOutdated = DownloadStatus.OUTDATED;
statusDownloading = CoreConstants.DOWNLOADING; statusDownloading = DownloadStatus.DOWNLOADING;
constructor() { constructor() {
this.action = new EventEmitter(); this.action = new EventEmitter();

View File

@ -23,7 +23,7 @@ import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils, CoreUtilsOpenFileOptions, OpenFileAction } from '@services/utils/utils'; import { CoreUtils, CoreUtilsOpenFileOptions, OpenFileAction } from '@services/utils/utils';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreWSFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { CorePlatform } from '@services/platform'; import { CorePlatform } from '@services/platform';
@ -53,7 +53,7 @@ export class CoreFileComponent implements OnInit, OnDestroy {
fileIcon?: string; fileIcon?: string;
fileName!: string; fileName!: string;
fileSizeReadable?: string; fileSizeReadable?: string;
state?: string; state?: TDownloadStatus;
timemodified!: number; timemodified!: number;
isIOS = false; isIOS = false;
openButtonIcon = ''; openButtonIcon = '';
@ -138,7 +138,7 @@ export class CoreFileComponent implements OnInit, OnDestroy {
this.canDownload = site.canDownloadFiles(); this.canDownload = site.canDownloadFiles();
this.state = state; this.state = state;
this.isDownloading = this.canDownload && state === CoreConstants.DOWNLOADING; this.isDownloading = this.canDownload && state === DownloadStatus.DOWNLOADING;
this.isDownloaded = this.canDownload && CoreFileHelper.isStateDownloaded(state); this.isDownloaded = this.canDownload && CoreFileHelper.isStateDownloaded(state);
} }
@ -193,7 +193,7 @@ export class CoreFileComponent implements OnInit, OnDestroy {
return; return;
} }
if (!this.canDownload || !this.state || this.state == CoreConstants.NOT_DOWNLOADABLE) { if (!this.canDownload || !this.state || this.state === DownloadStatus.NOT_DOWNLOADABLE) {
// File cannot be downloaded, just open it. // File cannot be downloaded, just open it.
if (CoreUrlUtils.isLocalFileUrl(this.fileUrl)) { if (CoreUrlUtils.isLocalFileUrl(this.fileUrl)) {
CoreUtils.openFile(this.fileUrl); CoreUtils.openFile(this.fileUrl);

View File

@ -46,6 +46,38 @@ export const enum ModPurpose {
MOD_PURPOSE_OTHER = 'other', MOD_PURPOSE_OTHER = 'other',
} }
/* eslint-disable @typescript-eslint/naming-convention */
/**
* Possible statuses for downloaded modules/files.
*/
export const DownloadedStatus = {
DOWNLOADED: 'downloaded',
DOWNLOADING: 'downloading',
OUTDATED: 'outdated',
} as const;
/**
* Possible statuses for not downloaded modules/files.
*/
export const NotDownloadedStatus = {
DOWNLOADABLE_NOT_DOWNLOADED: 'notdownloaded',
NOT_DOWNLOADABLE: 'notdownloadable',
} as const;
/**
* Possible statuses for modules regarding download.
*/
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 */
/** /**
* Static class to contain all the core constants. * Static class to contain all the core constants.
*/ */
@ -99,11 +131,26 @@ export class CoreConstants {
static readonly LOGIN_LAUNCH_DATA = 'CoreLoginLaunchData'; static readonly LOGIN_LAUNCH_DATA = 'CoreLoginLaunchData';
// Download status constants. // Download status constants.
static readonly DOWNLOADED = 'downloaded'; /**
static readonly DOWNLOADING = 'downloading'; * @deprecated since 4.4. Use DownloadStatus.DOWNLOADED instead.
static readonly NOT_DOWNLOADED = 'notdownloaded'; */
static readonly OUTDATED = 'outdated'; static readonly DOWNLOADED = DownloadStatus.DOWNLOADED;
static readonly NOT_DOWNLOADABLE = 'notdownloadable'; /**
* @deprecated since 4.4. Use DownloadStatus.DOWNLOADING instead.
*/
static readonly DOWNLOADING = DownloadStatus.DOWNLOADING;
/**
* @deprecated since 4.4. Use DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED instead.
*/
static readonly NOT_DOWNLOADED = DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
/**
* @deprecated since 4.4. Use DownloadStatus.OUTDATED instead.
*/
static readonly OUTDATED = DownloadStatus.OUTDATED;
/**
* @deprecated since 4.4. Use DownloadStatus.NOT_DOWNLOADABLE instead.
*/
static readonly NOT_DOWNLOADABLE = DownloadStatus.NOT_DOWNLOADABLE;
// Download / prefetch status icon. // Download / prefetch status icon.
static readonly ICON_DOWNLOADED = 'fam-cloud-done'; static readonly ICON_DOWNLOADED = 'fam-cloud-done';

View File

@ -32,7 +32,7 @@ import { CoreLogger } from '@singletons/logger';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreSite } from '@classes/sites/site'; import { CoreSite } from '@classes/sites/site';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreConstants } from '../constants'; import { DownloadStatus } from '../constants';
import { CoreNetwork } from '@services/network'; import { CoreNetwork } from '@services/network';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { AsyncDirective } from '@classes/async-directive'; import { AsyncDirective } from '@classes/async-directive';
@ -418,7 +418,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
} }
state = newState; state = newState;
if (state === CoreConstants.DOWNLOADING) { if (state === DownloadStatus.DOWNLOADING) {
return; return;
} }
@ -442,7 +442,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
clickableEl.addEventListener(eventName, () => { clickableEl.addEventListener(eventName, () => {
// User played media or opened a downloadable link. // User played media or opened a downloadable link.
// Download the file if in wifi and it hasn't been downloaded already (for big files). // Download the file if in wifi and it hasn't been downloaded already (for big files).
if (state !== CoreConstants.DOWNLOADED && state !== CoreConstants.DOWNLOADING && CoreNetwork.isWifi()) { if (state !== DownloadStatus.DOWNLOADED && state !== DownloadStatus.DOWNLOADING && CoreNetwork.isWifi()) {
// We aren't using the result, so it doesn't matter which of the 2 functions we call. // We aren't using the result, so it doesn't matter which of the 2 functions we call.
CoreFilepool.getUrlByUrl(site.getId(), url, this.component, this.componentId, 0, false); CoreFilepool.getUrlByUrl(site.getId(), url, this.component, this.componentId, 0, false);
} }

View File

@ -71,7 +71,7 @@ import { getXAPIServices } from '@features/xapi/xapi.module';
import { DomSanitizer } from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';
import { FormBuilder, Validators } from '@angular/forms'; import { FormBuilder, Validators } from '@angular/forms';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { CoreConstants } from '@/core/constants'; import { CoreConstants, DownloadStatus } from '@/core/constants';
import moment from 'moment-timezone'; import moment from 'moment-timezone';
import { Md5 } from 'ts-md5/dist/md5'; import { Md5 } from 'ts-md5/dist/md5';
@ -305,6 +305,7 @@ export class CoreCompileProvider {
instance['injector'] = this.injector; instance['injector'] = this.injector;
instance['Validators'] = Validators; instance['Validators'] = Validators;
instance['CoreConstants'] = CoreConstants; instance['CoreConstants'] = CoreConstants;
instance['DownloadStatus'] = DownloadStatus;
instance['CoreConfigConstants'] = CoreConstants.CONFIG; instance['CoreConfigConstants'] = CoreConstants.CONFIG;
instance['CoreEventsProvider'] = CoreEvents; instance['CoreEventsProvider'] = CoreEvents;
instance['CoreLoggerProvider'] = CoreLogger; instance['CoreLoggerProvider'] = CoreLogger;

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreFilterHelper } from '@features/filter/services/filter-helper'; import { CoreFilterHelper } from '@features/filter/services/filter-helper';
import { CoreNetwork } from '@services/network'; import { CoreNetwork } from '@services/network';
@ -150,7 +150,7 @@ export class CoreCourseActivityPrefetchHandlerBase extends CoreCourseModulePrefe
setDownloaded(id: number, siteId?: string, extra?: string): Promise<void> { setDownloaded(id: number, siteId?: string, extra?: string): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
return CoreFilepool.storePackageStatus(siteId, CoreConstants.DOWNLOADED, this.component, id, extra); return CoreFilepool.storePackageStatus(siteId, DownloadStatus.DOWNLOADED, this.component, id, extra);
} }
/** /**
@ -163,7 +163,7 @@ export class CoreCourseActivityPrefetchHandlerBase extends CoreCourseModulePrefe
setDownloading(id: number, siteId?: string): Promise<void> { setDownloading(id: number, siteId?: string): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
return CoreFilepool.storePackageStatus(siteId, CoreConstants.DOWNLOADING, this.component, id); return CoreFilepool.storePackageStatus(siteId, DownloadStatus.DOWNLOADING, this.component, id);
} }
/** /**

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { OnInit, OnDestroy, Input, Output, EventEmitter, Component, Optional, Inject } from '@angular/core'; import { OnInit, OnDestroy, Input, Output, EventEmitter, Component, Optional, Inject } from '@angular/core';
import { CoreAnyError } from '@classes/errors/error'; import { CoreAnyError } from '@classes/errors/error';
import { CoreNetwork } from '@services/network'; 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 isCurrentView = false; // Whether the component is in the current view.
protected siteId?: string; // Current Site ID. protected siteId?: string; // Current Site ID.
protected statusObserver?: CoreEventObserver; // Observer of package status. Only if setStatusListener is called. protected statusObserver?: CoreEventObserver; // Observer of package status. Only if setStatusListener is called.
currentStatus?: string; // The current status of the module. Only if setStatusListener is called. currentStatus?: TDownloadStatus; // 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. downloadTimeReadable?: string; // Last download time in a readable format. Only if setStatusListener is called.
protected completionObserver?: CoreEventObserver; protected completionObserver?: CoreEventObserver;
@ -242,7 +242,8 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
* @returns If module has been prefetched. * @returns If module has been prefetched.
*/ */
protected isPrefetched(): boolean { protected isPrefetched(): boolean {
return this.currentStatus != CoreConstants.NOT_DOWNLOADABLE && this.currentStatus != CoreConstants.NOT_DOWNLOADED; return this.currentStatus !== DownloadStatus.NOT_DOWNLOADABLE &&
this.currentStatus !== DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
} }
/** /**
@ -281,7 +282,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
* @param previousStatus The previous status. If not defined, there is no previous status. * @param previousStatus The previous status. If not defined, there is no previous status.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
protected showStatus(status: string, previousStatus?: string): void { protected showStatus(status: TDownloadStatus, previousStatus?: TDownloadStatus): void {
// To be overridden. // To be overridden.
} }
@ -345,7 +346,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
// Get module status to determine if it needs to be downloaded. // Get module status to determine if it needs to be downloaded.
await this.setStatusListener(refresh); await this.setStatusListener(refresh);
if (this.currentStatus != CoreConstants.DOWNLOADED) { if (this.currentStatus !== DownloadStatus.DOWNLOADED) {
// Download content. This function also loads module contents if needed. // Download content. This function also loads module contents if needed.
try { try {
await CoreCourseModulePrefetchDelegate.downloadModule(this.module, this.courseId); await CoreCourseModulePrefetchDelegate.downloadModule(this.module, this.courseId);

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { CoreConstants, DownloadStatus } from '@/core/constants';
import { AddonBlog } from '@addons/blog/services/blog'; import { AddonBlog } from '@addons/blog/services/blog';
import { AddonBlogMainMenuHandlerService } from '@addons/blog/services/handlers/mainmenu'; import { AddonBlogMainMenuHandlerService } from '@addons/blog/services/handlers/mainmenu';
import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import { Component, Input, OnDestroy, OnInit } from '@angular/core';
@ -216,15 +216,15 @@ export class CoreCourseModuleSummaryComponent implements OnInit, OnDestroy {
const moduleInfo = const moduleInfo =
await CoreCourseHelper.getModulePrefetchInfo(this.module, this.courseId, refresh, this.component); await CoreCourseHelper.getModulePrefetchInfo(this.module, this.courseId, refresh, this.component);
this.canPrefetch = moduleInfo.status != CoreConstants.NOT_DOWNLOADABLE; this.canPrefetch = moduleInfo.status !== DownloadStatus.NOT_DOWNLOADABLE;
this.downloadTimeReadable = ''; this.downloadTimeReadable = '';
if (this.canPrefetch) { if (this.canPrefetch) {
if (moduleInfo.downloadTime && moduleInfo.downloadTime > 0) { if (moduleInfo.downloadTime && moduleInfo.downloadTime > 0) {
this.downloadTimeReadable = CoreTextUtils.ucFirst(moduleInfo.downloadTimeReadable); this.downloadTimeReadable = CoreTextUtils.ucFirst(moduleInfo.downloadTimeReadable);
} }
this.prefetchLoading = moduleInfo.status == CoreConstants.DOWNLOADING; this.prefetchLoading = moduleInfo.status === DownloadStatus.DOWNLOADING;
this.prefetchDisabled = moduleInfo.status == CoreConstants.DOWNLOADED; this.prefetchDisabled = moduleInfo.status === DownloadStatus.DOWNLOADED;
} }
if (moduleInfo.size && moduleInfo.size > 0) { if (moduleInfo.size && moduleInfo.size > 0) {

View File

@ -27,7 +27,7 @@ import {
CoreCourseModulePrefetchDelegate, CoreCourseModulePrefetchDelegate,
CoreCourseModulePrefetchHandler, CoreCourseModulePrefetchHandler,
} from '@features/course/services/module-prefetch-delegate'; } from '@features/course/services/module-prefetch-delegate';
import { CoreConstants } from '@/core/constants'; import { CoreConstants, DownloadStatus, TDownloadStatus } from '@/core/constants';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
@ -115,7 +115,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
} }
if (this.showDownloadStatus && this.module.handlerData.showDownloadButton) { if (this.showDownloadStatus && this.module.handlerData.showDownloadButton) {
const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(this.module, this.module.course); const status = await CoreCourseModulePrefetchDelegate.getDownloadedModuleStatus(this.module, this.module.course);
this.updateModuleStatus(status); this.updateModuleStatus(status);
// Listen for changes on this module status, even if download isn't enabled. // Listen for changes on this module status, even if download isn't enabled.
@ -144,19 +144,19 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
/** /**
* Show module status. * Show module status.
* *
* @param prefetchstatus Module status. * @param prefetchStatus Module status.
*/ */
protected updateModuleStatus(prefetchstatus: string): void { protected updateModuleStatus(prefetchStatus: TDownloadStatus | null): void {
if (!prefetchstatus) { if (!prefetchStatus) {
return; return;
} }
switch (prefetchstatus) { switch (prefetchStatus) {
case CoreConstants.OUTDATED: case DownloadStatus.OUTDATED:
this.prefetchStatusIcon$.next(CoreConstants.ICON_OUTDATED); this.prefetchStatusIcon$.next(CoreConstants.ICON_OUTDATED);
this.prefetchStatusText$.next('core.outdated'); this.prefetchStatusText$.next('core.outdated');
break; break;
case CoreConstants.DOWNLOADED: case DownloadStatus.DOWNLOADED:
this.prefetchStatusIcon$.next(CoreConstants.ICON_DOWNLOADED); this.prefetchStatusIcon$.next(CoreConstants.ICON_DOWNLOADED);
this.prefetchStatusText$.next('core.downloaded'); this.prefetchStatusText$.next('core.downloaded');
break; break;
@ -166,7 +166,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
break; break;
} }
this.module.handlerData?.updateStatus?.(prefetchstatus); this.module.handlerData?.updateStatus?.(prefetchStatus);
} }
/** /**

View File

@ -28,7 +28,7 @@ import {
CoreCourseModuleCompletionStatus, CoreCourseModuleCompletionStatus,
CoreCourseGetContentsWSModule, CoreCourseGetContentsWSModule,
} from './course'; } from './course';
import { CoreConstants } from '@/core/constants'; import { CoreConstants, DownloadStatus, TDownloadStatus } from '@/core/constants';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { ApplicationInit, makeSingleton, Translate } from '@singletons'; import { ApplicationInit, makeSingleton, Translate } from '@singletons';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
@ -82,7 +82,7 @@ import { LazyRoutesModule } from '@/app/app-routing.module';
export type CoreCourseModulePrefetchInfo = CoreCourseModulePackageLastDownloaded & { export type CoreCourseModulePrefetchInfo = CoreCourseModulePackageLastDownloaded & {
size: number; // Downloaded size. size: number; // Downloaded size.
sizeReadable: string; // Downloadable size in a readable format. sizeReadable: string; // Downloadable size in a readable format.
status: string; // Module status. status: TDownloadStatus; // Module status.
statusIcon?: string; // Icon's name of the module status. statusIcon?: string; // Icon's name of the module status.
}; };
@ -120,7 +120,7 @@ export type CoreCourseCoursesProgress = {
}; };
export type CorePrefetchStatusInfo = { export type CorePrefetchStatusInfo = {
status: string; // Status of the prefetch. status: TDownloadStatus; // Status of the prefetch.
statusTranslatable: string; // Status translatable string. statusTranslatable: string; // Status translatable string.
icon: string; // Icon based on the status. icon: string; // Icon based on the status.
loading: boolean; // If it's a loading status. loading: boolean; // If it's a loading status.
@ -291,13 +291,13 @@ export class CoreCourseHelperProvider {
// Check if it's being downloaded. // Check if it's being downloaded.
const downloadId = this.getSectionDownloadId(section); const downloadId = this.getSectionDownloadId(section);
if (CoreCourseModulePrefetchDelegate.isBeingDownloaded(downloadId)) { if (CoreCourseModulePrefetchDelegate.isBeingDownloaded(downloadId)) {
result.status = CoreConstants.DOWNLOADING; result.status = DownloadStatus.DOWNLOADING;
} }
sectionWithStatus.downloadStatus = result.status; sectionWithStatus.downloadStatus = result.status;
// Set this section data. // Set this section data.
if (result.status !== CoreConstants.DOWNLOADING) { if (result.status !== DownloadStatus.DOWNLOADING) {
sectionWithStatus.isDownloading = false; sectionWithStatus.isDownloading = false;
sectionWithStatus.total = 0; sectionWithStatus.total = 0;
} else { } else {
@ -328,7 +328,7 @@ export class CoreCourseHelperProvider {
checkUpdates: boolean = true, checkUpdates: boolean = true,
): Promise<CoreCourseSectionWithStatus[]> { ): Promise<CoreCourseSectionWithStatus[]> {
let allSectionsSection: CoreCourseSectionWithStatus | undefined; let allSectionsSection: CoreCourseSectionWithStatus | undefined;
let allSectionsStatus = CoreConstants.NOT_DOWNLOADABLE; let allSectionsStatus = DownloadStatus.NOT_DOWNLOADABLE as TDownloadStatus;
const promises = sections.map(async (section: CoreCourseSectionWithStatus) => { const promises = sections.map(async (section: CoreCourseSectionWithStatus) => {
section.isCalculating = true; section.isCalculating = true;
@ -356,7 +356,7 @@ export class CoreCourseHelperProvider {
if (allSectionsSection) { if (allSectionsSection) {
// Set "All sections" data. // Set "All sections" data.
allSectionsSection.downloadStatus = allSectionsStatus; allSectionsSection.downloadStatus = allSectionsStatus;
allSectionsSection.isDownloading = allSectionsStatus === CoreConstants.DOWNLOADING; allSectionsSection.isDownloading = allSectionsStatus === DownloadStatus.DOWNLOADING;
} }
return sections; return sections;
@ -389,7 +389,7 @@ export class CoreCourseHelperProvider {
data.downloadSucceeded = false; data.downloadSucceeded = false;
data.icon = CoreConstants.ICON_DOWNLOADING; data.icon = CoreConstants.ICON_DOWNLOADING;
data.status = CoreConstants.DOWNLOADING; data.status = DownloadStatus.DOWNLOADING;
data.loading = true; data.loading = true;
data.statusTranslatable = 'core.downloading'; data.statusTranslatable = 'core.downloading';
@ -632,9 +632,9 @@ export class CoreCourseHelperProvider {
* @param courses Courses * @param courses Courses
* @returns Promise resolved with the status. * @returns Promise resolved with the status.
*/ */
async determineCoursesStatus(courses: CoreCourseBasicData[]): Promise<string> { async determineCoursesStatus(courses: CoreCourseBasicData[]): Promise<TDownloadStatus> {
// Get the status of each course. // Get the status of each course.
const promises: Promise<string>[] = []; const promises: Promise<TDownloadStatus>[] = [];
const siteId = CoreSites.getCurrentSiteId(); const siteId = CoreSites.getCurrentSiteId();
courses.forEach((course) => { courses.forEach((course) => {
@ -724,12 +724,12 @@ export class CoreCourseHelperProvider {
// Error opening the file, some apps don't allow opening online files. // Error opening the file, some apps don't allow opening online files.
if (!CoreFile.isAvailable()) { if (!CoreFile.isAvailable()) {
throw error; throw error;
} else if (result.status === CoreConstants.DOWNLOADING) { } else if (result.status === DownloadStatus.DOWNLOADING) {
throw new CoreError(Translate.instant('core.erroropenfiledownloading')); throw new CoreError(Translate.instant('core.erroropenfiledownloading'));
} }
let path: string | undefined; let path: string | undefined;
if (result.status === CoreConstants.NOT_DOWNLOADED) { if (result.status === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
// Not downloaded, download it now and return the local file. // Not downloaded, download it now and return the local file.
await this.downloadModule(module, courseId, component, componentId, files, siteId); await this.downloadModule(module, courseId, component, componentId, files, siteId);
@ -817,7 +817,7 @@ export class CoreCourseHelperProvider {
files?: CoreCourseModuleContentFile[], files?: CoreCourseModuleContentFile[],
siteId?: string, siteId?: string,
options: CoreUtilsOpenFileOptions = {}, options: CoreUtilsOpenFileOptions = {},
): Promise<{ fixedUrl: string; path: string; status?: string }> { ): Promise<{ fixedUrl: string; path: string; status?: TDownloadStatus }> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
@ -843,16 +843,16 @@ export class CoreCourseHelperProvider {
let path = ''; let path = '';
if (status === CoreConstants.DOWNLOADING) { if (status === DownloadStatus.DOWNLOADING) {
// Use the online URL. // Use the online URL.
path = fixedUrl; path = fixedUrl;
} else if (status === CoreConstants.DOWNLOADED) { } else if (status === DownloadStatus.DOWNLOADED) {
try { try {
// Get the local file URL. // Get the local file URL.
path = await CoreFilepool.getInternalUrlByUrl(siteId, mainFile.fileurl); path = await CoreFilepool.getInternalUrlByUrl(siteId, mainFile.fileurl);
} catch (error){ } catch (error){
// File not found, mark the module as not downloaded. // File not found, mark the module as not downloaded.
await CoreFilepool.storePackageStatus(siteId, CoreConstants.NOT_DOWNLOADED, component, componentId); await CoreFilepool.storePackageStatus(siteId, DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED, component, componentId);
} }
} }
@ -870,7 +870,7 @@ export class CoreCourseHelperProvider {
options, options,
); );
} catch (error) { } catch (error) {
if (status !== CoreConstants.OUTDATED) { if (status !== DownloadStatus.OUTDATED) {
throw error; throw error;
} }
@ -910,7 +910,7 @@ export class CoreCourseHelperProvider {
courseId: number, courseId: number,
fixedUrl: string, fixedUrl: string,
files: CoreCourseModuleContentFile[], files: CoreCourseModuleContentFile[],
status: string, status: TDownloadStatus,
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
siteId?: string, siteId?: string,
@ -922,7 +922,7 @@ export class CoreCourseHelperProvider {
const mainFile = files[0]; const mainFile = files[0];
const timemodified = mainFile.timemodified || 0; const timemodified = mainFile.timemodified || 0;
if (!isOnline && status === CoreConstants.NOT_DOWNLOADED) { if (!isOnline && status === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
// Not downloaded and we're offline, reject. // Not downloaded and we're offline, reject.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }
@ -1239,7 +1239,7 @@ export class CoreCourseHelperProvider {
* @param status Course status. * @param status Course status.
* @returns Prefetch status info. * @returns Prefetch status info.
*/ */
getCoursePrefetchStatusInfo(status: string): CorePrefetchStatusInfo { getCoursePrefetchStatusInfo(status: TDownloadStatus): CorePrefetchStatusInfo {
const prefetchStatus: CorePrefetchStatusInfo = { const prefetchStatus: CorePrefetchStatusInfo = {
status: status, status: status,
icon: this.getPrefetchStatusIcon(status, false), icon: this.getPrefetchStatusIcon(status, false),
@ -1247,10 +1247,10 @@ export class CoreCourseHelperProvider {
loading: false, loading: false,
}; };
if (status == CoreConstants.DOWNLOADED) { if (status === DownloadStatus.DOWNLOADED) {
// Always show refresh icon, we cannot know if there's anything new in course options. // Always show refresh icon, we cannot know if there's anything new in course options.
prefetchStatus.statusTranslatable = 'core.course.refreshcourse'; prefetchStatus.statusTranslatable = 'core.course.refreshcourse';
} else if (status == CoreConstants.DOWNLOADING) { } else if (status === DownloadStatus.DOWNLOADING) {
prefetchStatus.statusTranslatable = 'core.downloading'; prefetchStatus.statusTranslatable = 'core.downloading';
prefetchStatus.loading = true; prefetchStatus.loading = true;
} else { } else {
@ -1266,7 +1266,7 @@ export class CoreCourseHelperProvider {
* @param status Courses status. * @param status Courses status.
* @returns Prefetch status info. * @returns Prefetch status info.
*/ */
getCoursesPrefetchStatusInfo(status: string): CorePrefetchStatusInfo { getCoursesPrefetchStatusInfo(status: TDownloadStatus): CorePrefetchStatusInfo {
const prefetchStatus: CorePrefetchStatusInfo = { const prefetchStatus: CorePrefetchStatusInfo = {
status: status, status: status,
icon: this.getPrefetchStatusIcon(status, false), icon: this.getPrefetchStatusIcon(status, false),
@ -1274,10 +1274,10 @@ export class CoreCourseHelperProvider {
loading: false, loading: false,
}; };
if (status == CoreConstants.DOWNLOADED) { if (status === DownloadStatus.DOWNLOADED) {
// Always show refresh icon, we cannot know if there's anything new in course options. // Always show refresh icon, we cannot know if there's anything new in course options.
prefetchStatus.statusTranslatable = 'core.courses.refreshcourses'; prefetchStatus.statusTranslatable = 'core.courses.refreshcourses';
} else if (status == CoreConstants.DOWNLOADING) { } else if (status === DownloadStatus.DOWNLOADING) {
prefetchStatus.statusTranslatable = 'core.downloading'; prefetchStatus.statusTranslatable = 'core.downloading';
prefetchStatus.loading = true; prefetchStatus.loading = true;
} else { } else {
@ -1294,17 +1294,17 @@ export class CoreCourseHelperProvider {
* @param trustDownload True to show download success, false to show an outdated status when downloaded. * @param trustDownload True to show download success, false to show an outdated status when downloaded.
* @returns Icon name. * @returns Icon name.
*/ */
getPrefetchStatusIcon(status: string, trustDownload: boolean = false): string { getPrefetchStatusIcon(status: TDownloadStatus, trustDownload: boolean = false): string {
if (status == CoreConstants.NOT_DOWNLOADED) { if (status === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
return CoreConstants.ICON_NOT_DOWNLOADED; return CoreConstants.ICON_NOT_DOWNLOADED;
} }
if (status == CoreConstants.OUTDATED || (status == CoreConstants.DOWNLOADED && !trustDownload)) { if (status === DownloadStatus.OUTDATED || (status === DownloadStatus.DOWNLOADED && !trustDownload)) {
return CoreConstants.ICON_OUTDATED; return CoreConstants.ICON_OUTDATED;
} }
if (status == CoreConstants.DOWNLOADED && trustDownload) { if (status === DownloadStatus.DOWNLOADED && trustDownload) {
return CoreConstants.ICON_DOWNLOADED; return CoreConstants.ICON_DOWNLOADED;
} }
if (status == CoreConstants.DOWNLOADING) { if (status === DownloadStatus.DOWNLOADING) {
return CoreConstants.ICON_DOWNLOADING; return CoreConstants.ICON_DOWNLOADING;
} }
@ -1348,16 +1348,16 @@ export class CoreCourseHelperProvider {
const status = results[1]; const status = results[1];
let statusIcon: string | undefined; let statusIcon: string | undefined;
switch (results[1]) { switch (results[1]) {
case CoreConstants.NOT_DOWNLOADED: case DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED:
statusIcon = CoreConstants.ICON_NOT_DOWNLOADED; statusIcon = CoreConstants.ICON_NOT_DOWNLOADED;
break; break;
case CoreConstants.DOWNLOADING: case DownloadStatus.DOWNLOADING:
statusIcon = CoreConstants.ICON_DOWNLOADING; statusIcon = CoreConstants.ICON_DOWNLOADING;
break; break;
case CoreConstants.OUTDATED: case DownloadStatus.OUTDATED:
statusIcon = CoreConstants.ICON_OUTDATED; statusIcon = CoreConstants.ICON_OUTDATED;
break; break;
case CoreConstants.DOWNLOADED: case DownloadStatus.DOWNLOADED:
break; break;
default: default:
statusIcon = ''; statusIcon = '';
@ -1391,7 +1391,12 @@ export class CoreCourseHelperProvider {
const packageData = await CoreUtils.ignoreErrors(CoreFilepool.getPackageData(siteId, component, module.id)); const packageData = await CoreUtils.ignoreErrors(CoreFilepool.getPackageData(siteId, component, module.id));
// Treat download time. // Treat download time.
if (!packageData || !packageData.downloadTime || !CoreFileHelper.isStateDownloaded(packageData.status || '')) { if (
!packageData ||
!packageData.downloadTime ||
!packageData.status ||
!CoreFileHelper.isStateDownloaded(packageData.status)
) {
// Not downloaded. // Not downloaded.
return { return {
downloadTime: 0, downloadTime: 0,
@ -1598,7 +1603,7 @@ export class CoreCourseHelperProvider {
// First of all, mark the course as being downloaded. // First of all, mark the course as being downloaded.
this.courseDwnPromises[requiredSiteId][course.id] = CoreCourse.setCourseStatus( this.courseDwnPromises[requiredSiteId][course.id] = CoreCourse.setCourseStatus(
course.id, course.id,
CoreConstants.DOWNLOADING, DownloadStatus.DOWNLOADING,
requiredSiteId, requiredSiteId,
).then(async () => { ).then(async () => {
@ -1636,7 +1641,7 @@ export class CoreCourseHelperProvider {
await CoreUtils.allPromises(promises); await CoreUtils.allPromises(promises);
// Download success, mark the course as downloaded. // Download success, mark the course as downloaded.
return CoreCourse.setCourseStatus(course.id, CoreConstants.DOWNLOADED, requiredSiteId); return CoreCourse.setCourseStatus(course.id, DownloadStatus.DOWNLOADED, requiredSiteId);
}).catch(async (error) => { }).catch(async (error) => {
// Error, restore previous status. // Error, restore previous status.
await CoreCourse.setCoursePreviousStatus(course.id, requiredSiteId); await CoreCourse.setCoursePreviousStatus(course.id, requiredSiteId);
@ -1709,7 +1714,7 @@ export class CoreCourseHelperProvider {
} }
// Download all the sections except "All sections". // Download all the sections except "All sections".
let allSectionsStatus = CoreConstants.NOT_DOWNLOADABLE; let allSectionsStatus = DownloadStatus.NOT_DOWNLOADABLE as TDownloadStatus;
section.isDownloading = true; section.isDownloading = true;
const promises = sections.map(async (section) => { const promises = sections.map(async (section) => {
@ -1733,7 +1738,7 @@ export class CoreCourseHelperProvider {
// Set "All sections" data. // Set "All sections" data.
section.downloadStatus = allSectionsStatus; section.downloadStatus = allSectionsStatus;
section.isDownloading = allSectionsStatus === CoreConstants.DOWNLOADING; section.isDownloading = allSectionsStatus === DownloadStatus.DOWNLOADING;
} finally { } finally {
section.isDownloading = false; section.isDownloading = false;
} }
@ -1787,7 +1792,7 @@ export class CoreCourseHelperProvider {
// Validate the section needs to be downloaded and calculate amount of modules that need to be downloaded. // Validate the section needs to be downloaded and calculate amount of modules that need to be downloaded.
const result = await CoreCourseModulePrefetchDelegate.getModulesStatus(section.modules, courseId, section.id); const result = await CoreCourseModulePrefetchDelegate.getModulesStatus(section.modules, courseId, section.id);
if (result.status == CoreConstants.DOWNLOADED || result.status == CoreConstants.NOT_DOWNLOADABLE) { if (result.status === DownloadStatus.DOWNLOADED || result.status === DownloadStatus.NOT_DOWNLOADABLE) {
// Section is downloaded or not downloadable, nothing to do. // Section is downloaded or not downloadable, nothing to do.
return ; return ;
} }
@ -1819,8 +1824,8 @@ export class CoreCourseHelperProvider {
} }
// We only download modules with status notdownloaded, downloading or outdated. // We only download modules with status notdownloaded, downloading or outdated.
const modules = result[CoreConstants.OUTDATED].concat(result[CoreConstants.NOT_DOWNLOADED]) const modules = result[DownloadStatus.OUTDATED].concat(result[DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED])
.concat(result[CoreConstants.DOWNLOADING]); .concat(result[DownloadStatus.DOWNLOADING]);
const downloadId = this.getSectionDownloadId(section); const downloadId = this.getSectionDownloadId(section);
section.isDownloading = true; section.isDownloading = true;
@ -1914,7 +1919,7 @@ export class CoreCourseHelperProvider {
modules.map((module) => this.removeModuleStoredData(module, courseId)), modules.map((module) => this.removeModuleStoredData(module, courseId)),
); );
await CoreCourse.setCourseStatus(courseId, CoreConstants.NOT_DOWNLOADED); await CoreCourse.setCourseStatus(courseId, DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED);
} }
/** /**
@ -2068,7 +2073,7 @@ export type CoreCourseSection = CoreCourseWSSection & {
* Section with data about prefetch. * Section with data about prefetch.
*/ */
export type CoreCourseSectionWithStatus = CoreCourseSection & { export type CoreCourseSectionWithStatus = CoreCourseSection & {
downloadStatus?: string; // Section status. downloadStatus?: TDownloadStatus; // Section status.
isDownloading?: boolean; // Whether section is being downloaded. isDownloading?: boolean; // Whether section is being downloaded.
total?: number; // Total of modules being downloaded. total?: number; // Total of modules being downloaded.
count?: number; // Number of downloaded modules. count?: number; // Number of downloaded modules.

View File

@ -22,7 +22,7 @@ import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@
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 { CoreSite } from '@classes/sites/site'; import { CoreSite } from '@classes/sites/site';
import { CoreConstants } from '@/core/constants'; import { CoreConstants, DownloadStatus, TDownloadStatus } from '@/core/constants';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
@ -268,7 +268,11 @@ export class CoreCourseProvider {
this.logger.debug('Clear all course status for site ' + site.id); this.logger.debug('Clear all course status for site ' + site.id);
await this.statusTables[site.getId()].delete(); await this.statusTables[site.getId()].delete();
this.triggerCourseStatusChanged(CoreCourseProvider.ALL_COURSES_CLEARED, CoreConstants.NOT_DOWNLOADED, site.id); this.triggerCourseStatusChanged(
CoreCourseProvider.ALL_COURSES_CLEARED,
DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED,
site.id,
);
} }
/** /**
@ -473,13 +477,13 @@ export class CoreCourseProvider {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Promise resolved with the status. * @returns Promise resolved with the status.
*/ */
async getCourseStatus(courseId: number, siteId?: string): Promise<string> { async getCourseStatus(courseId: number, siteId?: string): Promise<TDownloadStatus> {
try { try {
const entry = await this.getCourseStatusData(courseId, siteId); const entry = await this.getCourseStatusData(courseId, siteId);
return entry.status || CoreConstants.NOT_DOWNLOADED; return entry.status || DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
} catch { } catch {
return CoreConstants.NOT_DOWNLOADED; return DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
} }
} }
@ -490,7 +494,8 @@ export class CoreCourseProvider {
* @returns Resolves with an array containing downloaded course ids. * @returns Resolves with an array containing downloaded course ids.
*/ */
async getDownloadedCourseIds(siteId?: string): Promise<number[]> { async getDownloadedCourseIds(siteId?: string): Promise<number[]> {
const downloadedStatuses = [CoreConstants.DOWNLOADED, CoreConstants.DOWNLOADING, CoreConstants.OUTDATED]; const downloadedStatuses: TDownloadStatus[] =
[DownloadStatus.DOWNLOADED, DownloadStatus.DOWNLOADING, DownloadStatus.OUTDATED];
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
const entries = await this.statusTables[site.getId()].getManyWhere({ const entries = await this.statusTables[site.getId()].getManyWhere({
sql: 'status IN (?,?,?)', sql: 'status IN (?,?,?)',
@ -1398,7 +1403,7 @@ export class CoreCourseProvider {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when the status is changed. Resolve param: new status. * @returns Promise resolved when the status is changed. Resolve param: new status.
*/ */
async setCoursePreviousStatus(courseId: number, siteId?: string): Promise<string> { async setCoursePreviousStatus(courseId: number, siteId?: string): Promise<TDownloadStatus> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
this.logger.debug(`Set previous status for course ${courseId} in site ${siteId}`); this.logger.debug(`Set previous status for course ${courseId} in site ${siteId}`);
@ -1410,10 +1415,10 @@ export class CoreCourseProvider {
const newData = { const newData = {
id: courseId, id: courseId,
status: entry.previous || CoreConstants.NOT_DOWNLOADED, status: entry.previous || DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED,
updated: Date.now(), updated: Date.now(),
// Going back from downloading to previous status, restore previous download time. // Going back from downloading to previous status, restore previous download time.
downloadTime: entry.status == CoreConstants.DOWNLOADING ? entry.previousDownloadTime : entry.downloadTime, downloadTime: entry.status == DownloadStatus.DOWNLOADING ? entry.previousDownloadTime : entry.downloadTime,
}; };
await this.statusTables[site.getId()].update(newData, { id: courseId }); await this.statusTables[site.getId()].update(newData, { id: courseId });
@ -1431,7 +1436,7 @@ export class CoreCourseProvider {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when the status is stored. * @returns Promise resolved when the status is stored.
*/ */
async setCourseStatus(courseId: number, status: string, siteId?: string): Promise<void> { async setCourseStatus(courseId: number, status: TDownloadStatus, siteId?: string): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
this.logger.debug(`Set status '${status}' for course ${courseId} in site ${siteId}`); this.logger.debug(`Set status '${status}' for course ${courseId} in site ${siteId}`);
@ -1439,9 +1444,9 @@ export class CoreCourseProvider {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
let downloadTime = 0; let downloadTime = 0;
let previousDownloadTime = 0; let previousDownloadTime = 0;
let previousStatus = ''; let previousStatus: TDownloadStatus | undefined;
if (status == CoreConstants.DOWNLOADING) { if (status === DownloadStatus.DOWNLOADING) {
// Set download time if course is now downloading. // Set download time if course is now downloading.
downloadTime = CoreTimeUtils.timestamp(); downloadTime = CoreTimeUtils.timestamp();
} }
@ -1461,7 +1466,7 @@ export class CoreCourseProvider {
// New entry. // New entry.
} }
if (previousStatus != status) { if (previousStatus !== status) {
// Status has changed, update it. // Status has changed, update it.
await this.statusTables[site.getId()].insert({ await this.statusTables[site.getId()].insert({
id: courseId, id: courseId,
@ -1529,7 +1534,7 @@ export class CoreCourseProvider {
* @param status New course status. * @param status New course status.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
*/ */
protected triggerCourseStatusChanged(courseId: number, status: string, siteId?: string): void { protected triggerCourseStatusChanged(courseId: number, status: TDownloadStatus, siteId?: string): void {
CoreEvents.trigger(CoreEvents.COURSE_STATUS_CHANGED, { CoreEvents.trigger(CoreEvents.COURSE_STATUS_CHANGED, {
courseId: courseId, courseId: courseId,
status: status, status: status,

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { TDownloadStatus } from '@/core/constants';
import { CoreSiteSchema } from '@services/sites'; import { CoreSiteSchema } from '@services/sites';
/** /**
@ -120,8 +121,8 @@ export const OFFLINE_SITE_SCHEMA: CoreSiteSchema = {
export type CoreCourseStatusDBRecord = { export type CoreCourseStatusDBRecord = {
id: number; id: number;
status: string; status: TDownloadStatus;
previous: string; previous: TDownloadStatus | undefined;
updated: number; updated: number;
downloadTime: number; downloadTime: number;
previousDownloadTime: number; previousDownloadTime: number;

View File

@ -25,6 +25,7 @@ import { makeSingleton } from '@singletons';
import { CoreCourseModuleData } from './course-helper'; import { CoreCourseModuleData } from './course-helper';
import { CoreNavigationOptions } from '@services/navigator'; import { CoreNavigationOptions } from '@services/navigator';
import { CoreIonicColorNames } from '@singletons/colors'; import { CoreIonicColorNames } from '@singletons/colors';
import { TDownloadStatus } from '@/core/constants';
/** /**
* Interface that all course module handlers must implement. * Interface that all course module handlers must implement.
@ -222,7 +223,7 @@ export interface CoreCourseModuleHandlerData {
* *
* @param status Module status. * @param status Module status.
*/ */
updateStatus?(status: string): void; updateStatus?(status: TDownloadStatus): void;
/** /**
* On Destroy function in case it's needed. * On Destroy function in case it's needed.

View File

@ -25,7 +25,7 @@ import { CoreUtils } from '@services/utils/utils';
import { CoreCourse, CoreCourseAnyModuleData, CoreCourseModuleContentFile } from './course'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseModuleContentFile } from './course';
import { CoreCache } from '@classes/cache'; import { CoreCache } from '@classes/cache';
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus, TDownloadedStatus } from '@/core/constants';
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreEvents, CoreEventSectionStatusChangedData } from '@singletons/events'; import { CoreEvents, CoreEventSectionStatusChangedData } from '@singletons/events';
@ -122,8 +122,8 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
const promises = modules.map(async (module) => { const promises = modules.map(async (module) => {
try { try {
const data = await this.getModuleStatusAndDownloadTime(module, courseId); const data = await this.getModuleDownloadTime(module);
if (data.status != CoreConstants.DOWNLOADED) { if (!data.downloadTime || data.outdated) {
return; return;
} }
@ -160,7 +160,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param status Current status. * @param status Current status.
* @returns Module status. * @returns Module status.
*/ */
determineModuleStatus(module: CoreCourseAnyModuleData, status: string): string { determineModuleStatus(module: CoreCourseAnyModuleData, status: TDownloadStatus): TDownloadStatus {
const handler = this.getPrefetchHandlerFor(module.modname); const handler = this.getPrefetchHandlerFor(module.modname);
const siteId = CoreSites.getCurrentSiteId(); const siteId = CoreSites.getCurrentSiteId();
@ -168,7 +168,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
return status; return status;
} }
if (status == CoreConstants.DOWNLOADING) { if (status === DownloadStatus.DOWNLOADING) {
// Check if the download is being handled. // Check if the download is being handled.
if (!CoreFilepool.getPackageDownloadPromise(siteId, handler.component, module.id)) { if (!CoreFilepool.getPackageDownloadPromise(siteId, handler.component, module.id)) {
// Not handled, the app was probably restarted or something weird happened. // Not handled, the app was probably restarted or something weird happened.
@ -346,7 +346,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
// 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);
const downloadableModules = data[CoreConstants.NOT_DOWNLOADED].concat(data[CoreConstants.OUTDATED]); const downloadableModules = data[DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED].concat(data[DownloadStatus.OUTDATED]);
const result: CoreFileSizeSum = { const result: CoreFileSizeSum = {
size: 0, size: 0,
total: true, total: true,
@ -528,17 +528,17 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
updates?: CourseUpdates | false, updates?: CourseUpdates | false,
refresh?: boolean, refresh?: boolean,
sectionId?: number, sectionId?: number,
): Promise<string> { ): Promise<TDownloadStatus> {
const handler = this.getPrefetchHandlerFor(module.modname); const handler = this.getPrefetchHandlerFor(module.modname);
if (!handler) { if (!handler) {
// No handler found, module not downloadable. // No handler found, module not downloadable.
return CoreConstants.NOT_DOWNLOADABLE; return DownloadStatus.NOT_DOWNLOADABLE;
} }
// Check if the status is cached. // Check if the status is cached.
const packageId = CoreFilepool.getPackageId(handler.component, module.id); const packageId = CoreFilepool.getPackageId(handler.component, module.id);
const status = this.statusCache.getValue<string>(packageId, 'status'); const status = this.statusCache.getValue<TDownloadStatus>(packageId, 'status');
if (!refresh && status !== undefined) { if (!refresh && status !== undefined) {
this.storeCourseAndSection(packageId, courseId, sectionId); this.storeCourseAndSection(packageId, courseId, sectionId);
@ -554,6 +554,52 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
return this.determineModuleStatus(module, result.status); return this.determineModuleStatus(module, result.status);
} }
/**
* If a module is downloaded or downloading, return its status.
* This function has a better performance than getModuleStatus, but it doesn't allow you to differentiate betweeen
* NOT_DOWNLOADABLE and DOWNLOADABLE_NOT_DOWNLOADED.
*
* @param module Module.
* @param courseId Course ID the module belongs to.
* @param updates Result of getCourseUpdates for all modules in the course. If not provided, it will be
* calculated (slower). If it's false it means the site doesn't support check updates.
* @param refresh True if it should ignore the memory cache, not the WS cache.
* @param sectionId ID of the section the module belongs to.
* @returns Promise resolved with the status, null if not downloaded.
*/
async getDownloadedModuleStatus(
module: CoreCourseAnyModuleData,
courseId: number,
updates?: CourseUpdates | false,
refresh?: boolean,
sectionId?: number,
): Promise<TDownloadedStatus | null> {
const handler = this.getPrefetchHandlerFor(module.modname);
if (!handler) {
// No handler found, module not downloadable.
return null;
}
// Check if the status is cached.
const packageId = CoreFilepool.getPackageId(handler.component, module.id);
const status = this.statusCache.getValue<TDownloadStatus>(packageId, 'status');
if (!refresh && status !== undefined) {
this.storeCourseAndSection(packageId, courseId, sectionId);
return this.filterDownloadedStatus(this.determineModuleStatus(module, status));
}
const result = await this.calculateDownloadedModuleStatus(handler, module, courseId, updates, sectionId);
if (result.updateStatus && result.status) {
this.updateStatusCache(result.status, handler.component, module.id, courseId, sectionId);
}
return this.filterDownloadedStatus(
this.determineModuleStatus(module, result.status ?? DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED),
);
}
/** /**
* Calculate a module status. * Calculate a module status.
* *
@ -571,24 +617,52 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
courseId: number, courseId: number,
updates?: CourseUpdates | false, updates?: CourseUpdates | false,
sectionId?: number, sectionId?: number,
): Promise<{status: string; updateStatus: boolean}> { ): Promise<{status: TDownloadStatus; updateStatus: boolean}> {
// Check if the module is downloadable. // Check if the module is downloadable.
const downloadable = await this.isModuleDownloadable(module, courseId); const downloadable = await this.isModuleDownloadable(module, courseId);
if (!downloadable) { if (!downloadable) {
return { return {
status: CoreConstants.NOT_DOWNLOADABLE, status: DownloadStatus.NOT_DOWNLOADABLE,
updateStatus: true, updateStatus: true,
}; };
} }
const result = await this.calculateDownloadedModuleStatus(handler, module, courseId, updates, sectionId);
return {
status: result.status ?? DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED,
updateStatus: result.updateStatus,
};
}
/**
* Calculate the status of a downloaded module.
* This function has a better performance than calculateModuleStatus, but it doesn't allow you to differentiate betweeen
* NOT_DOWNLOADABLE and DOWNLOADABLE_NOT_DOWNLOADED.
*
* @param handler Prefetch handler.
* @param module Module.
* @param courseId Course ID the module belongs to.
* @param updates Result of getCourseUpdates for all modules in the course. If not provided, it will be
* calculated (slower). If it's false it means the site doesn't support check updates.
* @param sectionId ID of the section the module belongs to.
* @returns Promise resolved with the status.
*/
protected async calculateDownloadedModuleStatus(
handler: CoreCourseModulePrefetchHandler,
module: CoreCourseAnyModuleData,
courseId: number,
updates?: CourseUpdates | false,
sectionId?: number,
): Promise<{status: TDownloadedStatus | null; updateStatus: boolean}> {
// Get the saved package status. // Get the saved package status.
const siteId = CoreSites.getCurrentSiteId(); const siteId = CoreSites.getCurrentSiteId();
const currentStatus = await CoreFilepool.getPackageStatus(siteId, handler.component, module.id); const currentStatus = await CoreFilepool.getPackageStatus(siteId, handler.component, module.id);
let status = handler.determineStatus ? handler.determineStatus(module, currentStatus, true) : currentStatus; let status = handler.determineStatus ? handler.determineStatus(module, currentStatus, true) : currentStatus;
if (status != CoreConstants.DOWNLOADED || updates === false) { if (status !== DownloadStatus.DOWNLOADED || updates === false) {
return { return {
status, status: this.filterDownloadedStatus(status),
updateStatus: true, updateStatus: true,
}; };
} }
@ -604,7 +678,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
this.storeCourseAndSection(packageId, courseId, sectionId); this.storeCourseAndSection(packageId, courseId, sectionId);
return { return {
status: currentStatus, status: this.filterDownloadedStatus(currentStatus),
updateStatus: false, updateStatus: false,
}; };
} }
@ -613,7 +687,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
if (!updates || updates[module.id] === false) { if (!updates || updates[module.id] === false) {
// Cannot check updates, always show outdated. // Cannot check updates, always show outdated.
return { return {
status: CoreConstants.OUTDATED, status: DownloadStatus.OUTDATED,
updateStatus: true, updateStatus: true,
}; };
} }
@ -631,7 +705,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
} }
// Has updates, mark the module as outdated. // Has updates, mark the module as outdated.
status = CoreConstants.OUTDATED; status = DownloadStatus.OUTDATED;
await CoreUtils.ignoreErrors( await CoreUtils.ignoreErrors(
CoreFilepool.storePackageStatus(siteId, status, handler.component, module.id), CoreFilepool.storePackageStatus(siteId, status, handler.component, module.id),
@ -644,15 +718,26 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
} catch { } catch {
// Error checking if module has updates. // Error checking if module has updates.
const packageId = CoreFilepool.getPackageId(handler.component, module.id); const packageId = CoreFilepool.getPackageId(handler.component, module.id);
const status = this.statusCache.getValue<string>(packageId, 'status', true); const status = this.statusCache.getValue<TDownloadStatus>(packageId, 'status', true);
return { return {
status: this.determineModuleStatus(module, status || CoreConstants.NOT_DOWNLOADED), status: status ? this.filterDownloadedStatus(status) : null,
updateStatus: true, updateStatus: true,
}; };
} }
} }
/**
* Given a download status, filter it to return only the downloaded statuses.
*
* @param status Status.
* @returns Filtered status, null for not downloaded statuses.
*/
protected filterDownloadedStatus(status: TDownloadStatus): TDownloadedStatus | null {
return status === DownloadStatus.NOT_DOWNLOADABLE || status === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED ?
null : status;
}
/** /**
* Get the status of a list of modules, along with the lists of modules for each status. * Get the status of a list of modules, along with the lists of modules for each status.
* *
@ -676,11 +761,11 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
let updates: CourseUpdates | false = false; let updates: CourseUpdates | false = false;
const result: CoreCourseModulesStatus = { const result: CoreCourseModulesStatus = {
total: 0, total: 0,
status: CoreConstants.NOT_DOWNLOADABLE, status: DownloadStatus.NOT_DOWNLOADABLE,
[CoreConstants.NOT_DOWNLOADED]: [], [DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED]: [],
[CoreConstants.DOWNLOADED]: [], [DownloadStatus.DOWNLOADED]: [],
[CoreConstants.DOWNLOADING]: [], [DownloadStatus.DOWNLOADING]: [],
[CoreConstants.OUTDATED]: [], [DownloadStatus.OUTDATED]: [],
}; };
if (checkUpdates) { if (checkUpdates) {
@ -711,7 +796,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
result.total++; result.total++;
} catch (error) { } catch (error) {
const packageId = CoreFilepool.getPackageId(handler.component, module.id); const packageId = CoreFilepool.getPackageId(handler.component, module.id);
const cacheStatus = this.statusCache.getValue<string>(packageId, 'status', true); const cacheStatus = this.statusCache.getValue<TDownloadStatus>(packageId, 'status', true);
if (cacheStatus === undefined) { if (cacheStatus === undefined) {
throw error; throw error;
} }
@ -730,37 +815,28 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
} }
/** /**
* Get a module status and download time. It will only return the download time if the module is downloaded or outdated. * Get the time a module was downloaded, and whether the download is outdated.
* It will only return the download time if the module is downloaded or outdated.
* *
* @param module Module. * @param module Module.
* @param courseId Course ID the module belongs to.
* @returns Promise resolved with the data. * @returns Promise resolved with the data.
*/ */
protected async getModuleStatusAndDownloadTime( protected async getModuleDownloadTime(
module: CoreCourseAnyModuleData, module: CoreCourseAnyModuleData,
courseId: number, ): Promise<{ downloadTime?: number; outdated?: boolean }> {
): Promise<{ status: string; downloadTime?: number }> {
const handler = this.getPrefetchHandlerFor(module.modname); const handler = this.getPrefetchHandlerFor(module.modname);
const siteId = CoreSites.getCurrentSiteId(); const siteId = CoreSites.getCurrentSiteId();
if (!handler) { if (!handler) {
// No handler found, module not downloadable. return {};
return { status: CoreConstants.NOT_DOWNLOADABLE };
} }
// Get the status from the cache. // Get the status from the cache.
const packageId = CoreFilepool.getPackageId(handler.component, module.id); const packageId = CoreFilepool.getPackageId(handler.component, module.id);
const status = this.statusCache.getValue<string>(packageId, 'status'); const status = this.statusCache.getValue<TDownloadStatus>(packageId, 'status');
if (status !== undefined && !CoreFileHelper.isStateDownloaded(status)) { if (status !== undefined && !CoreFileHelper.isStateDownloaded(status)) {
// Module isn't downloaded, just return the status. return {};
return { status };
}
// Check if the module is downloadable.
const downloadable = await this.isModuleDownloadable(module, courseId);
if (!downloadable) {
return { status: CoreConstants.NOT_DOWNLOADABLE };
} }
try { try {
@ -768,11 +844,11 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
const data = await CoreFilepool.getPackageData(siteId, handler.component, module.id); const data = await CoreFilepool.getPackageData(siteId, handler.component, module.id);
return { return {
status: data.status || CoreConstants.NOT_DOWNLOADED, downloadTime: data.downloadTime,
downloadTime: data.downloadTime || 0, outdated: data.status === DownloadStatus.OUTDATED,
}; };
} catch { } catch {
return { status: CoreConstants.NOT_DOWNLOADED }; return {};
} }
} }
@ -795,8 +871,8 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
const data = await this.getModuleStatusAndDownloadTime(module, courseId); const data = await this.getModuleDownloadTime(module);
if (!CoreFileHelper.isStateDownloaded(data.status)) { if (!data.downloadTime) {
// Not downloaded, no updates. // Not downloaded, no updates.
return null; return null;
} }
@ -1185,7 +1261,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
return; return;
} }
await CoreFilepool.storePackageStatus(siteId, CoreConstants.NOT_DOWNLOADED, handler.component, module.id); await CoreFilepool.storePackageStatus(siteId, DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED, handler.component, module.id);
} }
/** /**
@ -1267,14 +1343,14 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
* @param sectionId Section ID of the module. * @param sectionId Section ID of the module.
*/ */
updateStatusCache( updateStatusCache(
status: string, status: TDownloadStatus,
component: string, component: string,
componentId?: string | number, componentId?: string | number,
courseId?: number, courseId?: number,
sectionId?: number, sectionId?: number,
): void { ): void {
const packageId = CoreFilepool.getPackageId(component, componentId); const packageId = CoreFilepool.getPackageId(component, componentId);
const cachedStatus = this.statusCache.getValue<string>(packageId, 'status', true); const cachedStatus = this.statusCache.getValue<TDownloadStatus>(packageId, 'status', true);
// If courseId/sectionId is set, store it. // If courseId/sectionId is set, store it.
this.storeCourseAndSection(packageId, courseId, sectionId); this.storeCourseAndSection(packageId, courseId, sectionId);
@ -1413,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. * @param canCheck Whether the site allows checking for updates. This parameter was deprecated since app 4.0.
* @returns Status to display. * @returns Status to display.
*/ */
determineStatus?(module: CoreCourseAnyModuleData, status: string, canCheck: true): string; determineStatus?(module: CoreCourseAnyModuleData, status: TDownloadStatus, canCheck: true): TDownloadStatus;
/** /**
* 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).
@ -1506,11 +1582,11 @@ 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: TDownloadStatus; // Status of the list of modules.
[CoreConstants.NOT_DOWNLOADED]: CoreCourseModuleData[]; // Modules with state NOT_DOWNLOADED. [DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED]: CoreCourseModuleData[]; // Modules with state NOT_DOWNLOADED.
[CoreConstants.DOWNLOADED]: CoreCourseModuleData[]; // Modules with state DOWNLOADED. [DownloadStatus.DOWNLOADED]: CoreCourseModuleData[]; // Modules with state DOWNLOADED.
[CoreConstants.DOWNLOADING]: CoreCourseModuleData[]; // Modules with state DOWNLOADING. [DownloadStatus.DOWNLOADING]: CoreCourseModuleData[]; // Modules with state DOWNLOADING.
[CoreConstants.OUTDATED]: CoreCourseModuleData[]; // Modules with state OUTDATED. [DownloadStatus.OUTDATED]: CoreCourseModuleData[]; // Modules with state OUTDATED.
}; };
/** /**

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { Component, ElementRef, Input, OnChanges, OnDestroy, OnInit } from '@angular/core'; import { Component, ElementRef, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
import { CoreCourseProvider, CoreCourse } from '@features/course/services/course'; import { CoreCourseProvider, CoreCourse } from '@features/course/services/course';
import { CoreCourseHelper, CorePrefetchStatusInfo } from '@features/course/services/course-helper'; import { CoreCourseHelper, CorePrefetchStatusInfo } from '@features/course/services/course-helper';
@ -51,7 +51,7 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On
prefetchCourseData: CorePrefetchStatusInfo = { prefetchCourseData: CorePrefetchStatusInfo = {
icon: '', icon: '',
statusTranslatable: 'core.loading', statusTranslatable: 'core.loading',
status: '', status: DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED,
loading: true, loading: true,
}; };
@ -60,7 +60,7 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On
progress = -1; progress = -1;
completionUserTracked: boolean | undefined = false; completionUserTracked: boolean | undefined = false;
protected courseStatus = CoreConstants.NOT_DOWNLOADED; protected courseStatus: TDownloadStatus = DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
protected isDestroyed = false; protected isDestroyed = false;
protected courseStatusObserver?: CoreEventObserver; protected courseStatusObserver?: CoreEventObserver;
@ -211,7 +211,7 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On
* *
* @param status Status to show. * @param status Status to show.
*/ */
protected updateCourseStatus(status: string): void { protected updateCourseStatus(status: TDownloadStatus): void {
const statusData = CoreCourseHelper.getCoursePrefetchStatusInfo(status); const statusData = CoreCourseHelper.getCoursePrefetchStatusInfo(status);
this.courseStatus = status; this.courseStatus = status;
@ -219,7 +219,7 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On
this.prefetchCourseData.icon = statusData.icon; this.prefetchCourseData.icon = statusData.icon;
this.prefetchCourseData.statusTranslatable = statusData.statusTranslatable; this.prefetchCourseData.statusTranslatable = statusData.statusTranslatable;
this.prefetchCourseData.loading = statusData.loading; this.prefetchCourseData.loading = statusData.loading;
this.prefetchCourseData.downloadSucceeded = status === CoreConstants.DOWNLOADED; this.prefetchCourseData.downloadSucceeded = status === DownloadStatus.DOWNLOADED;
} }
/** /**
@ -295,7 +295,7 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On
} }
break; break;
case 'delete': case 'delete':
if (this.courseStatus == CoreConstants.DOWNLOADED || this.courseStatus == CoreConstants.OUTDATED) { if (this.courseStatus === DownloadStatus.DOWNLOADED || this.courseStatus === DownloadStatus.OUTDATED) {
this.deleteCourseStoredData(); this.deleteCourseStoredData();
} }
break; break;

View File

@ -24,7 +24,7 @@ import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreH5P } from '@features/h5p/services/h5p'; import { CoreH5P } from '@features/h5p/services/h5p';
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { CoreSite } from '@classes/sites/site'; import { CoreSite } from '@classes/sites/site';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { CoreH5PCore, CoreH5PDisplayOptions } from '../../classes/core'; import { CoreH5PCore, CoreH5PDisplayOptions } from '../../classes/core';
@ -100,7 +100,7 @@ export class CoreH5PIframeComponent implements OnChanges, OnDestroy {
*/ */
protected async play(): Promise<void> { protected async play(): Promise<void> {
let localUrl: string | undefined; let localUrl: string | undefined;
let state: string; let state: TDownloadStatus;
this.onlinePlayerUrl = this.onlinePlayerUrl || CoreH5P.h5pPlayer.calculateOnlinePlayerUrl( this.onlinePlayerUrl = this.onlinePlayerUrl || CoreH5P.h5pPlayer.calculateOnlinePlayerUrl(
this.site.getURL(), this.site.getURL(),
this.fileUrl || '', this.fileUrl || '',
@ -111,7 +111,7 @@ export class CoreH5PIframeComponent implements OnChanges, OnDestroy {
if (this.fileUrl) { if (this.fileUrl) {
state = await CoreFilepool.getFileStateByUrl(this.siteId, this.fileUrl); state = await CoreFilepool.getFileStateByUrl(this.siteId, this.fileUrl);
} else { } else {
state = CoreConstants.NOT_DOWNLOADABLE; state = DownloadStatus.NOT_DOWNLOADABLE;
} }
if (this.siteCanDownload && CoreFileHelper.isStateDownloaded(state)) { if (this.siteCanDownload && CoreFileHelper.isStateDownloaded(state)) {

View File

@ -20,7 +20,7 @@ import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CorePluginFileDelegate } from '@services/plugin-file-delegate';
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { CoreSite } from '@classes/sites/site'; import { CoreSite } from '@classes/sites/site';
import { CoreEvents, CoreEventObserver } from '@singletons/events'; import { CoreEvents, CoreEventObserver } from '@singletons/events';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
@ -94,7 +94,10 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
this.displayOptions = CoreH5P.h5pPlayer.getDisplayOptionsFromUrlParams(this.urlParams); this.displayOptions = CoreH5P.h5pPlayer.getDisplayOptionsFromUrlParams(this.urlParams);
this.showPackage = true; this.showPackage = true;
if (!this.canDownload$.getValue() || (this.state != CoreConstants.OUTDATED && this.state != CoreConstants.NOT_DOWNLOADED)) { if (
!this.canDownload$.getValue() ||
(this.state !== DownloadStatus.OUTDATED && this.state !== DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED)
) {
return; return;
} }

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { TDownloadStatus } from '@/core/constants';
import { CoreAppSchema } from '@services/app'; import { CoreAppSchema } from '@services/app';
import { CoreSiteSchema } from '@services/sites'; import { CoreSiteSchema } from '@services/sites';
@ -314,12 +315,12 @@ export type CoreFilepoolPackageEntry = {
/** /**
* Package status. * Package status.
*/ */
status?: string; status?: TDownloadStatus;
/** /**
* Package previous status. * Package previous status.
*/ */
previous?: string; previous?: TDownloadStatus;
/** /**
* Timestamp when this package was updated. * Timestamp when this package was updated.

View File

@ -23,7 +23,7 @@ import { CoreWS, CoreWSFile } from '@services/ws';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils, CoreUtilsOpenFileOptions, OpenFileAction } from '@services/utils/utils'; import { CoreUtils, CoreUtilsOpenFileOptions, OpenFileAction } from '@services/utils/utils';
import { CoreConstants } from '@/core/constants'; import { CoreConstants, DownloadStatus, TDownloadStatus } from '@/core/constants';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
@ -63,7 +63,7 @@ export class CoreFileHelperProvider {
file: CoreWSFile, file: CoreWSFile,
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
state?: string, state?: TDownloadStatus,
onProgress?: CoreFileHelperOnProgress, onProgress?: CoreFileHelperOnProgress,
siteId?: string, siteId?: string,
options: CoreUtilsOpenFileOptions = {}, options: CoreUtilsOpenFileOptions = {},
@ -113,11 +113,11 @@ export class CoreFileHelperProvider {
state = await CoreFilepool.getFileStateByUrl(siteId, fileUrl, timemodified); state = await CoreFilepool.getFileStateByUrl(siteId, fileUrl, timemodified);
} }
if (state == CoreConstants.DOWNLOADING) { if (state === DownloadStatus.DOWNLOADING) {
throw new CoreError(Translate.instant('core.erroropenfiledownloading')); throw new CoreError(Translate.instant('core.erroropenfiledownloading'));
} }
if (state === CoreConstants.NOT_DOWNLOADED) { if (state === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
// File is not downloaded, download and then return the local URL. // File is not downloaded, download and then return the local URL.
url = await this.downloadFile(fileUrl, component, componentId, timemodified, onProgress, file, siteId); url = await this.downloadFile(fileUrl, component, componentId, timemodified, onProgress, file, siteId);
} else { } else {
@ -150,7 +150,7 @@ export class CoreFileHelperProvider {
component?: string, component?: string,
componentId?: string | number, componentId?: string | number,
timemodified?: number, timemodified?: number,
state?: string, state?: TDownloadStatus,
onProgress?: CoreFileHelperOnProgress, onProgress?: CoreFileHelperOnProgress,
siteId?: string, siteId?: string,
options: CoreUtilsOpenFileOptions = {}, options: CoreUtilsOpenFileOptions = {},
@ -174,7 +174,7 @@ export class CoreFileHelperProvider {
const isWifi = CoreNetwork.isWifi(); const isWifi = CoreNetwork.isWifi();
const isOnline = CoreNetwork.isOnline(); const isOnline = CoreNetwork.isOnline();
if (state == CoreConstants.DOWNLOADED) { if (state === DownloadStatus.DOWNLOADED) {
// File is downloaded, get the local file URL. // File is downloaded, get the local file URL.
return CoreFilepool.getUrlByUrl(siteId, fileUrl, component, componentId, timemodified, false, false, file); return CoreFilepool.getUrlByUrl(siteId, fileUrl, component, componentId, timemodified, false, false, file);
} else { } else {
@ -191,7 +191,7 @@ export class CoreFileHelperProvider {
const shouldDownloadFirst = await CoreFilepool.shouldDownloadFileBeforeOpen(fixedUrl, file.filesize || 0, options); const shouldDownloadFirst = await CoreFilepool.shouldDownloadFileBeforeOpen(fixedUrl, file.filesize || 0, options);
if (shouldDownloadFirst) { if (shouldDownloadFirst) {
// Download the file first. // Download the file first.
if (state == CoreConstants.DOWNLOADING) { if (state === DownloadStatus.DOWNLOADING) {
// It's already downloading, stop. // It's already downloading, stop.
return fixedUrl; return fixedUrl;
} }
@ -304,8 +304,8 @@ export class CoreFileHelperProvider {
* @param state The state to check. * @param state The state to check.
* @returns If file has been downloaded (or outdated). * @returns If file has been downloaded (or outdated).
*/ */
isStateDownloaded(state: string): boolean { isStateDownloaded(state: TDownloadStatus): boolean {
return state === CoreConstants.DOWNLOADED || state === CoreConstants.OUTDATED; return state === DownloadStatus.DOWNLOADED || state === DownloadStatus.OUTDATED;
} }
/** /**

View File

@ -29,7 +29,7 @@ import { CoreTimeUtils } from '@services/utils/time';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils, CoreUtilsOpenFileOptions } from '@services/utils/utils'; import { CoreUtils, CoreUtilsOpenFileOptions } from '@services/utils/utils';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreConstants } from '@/core/constants'; import { DownloadStatus, TDownloadStatus } from '@/core/constants';
import { ApplicationInit, makeSingleton, NgZone, Translate } from '@singletons'; import { ApplicationInit, makeSingleton, NgZone, Translate } from '@singletons';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { import {
@ -593,7 +593,12 @@ export class CoreFilepoolProvider {
} }
// Trigger module status changed, setting it as not downloaded. // Trigger module status changed, setting it as not downloaded.
this.triggerPackageStatusChanged(siteId, CoreConstants.NOT_DOWNLOADED, entry.component, entry.componentId); this.triggerPackageStatusChanged(
siteId,
DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED,
entry.component,
entry.componentId,
);
}); });
} }
@ -669,36 +674,36 @@ export class CoreFilepoolProvider {
/** /**
* Given the current status of a list of packages and the status of one of the packages, * Given the current status of a list of packages and the status of one of the packages,
* determine the new status for the list of packages. The status of a list of packages is: * determine the new status for the list of packages. The status of a list of packages is:
* - CoreConstants.NOT_DOWNLOADABLE if there are no downloadable packages. * - NOT_DOWNLOADABLE if there are no downloadable packages.
* - CoreConstants.NOT_DOWNLOADED if at least 1 package has status CoreConstants.NOT_DOWNLOADED. * - DOWNLOADABLE_NOT_DOWNLOADED if at least 1 package has status DOWNLOADABLE_NOT_DOWNLOADED.
* - CoreConstants.DOWNLOADED if ALL the downloadable packages have status CoreConstants.DOWNLOADED. * - DOWNLOADED if ALL the downloadable packages have status DOWNLOADED.
* - CoreConstants.DOWNLOADING if ALL the downloadable packages have status CoreConstants.DOWNLOADING or * - DOWNLOADING if ALL the downloadable packages have status DOWNLOADING or DOWNLOADED, with at least 1 package
* CoreConstants.DOWNLOADED, with at least 1 package with CoreConstants.DOWNLOADING. * with status DOWNLOADING.
* - CoreConstants.OUTDATED if ALL the downloadable packages have status CoreConstants.OUTDATED or CoreConstants.DOWNLOADED * - OUTDATED if ALL the downloadable packages have status OUTDATED or DOWNLOADED or DOWNLOADING, with at least 1 package
* or CoreConstants.DOWNLOADING, with at least 1 package with CoreConstants.OUTDATED. * with OUTDATED.
* *
* @param current Current status of the list of packages. * @param current Current status of the list of packages.
* @param packageStatus Status of one of the packages. * @param packageStatus Status of one of the packages.
* @returns New status for the list of packages; * @returns New status for the list of packages;
*/ */
determinePackagesStatus(current: string, packageStatus: string): string { determinePackagesStatus(current: TDownloadStatus, packageStatus: TDownloadStatus): TDownloadStatus {
if (!current) { if (!current) {
current = CoreConstants.NOT_DOWNLOADABLE; current = DownloadStatus.NOT_DOWNLOADABLE;
} }
if (packageStatus === CoreConstants.NOT_DOWNLOADED) { if (packageStatus === DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
// If 1 package is not downloaded the status of the whole list will always be not downloaded. // If 1 package is not downloaded the status of the whole list will always be not downloaded.
return CoreConstants.NOT_DOWNLOADED; return DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
} else if (packageStatus === CoreConstants.DOWNLOADED && current === CoreConstants.NOT_DOWNLOADABLE) { } else if (packageStatus === DownloadStatus.DOWNLOADED && current === DownloadStatus.NOT_DOWNLOADABLE) {
// If all packages are downloaded or not downloadable with at least 1 downloaded, status will be downloaded. // If all packages are downloaded or not downloadable with at least 1 downloaded, status will be downloaded.
return CoreConstants.DOWNLOADED; return DownloadStatus.DOWNLOADED;
} else if (packageStatus === CoreConstants.DOWNLOADING && } else if (packageStatus === DownloadStatus.DOWNLOADING &&
(current === CoreConstants.NOT_DOWNLOADABLE || current === CoreConstants.DOWNLOADED)) { (current === DownloadStatus.NOT_DOWNLOADABLE || current === DownloadStatus.DOWNLOADED)) {
// If all packages are downloading/downloaded/notdownloadable with at least 1 downloading, status will be downloading. // If all packages are downloading/downloaded/notdownloadable with at least 1 downloading, status will be downloading.
return CoreConstants.DOWNLOADING; return DownloadStatus.DOWNLOADING;
} else if (packageStatus === CoreConstants.OUTDATED && current !== CoreConstants.NOT_DOWNLOADED) { } else if (packageStatus === DownloadStatus.OUTDATED && current !== DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED) {
// If there are no packages notdownloaded and there is at least 1 outdated, status will be outdated. // If there are no packages notdownloaded and there is at least 1 outdated, status will be outdated.
return CoreConstants.OUTDATED; return DownloadStatus.OUTDATED;
} }
// Status remains the same. // Status remains the same.
@ -886,7 +891,7 @@ export class CoreFilepoolProvider {
} }
// Set package as downloading. // Set package as downloading.
const promise = this.storePackageStatus(siteId, CoreConstants.DOWNLOADING, component, componentId).then(async () => { const promise = this.storePackageStatus(siteId, DownloadStatus.DOWNLOADING, component, componentId).then(async () => {
const promises: Promise<string | void>[] = []; const promises: Promise<string | void>[] = [];
let packageLoaded = 0; let packageLoaded = 0;
@ -959,7 +964,7 @@ export class CoreFilepoolProvider {
try { try {
await Promise.all(promises); await Promise.all(promises);
// Success prefetching, store package as downloaded. // Success prefetching, store package as downloaded.
await this.storePackageStatus(siteId, CoreConstants.DOWNLOADED, component, componentId, extra); await this.storePackageStatus(siteId, DownloadStatus.DOWNLOADED, component, componentId, extra);
return; return;
} catch (error) { } catch (error) {
@ -1520,13 +1525,13 @@ export class CoreFilepoolProvider {
timemodified: number = 0, timemodified: number = 0,
filePath?: string, filePath?: string,
revision?: number, revision?: number,
): Promise<string> { ): Promise<TDownloadStatus> {
let file: CoreWSFile; let file: CoreWSFile;
try { try {
file = await this.fixPluginfileURL(siteId, fileUrl, timemodified); file = await this.fixPluginfileURL(siteId, fileUrl, timemodified);
} catch (e) { } catch (e) {
return CoreConstants.NOT_DOWNLOADABLE; return DownloadStatus.NOT_DOWNLOADABLE;
} }
fileUrl = CoreUrl.removeUrlAnchor(CoreFileHelper.getFileUrl(file)); fileUrl = CoreUrl.removeUrlAnchor(CoreFileHelper.getFileUrl(file));
@ -1538,7 +1543,7 @@ export class CoreFilepoolProvider {
// Check if the file is in queue (waiting to be downloaded). // Check if the file is in queue (waiting to be downloaded).
await this.hasFileInQueue(siteId, fileId); await this.hasFileInQueue(siteId, fileId);
return CoreConstants.DOWNLOADING; return DownloadStatus.DOWNLOADING;
} catch (e) { } catch (e) {
// Check if the file is being downloaded right now. // Check if the file is being downloaded right now.
const extension = CoreMimetypeUtils.guessExtensionFromUrl(fileUrl); const extension = CoreMimetypeUtils.guessExtensionFromUrl(fileUrl);
@ -1547,7 +1552,7 @@ export class CoreFilepoolProvider {
const downloadId = this.getFileDownloadId(fileUrl, filePath); const downloadId = this.getFileDownloadId(fileUrl, filePath);
if (this.filePromises[siteId] && this.filePromises[siteId][downloadId] !== undefined) { if (this.filePromises[siteId] && this.filePromises[siteId][downloadId] !== undefined) {
return CoreConstants.DOWNLOADING; return DownloadStatus.DOWNLOADING;
} }
try { try {
@ -1555,12 +1560,12 @@ export class CoreFilepoolProvider {
const entry = await this.hasFileInPool(siteId, fileId); const entry = await this.hasFileInPool(siteId, fileId);
if (this.isFileOutdated(entry, revision, timemodified)) { if (this.isFileOutdated(entry, revision, timemodified)) {
return CoreConstants.OUTDATED; return DownloadStatus.OUTDATED;
} }
return CoreConstants.DOWNLOADED; return DownloadStatus.DOWNLOADED;
} catch (e) { } catch (e) {
return CoreConstants.NOT_DOWNLOADED; return DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
} }
} }
} }
@ -1855,13 +1860,13 @@ export class CoreFilepoolProvider {
* @param componentId An ID to use in conjunction with the component. * @param componentId An ID to use in conjunction with the component.
* @returns Promise resolved with the status. * @returns Promise resolved with the status.
*/ */
async getPackagePreviousStatus(siteId: string, component: string, componentId?: string | number): Promise<string> { async getPackagePreviousStatus(siteId: string, component: string, componentId?: string | number): Promise<TDownloadStatus> {
try { try {
const entry = await this.getPackageData(siteId, component, componentId); const entry = await this.getPackageData(siteId, component, componentId);
return entry.previous || CoreConstants.NOT_DOWNLOADED; return entry.previous || DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
} catch (error) { } catch (error) {
return CoreConstants.NOT_DOWNLOADED; return DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
} }
} }
@ -1873,13 +1878,13 @@ export class CoreFilepoolProvider {
* @param componentId An ID to use in conjunction with the component. * @param componentId An ID to use in conjunction with the component.
* @returns Promise resolved with the status. * @returns Promise resolved with the status.
*/ */
async getPackageStatus(siteId: string, component: string, componentId?: string | number): Promise<string> { async getPackageStatus(siteId: string, component: string, componentId?: string | number): Promise<TDownloadStatus> {
try { try {
const entry = await this.getPackageData(siteId, component, componentId); const entry = await this.getPackageData(siteId, component, componentId);
return entry.status || CoreConstants.NOT_DOWNLOADED; return entry.status || DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
} catch (error) { } catch (error) {
return CoreConstants.NOT_DOWNLOADED; return DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
} }
} }
@ -2324,7 +2329,7 @@ export class CoreFilepoolProvider {
): Promise<boolean> { ): Promise<boolean> {
const state = await this.getFileStateByUrl(siteId, fileUrl, timemodified, filePath, revision); const state = await this.getFileStateByUrl(siteId, fileUrl, timemodified, filePath, revision);
return state != CoreConstants.NOT_DOWNLOADABLE; return state !== DownloadStatus.NOT_DOWNLOADABLE;
} }
/** /**
@ -2807,7 +2812,7 @@ export class CoreFilepoolProvider {
* @param componentId An ID to use in conjunction with the component. * @param componentId An ID to use in conjunction with the component.
* @returns Promise resolved when the status is changed. Resolve param: new status. * @returns Promise resolved when the status is changed. Resolve param: new status.
*/ */
async setPackagePreviousStatus(siteId: string, component: string, componentId?: string | number): Promise<string> { async setPackagePreviousStatus(siteId: string, component: string, componentId?: string | number): Promise<TDownloadStatus> {
componentId = this.fixComponentId(componentId); componentId = this.fixComponentId(componentId);
this.logger.debug(`Set previous status for package ${component} ${componentId}`); this.logger.debug(`Set previous status for package ${component} ${componentId}`);
@ -2816,11 +2821,11 @@ export class CoreFilepoolProvider {
// Get current stored data, we'll only update 'status' and 'updated' fields. // Get current stored data, we'll only update 'status' and 'updated' fields.
const entry = await this.packagesTables[siteId].getOneByPrimaryKey({ id: packageId }); const entry = await this.packagesTables[siteId].getOneByPrimaryKey({ id: packageId });
const newData: CoreFilepoolPackageEntry = {}; const newData: CoreFilepoolPackageEntry = {};
if (entry.status == CoreConstants.DOWNLOADING) { if (entry.status === DownloadStatus.DOWNLOADING) {
// Going back from downloading to previous status, restore previous download time. // Going back from downloading to previous status, restore previous download time.
newData.downloadTime = entry.previousDownloadTime; newData.downloadTime = entry.previousDownloadTime;
} }
newData.status = entry.previous || CoreConstants.NOT_DOWNLOADED; newData.status = entry.previous || DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED;
newData.updated = Date.now(); newData.updated = Date.now();
this.logger.debug(`Set previous status '${entry.status}' for package ${component} ${componentId}`); this.logger.debug(`Set previous status '${entry.status}' for package ${component} ${componentId}`);
@ -2886,7 +2891,7 @@ export class CoreFilepoolProvider {
*/ */
async storePackageStatus( async storePackageStatus(
siteId: string, siteId: string,
status: string, status: TDownloadStatus,
component: string, component: string,
componentId?: string | number, componentId?: string | number,
extra?: string, extra?: string,
@ -2898,12 +2903,12 @@ export class CoreFilepoolProvider {
let downloadTime: number | undefined; let downloadTime: number | undefined;
let previousDownloadTime: number | undefined; let previousDownloadTime: number | undefined;
if (status == CoreConstants.DOWNLOADING) { if (status === DownloadStatus.DOWNLOADING) {
// Set download time if package is now downloading. // Set download time if package is now downloading.
downloadTime = CoreTimeUtils.timestamp(); downloadTime = CoreTimeUtils.timestamp();
} }
let previousStatus: string | undefined; let previousStatus: TDownloadStatus | undefined;
// Search current status to set it as previous status. // Search current status to set it as previous status.
try { try {
const entry = await this.packagesTables[siteId].getOneByPrimaryKey({ id: packageId }); const entry = await this.packagesTables[siteId].getOneByPrimaryKey({ id: packageId });
@ -3050,7 +3055,12 @@ export class CoreFilepoolProvider {
* @param component Package's component. * @param component Package's component.
* @param componentId An ID to use in conjunction with the component. * @param componentId An ID to use in conjunction with the component.
*/ */
protected triggerPackageStatusChanged(siteId: string, status: string, component: string, componentId?: string | number): void { protected triggerPackageStatusChanged(
siteId: string,
status: TDownloadStatus,
component: string,
componentId?: string | number,
): void {
const data: CoreEventPackageStatusChanged = { const data: CoreEventPackageStatusChanged = {
component, component,
componentId: this.fixComponentId(componentId), componentId: this.fixComponentId(componentId),
@ -3068,7 +3078,6 @@ export class CoreFilepoolProvider {
* @param siteId Site ID. * @param siteId Site ID.
* @param component Package's component. * @param component Package's component.
* @param componentId An ID to use in conjunction with the component. * @param componentId An ID to use in conjunction with the component.
* @returns Promise resolved when status is stored.
*/ */
async updatePackageDownloadTime(siteId: string, component: string, componentId?: string | number): Promise<void> { async updatePackageDownloadTime(siteId: string, component: string, componentId?: string | number): Promise<void> {
componentId = this.fixComponentId(componentId); componentId = this.fixComponentId(componentId);

View File

@ -17,7 +17,7 @@ import { FileEntry } from '@awesome-cordova-plugins/file/ngx';
import { CoreFilepool, CoreFilepoolOnProgressCallback } from '@services/filepool'; import { CoreFilepool, CoreFilepoolOnProgressCallback } from '@services/filepool';
import { CoreWSFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { CoreConstants } from '@/core/constants'; import { DownloadStatus } from '@/core/constants';
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreSites } from './sites'; import { CoreSites } from './sites';
@ -141,7 +141,7 @@ export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHa
await Promise.all(files.map(async (file) => { await Promise.all(files.map(async (file) => {
const state = await CoreFilepool.getFileStateByUrl(siteIdentifier, CoreFileHelper.getFileUrl(file), file.timemodified); const state = await CoreFilepool.getFileStateByUrl(siteIdentifier, CoreFileHelper.getFileUrl(file), file.timemodified);
if (state !== CoreConstants.DOWNLOADED && state !== CoreConstants.NOT_DOWNLOADABLE) { if (state !== DownloadStatus.DOWNLOADED && state !== DownloadStatus.NOT_DOWNLOADABLE) {
filteredFiles.push(file); filteredFiles.push(file);
} }
})); }));

View File

@ -21,6 +21,7 @@ import { CoreRedirectPayload } from '@services/navigator';
import { CoreCourseModuleCompletionData } from '@features/course/services/course-helper'; import { CoreCourseModuleCompletionData } from '@features/course/services/course-helper';
import { CoreScreenOrientation } from '@services/screen'; import { CoreScreenOrientation } from '@services/screen';
import { CoreSiteInfoResponse, CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site'; import { CoreSiteInfoResponse, CoreSitePublicConfigResponse } from '@classes/sites/unauthenticated-site';
import { TDownloadStatus } from '../constants';
/** /**
* Observer instance to stop listening to an event. * Observer instance to stop listening to an event.
@ -326,7 +327,7 @@ export type CoreEventLoadingChangedData = {
*/ */
export type CoreEventCourseStatusChanged = { export type CoreEventCourseStatusChanged = {
courseId: number; // Course Id. courseId: number; // Course Id.
status: string; status: TDownloadStatus;
}; };
/** /**
@ -335,7 +336,7 @@ export type CoreEventCourseStatusChanged = {
export type CoreEventPackageStatusChanged = { export type CoreEventPackageStatusChanged = {
component: string; component: string;
componentId: string | number; componentId: string | number;
status: string; status: TDownloadStatus;
}; };
/** /**