From 7a761fd47ffe3c4a104dbd9fecfc14fff1fe3c84 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 24 Apr 2023 13:23:02 +0200 Subject: [PATCH] MOBILE-4282 course: Respect indentation format --- .../components/course-index/course-index.ts | 4 +++- .../course/components/module/module.ts | 3 ++- src/core/features/course/services/course.ts | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/core/features/course/components/course-index/course-index.ts b/src/core/features/course/components/course-index/course-index.ts index e78855a22..cafce1827 100644 --- a/src/core/features/course/components/course-index/course-index.ts +++ b/src/core/features/course/components/course-index/course-index.ts @@ -14,6 +14,7 @@ import { Component, ElementRef, Input, OnInit } from '@angular/core'; import { + CoreCourse, CoreCourseModuleCompletionStatus, CoreCourseModuleCompletionTracking, CoreCourseProvider, @@ -77,7 +78,8 @@ export class CoreCourseCourseIndexComponent implements OnInit { // Clone sections to add information. const site = CoreSites.getRequiredCurrentSite(); - const enableIndentation = site.isVersionGreaterEqualThan('4.2'); + + const enableIndentation = await CoreCourse.isCourseIndentationEnabled(site, this.course.id); this.sectionsToRender = this.sections .filter((section) => !CoreCourseHelper.isSectionStealth(section)) diff --git a/src/core/features/course/components/module/module.ts b/src/core/features/course/components/module/module.ts index 8d9863dda..00b9ea2e0 100644 --- a/src/core/features/course/components/module/module.ts +++ b/src/core/features/course/components/module/module.ts @@ -71,8 +71,9 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { */ async ngOnInit(): Promise { const site = CoreSites.getRequiredCurrentSite(); + const enableIndentation = await CoreCourse.isCourseIndentationEnabled(site, this.module.course); - this.indented = site.isVersionGreaterEqualThan('4.2') && this.module.indent > 0; + this.indented = enableIndentation && this.module.indent > 0; this.modNameTranslated = CoreCourse.translateModuleName(this.module.modname, this.module.modplural); this.showLegacyCompletion = this.showLegacyCompletion ?? CoreConstants.CONFIG.uselegacycompletion ?? diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index a2a18b9c7..f7506171e 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -33,6 +33,7 @@ import { CoreCourseOffline } from './course-offline'; import { CoreError } from '@classes/errors/error'; import { CoreCourseAnyCourseData, + CoreCourses, CoreCoursesProvider, } from '../../courses/services/courses'; import { CoreDomUtils } from '@services/utils/dom'; @@ -250,6 +251,28 @@ export class CoreCourseProvider { completion.state === CoreCourseModuleCompletionStatus.COMPLETION_INCOMPLETE; } + /** + * Check whether a course has indentation enabled. + * + * @param site Site. + * @param courseId Course id. + * @returns Whether indentation is enabled. + */ + async isCourseIndentationEnabled(site: CoreSite, courseId: number): Promise { + if (!site.isVersionGreaterEqualThan('4.0')) { + return false; + } + + const course = await CoreCourses.getCourseByField('id', courseId, site.id); + const formatOptions = CoreUtils.objectToKeyValueMap<{ indentation?: string }>( + course.courseformatoptions ?? [], + 'name', + 'value', + ); + + return formatOptions.indentation === '1'; + } + /** * Clear all courses status in a site. *