| |
@@ -4,6 +4,7 @@
|
| |
|
| |
import { NotificationsPage } from '../../pages/notifications/notifications';
|
| |
import { FedoCalService, Calendar as CalendarType, Meeting } from '../../providers/fedo-cal/fedo-cal';
|
| |
+ import { CalendarSubscriptionManager } from '../../providers/calendar-subscription-manager/calendar-subscription-manager';
|
| |
|
| |
|
| |
/**
|
| |
@@ -19,14 +20,13 @@
|
| |
*/
|
| |
@Component({
|
| |
templateUrl: 'calendar.html',
|
| |
- providers: [FedoCalService, Calendar]
|
| |
})
|
| |
export class CalendarPage {
|
| |
|
| |
/**
|
| |
* Set the current active segment as Upcoming Events in the interface
|
| |
*/
|
| |
- showEventsBy: string = "upcoming";
|
| |
+ showEventsBy = 'upcoming';
|
| |
|
| |
/**
|
| |
* List of calendars in FedoCal
|
| |
@@ -36,14 +36,18 @@
|
| |
/**
|
| |
* List of meetings in the selected calendar
|
| |
*/
|
| |
- private meetings: Meeting[];
|
| |
+ meetings: Meeting[];
|
| |
|
| |
/**
|
| |
* ID of the selected calendar
|
| |
*/
|
| |
public selectedCalendar: CalendarType;
|
| |
|
| |
- constructor(private fedoCal: FedoCalService, private calendar: Calendar, public modalCtrl: ModalController, public navCtrl: NavController) {
|
| |
+ constructor(
|
| |
+ private fedoCal: FedoCalService,
|
| |
+ private calendar: Calendar,
|
| |
+ private modalCtrl: ModalController,
|
| |
+ private navCtrl: NavController) {
|
| |
this.calendars = [];
|
| |
this.meetings = [];
|
| |
|
| |
@@ -52,17 +56,7 @@
|
| |
|
| |
ngOnInit() {
|
| |
this.updateCalendars();
|
| |
- /**
|
| |
- * Fetch upcoming meetings
|
| |
- */
|
| |
- this.updateMeetings('start');
|
| |
- }
|
| |
-
|
| |
- /**
|
| |
- * Change the meeting view according to active segment
|
| |
- */
|
| |
- onSegmentChange() {
|
| |
- this.showEventsBy == 'upcoming' ? this.updateMeetings('start') : this.updateMeetings('end');
|
| |
+ this.updateMeetings();
|
| |
}
|
| |
|
| |
/**
|
| |
@@ -80,9 +74,20 @@
|
| |
* Update the list of meetings for the selected calendar
|
| |
* @param type type of meetings to fetch, upcoming or past
|
| |
*/
|
| |
- updateMeetings(type: string): void {
|
| |
+ updateMeetings(): void {
|
| |
+ const params: any = {};
|
| |
+
|
| |
+ const now = new Date();
|
| |
+ const today = now.toISOString().split('T')[0];
|
| |
+
|
| |
+ if (this.showEventsBy === 'upcoming') {
|
| |
+ params.start = today;
|
| |
+ } else {
|
| |
+ params.end = today;
|
| |
+ }
|
| |
+
|
| |
this.fedoCal
|
| |
- .getMeetings(this.selectedCalendar, type)
|
| |
+ .getMeetings(this.selectedCalendar, params)
|
| |
.subscribe(meetings => {
|
| |
this.meetings = meetings;
|
| |
});
|
| |
@@ -93,10 +98,11 @@
|
| |
*/
|
| |
showSearch() {
|
| |
let searchModal = this.modalCtrl.create(Search, { calendars: this.calendars }, {
|
| |
- cssClass: "search-modal",
|
| |
+ cssClass: 'search-modal',
|
| |
showBackdrop: false,
|
| |
enableBackdropDismiss: false
|
| |
});
|
| |
+
|
| |
/**
|
| |
* Update calendars when search modal closes
|
| |
*/
|
| |
@@ -105,7 +111,7 @@
|
| |
if (data !== undefined) {
|
| |
let receivedCalendar = { realName: data.calendarChoice };
|
| |
this.selectedCalendar = receivedCalendar as CalendarType;
|
| |
- this.showEventsBy == 'upcoming' ? this.updateMeetings('start') : this.updateMeetings('end');
|
| |
+ this.updateMeetings();
|
| |
}
|
| |
});
|
| |
searchModal.present();
|
| |
@@ -152,6 +158,10 @@
|
| |
openMeetingDetails(meeting: Meeting) {
|
| |
this.navCtrl.push(meetingDetails, { meeting: meeting });
|
| |
}
|
| |
+
|
| |
+ onSegmentChange() {
|
| |
+ this.updateMeetings();
|
| |
+ }
|
| |
}
|
| |
|
| |
/**
|
| |
@@ -161,7 +171,7 @@
|
| |
@Component({
|
| |
templateUrl: 'search.html',
|
| |
selector: 'searchpage',
|
| |
- providers: [FedoCalService, Calendar]
|
| |
+ providers: [FedoCalService]
|
| |
})
|
| |
export class Search {
|
| |
|
| |
@@ -177,7 +187,10 @@
|
| |
activeIcon: string = './assets/img/star-active.svg';
|
| |
inactiveIcon: string = './assets/img/star-inactive.svg';
|
| |
|
| |
- constructor(public viewCtrl: ViewController, navParams: NavParams, public toastCtrl: ToastController) {
|
| |
+ constructor(
|
| |
+ private viewCtrl: ViewController, navParams: NavParams,
|
| |
+ private toastCtrl: ToastController,
|
| |
+ private subscriptionManager: CalendarSubscriptionManager) {
|
| |
//store all the calendars in one place
|
| |
this.allCalendars = navParams.get('calendars');
|
| |
|
| |
@@ -191,9 +204,9 @@
|
| |
|
| |
/**
|
| |
* Listens to input on the search bar
|
| |
- *
|
| |
+ *
|
| |
* Returns calendars matching the query
|
| |
- *
|
| |
+ *
|
| |
* @param query search query entered in the input box
|
| |
*/
|
| |
onInput(query: string): void {
|
| |
@@ -219,29 +232,32 @@
|
| |
/**
|
| |
* Function called when someone taps the star to subscribe to the calendar
|
| |
*/
|
| |
- subscribeToCal(calendar: CalendarType, i: number): void {
|
| |
- /**
|
| |
- * Declare toasts for showing events
|
| |
- */
|
| |
- const subscribedToast = this.toastCtrl.create({
|
| |
- message: 'Subscribed to calendar: ' + calendar.realName,
|
| |
- duration: 2000
|
| |
- });
|
| |
- const unsubscribedToast = this.toastCtrl.create({
|
| |
- message: 'Unsubscribed from calendar: ' + calendar.realName,
|
| |
- duration: 2000
|
| |
- });
|
| |
+ async subscribeToCal(calendar: CalendarType, i: number) {
|
| |
|
| |
- /**
|
| |
- * Fire event on the basis of selected icon
|
| |
- */
|
| |
+ const options:any = {
|
| |
+ duration: 2000,
|
| |
+ position: 'bottom'
|
| |
+ };
|
| |
+
|
| |
+ // Fire event on the basis of selected icon
|
| |
if (this.calendarIcon[i] === this.inactiveIcon) {
|
| |
this.calendarIcon[i] = this.activeIcon;
|
| |
- subscribedToast.present();
|
| |
+
|
| |
+ try {
|
| |
+ await this.subscriptionManager.subscribeToCalendar(calendar);
|
| |
+ } catch(e) {
|
| |
+ options.message = 'Error subscribing to calendar';
|
| |
+ console.error(e);
|
| |
+ }
|
| |
+
|
| |
+ options.message = 'Subscribed to calendar: ' + calendar.displayName;
|
| |
+
|
| |
} else {
|
| |
this.calendarIcon[i] = this.inactiveIcon;
|
| |
- unsubscribedToast.present();
|
| |
+ options.message = 'Unsubscribed to calendar: ' + calendar.displayName;
|
| |
}
|
| |
+
|
| |
+ this.toastCtrl.create(options).present();
|
| |
}
|
| |
}
|
| |
|
| |
@@ -271,4 +287,4 @@
|
| |
meeting.timeEnd
|
| |
);
|
| |
}
|
| |
- }
|
| |
\ No newline at end of file
|
| |
+ }
|
| |
Allows subscribing a calendar on FedoCal