MOBILE-2709 courses: Filter courses using shortname

main
Pau Ferrer Ocaña 2018-11-09 13:27:46 +01:00
parent 85a15eb651
commit 900a0b3319
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]) {
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;
});
}
}
}

View File

@ -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;
});
}
}
}