From 7ec4100f0f41dfa9d2880f32508e4e011308cd25 Mon Sep 17 00:00:00 2001 From: aritas1 Date: Tue, 14 Feb 2012 02:51:13 +0400 Subject: [PATCH 01/10] add listGroups to API fix wrong link in tests.html --- node/db/API.js | 1 + node/db/GroupManager.js | 37 +++++++++++++++++++++++++++++++++++++ node/handler/APIHandler.js | 1 + static/tests.html | 3 ++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/node/db/API.js b/node/db/API.js index 09cc95afc..c3bea2723 100644 --- a/node/db/API.js +++ b/node/db/API.js @@ -35,6 +35,7 @@ var cleanText = require("./Pad").cleanText; /**GROUP FUNCTIONS*****/ /**********************/ +exports.listGroups = groupManager.listGroups; exports.createGroup = groupManager.createGroup; exports.createGroupIfNotExistsFor = groupManager.createGroupIfNotExistsFor; exports.deleteGroup = groupManager.deleteGroup; diff --git a/node/db/GroupManager.js b/node/db/GroupManager.js index 7e3b7d6d1..d6f9717b4 100644 --- a/node/db/GroupManager.js +++ b/node/db/GroupManager.js @@ -111,6 +111,16 @@ exports.deleteGroup = function(groupID, callback) callback(); }); } + +exports.listGroups = function(callback) +{ + //try to get the groups entry + db.get("groups", function (err, groups) + { + if(ERR(err, callback)) return; + callback(null, groups); + }); +} exports.doesGroupExist = function(groupID, callback) { @@ -124,9 +134,36 @@ exports.doesGroupExist = function(groupID, callback) exports.createGroup = function(callback) { + // load all existing groups from db + existingGroups = []; + + exports.listGroups(function(err, responseGroups) + { + if(ERR(err, callback)) return; + if(responseGroups != undefined) + { + for(var key in responseGroups['groups']) + { + existingGroups.push(responseGroups['groups'][key]); + } + } + }); + //search for non existing groupID var groupID = "g." + randomString(16); + // check if group already exisits + exports.doesGroupExist(groupID, function(err, groupExist) + { + if(groupExist) return; + }); + + // add the new group to the array + existingGroups.push(groupID); + + // update the entry to the db, which hold all groups + db.set("groups", {groups: existingGroups}); + //create the group db.set("group:" + groupID, {pads: {}}); callback(null, {groupID: groupID}); diff --git a/node/handler/APIHandler.js b/node/handler/APIHandler.js index ca45e1f8f..1a25b989c 100644 --- a/node/handler/APIHandler.js +++ b/node/handler/APIHandler.js @@ -38,6 +38,7 @@ catch(e) //a list of all functions var functions = { + "listGroups" : [], "createGroup" : [], "createGroupIfNotExistsFor" : ["groupMapper"], "deleteGroup" : ["groupID"], diff --git a/static/tests.html b/static/tests.html index bd5bc578f..f1f47b38d 100644 --- a/static/tests.html +++ b/static/tests.html @@ -3,7 +3,7 @@ API Test and Examples Page - +