Skip to content

Commit 4cc95b0

Browse files
committed
MOBILE-4270 calendar: Fix all courses filter item
1 parent ea44d5c commit 4cc95b0

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

src/addons/calendar/components/filter/filter.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ModalController } from '@singletons';
1919
import { CoreEvents } from '@singletons/events';
2020
import { AddonCalendarEventType, AddonCalendarProvider } from '../../services/calendar';
2121
import { AddonCalendarFilter, AddonCalendarEventIcons } from '../../services/calendar-helper';
22+
import { ALL_COURSES_ID } from '@features/courses/services/courses-helper';
2223

2324
/**
2425
* Component to display the events filter that includes events types and a list of courses.
@@ -30,7 +31,7 @@ import { AddonCalendarFilter, AddonCalendarEventIcons } from '../../services/cal
3031
})
3132
export class AddonCalendarFilterComponent implements OnInit {
3233

33-
@Input() courses: Partial<CoreEnrolledCourseData>[] = [];
34+
@Input() courses: CoreEnrolledCourseData[] = [];
3435
@Input() filter: AddonCalendarFilter = {
3536
filtered: false,
3637
courseId: undefined,
@@ -45,7 +46,7 @@ export class AddonCalendarFilterComponent implements OnInit {
4546
courseId = -1;
4647
typeIcons: AddonCalendarEventIcons[] = [];
4748
types: string[] = [];
48-
sortedCourses: Partial<CoreEnrolledCourseData>[] = [];
49+
sortedCourses: CoreEnrolledCourseData[] = [];
4950

5051
constructor() {
5152
CoreUtils.enumKeys(AddonCalendarEventType).forEach((name) => {
@@ -60,10 +61,18 @@ export class AddonCalendarFilterComponent implements OnInit {
6061
* @inheritdoc
6162
*/
6263
ngOnInit(): void {
63-
this.courseId = this.filter.courseId || -1;
64+
this.courseId = this.filter.courseId || ALL_COURSES_ID;
65+
this.sortedCourses = Array.from(this.courses).sort((a, b) => {
66+
if (a.id === ALL_COURSES_ID) {
67+
return -1;
68+
}
6469

65-
this.sortedCourses = Array.from(this.courses)
66-
.sort((a, b) => (a.shortname?.toLowerCase() ?? '').localeCompare(b.shortname?.toLowerCase() ?? ''));
70+
if (b.id === ALL_COURSES_ID) {
71+
return 1;
72+
}
73+
74+
return (a.shortname?.toLowerCase() ?? '').localeCompare(b.shortname?.toLowerCase() ?? '');
75+
});
6776
}
6877

6978
/**

src/addons/calendar/pages/day/day.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ type PreloadedDay = DayBasicData & CoreSwipeSlidesDynamicItem & {
489489
*/
490490
class AddonCalendarDaySlidesItemsManagerSource extends CoreSwipeSlidesDynamicItemsManagerSource<PreloadedDay> {
491491

492-
courses: Partial<CoreEnrolledCourseData>[] = [];
492+
courses: CoreEnrolledCourseData[] = [];
493493
eventsSources: Set<AddonCalendarEventsSource> = new Set();
494494
// Offline events classified in month & day.
495495
offlineEvents: Record<string, Record<number, AddonCalendarEventToDisplay[]>> = {};

src/addons/calendar/pages/index/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy {
6262
year?: number;
6363
month?: number;
6464
canCreate = false;
65-
courses: Partial<CoreEnrolledCourseData>[] = [];
65+
courses: CoreEnrolledCourseData[] = [];
6666
loaded = false;
6767
hasOffline = false;
6868
isOnline = false;

src/core/features/courses/services/courses-helper.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import { firstValueFrom, zipIncludingComplete } from '@/core/utils/rxjs';
3131
import { catchError, map } from 'rxjs/operators';
3232
import { chainRequests, WSObservable } from '@classes/site';
3333

34+
// Id for a course item representing all courses (for example, for course filters).
35+
export const ALL_COURSES_ID = -1;
36+
3437
/**
3538
* Helper to gather some common courses functions.
3639
*/
@@ -45,14 +48,17 @@ export class CoreCoursesHelperProvider {
4548
* @param courseId Course ID to get the category.
4649
* @returns Promise resolved with the list of courses and the category.
4750
*/
48-
async getCoursesForPopover(courseId?: number): Promise<{courses: Partial<CoreEnrolledCourseData>[]; categoryId?: number}> {
49-
const courses: Partial<CoreEnrolledCourseData>[] = await CoreCourses.getUserCourses(false);
51+
async getCoursesForPopover(courseId?: number): Promise<{courses: CoreEnrolledCourseData[]; categoryId?: number}> {
52+
const courses: CoreEnrolledCourseData[] = await CoreCourses.getUserCourses(false);
5053

5154
// Add "All courses".
5255
courses.unshift({
53-
id: -1,
56+
id: ALL_COURSES_ID,
5457
fullname: Translate.instant('core.fulllistofcourses'),
58+
shortname: Translate.instant('core.fulllistofcourses'),
5559
categoryid: -1,
60+
summary: '',
61+
summaryformat: 1,
5662
});
5763

5864
let categoryId: number | undefined;

0 commit comments

Comments
 (0)