Skip to content

Commit a0cf5bf

Browse files
committed
MOBILE-4660 course: Count subsections in download progress
1 parent d1856f5 commit a0cf5bf

File tree

2 files changed

+61
-11
lines changed

2 files changed

+61
-11
lines changed

src/addons/storagemanager/pages/course-storage/course-storage.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ <h1>{{ 'addon.storagemanager.coursedownloads' | translate }}</h1>
7474
</ion-badge>
7575
<!-- Download progress. -->
7676
<p *ngIf="downloadEnabled && section.isDownloading">
77-
<core-progress-bar [progress]="section.total === 0 ? -1 : (section.count / section.total) * 100" />
77+
<core-progress-bar
78+
[progress]="section.total === undefined || section.total === 0 ? -1 : (section.count / section.total) * 100" />
7879
</p>
7980
</ion-label>
8081
<div class="storage-buttons" slot="end" *ngIf="(!section.calculatingSize && section.totalSize > 0) || downloadEnabled">
@@ -86,7 +87,7 @@ <h1>{{ 'addon.storagemanager.coursedownloads' | translate }}</h1>
8687
[statusSubject]="section.name" />
8788

8889
<ion-badge class="core-course-download-section-progress"
89-
*ngIf="section.isDownloading && section.count < section.total" role="progressbar"
90+
*ngIf="section.isDownloading && section.total !== undefined && section.count < section.total" role="progressbar"
9091
[attr.aria-valuemax]="section.total" [attr.aria-valuenow]="section.count"
9192
[attr.aria-valuetext]="'core.course.downloadsectionprogressdescription' | translate:section">
9293
{{section.count}} / {{section.total}}

src/core/features/course/services/course-helper.ts

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,12 @@ export class CoreCourseHelperProvider {
318318
// Set this section data.
319319
if (statusData.status !== DownloadStatus.DOWNLOADING) {
320320
sectionWithStatus.isDownloading = false;
321-
sectionWithStatus.total = 0;
321+
this.resetSectionDownloadCount(section);
322322
} else {
323323
// Section is being downloaded.
324324
sectionWithStatus.isDownloading = true;
325325
CoreCourseModulePrefetchDelegate.setOnProgress(downloadId, (data) => {
326-
sectionWithStatus.count = data.count;
327-
sectionWithStatus.total = data.total;
326+
this.setSectionDownloadCount(sectionWithStatus, data.count, data.total);
328327
});
329328
}
330329

@@ -1757,9 +1756,15 @@ export class CoreCourseHelperProvider {
17571756
await this.prefetchSingleSection(section, result, courseId);
17581757
};
17591758

1759+
this.setSectionDownloadCount(section, 0, subsections.length, true);
1760+
17601761
await Promise.all([
17611762
syncAndPrefetchModules(),
1762-
Promise.all(subsections.map(subsection => this.prefetchSingleSectionIfNeeded(subsection, courseId))),
1763+
Promise.all(subsections.map(async (subsection) => {
1764+
await this.prefetchSingleSectionIfNeeded(subsection, courseId);
1765+
1766+
this.setSectionDownloadCount(section, (section.subsectionCount ?? 0) + 1, subsections.length, true);
1767+
})),
17631768
]);
17641769
}
17651770

@@ -1781,7 +1786,7 @@ export class CoreCourseHelperProvider {
17811786
return;
17821787
}
17831788

1784-
if (section.total && section.total > 0) {
1789+
if (section.moduleTotal && section.moduleTotal > 0) {
17851790
// Already being downloaded.
17861791
return ;
17871792
}
@@ -1795,8 +1800,7 @@ export class CoreCourseHelperProvider {
17951800

17961801
// Prefetch all modules to prevent incoeherences in download count and to download stale data not marked as outdated.
17971802
await CoreCourseModulePrefetchDelegate.prefetchModules(downloadId, modules, courseId, (data) => {
1798-
section.count = data.count;
1799-
section.total = data.total;
1803+
this.setSectionDownloadCount(section, data.count, data.total);
18001804
});
18011805
}
18021806

@@ -2154,6 +2158,47 @@ export class CoreCourseHelperProvider {
21542158
return sections.concat(subsections);
21552159
}
21562160

2161+
/**
2162+
* Reset download counts of a section.
2163+
*
2164+
* @param section Section.
2165+
*/
2166+
protected resetSectionDownloadCount(section: CoreCourseSectionWithStatus): void {
2167+
section.moduleTotal = undefined;
2168+
section.subsectionTotal = undefined;
2169+
section.moduleCount = undefined;
2170+
section.subsectionCount = undefined;
2171+
section.total = undefined;
2172+
}
2173+
2174+
/**
2175+
* Set download counts of a section.
2176+
*
2177+
* @param section Section.
2178+
* @param count Count value.
2179+
* @param total Total value.
2180+
* @param isSubsectionCount True to set subsection count, false to set module count.
2181+
*/
2182+
protected setSectionDownloadCount(
2183+
section: CoreCourseSectionWithStatus,
2184+
count: number,
2185+
total: number,
2186+
isSubsectionCount = false,
2187+
): void {
2188+
if (isSubsectionCount) {
2189+
section.subsectionCount = count;
2190+
section.subsectionTotal = total;
2191+
} else {
2192+
section.moduleCount = count;
2193+
section.moduleTotal = total;
2194+
}
2195+
2196+
section.count = section.moduleCount !== undefined && section.subsectionCount !== undefined ?
2197+
section.moduleCount + section.subsectionCount : undefined;
2198+
section.total = section.moduleTotal !== undefined && section.subsectionTotal !== undefined ?
2199+
section.moduleTotal + section.subsectionTotal : undefined;
2200+
}
2201+
21572202
}
21582203

21592204
export const CoreCourseHelper = makeSingleton(CoreCourseHelperProvider);
@@ -2172,8 +2217,12 @@ export type CoreCourseSection = Omit<CoreCourseWSSection, 'contents'> & {
21722217
export type CoreCourseSectionWithStatus = CoreCourseSection & {
21732218
downloadStatus?: DownloadStatus; // Section status.
21742219
isDownloading?: boolean; // Whether section is being downloaded.
2175-
total?: number; // Total of modules being downloaded.
2176-
count?: number; // Number of downloaded modules.
2220+
total?: number; // Total of modules and subsections being downloaded.
2221+
count?: number; // Number of downloaded modules and subsections.
2222+
moduleTotal?: number; // Total of modules being downloaded.
2223+
moduleCount?: number; // Number of downloaded modules.
2224+
subsectionTotal?: number; // Total of subsections being downloaded.
2225+
subsectionCount?: number; // Number of downloaded subsections.
21772226
isCalculating?: boolean; // Whether status is being calculated.
21782227
};
21792228

0 commit comments

Comments
 (0)