Преглед изворни кода

Add filters for untested/failed locations on map overview page

Alan Lam пре 3 година
родитељ
комит
a9969136bc

+ 3 - 1
controllers/map_overview.php

@@ -24,6 +24,8 @@ $projects = Project::query([
 	"sort" => "dts_deadline"
 ]);
 
+$filter = http::value("filter");
+
 View::includeOnce("header", compact("page_title"));
-View::include("map_overview", compact("customers", "projects"));
+View::include("map_overview", compact("customers", "projects", "filter"));
 View::includeOnce("footer");

+ 12 - 1
controllers/map_overview_ajax.php

@@ -17,11 +17,22 @@ if($submit) {
 
 		Core::validateCSRFToken($submit);
 
+		$options = [];
+
+		$filter = http::value("filter");
+		if($filter === "untested-only") {
+			$options["untested_only"] = true;
+		}
+		if($filter === "failed-only") {
+			$options["failed_only"] = true;
+		}
+
 		switch($action) {
 
 			// Gets all locations for a customer
 			case "get-customer-locations": {
 
+
 				// Input
 				$customer_id = http::value("customer_id", "int");
 
@@ -37,7 +48,7 @@ if($submit) {
 				// Get locations
 				$locations = $customer->getLocations(["archived" => 0]);
 
-				$output = LocationHelper::getMarkerDataForLocations($locations, $min_date, $max_date);
+				$output = LocationHelper::getMarkerDataForLocations($locations, $min_date, $max_date, $options);
 
 				if($min_date && $max_date) {
 					if(preg_match($date_format, $min_date) && preg_match($date_format, $max_date)) {

+ 13 - 1
engine/helpers/location_helper.php

@@ -21,12 +21,15 @@ class LocationHelper {
 	 * @return array
 	 * @throws Exception
 	 */
-	public static function getMarkerDataForLocations(array $locations, ?string $min_date, ?string $max_date): array {
+	public static function getMarkerDataForLocations(array $locations, ?string $min_date, ?string $max_date, array $options = []): array {
 
 		if(empty($locations)) {
 			return [];
 		}
 
+		$failed_only = $options["failed_only"] ?? false;
+		$untested_only = $options["untested_only"] ?? false;
+
 		$location = reset($locations);
 
 		$customer = $location->getCustomer();
@@ -184,6 +187,7 @@ class LocationHelper {
 					"formattedDueDts" => $formatted_due_dts,
 					"tester" => null,
 					"pastDue" => $past_due,
+					"passed" => $test->isPass(),
 				];
 
 				if($tester) {
@@ -197,6 +201,14 @@ class LocationHelper {
 			$output[] = $data;
 		}
 
+		if($failed_only) {
+			$output = array_values(array_filter($output, static fn($test) => isset($test["test"]) && !$test["test"]["passed"]));
+		}
+
+		if($untested_only) {
+			$output = array_values(array_filter($output, static fn($test) => $test["test"] === null));
+		}
+
 		return $output;
 	}
 

+ 44 - 1
public/js/app-map-overview.js

@@ -18,8 +18,10 @@ $(function() {
 	const $hideInactiveTestersSwitch = $("#hide-inactive-testers");
 	$hideInactiveTestersSwitch.on("change", () => loadAllAddresses());
 
+	const $customerRows = $("a[data-customer-id]");
+
 	// On customer select
-	$("a[data-customer-id]").on("click", function() {
+	$customerRows.on("click", function() {
 		let customerId = $(this).data("customer-id");
 
 		let key = "customer-" + customerId;
@@ -93,6 +95,46 @@ $(function() {
 
 	});
 
+	const filter = $("input[name=filter]:checked").val();
+	if(filter) {
+		$customerRows.each((index, element) => {
+			setTimeout(() => {
+				$(element).trigger("click");
+			}, index * 250);
+		})
+	}
+
+	const $toggleAllCustomers = $("#toggle-all-customers");
+	$toggleAllCustomers.on("click", event => {
+		event.preventDefault();
+
+		const $firstRow = $customerRows.eq(0);
+		const selected = $firstRow.data("selected");
+		if(!selected) {
+			let loadCount = 0;
+			$customerRows.each((index, element) => {
+				const $row = $(element);
+				const selected = $row.data("selected");
+				if(!selected) {
+					setTimeout(() => {
+						$row.trigger("click");
+					}, loadCount * 250);
+					loadCount++;
+				}
+			});
+		}
+		else {
+			$customerRows.each((index, element) => {
+				const $row = $(element);
+				const selected = $row.data("selected");
+				if(selected) {
+					$row.trigger("click");
+				}
+			});
+		}
+	});
+
+
 });
 
 function loadCustomerLocations(customerId) {
@@ -117,6 +159,7 @@ function loadCustomerLocations(customerId) {
 		customer_id: customerId,
 		min_date: minDate,
 		max_date: maxDate,
+		filter: $("input[name=filter]:checked").val(),
 		submit: $("#submit").val()
 	}, function(response) {
 		if(!response.success) return false;

+ 28 - 1
views/map_overview.php

@@ -2,6 +2,7 @@
 /**
  * @var Customer[] $customers
  * @var Project[] $projects
+ * @var string $filter
  */
 ?>
 <div class="container mt-3 py-4">
@@ -34,6 +35,22 @@
 		</div>
 	</div>
 
+	<div class="form-group">
+		<label>Filter</label><br />
+		<div class="form-check form-check-inline">
+			<input class="form-check-input" type="radio" name="filter" id="filter-all" value="" <?=HtmlHelper::checked(!$filter)?> />
+			<label class="form-check-label" for="filter-all">Any</label>
+		</div>
+		<div class="form-check form-check-inline">
+			<input class="form-check-input" type="radio" name="filter" id="filter-untested-only" value="untested-only" <?=HtmlHelper::checked($filter === "untested-only")?> />
+			<label class="form-check-label" for="filter-untested-only">Untested Only</label>
+		</div>
+		<div class="form-check form-check-inline">
+			<input class="form-check-input" type="radio" name="filter" id="filter-failed-only" value="failed-only" <?=HtmlHelper::checked($filter === "failed-only")?>/>
+			<label class="form-check-label" for="filter-failed-only">Failed Only</label>
+		</div>
+	</div>
+
 	<div class="form-row mb-4">
 		<div class="col-md">
 			<div class="mb-4" id="map" data-maps data-lat="51.3555177" data-lng="-1.1743197" data-zoom="7" style="height: 512px;"></div>
@@ -78,7 +95,17 @@
 				</div>
 			</section>
 
-			<h3>Customers</h3>
+			<div class="row align-items-center mb-3">
+				<div class="col">
+					<h3 class="mb-0">
+						Customers
+					</h3>
+				</div>
+				<div class="col-auto">
+					<a id="toggle-all-customers" href="#">Toggle All</a>
+				</div>
+			</div>
+
 			<div class="list-group d-block">
 			<?php
 			foreach($customers as $customer) {