Commit 79cf2abd authored by Stephane Glondu's avatar Stephane Glondu
Browse files

In admin page, sort elections by finalization time

parent cad62a7f
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
(**************************************************************************) (**************************************************************************)
open Lwt open Lwt
open Serializable_builtin_j
open Serializable_t open Serializable_t
open Common open Common
...@@ -39,6 +40,17 @@ let get_election_state x = ...@@ -39,6 +40,17 @@ let get_election_state x =
let set_election_state x s = let set_election_state x s =
Ocsipersist.add election_states x s Ocsipersist.add election_states x s
let election_dates = Ocsipersist.open_table "election_dates"
let past = datetime_of_string "\"2015-10-01 00:00:00.000000\""
let get_election_date x =
try_lwt Ocsipersist.find election_dates x
with Not_found -> return past
let set_election_date x d =
Ocsipersist.add election_dates x d
let store = Ocsipersist.open_store "site" let store = Ocsipersist.open_store "site"
lwt main_election = lwt main_election =
......
...@@ -30,6 +30,9 @@ type election_state = ...@@ -30,6 +30,9 @@ type election_state =
val get_election_state : string -> election_state Lwt.t val get_election_state : string -> election_state Lwt.t
val set_election_state : string -> election_state -> unit Lwt.t val set_election_state : string -> election_state -> unit Lwt.t
val get_election_date : string -> datetime Lwt.t
val set_election_date : string -> datetime -> unit Lwt.t
val get_main_election : unit -> string option Lwt.t val get_main_election : unit -> string option Lwt.t
val set_main_election : string -> unit Lwt.t val set_main_election : string -> unit Lwt.t
val unset_main_election : unit -> unit Lwt.t val unset_main_election : unit -> unit Lwt.t
......
...@@ -277,10 +277,11 @@ let () = Html5.register ~service:admin ...@@ -277,10 +277,11 @@ let () = Html5.register ~service:admin
if W.metadata.e_owner = Some u then ( if W.metadata.e_owner = Some u then (
let uuid_s = Uuidm.to_string W.election.e_params.e_uuid in let uuid_s = Uuidm.to_string W.election.e_params.e_uuid in
lwt state = Web_persist.get_election_state uuid_s in lwt state = Web_persist.get_election_state uuid_s in
lwt date = Web_persist.get_election_date uuid_s in
lwt elections, tallied = accu in lwt elections, tallied = accu in
match state with match state with
| `Tallied _ -> return (elections, w :: tallied) | `Tallied _ -> return (elections, (date, w) :: tallied)
| _ -> return (w :: elections, tallied) | _ -> return ((date, w) :: elections, tallied)
) else ( ) else (
accu accu
) )
...@@ -291,7 +292,13 @@ let () = Html5.register ~service:admin ...@@ -291,7 +292,13 @@ let () = Html5.register ~service:admin
then return ((uuid_of_string k, v.se_questions.t_name) :: accu) then return ((uuid_of_string k, v.se_questions.t_name) :: accu)
else return accu else return accu
) election_stable [] ) election_stable []
in return @@ Some (elections, tallied, setup_elections) in
let sort l =
List.sort (fun (x, _) (y, _) -> datetime_compare x y) l |>
List.map (fun (_, x) -> x)
in
let elections = sort elections and tallied = sort tallied in
return @@ Some (elections, tallied, setup_elections)
in in
T.admin ~elections () T.admin ~elections ()
) )
...@@ -965,6 +972,7 @@ let () = ...@@ -965,6 +972,7 @@ let () =
Ocsipersist.remove election_pktokens token) Ocsipersist.remove election_pktokens token)
se.se_public_keys >> se.se_public_keys >>
Ocsipersist.remove election_stable uuid_s >> Ocsipersist.remove election_stable uuid_s >>
Web_persist.set_election_date uuid_s (now ()) >>
Redirection.send Redirection.send
(preapply election_admin (W.election.e_params.e_uuid, ())) (preapply election_admin (W.election.e_params.e_uuid, ()))
end end
......
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