Skip to content

Instantly share code, notes, and snippets.

@jurajkrivda
Last active July 27, 2016 17:57
Show Gist options
  • Save jurajkrivda/69cadf99681114d952f5 to your computer and use it in GitHub Desktop.
Save jurajkrivda/69cadf99681114d952f5 to your computer and use it in GitHub Desktop.
Reactive fullcalendar
Template.Calendar.onCreated(function () {
const instance = this;
instance.viewDate = new ReactiveVar();
instance.autorun(() => {
const viewDate = instance.viewDate.get();
if (typeof viewDate !== 'undefined') {
const startDate = Math.round(viewDate.start / 1000);
const endDate = Math.round(viewDate.end / 1000);
instance.subscribe('subscribe', startDate, endDate);
}
});
});
Template.Calendar.onRendered(function () {
const instance = Template.instance();
const calendar = instance.$('#calendar');
instance.autorun(function () {
calendar.fullCalendar({
// options
});
const viewDate = instance.viewDate.get();
if (typeof viewDate !== 'undefined') {
if (!!instance.handle) {
instance.handle.stop();
}
const someData = Collection.find({
$or: [
{date: {$gte: new Date(viewDate.start * 1000)}},
{date: {$lte: new Date(viewDate.end * 1000)}}
]
});
instance.handle = someData.observeChanges({
added: function (id, doc) {
calendar.fullCalendar('renderEvent', {
id, title
}, true);
},
removed: function (value) {
calendar.fullCalendar('removeEvents', value);
}
});
}
})
})
@nosizejosh
Copy link

Solved.
Appointments.find({ start: { $gte: new Date(args.start) }, end: { $lte: new Date(args.end) }, 'provider_id': args.provider_id } Thanks
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment