From 8acb8b74e283f4334ddfc4f1a1d39afe70caf4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 13 Oct 2021 16:17:40 +0200 Subject: [PATCH] MOBILE-3686 courses: Merge list courses and my courses page --- scripts/langindex.json | 1 + .../core-courses-course-list-item.html | 8 +- .../course-list-item/course-list-item.ts | 34 +-- .../features/courses/courses-lazy.module.ts | 8 +- src/core/features/courses/courses.module.ts | 2 +- src/core/features/courses/lang.json | 1 + .../features/courses/pages/list/list.html | 14 +- src/core/features/courses/pages/list/list.ts | 101 +++++++- .../courses/pages/my-courses/my-courses.html | 54 ----- .../pages/my-courses/my-courses.module.ts | 40 ---- .../courses/pages/my-courses/my-courses.ts | 219 ------------------ src/core/features/courses/services/courses.ts | 12 + .../features/sitehome/pages/index/index.ts | 2 +- 13 files changed, 147 insertions(+), 349 deletions(-) delete mode 100644 src/core/features/courses/pages/my-courses/my-courses.html delete mode 100644 src/core/features/courses/pages/my-courses/my-courses.module.ts delete mode 100644 src/core/features/courses/pages/my-courses/my-courses.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index 0ec207051..9cd4ae19c 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1551,6 +1551,7 @@ "core.courses.selfenrolment": "local_moodlemobileapp", "core.courses.sendpaymentbutton": "enrol_paypal", "core.courses.show": "block_myoverview", + "core.courses.showonlyenrolled": "local_moodlemobileapp", "core.courses.therearecourses": "moodle", "core.courses.totalcoursesearchresults": "local_moodlemobileapp", "core.currentdevice": "local_moodlemobileapp", diff --git a/src/core/features/courses/components/course-list-item/core-courses-course-list-item.html b/src/core/features/courses/components/course-list-item/core-courses-course-list-item.html index aead6199e..0d81bc533 100644 --- a/src/core/features/courses/components/course-list-item/core-courses-course-list-item.html +++ b/src/core/features/courses/components/course-list-item/core-courses-course-list-item.html @@ -6,6 +6,10 @@ +

+ + +

@@ -19,10 +23,6 @@

-

- - -

diff --git a/src/core/features/courses/components/course-list-item/course-list-item.ts b/src/core/features/courses/components/course-list-item/course-list-item.ts index e7778782f..e4248e0e3 100644 --- a/src/core/features/courses/components/course-list-item/course-list-item.ts +++ b/src/core/features/courses/components/course-list-item/course-list-item.ts @@ -15,8 +15,11 @@ import { Component, Input, OnInit } from '@angular/core'; import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreNavigator } from '@services/navigator'; -import { CoreCourses, CoreCourseSearchedData } from '../../services/courses'; -import { CoreCoursesHelper, CoreCourseWithImageAndColor } from '../../services/courses-helper'; +import { CoreSites } from '@services/sites'; +import { CoreDomUtils } from '@services/utils/dom'; +import { CoreEventCourseStatusChanged, CoreEventObserver, CoreEvents } from '@singletons/events'; +import { CoreCourseListItem, CoreCourses } from '../../services/courses'; +import { CoreCoursesHelper } from '../../services/courses-helper'; /** * This directive is meant to display an item for a list of courses. @@ -32,10 +35,7 @@ import { CoreCoursesHelper, CoreCourseWithImageAndColor } from '../../services/c }) export class CoreCoursesCourseListItemComponent implements OnInit { - @Input() course!: CoreCourseSearchedData & CoreCourseWithImageAndColor & { - completionusertracked?: boolean; // If the user is completion tracked. - progress?: number | null; // Progress percentage. - }; // The course to render. + @Input() course!: CoreCourseListItem; // The course to render. icons: CoreCoursesEnrolmentIcons[] = []; isEnrolled = false; @@ -46,15 +46,21 @@ export class CoreCoursesCourseListItemComponent implements OnInit { async ngOnInit(): Promise { CoreCoursesHelper.loadCourseColorAndImage(this.course); - // Check if the user is enrolled in the course. - try { - const course = await CoreCourses.getUserCourse(this.course.id); - this.course.progress = course.progress; - this.course.completionusertracked = course.completionusertracked; + this.isEnrolled = this.course.progress !== undefined; - this.isEnrolled = true; - } catch { - this.isEnrolled = false; + if (!this.isEnrolled) { + try { + const course = await CoreCourses.getUserCourse(this.course.id); + this.course.progress = course.progress; + this.course.completionusertracked = course.completionusertracked; + + this.isEnrolled = true; + } catch { + this.isEnrolled = false; + } + } + + if (!this.isEnrolled) { this.icons = []; this.course.enrollmentmethods.forEach((instance) => { diff --git a/src/core/features/courses/courses-lazy.module.ts b/src/core/features/courses/courses-lazy.module.ts index ad6fc7cdf..cfffc2db4 100644 --- a/src/core/features/courses/courses-lazy.module.ts +++ b/src/core/features/courses/courses-lazy.module.ts @@ -18,7 +18,7 @@ import { RouterModule, Routes } from '@angular/router'; const routes: Routes = [ { path: '', - redirectTo: 'my', + redirectTo: 'list', pathMatch: 'full', }, { @@ -38,12 +38,6 @@ const routes: Routes = [ import('./pages/list/list.module') .then(m => m.CoreCoursesListPageModule), }, - { - path: 'my', - loadChildren: () => - import('./pages/my-courses/my-courses.module') - .then(m => m.CoreCoursesMyCoursesPageModule), - }, ]; @NgModule({ diff --git a/src/core/features/courses/courses.module.ts b/src/core/features/courses/courses.module.ts index b07d4bc2b..25129ac4a 100644 --- a/src/core/features/courses/courses.module.ts +++ b/src/core/features/courses/courses.module.ts @@ -44,7 +44,7 @@ const mainMenuHomeChildrenRoutes: Routes = [ }, { path: CoreCoursesMyCoursesHomeHandlerService.PAGE_NAME, - loadChildren: () => import('./pages/my-courses/my-courses.module').then(m => m.CoreCoursesMyCoursesPageModule), + loadChildren: () => import('./pages/list/list.module').then(m => m.CoreCoursesListPageModule), }, ]; diff --git a/src/core/features/courses/lang.json b/src/core/features/courses/lang.json index 668442a99..47924a0bd 100644 --- a/src/core/features/courses/lang.json +++ b/src/core/features/courses/lang.json @@ -40,6 +40,7 @@ "selfenrolment": "Self enrolment", "sendpaymentbutton": "Send payment via PayPal", "show": "Restore to view", + "showonlyenrolled": "Show only my courses", "therearecourses": "There are {{$a}} courses", "totalcoursesearchresults": "Total courses: {{$a}}" } diff --git a/src/core/features/courses/pages/list/list.html b/src/core/features/courses/pages/list/list.html index 3b2471ad6..fe2dbc491 100644 --- a/src/core/features/courses/pages/list/list.html +++ b/src/core/features/courses/pages/list/list.html @@ -3,7 +3,19 @@ -

{{ 'core.courses.availablecourses' | translate }}

+

{{ 'core.courses.availablecourses' | translate }}

+

{{ 'core.courses.mycourses' | translate }}

+ + + + + + + diff --git a/src/core/features/courses/pages/list/list.ts b/src/core/features/courses/pages/list/list.ts index 12c0cf317..7d0174397 100644 --- a/src/core/features/courses/pages/list/list.ts +++ b/src/core/features/courses/pages/list/list.ts @@ -13,14 +13,15 @@ // limitations under the License. import { Component, OnDestroy, OnInit } from '@angular/core'; +import { CoreCoursesHelper, CoreEnrolledCourseDataWithExtraInfo } from '@features/courses/services/courses-helper'; import { IonRefresher } from '@ionic/angular'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; -import { CoreCourseBasicSearchedData, CoreCourses } from '../../services/courses'; +import { CoreCourseBasicSearchedData, CoreCourses, CoreCoursesProvider } from '../../services/courses'; -type CoreCoursesListMode = 'search' | 'all'; +type CoreCoursesListMode = 'search' | 'all' | 'my'; /** * Page that shows a list of courses. @@ -31,31 +32,60 @@ type CoreCoursesListMode = 'search' | 'all'; }) export class CoreCoursesListPage implements OnInit, OnDestroy { + downloadAllCoursesEnabled = false; + searchEnabled = false; + myCoursesEnabled = true; searchMode = false; searchCanLoadMore = false; searchLoadMoreError = false; searchTotal = 0; - mode: CoreCoursesListMode = 'all'; + downloadEnabled = false; + downloadCourseEnabled = false; + downloadCoursesEnabled = false; - courses: CoreCourseBasicSearchedData[] = []; + mode: CoreCoursesListMode = 'my'; + + courses: (CoreCourseBasicSearchedData|CoreEnrolledCourseDataWithExtraInfo)[] = []; coursesLoaded = false; + showOnlyEnrolled = false; + protected currentSiteId: string; protected frontpageCourseId: number; protected searchPage = 0; protected searchText = ''; + protected myCoursesObserver: CoreEventObserver; protected siteUpdatedObserver: CoreEventObserver; + protected courseIds = ''; + protected isDestroyed = false; constructor() { this.currentSiteId = CoreSites.getRequiredCurrentSite().getId(); this.frontpageCourseId = CoreSites.getRequiredCurrentSite().getSiteHomeId(); + // Update list if user enrols in a course. + this.myCoursesObserver = CoreEvents.on( + CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, + (data) => { + + if (data.action == CoreCoursesProvider.ACTION_ENROL) { + this.fetchCourses(); + } + }, + + this.currentSiteId, + ); + // Refresh the enabled flags if site is updated. this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite(); + this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); + this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); + this.myCoursesEnabled = !CoreCourses.isMyCoursesDisabledInSite(); + this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && this.downloadEnabled; if (!this.searchEnabled) { this.searchMode = false; @@ -68,12 +98,25 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { * @inheritdoc */ ngOnInit(): void { + this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); + this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); + this.mode = CoreNavigator.getRouteParam('mode') || this.mode; + this.myCoursesEnabled = !CoreCourses.isMyCoursesDisabledInSite(); + if (this.mode == 'my' && !this.myCoursesEnabled) { + this.mode = 'all'; + this.showOnlyEnrolled = false; + } + if (this.mode == 'search') { this.searchMode = true; } + if (this.mode == 'my') { + this.showOnlyEnrolled = true; + } + this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite(); if (!this.searchEnabled) { this.searchMode = false; @@ -91,6 +134,8 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { try { if (this.searchMode && this.searchText) { await this.search(this.searchText); + } else if (this.showOnlyEnrolled) { + await this.loadMyCourses(); } else { await this.loadAvailableCourses(); } @@ -99,6 +144,24 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { } } + /** + * Fetch the user courses. + * + * @return Promise resolved when done. + */ + protected async loadMyCourses(): Promise { + try { + const courses: CoreEnrolledCourseDataWithExtraInfo[] = await CoreCourses.getUserCourses(); + this.courseIds = courses.map((course) => course.id).join(','); + + await CoreCoursesHelper.loadCoursesExtraInfo(courses, true); + + this.courses = courses; + } catch (error) { + !this.isDestroyed && CoreDomUtils.showErrorModalDefault(error, 'core.courses.errorloadcourses', true); + } + } + /** * Load the courses. * @@ -110,7 +173,7 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { this.courses = courses.filter((course) => course.id != this.frontpageCourseId); } catch (error) { - CoreDomUtils.showErrorModalDefault(error, 'core.courses.errorloadcourses', true); + !this.isDestroyed && CoreDomUtils.showErrorModalDefault(error, 'core.courses.errorloadcourses', true); } } @@ -124,6 +187,9 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { promises.push(CoreCourses.invalidateUserCourses()); promises.push(CoreCourses.invalidateCoursesByField()); + if (this.courseIds) { + promises.push(CoreCourses.invalidateCoursesByField('ids', this.courseIds)); + } Promise.all(promises).finally(() => { this.fetchCourses().finally(() => { @@ -145,7 +211,7 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { this.searchTotal = 0; const modal = await CoreDomUtils.showModalLoading('core.searching', true); - this.searchCourses().finally(() => { + await this.searchCourses().finally(() => { modal.dismiss(); }); } @@ -184,7 +250,7 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { this.searchLoadMoreError = false; try { - const response = await CoreCourses.search(this.searchText, this.searchPage); + const response = await CoreCourses.search(this.searchText, this.searchPage, undefined, this.showOnlyEnrolled); if (this.searchPage === 0) { this.courses = response.courses; @@ -197,15 +263,34 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { this.searchCanLoadMore = this.courses.length < this.searchTotal; } catch (error) { this.searchLoadMoreError = true; // Set to prevent infinite calls with infinite-loading. - CoreDomUtils.showErrorModalDefault(error, 'core.courses.errorsearching', true); + !this.isDestroyed && CoreDomUtils.showErrorModalDefault(error, 'core.courses.errorsearching', true); } } + /** + * Toggle show only my courses. + */ + toggleEnrolled(enabled: boolean): void { + this.coursesLoaded = false; + this.showOnlyEnrolled = enabled; + + this.fetchCourses(); + } + + /** + * Toggle download enabled. + */ + toggleDownload(enabled: boolean): void { + this.downloadEnabled = enabled; + } + /** * @inheritdoc */ ngOnDestroy(): void { + this.myCoursesObserver?.off(); this.siteUpdatedObserver?.off(); + this.isDestroyed = true; } } diff --git a/src/core/features/courses/pages/my-courses/my-courses.html b/src/core/features/courses/pages/my-courses/my-courses.html deleted file mode 100644 index 2e22ce7ee..000000000 --- a/src/core/features/courses/pages/my-courses/my-courses.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - -

{{ 'core.courses.mycourses' | translate }}

- - - - - - - - - - - - {{downloadAllCoursesBadge}} - - - -
-
- - - - - - - - - - - - - - - - - -

{{ 'core.courses.searchcoursesadvice' | translate }}

-
-
-
diff --git a/src/core/features/courses/pages/my-courses/my-courses.module.ts b/src/core/features/courses/pages/my-courses/my-courses.module.ts deleted file mode 100644 index d07c58ced..000000000 --- a/src/core/features/courses/pages/my-courses/my-courses.module.ts +++ /dev/null @@ -1,40 +0,0 @@ -// (C) Copyright 2015 Moodle Pty Ltd. -// -// 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 { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; - -import { CoreSharedModule } from '@/core/shared.module'; -import { CoreCoursesMyCoursesPage } from './my-courses'; -import { CoreCoursesComponentsModule } from '../../components/components.module'; - -const routes: Routes = [ - { - path: '', - component: CoreCoursesMyCoursesPage, - }, -]; - -@NgModule({ - imports: [ - RouterModule.forChild(routes), - CoreSharedModule, - CoreCoursesComponentsModule, - ], - declarations: [ - CoreCoursesMyCoursesPage, - ], - exports: [RouterModule], -}) -export class CoreCoursesMyCoursesPageModule { } diff --git a/src/core/features/courses/pages/my-courses/my-courses.ts b/src/core/features/courses/pages/my-courses/my-courses.ts deleted file mode 100644 index 675933daf..000000000 --- a/src/core/features/courses/pages/my-courses/my-courses.ts +++ /dev/null @@ -1,219 +0,0 @@ -// (C) Copyright 2015 Moodle Pty Ltd. -// -// 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, OnInit, OnDestroy, ViewChild } from '@angular/core'; -import { IonSearchbar, IonRefresher } from '@ionic/angular'; -import { CoreEventObserver, CoreEvents } from '@singletons/events'; -import { CoreSites } from '@services/sites'; -import { CoreDomUtils } from '@services/utils/dom'; -import { - CoreCoursesProvider, - CoreCourses, -} from '../../services/courses'; -import { CoreCoursesHelper, CoreEnrolledCourseDataWithExtraInfoAndOptions } from '../../services/courses-helper'; -import { CoreCourseHelper } from '@features/course/services/course-helper'; -import { CoreConstants } from '@/core/constants'; -import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate'; -import { CoreNavigator } from '@services/navigator'; -import { Translate } from '@singletons'; - -/** - * Page that displays the list of courses the user is enrolled in. - */ -@Component({ - selector: 'page-core-courses-my-courses', - templateUrl: 'my-courses.html', -}) -export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy { - - @ViewChild(IonSearchbar) searchbar!: IonSearchbar; - - courses: CoreEnrolledCourseDataWithExtraInfoAndOptions[] = []; - filteredCourses: CoreEnrolledCourseDataWithExtraInfoAndOptions[] = []; - searchEnabled = false; - filter = ''; - showFilter = false; - coursesLoaded = false; - downloadAllCoursesIcon = CoreConstants.ICON_NOT_DOWNLOADED; - downloadAllCoursesLoading = false; - downloadAllCoursesBadge = ''; - downloadAllCoursesEnabled = false; - downloadAllCoursesCount?: number; - downloadAllCoursesTotal?: number; - downloadAllCoursesBadgeA11yText = ''; - - protected myCoursesObserver: CoreEventObserver; - protected siteUpdatedObserver: CoreEventObserver; - protected isDestroyed = false; - protected courseIds = ''; - - constructor() { - // Update list if user enrols in a course. - this.myCoursesObserver = CoreEvents.on( - CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, - (data) => { - - if (data.action == CoreCoursesProvider.ACTION_ENROL) { - this.fetchCourses(); - } - }, - - CoreSites.getCurrentSiteId(), - ); - - // Refresh the enabled flags if site is updated. - this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { - this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite(); - this.downloadAllCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); - }, CoreSites.getCurrentSiteId()); - } - - /** - * Component being initialized. - */ - ngOnInit(): void { - this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite(); - this.downloadAllCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); - - this.fetchCourses().finally(() => { - this.coursesLoaded = true; - }); - } - - /** - * Fetch the user courses. - * - * @return Promise resolved when done. - */ - protected async fetchCourses(): Promise { - try { - const courses: CoreEnrolledCourseDataWithExtraInfoAndOptions[] = await CoreCourses.getUserCourses(); - const courseIds = courses.map((course) => course.id); - - this.courseIds = courseIds.join(','); - - await CoreCoursesHelper.loadCoursesExtraInfo(courses); - - const options = await CoreCourses.getCoursesAdminAndNavOptions(courseIds); - courses.forEach((course) => { - course.navOptions = options.navOptions[course.id]; - course.admOptions = options.admOptions[course.id]; - }); - - this.courses = courses; - this.filteredCourses = this.courses; - this.filter = ''; - } catch (error) { - CoreDomUtils.showErrorModalDefault(error, 'core.courses.errorloadcourses', true); - } - } - - /** - * Refresh the courses. - * - * @param refresher Refresher. - */ - refreshCourses(refresher: IonRefresher): void { - const promises: Promise[] = []; - - promises.push(CoreCourses.invalidateUserCourses()); - promises.push(CoreCourseOptionsDelegate.clearAndInvalidateCoursesOptions()); - if (this.courseIds) { - promises.push(CoreCourses.invalidateCoursesByField('ids', this.courseIds)); - } - - Promise.all(promises).finally(() => { - this.fetchCourses().finally(() => { - refresher?.complete(); - }); - }); - } - - /** - * Show or hide the filter. - */ - switchFilter(): void { - this.filter = ''; - this.showFilter = !this.showFilter; - this.filteredCourses = this.courses; - if (this.showFilter) { - setTimeout(() => { - this.searchbar.setFocus(); - }, 500); - } - } - - /** - * The filter has changed. - * - * @param Received Event. - */ - filterChanged(event?: Event): void { - const target = event?.target || null; - const newValue = target ? String(target.value).trim().toLowerCase() : null; - if (!newValue || !this.courses) { - this.filteredCourses = this.courses; - } else { - // Use displayname if available, or fullname if not. - if (this.courses.length > 0 && typeof this.courses[0].displayname != 'undefined') { - this.filteredCourses = this.courses.filter((course) => course.displayname!.toLowerCase().indexOf(newValue) > -1); - } else { - this.filteredCourses = this.courses.filter((course) => course.fullname.toLowerCase().indexOf(newValue) > -1); - } - } - } - - /** - * Prefetch all the courses. - * - * @return Promise resolved when done. - */ - async prefetchCourses(): Promise { - this.downloadAllCoursesLoading = true; - - try { - await CoreCourseHelper.confirmAndPrefetchCourses(this.courses, { onProgress: (progress) => { - this.downloadAllCoursesBadge = progress.count + ' / ' + progress.total; - this.downloadAllCoursesBadgeA11yText = - Translate.instant('core.course.downloadcoursesprogressdescription', progress); - this.downloadAllCoursesCount = progress.count; - this.downloadAllCoursesTotal = progress.total; - } }); - } catch (error) { - if (!this.isDestroyed) { - CoreDomUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true); - } - } - - this.downloadAllCoursesBadge = ''; - this.downloadAllCoursesLoading = false; - } - - /** - * Go to search courses. - */ - openSearch(): void { - CoreNavigator.navigateToSitePath('courses/list', { params : { mode: 'search' } }); - } - - /** - * Page destroyed. - */ - ngOnDestroy(): void { - this.isDestroyed = true; - this.myCoursesObserver?.off(); - this.siteUpdatedObserver?.off(); - } - -} diff --git a/src/core/features/courses/services/courses.ts b/src/core/features/courses/services/courses.ts index e05585344..7b52afce7 100644 --- a/src/core/features/courses/services/courses.ts +++ b/src/core/features/courses/services/courses.ts @@ -20,6 +20,7 @@ import { makeSingleton } from '@singletons'; import { CoreStatusWithWarningsWSResponse, CoreWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; import { CoreEvents } from '@singletons/events'; import { CoreWSError } from '@classes/errors/wserror'; +import { CoreCourseWithImageAndColor } from './courses-helper'; const ROOT_CACHE_KEY = 'mmCourses:'; @@ -1121,6 +1122,7 @@ export class CoreCoursesProvider { * @param text Text to search. * @param page Page to get. * @param perPage Number of courses per page. Defaults to CoreCoursesProvider.SEARCH_PER_PAGE. + * @param limitToEnrolled Limit to enrolled courses. * @param siteId Site ID. If not defined, use current site. * @return Promise resolved with the courses and the total of matches. */ @@ -1128,6 +1130,7 @@ export class CoreCoursesProvider { text: string, page: number = 0, perPage: number = CoreCoursesProvider.SEARCH_PER_PAGE, + limitToEnrolled: boolean = false, siteId?: string, ): Promise<{ total: number; courses: CoreCourseBasicSearchedData[] }> { const site = await CoreSites.getSite(siteId); @@ -1136,6 +1139,7 @@ export class CoreCoursesProvider { criteriavalue: text, page: page, perpage: perPage, + limittoenrolled: limitToEnrolled, }; const preSets: CoreSiteWSPreSets = { getFromCache: false, @@ -1358,6 +1362,14 @@ export type CoreCourseSearchedData = CoreCourseBasicSearchedData & { courseformatoptions?: CoreCourseFormatOption[]; // Additional options for particular course format. }; +/** + * Course to render as list item. + */ +export type CoreCourseListItem = CoreCourseSearchedData & CoreCourseWithImageAndColor & { + completionusertracked?: boolean; // If the user is completion tracked. + progress?: number | null; // Progress percentage. +}; + export type CoreCourseGetCoursesData = CoreEnrolledCourseBasicData & { categoryid: number; // Category id. categorysortorder?: number; // Sort order into the category. diff --git a/src/core/features/sitehome/pages/index/index.ts b/src/core/features/sitehome/pages/index/index.ts index 5216e6973..dcc3491de 100644 --- a/src/core/features/sitehome/pages/index/index.ts +++ b/src/core/features/sitehome/pages/index/index.ts @@ -223,7 +223,7 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy { * Go to my courses. */ openMyCourses(): void { - CoreNavigator.navigateToSitePath('courses/my'); + CoreNavigator.navigateToSitePath('courses/list', { params : { mode: 'my' } }); } /**