diff --git a/src/core/course/components/format/format.ts b/src/core/course/components/format/format.ts index f084a9e07..a47d48eee 100644 --- a/src/core/course/components/format/format.ts +++ b/src/core/course/components/format/format.ts @@ -246,7 +246,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { */ showSectionSelector(): void { const modal = this.modalCtrl.create('CoreCourseSectionSelectorPage', - {sections: this.sections, selected: this.selectedSection}); + {course: this.course, sections: this.sections, selected: this.selectedSection}); modal.onDidDismiss((newSection) => { if (newSection) { this.sectionChanged(newSection); diff --git a/src/core/course/pages/section-selector/section-selector.html b/src/core/course/pages/section-selector/section-selector.html index 76575b617..93d3d8184 100644 --- a/src/core/course/pages/section-selector/section-selector.html +++ b/src/core/course/pages/section-selector/section-selector.html @@ -13,7 +13,7 @@

- + {{ 'core.course.hiddenfromstudents' | translate }}
diff --git a/src/core/course/pages/section-selector/section-selector.ts b/src/core/course/pages/section-selector/section-selector.ts index c2ed6206f..f438ceef9 100644 --- a/src/core/course/pages/section-selector/section-selector.ts +++ b/src/core/course/pages/section-selector/section-selector.ts @@ -34,24 +34,28 @@ export class CoreCourseSectionSelectorPage { constructor(navParams: NavParams, courseHelper: CoreCourseHelperProvider, private viewCtrl: ViewController) { this.sections = navParams.get('sections'); this.selected = navParams.get('selected'); - this.sections.forEach((section) => { - let complete = 0, - total = 0; - section.modules && section.modules.forEach((module) => { - if (typeof module.completiondata != 'undefined' && - module.completiondata.tracking > CoreCourseProvider.COMPLETION_TRACKING_NONE) { - total++; - if (module.completiondata.state == CoreCourseProvider.COMPLETION_COMPLETE || - module.completiondata.state == CoreCourseProvider.COMPLETION_COMPLETE_PASS) { - complete++; + const course = navParams.get('course'); + + if (course && course.enablecompletion && course.courseformatoptions && course.courseformatoptions.coursedisplay == 1) { + this.sections.forEach((section) => { + let complete = 0, + total = 0; + section.modules && section.modules.forEach((module) => { + if (module.uservisible && typeof module.completiondata != 'undefined' && + module.completiondata.tracking > CoreCourseProvider.COMPLETION_TRACKING_NONE) { + total++; + if (module.completiondata.state == CoreCourseProvider.COMPLETION_COMPLETE || + module.completiondata.state == CoreCourseProvider.COMPLETION_COMPLETE_PASS) { + complete++; + } } + }); + + if (total > 0) { + section.progress = complete / total * 100; } }); - - if (total > 0) { - section.progress = complete / total * 100; - } - }); + } } /** diff --git a/src/core/course/pages/section/section.ts b/src/core/course/pages/section/section.ts index 39ecb6568..c915b4b4e 100644 --- a/src/core/course/pages/section/section.ts +++ b/src/core/course/pages/section/section.ts @@ -19,6 +19,7 @@ import { CoreEventsProvider } from '@providers/events'; import { CoreSitesProvider } from '@providers/sites'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreTextUtilsProvider } from '@providers/utils/text'; +import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreCourseProvider } from '../../providers/course'; import { CoreCourseHelperProvider } from '../../providers/helper'; import { CoreCourseFormatDelegate } from '../../providers/format-delegate'; @@ -72,7 +73,8 @@ export class CoreCourseSectionPage implements OnDestroy { private translate: TranslateService, private courseHelper: CoreCourseHelperProvider, eventsProvider: CoreEventsProvider, private textUtils: CoreTextUtilsProvider, private coursesProvider: CoreCoursesProvider, sitesProvider: CoreSitesProvider, private navCtrl: NavController, private injector: Injector, - private prefetchDelegate: CoreCourseModulePrefetchDelegate, private syncProvider: CoreCourseSyncProvider) { + private prefetchDelegate: CoreCourseModulePrefetchDelegate, private syncProvider: CoreCourseSyncProvider, + private utils: CoreUtilsProvider) { this.course = navParams.get('course'); this.sectionId = navParams.get('sectionId'); this.sectionNumber = navParams.get('sectionNumber'); @@ -275,6 +277,20 @@ export class CoreCourseSectionPage implements OnDestroy { } })); + // Load the course format options when course completion is enabled to show completion progress on sections. + if (this.course.enablecompletion && this.coursesProvider.isGetCoursesByFieldAvailable()) { + promises.push(this.coursesProvider.getCoursesByField('id', this.course.id).catch(() => { + // Ignore errors. + }).then((courses) => { + courses && courses[0] && Object.assign(this.course, courses[0]); + + if (this.course.courseformatoptions) { + this.course.courseformatoptions = this.utils.objectToKeyValueMap(this.course.courseformatoptions, + 'name', 'value'); + } + })); + } + return Promise.all(promises).catch((error) => { this.domUtils.showErrorModalDefault(error, 'core.course.couldnotloadsectioncontent', true); });