MOBILE-2308 calendar: Init process

main
Pau Ferrer Ocaña 2017-12-29 13:47:00 +01:00
parent d4ddfc74a1
commit 04e3d6d2d1
7 changed files with 90 additions and 11 deletions

View File

@ -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);
});
});
}
});
}
}

View File

@ -7,7 +7,7 @@
<ion-refresher [enabled]="eventLoaded" (ionRefresh)="refreshEvent($event)">
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<core-loading [hideUntil]="eventLoaded" class="mm-loading-center">
<core-loading [hideUntil]="eventLoaded" class="core-loading-center">
<ion-card>
<ion-card-content>
<ion-card-title text-wrap>

View File

@ -40,7 +40,7 @@ export class AddonCalendarEventPage {
eventLoaded: boolean;
notificationTime: number;
defaultTimeReadable: string;
event = {};
event: any = {};
title: string;
courseName: string;
notificationsEnabled = false;

View File

@ -15,14 +15,14 @@
<ion-refresher [enabled]="eventsLoaded" (ionRefresh)="refreshEvents($event)">
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<core-loading [hideUntil]="eventsLoaded" class="mm-loading-center">
<core-loading [hideUntil]="eventsLoaded" class="core-loading-center">
<!-- @todo: Split view. -->
<core-empty-box *ngIf="!filteredEvents || !filteredEvents.length" icon="calendar" [message]="'addon.calendar.noevents' | translate">
</core-empty-box>
<ion-list *ngIf="filteredEvents && filteredEvents.length">
<a ion-item text-wrap *ngFor="let event of filteredEvents" [title]="event.name" (click)="gotoEvent(event.id)">
<!-- mm-split-view-link="site.calendar-event({id: event.id})" -->
<!-- core-split-view-link="site.calendar-event({id: event.id})" -->
<img *ngIf="event.moduleIcon" src="{{event.moduleIcon}}" item-start>
<ion-icon *ngIf="!event.moduleIcon" name="{{event.icon}}" item-start></ion-icon>
<h2><core-format-text [text]="event.name"></core-format-text></h2>

View File

@ -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.
// 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;

View File

@ -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<any[]>} Promise to be resolved when the participants are retrieved.
*/
getEventsList(daysToStart = 0, daysInterval=AddonCalendarProvider.DAYS_INTERVAL, siteId?: string) : Promise<any[]> {
getEventsList(daysToStart = 0, daysInterval = AddonCalendarProvider.DAYS_INTERVAL, siteId?: string) : Promise<any[]> {
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<boolean>} Promise resolved with true if disabled, rejected or resolved with false otherwise.
*/
isDisabled(siteId?: string) : Promise<boolean> {
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<any[]> {
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.

View File

@ -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)