MOBILE-2614 dashboard: Sort courses on refresh
parent
abddc4766d
commit
e9237358a1
|
@ -243,6 +243,21 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
* @param {any[]} courses Courses to filter.
|
* @param {any[]} courses Courses to filter.
|
||||||
*/
|
*/
|
||||||
initCourseFilters(courses: any[]): void {
|
initCourseFilters(courses: any[]): void {
|
||||||
|
if (this.showSortFilter) {
|
||||||
|
if (this.sort == 'lastaccess') {
|
||||||
|
courses.sort((a, b) => {
|
||||||
|
return b.lastaccess - a.lastaccess;
|
||||||
|
});
|
||||||
|
} else if (this.sort == 'fullname') {
|
||||||
|
courses.sort((a, b) => {
|
||||||
|
const compareA = a.fullname.toLowerCase(),
|
||||||
|
compareB = b.fullname.toLowerCase();
|
||||||
|
|
||||||
|
return compareA.localeCompare(compareB);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.courses.all = [];
|
this.courses.all = [];
|
||||||
this.courses.past = [];
|
this.courses.past = [];
|
||||||
this.courses.inprogress = [];
|
this.courses.inprogress = [];
|
||||||
|
@ -285,24 +300,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
switchSort(sort: string): void {
|
switchSort(sort: string): void {
|
||||||
this.sort = sort;
|
this.sort = sort;
|
||||||
this.currentSite.setLocalSiteConfig('AddonBlockMyOverviewSort', this.sort);
|
this.currentSite.setLocalSiteConfig('AddonBlockMyOverviewSort', this.sort);
|
||||||
const courses = this.courses.all.concat(this.courses.hidden);
|
this.initCourseFilters(this.courses.all.concat(this.courses.hidden));
|
||||||
|
|
||||||
if (this.showSortFilter) {
|
|
||||||
if (this.sort == 'lastaccess') {
|
|
||||||
courses.sort((a, b) => {
|
|
||||||
return b.lastaccess - a.lastaccess;
|
|
||||||
});
|
|
||||||
} else if (this.sort == 'fullname') {
|
|
||||||
courses.sort((a, b) => {
|
|
||||||
const compareA = a.fullname.toLowerCase(),
|
|
||||||
compareB = b.fullname.toLowerCase();
|
|
||||||
|
|
||||||
return compareA.localeCompare(compareB);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initCourseFilters(courses);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue