Skip to content

Commit

Permalink
closes #63, closes #13, closes #36, closes #44 - several updates on i…
Browse files Browse the repository at this point in the history
…ssue, issue voting and power data, also issue times front-end validated only
  • Loading branch information
cristiandouce committed Dec 31, 2012
1 parent a7f6a68 commit 731415c
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 34 deletions.
30 changes: 27 additions & 3 deletions models/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ var mongoose = require('mongoose')
, ObjectId = Schema.ObjectId
, categories = Object.keys(require('../fixtures/categories'));

/*
* Length in miliseconds for
* Issue Stages times...
*/
var dayTime = 24*60*60*1000
, daysOfDiscussion = 7
, discussionTime = dayTime * daysOfDiscussion
, daysOpenForIdeas = 7
, openForIdeasTime = dayTime * daysOpenForIdeas
, daysOfVoting = 7
, votingTime = dayTime * daysOfVoting;

var IssueVoteOptionSchema = require('./issueVoteOption').schema;

/*
Expand All @@ -24,10 +36,22 @@ var IssueSchema = new Schema({
updatedAt: {type: Date, default: Date.now}
},

// comments?

createdAt: { type: Date, default: Date.now },
updatedAt: Date
updatedAt: Date,

discussionEndDate: { type: Date, default: function() {
return Date.now() + discussionTime;
}},

openForIdeasEndDate: { type: Date, default: function() {
return Date.now() + openForIdeasTime + discussionTime;
}},

votingEndDate: { type: Date, default: function() {
return Date.now() + votingTime + openForIdeasTime + discussionTime;
}},


});

IssueSchema.path('title').validate(function(value) {
Expand Down
11 changes: 9 additions & 2 deletions routes/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,27 @@ module.exports = function(app, utils) {
Issue
.findById(req.params.id)
.populate('author')
.populate('census')
.populate('vote.choices.idea')
.populate('vote.choices.author')
.populate('vote.choices.sponsor')
.populate('vote.voters')
.exec(function(err, issue) {
if(err) console.log(err);
if(!issue) return res.redirect('/');
issue.loadComments(function(err, comments) {
if(req.user) {
Delegation
.findOne({truster: req.user.id, category: issue.category})
.findOne({ truster: req.user.id, category: issue.category })
// .select('trustees')
.populate('trustees')
.exec(function(err, delegation) {
res.render('issue', {page: 'idea', issue: issue, author: issue.author, comments: comments, delegation: delegation});
Delegation
.find({ trustees: req.user.id, category: issue.category })
.populate('truster')
.exec(function(err, delegations) {
res.render('issue', { page: 'idea', issue: issue, author: issue.author, comments: comments, delegation: delegation, delegations: delegations });
});
});
} else {
res.render('issue', {page: 'idea', issue: issue, author: issue.author, comments: comments, delegation: {}});
Expand Down
4 changes: 3 additions & 1 deletion strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ module.exports = function(app) {
});

passport.deserializeUser(function(citizenId, done) {
Citizen.findById(citizenId, function(err, citizen) {
Citizen
.findById(citizenId)
.exec(function(err, citizen) {
done(null, citizen);
});
});
Expand Down
5 changes: 2 additions & 3 deletions views/element/delegation_form.jade
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@

form().form-delegation
- if(delegation.trustees && delegation.trustees.length) {
- var len = delegation.trustees.length - 1;
- var trustee = delegation.trustees[len];
- var trustee = delegation.trustees[delegation.trustees.length - 1];
h5
| Usted esta delegando su voto en
span.fullname #{trustee.fullName}
| (@
span.username #{trustee.username}
| )
img.profile-delegation(src="#{trustee.imageUrl}")
img.profile-delegation(src="#{trustee.imageUrlRSmall}")

p
a.delegate-button(href="#") Prefiero delegar mi voto en otra persona
Expand Down
27 changes: 27 additions & 0 deletions views/issue-citizen-info.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//- @param issue
//- @param citizen
//- @param delegation
//- @param delegations
h3.block-title
i.icon
span Delegaciones
.box-content
- if(typeof(delegation) !== 'undefined' && delegation) {
- var trustee = delegation.trustees[0];
h5 Mi delegado en
a(href="#")= categories[issue.category].name

//- Citizen delegation in category
a(href="/profiles/#{trustee.id}", rel="tooltip", title="#{trustee.fullName}", data-placement="bottom", class="tt")
img(src="#{trustee.imageUrlMini}")

- }

- if(typeof(delegations) !== 'undefined' && delegations.length) {
h5 Ciudadanos delegando en mi
- delegations.forEach(function(d) {
a(href="/profiles/#{trustee.id}", rel="tooltip", title="#{trustee.fullName}", data-placement="bottom", class="tt")
img(src="#{trustee.imageUrlMini}")
- })
- }
14 changes: 14 additions & 0 deletions views/issue-info.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//- @param issue
//- @param citizen
h3.block-title
i.icon
span Información
.box-content
h6 Ciudadanos activos en esta problemática
- if(issue.census.length) {
- issue.census.forEach(function(activeCitizen) {
a(href="/profiles/#{activeCitizen.id}", rel="tooltip", title="#{activeCitizen.fullName}", data-placement="bottom", class="tt")
img(src="#{activeCitizen.imageUrlMini}")
- })
-}
98 changes: 73 additions & 25 deletions views/issue.jade
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,29 @@ block content
a(href="")= categories[element.category].name
h2= element.title
.issue-content-description!= md(element.essay)

//
#issue-full.modal(role="dialog", style="display:none;")
.modal-header
a.close(type="button", data-dismiss="modal", aria-hidden="true") ×
h2= element.title
.modal-body
p.issue-content-description!= md(element.essay)
p
a(data-toggle="modal", role="button", href="#issue-full").full-read Leer Completo

.block-info.span9.box.clearfix
include issue-info

- if(typeof(citizen) != 'undefined') {
.block-citizen-info.span9.box.clearfix
include issue-citizen-info
- }

.block-ideas.box.clearfix
- if(typeof(citizen) != 'undefined' && element.vote.voters.indexOf(citizen.id) >=0 ) {
- var voted = true;
- if(typeof(citizen) != 'undefined') {
- var voted = false;
- element.vote.voters.some(function(v) {
- if(v.id == citizen.id) {
- voted = true;
- };
- return voted;
- })
- };
- if(!voted) {

- if( (Date.now() > element.discussionEndDate) && (Date.now() < element.votingEndDate) ) {
.span9
//- Change delegation
- if(typeof(citizen) != 'undefined') {
a.delegate(data-toggle="modal", role="button", href="#delegation")
| Prefiero delegar mi voto a otra persona
Expand All @@ -56,25 +62,67 @@ block content
a.total-comments(data-toggle="modal", role="button", href="#choice-full-#{choice.id}")
i
| 23
- if(!voted) {
- if(!voted && (Date.now() > element.openForIdeasEndDate) ) {
a.vote(href="#") Votar
- };
- });
.span3
a.create-idea.vote-option(data-toggle="modal", role="button", href='#compose-initiative', data-backdrop="false", data-keyboard="false", rel="tooltip", title="Redactar una iniciativa", data-placement="bottom")
i +
span Crear Propuesta
- } else {

- if( Date.now() < element.openForIdeasEndDate ) {
.span3
a.create-idea.vote-option(data-toggle="modal", role="button", href='#compose-initiative', data-backdrop="false", data-keyboard="false", rel="tooltip", title="Redactar una iniciativa", data-placement="bottom")
i +
span Crear Propuesta
- };

- }

//- Preliminar results
- if( voted && (Date.now() < element.votingEndDate) ) {
.span9.box.block-results
h3.block-title
i.icon
span Resultados preliminares
- var totalVoters = element.vote.voters.length;
- var voters = totalVoters == 1 ? "Votó $n ciudadano" : "Votaron $n ciudadanos"
h4
| #{voters.replace('$n',totalVoters)}

.box-content.clearfix
h4
| Hay
span.number= element.vote.voters.length
| votos contados
- element.vote.voters.forEach(function(voter) {
a(href="/profiles/#{voter.id}", rel="tooltip", title="#{voter.fullName}", data-placement="bottom", class="tt")
img(src="#{voter.imageUrlMini}")
- });

h4
span.number= element.vote.voters.length
| votos por delegados
- element.vote.voters.forEach(function(voter) {
a(href="/profiles/#{voter.id}", rel="tooltip", title="#{voter.fullName}", data-placement="bottom", class="tt")
img(src="#{voter.imageUrlMini}")
- })

h4
| y
span.number= element.vote.voters.length
| votos unipersonales
- element.vote.voters.forEach(function(voter) {
a(href="/profiles/#{voter.id}", rel="tooltip", title="#{voter.fullName}", data-placement="bottom", class="tt")
img(src="#{voter.imageUrlMini}")
- })
- }

//- Final results
- if(Date.now() > element.votingEndDate) {
.span9.box.block-results
h3.block-title
i.icon
span Resultados final
- var totalVoters = element.vote.voters.length;
.box-content.clearfix
h4
span.number= element.vote.voters.length
| votos contados

- element.vote.choices.forEach(function(choice) {
.partial(style="width:100%;float:left;")
- var partial = choice.result / (totalVoters || 1) * 100;
Expand All @@ -83,7 +131,7 @@ block content
a(data-toggle="modal", role="button", href="#choice-full-#{choice.id}")
| Leer...
.bar(style="width:#{partial.toFixed(0)}%;")
span
span.tt(rel="tooltip", data-placement="top", title="#{choice.result} votos")
| #{partial.toFixed(0)} %
- });
- };
Expand Down

0 comments on commit 731415c

Please sign in to comment.