diff options
-rw-r--r-- | frontend.js | 9 | ||||
-rw-r--r-- | model_fs.js | 24 |
2 files changed, 18 insertions, 15 deletions
diff --git a/frontend.js b/frontend.js index ed50fc7..a069966 100644 --- a/frontend.js +++ b/frontend.js @@ -28,11 +28,10 @@ exports.start = function(config) { } var eventStr = ''; for(var date in slides['events']) { - if(!slides['events'].hasOwnProperty(date)) { continue; } - eventStr = eventStr + '<h4>'+slides['events'][date]['date']+'</h4><hr><ul>'; - for(var ev in slides['events'][date]['events']) { - if(!slides['events'][date]['events'].hasOwnProperty(ev)) { continue; } - eventStr = eventStr + '<li>'+slides['events'][date]['events'][ev]['time']+' - '+slides['events'][date]['events'][ev]['text']+'</li>'; + eventStr = eventStr + '<h4>'+date+'</h4><hr><ul>'; + for(var ev in slides['events'][date]) { + if(!slides['events'][date].hasOwnProperty(ev)) { continue; } + eventStr = eventStr + '<li>'+slides['events'][date][ev]['time']+' - '+slides['events'][date][ev]['text']+'</li>'; } eventStr = eventStr + '</ul>'; } diff --git a/model_fs.js b/model_fs.js index 6c64211..14cb4b5 100644 --- a/model_fs.js +++ b/model_fs.js @@ -17,7 +17,6 @@ exports.start = function(config) { watcher.on('fileCreated', exports.rebuildFiles); watcher.on('fileModified', exports.rebuildFiles); exports.rebuildFiles(); - }; exports.rebuildFiles = function() { @@ -86,27 +85,32 @@ exports.rebuildFiles = function() { } /* collect events and adds them to the slideset */ var collectEvents = function(slideset) { - fs.readFile(path.join(__dirname, configuration.dir, 'default', configuration.events), function(err, data) { + fs.readFile(path.join(__dirname, configuration.dir, slideset, configuration.events), function(err, data) { if(err) { throw err; } var events = JSON.parse(data.toString()); if(events['type'] == 'text') { - files[slideset]['events'] = events['events']; + setEvents(slideset, events['events'], function(err) { + if(err) { throw err; } + }); } else if(events['type'] == 'ical') { - var compEv = []; ical.fromURL(events['url'], {}, function(err, data) { + if(err) { throw err; } + var compEv = []; for (var k in data) { if (data.hasOwnProperty(k)) { var ev = data[k]; if(ev.start && ev.summary) { - compEv.push({ - date: - ev.start, - text: - ev.summary - }); + var curDate = new Date(ev.start); + if(typeof compEv[curDate.toDateString()] == "undefined") { + compEv[curDate.toDateString()] = []; + } + compEv[curDate.toDateString()].push({time: curDate.toTimeString(), text: ev.summary}); } } } + setEvents(slideset, compEv, function(err) { + if(err) { throw err; } + }); }); } }); |