-
-
Save odesey/70f4833f3db155a3a6abcbf93da6ce3b to your computer and use it in GitHub Desktop.
Reactive fullcalendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment