Permalink
Browse files

merged

  • Loading branch information...
2 parents 2c23a3c + 3666536 commit 19a6c0abd1597175b6679ecf7342a0d7a9021e63 @pinguxx pinguxx committed Jan 24, 2012
Showing with 165 additions and 70 deletions.
  1. +0 −11 README
  2. +32 −0 README.md
  3. +71 −6 controllers/nominator.js
  4. +11 −7 logs/dev.log
  5. +1 −1 models/nomination.js
  6. +50 −45 routes/dashboard.js
View
11 README
@@ -1,11 +0,0 @@
-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/
-la pagina esta aqui:
-http://nomination.cloudno.de
-La pagina de facebook aqui:
-https://www.facebook.com/pages/Nomi-nation/354591181220133
-Codigo abierto, ayudanos a resolver los issues abiertos, propon nueva funcionalidad
-Pequeño manual para usar la aplicacion:
-https://github.com/nodejs-mexico/nomi-nation/wiki
View
@@ -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
View
@@ -28,24 +28,88 @@ function findIndexByKeyValue(obj, key, value)
* @userId string
* @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) {
//TODO: check we dont want more than 10 users per nomination
var isPresent = -1;
+ var oldEnough = true;
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){
isPresent = -1;
}
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: push to voters
- var index = findIndexByKeyValue(nomination.users, "_id", userId);
- nomination.users[index].votes += 1;
- nomination.save(callback);
- //Nomination.update({_id :nomination.id}, {users: nomination.users}, callback);
+ if (oldEnough){
+ var index = findIndexByKeyValue(nomination.users, "_id", userId);
+ nomination.users[index].votes += 1;
+ nomination.save(callback);
+ //Nomination.update({_id :nomination.id}, {users: nomination.users}, callback);
+ } else {
+ callback(new Error('No Old Enough'),null);
+ }
};
/**
@@ -88,6 +152,7 @@ NOMINATOR.eraseUser = function(nomination, user, callback) {
* @callback function
*/
NOMINATOR.createNomination = function(nomination, callback) {
+ nomination.votersDate = {}
var myNomination = new Nomination(nomination);
myNomination.save(callback);
};
View
@@ -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)
-[Thu, 19 Jan 2012 01:13:41 GMT] NOTICE trying to login:Thu Jan 19 2012 01:13:41 GMT+0000 (GMT)
-[Thu, 19 Jan 2012 01:13:42 GMT] NOTICE response from fb: Thu Jan 19 2012 01:13:42 GMT+0000 (GMT)
-[Thu, 19 Jan 2012 01:13:43 GMT] NOTICE trying to get the tokens:Thu Jan 19 2012 01:13:43 GMT+0000 (GMT)
-[Thu, 19 Jan 2012 01:13:43 GMT] NOTICE getting info from user:1239274592
-[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)
-[Thu, 19 Jan 2012 01:13:44 GMT] NOTICE getting friends from user:1239274592
+[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)
+[Sun, 22 Jan 2012 03:42:48 GMT] ERROR Error: Error: nli
+[Sun, 22 Jan 2012 03:42:48 GMT] NOTICE landed on:Sat Jan 21 2012 21:42:48 GMT-0600 (CST)
+[Sun, 22 Jan 2012 03:42:50 GMT] NOTICE trying to login:Sat Jan 21 2012 21:42:50 GMT-0600 (CST)
+[Sun, 22 Jan 2012 03:42:54 GMT] NOTICE response from fb: Sat Jan 21 2012 21:42:54 GMT-0600 (CST)
+[Sun, 22 Jan 2012 03:42:56 GMT] NOTICE trying to get the tokens:Sat Jan 21 2012 21:42:56 GMT-0600 (CST)
+[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
View
@@ -24,7 +24,7 @@ function defineModels(mongoose, fn) {
'owner' : String, //who is the owner of the nomination
'endDate' : Date, //when this nomination is going to end
'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,
'sub_cat' : String,
'active' : Boolean, //nomination finished
View
@@ -323,76 +323,81 @@ module.exports = function(app, log){
var id = req.param('id');
nominator.findNomination(id,function(err, doc){
if (err) { log.debug('error getting nominations:' + err); res.json(null); return; }
+ console.log(doc);
var users = doc.users;
var usersl = doc.users.length;
var voters = doc.voters;
var votersl = doc.voters.length;
- var winner = users[0];
- 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);
+ console.log(users.length)
+ if (users.length > 0){
+ var winner = users[0];
+ for (var j=1; j<usersl;j++){
+ if (winner.votes < users[j].votes){
+ winner = users[j];
+ }
}
- );
- for (var i=0;i<usersl;i++){
- if (users[i]._id == req.session.user.id){ continue; }
+ res.json(winner);
fb.apiCall(
'POST',
- '/'+users[i]._id+'/feed',
+ '/'+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
+ 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 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){
if (err) { log.debug('error erasing nomination'); return; }
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){
if (err) { log.debug('error erasing nomination'); return; }
log.notice('nomination '+ req.param('name') +' erased by: ' + req.session.user.id );
});
+ try { res.json('_winner_');} catch(e){}
});
});

0 comments on commit 19a6c0a

Please sign in to comment.