Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Apr 2014 11:57:12 +0000 (UTC)
From:      Dag-Erling Smørgrav <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r264595 - in user/des/fbp: lib/FBP/Controller root/poll
Message-ID:  <201404171157.s3HBvCXv015004@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: des
Date: Thu Apr 17 11:57:11 2014
New Revision: 264595
URL: http://svnweb.freebsd.org/changeset/base/264595

Log:
  Add a result page.

Added:
  user/des/fbp/root/poll/result.tt   (contents, props changed)
Modified:
  user/des/fbp/lib/FBP/Controller/Poll.pm

Modified: user/des/fbp/lib/FBP/Controller/Poll.pm
==============================================================================
--- user/des/fbp/lib/FBP/Controller/Poll.pm	Thu Apr 17 11:56:38 2014	(r264594)
+++ user/des/fbp/lib/FBP/Controller/Poll.pm	Thu Apr 17 11:57:11 2014	(r264595)
@@ -232,6 +232,29 @@ sub done :Chained('poll') :Path :Args(0)
     delete($c->session->{$pid});
 }
 
+=head2 result
+
+Show results.
+
+=cut
+
+sub result :Chained('poll') :Path :Args(0) {
+    my ($self, $c) = @_;
+
+    my $poll = $c->stash->{poll};
+    $c->detach('/default')
+	unless ($c->user->admin || $poll->ended);
+    my $questions = $poll->questions;
+    foreach my $question ($questions->all) {
+	$c->log->debug("Question " . $question->id);
+	my $options = $question->options;
+	foreach my $option ($options->all) {
+	    $c->log->debug("Option " . $option->id . ": " . $option->label);
+	    $c->log->debug("Votes: " . $option->votes->count);
+	}
+    }
+}
+
 =head2 default
 
 Default page.

Added: user/des/fbp/root/poll/result.tt
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/des/fbp/root/poll/result.tt	Thu Apr 17 11:57:11 2014	(r264595)
@@ -0,0 +1,45 @@
+[%-# $FreeBSD$ -%]
+[% USE WikiFormat %]
+[% PROCESS lib/html_top %]
+[% PROCESS lib/header %]
+[% WRAPPER lib/main %]
+
+<div class="result">
+<div class="wiki synopsis">
+[% poll.synopsis | wiki %]
+</div>
+[% IF error %]
+<div class="error">
+<p>[% error | html %]</p>
+</div>
+[% ELSIF now < poll.starts %]
+<p>This poll has not started yet.</p>
+[% ELSIF poll.votes_rs.count == 0 %]
+<p>No votes have been cast yet.</p>
+[% ELSE %]
+<p>Here are the[% IF now < poll.ends %] preliminary[% END %] results of the poll:</p>
+[% FOREACH question IN poll.questions %]
+[% qid = question.id %]
+<div class="short">
+[% question.short | wiki %]
+</div>
+<table>
+<tr>
+<th>Option</th>
+<th>Votes</th>
+<th>Percentage</th>
+</tr>
+[% FOREACH option IN question.options %]
+<td>[% option.label | html %]</td>
+<td>[% IF option.votes_rs.count > 0 %][% option.votes_rs.count %][% ELSE %]-[% END %]</td>
+<td>[% IF option.votes_rs.count > 0 && question.votes_rs.count > 0 %][% option.votes_rs.count * 100 / question.votes_rs.count %]%[% ELSE %]-[% END %]</td>
+</tr>
+[% END %]
+</table>
+[% END %]
+[% END %]
+</div>
+
+[% END %]
+[% PROCESS lib/footer %]
+[% PROCESS lib/html_bottom %]



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201404171157.s3HBvCXv015004>