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

@ -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.