Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguxx committed Jan 24, 2012
2 parents 2c23a3c + 3666536 commit 19a6c0a
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 70 deletions.
11 changes: 0 additions & 11 deletions README

This file was deleted.

32 changes: 32 additions & 0 deletions README.md
@@ -0,0 +1,32 @@
# Nomi-nation

Aplicacion basada en facebook para que puedas nominar a tus amigos en cualquier tipo de nominacion que se te ocurra, para ver como se hizo sigue este url:

[http://ipseitycloud.com/wordpress/](http://ipseitycloud.com/wordpress/)

Un ejemplo esta funcionando en la siguiente página:

[http://nomination.cloudno.de](http://nomination.cloudno.de)

La página de facebook:

[https://www.facebook.com/pages/Nomi-nation/354591181220133](https://www.facebook.com/pages/Nomi-nation/354591181220133)


## Manual

Pequeño manual para usar la aplicacion:
[https://github.com/nodejs-mexico/nomi-nation/wiki](https://github.com/nodejs-mexico/nomi-nation/wiki)


## Instalación

Si quieres contribuir, asegurate de instalar `nomi-nation` localmente siguiente [estos pasos](https://github.com/nodejs-mexico/nomi-nation/wiki/Instalando-nomi-nation-Localmente)

**Nomi-nation es código abierto**, ayudanos a resolver los `issues` abiertos, propón nueva funcionalidad.

## Licence

Copyright (C) 2011 Ivan Torres -MrPix

See license
77 changes: 71 additions & 6 deletions controllers/nominator.js
Expand Up @@ -28,24 +28,88 @@ function findIndexByKeyValue(obj, key, value)
* @userId string * @userId string
* @callback function * @callback function
*/ */
function getDate (array, value) {
var resp = null;
array.forEach(function(m){
if (m[value] !== undefined){
resp = m[value];
}
});
return resp;
}
function presence (array, value) {
var resp = -1;
array.forEach(function(m){
if (m[value] !== undefined){
resp = array.indexOf(m);
}
});
return resp;
}
function prettyDate(a) {
/*
* prettyDate
* @parametros {a}
* @formato {'mm-dd-yyyy' + T + 'HH:MM:ss', tipo: 'isoDateTime'}
*/
var d = [
[60, "menos de un dia"],
[90, "menos de un dia"],
[3600, "menos de un dia", 60],
[5400, "menos de un dia"],
[86400, "menos de un dia", 3600],
[129600, "1 dia"],
[604800, "dias", 86400],
[907200, "1 semana"],
[2628E3, "semanas", 604800],
[3942E3, "1 mes"],
[31536E3, "meses", 2628E3],
[47304E3, "1 año"],
[31536E5, "años", 31536E3],
[47304E5, "1 milenio"]
],
e = ("" + a).replace(/-/g, "/").replace(/[TZ]/g, " "),
n = new Date,
e = (n - new Date(e) + n.getTimezoneOffset() * 0) / 1E3,
n = "Hace ",
l = 0,
h;
e < 0 && (e = Math.abs(e), n = "");
for (; h = d[l++];) if (e < h[0]) return h.length == 2 ? (l > 1 ? n : "") + h[1] : (l > 1 ? n : "") + Math.round(e / h[2]) + " " + h[1];
if (e > 47304E5) return n + Math.round(e / 47304E5) + " Milenios";
return a
}
NOMINATOR.vote = function(nomination, voterId, userId, callback) { NOMINATOR.vote = function(nomination, voterId, userId, callback) {
//TODO: check we dont want more than 10 users per nomination //TODO: check we dont want more than 10 users per nomination
var isPresent = -1; var isPresent = -1;
var oldEnough = true;
try { try {
isPresent = nomination.voters.indexOf(voterId); isPresent = presence(nomination.voters, voterId);
if (isPresent !== -1) {
oldDate = prettyDate(getDate(nomination.voters, voterId).toISOString()),
if (oldDate.search('menos de un dia') !== -1){
oldEnough = false;
}
}
} }
catch (e){ catch (e){
isPresent = -1; isPresent = -1;
} }
if (isPresent < 0){ if (isPresent < 0){
nomination.voters.push(voterId); var toSave = {};
toSave[voterId] = new Date;
nomination.voters.push(toSave);
} }
//TODO: change to an actual mongo function //TODO: change to an actual mongo function
//TODO: push to voters //TODO: push to voters
var index = findIndexByKeyValue(nomination.users, "_id", userId); if (oldEnough){
nomination.users[index].votes += 1; var index = findIndexByKeyValue(nomination.users, "_id", userId);
nomination.save(callback); nomination.users[index].votes += 1;
//Nomination.update({_id :nomination.id}, {users: nomination.users}, callback); nomination.save(callback);
//Nomination.update({_id :nomination.id}, {users: nomination.users}, callback);
} else {
callback(new Error('No Old Enough'),null);
}
}; };


/** /**
Expand Down Expand Up @@ -88,6 +152,7 @@ NOMINATOR.eraseUser = function(nomination, user, callback) {
* @callback function * @callback function
*/ */
NOMINATOR.createNomination = function(nomination, callback) { NOMINATOR.createNomination = function(nomination, callback) {
nomination.votersDate = {}
var myNomination = new Nomination(nomination); var myNomination = new Nomination(nomination);
myNomination.save(callback); myNomination.save(callback);
}; };
Expand Down
18 changes: 11 additions & 7 deletions logs/dev.log
@@ -1,7 +1,11 @@
[Thu, 19 Jan 2012 01:13:38 GMT] NOTICE landed on:Thu Jan 19 2012 01:13:38 GMT+0000 (GMT) [Sun, 22 Jan 2012 03:42:48 GMT] NOTICE someone try to go directly to dashboard on: Sat Jan 21 2012 21:42:48 GMT-0600 (CST)
[Thu, 19 Jan 2012 01:13:41 GMT] NOTICE trying to login:Thu Jan 19 2012 01:13:41 GMT+0000 (GMT) [Sun, 22 Jan 2012 03:42:48 GMT] ERROR Error: Error: nli
[Thu, 19 Jan 2012 01:13:42 GMT] NOTICE response from fb: Thu Jan 19 2012 01:13:42 GMT+0000 (GMT) [Sun, 22 Jan 2012 03:42:48 GMT] NOTICE landed on:Sat Jan 21 2012 21:42:48 GMT-0600 (CST)
[Thu, 19 Jan 2012 01:13:43 GMT] NOTICE trying to get the tokens:Thu Jan 19 2012 01:13:43 GMT+0000 (GMT) [Sun, 22 Jan 2012 03:42:50 GMT] NOTICE trying to login:Sat Jan 21 2012 21:42:50 GMT-0600 (CST)
[Thu, 19 Jan 2012 01:13:43 GMT] NOTICE getting info from user:1239274592 [Sun, 22 Jan 2012 03:42:54 GMT] NOTICE response from fb: Sat Jan 21 2012 21:42:54 GMT-0600 (CST)
[Thu, 19 Jan 2012 01:13:43 GMT] NOTICE landed on dashboard user: 1239274592 on: Thu Jan 19 2012 01:13:43 GMT+0000 (GMT) [Sun, 22 Jan 2012 03:42:56 GMT] NOTICE trying to get the tokens:Sat Jan 21 2012 21:42:56 GMT-0600 (CST)
[Thu, 19 Jan 2012 01:13:44 GMT] NOTICE getting friends from user:1239274592 [Sun, 22 Jan 2012 03:43:00 GMT] NOTICE getting info from user:100003382906409
[Sun, 22 Jan 2012 03:43:00 GMT] NOTICE landed on dashboard user: 100003382906409 on: Sat Jan 21 2012 21:43:00 GMT-0600 (CST)
[Sun, 22 Jan 2012 03:43:04 GMT] NOTICE getting friends from user:100003382906409
[Sun, 22 Jan 2012 03:43:08 GMT] DEBUG error getting nominations:Error: No Old Enough
[Sun, 22 Jan 2012 03:43:14 GMT] DEBUG error getting nominations:Error: No Old Enough
2 changes: 1 addition & 1 deletion models/nomination.js
Expand Up @@ -24,7 +24,7 @@ function defineModels(mongoose, fn) {
'owner' : String, //who is the owner of the nomination 'owner' : String, //who is the owner of the nomination
'endDate' : Date, //when this nomination is going to end 'endDate' : Date, //when this nomination is going to end
'users' : [User], //users added to this nomination 'users' : [User], //users added to this nomination
'voters' : [String], //all the dudes that vote this nomination 'voters':{type:Array, default:[]}, //all the dudes that vote this nomination
'category' : String, 'category' : String,
'sub_cat' : String, 'sub_cat' : String,
'active' : Boolean, //nomination finished 'active' : Boolean, //nomination finished
Expand Down
95 changes: 50 additions & 45 deletions routes/dashboard.js
Expand Up @@ -323,76 +323,81 @@ module.exports = function(app, log){
var id = req.param('id'); var id = req.param('id');
nominator.findNomination(id,function(err, doc){ nominator.findNomination(id,function(err, doc){
if (err) { log.debug('error getting nominations:' + err); res.json(null); return; } if (err) { log.debug('error getting nominations:' + err); res.json(null); return; }
console.log(doc);
var users = doc.users; var users = doc.users;
var usersl = doc.users.length; var usersl = doc.users.length;
var voters = doc.voters; var voters = doc.voters;
var votersl = doc.voters.length; var votersl = doc.voters.length;
var winner = users[0]; console.log(users.length)
for (var j=1; j<usersl;j++){ if (users.length > 0){
if (winner.votes < users[j].votes){ var winner = users[0];
winner = users[j]; for (var j=1; j<usersl;j++){
} if (winner.votes < users[j].votes){
} winner = users[j];
res.json(winner); }
fb.apiCall(
'POST',
'/'+req.session.user.id+'/feed',
{
access_token: req.session.user.access_token,
message: winner.name + ' gano "' + doc.name + '" en nomi-nation ' +
'crea tu propia nominacion',
name: "Crear",
link: url + '?invited=' + req.param('id')
},
function (error, response, body) {
if (error) { log.debug('error posting on voted user'); return; }
log.notice('posted on the created user wall: ' + req.session.user.id);
} }
); res.json(winner);
for (var i=0;i<usersl;i++){
if (users[i]._id == req.session.user.id){ continue; }
fb.apiCall( fb.apiCall(
'POST', 'POST',
'/'+users[i]._id+'/feed', '/'+req.session.user.id+'/feed',
{ {
access_token: req.session.user.access_token, access_token: req.session.user.access_token,
message: winner.name + ' gano "' + doc.name + '" en nomi-nation ' + message: winner.name + ' gano "' + doc.name + '" en nomi-nation ' +
'crea tu propia nominacion', 'crea tu propia nominacion',
name: "Crear", name: "Crear",
link: url link: url + '?invited=' + req.param('id')
}, },
function (error, response, body) { function (error, response, body) {
if (error) { log.debug('error posting on voted user'); return; } if (error) { log.debug('error posting on voted user'); return; }
log.notice('posted on the user wall: ' + users[i]._id); log.notice('posted on the created user wall: ' + req.session.user.id);
} }
); );
} for (var i=0;i<usersl;i++){
if (users[i]._id == req.session.user.id){ continue; }
fb.apiCall(
'POST',
'/'+users[i]._id+'/feed',
{
access_token: req.session.user.access_token,
message: winner.name + ' gano "' + doc.name + '" en nomi-nation ' +
'crea tu propia nominacion',
name: "Crear",
link: url
},
function (error, response, body) {
if (error) { log.debug('error posting on voted user'); return; }
log.notice('posted on the user wall: ' + (users[i]._id || 1));
}
);
}
for (var i=0;i<votersl;i++){
if (voters[i]._id == req.session.user.id){ continue; }
fb.apiCall(
'POST',
'/'+voters[i]._id+'/feed',
{
access_token: req.session.user.access_token,
message: winner.name + ' gano "' + doc.name + '" en nomi-nation ' +
'crea tu propia nominacion',
name: "Crear",
link: url
},
function (error, response, body) {
if (error) { log.debug('error posting on voted user'); return; }
log.notice('posted on the user wall: ' + (voters[i]._id || 0));
}
);
}
}
nominator.eraseNomination(id, function(err){ nominator.eraseNomination(id, function(err){
if (err) { log.debug('error erasing nomination'); return; } if (err) { log.debug('error erasing nomination'); return; }
log.notice('nomination '+ req.param('name') +' erased by: ' + req.session.user.id ); log.notice('nomination '+ req.param('name') +' erased by: ' + req.session.user.id );
}); });
for (var i=0;i<votersl;i++){
if (voters[i]._id == req.session.user.id){ continue; }
fb.apiCall(
'POST',
'/'+voters[i]._id+'/feed',
{
access_token: req.session.user.access_token,
message: winner.name + ' gano "' + doc.name + '" en nomi-nation ' +
'crea tu propia nominacion',
name: "Crear",
link: url
},
function (error, response, body) {
if (error) { log.debug('error posting on voted user'); return; }
log.notice('posted on the user wall: ' + voters[i]._id);
}
);
}
nominator.eraseNomination(id, function(err){ nominator.eraseNomination(id, function(err){
if (err) { log.debug('error erasing nomination'); return; } if (err) { log.debug('error erasing nomination'); return; }
log.notice('nomination '+ req.param('name') +' erased by: ' + req.session.user.id ); log.notice('nomination '+ req.param('name') +' erased by: ' + req.session.user.id );
}); });
try { res.json('_winner_');} catch(e){}
}); });
}); });


Expand Down

0 comments on commit 19a6c0a

Please sign in to comment.