1
0
Эх сурвалжийг харах

Add support for test date range in Map Overview

Alan Lam 7 жил өмнө
parent
commit
504dc39777

+ 19 - 2
controllers/map_overview_ajax.php

@@ -20,10 +20,27 @@ if($submit) {
 
 				$locations = $customer->getLocations();
 
-				$tests = Test::query([
+				$min_date = http::value("min_date");
+				$max_date = http::value("max_date");
+
+				$nvp = [
 					"status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
 					"location_id" => array_column($locations, "id")
-				]);
+				];
+
+				$date_format = "/^2[0-9]{3}\-[0-1][0-9]\-[0-3][0-9]$/";
+
+				if($min_date && preg_match($date_format, $min_date)) {
+					$min_dts = "{$min_date} 00:00:00";
+					$nvp["dts_start"] = (new Constraint("MORE_THAN_OR_EQUAL"))->setValues($min_dts);
+				}
+
+				if($max_date && preg_match($date_format, $max_date)) {
+					$max_dts = "{$max_date} 23:59:59";
+					$nvp["dts_start"] = (new Constraint("LESS_THAN_OR_EQUAL"))->setValues($max_dts);
+				}
+
+				$tests = Test::query($nvp);
 
 				$location_test_array = [];
 				foreach($tests as $test) {

+ 10 - 0
public/js/app-map-overview.js

@@ -79,8 +79,13 @@ function loadCustomerLocations(customerId) {
 		infoWindow = new google.maps.InfoWindow();
 	}
 
+	let minDate = $("#min-date").val();
+	let maxDate = $("#max-date").val();
+
 	$.get("/account/map-overview/get-customer-locations", {
 		customer_id: customerId,
+		min_date: minDate,
+		max_date: maxDate,
 		submit: $("#submit").val()
 	}, function(response) {
 		if(!response.success) return false;
@@ -127,8 +132,13 @@ function loadProjectLocations(projectId) {
 		infoWindow = new google.maps.InfoWindow();
 	}
 
+	let minDate = $("#min-date").val();
+	let maxDate = $("#max-date").val();
+
 	$.get("/account/map-overview/get-project-locations", {
 		project_id: projectId,
+		min_date: minDate,
+		max_date: maxDate,
 		submit: $("#submit").val()
 	}, function(response) {
 		if(!response.success) return false;

+ 21 - 7
views/map_overview.php

@@ -4,16 +4,30 @@
 
 	<h2>Map Overview</h2>
 
-	<div class="input-group">
-		<div class="input-group-prepend">
-			<span class="input-group-text">Location</span>
+	<div class="row">
+		<div class="col-6">
+			<div class="form-group">
+				<label for="location">Location</label>
+				<input type="text" class="form-control" id="location" placeholder="Type location" data-autocomplete="map" />
+				<div class="help-text text-muted">
+					<small>Type location and select to jump to location.</small>
+				</div>
+			</div>
+		</div>
+		<div class="col-3">
+			<div class="form-group">
+				<label for="min-date">Min Test Date</label>
+				<input type="date" class="form-control" id="min-date" placeholder="Type date" value="<?=date("Y")?>-01-01" />
+			</div>
+		</div>
+		<div class="col-3">
+			<div class="form-group">
+				<label for="min-date">Max Test Date</label>
+				<input type="date" class="form-control" id="min-date" placeholder="Type date" value="<?=date("Y")?>-12-31" />
+			</div>
 		</div>
-		<input type="text" class="form-control" placeholder="Type location" data-autocomplete="map" />
 	</div>
 
-	<div class="help-text text-muted mb-3">
-		<small>Type location and select to jump to location.</small>
-	</div>
 
 	<div class="mb-4" id="map" data-maps data-lat="51.3555177" data-lng="-1.1743197" data-zoom="7" style="height: 512px;"></div>