Commit cad62a7f authored by Stephane Glondu's avatar Stephane Glondu

In admin page, show tallied elections in a new section

parent 008f5f50
......@@ -271,22 +271,27 @@ let () = Html5.register ~service:admin
match site_user with
| None -> return None
| Some u ->
lwt elections =
lwt elections, tallied =
SMap.fold (fun _ w accu ->
let module W = (val w : WEB_ELECTION) in
if W.metadata.e_owner = Some u then (
w :: accu
let uuid_s = Uuidm.to_string W.election.e_params.e_uuid in
lwt state = Web_persist.get_election_state uuid_s in
lwt elections, tallied = accu in
match state with
| `Tallied _ -> return (elections, w :: tallied)
| _ -> return (w :: elections, tallied)
) else (
accu
)
) !election_table [] |> List.rev |> return
) !election_table (return ([], []))
and setup_elections =
Ocsipersist.fold_step (fun k v accu ->
if v.se_owner = u
then return ((uuid_of_string k, v.se_questions.t_name) :: accu)
else return accu
) election_stable []
in return @@ Some (elections, setup_elections)
in return @@ Some (elections, tallied, setup_elections)
in
T.admin ~elections ()
)
......
......@@ -194,7 +194,7 @@ let admin ~elections () =
] in
lwt login_box = site_login_box () in
base ~title ~login_box ~content ()
| Some (elections, setup_elections) ->
| Some (elections, tallied, setup_elections) ->
let setup_form = post_form ~service:election_setup_new
(fun () ->
[
......@@ -207,6 +207,11 @@ let admin ~elections () =
| [] -> p [pcdata "You own no such elections!"]
| _ -> ul @@ List.map (format_election `Admin) elections
in
let tallied =
match tallied with
| [] -> p [pcdata "You own no such elections!"]
| _ -> ul @@ List.map (format_election `Admin) tallied
in
let setup_elections =
match setup_elections with
| [] -> p [pcdata "You own no such elections!"]
......@@ -224,6 +229,9 @@ let admin ~elections () =
div [br ()];
h2 [pcdata "Elections you can administer"];
elections;
div [br ()];
h2 [pcdata "Tallied elections"];
tallied;
];
] in
lwt login_box = site_login_box () in
......
......@@ -22,7 +22,7 @@
open Web_signatures
val home : featured:(module WEB_ELECTION) list -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val admin : elections:((module WEB_ELECTION) list * (Uuidm.t * string) list) option -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val admin : elections:((module WEB_ELECTION) list * (module WEB_ELECTION) list * (Uuidm.t * string) list) option -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
val new_election_failure : [ `Exists | `Exception of exn ] -> unit -> [> `Html ] Eliom_content.Html5.F.elt Lwt.t
......
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