[guadec-web-regcfp/develop] Allow accepting
- From: Patrick Uiterwijk <puiterwijk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [guadec-web-regcfp/develop] Allow accepting
- Date: Fri, 22 May 2015 09:17:46 +0000 (UTC)
commit 38be244233330c9e27d3466c4b63df1446c45aea
Author: Patrick Uiterwijk <puiterwijk redhat com>
Date: Fri May 22 11:17:21 2015 +0200
Allow accepting
config/config.json.example | 3 +-
routes/papers.js | 76 ++++++++++++++++++++++++++++++++++++++++
views/index/index.hbs | 3 ++
views/papers/accept_submit.hbs | 2 +
views/papers/showvotes.hbs | 30 ++++++++++++++++
5 files changed, 113 insertions(+), 1 deletions(-)
---
diff --git a/config/config.json.example b/config/config.json.example
index b122e09..4373920 100644
--- a/config/config.json.example
+++ b/config/config.json.example
@@ -18,7 +18,8 @@
"all": ["puiterwijk fedoraproject org"]
},
"vote": ["puiterwijk fedoraproject org"],
- "seevotes": ["puiterwijk fedoraproject org"]
+ "showvotes": ["puiterwijk fedoraproject org"],
+ "accept": ["puiterwijk fedoraproject org"]
}
},
diff --git a/routes/papers.js b/routes/papers.js
index 6b5947c..d2027be 100644
--- a/routes/papers.js
+++ b/routes/papers.js
@@ -91,6 +91,82 @@ router.get('/admin/list', function(req, res, next) {
});
});
+router.all('/admin/vote/show', utils.require_user);
+router.all('/admin/vote/show', utils.require_permission('papers/showvotes'));
+router.get('/admin/vote/show', function(req, res, next) {
+ Paper.findAll({include: [User, PaperVote]})
+ .complete(function(err, papers) {
+ paper_info = [];
+ for(paper in papers) {
+ paper = papers[paper];
+ ppr = {
+ id: paper.id,
+ title: paper.title,
+ summary: paper.summary,
+ User: paper.User,
+ accepted: paper.accepted,
+ vote_count: 0,
+ vote_total: 0,
+ votes: []
+ };
+ for(vote in paper.PaperVotes) {
+ vote = paper.PaperVotes[vote];
+ if(!vote.abstained) {
+ ppr.vote_count++;
+ ppr.vote_total += vote.vote;
+ }
+ ppr.votes.push({
+ user: vote.UserId,
+ vote: vote.vote,
+ comment: vote.comment,
+ abstained: vote.abstained
+ });
+ }
+ ppr.vote_average = (ppr.vote_total / ppr.vote_count);
+ paper_info.push(ppr);
+ }
+ paper_info = paper_info.sort(function(a, b) {
+ return b.vote_average - a.vote_average;
+ });
+ res.render('papers/showvotes', { papers: paper_info });
+ });
+});
+
+function save_accepts(keys, errors, req, res, next) {
+ if(keys.length == 0) {
+ res.render('papers/accept_submit', { errors: errors });
+ } else {
+ var key = keys[0];
+ keys = keys.slice(1);
+ if(key.substring(0, 7) == 'accept_') {
+ var id = key.substring(7);
+ console.log('Id: ' + id);
+ var accepted = req.body[key];
+ console.log('Accepted: ' + accepted);
+ Paper.findOne({where: {
+ id: id
+ }}).then(function(paper) {
+ if(accepted == 'no') {
+ paper.accepted = false;
+ } else {
+ paper.accepted = true;
+ }
+ paper.save().complete(function(err, paper) {
+ if(!!err) {
+ errors.push({id: id, err: err});
+ }
+ save_accepts(keys, errors, req, res, next);
+ });
+ });
+ }
+ }
+};
+
+router.post('/admin/vote/show', utils.require_permission('papers/accept'));
+router.post('/admin/vote/show', function(req, res, next) {
+ save_accepts(Object.keys(req.body), [], req, res, next);
+});
+
router.all('/admin/vote', utils.require_user);
router.all('/admin/vote', utils.require_permission('papers/vote'));
router.get('/admin/vote', function(req, res, next) {
diff --git a/views/index/index.hbs b/views/index/index.hbs
index 7247e46..e29a222 100644
--- a/views/index/index.hbs
+++ b/views/index/index.hbs
@@ -44,6 +44,9 @@ Hello, please login, or choose an option below.
{{#has_permission "papers/vote"}}
<div class="button"><a href="/papers/admin/vote">Vote on talks</a></div>
{{/has_permission}}
+{{#has_permission "papers/showvotes" }}
+<div class="button"><a href="/papers/admin/vote/show">Show talk votes</a></div>
+{{/has_permission}}
</div>
<h3>Registration</h3>
diff --git a/views/papers/accept_submit.hbs b/views/papers/accept_submit.hbs
new file mode 100644
index 0000000..b8e0738
--- /dev/null
+++ b/views/papers/accept_submit.hbs
@@ -0,0 +1,2 @@
+Acceptances saved.<br />
+Errors: {{errors}}
diff --git a/views/papers/showvotes.hbs b/views/papers/showvotes.hbs
new file mode 100644
index 0000000..f27d190
--- /dev/null
+++ b/views/papers/showvotes.hbs
@@ -0,0 +1,30 @@
+Vote on papers:
+
+<form action="/papers/admin/vote/show" method="POST">
+<table border="1">
+<tr><th>Title</th><th>Author</th><th>Vote average</th><th>Accepted</th></tr>
+ {{#each papers}}
+ <tr>
+ <th><span title="{{this.summary}}">{{ this.title }}</span></th>
+ <td>{{ this.User.name }}</td>
+ <td>{{ this.vote_average }} (num: {{this.vote_count}}, total: {{this.vote_total}})</td>
+ <td>
+ <input type="hidden" name="accept_{{this.id}}" value="no">
+ <input type="checkbox" name="accept_{{this.id}}" value="yes"
+ {{#if this.accepted}}
+ checked
+ {{/if}}
+ {{#has_permission "papers/accept"}}
+ {{else}}
+ disabled
+ {{/has_permission}}
+ >
+ </td>
+ </tr>
+ {{/each}}
+</table>
+
+{{#has_permission "papers/accept"}}
+<input type="submit" value="Submit">
+{{/has_permission}}
+</form>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]