فهرست منبع

Add latest test details to Nearby Locations list

Alan Lam 8 سال پیش
والد
کامیت
0cca0c2813
3فایلهای تغییر یافته به همراه97 افزوده شده و 19 حذف شده
  1. 24 9
      controllers/user_ajax.php
  2. 53 9
      public/js/app-user.js
  3. 20 1
      views/user.php

+ 24 - 9
controllers/user_ajax.php

@@ -63,7 +63,7 @@ switch($action) {
 			<=>
 			Geolocation::getDistance($address->getGeolocation(), $b->getGeolocation());
 		});
-		
+
 		// Get tests
 		$tests = Test::query([
 			"status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
@@ -87,10 +87,13 @@ switch($action) {
 				}
 			}
 		}
-		
+
+		// Get projects
+		$projects = Project::load(array_column($location_test_array, "project_id"));
+
 		// Start output
 		foreach($locations as $location) {
-			
+
 			// Filter by distance
 			$distance = Geolocation::getDistance($address->getGeolocation(), $location->getGeolocation());
 			if($distance > $max_distance) continue;
@@ -111,10 +114,11 @@ switch($action) {
 			// Icon
 			$icon = null;
 			$icon_file = "{$customer_slug}_none.png";
-			
-			// Process test	
+
+			// Process test
 			if($test) {
 				$tester = $test->getTester();
+				$project = $test->getProject();
 
 				if(!is_null($test->dts_start)) {
 					$unix_start = strtotime($test->dts_start);
@@ -128,7 +132,7 @@ switch($action) {
 					if(!is_null($test->dts_due)) {
 						$unix_due = strtotime($test->dts_due);
 						$formatted_due_dts = date("d/m/Y H:i", $unix_due);
-						
+
 						if($tester && time() > $unix_due) {
 							$icon_file = "{$customer_slug}_past_due.png";
 							$past_due = true;
@@ -161,22 +165,33 @@ switch($action) {
 			];
 
 			if($test) {
+
+				$pass = is_null($test->pass) ? null : intval($test->pass);
+
 				$data["test"] = [
-					"id" => $test->id,
+					"id" => (int) $test->id,
+					"pass" => $pass,
 					"formattedStartDts" => $formatted_start_dts,
 					"formattedDueDts" => $formatted_due_dts,
 					"tester" => null,
 					"pastDue" => $past_due,
 				];
 
+				if($project) {
+					$data["test"]["project"] = [
+						"id" => (int) $project->id,
+						"name" => $project->name,
+					];
+				}
+
 				if($tester) {
 					$data["test"]["tester"] = [
-						"id" => $tester->id,
+						"id" => (int) $tester->id,
 						"name" => $tester->getDisplayName(),
 					];
 				}
 			}
-			
+
 			$output[] = $data;
 		}
 

+ 53 - 9
public/js/app-user.js

@@ -139,16 +139,60 @@ function initialiseLocations() {
 
 
 			// Add to list group
-			let listGroupItem = $("div[data-nearby-location-list-group-item-template]").clone();
-			listGroupItem.removeAttr("data-nearby-location-list-group-item-template");
+			let lgi = $("div[data-nearby-location-list-group-item-template]").clone();
+			lgi.removeAttr("data-nearby-location-list-group-item-template");
 
-			listGroupItem.find("a[data-location-name]").text(location.name);
-			listGroupItem.find("span[data-location-distance]").text(location.distance + " miles");
-			listGroupItem.find("span[data-location-id]").text(location.id);
-			listGroupItem.find("span[data-location-internal-id]").text(location.internalId);
-			listGroupItem.find("small[data-location-address]").text(location.address);
+			lgi.find("a[data-location-name]").text(location.name);
+			lgi.find("span[data-location-distance]").text(location.distance + " miles");
+			lgi.find("span[data-location-id]").text(location.id);
+			lgi.find("span[data-location-internal-id]").text(location.internalId);
+			lgi.find("small[data-location-address]").text(location.address);
 
-			listGroupItem.appendTo("#nearby-locations-list-group").show();
+			if(location.test) {
+				let test = location.test;
+				let tester = test.tester;
+				let project = test.project;
+
+				lgi.find("div[data-test-container]").removeClass("d-none");
+				lgi.find("div[data-test-id-container] a").text(test.id).attr("href", "/account/tests/" + test.id);
+				lgi.find("div[data-test-project-name-container] a").text(project.name).attr("href", "/account/projects/" + project.id);
+
+				if(tester) {
+					lgi.find("div[data-test-user-name-container] a").text(tester.name).attr("href", "/account/users/" + tester.id);
+
+					let passText = "";
+					let passClass = "";
+
+					if(test.pass === null) {
+						passText = "Pending";
+						passClass = "warning";
+						lgi.find("div[data-test-due-dts-container]").removeClass("d-none").find("span").text(test.formattedDueDts);
+
+						if(test.pastDue) {
+							lgi.find("div[data-test-due-dts-container]").append(" <span class=\"badge badge-danger\">Overdue</span>");
+						}
+					}
+					else if(test.pass === 0) {
+						passText = "Fail";
+						passClass = "danger";
+					}
+					else if(test.pass === 1) {
+						passText = "Pass";
+						passClass = "success";
+					}
+
+					if(test.pass !== null) {
+						lgi.find("div[data-test-start-dts-container]").removeClass("d-none").find("span").text(test.formattedStartDts);
+					}
+
+					lgi.find("div[data-test-pass-container] span").addClass("text-" + passClass).text(passText);
+
+				}
+
+
+			}
+
+			lgi.appendTo("#nearby-locations-list-group").show();
 
 			addMarkerClickListenerForLocation(marker, location);
 
@@ -188,7 +232,7 @@ function addMarkerClickListenerForLocation(m, l) {
 
 			let pastDueBadge = '';
 			if(l.test.pastDue) {
-				pastDueBadge = '<span class="badge badge-lg badge-primary">Past Due</span>';
+				pastDueBadge = '<span class="badge badge-lg badge-primary">Overdue</span>';
 			}
 
 			if(l.test.formattedDueDts) {

+ 20 - 1
views/user.php

@@ -304,12 +304,31 @@ var userId = <?=$user->id?>;
 									<a href="#" data-location-name>Location Name</a>
 								</div>
 								<div class="col-md-auto">
-									Distance: <span data-location-distance></span>
+									<span data-location-distance></span>
 								</div>
 							</div>
 							<span class="badge badge-primary">ID: <span data-location-id>123</span></span>
 							<span class="badge badge-info">Internal ID: <span data-location-internal-id>123</span></span><br />
 							<small data-location-address>Address</small>
+							<div class="d-none mt-2 small" data-test-container>
+								<div class="card card-body p-2">
+									<div><strong>Latest Test Details</strong></div>
+									<div class="row">
+										<div class="col-md">
+											<div data-test-id-container><strong>ID:</strong> <a data-test-id></a></div>
+											<div data-test-project-name-container><strong>Project:</strong> <a data-project-name></a></div>
+											<div class="d-none" data-test-user-name-container><strong>Tester:</strong> <a></a></div>
+										</div>
+										<div class="col-md">
+											<div class="d-none" data-test-start-dts-container><strong>Tested:</strong> <span></span></div>
+											<div class="d-none" data-test-due-dts-container><strong>Due:</strong> <span></span></div>
+											<div data-test-pass-container><strong>Result:</strong> <span></span></div>
+										</div>
+									</div>
+
+
+								</div>
+							</div>
 						</div>
 
 					</div>