Commit 6bfa7c43 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Add countdown to automatic open/close on election_home

parent 950c2d35
......@@ -89,6 +89,26 @@ let explain_error l e =
| CastError ECastReusedCredential -> L.error_ReusedCredential
| CastError ECastWrongCredential -> L.error_WrongCredential
let decompose_seconds s =
let h = int_of_float (s /. 3600.) in
let s = s -. float_of_int h *. 3600. in
let m = int_of_float (s /. 60.) in
let s = s -. float_of_int m *. 60. in
(h, m, int_of_float s)
let format_period l x =
let module L = (val l : Web_i18n_sig.LocalizedStrings) in
let y, m, d, s = ymds x in
let y = if y = 0 then "" else string_of_int y ^ L.years in
let m = if m = 0 then "" else string_of_int m ^ L.months in
let d = if d = 0 then "" else string_of_int d ^ L.days in
let hrs, min, sec = decompose_seconds s in
let hrs = if hrs = 0 then "" else string_of_int hrs ^ L.hours in
let min = if min = 0 then "" else string_of_int min ^ L.minutes in
let sec = if sec = 0 then "" else string_of_int sec ^ L.seconds in
let approx = String.concat " " (List.filter (fun x -> x <> "") [y; m; d; hrs; min]) in
if approx = "" then sec else approx
let security_logfile = ref None
let open_security_log f =
......
......@@ -21,6 +21,7 @@
open Signatures
open Serializable_t
open Web_serializable_builtin_t
open Web_serializable_t
module LwtRandom : RANDOM with type 'a t = 'a Lwt.t
......@@ -48,6 +49,8 @@ val fail : error -> 'a Lwt.t
val explain_error : (module Web_i18n_sig.LocalizedStrings) -> error -> string
val format_period : (module Web_i18n_sig.LocalizedStrings) -> period -> string
val open_security_log : string -> unit Lwt.t
(** Set the path to the security logger. *)
......
......@@ -112,6 +112,14 @@ module type LocalizedStrings = sig
val result_with_crypto_proofs : string
val blank_vote : string
val no_other_blank : string
val it_will_open_in : string
val the_election_will_close_in : string
val years : string
val months : string
val days : string
val hours : string
val minutes : string
val seconds : string
val mail_password_subject : (string -> 'f, 'b, 'c, 'e, 'e, 'f) format6
val mail_password : (string -> string -> string -> string -> string -> 'f, 'b, 'c, 'e, 'e, 'f) format6
val mail_credential_subject : (string -> 'f, 'b, 'c, 'e, 'e, 'f) format6
......
......@@ -111,6 +111,14 @@ let you_can_also_download = "Sie können außerdem das "
let result_with_crypto_proofs = "Ergbnis mit den kryptographischen Beweisen herunterladen"
let blank_vote = "ungültige Stimme"
let no_other_blank = "Bei einer ungültigen Stimme sind keine anderen Auswahlmöglichkeiten vorhanden."
let it_will_open_in = "It will close in "
let the_election_will_close_in = "The election will close in "
let years = " year(s)"
let months = " month(s)"
let days = " day(s)"
let hours = " hour(s)"
let minutes = " minute(s)"
let seconds = " second(s)"
let mail_password_subject : ('a, 'b, 'c, 'd, 'e, 'f) format6 =
......
......@@ -111,6 +111,14 @@ let you_can_also_download = "You can also download the "
let result_with_crypto_proofs = "result with cryptographic proofs"
let blank_vote = "Blank vote"
let no_other_blank = "No other choices are allowed when voting blank"
let it_will_open_in = "It will close in "
let the_election_will_close_in = "The election will close in "
let years = " year(s)"
let months = " month(s)"
let days = " day(s)"
let hours = " hour(s)"
let minutes = " minute(s)"
let seconds = " second(s)"
let mail_password_subject : ('a, 'b, 'c, 'd, 'e, 'f) format6 =
......
......@@ -111,6 +111,14 @@ let you_can_also_download = "Vous pouvez également télécharger le "
let result_with_crypto_proofs = "résultat avec les preuves cryptographiques"
let blank_vote = "Vote blanc"
let no_other_blank = "Vous ne pouvez pas sélectionner d'autres choix lors d'un vote blanc"
let it_will_open_in = "Elle ouvrira dans "
let the_election_will_close_in = "L'élection fermera dans "
let years = " année(s)"
let months = " mois"
let days = " jour(s)"
let hours = " heure(s)"
let minutes = " minute(s)"
let seconds = " seconde(s)"
let mail_password_subject : ('a, 'b, 'c, 'd, 'e, 'f) format6 =
......
......@@ -111,6 +111,14 @@ let you_can_also_download = "È possibile scaricare il "
let result_with_crypto_proofs = "risultato con le prove crittografiche"
let blank_vote = "Scheda bianca"
let no_other_blank = "Nessun'altra scelta è autorizzata quando la scheda è bianca"
let it_will_open_in = "It will close in "
let the_election_will_close_in = "The election will close in "
let years = " year(s)"
let months = " month(s)"
let days = " day(s)"
let hours = " hour(s)"
let minutes = " minute(s)"
let seconds = " second(s)"
let mail_password_subject : ('a, 'b, 'c, 'd, 'e, 'f) format6 =
......
......@@ -111,6 +111,14 @@ let you_can_also_download = "De asemenea, puteți descărca "
let result_with_crypto_proofs = "rezultat cu dovada criptografică"
let blank_vote = "Vot alb"
let no_other_blank = "Nu puteți selecta o altă opțiune la un vot alb"
let it_will_open_in = "It will close in "
let the_election_will_close_in = "The election will close in "
let years = " year(s)"
let months = " month(s)"
let days = " day(s)"
let hours = " hour(s)"
let minutes = " minute(s)"
let seconds = " second(s)"
let mail_password_subject : ('a, 'b, 'c, 'd, 'e, 'f) format6 =
......
......@@ -57,3 +57,8 @@ let second = CalendarLib.Fcalendar.Precise.Period.second
let datetime_add (a, _) x =
CalendarLib.Fcalendar.Precise.add a x, None
let datetime_sub (a, _) (b, _) =
CalendarLib.Fcalendar.Precise.sub a b
let ymds = CalendarLib.Fcalendar.Precise.Period.ymds
......@@ -30,3 +30,5 @@ type period
val day : int -> period
val second : float -> period
val datetime_add : datetime -> period -> datetime
val datetime_sub : datetime -> datetime -> period
val ymds : period -> int * int * int * float
......@@ -1596,17 +1596,43 @@ let rec list_concat elt = function
let election_home election state () =
let%lwt language = Eliom_reference.get Web_state.language in
let module L = (val Web_i18n.get_lang language) in
let l = Web_i18n.get_lang language in
let module L = (val l) in
let params = election.e_params in
let uuid = params.e_uuid in
let%lwt d = Web_persist.get_election_auto_dates uuid in
let now = now () in
let state_ =
match state with
| `Closed ->
let it_will_open =
match d.Web_persist.auto_open with
| Some t when datetime_compare now t < 0 ->
span [
pcdata " ";
pcdata L.it_will_open_in;
pcdata (format_period l (datetime_sub t now));
pcdata ".";
]
| _ -> pcdata ""
in
[
pcdata " ";
b [pcdata L.election_currently_closed];
it_will_open;
]
| `Open -> []
| `Open ->
let it_will_close =
match d.Web_persist.auto_close with
| Some t when datetime_compare now t < 0 ->
span [
pcdata L.the_election_will_close_in;
pcdata (format_period l (datetime_sub t now));
pcdata ".";
]
| _ -> pcdata ""
in
[it_will_close]
| `EncryptedTally (_, _, hash) ->
[
pcdata " ";
......
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