From 0298273fc4c62b88b8473790d64cbaf976d6d246 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 29 Mar 2022 12:39:18 +0200 Subject: [PATCH] MOBILE-3833 course: Collapse sections in downloads page --- .../pages/course-storage/course-storage.html | 84 ++++++++++--------- .../pages/course-storage/course-storage.ts | 30 ++++++- .../course-format/course-format.html | 5 ++ .../components/course-format/course-format.ts | 64 +++++++++----- .../components/course-index/course-index.html | 56 +++++++------ .../course/pages/contents/contents.html | 5 -- .../course/pages/contents/contents.ts | 8 -- 7 files changed, 152 insertions(+), 100 deletions(-) diff --git a/src/addons/storagemanager/pages/course-storage/course-storage.html b/src/addons/storagemanager/pages/course-storage/course-storage.html index 57b45f33c..2df7b3282 100644 --- a/src/addons/storagemanager/pages/course-storage/course-storage.html +++ b/src/addons/storagemanager/pages/course-storage/course-storage.html @@ -47,7 +47,13 @@ - + + +

- - - - - - -

- - -

- - - {{ module.totalSize | coreBytesToSize }} - - - {{ 'core.calculating' | translate }} - -
+ + + + + + + +

+ + +

+ + + {{ module.totalSize | coreBytesToSize }} + + + {{ 'core.calculating' | translate }} + +
-
- - - - - - -
-
+
+ + + + + + +
+
+
diff --git a/src/addons/storagemanager/pages/course-storage/course-storage.ts b/src/addons/storagemanager/pages/course-storage/course-storage.ts index 39c3d42d0..6aa817913 100644 --- a/src/addons/storagemanager/pages/course-storage/course-storage.ts +++ b/src/addons/storagemanager/pages/course-storage/course-storage.ts @@ -13,7 +13,7 @@ // limitations under the License. import { CoreConstants } from '@/core/constants'; -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core'; import { CoreCourse, CoreCourseProvider } from '@features/course/services/course'; import { CoreCourseHelper, @@ -30,6 +30,7 @@ import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; import { Translate } from '@singletons'; +import { CoreDom } from '@singletons/dom'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; /** @@ -62,6 +63,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { statusDownloaded = CoreConstants.DOWNLOADED; + protected initialSectionId?: number; protected siteUpdatedObserver?: CoreEventObserver; protected courseStatusObserver?: CoreEventObserver; protected sectionStatusObserver?: CoreEventObserver; @@ -69,7 +71,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { protected isDestroyed = false; protected isGuest = false; - constructor() { + constructor(protected elementRef: ElementRef) { // Refresh the enabled flags if site is updated. this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); @@ -100,16 +102,19 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { } this.isGuest = !!CoreNavigator.getRouteBooleanParam('isGuest'); + this.initialSectionId = CoreNavigator.getRouteNumberParam('sectionId'); this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); this.downloadEnabled = !CoreSites.getRequiredCurrentSite().isOfflineDisabled(); - const sections = await CoreCourse.getSections(this.courseId, false, true); + const sections = (await CoreCourse.getSections(this.courseId, false, true)) + .filter((section) => !CoreCourseHelper.isSectionStealth(section)); this.sections = (await CoreCourseHelper.addHandlerDataForModules(sections, this.courseId)).sections .map(section => ({ ...section, totalSize: 0, calculatingSize: true, + expanded: section.id === this.initialSectionId, modules: section.modules.map(module => ({ ...module, calculatingSize: true, @@ -118,6 +123,12 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { this.loaded = true; + CoreDom.scrollToElement( + this.elementRef.nativeElement, + '.core-course-storage-section-expanded', + { addYAxis: -10 }, + ); + await Promise.all([ this.initSizes(), this.initCoursePrefetch(), @@ -641,6 +652,18 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { } } + /** + * Toggle expand status. + * + * @param event Event object. + * @param section Section to expand / collapse. + */ + toggleExpand(event: Event, section: AddonStorageManagerCourseSection): void { + section.expanded = !section.expanded; + event.stopPropagation(); + event.preventDefault(); + } + /** * @inheritdoc */ @@ -663,6 +686,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { type AddonStorageManagerCourseSection = Omit & { totalSize: number; calculatingSize: boolean; + expanded: boolean; modules: AddonStorageManagerModule[]; }; diff --git a/src/core/features/course/components/course-format/course-format.html b/src/core/features/course/components/course-format/course-format.html index 2d8cd3391..4031d1654 100644 --- a/src/core/features/course/components/course-format/course-format.html +++ b/src/core/features/course/components/course-format/course-format.html @@ -1,3 +1,8 @@ + + + + + diff --git a/src/core/features/course/components/course-format/course-format.ts b/src/core/features/course/components/course-format/course-format.ts index dca3d5443..c1bee68f6 100644 --- a/src/core/features/course/components/course-format/course-format.ts +++ b/src/core/features/course/components/course-format/course-format.ts @@ -391,29 +391,38 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { ); } + /** + * Get selected section ID. If viewing all sections, use current scrolled section. + * + * @return Section ID, undefined if not found. + */ + protected async getSelectedSectionId(): Promise { + if (this.selectedSection?.id !== this.allSectionsId) { + return this.selectedSection?.id; + } + + // Check current scrolled section. + const allSectionElements: NodeListOf = + this.elementRef.nativeElement.querySelectorAll('section.core-course-module-list-wrapper'); + + const scroll = await this.content.getScrollElement(); + const containerTop = scroll.getBoundingClientRect().top; + + const element = Array.from(allSectionElements).find((element) => { + const position = element.getBoundingClientRect(); + + // The bottom is inside the container or lower. + return position.bottom >= containerTop; + }); + + return Number(element?.getAttribute('id')) || undefined; + } + /** * Display the course index modal. */ async openCourseIndex(): Promise { - let selectedId = this.selectedSection?.id; - - if (selectedId == this.allSectionsId) { - // Check current scrolled section. - const allSectionElements: NodeListOf = - this.elementRef.nativeElement.querySelectorAll('section.section-wrapper'); - - const scroll = await this.content.getScrollElement(); - const containerTop = scroll.getBoundingClientRect().top; - - const element = Array.from(allSectionElements).find((element) => { - const position = element.getBoundingClientRect(); - - // The bottom is inside the container or lower. - return position.bottom >= containerTop; - }); - - selectedId = Number(element?.getAttribute('id')) || undefined; - } + const selectedId = await this.getSelectedSectionId(); const data = await CoreDomUtils.openModal({ component: CoreCourseCourseIndexComponent, @@ -453,6 +462,23 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { this.moduleId = data.moduleId; } + /** + * Open course downloads page. + */ + async gotoCourseDownloads(): Promise { + const selectedId = await this.getSelectedSectionId(); + + CoreNavigator.navigateToSitePath( + `storage/${this.course.id}`, + { + params: { + title: this.course.fullname, + sectionId: selectedId, + }, + }, + ); + } + /** * Function called when selected section changes. * diff --git a/src/core/features/course/components/course-index/course-index.html b/src/core/features/course/components/course-index/course-index.html index 892a63767..8de92a89b 100644 --- a/src/core/features/course/components/course-index/course-index.html +++ b/src/core/features/course/components/course-index/course-index.html @@ -48,34 +48,36 @@ - - - - - - - - - - - -

- - -

-
- -
+
+ + + + + + + + + + + +

+ + +

+
+ +
+
- +
diff --git a/src/core/features/course/pages/contents/contents.html b/src/core/features/course/pages/contents/contents.html index bc3f404f8..2d0eeb1db 100644 --- a/src/core/features/course/pages/contents/contents.html +++ b/src/core/features/course/pages/contents/contents.html @@ -1,8 +1,3 @@ - - - - - diff --git a/src/core/features/course/pages/contents/contents.ts b/src/core/features/course/pages/contents/contents.ts index 81953a209..7413a0444 100644 --- a/src/core/features/course/pages/contents/contents.ts +++ b/src/core/features/course/pages/contents/contents.ts @@ -366,14 +366,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { } } - gotoCourseDownloads(): void { - CoreNavigator.navigateToSitePath( - `storage/${this.course.id}`, - { params: { title: this.course.fullname } }, - ); - - } - /** * @inheritdoc */