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