Просмотр исходного кода

Add support to show pending tests in Nearby Locations tab

Alan Lam 6 лет назад
Родитель
Сommit
04d73330d9
3 измененных файлов с 65 добавлено и 36 удалено
  1. 20 5
      controllers/user_ajax.php
  2. 24 20
      public/js/app-user.js
  3. 21 11
      views/user.php

+ 20 - 5
controllers/user_ajax.php

@@ -37,6 +37,8 @@ switch($action) {
 		$date_start = http::value("date_start", "db");
 		$date_end = http::value("date_end", "db");
 
+		$pending_tests = http::value("pending_tests", "int");
+
 		$address = UserAddress::queryOne([
 			"id" => $address_id,
 			"user_id" => $id,
@@ -74,11 +76,19 @@ switch($action) {
 		});
 
 		// Get tests
-		$tests = Test::query([
+		$test_nvp = [
 			"status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
-			"dts_start" => (new Constraint("BETWEEN"))->setValues($date_start, $date_end),
 			"location_id" => array_column($locations, "id")
-		]);
+		];
+
+		if($pending_tests) {
+			$test_nvp["status"] = [Test::STATUS_UNASSIGNED, Test::STATUS_ASSIGNED];
+		}
+		else {
+			$test_nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues($date_start, $date_end);
+		}
+
+		$tests = Test::query($test_nvp);
 
 		// Get projects
 		$projects = Project::load(array_column($tests, "project_id"));
@@ -108,8 +118,13 @@ switch($action) {
 			$distance = Geolocation::getDistance($address->getGeolocation(), $location->getGeolocation());
 			if($distance > $max_distance) continue;
 
-			// Get test
-			$test = $location_test_array[$location->id] ?? false;
+			/** @var Test $test */
+			$test = $location_test_array[$location->id] ?? null;
+
+			if($pending_tests) {
+				if(!$test) continue;
+				if($test->dts_start) continue;
+			}
 
 			// Get customer
 			$customer = $location->getCustomer();

+ 24 - 20
public/js/app-user.js

@@ -39,6 +39,8 @@ $(function() {
 		initialiseLocations();
 	});
 
+	$("#pending-tests").on("change", () => initialiseLocations());
+
 });
 
 function initialiseAddresses() {
@@ -99,9 +101,10 @@ function initialiseLocations() {
 	let map = maps["nearby-locations-map"];
 
 	$.get("/api/users/" + userId + "/get-locations", {
-		"address_id": $("#address-id").val(),
-		"date_start": $("#date-start").val(),
-		"date_end": $("#date-end").val()
+		address_id: $("#address-id").val(),
+		date_start: $("#date-start").val(),
+		date_end: $("#date-end").val(),
+		pending_tests: $("#pending-tests").is(":checked") ? 1 : 0
 	}, function(response) {
 		if(!response.success) return false;
 		if(!response.locations) return false;
@@ -224,45 +227,46 @@ function initialiseLocations() {
 
 }
 
-function addMarkerClickListenerForLocation(m, l) {
+function addMarkerClickListenerForLocation(marker, location) {
 
 	let map = maps["map"];
 
-	m.addListener("click", function() {
-		let content = "<strong><a href=\"/account/locations/" + l.id + "\" target=\"_blank\">" + l.name + "</a></strong><br />";
-		if(l.internalId) {
-			content += "<div class=\"small\"><strong>Internal ID:</strong> " + l.internalId + "</div>";
+	marker.addListener("click", function() {
+		let content = "<strong><a href=\"/account/locations/" + location.id + "\" target=\"_blank\">" + location.name + "</a></strong><br />";
+		if(location.internalId) {
+			content += "<div class=\"small\"><strong>Internal ID:</strong> " + location.internalId + "</div>";
 		}
-		content += "<div class=\"small\"><strong>Location ID:</strong> " + l.id + "</div>";
+		content += "<div class=\"small\"><strong>Location ID:</strong> " + location.id + "</div>";
 
-		if(l.test) {
+		if(location.test) {
 
 			content += '<hr />';
 
-			content += '<div class="small"><strong>Test ID:</strong> <a href="/account/tests/' + l.test.id + '" target="_blank">' + l.test.id + '</a></div>';
+			content += '<div class="small"><strong>Test ID:</strong> <a href="/account/tests/' + location.test.id + '" target="_blank">' + location.test.id + '</a></div>';
+			content += '<div class="small"><strong>Project:</strong> <a href="/account/projects/' + location.test.project.id + '" target="_blank">' + location.test.project.name + '</a></div>';
 
-			if(l.test.formattedStartDts) {
-				content += '<div class="small"><strong>Date/Time:</strong> ' + l.test.formattedStartDts + '</div>';
+			if(location.test.formattedStartDts) {
+				content += '<div class="small"><strong>Date/Time:</strong> ' + location.test.formattedStartDts + '</div>';
 			}
 
-			if(l.test.tester) {
-				content += '<div class="small"><strong>Tester ID:</strong> ' + l.test.tester.id + '</div>';
-				content += '<div class="small"><strong>Tester Name:</strong> <a href="/account/users/' + l.test.tester.id + '" target="_blank">' + l.test.tester.name + '</a></div>';
+			if(location.test.tester) {
+				content += '<div class="small"><strong>Tester ID:</strong> ' + location.test.tester.id + '</div>';
+				content += '<div class="small"><strong>Tester Name:</strong> <a href="/account/users/' + location.test.tester.id + '" target="_blank">' + location.test.tester.name + '</a></div>';
 			}
 
 			let pastDueBadge = '';
-			if(l.test.pastDue) {
+			if(location.test.pastDue) {
 				pastDueBadge = '<span class="badge badge-lg badge-primary">Overdue</span>';
 			}
 
-			if(l.test.formattedDueDts) {
-				content += '<div class="small"><strong>Due:</strong> ' + l.test.formattedDueDts + ' ' + pastDueBadge + '</div>';
+			if(location.test.formattedDueDts) {
+				content += '<div class="small"><strong>Due:</strong> ' + location.test.formattedDueDts + ' ' + pastDueBadge + '</div>';
 			}
 
 		}
 
 		infoWindow.setContent(content);
-		infoWindow.open(map, m);
+		infoWindow.open(map, marker);
 	});
 
 }

+ 21 - 11
views/user.php

@@ -296,10 +296,6 @@ const userId = <?=$user->id?>;
 			?>
 		</div>
 		<div class="tab-pane fade" id="nearby-locations" role="tabpanel" aria-labelledby="nearby-locations-tab">
-			<h3>
-				Nearby Locations
-			</h3>
-
 			<?php
 			if(empty($addresses)) {
 				?>
@@ -312,6 +308,8 @@ const userId = <?=$user->id?>;
 				?>
 				<div class="row">
 					<div class="col-lg-6 mb-4">
+						<h3>Nearby Locations</h3>
+
 						<label for="address-id" class="sr-only"><?=htmlspecialchars(__("Address"))?></label>
 						<select class="form-control mb-3" id="address-id">
 						<?php
@@ -364,17 +362,29 @@ const userId = <?=$user->id?>;
 					<div class="col-lg-6 mb-4">
 						<h3>Tests</h3>
 
-						<label for="date-range" class="sr-only"><?=htmlspecialchars(__("Date Range"))?></label>
+						<div class="row align-items-middle">
+							<div class="col-6">
+								<label for="date-range" class="sr-only"><?=htmlspecialchars(__("Date Range"))?></label>
+
+								<div class="input-group input-group-sm mb-3">
+									<div class="input-group-prepend">
+										<span class="input-group-text">Date Range</span>
+									</div>
+									<input class="form-control" type="text" id="date-range" value="<?=$date_range?>" />
+								</div>
 
-						<div class="input-group mb-3">
-							<div class="input-group-prepend">
-								<span class="input-group-text">Date Range</span>
+								<input type="hidden" id="date-start" name="date_start" value="<?=htmlspecialchars($min_date)?>" />
+								<input type="hidden" id="date-end" name="date_end" value="<?=htmlspecialchars($max_date)?>" />
+							</div>
+							<div class="col-6">
+								<div class="custom-control custom-switch">
+									<input type="checkbox" class="custom-control-input" id="pending-tests" />
+									<label for="pending-tests" class="custom-control-label"><?=htmlspecialchars(__("Pending Tests Only"))?></label>
+								</div>
 							</div>
-							<input class="form-control" type="text" id="date-range" value="<?=$date_range?>" />
 						</div>
 
-						<input type="hidden" id="date-start" name="date_start" value="<?=htmlspecialchars($min_date)?>" />
-						<input type="hidden" id="date-end" name="date_end" value="<?=htmlspecialchars($max_date)?>" />
+
 
 						<div id="nearby-locations-map" style="height: 480px;" data-maps data-lat="<?=$address->latitude?>" data-lng="<?=$address->longitude?>" data-zoom="10">
 						</div>