Răsfoiți Sursa

Add ability to hide tested locations on map

Alan Lam 4 ani în urmă
părinte
comite
b42fb83c6c

+ 8 - 0
controllers/customer_ajax.php

@@ -29,6 +29,7 @@ switch($action) {
 		$legal_entity_name = http::value("legal_entity_name", "trim");
 		$include_archived = http::value("include_archived", "int");
 		$include_closed = http::value("include_closed", "int");
+		$hide_tested = Http::value("hide_tested", "int");
 		$min_date = http::value("min_date");
 		$max_date = http::value("max_date");
 
@@ -43,6 +44,13 @@ switch($action) {
 
 		$output = LocationHelper::getMarkerDataForLocations($locations, $min_date, $max_date);
 
+		if($hide_tested) {
+			$output = array_filter($output, static function(array $result) {
+				return !isset($result["test"]);
+			});
+			$output = array_values($output);
+		}
+
 		JSON::success([
 			"locations" => $output
 		]);

+ 18 - 2
controllers/locations.php

@@ -36,8 +36,13 @@ $ids = http::value("ids", "int");
 $internal_id = http::value("internal_id", "trim");
 $name = http::value("name", "trim");
 $legal_entity_name = http::value("legal_entity_name", "trim");
+
+$min_date = http::value("min_date");
+$max_date = http::value("max_date");
+
 $include_archived = (int) http::value("include_archived");
 $include_closed = (int) http::value("include_closed");
+$hide_tested = (int) http::value("hide_tested");
 
 $filter_count = 0;
 
@@ -80,6 +85,18 @@ else {
 	$where_strings[] = "`location`.`closed`='0'";
 }
 
+if($min_date) {
+	$filter_count++;
+}
+
+if($max_date) {
+	$filter_count++;
+}
+
+if($hide_tested) {
+	$filter_count++;
+}
+
 $sort = http::value("sort");
 switch($sort) {
 	case "last-added":
@@ -108,7 +125,6 @@ if($where_strings) {
 	$where_string = "AND " . implode(" AND ", $where_strings);
 }
 
-
 [$date_start, $date_end] = $customer->getYearCycleDates();
 
 $sql = "SELECT `location`.*, COUNT(`test`.`id`) AS `test_count`, SUM(IF(`test`.`retest` = 1, 1, 0)) AS `retest_count` 
@@ -145,6 +161,6 @@ if(!empty($action)) {
 }
 
 View::includeOnce("header", compact("page_title"));
-View::include("locations", compact("customer", "include_archived", "include_closed", "filter_count", "sorts", "sort", "locations"));
+View::include("locations", compact("customer", "include_archived", "include_closed", "hide_tested", "filter_count", "sorts", "sort", "locations"));
 View::include("modal_add_locations_to_project", compact("customer"));
 View::includeOnce("footer");

+ 4 - 0
engine/html_helper.php

@@ -2,6 +2,10 @@
 
 class HtmlHelper {
 
+	public static function checked(?string $value): string {
+		return $value ? "checked" : "";
+	}
+
 	public static function selected(?string $value, ?string $selected): string {
 		return ((string) $value === (string) $selected) ? "selected" : "";
 	}

+ 4 - 6
public/js/app-locations.js

@@ -13,16 +13,14 @@ function initialiseLocations() {
 		infoWindow = new google.maps.InfoWindow();
 	}
 
-	const includeArchived = $("#include-archived").prop("checked") ? 1 : 0;
-	const includeClosed = $("#include-closed").prop("checked") ? 1 : 0;
-
 	$.get(`/api/customers/${customerId}/get-locations`, {
 		id: $("#id").val(),
 		internal_id: $("#internal-id").val(),
 		name: $("#name").val(),
 		legal_entity_name: $("#legal-entity-name").val(),
-		include_archived: includeArchived,
-		include_closed: includeClosed,
+		include_archived: $("#include-archived").prop("checked") ? 1 : 0,
+		include_closed: $("#include-closed").prop("checked") ? 1 : 0,
+		hide_tested: $("#hide-tested").prop("checked") ? 1 : 0,
 		min_date: $("#min-date").val(),
 		max_date: $("#max-date").val(),
 	}, function(response) {
@@ -258,7 +256,7 @@ class AddLocationsToProjectModal {
 		this.$projectDropdown = this.$form.find("[name=project_id]");
 	}
 
-	onShow(event) {
+	onShow() {
 		this.$form.find(`input[name="location_ids[]"]`).remove();
 
 		exportIds.forEach(locationId => {

+ 10 - 5
views/locations.php

@@ -4,6 +4,7 @@
  * @var Customer $customer
  * @var int $include_archived
  * @var int $include_closed
+ * @var int $hide_tested
  * @var int $filter_count
  * @var string[] $sorts
  * @var string $sort
@@ -14,9 +15,6 @@ $query = $_GET;
 unset($query["path"]);
 $query["sort"] = "SORT";
 
-$include_archived_checked = $include_archived ? "checked" : "";
-$include_closed_checked = $include_closed ? "checked" : "";
-
 ?>
 
 <script>
@@ -133,17 +131,24 @@ var customerId = <?=$customer->id?>;
 								<div class="form-group">
 									<div class="custom-control custom-switch">
 										<input class="custom-control-input" id="include-archived" name="include_archived"
-											   type="checkbox" value="1" <?=$include_archived_checked?> />
+											   type="checkbox" value="1" <?=HtmlHelper::checked($include_archived)?> />
 										<label class="custom-control-label"
 											   for="include-archived"><?= htmlspecialchars(__("Include Archived")) ?></label>
 									</div>
 									<div class="custom-control custom-switch">
 										<input class="custom-control-input" id="include-closed" name="include_closed"
 											   type="checkbox"
-											   value="1" <?=$include_closed_checked?> />
+											   value="1" <?=HtmlHelper::checked($include_closed)?> />
 										<label class="custom-control-label"
 											   for="include-closed"><?= htmlspecialchars(__("Include Closed")) ?></label>
 									</div>
+									<div class="custom-control custom-switch">
+										<input class="custom-control-input" id="hide-tested" name="hide_tested"
+											   type="checkbox"
+											   value="1" <?=HtmlHelper::checked($hide_tested)?>/>
+										<label class="custom-control-label"
+											   for="hide-tested"><?= htmlspecialchars(__("Hide Tested On Map")) ?></label>
+									</div>
 								</div>
 
 								<button class="btn btn-primary" type="submit">Submit</button>