From: Brian Flowers Date: Fri, 7 Feb 2025 03:51:08 +0000 (-0500) Subject: Initial commit of canvass monitoring response X-Git-Url: http://git.slightlycyberpunk.com%2C%20git.slightlycyberpunk.com/git/?a=commitdiff_plain;h=7517991d89a944b22a77a0ebe0ba4b6cc2a7f909;p=CCCP.git Initial commit of canvass monitoring response --- diff --git a/api.php b/api.php index 4a6d423..a7d8e86 100644 --- 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 diff --git a/js/canvassing.js b/js/canvassing.js index 113beaf..c7a8019 100644 --- a/js/canvassing.js +++ b/js/canvassing.js @@ -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); + }); }