MOBILE-4270 calendar: Fix all courses filter item
parent
ea44d5cc63
commit
4cc95b0493
|
@ -19,6 +19,7 @@ import { ModalController } from '@singletons';
|
|||
import { CoreEvents } from '@singletons/events';
|
||||
import { AddonCalendarEventType, AddonCalendarProvider } from '../../services/calendar';
|
||||
import { AddonCalendarFilter, AddonCalendarEventIcons } from '../../services/calendar-helper';
|
||||
import { ALL_COURSES_ID } from '@features/courses/services/courses-helper';
|
||||
|
||||
/**
|
||||
* 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
|
|||
})
|
||||
export class AddonCalendarFilterComponent implements OnInit {
|
||||
|
||||
@Input() courses: Partial<CoreEnrolledCourseData>[] = [];
|
||||
@Input() courses: CoreEnrolledCourseData[] = [];
|
||||
@Input() filter: AddonCalendarFilter = {
|
||||
filtered: false,
|
||||
courseId: undefined,
|
||||
|
@ -45,7 +46,7 @@ export class AddonCalendarFilterComponent implements OnInit {
|
|||
courseId = -1;
|
||||
typeIcons: AddonCalendarEventIcons[] = [];
|
||||
types: string[] = [];
|
||||
sortedCourses: Partial<CoreEnrolledCourseData>[] = [];
|
||||
sortedCourses: CoreEnrolledCourseData[] = [];
|
||||
|
||||
constructor() {
|
||||
CoreUtils.enumKeys(AddonCalendarEventType).forEach((name) => {
|
||||
|
@ -60,10 +61,18 @@ export class AddonCalendarFilterComponent implements OnInit {
|
|||
* @inheritdoc
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.courseId = this.filter.courseId || -1;
|
||||
this.courseId = this.filter.courseId || ALL_COURSES_ID;
|
||||
this.sortedCourses = Array.from(this.courses).sort((a, b) => {
|
||||
if (a.id === ALL_COURSES_ID) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
this.sortedCourses = Array.from(this.courses)
|
||||
.sort((a, b) => (a.shortname?.toLowerCase() ?? '').localeCompare(b.shortname?.toLowerCase() ?? ''));
|
||||
if (b.id === ALL_COURSES_ID) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return (a.shortname?.toLowerCase() ?? '').localeCompare(b.shortname?.toLowerCase() ?? '');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -489,7 +489,7 @@ type PreloadedDay = DayBasicData & CoreSwipeSlidesDynamicItem & {
|
|||
*/
|
||||
class AddonCalendarDaySlidesItemsManagerSource extends CoreSwipeSlidesDynamicItemsManagerSource<PreloadedDay> {
|
||||
|
||||
courses: Partial<CoreEnrolledCourseData>[] = [];
|
||||
courses: CoreEnrolledCourseData[] = [];
|
||||
eventsSources: Set<AddonCalendarEventsSource> = new Set();
|
||||
// Offline events classified in month & day.
|
||||
offlineEvents: Record<string, Record<number, AddonCalendarEventToDisplay[]>> = {};
|
||||
|
|
|
@ -62,7 +62,7 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy {
|
|||
year?: number;
|
||||
month?: number;
|
||||
canCreate = false;
|
||||
courses: Partial<CoreEnrolledCourseData>[] = [];
|
||||
courses: CoreEnrolledCourseData[] = [];
|
||||
loaded = false;
|
||||
hasOffline = false;
|
||||
isOnline = false;
|
||||
|
|
|
@ -31,6 +31,9 @@ import { firstValueFrom, zipIncludingComplete } from '@/core/utils/rxjs';
|
|||
import { catchError, map } from 'rxjs/operators';
|
||||
import { chainRequests, WSObservable } from '@classes/site';
|
||||
|
||||
// Id for a course item representing all courses (for example, for course filters).
|
||||
export const ALL_COURSES_ID = -1;
|
||||
|
||||
/**
|
||||
* Helper to gather some common courses functions.
|
||||
*/
|
||||
|
@ -45,14 +48,17 @@ export class CoreCoursesHelperProvider {
|
|||
* @param courseId Course ID to get the category.
|
||||
* @returns Promise resolved with the list of courses and the category.
|
||||
*/
|
||||
async getCoursesForPopover(courseId?: number): Promise<{courses: Partial<CoreEnrolledCourseData>[]; categoryId?: number}> {
|
||||
const courses: Partial<CoreEnrolledCourseData>[] = await CoreCourses.getUserCourses(false);
|
||||
async getCoursesForPopover(courseId?: number): Promise<{courses: CoreEnrolledCourseData[]; categoryId?: number}> {
|
||||
const courses: CoreEnrolledCourseData[] = await CoreCourses.getUserCourses(false);
|
||||
|
||||
// Add "All courses".
|
||||
courses.unshift({
|
||||
id: -1,
|
||||
id: ALL_COURSES_ID,
|
||||
fullname: Translate.instant('core.fulllistofcourses'),
|
||||
shortname: Translate.instant('core.fulllistofcourses'),
|
||||
categoryid: -1,
|
||||
summary: '',
|
||||
summaryformat: 1,
|
||||
});
|
||||
|
||||
let categoryId: number | undefined;
|
||||
|
|
Loading…
Reference in New Issue