diff --git a/src/addon/calendar/pages/list/list.html b/src/addon/calendar/pages/list/list.html index bba5d8fa7..33ec3cebc 100644 --- a/src/addon/calendar/pages/list/list.html +++ b/src/addon/calendar/pages/list/list.html @@ -29,12 +29,7 @@ -
- - - - -
+ \ No newline at end of file diff --git a/src/addon/calendar/pages/list/list.ts b/src/addon/calendar/pages/list/list.ts index 324d4b76f..90d85d4e9 100644 --- a/src/addon/calendar/pages/list/list.ts +++ b/src/addon/calendar/pages/list/list.ts @@ -179,6 +179,18 @@ export class AddonCalendarListPage implements OnDestroy { }); } + /** + * Function to load more events. + * + * @param {any} [infiniteComplete] Infinite scroll complete function. Only used from core-infinite-loading. + * @return {Promise} Resolved when done. + */ + loadMoreEvents(infiniteComplete?: any): Promise { + return this.fetchEvents().finally(() => { + infiniteComplete && infiniteComplete(); + }); + } + /** * Get filtered events. * diff --git a/src/addon/messages/pages/discussion/discussion.html b/src/addon/messages/pages/discussion/discussion.html index 9d33ba0fd..da8d7e7c4 100644 --- a/src/addon/messages/pages/discussion/discussion.html +++ b/src/addon/messages/pages/discussion/discussion.html @@ -15,12 +15,7 @@ -
- - - - -
+ diff --git a/src/addon/messages/pages/discussion/discussion.ts b/src/addon/messages/pages/discussion/discussion.ts index e8cb226dc..3080b974a 100644 --- a/src/addon/messages/pages/discussion/discussion.ts +++ b/src/addon/messages/pages/discussion/discussion.ts @@ -543,10 +543,10 @@ export class AddonMessagesDiscussionPage implements OnDestroy { /** * Function to load previous messages. * - * @param {any} [infiniteScroll] Infinite scroll object. + * @param {any} [infiniteComplete] Infinite scroll complete function. Only used from core-infinite-loading. * @return {Promise} Resolved when done. */ - loadPrevious(infiniteScroll: any): Promise { + loadPrevious(infiniteComplete?: any): Promise { // If there is an ongoing fetch, wait for it to finish. return this.waitForFetch().finally(() => { this.pagesLoaded++; @@ -555,7 +555,7 @@ export class AddonMessagesDiscussionPage implements OnDestroy { this.pagesLoaded--; this.domUtils.showErrorModalDefault(error, 'addon.messages.errorwhileretrievingmessages', true); }).finally(() => { - infiniteScroll.complete(); + infiniteComplete && infiniteComplete(); }); }); } diff --git a/src/addon/mod/forum/components/index/addon-mod-forum-index.html b/src/addon/mod/forum/components/index/addon-mod-forum-index.html index a9fde4ef3..463d9bbdf 100644 --- a/src/addon/mod/forum/components/index/addon-mod-forum-index.html +++ b/src/addon/mod/forum/components/index/addon-mod-forum-index.html @@ -88,12 +88,7 @@ -
- - - - -
+
diff --git a/src/addon/mod/forum/components/index/index.ts b/src/addon/mod/forum/components/index/index.ts index 8ab76ab1f..685c671c0 100644 --- a/src/addon/mod/forum/components/index/index.ts +++ b/src/addon/mod/forum/components/index/index.ts @@ -305,13 +305,16 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom /** * Convenience function to load more forum discussions. * + * @param {any} [infiniteComplete] Infinite scroll complete function. Only used from core-infinite-loading. * @return {Promise} Promise resolved when done. */ - protected fetchMoreDiscussions(): Promise { + fetchMoreDiscussions(infiniteComplete?: any): Promise { return this.fetchDiscussions(false).catch((message) => { this.domUtils.showErrorModalDefault(message, 'addon.mod_forum.errorgetforum', true); this.canLoadMore = false; // Set to false to prevent infinite calls with infinite-loading. + }).finally(() => { + infiniteComplete && infiniteComplete(); }); } diff --git a/src/addon/mod/glossary/components/index/addon-mod-glossary-index.html b/src/addon/mod/glossary/components/index/addon-mod-glossary-index.html index 266a22449..8745e6f6b 100644 --- a/src/addon/mod/glossary/components/index/addon-mod-glossary-index.html +++ b/src/addon/mod/glossary/components/index/addon-mod-glossary-index.html @@ -56,12 +56,7 @@ -
- - - - -
+ diff --git a/src/addon/mod/glossary/components/index/index.ts b/src/addon/mod/glossary/components/index/index.ts index 461178374..9cb87dd68 100644 --- a/src/addon/mod/glossary/components/index/index.ts +++ b/src/addon/mod/glossary/components/index/index.ts @@ -289,11 +289,14 @@ export class AddonModGlossaryIndexComponent extends CoreCourseModuleMainActivity /** * Convenience function to load more forum discussions. * + * @param {any} [infiniteComplete] Infinite scroll complete function. Only used from core-infinite-loading. * @return {Promise} Promise resolved when done. */ - loadMoreEntries(): Promise { + loadMoreEntries(infiniteComplete?: any): Promise { return this.fetchEntries(true).catch((error) => { this.domUtils.showErrorModalDefault(error, 'addon.mod_glossary.errorloadingentries', true); + }).finally(() => { + infiniteComplete && infiniteComplete(); }); } diff --git a/src/addon/notifications/pages/list/list.html b/src/addon/notifications/pages/list/list.html index e1cd62ea5..0ee4eb357 100644 --- a/src/addon/notifications/pages/list/list.html +++ b/src/addon/notifications/pages/list/list.html @@ -32,11 +32,6 @@ -
- - - - -
+
diff --git a/src/addon/notifications/pages/list/list.ts b/src/addon/notifications/pages/list/list.ts index 07de7da86..fe21ee62f 100644 --- a/src/addon/notifications/pages/list/list.ts +++ b/src/addon/notifications/pages/list/list.ts @@ -204,11 +204,11 @@ export class AddonNotificationsListPage { /** * Load more results. * - * @param {any} infiniteScroll The infinit scroll instance. + * @param {any} [infiniteComplete] Infinite scroll complete function. Only used from core-infinite-loading. */ - loadMoreNotifications(infiniteScroll: any): void { + loadMoreNotifications(infiniteComplete?: any): void { this.fetchNotifications().finally(() => { - infiniteScroll.complete(); + infiniteComplete && infiniteComplete(); }); } diff --git a/src/components/components.module.ts b/src/components/components.module.ts index 6163a7d83..487778e49 100644 --- a/src/components/components.module.ts +++ b/src/components/components.module.ts @@ -49,6 +49,7 @@ import { CoreNavigationBarComponent } from './navigation-bar/navigation-bar'; import { CoreAttachmentsComponent } from './attachments/attachments'; import { CoreIonTabsComponent } from './ion-tabs/ion-tabs'; import { CoreIonTabComponent } from './ion-tabs/ion-tab'; +import { CoreInfiniteLoadingComponent } from './infinite-loading/infinite-loading'; @NgModule({ declarations: [ @@ -83,7 +84,8 @@ import { CoreIonTabComponent } from './ion-tabs/ion-tab'; CoreNavigationBarComponent, CoreAttachmentsComponent, CoreIonTabsComponent, - CoreIonTabComponent + CoreIonTabComponent, + CoreInfiniteLoadingComponent ], entryComponents: [ CoreContextMenuPopoverComponent, @@ -125,7 +127,8 @@ import { CoreIonTabComponent } from './ion-tabs/ion-tab'; CoreNavigationBarComponent, CoreAttachmentsComponent, CoreIonTabsComponent, - CoreIonTabComponent + CoreIonTabComponent, + CoreInfiniteLoadingComponent ] }) export class CoreComponentsModule {} diff --git a/src/components/infinite-loading/core-infinite-loading.html b/src/components/infinite-loading/core-infinite-loading.html new file mode 100644 index 000000000..e52c393a5 --- /dev/null +++ b/src/components/infinite-loading/core-infinite-loading.html @@ -0,0 +1,19 @@ +
+ +
+ + + + + +
+ +
+ +
+ +
\ No newline at end of file diff --git a/src/components/infinite-loading/infinite-loading.ts b/src/components/infinite-loading/infinite-loading.ts new file mode 100644 index 000000000..7c7b3b4d6 --- /dev/null +++ b/src/components/infinite-loading/infinite-loading.ts @@ -0,0 +1,68 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Component, Input, Output, EventEmitter } from '@angular/core'; +import { InfiniteScroll } from 'ionic-angular'; + +/** + * Component to show a infinite loading trigger and spinner while more data is being loaded. + * + * Usage: + * + */ +@Component({ + selector: 'core-infinite-loading', + templateUrl: 'core-infinite-loading.html', +}) +export class CoreInfiniteLoadingComponent { + @Input() enabled: boolean; + @Input() position = 'bottom'; + @Output() action: EventEmitter<() => void>; // Will emit an event when triggered. + + loadingMore = false; // Hide button and avoid loading more. + + protected infiniteScroll: InfiniteScroll; + + constructor() { + this.action = new EventEmitter(); + } + + /** + * Load More items calling the action provided. + * + * @param {InfiniteScroll} [infiniteScroll] Infinite scroll object only if triggered from the scroll. + */ + loadMore(infiniteScroll?: InfiniteScroll): void { + if (this.loadingMore) { + return; + } + + if (infiniteScroll) { + this.infiniteScroll = infiniteScroll; + } + this.loadingMore = true; + + this.action.emit(this.complete.bind(this)); + } + + /** + * Complete loading. + */ + complete(): void { + this.loadingMore = false; + this.infiniteScroll && this.infiniteScroll.complete(); + this.infiniteScroll = undefined; + } + +} diff --git a/src/core/course/components/format/core-course-format.html b/src/core/course/components/format/core-course-format.html index 621fc9f1e..4b244729d 100644 --- a/src/core/course/components/format/core-course-format.html +++ b/src/core/course/components/format/core-course-format.html @@ -51,12 +51,7 @@ -
- - - - -
+ diff --git a/src/core/course/components/format/format.ts b/src/core/course/components/format/format.ts index 65d5133c8..37b239a6e 100644 --- a/src/core/course/components/format/format.ts +++ b/src/core/course/components/format/format.ts @@ -373,9 +373,9 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { /** * Show more activities (only used when showing all the sections at the same time). * - * @return {Promise} Resolved when done to change infinite loading status. + * @param {any} [infiniteComplete] Infinite scroll complete function. Only used from core-infinite-loading. */ - showMoreActivities(): Promise { + showMoreActivities(infiniteComplete?: any): void { this.canLoadMore = false; let modulesLoaded = 0, @@ -399,7 +399,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { // 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) { + if (this.sections[i].hasContent && this.sections[i].modules && this.sections[i].modules.length > 0) { thereAreMore = true; break; } @@ -407,7 +407,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { this.canLoadMore = thereAreMore; } - return Promise.resolve(); + infiniteComplete && infiniteComplete(); } /** diff --git a/src/core/course/providers/default-format.ts b/src/core/course/providers/default-format.ts index 146f44232..50ae2701c 100644 --- a/src/core/course/providers/default-format.ts +++ b/src/core/course/providers/default-format.ts @@ -16,7 +16,6 @@ import { Injectable } from '@angular/core'; import { NavController } from 'ionic-angular'; import { CoreCoursesProvider } from '@core/courses/providers/courses'; import { CoreCourseFormatHandler } from './format-delegate'; -import { CoreCourseProvider } from './course'; /** * Default handler used when the course format doesn't have a specific implementation. diff --git a/src/core/courses/pages/search/search.html b/src/core/courses/pages/search/search.html index d9018b556..0174eb683 100644 --- a/src/core/courses/pages/search/search.html +++ b/src/core/courses/pages/search/search.html @@ -10,12 +10,7 @@ {{ 'core.courses.totalcoursesearchresults' | translate:{$a: total} }} -
- - - - -
+ diff --git a/src/core/courses/pages/search/search.ts b/src/core/courses/pages/search/search.ts index 43c988d3d..38607e129 100644 --- a/src/core/courses/pages/search/search.ts +++ b/src/core/courses/pages/search/search.ts @@ -54,11 +54,11 @@ export class CoreCoursesSearchPage { /** * Load more results. * - * @param {any} infiniteScroll The infinit scroll instance. + * @param {any} [infiniteComplete] Infinite scroll complete function. Only used from core-infinite-loading. */ - loadMoreResults(infiniteScroll: any): void { + loadMoreResults(infiniteComplete?: any): void { this.searchCourses().finally(() => { - infiniteScroll.complete(); + infiniteComplete && infiniteComplete(); }); } diff --git a/src/core/user/components/participants/core-user-participants.html b/src/core/user/components/participants/core-user-participants.html index 8000e1abe..287c76baa 100644 --- a/src/core/user/components/participants/core-user-participants.html +++ b/src/core/user/components/participants/core-user-participants.html @@ -16,13 +16,7 @@

{{ 'core.lastaccess' | translate }}: {{ participant.lastaccess * 1000 | coreFormatDate:"dfmediumdate"}}

- -
- - - - -
+ \ No newline at end of file diff --git a/src/core/user/components/participants/participants.ts b/src/core/user/components/participants/participants.ts index ff4434a9e..f933be290 100644 --- a/src/core/user/components/participants/participants.ts +++ b/src/core/user/components/participants/participants.ts @@ -82,6 +82,18 @@ export class CoreUserParticipantsComponent implements OnInit { }); } + /** + * Function to load more data. + * + * @param {any} [infiniteComplete] Infinite scroll complete function. Only used from core-infinite-loading. + * @return {Promise} Resolved when done. + */ + loadMoreData(infiniteComplete?: any): Promise { + return this.fetchData().finally(() => { + infiniteComplete && infiniteComplete(); + }); + } + /** * Refresh data. *