diff --git a/node/db/API.js b/node/db/API.js index c3bea2723..9bc8e6667 100644 --- a/node/db/API.js +++ b/node/db/API.js @@ -464,6 +464,46 @@ exports.isPasswordProtected = function(padID, callback) }); } +/** +listAllPads() returns a array with all pads + +Example returns: + +{code: 0, message:"ok", data: ["pad1", "pad2"]} +*/ +exports.listAllPads = function(callback) +{ + allPads = []; + + var defaultGroup = "g.defaultGroupName"; + + //get all groups + groupManager.listGroups(function (err, groups) + { + groups=groups["groups"]; + // if defaultGroup exists add this too, becaus ists not listed in groupManager.listGroups + groupManager.doesGroupExist(defaultGroup, function(err, exists) + { + if(exists) + { + groups.push(defaultGroup); + } + }); + for(var group in groups) + { + groupManager.listPads(groups[group], function(err, pads) + { + for(var pad in pads) + { + allPads.push(pads[pad]); + } + }); + } + }); + + callback(null, {padIDs: allPads}); +} + /******************************/ /** INTERNAL HELPER FUNCTIONS */ /******************************/ diff --git a/node/db/GroupManager.js b/node/db/GroupManager.js index 13620c2e5..bc15e430f 100644 --- a/node/db/GroupManager.js +++ b/node/db/GroupManager.js @@ -142,6 +142,7 @@ exports.listGroups = function(callback) //try to get the groups entry db.get("groups", function (err, groups) { + if(groups == null) groups = []; if(ERR(err, callback)) return; callback(null, groups); }); diff --git a/node/db/Pad.js b/node/db/Pad.js index a6e90976c..22dfc7a2f 100644 --- a/node/db/Pad.js +++ b/node/db/Pad.js @@ -354,6 +354,7 @@ Pad.prototype.init = function init(text, callback) { if(_this.id.indexOf("$")==-1) { groupID = "g.defaultGroupName"; + console.log(groupManager); groupManager.doesGroupExist(groupID, function(err, exists) { if(!exists) diff --git a/node/handler/APIHandler.js b/node/handler/APIHandler.js index 1a25b989c..c987120c7 100644 --- a/node/handler/APIHandler.js +++ b/node/handler/APIHandler.js @@ -42,7 +42,8 @@ var functions = { "createGroup" : [], "createGroupIfNotExistsFor" : ["groupMapper"], "deleteGroup" : ["groupID"], - "listPads" : ["groupID"], + "listPads" : ["groupID"], + "listAllPads" : [], "createPad" : ["padID", "text"], "createGroupPad" : ["groupID", "padName", "text"], "createAuthor" : ["name"], diff --git a/static/tests.html b/static/tests.html index f1f47b38d..57f3117c2 100644 --- a/static/tests.html +++ b/static/tests.html @@ -144,6 +144,7 @@