diff --git a/src/addons/calendar/components/filter/addon-calendar-filter-popover.html b/src/addons/calendar/components/filter/addon-calendar-filter-popover.html index 8c2d75c7d..590a32b27 100644 --- a/src/addons/calendar/components/filter/addon-calendar-filter-popover.html +++ b/src/addons/calendar/components/filter/addon-calendar-filter-popover.html @@ -9,7 +9,7 @@ - + diff --git a/src/addons/calendar/components/filter/filter.ts b/src/addons/calendar/components/filter/filter.ts index 9398c60b7..8827846c5 100644 --- a/src/addons/calendar/components/filter/filter.ts +++ b/src/addons/calendar/components/filter/filter.ts @@ -31,7 +31,7 @@ export class AddonCalendarFilterPopoverComponent implements OnInit { @Input() filter: AddonCalendarFilter = { filtered: false, - courseId: -1, + courseId: undefined, categoryId: undefined, course: true, group: true, @@ -40,7 +40,7 @@ export class AddonCalendarFilterPopoverComponent implements OnInit { category: true, }; - courseId = '-1'; + courseId = -1; @Input() courses: Partial[] = []; typeIcons: AddonCalendarEventIcons[] = []; @@ -59,24 +59,23 @@ export class AddonCalendarFilterPopoverComponent implements OnInit { * Init the component. */ ngOnInit(): void { - this.courseId = (this.filter.courseId || -1) + ''; + this.courseId = this.filter.courseId || -1; } /** * Function called when an item is clicked. */ onChange(): void { - const courseId = parseInt(this.courseId, 10); - if (courseId > 0) { - const course = this.courses.find((course) => courseId == course.id); - this.filter.courseId = course?.id || -1; + if (this.courseId > 0) { + const course = this.courses.find((course) => this.courseId == course.id); + this.filter.courseId = course?.id; this.filter.categoryId = course?.categoryid; } else { - this.filter.courseId = -1; + this.filter.courseId = undefined; this.filter.categoryId = undefined; } - this.filter.filtered = this.filter.courseId > 0 || this.types.some((name) => !this.filter[name]); + this.filter.filtered = !!this.filter.courseId || this.types.some((name) => !this.filter[name]); CoreEvents.trigger(AddonCalendarProvider.FILTER_CHANGED_EVENT, this.filter); } diff --git a/src/addons/calendar/pages/list/list.page.ts b/src/addons/calendar/pages/list/list.page.ts index 33d00b3c8..d7d97a084 100644 --- a/src/addons/calendar/pages/list/list.page.ts +++ b/src/addons/calendar/pages/list/list.page.ts @@ -89,7 +89,7 @@ export class AddonCalendarListPage implements OnInit, OnDestroy { syncIcon = CoreConstants.ICON_LOADING; filter: AddonCalendarFilter = { filtered: false, - courseId: -1, + courseId: undefined, categoryId: undefined, course: true, group: true, @@ -212,7 +212,7 @@ export class AddonCalendarListPage implements OnInit, OnDestroy { * View loaded. */ async ngOnInit(): Promise { - this.filter.courseId = CoreNavigator.getRouteNumberParam('courseId') || -1; + this.filter.courseId = CoreNavigator.getRouteNumberParam('courseId'); this.syncIcon = CoreConstants.ICON_LOADING; await this.fetchData(false, true, false); diff --git a/src/addons/mod/data/fields/date/component/date.ts b/src/addons/mod/data/fields/date/component/date.ts index 5639572e9..5fa517dd7 100644 --- a/src/addons/mod/data/fields/date/component/date.ts +++ b/src/addons/mod/data/fields/date/component/date.ts @@ -36,6 +36,10 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo */ protected init(): void { if (this.displayMode) { + this.displayDate = this.value?.content + ? parseInt(this.value.content, 10) * 1000 + : undefined; + return; } @@ -62,10 +66,6 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo ? new Date(parseInt(this.value.content, 10) * 1000) : new Date(); - this.displayDate = this.value?.content - ? parseInt(this.value.content, 10) * 1000 - : undefined; - } this.addControl('f_' + this.field.id, CoreTimeUtils.toDatetimeFormat(date.getTime())); diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 5895170ad..789922816 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -407,7 +407,11 @@ export class CoreDomUtilsProvider { return size; } - size = Number(size); + if (typeof size == 'string') { + // It's important to use parseInt instead of Number because Number('') is 0 instead of NaN. + size = parseInt(size, 10); + } + if (!isNaN(size)) { return size + 'px'; }