diff --git a/src/addon/calendar/calendar.module.ts b/src/addon/calendar/calendar.module.ts index ac20c15e7..a79aa07dd 100644 --- a/src/addon/calendar/calendar.module.ts +++ b/src/addon/calendar/calendar.module.ts @@ -17,6 +17,9 @@ import { AddonCalendarProvider } from './providers/calendar'; import { AddonCalendarHelperProvider } from './providers/helper'; import { AddonCalendarMainMenuHandler } from './providers/handlers'; import { CoreMainMenuDelegate } from '../../core/mainmenu/providers/delegate'; +import { CoreInitDelegate } from '../../providers/init'; +import { CoreLocalNotificationsProvider } from '../../providers/local-notifications'; +import { CoreLoginHelperProvider } from '../../core/login/providers/helper'; @NgModule({ declarations: [ @@ -30,7 +33,29 @@ import { CoreMainMenuDelegate } from '../../core/mainmenu/providers/delegate'; ] }) export class AddonCalendarModule { - constructor(mainMenuDelegate: CoreMainMenuDelegate, calendarHandler: AddonCalendarMainMenuHandler) { + constructor(mainMenuDelegate: CoreMainMenuDelegate, calendarHandler: AddonCalendarMainMenuHandler, + initDelegate: CoreInitDelegate, calendarProvider: AddonCalendarProvider, loginHelper: CoreLoginHelperProvider, + localNotificationsProvider: CoreLocalNotificationsProvider) { mainMenuDelegate.registerHandler(calendarHandler); + + initDelegate.ready().then(() => { + calendarProvider.scheduleAllSitesEventsNotifications(); + }); + + + localNotificationsProvider.registerClick(AddonCalendarProvider.COMPONENT, (data) => { + if (data.eventid) { + initDelegate.ready().then(() => { + calendarProvider.isDisabled(data.siteId).then(function(disabled) { + if (disabled) { + // The calendar is disabled in the site, don't open it. + return; + } + + loginHelper.redirect('AddonCalendarListPage', {eventid: data.eventid}, data.siteId); + }); + }); + } + }); } } \ No newline at end of file diff --git a/src/addon/calendar/pages/event/event.html b/src/addon/calendar/pages/event/event.html index 61451a1cb..f3f20e707 100644 --- a/src/addon/calendar/pages/event/event.html +++ b/src/addon/calendar/pages/event/event.html @@ -7,7 +7,7 @@ - + diff --git a/src/addon/calendar/pages/event/event.ts b/src/addon/calendar/pages/event/event.ts index e0c102ca7..590e3806a 100644 --- a/src/addon/calendar/pages/event/event.ts +++ b/src/addon/calendar/pages/event/event.ts @@ -40,7 +40,7 @@ export class AddonCalendarEventPage { eventLoaded: boolean; notificationTime: number; defaultTimeReadable: string; - event = {}; + event: any = {}; title: string; courseName: string; notificationsEnabled = false; diff --git a/src/addon/calendar/pages/list/list.html b/src/addon/calendar/pages/list/list.html index 9052d8bb1..8ecc9754b 100644 --- a/src/addon/calendar/pages/list/list.html +++ b/src/addon/calendar/pages/list/list.html @@ -15,14 +15,14 @@ - + - +

diff --git a/src/addon/calendar/pages/list/list.ts b/src/addon/calendar/pages/list/list.ts index 8e473800e..355cb5b89 100644 --- a/src/addon/calendar/pages/list/list.ts +++ b/src/addon/calendar/pages/list/list.ts @@ -92,8 +92,18 @@ export class AddonCalendarListPage implements OnDestroy { this.fetchData().then(() => { // @TODO: Split view once single event is done. if (this.eventId && this.appProvider.isWide()) { - // There is an event to load and it's a phone device, open the event in a new state. - this.gotoEvent(this.eventId); + // There is an event to load and it's a tablet device. Search the position of the event in the list and load it. + let found = this.events.findIndex((e) => {return e.id == this.eventId}); + + if (found > 0) { + this.eventToLoad = found + 1; + } else { + // Event not found in the list, open it in a new state. Use a $timeout to open the state after the + // split view is loaded. + //$timeout(function() { + this.gotoEvent(this.eventId); + //}); + } } }).finally(() => { this.eventsLoaded = true; diff --git a/src/addon/calendar/providers/calendar.ts b/src/addon/calendar/providers/calendar.ts index 1e9d85ffb..d4dbfb03d 100644 --- a/src/addon/calendar/providers/calendar.ts +++ b/src/addon/calendar/providers/calendar.ts @@ -29,10 +29,10 @@ import { CoreConfigProvider } from '../../../providers/config'; @Injectable() export class AddonCalendarProvider { public static DAYS_INTERVAL = 30; + public static COMPONENT = 'AddonCalendarEvents'; public static DEFAULT_NOTIFICATION_TIME_CHANGED = 'AddonCalendarDefaultNotificationTimeChangedEvent'; - protected static DEFAULT_NOTIFICATION_TIME_SETTING = 'AddonCalendarDefaultNotifTime'; + protected static DEFAULT_NOTIFICATION_TIME_SETTING = 'mmaCalendarDefaultNotifTime'; protected static DEFAULT_NOTIFICATION_TIME = 60; - protected static COMPONENT = 'AddonCalendarEvents'; // Variables for database. protected static EVENTS_TABLE = 'calendar_events'; // Queue of files to download. @@ -220,7 +220,7 @@ export class AddonCalendarProvider { * @param {string} [siteId] Site to get the events from. If not defined, use current site. * @return {Promise} Promise to be resolved when the participants are retrieved. */ - getEventsList(daysToStart = 0, daysInterval=AddonCalendarProvider.DAYS_INTERVAL, siteId?: string) : Promise { + getEventsList(daysToStart = 0, daysInterval = AddonCalendarProvider.DAYS_INTERVAL, siteId?: string) : Promise { return this.sitesProvider.getSite(siteId).then((site) => { siteId = site.getId(); @@ -327,6 +327,50 @@ export class AddonCalendarProvider { return site.isFeatureDisabled('$mmSideMenuDelegate_mmaCalendar'); } + /** + * Check if Calendar is disabled in a certain site. + * + * @param {string} [siteId] Site Id. If not defined, use current site. + * @return {Promise} Promise resolved with true if disabled, rejected or resolved with false otherwise. + */ + isDisabled(siteId?: string) : Promise { + return this.sitesProvider.getSite(siteId).then((site) => { + return this.isCalendarDisabledInSite(site); + }); + } + + + /** + * Get the next events for all the sites and schedules their notifications. + * If an event notification time is 0, cancel its scheduled notification (if any). + * If local notification plugin is not enabled, resolve the promise. + * + * @return {Promise} Promise resolved when all the notifications have been scheduled. + */ + scheduleAllSitesEventsNotifications() : Promise { + if (this.localNotificationsProvider.isAvailable()) { + return this.sitesProvider.getSitesIds().then((siteIds) => { + let promises = []; + + siteIds.forEach((siteId) => { + // Check if calendar is disabled for the site. + promises.push(this.isDisabled(siteId).then((disabled) => { + if (!disabled) { + // Get first events. + return this.getEventsList(undefined, undefined, siteId).then((events) => { + return this.scheduleEventsNotifications(events, siteId); + }); + } + })); + }); + + return Promise.all(promises); + }); + } else { + return Promise.resolve([]); + } + } + /** * Schedules an event notification. If time is 0, cancel scheduled notification if any. * If local notification plugin is not enabled, resolve the promise. diff --git a/src/app/app.md.scss b/src/app/app.md.scss index 4aa56ca6d..c0814c60b 100644 --- a/src/app/app.md.scss +++ b/src/app/app.md.scss @@ -17,7 +17,7 @@ } // Highlights inside the input element. -@if ($mm-text-input-md-show-highlight) { +@if ($core-text-input-md-show-highlight) { .card-md, .list-md { // In order to get a 2px border we need to add an inset // box-shadow 1px (this is to avoid the div resizing)