From 3959df94d5ffc03290d55d70e15c43fae6178607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 15 Nov 2024 12:53:15 +0100 Subject: [PATCH] MOBILE-4653 calendar: Partially decouple calendar --- .../calendarmonth/services/block-handler.ts | 4 +- .../services/block-handler.ts | 4 +- src/addons/calendar/calendar-lazy.module.ts | 4 +- src/addons/calendar/calendar.module.ts | 5 +- .../calendar/components/calendar/calendar.ts | 4 +- .../calendar/components/filter/filter.ts | 6 +- .../upcoming-events/upcoming-events.ts | 4 +- src/addons/calendar/constants.ts | 43 +++++++ src/addons/calendar/pages/day/day.ts | 33 ++++-- .../calendar/pages/edit-event/edit-event.ts | 26 +++-- src/addons/calendar/pages/event/event.ts | 28 +++-- src/addons/calendar/pages/index/index.ts | 32 ++++-- .../calendar/services/calendar-helper.ts | 25 ++-- src/addons/calendar/services/calendar-sync.ts | 36 ++++-- src/addons/calendar/services/calendar.ts | 108 ++++++++---------- .../services/database/calendar-offline.ts | 3 +- .../calendar/services/database/calendar.ts | 7 +- .../calendar/services/handlers/mainmenu.ts | 5 +- .../reminders/services/database/reminders.ts | 8 +- 19 files changed, 225 insertions(+), 160 deletions(-) diff --git a/src/addons/block/calendarmonth/services/block-handler.ts b/src/addons/block/calendarmonth/services/block-handler.ts index fa717ab6c..e18a10275 100644 --- a/src/addons/block/calendarmonth/services/block-handler.ts +++ b/src/addons/block/calendarmonth/services/block-handler.ts @@ -19,8 +19,8 @@ import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler import { CoreCourseBlock } from '@features/course/services/course'; import { Params } from '@angular/router'; import { makeSingleton } from '@singletons'; -import { AddonCalendarMainMenuHandlerService } from '@addons/calendar/services/handlers/mainmenu'; import { ContextLevel } from '@/core/constants'; +import { ADDON_CALENDAR_PAGE_NAME } from '@addons/calendar/constants'; /** * Block handler. @@ -46,7 +46,7 @@ export class AddonBlockCalendarMonthHandlerService extends CoreBlockBaseHandler title: 'addon.block_calendarmonth.pluginname', class: 'addon-block-calendar-month', component: CoreBlockOnlyTitleComponent, - link: AddonCalendarMainMenuHandlerService.PAGE_NAME, + link: ADDON_CALENDAR_PAGE_NAME, linkParams: linkParams, navOptions: { preferCurrentTab: false, diff --git a/src/addons/block/calendarupcoming/services/block-handler.ts b/src/addons/block/calendarupcoming/services/block-handler.ts index be3ff2c1e..68aa09ffe 100644 --- a/src/addons/block/calendarupcoming/services/block-handler.ts +++ b/src/addons/block/calendarupcoming/services/block-handler.ts @@ -19,9 +19,9 @@ import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler import { CoreCourseBlock } from '@features/course/services/course'; import { Params } from '@angular/router'; import { makeSingleton } from '@singletons'; -import { AddonCalendarMainMenuHandlerService } from '@addons/calendar/services/handlers/mainmenu'; import { CoreSites } from '@services/sites'; import { ContextLevel } from '@/core/constants'; +import { ADDON_CALENDAR_PAGE_NAME } from '@addons/calendar/constants'; /** * Block handler. @@ -51,7 +51,7 @@ export class AddonBlockCalendarUpcomingHandlerService extends CoreBlockBaseHandl title: 'addon.block_calendarupcoming.pluginname', class: 'addon-block-calendar-upcoming', component: CoreBlockOnlyTitleComponent, - link: AddonCalendarMainMenuHandlerService.PAGE_NAME, + link: ADDON_CALENDAR_PAGE_NAME, linkParams: linkParams, }; } diff --git a/src/addons/calendar/calendar-lazy.module.ts b/src/addons/calendar/calendar-lazy.module.ts index d228e4b70..538c6c366 100644 --- a/src/addons/calendar/calendar-lazy.module.ts +++ b/src/addons/calendar/calendar-lazy.module.ts @@ -25,7 +25,7 @@ import { CoreEditorComponentsModule } from '@features/editor/components/componen import { CoreMainMenuComponentsModule } from '@features/mainmenu/components/components.module'; import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module'; -import { AddonCalendarMainMenuHandlerService } from './services/handlers/mainmenu'; +import { ADDON_CALENDAR_PAGE_NAME } from './constants'; /** * Build module routes. @@ -37,7 +37,7 @@ function buildRoutes(injector: Injector): Routes { return [ { path: 'index', - data: { mainMenuTabRoot: AddonCalendarMainMenuHandlerService.PAGE_NAME }, + data: { mainMenuTabRoot: ADDON_CALENDAR_PAGE_NAME }, component: AddonCalendarIndexPage, }, { diff --git a/src/addons/calendar/calendar.module.ts b/src/addons/calendar/calendar.module.ts index 933c3ed40..cf90bae05 100644 --- a/src/addons/calendar/calendar.module.ts +++ b/src/addons/calendar/calendar.module.ts @@ -20,7 +20,7 @@ import { CoreMainMenuDelegate } from '@features/mainmenu/services/mainmenu-deleg import { CoreCronDelegate } from '@services/cron'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; import { AddonCalendarViewLinkHandler } from './services/handlers/view-link'; -import { AddonCalendarMainMenuHandler, AddonCalendarMainMenuHandlerService } from './services/handlers/mainmenu'; +import { AddonCalendarMainMenuHandler } from './services/handlers/mainmenu'; import { AddonCalendarSyncCronHandler } from './services/handlers/sync-cron'; import { CORE_SITE_SCHEMAS } from '@services/sites'; @@ -29,6 +29,7 @@ import { CALENDAR_OFFLINE_SITE_SCHEMA } from './services/database/calendar-offli import { AddonCalendarComponentsModule } from './components/components.module'; import { AddonCalendar } from './services/calendar'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; +import { ADDON_CALENDAR_PAGE_NAME } from './constants'; /** * Get calendar services. @@ -51,7 +52,7 @@ export async function getCalendarServices(): Promise[]> { const mainMenuChildrenRoutes: Routes = [ { - path: AddonCalendarMainMenuHandlerService.PAGE_NAME, + path: ADDON_CALENDAR_PAGE_NAME, loadChildren: () => import('./calendar-lazy.module'), }, ]; diff --git a/src/addons/calendar/components/calendar/calendar.ts b/src/addons/calendar/components/calendar/calendar.ts index 36fd30afa..419d6b047 100644 --- a/src/addons/calendar/components/calendar/calendar.ts +++ b/src/addons/calendar/components/calendar/calendar.ts @@ -32,7 +32,6 @@ import { CoreTimeUtils } from '@services/utils/time'; import { CoreUtils } from '@services/utils/utils'; import { AddonCalendar, - AddonCalendarProvider, AddonCalendarWeek, AddonCalendarWeekDaysTranslationKeys, AddonCalendarEventToDisplay, @@ -54,6 +53,7 @@ import { CoreUrl } from '@singletons/url'; import { CoreTime } from '@singletons/time'; import { Translate } from '@singletons'; import { toBoolean } from '@/core/transforms/boolean'; +import { ADDON_CALENDAR_UNDELETED_EVENT_EVENT } from '@addons/calendar/constants'; /** * Component that displays a calendar. @@ -93,7 +93,7 @@ export class AddonCalendarCalendarComponent implements OnInit, DoCheck, OnDestro // Listen for events "undeleted" (offline). this.undeleteEventObserver = CoreEvents.on( - AddonCalendarProvider.UNDELETED_EVENT_EVENT, + ADDON_CALENDAR_UNDELETED_EVENT_EVENT, (data) => { if (!data || !data.eventId) { return; diff --git a/src/addons/calendar/components/filter/filter.ts b/src/addons/calendar/components/filter/filter.ts index 94db1a1ca..929db0c2c 100644 --- a/src/addons/calendar/components/filter/filter.ts +++ b/src/addons/calendar/components/filter/filter.ts @@ -17,10 +17,10 @@ import { CoreEnrolledCourseData } from '@features/courses/services/courses'; import { CoreUtils } from '@services/utils/utils'; import { ModalController } from '@singletons'; import { CoreEvents } from '@singletons/events'; -import { AddonCalendarEventType, AddonCalendarProvider } from '../../services/calendar'; -import { AddonCalendarFilter, AddonCalendarEventIcons } from '../../services/calendar-helper'; +import { AddonCalendarFilter } from '@addons/calendar/services/calendar-helper'; import { ALL_COURSES_ID } from '@features/courses/services/courses-helper'; import { CoreSharedModule } from '@/core/shared.module'; +import { ADDON_CALENDAR_FILTER_CHANGED_EVENT, AddonCalendarEventIcons, AddonCalendarEventType } from '@addons/calendar/constants'; /** * Component to display the events filter that includes events types and a list of courses. @@ -95,7 +95,7 @@ export class AddonCalendarFilterComponent implements OnInit { this.filter.filtered = !!this.filter.courseId || this.types.some((name) => !this.filter[name]); - CoreEvents.trigger(AddonCalendarProvider.FILTER_CHANGED_EVENT, this.filter); + CoreEvents.trigger(ADDON_CALENDAR_FILTER_CHANGED_EVENT, this.filter); } /** diff --git a/src/addons/calendar/components/upcoming-events/upcoming-events.ts b/src/addons/calendar/components/upcoming-events/upcoming-events.ts index 583a762f0..c96493a03 100644 --- a/src/addons/calendar/components/upcoming-events/upcoming-events.ts +++ b/src/addons/calendar/components/upcoming-events/upcoming-events.ts @@ -17,7 +17,6 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { - AddonCalendarProvider, AddonCalendarEventToDisplay, AddonCalendar, } from '../../services/calendar'; @@ -29,6 +28,7 @@ import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreUrl } from '@singletons/url'; import { CoreTime } from '@singletons/time'; import { Translate } from '@singletons'; +import { ADDON_CALENDAR_UNDELETED_EVENT_EVENT } from '@addons/calendar/constants'; /** * Component that displays upcoming events. @@ -70,7 +70,7 @@ export class AddonCalendarUpcomingEventsComponent implements OnInit, DoCheck, On // Listen for events "undeleted" (offline). this.undeleteEventObserver = CoreEvents.on( - AddonCalendarProvider.UNDELETED_EVENT_EVENT, + ADDON_CALENDAR_UNDELETED_EVENT_EVENT, (data) => { if (!data || !data.eventId) { return; diff --git a/src/addons/calendar/constants.ts b/src/addons/calendar/constants.ts index d4632c2b8..fb3550a72 100644 --- a/src/addons/calendar/constants.ts +++ b/src/addons/calendar/constants.ts @@ -13,3 +13,46 @@ // limitations under the License. export const ADDON_CALENDAR_COMPONENT = 'AddonCalendarEvents'; + +export const ADDON_CALENDAR_PAGE_NAME = 'calendar'; + +export const ADDON_CALENDAR_EVENTS_TABLE = 'addon_calendar_events_3'; + +export const ADDON_CALENDAR_AUTO_SYNCED = 'addon_calendar_autom_synced'; +export const ADDON_CALENDAR_MANUAL_SYNCED = 'addon_calendar_manual_synced'; +export const ADDON_CALENDAR_SYNC_ID = 'calendar'; + +export const ADDON_CALENDAR_DAYS_INTERVAL = 30; + +export const ADDON_CALENDAR_STARTING_WEEK_DAY = 'addon_calendar_starting_week_day'; +export const ADDON_CALENDAR_TF_24 = '%H:%M'; // Calendar time in 24 hours format. +export const ADDON_CALENDAR_TF_12 = '%I:%M %p'; // Calendar time in 12 hours format. + +export const ADDON_CALENDAR_NEW_EVENT_EVENT = 'addon_calendar_new_event'; +export const ADDON_CALENDAR_NEW_EVENT_DISCARDED_EVENT = 'addon_calendar_new_event_discarded'; +export const ADDON_CALENDAR_EDIT_EVENT_EVENT = 'addon_calendar_edit_event'; +export const ADDON_CALENDAR_DELETED_EVENT_EVENT = 'addon_calendar_deleted_event'; +export const ADDON_CALENDAR_UNDELETED_EVENT_EVENT = 'addon_calendar_undeleted_event'; +export const ADDON_CALENDAR_FILTER_CHANGED_EVENT = 'addon_calendar_filter_changed_event'; + +/** + * Context levels enumeration. + */ +export enum AddonCalendarEventIcons { + SITE = 'fas-globe', + CATEGORY = 'fas-cubes', + COURSE = 'fas-graduation-cap', + GROUP = 'fas-users', + USER = 'fas-user', +} + +/** + * Main calendar Event types enumeration. + */ +export enum AddonCalendarEventType { + SITE = 'site', + CATEGORY = 'category', + COURSE = 'course', + GROUP = 'group', + USER = 'user', +} diff --git a/src/addons/calendar/pages/day/day.ts b/src/addons/calendar/pages/day/day.ts index 16faee918..bc7039a1c 100644 --- a/src/addons/calendar/pages/day/day.ts +++ b/src/addons/calendar/pages/day/day.ts @@ -19,15 +19,13 @@ import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreTimeUtils } from '@services/utils/time'; import { - AddonCalendarProvider, AddonCalendar, AddonCalendarEventToDisplay, AddonCalendarCalendarDay, - AddonCalendarEventType, } from '../../services/calendar'; import { AddonCalendarOffline } from '../../services/calendar-offline'; import { AddonCalendarFilter, AddonCalendarHelper } from '../../services/calendar-helper'; -import { AddonCalendarSync, AddonCalendarSyncProvider } from '../../services/calendar-sync'; +import { AddonCalendarSync } from '../../services/calendar-sync'; import { CoreCategoryData, CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses'; import { CoreCoursesHelper } from '@features/courses/services/courses-helper'; import moment from 'moment-timezone'; @@ -49,6 +47,17 @@ import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreUrl } from '@singletons/url'; import { CoreTime } from '@singletons/time'; import { CoreModals } from '@services/modals'; +import { + ADDON_CALENDAR_AUTO_SYNCED, + ADDON_CALENDAR_DELETED_EVENT_EVENT, + ADDON_CALENDAR_EDIT_EVENT_EVENT, + ADDON_CALENDAR_FILTER_CHANGED_EVENT, + ADDON_CALENDAR_MANUAL_SYNCED, + ADDON_CALENDAR_NEW_EVENT_DISCARDED_EVENT, + ADDON_CALENDAR_NEW_EVENT_EVENT, + ADDON_CALENDAR_UNDELETED_EVENT_EVENT, + AddonCalendarEventType, +} from '@addons/calendar/constants'; /** * Page that displays the calendar events for a certain day. @@ -91,7 +100,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { // Listen for events added. When an event is added, reload the data. this.eventObservers.push(CoreEvents.on( - AddonCalendarProvider.NEW_EVENT_EVENT, + ADDON_CALENDAR_NEW_EVENT_EVENT, (data) => { if (data && data.eventId) { this.manager?.getSource().markAllItemsUnloaded(); @@ -102,14 +111,14 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { )); // Listen for new event discarded event. When it does, reload the data. - this.eventObservers.push(CoreEvents.on(AddonCalendarProvider.NEW_EVENT_DISCARDED_EVENT, () => { + this.eventObservers.push(CoreEvents.on(ADDON_CALENDAR_NEW_EVENT_DISCARDED_EVENT, () => { this.manager?.getSource().markAllItemsUnloaded(); this.refreshData(true, true); }, this.currentSiteId)); // Listen for events edited. When an event is edited, reload the data. this.eventObservers.push(CoreEvents.on( - AddonCalendarProvider.EDIT_EVENT_EVENT, + ADDON_CALENDAR_EDIT_EVENT_EVENT, (data) => { if (data && data.eventId) { this.manager?.getSource().markAllItemsUnloaded(); @@ -120,13 +129,13 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { )); // Refresh data if calendar events are synchronized automatically. - this.eventObservers.push(CoreEvents.on(AddonCalendarSyncProvider.AUTO_SYNCED, () => { + this.eventObservers.push(CoreEvents.on(ADDON_CALENDAR_AUTO_SYNCED, () => { this.manager?.getSource().markAllItemsUnloaded(); this.refreshData(false, true); }, this.currentSiteId)); // Refresh data if calendar events are synchronized manually but not by this page. - this.eventObservers.push(CoreEvents.on(AddonCalendarSyncProvider.MANUAL_SYNCED, (data) => { + this.eventObservers.push(CoreEvents.on(ADDON_CALENDAR_MANUAL_SYNCED, (data) => { const selectedDay = this.manager?.getSelectedItem(); if (data && (data.source != 'day' || !selectedDay || !data.moment || !selectedDay.moment.isSame(data.moment, 'day'))) { this.manager?.getSource().markAllItemsUnloaded(); @@ -136,7 +145,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { // Update the events when an event is deleted. this.eventObservers.push(CoreEvents.on( - AddonCalendarProvider.DELETED_EVENT_EVENT, + ADDON_CALENDAR_DELETED_EVENT_EVENT, (data) => { if (data && !data.sent) { // Event was deleted in offline. Just mark it as deleted, no need to refresh. @@ -151,7 +160,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { // Listen for events "undeleted" (offline). this.eventObservers.push(CoreEvents.on( - AddonCalendarProvider.UNDELETED_EVENT_EVENT, + ADDON_CALENDAR_UNDELETED_EVENT_EVENT, (data) => { if (!data || !data.eventId) { return; @@ -164,7 +173,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { )); this.eventObservers.push(CoreEvents.on( - AddonCalendarProvider.FILTER_CHANGED_EVENT, + ADDON_CALENDAR_FILTER_CHANGED_EVENT, async (data) => { this.filter = data; @@ -343,7 +352,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { result.moment = selectedDay?.moment; this.manager?.getSource().markAllItemsUnloaded(); - CoreEvents.trigger(AddonCalendarSyncProvider.MANUAL_SYNCED, result, this.currentSiteId); + CoreEvents.trigger(ADDON_CALENDAR_MANUAL_SYNCED, result, this.currentSiteId); } } catch (error) { if (showErrors) { diff --git a/src/addons/calendar/pages/edit-event/edit-event.ts b/src/addons/calendar/pages/edit-event/edit-event.ts index e90b5b7d3..ecaf421c3 100644 --- a/src/addons/calendar/pages/edit-event/edit-event.ts +++ b/src/addons/calendar/pages/edit-event/edit-event.ts @@ -24,16 +24,14 @@ import { CoreUtils } from '@services/utils/utils'; import { CoreCategoryData, CoreCourses, CoreCourseSearchedData, CoreEnrolledCourseData } from '@features/courses/services/courses'; import { CoreEditorRichTextEditorComponent } from '@features/editor/components/rich-text-editor/rich-text-editor'; import { - AddonCalendarProvider, AddonCalendarGetCalendarAccessInformationWSResponse, AddonCalendarEvent, - AddonCalendarEventType, AddonCalendar, AddonCalendarSubmitCreateUpdateFormDataWSParams, } from '../../services/calendar'; import { AddonCalendarOffline } from '../../services/calendar-offline'; import { AddonCalendarEventTypeOption, AddonCalendarHelper } from '../../services/calendar-helper'; -import { AddonCalendarSync, AddonCalendarSyncProvider } from '../../services/calendar-sync'; +import { AddonCalendarSync } from '../../services/calendar-sync'; import { CoreSite } from '@classes/sites/site'; import { Translate } from '@singletons'; import { CoreFilterHelper } from '@features/filter/services/filter-helper'; @@ -44,7 +42,13 @@ import { CanLeave } from '@guards/can-leave'; import { CoreForms } from '@singletons/form'; import { CoreReminders, CoreRemindersService, CoreRemindersUnits } from '@features/reminders/services/reminders'; import moment from 'moment-timezone'; -import { ADDON_CALENDAR_COMPONENT } from '@addons/calendar/constants'; +import { + ADDON_CALENDAR_COMPONENT, + ADDON_CALENDAR_EDIT_EVENT_EVENT, + ADDON_CALENDAR_NEW_EVENT_EVENT, + ADDON_CALENDAR_SYNC_ID, + AddonCalendarEventType, +} from '@addons/calendar/constants'; import { ContextLevel } from '@/core/constants'; import { CorePopovers } from '@services/popovers'; import { CoreLoadings } from '@services/loadings'; @@ -179,7 +183,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave { // Editing an event, get the event data. Wait for sync first. const eventId = this.eventId; - promises.push(AddonCalendarSync.waitForSync(AddonCalendarSyncProvider.SYNC_ID).then(async () => { + promises.push(AddonCalendarSync.waitForSync(ADDON_CALENDAR_SYNC_ID).then(async () => { // Do not block if the scope is already destroyed. if (!this.isDestroyed && this.eventId) { CoreSync.blockOperation(ADDON_CALENDAR_COMPONENT, eventId); @@ -363,7 +367,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave { this.form.controls.repeateditall.setValue(1); } - if (event.eventtype == AddonCalendarEventType.GROUP && courseId) { + if (event.eventtype === AddonCalendarEventType.GROUP && courseId) { await this.loadGroups(courseId); } } @@ -489,12 +493,12 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave { repeat: formData.repeat, }; - if (formData.eventtype == AddonCalendarEventType.COURSE) { + if (formData.eventtype === AddonCalendarEventType.COURSE) { data.courseid = formData.courseid; - } else if (formData.eventtype == AddonCalendarEventType.GROUP) { + } else if (formData.eventtype === AddonCalendarEventType.GROUP) { data.groupcourseid = formData.groupcourseid; data.groupid = formData.groupid; - } else if (formData.eventtype == AddonCalendarEventType.CATEGORY) { + } else if (formData.eventtype === AddonCalendarEventType.CATEGORY) { data.categoryid = formData.categoryid; } @@ -560,13 +564,13 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave { if (this.eventId && this.eventId > 0) { // Editing an event. CoreEvents.trigger( - AddonCalendarProvider.EDIT_EVENT_EVENT, + ADDON_CALENDAR_EDIT_EVENT_EVENT, { eventId: this.eventId }, this.currentSite.getId(), ); } else { CoreEvents.trigger( - AddonCalendarProvider.NEW_EVENT_EVENT, + ADDON_CALENDAR_NEW_EVENT_EVENT, { eventId: event.id, oldEventId: this.eventId, diff --git a/src/addons/calendar/pages/event/event.ts b/src/addons/calendar/pages/event/event.ts index d97f1d3dd..826133092 100644 --- a/src/addons/calendar/pages/event/event.ts +++ b/src/addons/calendar/pages/event/event.ts @@ -17,11 +17,10 @@ import { AlertOptions } from '@ionic/core'; import { AddonCalendar, AddonCalendarEventToDisplay, - AddonCalendarProvider, } from '../../services/calendar'; import { AddonCalendarEventReminder, AddonCalendarHelper } from '../../services/calendar-helper'; import { AddonCalendarOffline } from '../../services/calendar-offline'; -import { AddonCalendarSync, AddonCalendarSyncEvents, AddonCalendarSyncProvider } from '../../services/calendar-sync'; +import { AddonCalendarSync, AddonCalendarSyncEvents } from '../../services/calendar-sync'; import { CoreNetwork } from '@services/network'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreDomUtils } from '@services/utils/dom'; @@ -46,6 +45,15 @@ import { CoreToasts, ToastDuration } from '@services/toasts'; import { CorePopovers } from '@services/popovers'; import { CoreLoadings } from '@services/loadings'; import { CoreUrl } from '@singletons/url'; +import { + ADDON_CALENDAR_AUTO_SYNCED, + ADDON_CALENDAR_DELETED_EVENT_EVENT, + ADDON_CALENDAR_EDIT_EVENT_EVENT, + ADDON_CALENDAR_MANUAL_SYNCED, + ADDON_CALENDAR_NEW_EVENT_DISCARDED_EVENT, + ADDON_CALENDAR_NEW_EVENT_EVENT, + ADDON_CALENDAR_UNDELETED_EVENT_EVENT, +} from '@addons/calendar/constants'; /** * Page that displays a single calendar event. @@ -99,7 +107,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { this.canEdit = AddonCalendar.canEditEventsInSite(); // Listen for event edited. If current event is edited, reload the data. - this.editEventObserver = CoreEvents.on(AddonCalendarProvider.EDIT_EVENT_EVENT, (data) => { + this.editEventObserver = CoreEvents.on(ADDON_CALENDAR_EDIT_EVENT_EVENT, (data) => { if (data && data.eventId === this.eventId) { this.eventLoaded = false; this.refreshEvent(true, false); @@ -107,7 +115,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { }, this.currentSiteId); // Listen for event created. If user edits the data of a new offline event or it's sent to server, this event is triggered. - this.newEventObserver = CoreEvents.on(AddonCalendarProvider.NEW_EVENT_EVENT, (data) => { + this.newEventObserver = CoreEvents.on(ADDON_CALENDAR_NEW_EVENT_EVENT, (data) => { if (this.eventId < 0 && data && (data.eventId === this.eventId || data.oldEventId === this.eventId)) { this.eventId = data.eventId; this.eventLoaded = false; @@ -117,14 +125,14 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { // Refresh data if this calendar event is synchronized automatically. this.syncObserver = CoreEvents.on( - AddonCalendarSyncProvider.AUTO_SYNCED, + ADDON_CALENDAR_AUTO_SYNCED, (data) => this.checkSyncResult(false, data), this.currentSiteId, ); // Refresh data if calendar events are synchronized manually but not by this page. this.manualSyncObserver = CoreEvents.on( - AddonCalendarSyncProvider.MANUAL_SYNCED, + ADDON_CALENDAR_MANUAL_SYNCED, (data) => this.checkSyncResult(true, data), this.currentSiteId, ); @@ -364,7 +372,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { result.source = 'event'; CoreEvents.trigger( - AddonCalendarSyncProvider.MANUAL_SYNCED, + ADDON_CALENDAR_MANUAL_SYNCED, result, this.currentSiteId, ); @@ -552,9 +560,9 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { // Trigger an event. if (this.event.id < 0) { - CoreEvents.trigger(AddonCalendarProvider.NEW_EVENT_DISCARDED_EVENT, {}, CoreSites.getCurrentSiteId()); + CoreEvents.trigger(ADDON_CALENDAR_NEW_EVENT_DISCARDED_EVENT, {}, CoreSites.getCurrentSiteId()); } else { - CoreEvents.trigger(AddonCalendarProvider.DELETED_EVENT_EVENT, { + CoreEvents.trigger(ADDON_CALENDAR_DELETED_EVENT_EVENT, { eventId: this.eventId, sent: onlineEventDeleted, }, CoreSites.getCurrentSiteId()); @@ -595,7 +603,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { await AddonCalendarOffline.unmarkDeleted(this.event.id); // Trigger an event. - CoreEvents.trigger(AddonCalendarProvider.UNDELETED_EVENT_EVENT, { + CoreEvents.trigger(ADDON_CALENDAR_UNDELETED_EVENT_EVENT, { eventId: this.eventId, }, CoreSites.getCurrentSiteId()); diff --git a/src/addons/calendar/pages/index/index.ts b/src/addons/calendar/pages/index/index.ts index 7bfa6e2d6..0ab5b077a 100644 --- a/src/addons/calendar/pages/index/index.ts +++ b/src/addons/calendar/pages/index/index.ts @@ -18,9 +18,9 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreCoursesHelper } from '@features/courses/services/courses-helper'; -import { AddonCalendar, AddonCalendarProvider } from '../../services/calendar'; +import { AddonCalendar } from '../../services/calendar'; import { AddonCalendarOffline } from '../../services/calendar-offline'; -import { AddonCalendarSync, AddonCalendarSyncProvider } from '../../services/calendar-sync'; +import { AddonCalendarSync } from '../../services/calendar-sync'; import { AddonCalendarFilter, AddonCalendarHelper } from '../../services/calendar-helper'; import { NgZone } from '@singletons'; import { Subscription } from 'rxjs'; @@ -31,6 +31,16 @@ import { AddonCalendarUpcomingEventsComponent } from '../../components/upcoming- import { CoreNavigator } from '@services/navigator'; import { CoreConstants } from '@/core/constants'; import { CoreModals } from '@services/modals'; +import { + ADDON_CALENDAR_AUTO_SYNCED, + ADDON_CALENDAR_DELETED_EVENT_EVENT, + ADDON_CALENDAR_EDIT_EVENT_EVENT, + ADDON_CALENDAR_FILTER_CHANGED_EVENT, + ADDON_CALENDAR_MANUAL_SYNCED, + ADDON_CALENDAR_NEW_EVENT_DISCARDED_EVENT, + ADDON_CALENDAR_NEW_EVENT_EVENT, + ADDON_CALENDAR_UNDELETED_EVENT_EVENT, +} from '@addons/calendar/constants'; /** * Page that displays the calendar events. @@ -85,7 +95,7 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy { // Listen for events added. When an event is added, reload the data. this.newEventObserver = CoreEvents.on( - AddonCalendarProvider.NEW_EVENT_EVENT, + ADDON_CALENDAR_NEW_EVENT_EVENT, (data) => { if (data && data.eventId) { this.loaded = false; @@ -96,14 +106,14 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy { ); // Listen for new event discarded event. When it does, reload the data. - this.discardedObserver = CoreEvents.on(AddonCalendarProvider.NEW_EVENT_DISCARDED_EVENT, () => { + this.discardedObserver = CoreEvents.on(ADDON_CALENDAR_NEW_EVENT_DISCARDED_EVENT, () => { this.loaded = false; this.refreshData(true, false, true); }, this.currentSiteId); // Listen for events edited. When an event is edited, reload the data. this.editEventObserver = CoreEvents.on( - AddonCalendarProvider.EDIT_EVENT_EVENT, + ADDON_CALENDAR_EDIT_EVENT_EVENT, (data) => { if (data && data.eventId) { this.loaded = false; @@ -114,13 +124,13 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy { ); // Refresh data if calendar events are synchronized automatically. - this.syncObserver = CoreEvents.on(AddonCalendarSyncProvider.AUTO_SYNCED, () => { + this.syncObserver = CoreEvents.on(ADDON_CALENDAR_AUTO_SYNCED, () => { this.loaded = false; this.refreshData(false, false, true); }, this.currentSiteId); // Refresh data if calendar events are synchronized manually but not by this page. - this.manualSyncObserver = CoreEvents.on(AddonCalendarSyncProvider.MANUAL_SYNCED, (data) => { + this.manualSyncObserver = CoreEvents.on(ADDON_CALENDAR_MANUAL_SYNCED, (data) => { if (data && data.source != 'index') { this.loaded = false; this.refreshData(false, false, true); @@ -128,18 +138,18 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy { }, this.currentSiteId); // Update the events when an event is deleted. - this.deleteEventObserver = CoreEvents.on(AddonCalendarProvider.DELETED_EVENT_EVENT, () => { + this.deleteEventObserver = CoreEvents.on(ADDON_CALENDAR_DELETED_EVENT_EVENT, () => { this.loaded = false; this.refreshData(false, false, true); }, this.currentSiteId); // Update the "hasOffline" property if an event deleted in offline is restored. - this.undeleteEventObserver = CoreEvents.on(AddonCalendarProvider.UNDELETED_EVENT_EVENT, async () => { + this.undeleteEventObserver = CoreEvents.on(ADDON_CALENDAR_UNDELETED_EVENT_EVENT, async () => { this.hasOffline = await AddonCalendarOffline.hasOfflineData(); }, this.currentSiteId); this.filterChangedObserver = CoreEvents.on( - AddonCalendarProvider.FILTER_CHANGED_EVENT, + ADDON_CALENDAR_FILTER_CHANGED_EVENT, async (filterData) => { this.filter = filterData; @@ -205,7 +215,7 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy { result.source = 'index'; CoreEvents.trigger( - AddonCalendarSyncProvider.MANUAL_SYNCED, + ADDON_CALENDAR_MANUAL_SYNCED, result, this.currentSiteId, ); diff --git a/src/addons/calendar/services/calendar-helper.ts b/src/addons/calendar/services/calendar-helper.ts index 7f32071b2..295dc92c9 100644 --- a/src/addons/calendar/services/calendar-helper.ts +++ b/src/addons/calendar/services/calendar-helper.ts @@ -20,9 +20,7 @@ import { AddonCalendarEvent, AddonCalendarEventBase, AddonCalendarEventToDisplay, - AddonCalendarEventType, AddonCalendarGetEventsEvent, - AddonCalendarProvider, AddonCalendarWeek, AddonCalendarWeekDay, } from './calendar'; @@ -32,24 +30,18 @@ import { CoreCourse } from '@features/course/services/course'; import { ContextLevel, CoreConstants } from '@/core/constants'; import moment from 'moment-timezone'; import { makeSingleton } from '@singletons'; -import { AddonCalendarSyncInvalidateEvent } from './calendar-sync'; import { AddonCalendarOfflineEventDBRecord } from './database/calendar-offline'; import { CoreCategoryData } from '@features/courses/services/courses'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreReminders, CoreRemindersService } from '@features/reminders/services/reminders'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; -import { ADDON_CALENDAR_COMPONENT } from '../constants'; - -/** - * Context levels enumeration. - */ -export enum AddonCalendarEventIcons { - SITE = 'fas-globe', - CATEGORY = 'fas-cubes', - COURSE = 'fas-graduation-cap', - GROUP = 'fas-users', - USER = 'fas-user', -} +import { + ADDON_CALENDAR_COMPONENT, + ADDON_CALENDAR_STARTING_WEEK_DAY, + AddonCalendarEventIcons, + AddonCalendarEventType, +} from '../constants'; +import { AddonCalendarSyncInvalidateEvent } from './calendar-sync'; /** * Service that provides some features regarding lists of courses and categories. @@ -418,7 +410,7 @@ export class AddonCalendarHelperProvider { const site = await CoreSites.getSite(siteId); // Get starting week day user preference, fallback to site configuration. let startWeekDayStr = site.getStoredConfig('calendar_startwday') || '1'; - startWeekDayStr = await CoreConfig.get(AddonCalendarProvider.STARTING_WEEK_DAY, startWeekDayStr); + startWeekDayStr = await CoreConfig.get(ADDON_CALENDAR_STARTING_WEEK_DAY, startWeekDayStr); const startWeekDay = parseInt(startWeekDayStr, 10); const today = moment(); @@ -784,7 +776,6 @@ export class AddonCalendarHelperProvider { } } - export const AddonCalendarHelper = makeSingleton(AddonCalendarHelperProvider); /** diff --git a/src/addons/calendar/services/calendar-sync.ts b/src/addons/calendar/services/calendar-sync.ts index bad6607d5..ebefd0bfa 100644 --- a/src/addons/calendar/services/calendar-sync.ts +++ b/src/addons/calendar/services/calendar-sync.ts @@ -29,7 +29,12 @@ import { makeSingleton, Translate } from '@singletons'; import { CoreSync, CoreSyncResult } from '@services/sync'; import { CoreNetworkError } from '@classes/errors/network-error'; import moment from 'moment-timezone'; -import { ADDON_CALENDAR_COMPONENT } from '../constants'; +import { + ADDON_CALENDAR_AUTO_SYNCED, + ADDON_CALENDAR_COMPONENT, + ADDON_CALENDAR_MANUAL_SYNCED, + ADDON_CALENDAR_SYNC_ID, +} from '../constants'; /** * Service to sync calendar. @@ -37,10 +42,6 @@ import { ADDON_CALENDAR_COMPONENT } from '../constants'; @Injectable({ providedIn: 'root' }) export class AddonCalendarSyncProvider extends CoreSyncBaseProvider { - static readonly AUTO_SYNCED = 'addon_calendar_autom_synced'; - static readonly MANUAL_SYNCED = 'addon_calendar_manual_synced'; - static readonly SYNC_ID = 'calendar'; - protected componentTranslatableString = 'addon.calendar.calendarevent'; constructor() { @@ -72,7 +73,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider { siteId = siteId || CoreSites.getCurrentSiteId(); - const needed = await this.isSyncNeeded(AddonCalendarSyncProvider.SYNC_ID, siteId); + const needed = await this.isSyncNeeded(ADDON_CALENDAR_SYNC_ID, siteId); if (needed) { return this.syncEvents(siteId); @@ -101,7 +102,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider { siteId = siteId || CoreSites.getCurrentSiteId(); - const currentSyncPromise = this.getOngoingSync(AddonCalendarSyncProvider.SYNC_ID, siteId); + const currentSyncPromise = this.getOngoingSync(ADDON_CALENDAR_SYNC_ID, siteId); if (currentSyncPromise) { // There's already a sync ongoing for this site, return the promise. return currentSyncPromise; @@ -112,7 +113,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider[] = []; promises.push(site.getDb().deleteRecords( - EVENTS_TABLE, + ADDON_CALENDAR_EVENTS_TABLE, { id: eventId }, )); promises.push(CoreReminders.removeReminders({ @@ -297,7 +283,7 @@ export class AddonCalendarProvider { } CoreNavigator.navigateToSitePath( - AddonCalendarMainMenuHandlerService.PAGE_NAME, + ADDON_CALENDAR_PAGE_NAME, { siteId: notification.siteId, preferCurrentTab: false, @@ -429,7 +415,7 @@ export class AddonCalendarProvider { * @returns Cache key. */ protected getAccessInformationCacheKey(courseId?: number): string { - return ROOT_CACHE_KEY + 'accessInformation:' + (courseId || 0); + return AddonCalendarProvider.ROOT_CACHE_KEY + 'accessInformation:' + (courseId || 0); } /** @@ -441,7 +427,7 @@ export class AddonCalendarProvider { async getAllEventsFromLocalDb(siteId?: string): Promise { const site = await CoreSites.getSite(siteId); - return site.getDb().getAllRecords(EVENTS_TABLE); + return site.getDb().getAllRecords(ADDON_CALENDAR_EVENTS_TABLE); } /** @@ -482,7 +468,7 @@ export class AddonCalendarProvider { * @returns Cache key. */ protected getAllowedEventTypesCacheKey(courseId?: number): string { - return ROOT_CACHE_KEY + 'allowedEventTypes:' + (courseId || 0); + return AddonCalendarProvider.ROOT_CACHE_KEY + 'allowedEventTypes:' + (courseId || 0); } /** @@ -527,9 +513,9 @@ export class AddonCalendarProvider { format = site.getStoredConfig('calendar_site_timeformat'); } - if (format === AddonCalendarProvider.CALENDAR_TF_12) { + if (format === ADDON_CALENDAR_TF_12) { format = Translate.instant('core.strftimetime12'); - } else if (format === AddonCalendarProvider.CALENDAR_TF_24) { + } else if (format === ADDON_CALENDAR_TF_24) { format = Translate.instant('core.strftimetime24'); } @@ -641,7 +627,7 @@ export class AddonCalendarProvider { * @returns Cache key. */ protected getEventCacheKey(id: number): string { - return ROOT_CACHE_KEY + 'events:' + id; + return AddonCalendarProvider.ROOT_CACHE_KEY + 'events:' + id; } /** @@ -654,7 +640,7 @@ export class AddonCalendarProvider { async getEventFromLocalDb(id: number, siteId?: string): Promise { const site = await CoreSites.getSite(siteId); const record: AddonCalendarGetEventsEvent | AddonCalendarEvent | AddonCalendarEventDBRecord = - await site.getDb().getRecord(EVENTS_TABLE, { id: id }); + await site.getDb().getRecord(ADDON_CALENDAR_EVENTS_TABLE, { id: id }); const eventConverted = record as AddonCalendarEvent; const originalEvent = record as AddonCalendarGetEventsEvent; @@ -662,8 +648,8 @@ export class AddonCalendarProvider { // Calculate data to match the new WS. eventConverted.descriptionformat = originalEvent.format; - eventConverted.iscourseevent = originalEvent.eventtype == AddonCalendarEventType.COURSE; - eventConverted.iscategoryevent = originalEvent.eventtype == AddonCalendarEventType.CATEGORY; + eventConverted.iscourseevent = originalEvent.eventtype === AddonCalendarEventType.COURSE; + eventConverted.iscategoryevent = originalEvent.eventtype === AddonCalendarEventType.CATEGORY; eventConverted.normalisedeventtype = this.getEventType(recordAsRecord); try { eventConverted.category = CoreText.parseJSON(recordAsRecord.category || ''); @@ -797,7 +783,7 @@ export class AddonCalendarProvider { * @returns Prefix Cache key. */ protected getDayEventsPrefixCacheKey(): string { - return ROOT_CACHE_KEY + 'day:'; + return AddonCalendarProvider.ROOT_CACHE_KEY + 'day:'; } /** @@ -843,7 +829,7 @@ export class AddonCalendarProvider { async getEventsList( initialTime?: number, daysToStart: number = 0, - daysInterval: number = AddonCalendarProvider.DAYS_INTERVAL, + daysInterval: number = ADDON_CALENDAR_DAYS_INTERVAL, siteId?: string, ): Promise { @@ -907,7 +893,7 @@ export class AddonCalendarProvider { * @returns Prefix Cache key. */ protected getEventsListPrefixCacheKey(): string { - return ROOT_CACHE_KEY + 'events:'; + return AddonCalendarProvider.ROOT_CACHE_KEY + 'events:'; } /** @@ -931,7 +917,7 @@ export class AddonCalendarProvider { async getLocalEventsByRepeatIdFromLocalDb(repeatId: number, siteId?: string): Promise { const site = await CoreSites.getSite(siteId); - return site.getDb().getRecords(EVENTS_TABLE, { repeatid: repeatId }); + return site.getDb().getRecords(ADDON_CALENDAR_EVENTS_TABLE, { repeatid: repeatId }); } /** @@ -985,7 +971,7 @@ export class AddonCalendarProvider { // Store starting week day preference, we need it in offline to show months that are not in cache. if (CoreNetwork.isOnline()) { - CoreConfig.set(AddonCalendarProvider.STARTING_WEEK_DAY, response.daynames[0].dayno); + CoreConfig.set(ADDON_CALENDAR_STARTING_WEEK_DAY, response.daynames[0].dayno); } return response; @@ -997,7 +983,7 @@ export class AddonCalendarProvider { * @returns Prefix Cache key. */ protected getMonthlyEventsPrefixCacheKey(): string { - return ROOT_CACHE_KEY + 'monthly:'; + return AddonCalendarProvider.ROOT_CACHE_KEY + 'monthly:'; } /** @@ -1074,7 +1060,7 @@ export class AddonCalendarProvider { * @returns Prefix Cache key. */ protected getUpcomingEventsPrefixCacheKey(): string { - return ROOT_CACHE_KEY + 'upcoming:'; + return AddonCalendarProvider.ROOT_CACHE_KEY + 'upcoming:'; } /** @@ -1120,7 +1106,7 @@ export class AddonCalendarProvider { getWeekDays(startingDay?: number): AddonCalendarWeekDaysTranslationKeys[] { startingDay = startingDay || 0; - return this.weekDays.slice(startingDay).concat(this.weekDays.slice(0, startingDay)); + return AddonCalendarProvider.weekDays.slice(startingDay).concat(AddonCalendarProvider.weekDays.slice(0, startingDay)); } /** @@ -1440,7 +1426,7 @@ export class AddonCalendarProvider { await this.addDefaultEventReminder(eventRecord, site.getId()); } - await site.getDb().insertRecord(EVENTS_TABLE, eventRecord); + await site.getDb().insertRecord(ADDON_CALENDAR_EVENTS_TABLE, eventRecord); } /** @@ -2081,9 +2067,9 @@ export type AddonCalendarEventToDisplay = Partial & /** * Event triggered when an event is modified with event types: - * NEW_EVENT_EVENT, EDIT_EVENT_EVENT, DELETED_EVENT_EVENT, UNDELETED_EVENT_EVENT. + * NEW_EVENT, EDIT_EVENT, DELETED_EVENT, UNDELETED_EVENT. */ -export type AddonCalendarUpdatedEventEvent = { +export type AddonCalendarUpdatedEvent = { eventId: number; oldEventId?: number; // Old event ID. Used when an offline event is sent. sent?: boolean; diff --git a/src/addons/calendar/services/database/calendar-offline.ts b/src/addons/calendar/services/database/calendar-offline.ts index 5e08f8378..a6a4b2315 100644 --- a/src/addons/calendar/services/database/calendar-offline.ts +++ b/src/addons/calendar/services/database/calendar-offline.ts @@ -13,7 +13,8 @@ // limitations under the License. import { CoreSiteSchema } from '@services/sites'; -import { AddonCalendarEventType } from '../calendar'; +import { AddonCalendarEventType } from '@addons/calendar/constants'; + /** * Database variables for AddonDatabaseOffline service. */ diff --git a/src/addons/calendar/services/database/calendar.ts b/src/addons/calendar/services/database/calendar.ts index 1b87cb281..1320c0cdb 100644 --- a/src/addons/calendar/services/database/calendar.ts +++ b/src/addons/calendar/services/database/calendar.ts @@ -12,24 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { ADDON_CALENDAR_EVENTS_TABLE, AddonCalendarEventType } from '@addons/calendar/constants'; import { SQLiteDB } from '@classes/sqlitedb'; import { CoreRemindersService, CoreReminders } from '@features/reminders/services/reminders'; import { CoreConfig } from '@services/config'; import { CoreSiteSchema } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; -import { AddonCalendarEventType } from '../calendar'; /** * Database variables for AddonCalendarProvider service. */ -export const EVENTS_TABLE = 'addon_calendar_events_3'; export const CALENDAR_SITE_SCHEMA: CoreSiteSchema = { name: 'AddonCalendarProvider', version: 5, - canBeCleared: [EVENTS_TABLE], + canBeCleared: [ADDON_CALENDAR_EVENTS_TABLE], tables: [ { - name: EVENTS_TABLE, + name: ADDON_CALENDAR_EVENTS_TABLE, columns: [ { name: 'id', diff --git a/src/addons/calendar/services/handlers/mainmenu.ts b/src/addons/calendar/services/handlers/mainmenu.ts index 2cf9259a9..1b9269f13 100644 --- a/src/addons/calendar/services/handlers/mainmenu.ts +++ b/src/addons/calendar/services/handlers/mainmenu.ts @@ -16,6 +16,7 @@ import { Injectable } from '@angular/core'; import { AddonCalendar } from '../calendar'; import { makeSingleton } from '@singletons'; import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu/services/mainmenu-delegate'; +import { ADDON_CALENDAR_PAGE_NAME } from '@addons/calendar/constants'; /** * Handler to inject an option into main menu. @@ -23,8 +24,6 @@ import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu @Injectable({ providedIn: 'root' }) export class AddonCalendarMainMenuHandlerService implements CoreMainMenuHandler { - static readonly PAGE_NAME = 'calendar'; - name = 'AddonCalendar'; priority = 550; @@ -46,7 +45,7 @@ export class AddonCalendarMainMenuHandlerService implements CoreMainMenuHandler return { icon: 'far-calendar', title: 'addon.calendar.calendar', - page: AddonCalendarMainMenuHandlerService.PAGE_NAME, + page: ADDON_CALENDAR_PAGE_NAME, class: 'addon-calendar-handler', }; } diff --git a/src/core/features/reminders/services/database/reminders.ts b/src/core/features/reminders/services/database/reminders.ts index 00427ef0b..c4c2c8c8a 100644 --- a/src/core/features/reminders/services/database/reminders.ts +++ b/src/core/features/reminders/services/database/reminders.ts @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { ADDON_CALENDAR_COMPONENT } from '@addons/calendar/constants'; -import { AddonCalendarEventDBRecord, EVENTS_TABLE } from '@addons/calendar/services/database/calendar'; +import { ADDON_CALENDAR_COMPONENT, ADDON_CALENDAR_EVENTS_TABLE } from '@addons/calendar/constants'; import { SQLiteDB } from '@classes/sqlitedb'; import { CoreSiteSchema } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { CoreReminderData, CoreRemindersService } from '../reminders'; +import { AddonCalendarEventDBRecord } from '@addons/calendar/services/database/calendar'; /** * Database variables for CoreRemindersService service. @@ -100,7 +100,7 @@ const migrateFromCalendarRemindersV1 = async (db: SQLiteDB): Promise => { // Get the event to compare the reminder time with the event time. if (!events[record.eventid]) { try { - events[record.eventid] = await db.getRecord(EVENTS_TABLE, { id: record.eventid }); + events[record.eventid] = await db.getRecord(ADDON_CALENDAR_EVENTS_TABLE, { id: record.eventid }); } catch { // Event not found in local DB, shouldn't happen. Ignore the reminder. return; @@ -157,7 +157,7 @@ const migrateFromCalendarRemindersV2 = async (db: SQLiteDB): Promise => { // Get the event to compare the reminder time with the event time. if (!events[record.eventid]) { try { - events[record.eventid] = await db.getRecord(EVENTS_TABLE, { id: record.eventid }); + events[record.eventid] = await db.getRecord(ADDON_CALENDAR_EVENTS_TABLE, { id: record.eventid }); } catch { // Event not found in local DB, shouldn't happen. Ignore the reminder. return;