Alan Lam 8 лет назад
Родитель
Сommit
61ed83e85a
3 измененных файлов с 68 добавлено и 3 удалено
  1. 1 1
      controllers/project_ajax.php
  2. 49 2
      public/js/app-project.js
  3. 18 0
      views/project.php

+ 1 - 1
controllers/project_ajax.php

@@ -23,7 +23,6 @@ if($submit) {
 
 				$locations = Location::load(array_column($tests, "location_id"));
 
-
 				$location_tests = [];
 
 				foreach($tests as $test) {
@@ -60,6 +59,7 @@ if($submit) {
 
 					$output[] = (object) [
 						"id" => (int) $location->id,
+						"internalId" => $location->internal_id,
 						"testId" => (int) $test_id,
 						"name" => $location->name,
 						"address" => $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]),

+ 49 - 2
public/js/app-project.js

@@ -21,6 +21,41 @@ $(function() {
 		console.log(assignLatLngBounds);
 		maps["assign-map"].fitBounds(assignLatLngBounds);
 	});
+	$("input[data-filter-target]").keyup(function(event) {
+
+		let value = $(this).val().toLowerCase();
+		let target = $(this).data("filter-target");
+
+		if(value.length == 0) {
+			$(target).children().show();
+			return true;
+		}
+
+		$(target).children().each(function() {
+
+			let number = parseInt(value);
+			var show;
+			if(isNaN(number)) {
+				show = $(this).data("filter-value").indexOf(value) != -1;
+			}
+			else {
+				let test1 = (number == $(this).data("location-id"));
+				let test2 = (number == $(this).data("internal-id"));
+				let test3 = (number == $(this).data("tester-id"));
+
+				show = test1 || test2 || test3;
+			}
+
+			if(show) {
+				$(this).show();
+			}
+			else {
+				$(this).hide();
+			}
+		});
+
+		return true;
+	});
 });
 
 function initialiseLocations() {
@@ -75,11 +110,20 @@ function initialiseLocations() {
 
 			locationMarkers.push(marker);
 
+			var filterValueParts = [location.name, location.address];
+			var filterValue = filterValueParts.join("").toLowerCase();
+
 			// Populate table
-			var tr = $("<tr data-location-id=\"" + location.id + "\" data-latitude=\"" + location.latitude + "\" data-longitude=\"" + location.longitude + "\"></tr>");
+			var tr = $("<tr data-location-id=\"" + location.id + "\" data-internal-id=\"" + location.internalId + "\" data-latitude=\"" + location.latitude + "\" data-longitude=\"" + location.longitude + "\" data-filter-value=\"" + filterValue + "\"></tr>");
 
 			var a = $("<a>").attr("href", "/account/locations/" + location.id).attr("target", "_blank").text(location.name);
 
+			if(location.internalId) {
+				var small = $("<small>").text("(Internal ID: " + location.internalId + ")");
+				a.append(" ");
+				a.append(small);
+			}
+
 			var td = $("<td></td>");
 			td.append(a);
 			td.append("<br />");
@@ -214,7 +258,10 @@ function initialiseTesters() {
 
 			testerMarkers.push(marker);
 
-			var tr = $("<tr data-tester-id=\"" + tester.id + "\" data-address-id=\"" + tester.addressId + "\"></tr>");
+			var filterValueParts = [tester.name];
+			var filterValue = filterValueParts.join("").toLowerCase();
+
+			var tr = $("<tr data-tester-id=\"" + tester.id + "\" data-address-id=\"" + tester.addressId + "\" data-filter-value=\"" + filterValue + "\"></tr>");
 
 			var td = $("<td></td>");
 			td.append("<a href=\"/account/users/" + tester.id + "\" target=\"_blank\">" + tester.name + "</a>");

+ 18 - 0
views/project.php

@@ -105,6 +105,15 @@ var projectID = <?=$project->id?>;
 
 			<h3>Tests</h3>
 
+			<div class="input-group mb-3">
+				<div class="input-group-prepend">
+					<span class="input-group-text">
+						Filter
+					</span>
+				</div>
+				<input class="form-control" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#tests-tbody" />
+			</div>
+
 			<table class="table table-hover table-sm">
 				<thead>
 					<tr>
@@ -127,6 +136,15 @@ var projectID = <?=$project->id?>;
 
 			<h3>Testers</h3>
 
+			<div class="input-group mb-3">
+				<div class="input-group-prepend">
+					<span class="input-group-text">
+						Filter
+					</span>
+				</div>
+				<input class="form-control" type="text" placeholder="Enter name or ID" data-filter-target="#testers-tbody" />
+			</div>
+
 			<table class="table table-hover table-sm">
 				<thead>
 					<tr>