forked from aliasaria/scrumblr
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this is ddunlops work to abstract data layer and allow for mongodb thanks ddunlop Conflicts: .gitignore server.js
- Loading branch information
Showing
6 changed files
with
489 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.DS_Store | ||
rsync.sh | ||
*.swp | ||
*.log | ||
.monitor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/*exports.database = { | ||
type: 'mongodb', | ||
hostname: 'localhost', | ||
port: 27017, | ||
database: 'scrumblr' | ||
}; | ||
*/ | ||
|
||
exports.database = { | ||
type: 'redis', | ||
prefix: '#scrumblr#' | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var conf = require('../config.js').database; | ||
|
||
exports.db = require('./data/'+conf.type+'.js').db; | ||
|
||
/* | ||
var db = function(callback) { } | ||
db.prototype = { | ||
clearRoom: function(room, callback) { }, | ||
// theme commands | ||
setTheme: function(room, theme) { }, | ||
getTheme: function(room, callback) { }, | ||
// Column commands | ||
createColumn: function(room, name, callback) { }, | ||
getAllColumns: function(room, callback) { }, | ||
deleteColumn: function(room) { }, | ||
setColumns: function(room, columns) { }, | ||
// Card commands | ||
createCard: function(room, id, card) { }, | ||
getAllCards: function(room, callback) { }, | ||
cardEdit: function(room, id, text) { }, | ||
cardSetXY: function(room, id, x, y) { }, | ||
deleteCard: function(room, id) { }, | ||
addSticker: function(room, cardId, stickerId) { } | ||
}; | ||
exports.db = db; | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
var Db = require('mongodb').Db; | ||
Server = require('mongodb').Server, | ||
BSON = require('mongodb').BSONNative, | ||
conf = require('../../config.js').database; | ||
|
||
var db = function(callback) | ||
{ | ||
this.rooms = false; | ||
var t = this; | ||
|
||
var db = new Db(conf.database, new Server(conf.hostname, conf.port), {native_parser:true}); | ||
db.open(function(err, db) { | ||
db.collection('rooms', function(err, collection) { | ||
// make sure we have an index on name | ||
collection.ensureIndex([['name',1]],false,function() {}); | ||
t.rooms = collection; | ||
}); | ||
callback(); | ||
}); | ||
} | ||
|
||
db.prototype = { | ||
clearRoom: function(room, callback) | ||
{ | ||
this.rooms.remove({name:room},callback); | ||
}, | ||
|
||
// theme commands | ||
setTheme: function(room, theme) | ||
{ | ||
this.rooms.update( | ||
{name:room}, | ||
{$set:{theme:theme}} | ||
); | ||
}, | ||
|
||
getTheme: function(room, callback) | ||
{ | ||
this.rooms.findOne( | ||
{name:room}, | ||
{theme:true}, | ||
function(err, room) { | ||
if(room) { | ||
callback(room.theme); | ||
} else { | ||
callback(); | ||
} | ||
} | ||
); | ||
}, | ||
|
||
// Column commands | ||
createColumn: function(room, name, callback) | ||
{ | ||
this.rooms.update( | ||
{name:room}, | ||
{$push:{columns:name}}, | ||
{upsert:true} | ||
,callback | ||
); | ||
}, | ||
|
||
getAllColumns: function(room, callback) | ||
{ | ||
this.rooms.findOne({name:room},{columns:true},function(err, room) { | ||
if(room) { | ||
callback(room.columns); | ||
} else { | ||
callback(); | ||
} | ||
}); | ||
}, | ||
|
||
deleteColumn: function(room) | ||
{ | ||
this.rooms.update( | ||
{name:room}, | ||
{$pop:{columns:1}} | ||
); | ||
}, | ||
|
||
setColumns: function(room, columns) | ||
{ | ||
this.rooms.update( | ||
{name:room}, | ||
{$set:{columns:columns}}, | ||
{upsert:true} | ||
); | ||
}, | ||
|
||
// Card commands | ||
createCard: function(room, id, card) | ||
{ | ||
var doc = {}; | ||
doc['cards.'+id] = card; | ||
this.rooms.update( | ||
{name:room}, | ||
{$set:doc}, | ||
{upsert:true} | ||
); | ||
}, | ||
|
||
getAllCards: function(room, callback) | ||
{ | ||
this.rooms.findOne({name:room},{cards:true},function(err, room) { | ||
if(room) { | ||
callback(room.cards); | ||
} else { | ||
callback(); | ||
} | ||
}); | ||
}, | ||
|
||
cardEdit: function(room, id, text) | ||
{ | ||
var doc = {}; | ||
doc['cards.'+id+'.text'] = text; | ||
this.rooms.update( | ||
{name:room}, | ||
{$set:doc} | ||
); | ||
}, | ||
|
||
cardSetXY: function(room, id, x, y) | ||
{ | ||
var doc = {}; | ||
doc['cards.'+id+'.x'] = x; | ||
doc['cards.'+id+'.y'] = y; | ||
this.rooms.update( | ||
{name:room}, | ||
{$set:doc} | ||
); | ||
}, | ||
|
||
deleteCard: function(room, id) | ||
{ | ||
var doc = {}; | ||
doc['cards.'+id] = true; | ||
this.rooms.update( | ||
{name:room}, | ||
{$unset:doc} | ||
); | ||
}, | ||
|
||
addSticker: function(room, cardId, stickerId) | ||
{ | ||
var doc = {}; | ||
doc['cards.'+cardId+'.sticker'] = stickerId; | ||
this.rooms.update( | ||
{name:room}, | ||
{$set:doc} | ||
); | ||
} | ||
}; | ||
exports.db = db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
//var conf = require('../../config.js').database; | ||
|
||
var redis = require("redis"), | ||
redisClient = null; //redis.createClient(); | ||
|
||
var async = require("async"); | ||
|
||
// If you want Memory Store instead... | ||
// var MemoryStore = require('connect/middleware/session/memory'); | ||
// var session_store = new MemoryStore(); | ||
|
||
var RedisStore = require('connect-redis'); | ||
var session_store = new RedisStore( ); | ||
|
||
var REDIS_PREFIX = '#scrumblr#'; | ||
|
||
//For Redis Debugging | ||
|
||
|
||
var db = function(callback) { | ||
redisClient = redis.createClient(); | ||
redisClient.on("connect", function (err) { | ||
callback(); | ||
}); | ||
|
||
redisClient.on("error", function (err) { | ||
console.log("Redis error: " + err); | ||
}); | ||
|
||
} | ||
|
||
db.prototype = { | ||
clearRoom: function(room, callback) { | ||
redisClient.del(REDIS_PREFIX + '-room:/demo-cards', function (err, res) { | ||
redisClient.del(REDIS_PREFIX + '-room:/demo-columns', function (err, res) { | ||
callback(); | ||
}); | ||
}); | ||
}, | ||
|
||
// theme commands | ||
setTheme: function(room, theme) { | ||
redisClient.set(REDIS_PREFIX + '-room:' + room + '-theme', theme); | ||
}, | ||
|
||
getTheme: function(room, callback) { | ||
redisClient.get(REDIS_PREFIX + '-room:' + room + '-theme', function (err, res) { | ||
callback(res); | ||
}); | ||
}, | ||
|
||
// Column commands | ||
createColumn: function(room, name, callback) { | ||
redisClient.rpush(REDIS_PREFIX + '-room:' + room + '-columns', name, | ||
function (err, res) { | ||
if (typeof callback != "undefined" && callback !== null) callback(); | ||
} | ||
); | ||
}, | ||
|
||
getAllColumns: function(room, callback) { | ||
redisClient.lrange(REDIS_PREFIX + '-room:' + room + '-columns', 0, -1, function(err, res) { | ||
callback(res); | ||
}); | ||
}, | ||
|
||
deleteColumn: function(room) { | ||
redisClient.rpop(REDIS_PREFIX + '-room:' + room + '-columns'); | ||
}, | ||
|
||
setColumns: function(room, columns) { | ||
//1. first delete all columns | ||
redisClient.del(REDIS_PREFIX + '-room:' + room + '-columns', function () { | ||
//2. now add columns for each thingy | ||
async.forEachSeries( | ||
columns, | ||
function( item, callback ) { | ||
//console.log('rpush: ' + REDIS_PREFIX + '-room:' + room + '-columns' + ' -- ' + item); | ||
redisClient.rpush(REDIS_PREFIX + '-room:' + room + '-columns', item, | ||
function (err, res) { | ||
callback(); | ||
} | ||
); | ||
}, | ||
function() { | ||
//this happens when the series is complete | ||
} | ||
); | ||
}); | ||
}, | ||
|
||
// Card commands | ||
createCard: function(room, id, card) { | ||
var cardString = JSON.stringify(card); | ||
redisClient.hset( | ||
REDIS_PREFIX + '-room:' + room + '-cards', | ||
id, | ||
cardString | ||
); | ||
}, | ||
|
||
getAllCards: function(room, callback) { | ||
redisClient.hgetall(REDIS_PREFIX + '-room:' + room + '-cards', function (err, res) { | ||
|
||
var cards = []; | ||
|
||
for (i in res) { | ||
cards.push( JSON.parse(res[i]) ); | ||
} | ||
console.dir(cards); | ||
|
||
callback(cards); | ||
}); | ||
}, | ||
|
||
cardEdit: function(room, id, text) { | ||
redisClient.hget(REDIS_PREFIX + '-room:' + room + '-cards', id, function(err, res) { | ||
var card = JSON.parse(res); | ||
if (card !== null) { | ||
card.text = text; | ||
redisClient.hset(REDIS_PREFIX + '-room:' + room + '-cards', id, JSON.stringify(card)); | ||
} | ||
}); | ||
}, | ||
|
||
cardSetXY: function(room, id, x, y) { | ||
redisClient.hget(REDIS_PREFIX + '-room:' + room + '-cards', id, function(err, res) { | ||
var card = JSON.parse(res); | ||
if (card !== null) { | ||
card.x = x; | ||
card.y = y; | ||
redisClient.hset(REDIS_PREFIX + '-room:' + room + '-cards', id, JSON.stringify(card)); | ||
} | ||
}); | ||
}, | ||
|
||
deleteCard: function(room, id) { | ||
redisClient.hdel( | ||
REDIS_PREFIX + '-room:' + room + '-cards', | ||
id | ||
); | ||
}, | ||
|
||
addSticker: function(room, cardId, stickerId) { | ||
redisClient.hget(REDIS_PREFIX + '-room:' + room + '-cards', cardId, function(err, res) { | ||
var card = JSON.parse(res); | ||
if (card !== null) { | ||
card.sticker = stickerId; | ||
redisClient.hset(REDIS_PREFIX + '-room:' + room + '-cards', cardId, JSON.stringify(card)); | ||
} | ||
}); | ||
} | ||
}; | ||
exports.db = db; |
Oops, something went wrong.