From 900a0b3319faa737387dd52c270077e8bc4e60b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 9 Nov 2018 13:27:46 +0100 Subject: [PATCH] MOBILE-2709 courses: Filter courses using shortname --- .../myoverview/components/myoverview/myoverview.ts | 14 +++++++++++--- src/core/courses/pages/my-courses/my-courses.ts | 13 ++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/addon/block/myoverview/components/myoverview/myoverview.ts b/src/addon/block/myoverview/components/myoverview/myoverview.ts index b628deccd..690c590a8 100644 --- a/src/addon/block/myoverview/components/myoverview/myoverview.ts +++ b/src/addon/block/myoverview/components/myoverview/myoverview.ts @@ -176,9 +176,17 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem if (!newValue || !this.courses[this.selectedFilter]) { this.filteredCourses = this.courses[this.selectedFilter]; } else { - this.filteredCourses = this.courses[this.selectedFilter].filter((course) => { - return course.fullname.toLowerCase().indexOf(newValue) > -1; - }); + // Use displayname if avalaible, or fullname if not. + if (this.courses[this.selectedFilter].length > 0 && + typeof this.courses[this.selectedFilter][0].displayname != 'undefined') { + this.filteredCourses = this.courses[this.selectedFilter].filter((course) => { + return course.displayname.toLowerCase().indexOf(newValue) > -1; + }); + } else { + this.filteredCourses = this.courses[this.selectedFilter].filter((course) => { + return course.fullname.toLowerCase().indexOf(newValue) > -1; + }); + } } } diff --git a/src/core/courses/pages/my-courses/my-courses.ts b/src/core/courses/pages/my-courses/my-courses.ts index 6a67618a1..bf874e962 100644 --- a/src/core/courses/pages/my-courses/my-courses.ts +++ b/src/core/courses/pages/my-courses/my-courses.ts @@ -173,9 +173,16 @@ export class CoreCoursesMyCoursesPage implements OnDestroy { if (!newValue || !this.courses) { this.filteredCourses = this.courses; } else { - this.filteredCourses = this.courses.filter((course) => { - return course.fullname.toLowerCase().indexOf(newValue) > -1; - }); + // Use displayname if avalaible, or fullname if not. + if (this.courses.length > 0 && typeof this.courses[0].displayname != 'undefined') { + this.filteredCourses = this.courses.filter((course) => { + return course.displayname.toLowerCase().indexOf(newValue) > -1; + }); + } else { + this.filteredCourses = this.courses.filter((course) => { + return course.fullname.toLowerCase().indexOf(newValue) > -1; + }); + } } }