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

Colour-coded markers depending on their test status.

Alan Lam 8 лет назад
Родитель
Сommit
0df4f09a4f

+ 48 - 5
controllers/map_overview_ajax.php

@@ -20,17 +20,58 @@ if($submit) {
 
 				$locations = $customer->getLocations();
 
-				$filename = str_replace("-", "_", Util::slug($customer->name));
+				$tests = Test::query([
+					"status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
+					"location_id" => array_column($locations, "id")
+				]);
+
+				$location_test_array = [];
+				foreach($tests as $test) {
+					$exists = isset($location_test_array[$test->location_id]);
+					if(!$exists) {
+						$location_test_array[$test->location_id] = $test;
+					}
+					else {
+						$existing = $location_test_array[$test->location_id];
+
+						$unix_start_existing = is_null($existing->dts_start) ? 0 : strtotime($existing->dts_start . " UTC");
+						$unix_start_current = is_null($test->dts_start) ? 0 : strtotime($test->dts_start . " UTC");
 
-				$icon = null;
-				if(file_exists("public/img/markers/$filename.png")) {
-					$icon = "/img/markers/$filename.png";
+						if($unix_start_current > $unix_start_existing) {
+							$location_test_array[$test->location_id] = $test;
+						}
+					}
 				}
 
 				$output = [];
 
 				foreach($locations as $location) {
-					$output[] = [
+
+					$test = $location_test_array[$location->id] ?? false;
+
+					$customer_slug = str_replace("-", "_", Util::slug($customer->name));
+
+					$icon = null;
+					$icon_file = "{$customer_slug}_none.png";
+
+					if($test) {
+						if(is_null($test->pass)) {
+							$icon_file = "{$customer_slug}_pending.png";
+						}
+						else if($test->pass) {
+							$icon_file = "{$customer_slug}_pass.png";
+						}
+						else if(!$test->pass) {
+							$icon_file = "{$customer_slug}_fail.png";
+						}
+					}
+
+
+					if($icon_file && file_exists("public/img/markers/$icon_file")) {
+						$icon = $icon_file;
+					}
+
+					$data = [
 						"id" => (int) $location->id,
 						"internalId" => $location->internal_id,
 						"name" => $location->name,
@@ -38,6 +79,8 @@ if($submit) {
 						"longitude" => (float) $location->longitude,
 						"icon" => $icon
 					];
+
+					$output[] = $data;
 				}
 
 				JSON::success([

BIN
public/img/markers/bacta_fail.png


BIN
public/img/markers/bacta_none.png


BIN
public/img/markers/bacta_pass.png


BIN
public/img/markers/bacta_pending.png


BIN
public/img/markers/praesepe_fail.png


BIN
public/img/markers/praesepe_none.png


BIN
public/img/markers/praesepe_pass.png


BIN
public/img/markers/praesepe_pending.png


+ 2 - 2
public/js/app-map-overview.js

@@ -104,7 +104,7 @@ function loadCustomerLocations(customerId) {
 				map: map
 			};
 
-			if(l.icon) options.icon = l.icon;
+			if(l.icon) options.icon = "/img/markers/" + l.icon;
 
 			infoWindow.setContent("");
 
@@ -153,7 +153,7 @@ function loadProjectLocations(projectId) {
 				map: map
 			};
 
-			if(l.icon) options.icon = l.icon;
+			if(l.icon) options.icon = "/img/markers/" + l.icon;
 
 			let marker = new google.maps.Marker(options);
 			addMarkerClickListenerForLocation(marker, l);