diff options
author | Benjamin Kiessling <mittagessen@l.unchti.me> | 2012-03-02 21:54:50 +0100 |
---|---|---|
committer | Benjamin Kiessling <mittagessen@l.unchti.me> | 2012-03-02 21:54:50 +0100 |
commit | 9e24efbeb0b82f09b74ff979f6714f6636d0d606 (patch) | |
tree | 83afc5b631beba4d50e4b44dcdbed94f1bc00ef5 | |
parent | 8e5a36d32ab3cb89963689913d26f1083524ebbc (diff) |
Split up slides and event fetching
-rw-r--r-- | model_fs.js | 101 |
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; } + }); + }); + } }); }; |