scoutforpets / ember-fullcalendar

An Ember Component for FullCalendar and FullCalendar Scheduler
MIT License
39 stars 45 forks source link

Adds support for google calendar. #71

Open yortz opened 6 years ago

yortz commented 6 years ago

This adds the missing googleCalendarApiKey option available on fullcalendar.js by default to enable support for google calendar, together with the required (updated) gcal.min.js file. Currently using this on a production website, it runs smoothly just simply add the value for your google calendar api key and the url for the public calendar in eventsources e.g.:

googleCalendarApiKey: computed(function() {
  return this.get('currentUser.googleCalendarApiKey');
}),

calendarUrl: computed(function() {
  return this.get('currentUser.calendarUrl');
}),

eventSources: computed('currentUser.calendarUrl', function() {
  let events = [this.get('localEvents')];
  if (this.hasGoogleCalendarEvents()) {
    events.push(this.get('googleEvents'));
  }
  return events;
}),

hasGoogleCalendarEvents() {
  return (this.get('googleCalendarApiKey') && this.get('calendarUrl'));
},

localEvents: computed(function() {
    return events = Ember.A([{
     title: 'Event 1',
     start: '2016-05-05T07:08:08',
     end: '2016-05-05T09:08:08'
    }, {
     title: 'Event 2',
     start: '2016-05-06T07:08:08',
     end: '2016-05-07T09:08:08'
    }, {
     title: 'Event 3',
     start: '2016-05-10T07:08:08',
     end: '2016-05-10T09:48:08'
    }, {
     title: 'Event 4',
     start: '2016-05-11T07:15:08',
     end: '2016-05-11T09:08:08'
    }]);
}),

googleEvents: computed(function() {
  let calendarId = this.get('calendarUrl');
  return {
    googleCalendarId: calendarId,
    className: 'gcal-event'
  };
})
yortz commented 6 years ago

Actually, you need to explicitly require gcal.min.js in your ember app, being a not a js developer I cannot understand how to import it into the component, maybe this PR can save some time to other peeps trying to add google calendar via the fullcalendar addon for ember.