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
var button = document.createElement("input");
button.setAttribute("type", "button");
button.value = "Monitor";
- button.onclick = monitorCanvass.bind(null, turfs[i].canvasses[j].id);
+ button.onclick = monitorCanvass.bind(null, turfs[i].canvasses[j]);
cell.appendChild(button);
}
row.appendChild(cell);
function monitorCanvass(canvass) {
console.log(canvass);
- fetch("api.php?get=canvassMonitor&id="+id).then(data => data.json())
- .then(output => {
+// fetch("api.php?get=canvassMonitor&id="+canvass).then(data => data.json())
+// .then(output => {
+
+ // similar to startCanvass
+ // open the map, give buttons to return to menu and to view stats list
+ // Show pins for last contact from each team
+ // Dim contacts if no updates in...10m?
+ // Pop-up on updates
+ debug("monitorCanvass(..., ...)");
+ debug(canvass);
+// debug(turf);
+ setLoading(1);
+ map.on("moveend", loadCanvassers.bind(null, false, canvass));
+// loadTurfs();
+/* var json = turf.json;
+ var turfPoints = JSON.parse(json).geometry.coordinates[0];
+ var latTot = 0;
+ var lonTot = 0;
+ var i = 0;
+ for(i = 0; i < turfPoints.length; i++) {
+ latTot += turfPoints[i][1];
+ lonTot += turfPoints[i][0];
+ }
+*/
+ map.setZoom(19);
+ map.setView([latTot/i, lonTot/i]);
+ enableCanvassControls();
+ currentCanvass = canvass;
+// turfLayer = turf;
+// setTimeout(toggleTurf.bind(null, turf, true), 1000);
+ viewCanvass(canvass);
- resp = output.dataset;
- console.log(resp);
+/* var options = {
+ method: "POST",
+ headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"},
+ body: "id="+canvass.id;
+ }
+ fetch("api.php?get=canvassMonitor", options).then(data => data.json())
+ .then(resp => {
+ loadCanvassers(false);
+ debug("End Async monitorCanvass");
+ });*/
+ loadCanvassers(false, canvass);
+
+
+ toggleControls();
+ setLoading(-1);
+ debug("End Sync monitorCanvass");
});
}
+
+function loadCanvassers(force = false, canvass) {
+ debug("loadCanvassers");
+ var options = {
+ method: "POST",
+ headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"},
+ body: "id="+canvass.id;
+ }
+ fetch("api.php?get=canvassMonitor", options).then(data => data.json())
+ .then(resp => {
+// console.log(resp);
+ for(var i = 0; i < resp.length; i++) {
+ console.log(resp[i]);
+ }
+ debug("End loadCanvassers");
+ });
+
+}