Initial commit of canvass monitoring response
authorBrian Flowers <git-admn@bsflowers.net>
Fri, 7 Feb 2025 03:51:08 +0000 (22:51 -0500)
committerBrian Flowers <git-admn@bsflowers.net>
Fri, 7 Feb 2025 03:51:08 +0000 (22:51 -0500)
api.php
js/canvassing.js

diff --git a/api.php b/api.php
index 4a6d423..a7d8e86 100644 (file)
--- a/api.php
+++ b/api.php
@@ -706,6 +706,24 @@ if( isset($_GET['get']) &&
 
   print_r(json_encode($rows));
 
+// URL: ?get=canvassMonitor
+// fetch stats from a particular active canvass
+// GET: id -- id of the canvass to retrieve
+} else if( isset($_GET['get']) && $_GET['get'] == "canvassMonitor") {
+  if( !isset($_GET['id']) ) {
+    return "{}";
+  }
+  $id = $_GET['id'];
+
+  $query = "SELECT count(*), userId, max(timestamp) FROM canvassResults WHERE canvassId=? ".
+           "GROUP BY userId DESC;";
+  $params= [$id, $page*$pageSize, $pageSize];
+  $stmt  = $dbh->prepare($query);
+  $stmt -> execute($params);
+  $rows  = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+  echo json_encode($rows);
+
 // URL: ?get=canvassResults
 // fetch a list of results from a particular canvass
 // GET: id -- id of the canvass to retrieve
index 113beaf..c7a8019 100644 (file)
@@ -990,4 +990,10 @@ function reduceCacheBug() {
 
 function monitorCanvass(canvass) {
   console.log(canvass);
+  fetch("api.php?get=canvassMonitor&id="+id).then(data => data.json())
+    .then(output => {
+
+    resp = output.dataset;
+               console.log(resp);
+       });
 }