Commit b3eed6a9 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Start election_view

parent f50b1e47
......@@ -67,8 +67,9 @@ let base ~title ~header ~content =
]
) @ [
a ~service:Helios_services.project_home [
pcdata "About Helios | Help!"
pcdata "About Helios"
] ();
pcdata " | Help!";
(* footer links *)
br ~a:[a_style "clear:right;"] ();
]
......@@ -96,11 +97,26 @@ let login_box auth_systems = List.map
]
) auth_systems
type answer = {
count : int;
answer : string;
winner : bool;
}
type question = {
answers : answer list;
question : string;
}
type election = {
election_uuid : string;
election_short_name : string;
election_name : string;
election_description : string;
election_admin : Helios_services.user;
election_questions : string list;
election_trustees : string list;
election_state : [`Finished of question list | `Stopped | `Started];
}
let format_one_election e =
......@@ -217,3 +233,85 @@ let dummy_login ~service =
~title
~header:[h2 [pcdata title]]
~content:[div [form]]
let list_iteri f xs =
let rec loop i = function
| [] -> []
| x :: xs -> f i x :: loop (succ i) xs
in List.flatten (loop 0 xs)
let election_view ~election =
let content = [
div ~a:[a_style "float: left; margin-right: 50px;"] [pcdata "FIXME"];
br ();
br ();
br ~a:[a_style "clear: left;"] ();
div ~a:[a_style "margin-bottom: 25px;margin-left: 15px; border-left: 1px solid #aaa; padding-left: 5px; font-size:1.3em;"] [pcdata election.election_description];
p ~a:[a_style "text-align: center; font-size: 1.5em;"] [
a ~service:(Eliom_service.preapply Helios_services.election_questions election.election_uuid) [
pcdata "questions (";
pcdata (string_of_int (List.length election.election_questions));
pcdata ")";
] ();
(* FIXME: space (&nbsp) breaks the output *)
pcdata " | ";
a ~service:(Eliom_service.preapply Helios_services.election_voters election.election_uuid) [
pcdata "voters & ballots"
] ();
pcdata " | ";
a ~service:(Eliom_service.preapply Helios_services.election_trustees election.election_uuid) [
pcdata "trustees (";
pcdata (string_of_int (List.length election.election_trustees));
pcdata ")";
] ();
];
(* NOTE: administration things removed from here! *)
br ();
br ();
] @ (match election.election_state with
| `Finished result ->
[
span ~a:[a_class ["highlight-box"; "round"]] [
pcdata "This election is complete.";
];
br ();
br ();
h3 ~a:[a_class ["highlight-box"]] [pcdata "Tally"];
] @ (
list_iteri (fun i question ->
[
b [
span ~a:[a_style "font-size:0.8em;"] [
pcdata "Question #";
pcdata (string_of_int i);
];
br ();
pcdata question.question;
];
br ();
let table xs = match xs with
| x :: xs -> table ~a:[a_class ["pretty"]; a_style "width: auto;"] x xs
| [] -> assert false
in table (
List.map (fun answer ->
let style = if answer.winner then "font-weight:bold;" else "" in
tr [
td ~a:[a_style ("padding-right:80px;" ^ style)] [pcdata answer.answer];
td ~a:[a_style ("text-align:right;" ^ style)] [pcdata (string_of_int answer.count)];
]
) question.answers
);
]
) result
)
| `Stopped ->
[
(* FIXME *)
]
| `Started ->
[
(* FIXME *)
]
)
in
base ~title:election.election_name ~header:[] ~content
open Lwt
let get_featured_elections () =
let elections =
let open Helios_services in
let open Helios_templates in
return [
[
{
election_uuid = "94c1a03e-1c48-11e2-8866-3cd92b7981b8";
election_short_name = "editor";
election_name = "Best editor";
election_description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
......@@ -12,9 +13,49 @@ let get_featured_elections () =
user_name = "admin";
user_type = "dummy";
};
election_questions = [];
election_trustees = [];
election_state = `Finished [
{
answers = [
{
answer = "emacs";
count = 2;
winner = true;
};
{
answer = "vim";
count = 1;
winner = false;
};
{
answer = "gedit";
count = 0;
winner = false;
};
{
answer = "something else";
count = 1;
winner = false;
};
];
question = "What is your favourite editor?";
};
];
}
]
let get_featured_elections () =
return elections
let get_election_by_name x =
let open Helios_templates in
wrap2 List.find (fun e -> e.election_short_name = x) elections
let get_election_by_uuid x =
let open Helios_templates in
wrap2 List.find (fun e -> e.election_uuid = x) elections
let () = Eliom_registration.Html5.register
~service:Helios_services.home
(fun () () ->
......@@ -31,10 +72,16 @@ let () = Eliom_registration.Html5.register
(fun () () ->
Helios_templates.not_implemented "Create election")
let () = Eliom_registration.Html5.register
let () = Eliom_registration.Redirection.register
~service:Helios_services.election_shortcut
(fun _ () ->
Helios_templates.not_implemented "Election shortcut")
(fun name () ->
try_lwt
lwt e = get_election_by_name name in
return (Eliom_service.preapply
Helios_services.election_view
e.Helios_templates.election_uuid)
with Not_found ->
raise_lwt Eliom_common.Eliom_404)
let () = Eliom_registration.Html5.register
~service:Helios_services.login
......@@ -57,3 +104,27 @@ let () = Eliom_registration.Redirection.register
(fun () () ->
Eliom_state.discard ~scope:Eliom_common.session () >>
return Helios_services.home)
let () = Eliom_registration.Html5.register
~service:Helios_services.election_view
(fun uuid () ->
try_lwt
lwt election = get_election_by_uuid uuid in
Helios_templates.election_view ~election
with Not_found ->
raise_lwt Eliom_common.Eliom_404)
let () = Eliom_registration.Html5.register
~service:Helios_services.election_questions
(fun uuid () ->
Helios_templates.not_implemented "Questions")
let () = Eliom_registration.Html5.register
~service:Helios_services.election_voters
(fun uuid () ->
Helios_templates.not_implemented "Voters")
let () = Eliom_registration.Html5.register
~service:Helios_services.election_trustees
(fun uuid () ->
Helios_templates.not_implemented "Trustees")
......@@ -57,3 +57,23 @@ type user = {
let user = Eliom_reference.eref
~scope:Eliom_common.session
(None : (bool * user) option)
let election_view = service
~path:["elections"; "view"]
~get_params:(string "uuid")
()
let election_questions = service
~path:["elections"; "questions"]
~get_params:(string "uuid")
()
let election_voters = service
~path:["elections"; "voters"]
~get_params:(string "uuid")
()
let election_trustees = service
~path:["elections"; "trustees"]
~get_params:(string "uuid")
()
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