MOBILE-4653 calendar: Partially decouple calendar
parent
d1cae1464d
commit
3959df94d5
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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<Type<unknown>[]> {
|
|||
|
||||
const mainMenuChildrenRoutes: Routes = [
|
||||
{
|
||||
path: AddonCalendarMainMenuHandlerService.PAGE_NAME,
|
||||
path: ADDON_CALENDAR_PAGE_NAME,
|
||||
loadChildren: () => import('./calendar-lazy.module'),
|
||||
},
|
||||
];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<AddonCalendarSyncEvents> {
|
||||
|
||||
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<AddonCalenda
|
|||
|
||||
if (result?.updated) {
|
||||
// Sync successful, send event.
|
||||
CoreEvents.trigger(AddonCalendarSyncProvider.AUTO_SYNCED, result, siteId);
|
||||
CoreEvents.trigger(ADDON_CALENDAR_AUTO_SYNCED, result, siteId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +86,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider<AddonCalenda
|
|||
async syncEventsIfNeeded(siteId?: string): Promise<AddonCalendarSyncEvents | undefined> {
|
||||
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<AddonCalenda
|
|||
async syncEvents(siteId?: string): Promise<AddonCalendarSyncEvents> {
|
||||
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<AddonCalenda
|
|||
// Get offline events.
|
||||
const syncPromise = this.performSyncEvents(siteId);
|
||||
|
||||
return this.addOngoingSync(AddonCalendarSyncProvider.SYNC_ID, syncPromise, siteId);
|
||||
return this.addOngoingSync(ADDON_CALENDAR_SYNC_ID, syncPromise, siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,7 +157,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider<AddonCalenda
|
|||
}
|
||||
|
||||
// Sync finished, set sync time.
|
||||
await CoreUtils.ignoreErrors(this.setSyncTime(AddonCalendarSyncProvider.SYNC_ID, siteId));
|
||||
await CoreUtils.ignoreErrors(this.setSyncTime(ADDON_CALENDAR_SYNC_ID, siteId));
|
||||
|
||||
// All done, return the result.
|
||||
return result;
|
||||
|
@ -298,7 +299,6 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider<AddonCalenda
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
export const AddonCalendarSync = makeSingleton(AddonCalendarSyncProvider);
|
||||
|
||||
export type AddonCalendarSyncEvents = CoreSyncResult & {
|
||||
|
@ -316,3 +316,17 @@ export type AddonCalendarSyncInvalidateEvent = {
|
|||
timestart: number;
|
||||
repeated: number;
|
||||
};
|
||||
|
||||
declare module '@singletons/events' {
|
||||
|
||||
/**
|
||||
* Augment CoreEventsData interface with events specific to this service.
|
||||
*
|
||||
* @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
||||
*/
|
||||
export interface CoreEventsData {
|
||||
[ADDON_CALENDAR_MANUAL_SYNCED]: AddonCalendarSyncEvents;
|
||||
[ADDON_CALENDAR_AUTO_SYNCED]: AddonCalendarSyncEvents;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,17 +27,14 @@ import { AddonCalendarOffline } from './calendar-offline';
|
|||
import { CoreUser } from '@features/user/services/user';
|
||||
import { CoreWSExternalWarning, CoreWSDate } from '@services/ws';
|
||||
import moment from 'moment-timezone';
|
||||
import { AddonCalendarEventDBRecord, EVENTS_TABLE } from './database/calendar';
|
||||
import { AddonCalendarEventDBRecord } from './database/calendar';
|
||||
import { CoreCourses } from '@features/courses/services/courses';
|
||||
import { ContextLevel, CoreConstants } from '@/core/constants';
|
||||
import { CoreWSError } from '@classes/errors/wserror';
|
||||
import { ApplicationInit, makeSingleton, Translate } from '@singletons';
|
||||
import { AddonCalendarOfflineEventDBRecord } from './database/calendar-offline';
|
||||
import { AddonCalendarMainMenuHandlerService } from './handlers/mainmenu';
|
||||
import { SafeUrl } from '@angular/platform-browser';
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
import { AddonCalendarFilter } from './calendar-helper';
|
||||
import { AddonCalendarSyncEvents, AddonCalendarSyncProvider } from './calendar-sync';
|
||||
import { CorePath } from '@singletons/path';
|
||||
import { CorePlatform } from '@services/platform';
|
||||
import {
|
||||
|
@ -48,20 +45,22 @@ import {
|
|||
} from '@features/reminders/services/reminders';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
||||
import { ADDON_CALENDAR_COMPONENT } from '../constants';
|
||||
|
||||
const ROOT_CACHE_KEY = 'mmaCalendar:';
|
||||
|
||||
/**
|
||||
* Main calendar Event types enumeration.
|
||||
*/
|
||||
export enum AddonCalendarEventType {
|
||||
SITE = 'site',
|
||||
CATEGORY = 'category',
|
||||
COURSE = 'course',
|
||||
GROUP = 'group',
|
||||
USER = 'user',
|
||||
}
|
||||
import {
|
||||
ADDON_CALENDAR_COMPONENT,
|
||||
ADDON_CALENDAR_DAYS_INTERVAL,
|
||||
ADDON_CALENDAR_DELETED_EVENT_EVENT,
|
||||
ADDON_CALENDAR_EDIT_EVENT_EVENT,
|
||||
ADDON_CALENDAR_EVENTS_TABLE,
|
||||
ADDON_CALENDAR_FILTER_CHANGED_EVENT,
|
||||
ADDON_CALENDAR_NEW_EVENT_EVENT,
|
||||
ADDON_CALENDAR_PAGE_NAME,
|
||||
ADDON_CALENDAR_STARTING_WEEK_DAY,
|
||||
ADDON_CALENDAR_TF_12,
|
||||
ADDON_CALENDAR_TF_24,
|
||||
ADDON_CALENDAR_UNDELETED_EVENT_EVENT,
|
||||
AddonCalendarEventType,
|
||||
} from '../constants';
|
||||
import { AddonCalendarFilter } from './calendar-helper';
|
||||
|
||||
declare module '@singletons/events' {
|
||||
|
||||
|
@ -71,13 +70,11 @@ declare module '@singletons/events' {
|
|||
* @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
||||
*/
|
||||
export interface CoreEventsData {
|
||||
[AddonCalendarProvider.NEW_EVENT_EVENT]: AddonCalendarUpdatedEventEvent;
|
||||
[AddonCalendarProvider.EDIT_EVENT_EVENT]: AddonCalendarUpdatedEventEvent;
|
||||
[AddonCalendarProvider.DELETED_EVENT_EVENT]: AddonCalendarUpdatedEventEvent;
|
||||
[AddonCalendarProvider.UNDELETED_EVENT_EVENT]: AddonCalendarUpdatedEventEvent;
|
||||
[AddonCalendarProvider.FILTER_CHANGED_EVENT]: AddonCalendarFilter;
|
||||
[AddonCalendarSyncProvider.MANUAL_SYNCED]: AddonCalendarSyncEvents;
|
||||
[AddonCalendarSyncProvider.AUTO_SYNCED]: AddonCalendarSyncEvents;
|
||||
[ADDON_CALENDAR_NEW_EVENT_EVENT]: AddonCalendarUpdatedEvent;
|
||||
[ADDON_CALENDAR_EDIT_EVENT_EVENT]: AddonCalendarUpdatedEvent;
|
||||
[ADDON_CALENDAR_DELETED_EVENT_EVENT]: AddonCalendarUpdatedEvent;
|
||||
[ADDON_CALENDAR_UNDELETED_EVENT_EVENT]: AddonCalendarUpdatedEvent;
|
||||
[ADDON_CALENDAR_FILTER_CHANGED_EVENT]: AddonCalendarFilter;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -88,20 +85,7 @@ declare module '@singletons/events' {
|
|||
@Injectable({ providedIn: 'root' })
|
||||
export class AddonCalendarProvider {
|
||||
|
||||
static readonly DAYS_INTERVAL = 30;
|
||||
|
||||
static readonly STARTING_WEEK_DAY = 'addon_calendar_starting_week_day';
|
||||
static readonly NEW_EVENT_EVENT = 'addon_calendar_new_event';
|
||||
static readonly NEW_EVENT_DISCARDED_EVENT = 'addon_calendar_new_event_discarded';
|
||||
static readonly EDIT_EVENT_EVENT = 'addon_calendar_edit_event';
|
||||
static readonly DELETED_EVENT_EVENT = 'addon_calendar_deleted_event';
|
||||
static readonly UNDELETED_EVENT_EVENT = 'addon_calendar_undeleted_event';
|
||||
static readonly FILTER_CHANGED_EVENT = 'addon_calendar_filter_changed_event';
|
||||
|
||||
static readonly CALENDAR_TF_24 = '%H:%M'; // Calendar time in 24 hours format.
|
||||
static readonly CALENDAR_TF_12 = '%I:%M %p'; // Calendar time in 12 hours format.
|
||||
|
||||
protected weekDays: AddonCalendarWeekDaysTranslationKeys[] = [
|
||||
protected static weekDays: AddonCalendarWeekDaysTranslationKeys[] = [
|
||||
{
|
||||
shortname: 'addon.calendar.sun',
|
||||
fullname: 'addon.calendar.sunday',
|
||||
|
@ -132,6 +116,8 @@ export class AddonCalendarProvider {
|
|||
},
|
||||
];
|
||||
|
||||
protected static readonly ROOT_CACHE_KEY = 'mmaCalendar:';
|
||||
|
||||
/**
|
||||
* Check if a certain site allows creating and editing events.
|
||||
*
|
||||
|
@ -248,7 +234,7 @@ export class AddonCalendarProvider {
|
|||
const promises: Promise<unknown>[] = [];
|
||||
|
||||
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<AddonCalendarEventDBRecord[]> {
|
||||
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<AddonCalendarGetEventsEvent | AddonCalendarEvent> {
|
||||
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<AddonCalendarGetEventsEvent[]> {
|
||||
|
||||
|
@ -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<AddonCalendarEventDBRecord[]> {
|
||||
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<AddonCalendarCalendarEvent> &
|
|||
|
||||
/**
|
||||
* 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;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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<void> => {
|
|||
// 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<void> => {
|
|||
// 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;
|
||||
|
|
Loading…
Reference in New Issue