MOBILE-3249 blocks: Sort courses by short name
parent
221b1f51cb
commit
4e727ba860
|
@ -11,7 +11,8 @@
|
||||||
<core-context-menu item-end>
|
<core-context-menu item-end>
|
||||||
<core-context-menu-item *ngIf="loaded && showFilterSwitchButton()" [priority]="1000" [content]="'core.courses.filtermycourses' | translate" (action)="switchFilter()" iconAction="funnel" (onClosed)="switchFilterClosed()"></core-context-menu-item>
|
<core-context-menu-item *ngIf="loaded && showFilterSwitchButton()" [priority]="1000" [content]="'core.courses.filtermycourses' | translate" (action)="switchFilter()" iconAction="funnel" (onClosed)="switchFilterClosed()"></core-context-menu-item>
|
||||||
<core-context-menu-item *ngIf="loaded && showSortFilter" [priority]="900" content="{{('core.sortby' | translate) + ' ' + ('addon.block_myoverview.title' | translate)}}" (action)="switchSort('fullname')" [iconAction]="sort == 'fullname' ? 'radio-button-on' : 'radio-button-off'"></core-context-menu-item>
|
<core-context-menu-item *ngIf="loaded && showSortFilter" [priority]="900" content="{{('core.sortby' | translate) + ' ' + ('addon.block_myoverview.title' | translate)}}" (action)="switchSort('fullname')" [iconAction]="sort == 'fullname' ? 'radio-button-on' : 'radio-button-off'"></core-context-menu-item>
|
||||||
<core-context-menu-item *ngIf="loaded && showSortFilter" [priority]="800" content="{{('core.sortby' | translate) + ' ' + ('addon.block_myoverview.lastaccessed' | translate)}}" (action)="switchSort('lastaccess')" [iconAction]="sort == 'lastaccess' ? 'radio-button-on' : 'radio-button-off'"></core-context-menu-item>
|
<core-context-menu-item *ngIf="loaded && showSortFilter && showSortByShortName" [priority]="800" content="{{('core.sortby' | translate) + ' ' + ('addon.block_myoverview.shortname' | translate)}}" (action)="switchSort('shortname')" [iconAction]="sort == 'shortname' ? 'radio-button-on' : 'radio-button-off'"></core-context-menu-item>
|
||||||
|
<core-context-menu-item *ngIf="loaded && showSortFilter" [priority]="700" content="{{('core.sortby' | translate) + ' ' + ('addon.block_myoverview.lastaccessed' | translate)}}" (action)="switchSort('lastaccess')" [iconAction]="sort == 'lastaccess' ? 'radio-button-on' : 'radio-button-off'"></core-context-menu-item>
|
||||||
</core-context-menu>
|
</core-context-menu>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
<core-loading [hideUntil]="loaded" class="core-loading-center">
|
<core-loading [hideUntil]="loaded" class="core-loading-center">
|
||||||
|
|
|
@ -83,6 +83,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
protected updateSiteObserver;
|
protected updateSiteObserver;
|
||||||
protected courseIds = [];
|
protected courseIds = [];
|
||||||
protected fetchContentDefaultError = 'Error getting my overview data.';
|
protected fetchContentDefaultError = 'Error getting my overview data.';
|
||||||
|
protected showSortByShortName = false;
|
||||||
|
|
||||||
constructor(injector: Injector,
|
constructor(injector: Injector,
|
||||||
protected coursesProvider: CoreCoursesProvider,
|
protected coursesProvider: CoreCoursesProvider,
|
||||||
|
@ -181,6 +182,18 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
const showCategories = config && config.displaycategories && config.displaycategories.value == '1';
|
const showCategories = config && config.displaycategories && config.displaycategories.value == '1';
|
||||||
|
|
||||||
return this.coursesHelper.getUserCoursesWithOptions(this.sort, null, null, showCategories).then((courses) => {
|
return this.coursesHelper.getUserCoursesWithOptions(this.sort, null, null, showCategories).then((courses) => {
|
||||||
|
// Check to show sort by short name only if the text is visible.
|
||||||
|
if (courses.length > 0) {
|
||||||
|
const sampleCourse = courses[0];
|
||||||
|
this.showSortByShortName = sampleCourse.displayname && sampleCourse.shortname &&
|
||||||
|
sampleCourse.fullname != sampleCourse.displayname;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rollback to sort by full name if user is sorting by short name then Moodle web change the config.
|
||||||
|
if (!this.showSortByShortName && this.sort === 'shortname') {
|
||||||
|
this.switchSort('fullname');
|
||||||
|
}
|
||||||
|
|
||||||
this.courseIds = courses.map((course) => {
|
this.courseIds = courses.map((course) => {
|
||||||
return course.id;
|
return course.id;
|
||||||
});
|
});
|
||||||
|
@ -395,7 +408,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
this.courses.allincludinghidden = courses;
|
this.courses.allincludinghidden = courses;
|
||||||
|
|
||||||
if (this.showSortFilter) {
|
if (this.showSortFilter) {
|
||||||
if (this.sort == 'lastaccess') {
|
if (this.sort == 'lastaccess') {
|
||||||
courses.sort((a, b) => {
|
courses.sort((a, b) => {
|
||||||
return b.lastaccess - a.lastaccess;
|
return b.lastaccess - a.lastaccess;
|
||||||
});
|
});
|
||||||
|
@ -404,6 +417,14 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
const compareA = a.fullname.toLowerCase(),
|
const compareA = a.fullname.toLowerCase(),
|
||||||
compareB = b.fullname.toLowerCase();
|
compareB = b.fullname.toLowerCase();
|
||||||
|
|
||||||
|
return compareA.localeCompare(compareB);
|
||||||
|
});
|
||||||
|
} else if (this.sort == 'shortname') {
|
||||||
|
courses.sort((a, b) => {
|
||||||
|
const compareA = a.shortname.toLowerCase(),
|
||||||
|
compareB = b.shortname.toLowerCase();
|
||||||
|
compareA.localeCompare();
|
||||||
|
|
||||||
return compareA.localeCompare(compareB);
|
return compareA.localeCompare(compareB);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,5 +10,6 @@
|
||||||
"nocourses": "No courses",
|
"nocourses": "No courses",
|
||||||
"past": "Past",
|
"past": "Past",
|
||||||
"pluginname": "Course overview",
|
"pluginname": "Course overview",
|
||||||
|
"shortname": "Short name",
|
||||||
"title": "Course name"
|
"title": "Course name"
|
||||||
}
|
}
|
|
@ -49,6 +49,7 @@
|
||||||
"addon.block_myoverview.nocourses": "No courses",
|
"addon.block_myoverview.nocourses": "No courses",
|
||||||
"addon.block_myoverview.past": "Past",
|
"addon.block_myoverview.past": "Past",
|
||||||
"addon.block_myoverview.pluginname": "Course overview",
|
"addon.block_myoverview.pluginname": "Course overview",
|
||||||
|
"addon.block_myoverview.shortname": "Short name",
|
||||||
"addon.block_myoverview.title": "Course name",
|
"addon.block_myoverview.title": "Course name",
|
||||||
"addon.block_newsitems.pluginname": "Latest announcements",
|
"addon.block_newsitems.pluginname": "Latest announcements",
|
||||||
"addon.block_onlineusers.pluginname": "Online users",
|
"addon.block_onlineusers.pluginname": "Online users",
|
||||||
|
|
|
@ -212,6 +212,14 @@ export class CoreCoursesHelperProvider {
|
||||||
return b.timemodified - a.timemodified;
|
return b.timemodified - a.timemodified;
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case 'shortname':
|
||||||
|
courses.sort((a, b) => {
|
||||||
|
const compareA = a.shortname.toLowerCase(),
|
||||||
|
compareB = b.shortname.toLowerCase();
|
||||||
|
|
||||||
|
return compareA.localeCompare(compareB);
|
||||||
|
});
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// Sort not implemented. Do not sort.
|
// Sort not implemented. Do not sort.
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue