Merge pull request #1599 from crazyserver/MOBILE-2709

MOBILE-2709 courses: Filter courses using shortname
main
Juan Leyva 2018-11-12 16:41:20 +01:00 committed by GitHub
commit 6516b283e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View File

@ -176,9 +176,17 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
if (!newValue || !this.courses[this.selectedFilter]) { if (!newValue || !this.courses[this.selectedFilter]) {
this.filteredCourses = this.courses[this.selectedFilter]; this.filteredCourses = this.courses[this.selectedFilter];
} else { } else {
this.filteredCourses = this.courses[this.selectedFilter].filter((course) => { // Use displayname if avalaible, or fullname if not.
return course.fullname.toLowerCase().indexOf(newValue) > -1; 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;
});
}
} }
} }

View File

@ -173,9 +173,16 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
if (!newValue || !this.courses) { if (!newValue || !this.courses) {
this.filteredCourses = this.courses; this.filteredCourses = this.courses;
} else { } else {
this.filteredCourses = this.courses.filter((course) => { // Use displayname if avalaible, or fullname if not.
return course.fullname.toLowerCase().indexOf(newValue) > -1; 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;
});
}
} }
} }