Przeglądaj źródła

Add date range picker to Nearby Locations tab

Alan Lam 7 lat temu
rodzic
commit
7cc63fd1fb
3 zmienionych plików z 38 dodań i 12 usunięć
  1. 4 0
      controllers/user_ajax.php
  2. 18 1
      public/js/app-user.js
  3. 16 11
      views/user.php

+ 4 - 0
controllers/user_ajax.php

@@ -34,6 +34,9 @@ switch($action) {
 		$max_distance = http::value("max_distance", "int");
 		if($max_distance <= 0) $max_distance = 50;
 
+		$date_start = http::value("date_start", "db");
+		$date_end = http::value("date_end", "db");
+
 		$address = UserAddress::queryOne([
 			"id" => $address_id,
 			"user_id" => $id,
@@ -67,6 +70,7 @@ switch($action) {
 		// Get tests
 		$tests = Test::query([
 			"status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
+			"dts_start" => (new Constraint("BETWEEN"))->setValues($date_start, $date_end),
 			"location_id" => array_column($locations, "id")
 		]);
 

+ 18 - 1
public/js/app-user.js

@@ -24,6 +24,21 @@ $(function() {
 		initialiseLocations();
 	});
 
+	$("#date-range").daterangepicker({
+		locale: {
+			format: "DD/MM/YYYY"
+		}
+	}, function(start, end, label) {
+
+		var startValue = start.format('YYYY-MM-DD');
+		var endValue = end.format('YYYY-MM-DD');
+
+		$("#date-start").val(startValue);
+		$("#date-end").val(endValue);
+
+		initialiseLocations();
+	});
+
 });
 
 function initialiseAddresses() {
@@ -83,7 +98,9 @@ function initialiseLocations() {
 	let map = maps["nearby-locations-map"];
 
 	$.get("/api/users/" + userId + "/get-locations", {
-		"address_id": $("#address-id").val()
+		"address_id": $("#address-id").val(),
+		"date_start": $("#date-start").val(),
+		"date_end": $("#date-end").val()
 	}, function(response) {
 		if(!response.success) return false;
 		if(!response.locations) return false;

+ 16 - 11
views/user.php

@@ -28,10 +28,12 @@ if($referrer) {
 	$details["Referrer"] = "<a href=\"/account/users/$referrer->id\">" . htmlspecialchars($referrer->getDisplayName()) . "</a>";
 }
 
-
 $pending_tests = $user->getPendingTests();
 $completed_tests = $user->getCompletedTests();
 
+$year = date("Y");
+$date_range = "01/01/{$year} - 31/12/{$year}";
+
 ?>
 <script>
 var userId = <?=$user->id?>;
@@ -336,7 +338,18 @@ var userId = <?=$user->id?>;
 
 					</div>
 					<div class="col-lg-6 mb-4">
-						<h3><?=date("Y")?> Tests</h3>
+						<h3>Tests</h3>
+
+						<div class="input-group mb-3">
+							<div class="input-group-prepend">
+								<span class="input-group-text">Date Range</span>
+							</div>
+							<input class="form-control" type="text" id="date-range" value="<?=$date_range?>" />
+						</div>
+
+						<input type="hidden" id="date-start" name="date_start" value="<?=date("Y")?>-01-01" />
+						<input type="hidden" id="date-end" name="date_end" value="<?=date("Y")?>-12-31" />
+
 						<div id="nearby-locations-map" style="height: 480px;" data-maps data-lat="<?=$address->latitude?>" data-lng="<?=$address->longitude?>" data-zoom="10">
 					</div>
 					</div>
@@ -344,14 +357,6 @@ var userId = <?=$user->id?>;
 				<?php
 			}
 			?>
-
-
-
 		</div>
 	</div>
-
-
-
-
-
-</div>
+</div>