Merge pull request #2474 from dpalou/MOBILE-3493

MOBILE-3493 course: Don't display selector if course only has one sec…
main
Juan Leyva 2020-08-24 17:32:51 +02:00 committed by GitHub
commit 74dc84b55b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -11,7 +11,7 @@
<core-loading [hideUntil]="loaded">
<!-- Section selector. -->
<core-dynamic-component [component]="sectionSelectorComponent" [data]="data">
<div text-wrap *ngIf="displaySectionSelector && sections && sections.length" padding class="clearfix" ion-row justify-content-between class="safe-padding-horizontal core-button-selector-row" [class.core-section-download]="downloadEnabled">
<div text-wrap *ngIf="displaySectionSelector && sections && hasSeveralSections" padding class="clearfix" ion-row justify-content-between class="safe-padding-horizontal core-button-selector-row" [class.core-section-download]="downloadEnabled">
<button float-start ion-button icon-start icon-end (click)="showSectionSelector($event)" color="light" class="core-button-select button-no-uppercase" ion-col [attr.aria-label]="('core.course.sections' | translate) + ': ' + (selectedSection && (selectedSection.formattedName || selectedSection.name))" aria-haspopup="true" [attr.aria-expanded]="sectionSelectorExpanded" aria-controls="core-course-section-selector" id="core-course-section-button">
<core-icon name="fa-folder"></core-icon>
<span class="core-button-select-text">{{selectedSection && (selectedSection.formattedName || selectedSection.name) || 'core.course.sections' | translate }}</span>

View File

@ -76,6 +76,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
stealthModulesSectionId: number = CoreCourseProvider.STEALTH_MODULES_SECTION_ID;
selectOptions: any = {};
loaded: boolean;
hasSeveralSections: boolean;
protected sectionStatusObserver;
protected selectTabObserver;
@ -171,9 +172,16 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
}
if (changes.sections && this.sections) {
const hasAllSections = this.sections[0].id == CoreCourseProvider.ALL_SECTIONS_ID;
this.hasSeveralSections = this.sections.length > 2 || (this.sections.length == 2 && !hasAllSections);
if (!this.selectedSection) {
// There is no selected section yet, calculate which one to load.
if (this.initialSectionId || this.initialSectionNumber) {
if (!this.hasSeveralSections) {
// Always load "All sections" to display the section title. If it isn't there just load the section.
this.loaded = true;
this.sectionChanged(this.sections[0]);
} else if (this.initialSectionId || this.initialSectionNumber) {
// We have an input indicating the section ID to load. Search the section.
for (let i = 0; i < this.sections.length; i++) {
const section = this.sections[i];