From c6ee6f7af1dbe3b7f58ac5075a93cf61643aebc6 Mon Sep 17 00:00:00 2001 From: Benjamin Kiessling Date: Tue, 29 Nov 2011 15:47:48 +0100 Subject: Beautify code --- model_fs.js | 63 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/model_fs.js b/model_fs.js index 8a4aa13..6c64211 100644 --- a/model_fs.js +++ b/model_fs.js @@ -64,6 +64,7 @@ exports.rebuildFiles = function() { next(); }).on("end", function() { for(var slideset in newSlides) { + /* collects descriptions and adds them to the slideset */ var collectDescs = function(slideset) { fs.readFile(path.join(__dirname, configuration.dir, slideset, configuration.description), function(err, data) { if(err) { throw err; } @@ -80,52 +81,56 @@ exports.rebuildFiles = function() { } } } - exports.addSlides(slideset, newSlides[slideset], function(err) { if(err) { throw err; }}); - fs.readFile(path.join(__dirname, configuration.dir, 'default', configuration.events), function(err, data) { - var events = JSON.parse(data.toString()); - if(events['type'] == 'text') { - files[slideset]['events'] = events['events']; - } else if(events['type'] == 'ical') { - var compEv = []; - ical.fromURL(events['url'], {}, function(err, data) { - 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 - }); - } + 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.dir, 'default', configuration.events), function(err, data) { + if(err) { throw err; } + var events = JSON.parse(data.toString()); + if(events['type'] == 'text') { + files[slideset]['events'] = events['events']; + } else if(events['type'] == 'ical') { + var compEv = []; + ical.fromURL(events['url'], {}, function(err, data) { + 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 + }); } } - }); - } - }); + } + }); + } }); } collectDescs(slideset); + collectEvents(slideset); } }); }; -exports.setEvents = function(slideset, events, cb) { +var setEvents = function(slideset, events, cb) { - var found = 0; for (var searchset in files) { if(!files.hasOwnProperty(searchset)) { continue; } if(files[searchset].name == slideset) { files[searchset]['events'] = events; - found = 1; + cb(null); + return; } } - if(found) { cb('Couldn\'t find slideset'); } - else { cb(null); } + cb('Couldn\'t find slideset'); }; -exports.addSlides = function(slideName, newSlides, cb) { +var setSlides = function(slideName, newSlides, cb) { files[slideName] = newSlides; cb(null); }; @@ -136,8 +141,10 @@ exports.getSlides = function(slideset, cb) { if(!files.hasOwnProperty(searchset)) { continue; } if(files[searchset].name == slideset) { cb(null, files[searchset]); + return; } } + cb('Couldn\'t find slideset'); }; exports.getAllSlides = function(cb) { -- cgit v1.2.1