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

@ -175,12 +175,20 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
const newValue = event.target.value && event.target.value.trim().toLowerCase(); const newValue = event.target.value && event.target.value.trim().toLowerCase();
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 {
// 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 { } else {
this.filteredCourses = this.courses[this.selectedFilter].filter((course) => { this.filteredCourses = this.courses[this.selectedFilter].filter((course) => {
return course.fullname.toLowerCase().indexOf(newValue) > -1; return course.fullname.toLowerCase().indexOf(newValue) > -1;
}); });
} }
} }
}
/** /**
* Initialize the prefetch icon for selected courses. * Initialize the prefetch icon for selected courses.

View File

@ -172,12 +172,19 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
const newValue = event.target.value && event.target.value.trim().toLowerCase(); const newValue = event.target.value && event.target.value.trim().toLowerCase();
if (!newValue || !this.courses) { if (!newValue || !this.courses) {
this.filteredCourses = this.courses; this.filteredCourses = this.courses;
} else {
// 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 { } else {
this.filteredCourses = this.courses.filter((course) => { this.filteredCourses = this.courses.filter((course) => {
return course.fullname.toLowerCase().indexOf(newValue) > -1; return course.fullname.toLowerCase().indexOf(newValue) > -1;
}); });
} }
} }
}
/** /**
* Prefetch all the courses. * Prefetch all the courses.