Quellcode durchsuchen

Merge branch 'develop'

Alan Lam vor 7 Jahren
Ursprung
Commit
b47b2dcbe1

+ 19 - 2
controllers/map_overview_ajax.php

@@ -20,10 +20,27 @@ if($submit) {
 
 				$locations = $customer->getLocations();
 
-				$tests = Test::query([
+				$min_date = http::value("min_date");
+				$max_date = http::value("max_date");
+
+				$nvp = [
 					"status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
 					"location_id" => array_column($locations, "id")
-				]);
+				];
+
+				$date_format = "/^2[0-9]{3}\-[0-1][0-9]\-[0-3][0-9]$/";
+
+				if($min_date && preg_match($date_format, $min_date)) {
+					$min_dts = "{$min_date} 00:00:00";
+					$nvp["dts_start"] = (new Constraint("MORE_THAN_OR_EQUAL"))->setValues($min_dts);
+				}
+
+				if($max_date && preg_match($date_format, $max_date)) {
+					$max_dts = "{$max_date} 23:59:59";
+					$nvp["dts_start"] = (new Constraint("LESS_THAN_OR_EQUAL"))->setValues($max_dts);
+				}
+
+				$tests = Test::query($nvp);
 
 				$location_test_array = [];
 				foreach($tests as $test) {

+ 5 - 1
controllers/project_ajax.php

@@ -46,6 +46,8 @@ if($submit) {
 					$pass_text = "";
 					$pass_icon = "";
 
+					$retest = false;
+
 					$class = "secondary";
 					if($test) {
 						$test_id = (int) $test->id;
@@ -57,6 +59,7 @@ if($submit) {
 						$pass_class = $test->getPassClass();
 						$pass_text = $test->getPassText();
 						$pass_icon = $test->getPassIcon();
+						$retest = (bool) $test->retest;
 					}
 
 					$output[] = (object) [
@@ -75,7 +78,8 @@ if($submit) {
 						"passIcon" => $pass_icon,
 						"class" => $class,
 						"latitude" => (float) $location->latitude,
-						"longitude" => (float) $location->longitude
+						"longitude" => (float) $location->longitude,
+						"retest" => $retest,
 					];
 				}
 

+ 27 - 1
controllers/test.php

@@ -265,6 +265,14 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 
 			$test->verifier_notes = http::value("verifier_notes", "trim");
 
+			// Check selected retest project
+			$retest_project = false;
+			$retest_project_id = http::value("retest_project_id", "int");
+			if($retest_project_id) {
+				$retest_project = Project::get($retest_project_id);
+				if(!$retest_project || $retest_project->customer_id != $customer->id) throw new Exception("The retest project selected is invalid.");
+			}
+
 			// Modify test values
 
 			// Overrides
@@ -354,6 +362,16 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 				$tester->score++;
 				$tester->commit();
 
+				if(!$test->pass && $retest_project) {
+					$retest = new Test;
+					$retest->project_id = $retest_project->id;
+					$retest->location_id = $location->id;
+					$retest->status = Test::STATUS_UNASSIGNED;
+					$retest->dts_created = Util::getDateTime();
+					$retest->retest = 1;
+					$success = $retest->commit();
+				}
+
 				// Save PDF
 				$pdf = $test->getPDF();
 				$pdf_string = $pdf->Output("S");
@@ -398,8 +416,16 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 		}
 	}
 
+	$projects = $customer->getProjects();
+	$future_projects = array_filter($projects, function($p) use ($project) {
+		if($p->id == $project->id) return false;
+		if($p->template_id != $project->template_id) return false;
+		$unix_deadline = Util::getUnixTimeFromUTC($p->dts_deadline);
+		return ($unix_deadline > time());
+	});
+
 	View::includeOnce("header", compact("page_title"));
-	View::include("test_verify_form", compact("test", "has_pdf", "tester", "location", "project", "customer", "template", "fields", "values", "tester_message"));
+	View::include("test_verify_form", compact("test", "has_pdf", "tester", "location", "project", "future_projects", "customer", "template", "fields", "values", "tester_message"));
 	View::includeOnce("footer");
 	return;
 }

+ 2 - 2
engine/form.php

@@ -13,10 +13,10 @@ class Form {
 
 	public static function checkRecaptcha() {
 
-		if(!defined("GOOGLE_RECAPTCHA_SECRET_KEY")) return true;
+		if(!defined("GOOGLE_RECAPTCHA_SECRET")) return true;
 
 		$json = http::post("https://www.google.com/recaptcha/api/siteverify", [
-			"secret" => GOOGLE_RECAPTCHA_SECRET_KEY,
+			"secret" => GOOGLE_RECAPTCHA_SECRET,
 			"response" => http::value("g-recaptcha-response"),
 			"remoteip" => $_SERVER["REMOTE_ADDR"]
 		]);

+ 10 - 0
public/js/app-map-overview.js

@@ -79,8 +79,13 @@ function loadCustomerLocations(customerId) {
 		infoWindow = new google.maps.InfoWindow();
 	}
 
+	let minDate = $("#min-date").val();
+	let maxDate = $("#max-date").val();
+
 	$.get("/account/map-overview/get-customer-locations", {
 		customer_id: customerId,
+		min_date: minDate,
+		max_date: maxDate,
 		submit: $("#submit").val()
 	}, function(response) {
 		if(!response.success) return false;
@@ -127,8 +132,13 @@ function loadProjectLocations(projectId) {
 		infoWindow = new google.maps.InfoWindow();
 	}
 
+	let minDate = $("#min-date").val();
+	let maxDate = $("#max-date").val();
+
 	$.get("/account/map-overview/get-project-locations", {
 		project_id: projectId,
+		min_date: minDate,
+		max_date: maxDate,
 		submit: $("#submit").val()
 	}, function(response) {
 		if(!response.success) return false;

+ 50 - 35
public/js/app-project.js

@@ -151,6 +151,11 @@ function initialiseLocations() {
 
 			var td = $("<td></td>");
 			td.append(a);
+
+			if(location.retest) {
+				td.append(" <span class=\"badge badge-primary\">Retest</span>");
+			}
+
 			td.append("<br />");
 
 			if(location.internalId) {
@@ -300,7 +305,11 @@ function initialiseTesters() {
 
 		$("#tester-list-loading-container").text(response.testers.length + " tester addresses found in the vicinity.");
 
-		let tbody = $("#testers-tbody").detach();
+		let tbody = $("#testers-tbody").get(0);
+		tbody.innerHTML = "";
+
+		let tbodyInnerHtml = "";
+
 		let maxDistance = $("#testers-max-distance").val();
 
 		for(let i in response.testers) {
@@ -334,18 +343,7 @@ function initialiseTesters() {
 			var filterValueParts = [tester.name];
 			var filterValue = filterValueParts.join("").toLowerCase();
 
-			var tr = $("<tr data-tester-id=\"" + tester.id + "\" data-address-id=\"" + tester.addressId + "\" data-filter-value=\"" + filterValue + "\"></tr>");
-
-			if(tester.id == testerId) {
-				$(tr).addClass(highlightClass);
-			}
-
-			var td = $("<td class=\"text-right\"></td>");
-			td.append(tester.id);
-			tr.append(td);
-
-			var td = $("<td></td>");
-			td.append("<a href=\"/account/users/" + tester.id + "\" target=\"_blank\">" + tester.name + "</a> ");
+			var testerClass = (tester.id == testerId) ? highlightClass : "";
 
 			var scoreClass = "secondary";
 			if(tester.score > 0) {
@@ -355,50 +353,62 @@ function initialiseTesters() {
 				scoreClass = "danger";
 			}
 
-			td.append("<span class=\"badge badge-pill badge-" + scoreClass + "\" title=\"Score\">" +  tester.score + "</span>");
+			var distanceClass = "";
+			if(tester.maxRadiusExceeded) {
+				distanceClass = "text-danger";
+			}
 
-			td.append("<br />");
+			var trHtml = "<tr class=\"" + testerClass + "\" data-tester-id=\"" + tester.id + "\" data-address-id=\"" + tester.addressId + "\" data-filter-value=\"" + filterValue + "\">";
+
+			trHtml += "<td class=\"text-right\">" + tester.id + "</td>";
+			trHtml += "<td><a href=\"/account/users/" + tester.id + "\" target=\"_blank\">" + tester.name + "</a> <span class=\"badge badge-pill badge-" + scoreClass + "\" title=\"Score\">" +  tester.score + "</span><br />";
+
+			trHtml += "<small class=\"" + distanceClass + "\">";
+			trHtml += tester.distanceMiles + " / " + tester.maxRadiusMiles + " miles";
 
-			var small = $("<small>" + tester.distanceMiles + " / " + tester.maxRadiusMiles + " miles</small>");
 			if(tester.maxRadiusExceeded) {
-				small.addClass("text-danger");
-				small.append(" <i class=\"fas fa-exclamation-circle\"></i>");
+				trHtml += " <i class=\"fas fa-exclamation-circle\"></i>";
 			}
-			td.append(small);
-			tr.append(td);
 
-			td = $("<td class=\"text-right align-middle\"></td>");
-			td.append(tester.age);
-			tr.append(td);
+			trHtml += "</small>";
+			trHtml += "</td>";
 
-			td = $("<td class=\"text-right align-middle\"></td>");
+			trHtml += "<td class=\"text-right align-middle\">" + tester.age + "</td>";
+			trHtml += "<td class=\"text-right align-middle\">";
 
 			if(!tester.termsAccepted) {
-				td.append("<span class=\"badge badge-danger\" title=\"Terms and Conditions not accepted\">T&amp;C</span> ");
+				trHtml += "<span class=\"badge badge-danger\" title=\"Terms and Conditions not accepted\">T&amp;C</span> ";
 			}
 
 			if(tester.reported) {
-				td.append("<span class=\"badge badge-danger\" data-toggle=\"tooltip\" data-title=\"" + tester.reportedComment + "\">Reported</span> ");
+				trHtml += "<span class=\"badge badge-danger\" data-toggle=\"tooltip\" data-title=\"" + tester.reportedComment + "\">Reported</span> ";
 			}
 
-			td.append("<span class=\"badge badge-" + tester.levelClass + "\">" + tester.levelText + "</span>");
-			td.append("<br />");
-			td.append($("<small>").text(tester.phone));
-			tr.append(td);
+			trHtml += "<span class=\"badge badge-" + tester.levelClass + "\">" + tester.levelText + "</span><br />";
+			trHtml += "<small>" + tester.phone + "</small>";
+
+			trHtml += "<td class=\"text-right align-middle\">";
 
-			td = $("<td class=\"text-right align-middle\"></td>");
 			if(!tester.isCurrentTester) {
-				td.append($("<button class=\"btn btn-outline-primary\" data-assign-button title=\"Assign\" data-toggle=\"tooltip\"><i class=\"fal fa-fw fa-user-plus\"></i>...</button>").tooltip());
+				trHtml += "<button class=\"btn btn-outline-primary\" data-assign-button title=\"Assign\" data-toggle=\"tooltip\"><i class=\"fal fa-fw fa-user-plus\"></i></button>";
 			}
-			tr.append(td);
+			trHtml += "</td>";
 
-			$(tbody).append(tr);
+
+			trHtml += "</td>";
+			trHtml += "</tr>";
+
+			tbodyInnerHtml += trHtml;
 		}
 
-		$("#testers-table").append(tbody);
+		tbody.innerHTML = tbodyInnerHtml;
+
+		console.log(tbodyInnerHtml);
 
 		initialiseTooltips();
 
+		$("input[data-filter-target]").trigger("keyup");
+
 	});
 }
 
@@ -456,6 +466,11 @@ function handleAssignButtonClick(event) {
 		assignMarkers.push(marker);
 
 		$("#modal-assign-tester").find("[data-location-name]").text(location.name);
+
+		if(location.retest) {
+			$("#modal-assign-tester").find("[data-location-name]").append(" <span class=\"badge badge-primary\">Retest</span>");
+		}
+
 		$("#modal-assign-tester").find("[data-location-address]").text(location.address);
 	}
 

+ 21 - 7
views/map_overview.php

@@ -4,16 +4,30 @@
 
 	<h2>Map Overview</h2>
 
-	<div class="input-group">
-		<div class="input-group-prepend">
-			<span class="input-group-text">Location</span>
+	<div class="row">
+		<div class="col-6">
+			<div class="form-group">
+				<label for="location">Location</label>
+				<input type="text" class="form-control" id="location" placeholder="Type location" data-autocomplete="map" />
+				<div class="help-text text-muted">
+					<small>Type location and select to jump to location.</small>
+				</div>
+			</div>
+		</div>
+		<div class="col-3">
+			<div class="form-group">
+				<label for="min-date">Min Test Date</label>
+				<input type="date" class="form-control" id="min-date" placeholder="Type date" value="<?=date("Y")?>-01-01" />
+			</div>
+		</div>
+		<div class="col-3">
+			<div class="form-group">
+				<label for="min-date">Max Test Date</label>
+				<input type="date" class="form-control" id="min-date" placeholder="Type date" value="<?=date("Y")?>-12-31" />
+			</div>
 		</div>
-		<input type="text" class="form-control" placeholder="Type location" data-autocomplete="map" />
 	</div>
 
-	<div class="help-text text-muted mb-3">
-		<small>Type location and select to jump to location.</small>
-	</div>
 
 	<div class="mb-4" id="map" data-maps data-lat="51.3555177" data-lng="-1.1743197" data-zoom="7" style="height: 512px;"></div>
 

+ 15 - 0
views/test_verify_form.php

@@ -304,6 +304,21 @@ function render_card_list_group($details) {
 						<?php
 						if($test->status == Test::STATUS_PENDING_VERIFICATION) {
 							?>
+							<div class="row mb-1">
+								<div class="col-sm-4 col-form-label">Create Retest</div>
+								<div class="col-sm">
+									<select class="form-control" name="retest_project_id">
+										<option value="0">None</option>
+										<?php
+										foreach($future_projects as $future_project) {
+											?>
+											<option value="<?=$future_project->id?>"><?=htmlspecialchars($future_project->name)?></option>
+											<?php
+										}
+										?>
+									</select>
+								</div>
+							</div>
 							<?php
 							if($customer->email) {
 								?>