Commit 9fac0280 authored by Stephane Glondu's avatar Stephane Glondu

Pretty-print result when the election is tallied

parent 0dd3fd20
......@@ -20,13 +20,14 @@
(**************************************************************************)
open Lwt
open Serializable_t
open Common
type election_state =
[ `Open
| `Closed
| `EncryptedTally of int * int * string
| `Tallied
| `Tallied of plaintext
]
let election_states = Ocsipersist.open_table "election_states"
......
......@@ -19,11 +19,13 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Serializable_t
type election_state =
[ `Open
| `Closed
| `EncryptedTally of int * int * string
| `Tallied
| `Tallied of plaintext
]
val get_election_state : string -> election_state Lwt.t
val set_election_state : string -> election_state -> unit Lwt.t
......
......@@ -1206,7 +1206,7 @@ let () =
~mode:Output (W.dir / string_of_election_file ESResult)
(fun oc -> Lwt_io.write_line oc (string_of_result W.G.write result))
in
lwt () = Web_persist.set_election_state uuid_s `Tallied in
lwt () = Web_persist.set_election_state uuid_s (`Tallied result.result) in
Eliom_service.preapply
election_admin (W.election.e_params.e_uuid, ()) |>
Redirection.send)
......
......@@ -667,7 +667,7 @@ let election_home w state () =
pcdata ".";
]
in
let state =
let state_ =
match state with
| `Closed ->
[
......@@ -688,7 +688,7 @@ let election_home w state () =
b [pcdata hash];
pcdata ".";
]
| `Tallied ->
| `Tallied _ ->
[
pcdata " ";
b [pcdata "This election has been tallied."];
......@@ -736,9 +736,7 @@ let election_home w state () =
];
]
] in
let content = [
p (voting_period @ state);
br ();
let go_to_the_booth =
div ~a:[a_style "text-align:center;"] [
div [
make_button
......@@ -751,7 +749,33 @@ let election_home w state () =
~service:(Eliom_service.preapply election_cast (params.e_uuid, ()))
[pcdata "submit a raw ballot"] ();
];
];
]
in
let middle =
match state with
| `Tallied result ->
let questions = Array.to_list W.election.e_params.e_questions in
ul (List.mapi (fun i x ->
let answers = Array.to_list x.q_answers in
let answers = List.mapi (fun j x ->
tr [td [pcdata x]; td [pcdata @@ string_of_int result.(i).(j)]]
) answers in
let answers =
match answers with
| [] -> pcdata ""
| x :: xs -> table x xs
in
li [
pcdata x.q_question;
answers;
]
) questions)
| _ -> go_to_the_booth
in
let content = [
p (voting_period @ state_);
br ();
middle;
br ();
ballots_link;
] in
......@@ -855,7 +879,7 @@ let election_admin w ~is_featured state () =
];
release_form;
]
| `Tallied ->
| `Tallied _ ->
return @@ div [
pcdata "This election has been tallied.";
]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment