MOBILE-4282 course: Respect indentation format
parent
f019afa920
commit
7a761fd47f
|
@ -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))
|
||||
|
|
|
@ -71,8 +71,9 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
|
|||
*/
|
||||
async ngOnInit(): Promise<void> {
|
||||
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 ??
|
||||
|
|
|
@ -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<boolean> {
|
||||
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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue