add listAllPads API function

This commit is contained in:
aritas1 2012-02-14 19:48:47 +04:00
parent 2466e65212
commit 5f5a909420
5 changed files with 45 additions and 1 deletions

View file

@ -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 */
/******************************/

View file

@ -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);
});

View file

@ -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)

View file

@ -43,6 +43,7 @@ var functions = {
"createGroupIfNotExistsFor" : ["groupMapper"],
"deleteGroup" : ["groupID"],
"listPads" : ["groupID"],
"listAllPads" : [],
"createPad" : ["padID", "text"],
"createGroupPad" : ["groupID", "padName", "text"],
"createAuthor" : ["name"],

View file

@ -144,6 +144,7 @@
<div class="define">deleteGroup(groupID)</div>
<div class="define">createGroupIfNotExistsFor(groupMapper)</div>
<div class="define">listPads(groupID)</div>
<div class="define">listAllPads()</div>
<div class="define">createPad(padID,text)</div>
<div class="define">createGroupPad(groupID,padName,text)</div>
<div class="define">createAuthor(name)</div>