summaryrefslogtreecommitdiff
path: root/model_fs.js
diff options
context:
space:
mode:
Diffstat (limited to 'model_fs.js')
-rw-r--r--model_fs.js101
1 files changed, 51 insertions, 50 deletions
diff --git a/model_fs.js b/model_fs.js
index 5a40346..1a2dfbd 100644
--- a/model_fs.js
+++ b/model_fs.js
@@ -85,59 +85,60 @@ exports.rebuildFiles = function() {
setSlides(slideset, newSlides[slideset], function(err) { if(err) { throw err; }});
});
}
- /* collect events and adds them to the slideset */
- var collectEvents = function(slideset) {
- fs.readFile(path.join(__dirname, configuration.rootDir, slideset, configuration.eventFile), function(err, data) {
- if(err) { return; }
- try {
- var events = JSON.parse(data.toString());
- } catch(e) {
- return;
+ collectDescs(slideset);
+ fetchEvents(slideset);
+ }
+ });
+};
+
+/* collect events and adds them to the slideset */
+var fetchEvents = function(slideset) {
+ fs.readFile(path.join(__dirname, configuration.rootDir, slideset, configuration.eventFile), function(err, data) {
+ if(err) { return; }
+ try {
+ var events = JSON.parse(data.toString());
+ } catch(e) {
+ return;
+ }
+ if(events['type'] == 'text') {
+ setEvents(slideset, events['events'], function(err) {
+ if(err) { throw err; }
+ });
+ } else if(events['type'] == 'ical') {
+ ical.fromURL(events['url'], {}, function(err, bloat) {
+ if(err) { throw err; }
+ var bDate = new Date();
+ var fDate = new Date();
+ bDate.setMinutes(bDate.getMinutes() - events['before']);
+ fDate.setMinutes(bDate.getMinutes() + events['after']);
+ var data = ical.events_between(bDate, fDate);
+ var compEv = [];
+ for (var k in data) {
+ if (!data.hasOwnProperty(k)) { continue; }
+ var ev = data[k];
+ if(ev.start && ev.summary) {
+ var dateStr = ev.start.toLocaleDateString();
+ ev.start = ev.start.toLocaleTimeString();
+ ev.end = ev.end.toLocaleTimeString();
+ delete ev.rrule;
+ delete ev.uid;
+ delete ev.type;
+ for(var i in ev) {
+ if(!ev.hasOwnProperty(i)) { continue; }
+ if(typeof ev[i] != 'string') { continue; }
+ ev[i] = ev[i].replace(/\\,/g, ',');
}
- if(events['type'] == 'text') {
- setEvents(slideset, events['events'], function(err) {
- if(err) { throw err; }
- });
- } else if(events['type'] == 'ical') {
- ical.fromURL(events['url'], {}, function(err, bloat) {
- if(err) { throw err; }
- var bDate = new Date();
- var fDate = new Date();
- bDate.setMinutes(bDate.getMinutes() - events['before']);
- fDate.setMinutes(bDate.getMinutes() + events['after']);
- var data = ical.events_between(bDate, fDate);
- var compEv = [];
- for (var k in data) {
- if (!data.hasOwnProperty(k)) { continue; }
- var ev = data[k];
- if(ev.start && ev.summary) {
- var dateStr = ev.start.toLocaleDateString();
- ev.start = ev.start.toLocaleTimeString();
- ev.end = ev.end.toLocaleTimeString();
- delete ev.rrule;
- delete ev.uid;
- delete ev.type;
- for(var i in ev) {
- if(!ev.hasOwnProperty(i)) { continue; }
- if(typeof ev[i] != 'string') { continue; }
- ev[i] = ev[i].replace(/\\,/g, ',');
- }
- if(typeof compEv[dateStr] == "undefined") {
- compEv[dateStr] = [];
- }
- compEv[dateStr].push(ev);
- }
- }
- setEvents(slideset, compEv, function(err) {
- if(err) { throw err; }
- });
- });
+ if(typeof compEv[dateStr] == "undefined") {
+ compEv[dateStr] = [];
}
- });
+ compEv[dateStr].push(ev);
+ }
}
- collectDescs(slideset);
- collectEvents(slideset);
- }
+ setEvents(slideset, compEv, function(err) {
+ if(err) { throw err; }
+ });
+ });
+ }
});
};