From 018ebd6bb2e7fb55cf423b596f86f79defbb84a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 23 Dec 2021 15:11:21 +0100 Subject: [PATCH] MOBILE-3954 course: Remove prefetch module from course and blocks --- .../addon-block-sitemainmenu.html | 3 +- .../side-blocks-button/side-blocks-button.ts | 2 - .../components/side-blocks/side-blocks.html | 3 +- .../components/side-blocks/side-blocks.ts | 1 - .../components/format/core-course-format.html | 39 +---- .../course/components/format/format.scss | 15 -- .../course/components/format/format.ts | 127 +-------------- .../components/module/core-course-module.html | 12 +- .../course/components/module/module.ts | 138 +---------------- .../core-course-format-single-activity.html | 2 +- .../components/singleactivity.ts | 1 - .../handlers/singleactivity-format.ts | 7 - .../course/pages/contents/contents.html | 10 +- .../course/pages/contents/contents.ts | 146 +----------------- .../pages/list-mod-type/list-mod-type.html | 3 +- .../pages/list-mod-type/list-mod-type.page.ts | 3 - .../course/services/format-delegate.ts | 13 +- .../services/handlers/default-format.ts | 11 -- .../courses/pages/dashboard/dashboard.html | 2 +- .../features/sitehome/pages/index/index.html | 10 +- .../features/sitehome/pages/index/index.ts | 22 +-- .../classes/handlers/course-format-handler.ts | 7 - upgrade.txt | 1 + 23 files changed, 30 insertions(+), 548 deletions(-) diff --git a/src/addons/block/sitemainmenu/components/sitemainmenu/addon-block-sitemainmenu.html b/src/addons/block/sitemainmenu/components/sitemainmenu/addon-block-sitemainmenu.html index c650ba61e..de45bf3af 100644 --- a/src/addons/block/sitemainmenu/components/sitemainmenu/addon-block-sitemainmenu.html +++ b/src/addons/block/sitemainmenu/components/sitemainmenu/addon-block-sitemainmenu.html @@ -12,7 +12,6 @@ - + diff --git a/src/core/features/block/components/side-blocks-button/side-blocks-button.ts b/src/core/features/block/components/side-blocks-button/side-blocks-button.ts index 71f3e4898..bd59a030a 100644 --- a/src/core/features/block/components/side-blocks-button/side-blocks-button.ts +++ b/src/core/features/block/components/side-blocks-button/side-blocks-button.ts @@ -27,7 +27,6 @@ import { CoreBlockSideBlocksComponent } from '../side-blocks/side-blocks'; export class CoreBlockSideBlocksButtonComponent { @Input() courseId!: number; - @Input() downloadEnabled = false; /** * Open side blocks. @@ -37,7 +36,6 @@ export class CoreBlockSideBlocksButtonComponent { component: CoreBlockSideBlocksComponent, componentProps: { courseId: this.courseId, - downloadEnabled: this.downloadEnabled, }, }); } diff --git a/src/core/features/block/components/side-blocks/side-blocks.html b/src/core/features/block/components/side-blocks/side-blocks.html index 4b08c5b01..198cb21d2 100644 --- a/src/core/features/block/components/side-blocks/side-blocks.html +++ b/src/core/features/block/components/side-blocks/side-blocks.html @@ -17,8 +17,7 @@ - + diff --git a/src/core/features/block/components/side-blocks/side-blocks.ts b/src/core/features/block/components/side-blocks/side-blocks.ts index 0f817a4a0..b44b32557 100644 --- a/src/core/features/block/components/side-blocks/side-blocks.ts +++ b/src/core/features/block/components/side-blocks/side-blocks.ts @@ -33,7 +33,6 @@ import { CoreCoursesDashboard } from '@features/courses/services/dashboard'; export class CoreBlockSideBlocksComponent implements OnInit { @Input() courseId?: number; - @Input() downloadEnabled = false; @ViewChildren(CoreBlockComponent) blocksComponents?: QueryList; diff --git a/src/core/features/course/components/format/core-course-format.html b/src/core/features/course/components/format/core-course-format.html index e4b211c67..7e549a3c2 100644 --- a/src/core/features/course/components/format/core-course-format.html +++ b/src/core/features/course/components/format/core-course-format.html @@ -11,10 +11,8 @@ -
+ class="ion-text-wrap ion-justify-content-between ion-align-items-center core-button-selector-row"> {{ 'core.course.sections' | translate }} - -
- + (selectedSection.availabilityinfo || selectedSection.visible === 0))" lines="none" class="core-format-progress-list">
@@ -103,8 +99,7 @@ - +
@@ -114,7 +109,7 @@
+ [class.item-dimmed]="section.visible === 0 || section.uservisible === false">

@@ -133,8 +128,6 @@

- - @@ -145,28 +138,10 @@ -

- - - -
- - - {{section.count}} / {{section.total}} - - - - -
-
diff --git a/src/core/features/course/components/format/format.scss b/src/core/features/course/components/format/format.scss index 46ca0f415..76335d842 100644 --- a/src/core/features/course/components/format/format.scss +++ b/src/core/features/course/components/format/format.scss @@ -55,21 +55,6 @@ } } - .core-section-download { - core-combobox { - max-width: calc(100% - 64px); - } - .core-button-spinner { - display: flex; - align-items: center; - @include margin-horizontal(10px); - - ion-badge.core-course-download-courses-progress { - @include margin(null, 12px, null, null); - } - } - } - .core-course-section-nav-buttons { display: flex; justify-content: flex-end; diff --git a/src/core/features/course/components/format/format.ts b/src/core/features/course/components/format/format.ts index 683eb061e..7d93a2084 100644 --- a/src/core/features/course/components/format/format.ts +++ b/src/core/features/course/components/format/format.ts @@ -27,7 +27,6 @@ import { ElementRef, } from '@angular/core'; import { ModalOptions } from '@ionic/core'; -import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; @@ -37,17 +36,14 @@ import { CoreCourseProvider, } from '@features/course/services/course'; import { - CoreCourseHelper, CoreCourseModuleData, CoreCourseModuleCompletionData, CoreCourseSection, - CoreCourseSectionWithStatus, } from '@features/course/services/course-helper'; import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { IonContent, IonRefresher } from '@ionic/angular'; import { CoreUtils } from '@services/utils/utils'; -import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourseSectionSelectorComponent } from '../section-selector/section-selector'; import { CoreBlockHelper } from '@features/block/services/block-helper'; @@ -71,8 +67,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { static readonly LOAD_MORE_ACTIVITIES = 20; // How many activities should load each time showMoreActivities is called. @Input() course?: CoreCourseAnyCourseData; // The course to render. - @Input() sections?: CoreCourseSectionWithStatus[]; // List of course sections. The status will be calculated in this component. - @Input() downloadEnabled?: boolean; // Whether the download of sections and modules is enabled. + @Input() sections?: CoreCourseSection[]; // List of course sections. @Input() initialSectionId?: number; // The section to load first (by ID). @Input() initialSectionNumber?: number; // The section to load first (by number). @Input() moduleId?: number; // The module ID to scroll to. Must be inside the initial selected section. @@ -108,7 +103,6 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { componentProps: {}, }; - protected sectionStatusObserver?: CoreEventObserver; protected selectTabObserver?: CoreEventObserver; protected lastCourseFormat?: string; protected sectionSelectorExpanded = false; @@ -125,38 +119,6 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { * Component being initialized. */ ngOnInit(): void { - // Listen for section status changes. - this.sectionStatusObserver = CoreEvents.on( - CoreEvents.SECTION_STATUS_CHANGED, - async (data) => { - if (!this.downloadEnabled || !this.sections?.length || !data.sectionId || data.courseId != this.course?.id) { - return; - } - - // Check if the affected section is being downloaded. - // If so, we don't update section status because it'll already be updated when the download finishes. - const downloadId = CoreCourseHelper.getSectionDownloadId({ id: data.sectionId }); - if (CoreCourseModulePrefetchDelegate.isBeingDownloaded(downloadId)) { - return; - } - - // Get the affected section. - const section = this.sections.find(section => section.id == data.sectionId); - if (!section) { - return; - } - - // Recalculate the status. - await CoreCourseHelper.calculateSectionStatus(section, this.course.id, false); - - if (section.isDownloading && !CoreCourseModulePrefetchDelegate.isBeingDownloaded(downloadId)) { - // All the modules are now downloading, set a download all promise. - this.prefetch(section); - } - }, - CoreSites.getCurrentSiteId(), - ); - // Listen for select course tab events to select the right section if needed. this.selectTabObserver = CoreEvents.on(CoreEvents.SELECT_COURSE_TAB, (data) => { if (data.name) { @@ -205,10 +167,6 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { this.sectionSelectorModalOptions.componentProps!.sections = this.sections; this.treatSections(this.sections); } - - if (this.downloadEnabled && (changes.downloadEnabled || changes.sections)) { - this.calculateSectionsStatus(false); - } } /** @@ -219,7 +177,6 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { this.data.sections = this.sections; this.data.initialSectionId = this.initialSectionId; this.data.initialSectionNumber = this.initialSectionNumber; - this.data.downloadEnabled = this.downloadEnabled; this.data.moduleId = this.moduleId; this.data.completionChanged = this.completionChanged; } @@ -394,9 +351,6 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { this.canLoadMore = false; this.showSectionId = 0; this.showMoreActivities(); - if (this.downloadEnabled) { - this.calculateSectionsStatus(false); - } } if (this.moduleId && previousValue === undefined) { @@ -432,62 +386,6 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { return section1 && section2 ? section1.id === section2.id : section1 === section2; } - /** - * Calculate the status of sections. - * - * @param refresh If refresh or not. - */ - protected calculateSectionsStatus(refresh?: boolean): void { - if (!this.sections || !this.course) { - return; - } - - CoreUtils.ignoreErrors(CoreCourseHelper.calculateSectionsStatus(this.sections, this.course.id, refresh)); - } - - /** - * Confirm and prefetch a section. If the section is "all sections", prefetch all the sections. - * - * @param section Section to download. - * @param refresh Refresh clicked (not used). - */ - async prefetch(section: CoreCourseSectionWithStatus): Promise { - section.isCalculating = true; - - try { - await CoreCourseHelper.confirmDownloadSizeSection(this.course!.id, section, this.sections); - - await this.prefetchSection(section, true); - } catch (error) { - // User cancelled or there was an error calculating the size. - if (error) { - CoreDomUtils.showErrorModal(error); - } - } finally { - section.isCalculating = false; - } - } - - /** - * Prefetch a section. - * - * @param section The section to download. - * @param manual Whether the prefetch was started manually or it was automatically started because all modules - * are being downloaded. - */ - protected async prefetchSection(section: CoreCourseSectionWithStatus, manual?: boolean): Promise { - try { - await CoreCourseHelper.prefetchSection(section, this.course!.id, this.sections); - } catch (error) { - // Don't show error message if it's an automatic download. - if (!manual) { - return; - } - - CoreDomUtils.showErrorModalDefault(error, 'core.course.errordownloadingsection', true); - } - } - /** * Refresh the data. * @@ -580,7 +478,6 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { * Component destroyed. */ ngOnDestroy(): void { - this.sectionStatusObserver && this.sectionStatusObserver.off(); this.selectTabObserver && this.selectTabObserver.off(); } @@ -591,17 +488,6 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { this.dynamicComponents?.forEach((component) => { component.callComponentFunction('ionViewDidEnter'); }); - - if (!this.downloadEnabled || !this.course || !this.sections) { - return; - } - - // The download status of a section might have been changed from within a module page. - if (this.selectedSection && this.selectedSection.id !== CoreCourseProvider.ALL_SECTIONS_ID) { - CoreCourseHelper.calculateSectionStatus(this.selectedSection, this.course.id, false, false); - } else { - CoreCourseHelper.calculateSectionsStatus(this.sections, this.course.id, false, false); - } } /** @@ -653,17 +539,6 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { this.updateProgress(); } - /** - * Recalculate the download status of each section, in response to a module being downloaded. - */ - onModuleStatusChange(): void { - if (!this.downloadEnabled || !this.sections || !this.course) { - return; - } - - CoreCourseHelper.calculateSectionsStatus(this.sections, this.course.id, false, false); - } - /** * Update course progress. */ diff --git a/src/core/features/course/components/module/core-course-module.html b/src/core/features/course/components/module/core-course-module.html index 65637562c..fc9db736c 100644 --- a/src/core/features/course/components/module/core-course-module.html +++ b/src/core/features/course/components/module/core-course-module.html @@ -15,7 +15,7 @@

+ [courseId]="module.course" [attr.aria-label]="module.handlerData.a11yTitle + ', ' + modNameTranslated">

{{ 'core.restricted' | translate }} + [courseId]="module.course" class="ion-text-wrap"> @@ -48,13 +48,9 @@
- - - @@ -81,7 +77,7 @@ + contextLevel="module" [contextInstanceId]="module.id" [courseId]="module.course"> diff --git a/src/core/features/course/components/module/module.ts b/src/core/features/course/components/module/module.ts index 82df87061..936901f5f 100644 --- a/src/core/features/course/components/module/module.ts +++ b/src/core/features/course/components/module/module.ts @@ -15,20 +15,13 @@ import { Component, Input, Output, EventEmitter, OnInit, OnDestroy } from '@angular/core'; import { CoreSites } from '@services/sites'; -import { CoreDomUtils } from '@services/utils/dom'; -import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { - CoreCourseHelper, CoreCourseModuleData, CoreCourseModuleCompletionData, CoreCourseSection, } from '@features/course/services/course-helper'; import { CoreCourse } from '@features/course/services/course'; import { CoreCourseModuleDelegate, CoreCourseModuleHandlerButton } from '@features/course/services/module-delegate'; -import { - CoreCourseModulePrefetchDelegate, - CoreCourseModulePrefetchHandler, -} from '@features/course/services/module-prefetch-delegate'; /** * Component to display a module entry in a list of modules. @@ -45,47 +38,20 @@ import { export class CoreCourseModuleComponent implements OnInit, OnDestroy { @Input() module!: CoreCourseModuleData; // The module to render. - @Input() courseId?: number; // The course the module belongs to. @Input() section?: CoreCourseSection; // The section the module belongs to. @Input() showActivityDates = false; // Whether to show activity dates. @Input() showCompletionConditions = false; // Whether to show activity completion conditions. - // eslint-disable-next-line @angular-eslint/no-input-rename - @Input('downloadEnabled') set enabled(value: boolean) { - this.downloadEnabled = value; - - if (!this.module.handlerData?.showDownloadButton || !this.downloadEnabled || this.statusCalculated) { - return; - } - - // First time that the download is enabled. Initialize the data. - this.statusCalculated = true; - this.spinner = true; // Show spinner while calculating the status. - - // Get current status to decide which icon should be shown. - this.calculateAndShowStatus(); - } - @Output() completionChanged = new EventEmitter(); // Notify when module completion changes. - @Output() statusChanged = new EventEmitter(); // Notify when the download status changes. - downloadStatus?: string; - spinner?: boolean; // Whether to display a loading spinner. - downloadEnabled?: boolean; // Whether the download of sections and modules is enabled. modNameTranslated = ''; hasInfo = false; showLegacyCompletion = false; // Whether to show module completion in the old format. showManualCompletion = false; // Whether to show manual completion when completion conditions are disabled. - protected prefetchHandler?: CoreCourseModulePrefetchHandler; - protected statusObserver?: CoreEventObserver; - protected statusCalculated = false; - protected isDestroyed = false; - /** * Component being initialized. */ ngOnInit(): void { - this.courseId = this.courseId || this.module.course; this.modNameTranslated = CoreCourse.translateModuleName(this.module.modname) || ''; this.showLegacyCompletion = !CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.11'); this.checkShowManualCompletion(); @@ -103,29 +69,6 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { (this.showCompletionConditions && this.module.completiondata.isautomatic)) ) ); - - if (this.module.handlerData.showDownloadButton) { - // Listen for changes on this module status, even if download isn't enabled. - this.prefetchHandler = CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor(this.module.modname); - - this.statusObserver = CoreEvents.on(CoreEvents.PACKAGE_STATUS_CHANGED, (data) => { - if (!this.module || data.componentId != this.module.id || !this.prefetchHandler || - data.component != this.prefetchHandler.component) { - return; - } - - // Call determineModuleStatus to get the right status to display. - const status = CoreCourseModulePrefetchDelegate.determineModuleStatus(this.module, data.status); - - if (this.downloadEnabled) { - // Download is enabled, show the status. - this.showStatus(status); - } else if (this.module.handlerData?.updateStatus) { - // Download isn't enabled but the handler defines a updateStatus function, call it anyway. - this.module.handlerData.updateStatus(status); - } - }, CoreSites.getCurrentSiteId()); - } } /** @@ -143,7 +86,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { */ moduleClicked(event: Event): void { if (this.module.uservisible !== false && this.module.handlerData?.action) { - this.module.handlerData.action(event, this.module, this.courseId!); + this.module.handlerData.action(event, this.module, this.module.course); } } @@ -161,91 +104,14 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { event.preventDefault(); event.stopPropagation(); - button.action(event, this.module, this.courseId!); - } - - /** - * Download the module. - * - * @param refresh Whether it's refreshing. - * @return Promise resolved when done. - */ - async download(refresh: boolean): Promise { - if (!this.prefetchHandler || !this.module) { - return; - } - - // Show spinner since this operation might take a while. - this.spinner = true; - - try { - // Get download size to ask for confirm if it's high. - const size = await this.prefetchHandler.getDownloadSize(this.module, this.module.course, true); - - await CoreCourseHelper.prefetchModule(this.prefetchHandler, this.module, size, this.module.course, refresh); - - const eventData = { - sectionId: this.section?.id, - moduleId: this.module.id, - courseId: this.module.course, - }; - this.statusChanged.emit(eventData); - } catch (error) { - // Error, hide spinner. - this.spinner = false; - if (!this.isDestroyed) { - CoreDomUtils.showErrorModalDefault(error, 'core.errordownloading', true); - } - } - } - - /** - * Show download buttons according to module status. - * - * @param status Module status. - */ - protected showStatus(status: string): void { - if (!status) { - return; - } - - this.spinner = false; - this.downloadStatus = status; - - this.module.handlerData?.updateStatus?.(status); - } - - /** - * Calculate and show module status. - * - * @return Promise resolved when done. - */ - protected async calculateAndShowStatus(): Promise { - if (!this.module || !this.courseId) { - return; - } - - const status = await CoreCourseModulePrefetchDelegate.getModuleStatus(this.module, this.courseId); - - this.showStatus(status); + button.action(event, this.module, this.module.course); } /** * Component destroyed. */ ngOnDestroy(): void { - // this.statusObserver?.off(); this.module.handlerData?.onDestroy?.(); - this.isDestroyed = true; } } - -/** - * Data sent to the status changed output. - */ -export type CoreCourseModuleStatusChangedData = { - moduleId: number; - courseId: number; - sectionId?: number; -}; diff --git a/src/core/features/course/format/singleactivity/components/core-course-format-single-activity.html b/src/core/features/course/format/singleactivity/components/core-course-format-single-activity.html index 17cf0dd0f..68eedcebf 100644 --- a/src/core/features/course/format/singleactivity/components/core-course-format-single-activity.html +++ b/src/core/features/course/format/singleactivity/components/core-course-format-single-activity.html @@ -1,4 +1,4 @@ - + diff --git a/src/core/features/course/format/singleactivity/components/singleactivity.ts b/src/core/features/course/format/singleactivity/components/singleactivity.ts index 3fd7cf5c0..01da69058 100644 --- a/src/core/features/course/format/singleactivity/components/singleactivity.ts +++ b/src/core/features/course/format/singleactivity/components/singleactivity.ts @@ -36,7 +36,6 @@ export class CoreCourseFormatSingleActivityComponent implements OnChanges { @Input() course?: CoreCourseAnyCourseData; // The course to render. @Input() sections?: CoreCourseSectionWithStatus[]; // List of course sections. - @Input() downloadEnabled?: boolean; // Whether the download of sections and modules is enabled. @Input() initialSectionId?: number; // The section to load first (by ID). @Input() initialSectionNumber?: number; // The section to load first (by number). @Input() moduleId?: number; // The module ID to scroll to. Must be inside the initial selected section. diff --git a/src/core/features/course/format/singleactivity/services/handlers/singleactivity-format.ts b/src/core/features/course/format/singleactivity/services/handlers/singleactivity-format.ts index 3ce49d231..945b99e4c 100644 --- a/src/core/features/course/format/singleactivity/services/handlers/singleactivity-format.ts +++ b/src/core/features/course/format/singleactivity/services/handlers/singleactivity-format.ts @@ -68,13 +68,6 @@ export class CoreCourseFormatSingleActivityHandlerService implements CoreCourseF return ''; } - /** - * @inheritdoc - */ - displayEnableDownload(): boolean { - return false; - } - /** * @inheritdoc */ diff --git a/src/core/features/course/pages/contents/contents.html b/src/core/features/course/pages/contents/contents.html index 9c1633cad..1f6b46f1c 100644 --- a/src/core/features/course/pages/contents/contents.html +++ b/src/core/features/course/pages/contents/contents.html @@ -1,12 +1,5 @@ - - - - @@ -22,8 +15,7 @@ + [moduleId]="moduleId" (completionChanged)="onCompletionChange($event)" class="core-course-format-{{course.format}}"> diff --git a/src/core/features/course/pages/contents/contents.ts b/src/core/features/course/pages/contents/contents.ts index 03662c5b4..43bbcfb2d 100644 --- a/src/core/features/course/pages/contents/contents.ts +++ b/src/core/features/course/pages/contents/contents.ts @@ -15,20 +15,17 @@ import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core'; import { IonContent, IonRefresher } from '@ionic/angular'; -import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; -import { CoreCourses, CoreCourseAnyCourseData, CoreCoursesProvider } from '@features/courses/services/courses'; +import { CoreCourses, CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourse, CoreCourseCompletionActivityStatus, - CoreCourseProvider, } from '@features/course/services/course'; import { CoreCourseHelper, CoreCourseModuleCompletionData, CoreCourseSection, - CorePrefetchStatusInfo, } from '@features/course/services/course-helper'; import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; @@ -43,7 +40,6 @@ import { CoreEventObserver, } from '@singletons/events'; import { CoreNavigator } from '@services/navigator'; -import { CoreConstants } from '@/core/constants'; /** * Page that displays the contents of a course. @@ -63,47 +59,19 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { sectionNumber?: number; courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = []; dataLoaded = false; - downloadEnabled = false; downloadCourseEnabled = false; moduleId?: number; displayEnableDownload = false; displayRefresher = false; - prefetchCourseData: CorePrefetchStatusInfo = { - icon: CoreConstants.ICON_LOADING, - statusTranslatable: 'core.course.downloadcourse', - status: '', - loading: true, - }; protected formatOptions?: Record; protected completionObserver?: CoreEventObserver; - protected courseStatusObserver?: CoreEventObserver; - protected siteUpdatedObserver?: CoreEventObserver; - protected downloadEnabledObserver?: CoreEventObserver; protected syncObserver?: CoreEventObserver; protected isDestroyed = false; protected modulesHaveCompletion = false; - protected isGuest?: boolean; + protected isGuest = false; protected debouncedUpdateCachedCompletion?: () => void; // Update the cached completion after a certain time. - constructor() { - // Refresh the enabled flags if site is updated. - this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { - this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); - - this.displayEnableDownload = !CoreSites.getRequiredCurrentSite().isOfflineDisabled() && - CoreCourseFormatDelegate.displayEnableDownload(this.course); - - this.downloadEnabled = this.displayEnableDownload && this.downloadEnabled; - - this.initListeners(); - }, CoreSites.getCurrentSiteId()); - - this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => { - this.downloadEnabled = this.displayEnableDownload && data.enabled; - }); - } - /** * @inheritdoc */ @@ -121,13 +89,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { this.sectionId = CoreNavigator.getRouteNumberParam('sectionId'); this.sectionNumber = CoreNavigator.getRouteNumberParam('sectionNumber'); this.moduleId = CoreNavigator.getRouteNumberParam('moduleId'); - this.isGuest = CoreNavigator.getRouteBooleanParam('isGuest'); - - this.displayEnableDownload = !CoreSites.getRequiredCurrentSite().isOfflineDisabled() && - CoreCourseFormatDelegate.displayEnableDownload(this.course); - this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); - - this.downloadEnabled = this.displayEnableDownload && CoreCourses.getCourseDownloadOptionsEnabled(); + this.isGuest = !!CoreNavigator.getRouteBooleanParam('isGuest'); this.debouncedUpdateCachedCompletion = CoreUtils.debounce(() => { if (this.modulesHaveCompletion) { @@ -149,8 +111,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { await this.loadData(false, true); this.dataLoaded = true; - - this.initPrefetch(); } /** @@ -159,15 +119,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { * @return Promise resolved when done. */ protected async initListeners(): Promise { - if (this.downloadCourseEnabled && !this.courseStatusObserver) { - // Listen for changes in course status. - this.courseStatusObserver = CoreEvents.on(CoreEvents.COURSE_STATUS_CHANGED, (data) => { - if (data.courseId == this.course.id || data.courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { - this.updateCourseStatus(data.status); - } - }, CoreSites.getCurrentSiteId()); - } - // Check if the course format requires the view to be refreshed when completion changes. const shouldRefresh = await CoreCourseFormatDelegate.shouldRefreshWhenCompletionChanges(this.course); if (!shouldRefresh) { @@ -200,41 +151,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { } } - /** - * Init prefetch data if needed. - * - * @return Promise resolved when done. - */ - protected async initPrefetch(): Promise { - if (!this.downloadCourseEnabled) { - // Cannot download the whole course, stop. - return; - } - - // Determine the course prefetch status. - await this.determineCoursePrefetchIcon(); - - if (this.prefetchCourseData.icon != CoreConstants.ICON_LOADING) { - return; - } - - // Course is being downloaded. Get the download promise. - const promise = CoreCourseHelper.getCourseDownloadPromise(this.course.id); - if (promise) { - // There is a download promise. Show an error if it fails. - promise.catch((error) => { - if (!this.isDestroyed) { - CoreDomUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true); - } - }); - } else { - // No download, this probably means that the app was closed while downloading. Set previous status. - const status = await CoreCourse.setCoursePreviousStatus(this.course.id); - - this.updateCourseStatus(status); - } - } - /** * Fetch and load all the data required for the view. * @@ -463,59 +379,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { } } - /** - * Determines the prefetch icon of the course. - * - * @return Promise resolved when done. - */ - protected async determineCoursePrefetchIcon(): Promise { - this.prefetchCourseData = await CoreCourseHelper.getCourseStatusIconAndTitle(this.course.id); - } - - /** - * Prefetch the whole course. - */ - async prefetchCourse(): Promise { - try { - await CoreCourseHelper.confirmAndPrefetchCourse( - this.prefetchCourseData, - this.course, - { - sections: this.sections, - menuHandlers: this.courseMenuHandlers, - isGuest: this.isGuest, - }, - ); - } catch (error) { - if (this.isDestroyed) { - return; - } - - CoreDomUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true); - } - } - - /** - * Toggle download enabled. - */ - toggleDownload(): void { - CoreCourses.setCourseDownloadOptionsEnabled(this.downloadEnabled); - } - - /** - * Update the course status icon and title. - * - * @param status Status to show. - */ - protected updateCourseStatus(status: string): void { - const statusData = CoreCourseHelper.getCoursePrefetchStatusInfo(status); - - this.prefetchCourseData.status = statusData.status; - this.prefetchCourseData.icon = statusData.icon; - this.prefetchCourseData.statusTranslatable = statusData.statusTranslatable; - this.prefetchCourseData.loading = statusData.loading; - } - /** * Open the course summary */ @@ -542,10 +405,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { ngOnDestroy(): void { this.isDestroyed = true; this.completionObserver?.off(); - this.courseStatusObserver?.off(); this.syncObserver?.off(); - this.siteUpdatedObserver?.off(); - this.downloadEnabledObserver?.off(); } /** diff --git a/src/core/features/course/pages/list-mod-type/list-mod-type.html b/src/core/features/course/pages/list-mod-type/list-mod-type.html index 1d6d7d2aa..d0cf3b7d1 100644 --- a/src/core/features/course/pages/list-mod-type/list-mod-type.html +++ b/src/core/features/course/pages/list-mod-type/list-mod-type.html @@ -19,8 +19,7 @@ - + diff --git a/src/core/features/course/pages/list-mod-type/list-mod-type.page.ts b/src/core/features/course/pages/list-mod-type/list-mod-type.page.ts index 38e6cccf2..fde5d1830 100644 --- a/src/core/features/course/pages/list-mod-type/list-mod-type.page.ts +++ b/src/core/features/course/pages/list-mod-type/list-mod-type.page.ts @@ -14,7 +14,6 @@ import { Component, OnInit } from '@angular/core'; -import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreCourse } from '@features/course/services/course'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; @@ -36,7 +35,6 @@ export class CoreCourseListModTypePage implements OnInit { sections: CoreCourseSection[] = []; title = ''; loaded = false; - downloadEnabled = false; courseId?: number; protected modName?: string; @@ -49,7 +47,6 @@ export class CoreCourseListModTypePage implements OnInit { this.title = CoreNavigator.getRouteParam('title') || ''; this.courseId = CoreNavigator.getRouteNumberParam('courseId'); this.modName = CoreNavigator.getRouteParam('modName'); - this.downloadEnabled = !CoreSites.getCurrentSite()?.isOfflineDisabled(); try { await this.fetchData(); diff --git a/src/core/features/course/services/format-delegate.ts b/src/core/features/course/services/format-delegate.ts index b2ecc2f13..295691a0e 100644 --- a/src/core/features/course/services/format-delegate.ts +++ b/src/core/features/course/services/format-delegate.ts @@ -58,8 +58,9 @@ export interface CoreCourseFormatHandler extends CoreDelegateHandler { displayBlocks?(course: CoreCourseAnyCourseData): boolean; /** - * Whether the option to enable section/module download should be displayed. Defaults to true. + * Whether the option to enable section/module download should be displayed. * + * @deprecated on 4.0 Not used anymore because prefetch has been moved to storage manager. * @param course The course to check. * @return Whether the option to enable section/module download should be displayed. */ @@ -204,16 +205,6 @@ export class CoreCourseFormatDelegateService extends CoreDelegate(course.format || '', 'displayBlocks', [course]); } - /** - * Whether the option to enable section/module download should be displayed. Defaults to true. - * - * @param course The course to check. - * @return Whether the option to enable section/module download should be displayed - */ - displayEnableDownload(course: CoreCourseAnyCourseData): boolean { - return !!this.executeFunctionOnEnabled(course.format || '', 'displayEnableDownload', [course]); - } - /** * Whether the course refresher should be displayed. If it returns false, a refresher must be included in the course format, * and the doRefresh method of CoreCourseSectionPage must be called on refresh. Defaults to true. diff --git a/src/core/features/course/services/handlers/default-format.ts b/src/core/features/course/services/handlers/default-format.ts index c84073a96..4ef53ca4b 100644 --- a/src/core/features/course/services/handlers/default-format.ts +++ b/src/core/features/course/services/handlers/default-format.ts @@ -78,17 +78,6 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler { return true; } - /** - * Whether the option to enable section/module download should be displayed. Defaults to true. - * - * @param course The course to check. - * @return Whether the option to enable section/module download should be displayed - */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars - displayEnableDownload(course: CoreCourseAnyCourseData): boolean { - return true; - } - /** * Whether the default section selector should be displayed. Defaults to true. * diff --git a/src/core/features/courses/pages/dashboard/dashboard.html b/src/core/features/courses/pages/dashboard/dashboard.html index ee5fb7421..4e704d5e8 100644 --- a/src/core/features/courses/pages/dashboard/dashboard.html +++ b/src/core/features/courses/pages/dashboard/dashboard.html @@ -23,7 +23,7 @@ - + diff --git a/src/core/features/sitehome/pages/index/index.html b/src/core/features/sitehome/pages/index/index.html index e7437c3c7..62b96b90c 100644 --- a/src/core/features/sitehome/pages/index/index.html +++ b/src/core/features/sitehome/pages/index/index.html @@ -3,8 +3,6 @@ - - + @@ -54,7 +51,7 @@ - + @@ -73,8 +70,7 @@ - + diff --git a/src/core/features/sitehome/pages/index/index.ts b/src/core/features/sitehome/pages/index/index.ts index 4d6cc23a4..b28c7d648 100644 --- a/src/core/features/sitehome/pages/index/index.ts +++ b/src/core/features/sitehome/pages/index/index.ts @@ -21,7 +21,7 @@ import { CoreCourse, CoreCourseWSSection } from '@features/course/services/cours import { CoreDomUtils } from '@services/utils/dom'; import { CoreSites } from '@services/sites'; import { CoreSiteHome } from '@features/sitehome/services/sitehome'; -import { CoreCourses, CoreCoursesProvider } from '@features//courses/services/courses'; +import { CoreCourses } from '@features//courses/services/courses'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreCourseHelper, CoreCourseModuleData } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; @@ -50,24 +50,15 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy { siteHomeId = 1; currentSite!: CoreSite; searchEnabled = false; - displayEnableDownload = false; - downloadEnabled = false; newsForumModule?: CoreCourseModuleData; protected updateSiteObserver: CoreEventObserver; - protected downloadEnabledObserver: CoreEventObserver; constructor() { // Refresh the enabled flags if site is updated. this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite(); - - this.displayEnableDownload = !CoreSites.getRequiredCurrentSite().isOfflineDisabled(); }, CoreSites.getCurrentSiteId()); - - this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => { - this.downloadEnabled = data.enabled; - }); } /** @@ -85,9 +76,6 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy { CoreCourseHelper.openModule(module, this.siteHomeId, undefined, modParams); } - this.displayEnableDownload = !CoreSites.getRequiredCurrentSite().isOfflineDisabled(); - this.downloadEnabled = CoreCourses.getCourseDownloadOptionsEnabled(); - this.loadContent().finally(() => { this.dataLoaded = true; }); @@ -186,13 +174,6 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy { }); } - /** - * Switch download enabled. - */ - switchDownload(): void { - CoreCourses.setCourseDownloadOptionsEnabled(this.downloadEnabled); - } - /** * Open page to manage courses storage. */ @@ -240,7 +221,6 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy { */ ngOnDestroy(): void { this.updateSiteObserver.off(); - this.downloadEnabledObserver.off(); } } diff --git a/src/core/features/siteplugins/classes/handlers/course-format-handler.ts b/src/core/features/siteplugins/classes/handlers/course-format-handler.ts index 1878f6186..89cfaff07 100644 --- a/src/core/features/siteplugins/classes/handlers/course-format-handler.ts +++ b/src/core/features/siteplugins/classes/handlers/course-format-handler.ts @@ -35,13 +35,6 @@ export class CoreSitePluginsCourseFormatHandler extends CoreSitePluginsBaseHandl return this.handlerSchema.canviewallsections ?? true; } - /** - * @inheritdoc - */ - displayEnableDownload(): boolean { - return this.handlerSchema.displayenabledownload ?? true; - } - /** * @inheritdoc */ diff --git a/upgrade.txt b/upgrade.txt index b373c0db4..ddb9fc2c5 100644 --- a/upgrade.txt +++ b/upgrade.txt @@ -9,6 +9,7 @@ information provided here is intended especially for developers. - CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor now admits module name instead of full module object. - CoreCourse.getModuleBasicInfoByInstance and CoreCourse.getModuleBasicInfo have been modified to accept an "options" parameter instead of only siteId. - The function CoreFilepool.isFileDownloadingByUrl now returns Promise instead of relying on resolve/reject. +- downloadEnabled input has been removed from CoreBlockSideBlocksComponent, CoreCourseFormatComponent, CoreCourseFormatSingleActivityComponent and CoreCourseModuleComponent. === 3.9.5 ===