]> git.scottworley.com Git - voter/blobdiff - src/main.rs
Show vote counts
[voter] / src / main.rs
index 9f536ed6859b405112e088cce464b30a6be68987..a12f73a9c18328fd1d8742e8a0823754dd67a618 100644 (file)
@@ -146,6 +146,7 @@ const HTML_HEADER: &str = "<!DOCTYPE html>
   <body>
     <table>
       <tr>
+        <th>Count</th>
         <th>Vote</th>
         <th>Candidate</th>
       </tr>";
@@ -177,6 +178,10 @@ fn prompt_for_vote(dir: PathBuf, request: cgi::Request) -> Result<cgi::Response,
         std::iter::once(Ok(HTML_HEADER.to_owned()))
             .chain(std::io::BufReader::new(cfile).lines().map(|rc| {
                 rc.map(|c| {
+                    let count = tally
+                        .get(&c)
+                        .map(|supporters| supporters.len())
+                        .unwrap_or(0);
                     let checked = if me.map(|me| supports(&tally, me, &c)).unwrap_or(false) {
                         "checked"
                     } else {
@@ -184,6 +189,7 @@ fn prompt_for_vote(dir: PathBuf, request: cgi::Request) -> Result<cgi::Response,
                     };
                     format!(
                         "<tr>
+                        <td>{count}</td>
                         <td><input type=\"checkbox\" autocomplete=\"off\" {checked} disabled></td>
                         <td>{c}</td>
                         </tr>"