Commit adb1d44a authored by Stephane Glondu's avatar Stephane Glondu

Print number of accepted ballots on the result page

parent 3b8c71f5
......@@ -28,6 +28,8 @@ open Serializable_builtin_j
open Serializable_t
open Web_serializable_t
let spool_dir = ref "."
let enforce_single_element s =
let open Lwt_stream in
lwt t = next s in
......
......@@ -23,6 +23,8 @@ open Serializable_builtin_t
open Serializable_t
open Web_serializable_t
val spool_dir : string ref
val make_rng : unit -> Platform.rng Lwt.t
(** Create a pseudo random number generator initialized by a 128-bit
secure random seed. *)
......
......@@ -113,7 +113,7 @@ let spool_dir =
(** Build up the site *)
let () = Web_site.source_file := source_file
let () = Web_site.spool_dir := spool_dir
let () = Web_common.spool_dir := spool_dir
let () = Web_site_auth.configure (List.rev !auth_instances)
lwt () =
......
......@@ -21,8 +21,9 @@
open Lwt
open Serializable_builtin_j
open Serializable_t
open Serializable_j
open Common
open Web_common
type election_state =
[ `Open
......@@ -68,3 +69,12 @@ let get_auth_config x =
let set_auth_config x c =
Ocsipersist.add auth_configs x c
let ( / ) = Filename.concat
let get_election_result uuid =
try_lwt
Lwt_io.chars_of_file (!spool_dir / uuid / "result.json") |>
Lwt_stream.to_string >>= fun x ->
return @@ Some (result_of_string (Yojson.Safe.from_lexbuf ~stream:true) x)
with _ -> return_none
......@@ -38,3 +38,5 @@ val set_partial_decryptions : string -> (int * string) list -> unit Lwt.t
val get_auth_config : string -> (string * (string * string list)) list Lwt.t
val set_auth_config : string -> (string * (string * string list)) list -> unit Lwt.t
val get_election_result : string -> Yojson.Safe.json result option Lwt.t
......@@ -30,7 +30,6 @@ open Web_signatures
open Web_services
let source_file = ref "belenios.tar.gz"
let spool_dir = ref "."
let get_single_line x =
match_lwt Lwt_stream.get x with
......
......@@ -23,7 +23,6 @@ open Web_serializable_t
open Web_signatures
val source_file : string ref
val spool_dir : string ref
val import_election :
election_files -> (module REGISTRABLE_ELECTION) option Lwt.t
......@@ -838,26 +838,35 @@ let election_home w state () =
];
]
in
let middle =
match state with
| `Tallied result ->
lwt middle =
let uuid = Uuidm.to_string params.e_uuid in
lwt result = Web_persist.get_election_result uuid in
match result with
| Some r ->
let result = r.result in
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
return @@ div [
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);
div [
pcdata "Number of accepted ballots: ";
pcdata (string_of_int r.num_tallied);
];
]
| None -> return go_to_the_booth
in
let content = [
p state_;
......
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