Commit e5b9b3c0 authored by Stephane Glondu's avatar Stephane Glondu

Refactor result page to account for open questions

parent 473597a2
Pipeline #68064 passed with stages
in 17 minutes and 19 seconds
......@@ -197,6 +197,10 @@ module Shape = struct
| SArray _ -> invalid_arg "Shape.to_array"
) xs
let to_shape_array = function
| SAtomic _ -> invalid_arg "Shape.to_shape_array"
| SArray xs -> xs
let of_array_array x =
SArray (
Array.map (fun x ->
......
......@@ -66,6 +66,7 @@ module Shape : sig
| SAtomic of 'a
| SArray of 'a t array
val to_array : 'a t -> 'a array
val to_shape_array : 'a t -> 'a t array
val of_array_array : 'a array array -> 'a t
val to_array_array : 'a t -> 'a array array
val map : ('a -> 'b) -> 'a t -> 'b t
......
......@@ -1650,6 +1650,42 @@ let rec list_concat elt = function
| x :: ((_ :: _) as xs) -> x :: elt :: (list_concat elt xs)
| ([_] | []) as xs -> xs
let format_question_result l q r =
let module L = (val l : Web_i18n_sig.LocalizedStrings) in
match q with
| Question.Standard x ->
let r = Shape.to_array r in
let open Question_std_t in
let answers = Array.to_list x.q_answers in
let answers = match x.q_blank with
| Some true -> L.blank_vote :: answers
| _ -> answers
in
let answers =
List.mapi (fun j x ->
tr [td [pcdata x]; td [pcdata @@ string_of_int r.(j)]]
) answers
in
let answers =
match answers with
| [] -> pcdata ""
| y :: ys ->
match x.q_blank with
| Some true -> table (ys @ [y])
| _ -> table (y :: ys)
in
li [
pcdata x.q_question;
answers;
]
| Question.Open x ->
let open Question_open_t in
li [
pcdata x.q_question;
pcdata " ";
em [pcdata "(open)"];
]
let election_home election state () =
let%lwt language = Eliom_reference.get Web_state.language in
let l = Web_i18n.get_lang language in
......@@ -1749,32 +1785,12 @@ let election_home election state () =
let%lwt result = Web_persist.get_election_result uuid in
match result with
| Some r ->
let result = Shape.to_array_array r.result in
let questions = Array.to_list election.e_params.e_questions in
let result = Shape.to_shape_array r.result in
return @@ div [
ul (List.mapi (fun i (Question.Standard x) ->
let open Question_std_t in
let answers = Array.to_list x.q_answers in
let answers = match x.q_blank with
| Some true -> L.blank_vote :: answers
| _ -> 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 ""
| y :: ys ->
match x.q_blank with
| Some true -> table (ys @ [y])
| _ -> table (y :: ys)
in
li [
pcdata x.q_question;
answers;
]
) questions);
ul (
Array.map2 (format_question_result l) election.e_params.e_questions result
|> Array.to_list
);
div [
pcdata L.number_accepted_ballots;
pcdata (string_of_int r.num_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