MOBILE-2554 course: Add infinite scroll on course all sections
parent
2799bcdd5e
commit
2b3ebc5452
|
@ -29,9 +29,12 @@
|
||||||
</a>
|
</a>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
|
|
||||||
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="$event.waitFor(fetchEvents())">
|
<div *ngIf="canLoadMore" padding>
|
||||||
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
<button ion-button block (click)="fetchEvents()" color="light">{{'core.loadmore' | translate }}</button>
|
||||||
</ion-infinite-scroll>
|
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="$event.waitFor(fetchEvents())">
|
||||||
|
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
||||||
|
</ion-infinite-scroll>
|
||||||
|
</div>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
</core-split-view>
|
</core-split-view>
|
|
@ -15,9 +15,12 @@
|
||||||
<ion-content class="has-footer">
|
<ion-content class="has-footer">
|
||||||
<core-loading [hideUntil]="loaded">
|
<core-loading [hideUntil]="loaded">
|
||||||
<!-- Load previous messages. -->
|
<!-- Load previous messages. -->
|
||||||
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="loadPrevious($event)" position="top">
|
<div *ngIf="canLoadMore" padding>
|
||||||
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="loadPrevious($event)" position="top">
|
||||||
</ion-infinite-scroll>
|
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
||||||
|
</ion-infinite-scroll>
|
||||||
|
<button ion-button block (click)="loadPrevious()" color="light">{{'core.loadmore' | translate }}</button>
|
||||||
|
</div>
|
||||||
<ion-list class="addon-messages-discussion-container" [attr.aria-live]="polite">
|
<ion-list class="addon-messages-discussion-container" [attr.aria-live]="polite">
|
||||||
<ng-container *ngFor="let message of messages; index as index; last as last">
|
<ng-container *ngFor="let message of messages; index as index; last as last">
|
||||||
<ion-chip *ngIf="showDate(message, messages[index - 1])" class="addon-messages-date" color="light">
|
<ion-chip *ngIf="showDate(message, messages[index - 1])" class="addon-messages-date" color="light">
|
||||||
|
|
|
@ -88,9 +88,12 @@
|
||||||
</div>
|
</div>
|
||||||
</core-empty-box>
|
</core-empty-box>
|
||||||
|
|
||||||
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="$event.waitFor(fetchMoreDiscussions())">
|
<div *ngIf="canLoadMore" padding>
|
||||||
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
<button ion-button block (click)="fetchMoreDiscussions()" color="light">{{'core.loadmore' | translate }}</button>
|
||||||
</ion-infinite-scroll>
|
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="$event.waitFor(fetchMoreDiscussions())">
|
||||||
|
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
||||||
|
</ion-infinite-scroll>
|
||||||
|
</div>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
|
|
||||||
<ion-fab bottom end *ngIf="forum && forum.cancreatediscussions">
|
<ion-fab bottom end *ngIf="forum && forum.cancreatediscussions">
|
||||||
|
|
|
@ -56,9 +56,12 @@
|
||||||
|
|
||||||
<core-empty-box *ngIf="!entries.length && !offlineEntries.length" icon="list" [message]="'addon.mod_glossary.noentriesfound' | translate"></core-empty-box>
|
<core-empty-box *ngIf="!entries.length && !offlineEntries.length" icon="list" [message]="'addon.mod_glossary.noentriesfound' | translate"></core-empty-box>
|
||||||
|
|
||||||
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="$event.waitFor(loadMoreEntries())">
|
<div *ngIf="canLoadMore" padding>
|
||||||
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
<button ion-button block (click)="loadMoreEntries()" color="light">{{'core.loadmore' | translate }}</button>
|
||||||
</ion-infinite-scroll>
|
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="$event.waitFor(loadMoreEntries())">
|
||||||
|
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
||||||
|
</ion-infinite-scroll>
|
||||||
|
</div>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
|
|
||||||
<ion-fab bottom end *ngIf="canAdd">
|
<ion-fab bottom end *ngIf="canAdd">
|
||||||
|
|
|
@ -32,8 +32,11 @@
|
||||||
<addon-notifications-actions [contextUrl]="notification.contexturl" [courseId]="notification.courseid"></addon-notifications-actions>
|
<addon-notifications-actions [contextUrl]="notification.contexturl" [courseId]="notification.courseid"></addon-notifications-actions>
|
||||||
</ion-card>
|
</ion-card>
|
||||||
<core-empty-box *ngIf="!notifications || notifications.length <= 0" icon="notifications" [message]="'addon.notifications.therearentnotificationsyet' | translate"></core-empty-box>
|
<core-empty-box *ngIf="!notifications || notifications.length <= 0" icon="notifications" [message]="'addon.notifications.therearentnotificationsyet' | translate"></core-empty-box>
|
||||||
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="loadMoreNotifications($event)">
|
<div *ngIf="canLoadMore" padding>
|
||||||
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
<button ion-button block (click)="loadMoreNotifications()" color="light">{{'core.loadmore' | translate }}</button>
|
||||||
</ion-infinite-scroll>
|
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="loadMoreNotifications($event)">
|
||||||
|
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
||||||
|
</ion-infinite-scroll>
|
||||||
|
</div>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
|
@ -44,10 +44,19 @@
|
||||||
<!-- Multiple sections. -->
|
<!-- Multiple sections. -->
|
||||||
<div *ngIf="selectedSection && selectedSection.id == allSectionsId">
|
<div *ngIf="selectedSection && selectedSection.id == allSectionsId">
|
||||||
<core-dynamic-component [component]="allSectionsComponent" [data]="data">
|
<core-dynamic-component [component]="allSectionsComponent" [data]="data">
|
||||||
<ng-container *ngFor="let section of sections">
|
<ng-container *ngFor="let section of sections; index as i">
|
||||||
<ng-container *ngTemplateOutlet="sectionTemplate; context: {section: section}"></ng-container>
|
<ng-container *ngIf="i <= showSectionId">
|
||||||
|
<ng-container *ngTemplateOutlet="sectionTemplate; context: {section: section}"></ng-container>
|
||||||
|
</ng-container>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</core-dynamic-component>
|
</core-dynamic-component>
|
||||||
|
|
||||||
|
<div *ngIf="canLoadMore" padding>
|
||||||
|
<button ion-button block (click)="showMoreActivities()" color="light">{{'core.loadmore' | translate }}</button>
|
||||||
|
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="$event.waitFor(showMoreActivities())">
|
||||||
|
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
||||||
|
</ion-infinite-scroll>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
<ion-buttons padding end class="core-course-section-nav-buttons" *ngIf="displaySectionSelector && sections && sections.length">
|
<ion-buttons padding end class="core-course-section-nav-buttons" *ngIf="displaySectionSelector && sections && sections.length">
|
||||||
|
|
|
@ -41,6 +41,8 @@ import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-comp
|
||||||
templateUrl: 'core-course-format.html'
|
templateUrl: 'core-course-format.html'
|
||||||
})
|
})
|
||||||
export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
|
export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
|
static LOAD_MORE_ACTIVITIES = 20; // How many activities should load each time showMoreActivities is called.
|
||||||
|
|
||||||
@Input() course: any; // The course to render.
|
@Input() course: any; // The course to render.
|
||||||
@Input() sections: any[]; // List of course sections.
|
@Input() sections: any[]; // List of course sections.
|
||||||
@Input() downloadEnabled?: boolean; // Whether the download of sections and modules is enabled.
|
@Input() downloadEnabled?: boolean; // Whether the download of sections and modules is enabled.
|
||||||
|
@ -57,6 +59,8 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
sectionSelectorComponent: any;
|
sectionSelectorComponent: any;
|
||||||
singleSectionComponent: any;
|
singleSectionComponent: any;
|
||||||
allSectionsComponent: any;
|
allSectionsComponent: any;
|
||||||
|
canLoadMore = false;
|
||||||
|
showSectionId = 0;
|
||||||
|
|
||||||
// Data to pass to the components.
|
// Data to pass to the components.
|
||||||
data: any = {};
|
data: any = {};
|
||||||
|
@ -273,6 +277,9 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
} else {
|
} else {
|
||||||
this.previousSection = null;
|
this.previousSection = null;
|
||||||
this.nextSection = null;
|
this.nextSection = null;
|
||||||
|
this.canLoadMore = false;
|
||||||
|
this.showSectionId = 0;
|
||||||
|
this.showMoreActivities();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.moduleId && typeof previousValue == 'undefined') {
|
if (this.moduleId && typeof previousValue == 'undefined') {
|
||||||
|
@ -363,6 +370,46 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show more activities (only used when showing all the sections at the same time).
|
||||||
|
*
|
||||||
|
* @return {Promise<void>} Resolved when done to change infinite loading status.
|
||||||
|
*/
|
||||||
|
showMoreActivities(): Promise<void> {
|
||||||
|
this.canLoadMore = false;
|
||||||
|
|
||||||
|
let modulesLoaded = 0,
|
||||||
|
i;
|
||||||
|
for (i = this.showSectionId + 1; i < this.sections.length; i++) {
|
||||||
|
if (this.sections[i].hasContent && this.sections[i].modules) {
|
||||||
|
modulesLoaded += this.sections[i].modules.reduce((total, module) => {
|
||||||
|
return module.visibleoncoursepage !== 0 ? total + 1 : total;
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
if (modulesLoaded >= CoreCourseFormatComponent.LOAD_MORE_ACTIVITIES) {
|
||||||
|
this.showSectionId = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.canLoadMore = i < this.sections.length;
|
||||||
|
|
||||||
|
if (this.canLoadMore) {
|
||||||
|
// Check if any of the following sections have any content.
|
||||||
|
let thereAreMore = false;
|
||||||
|
for (i++; i < this.sections.length; i++) {
|
||||||
|
if (this.sections[i].hasContent && this.sections[i].modules) {
|
||||||
|
thereAreMore = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.canLoadMore = thereAreMore;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component destroyed.
|
* Component destroyed.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,9 +10,12 @@
|
||||||
<ion-item-divider color="light">{{ 'core.courses.totalcoursesearchresults' | translate:{$a: total} }}</ion-item-divider>
|
<ion-item-divider color="light">{{ 'core.courses.totalcoursesearchresults' | translate:{$a: total} }}</ion-item-divider>
|
||||||
<core-empty-box *ngIf="total == 0" icon="search" [message]="'core.courses.nosearchresults' | translate"></core-empty-box>
|
<core-empty-box *ngIf="total == 0" icon="search" [message]="'core.courses.nosearchresults' | translate"></core-empty-box>
|
||||||
<core-courses-course-list-item *ngFor="let course of courses" [course]="course"></core-courses-course-list-item>
|
<core-courses-course-list-item *ngFor="let course of courses" [course]="course"></core-courses-course-list-item>
|
||||||
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="loadMoreResults($event)">
|
<div *ngIf="canLoadMore" padding>
|
||||||
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
<button ion-button block (click)="loadMoreResults()" color="light">{{'core.loadmore' | translate }}</button>
|
||||||
</ion-infinite-scroll>
|
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="loadMoreResults($event)">
|
||||||
|
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
||||||
|
</ion-infinite-scroll>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,12 @@
|
||||||
</a>
|
</a>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
|
|
||||||
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="$event.waitFor(fetchData())">
|
<div *ngIf="canLoadMore" padding>
|
||||||
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
<button ion-button block (click)="fetchData()" color="light">{{'core.loadmore' | translate }}</button>
|
||||||
</ion-infinite-scroll>
|
<ion-infinite-scroll [enabled]="canLoadMore" (ionInfinite)="$event.waitFor(fetchData())">
|
||||||
|
<ion-infinite-scroll-content></ion-infinite-scroll-content>
|
||||||
|
</ion-infinite-scroll>
|
||||||
|
</div>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
</core-split-view>
|
</core-split-view>
|
Loading…
Reference in New Issue