소스 검색

Added quick filters.

Alan Lam 8 년 전
부모
커밋
3aadabb0f1
2개의 변경된 파일과 131개의 추가작업 그리고 36개의 파일을 삭제
  1. 35 0
      public/js/app-project-form.js
  2. 96 36
      views/project_form.php

+ 35 - 0
public/js/app-project-form.js

@@ -5,6 +5,41 @@ $(function() {
 	$(document).on("click", "#not-selected-locations-list-group button", handleSelectButton);
 	$(document).on("click", "#not-selected-locations-list-group button", handleSelectButton);
 	$(document).on("click", "#selected-locations-list-group button", handleDeselectButton);
 	$(document).on("click", "#selected-locations-list-group button", handleDeselectButton);
 
 
+	$("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"));
+
+				show = test1 || test2;
+			}
+
+			if(show) {
+				$(this).show();
+			}
+			else {
+				$(this).hide();
+			}
+		});
+
+		return true;
+	});
+
 });
 });
 
 
 function handleSelectButton() {
 function handleSelectButton() {

+ 96 - 36
views/project_form.php

@@ -108,54 +108,114 @@ $date_deadline = explode(" ", $project->dts_deadline)[0];
 		<div class="row">
 		<div class="row">
 			<div class="col-md mb-3">
 			<div class="col-md mb-3">
 				<h4>Selected</h4>
 				<h4>Selected</h4>
-				<div class="list-group" id="selected-locations-list-group">
-				<?php
-				foreach($locations as $index => $location) {
-					if(!in_array($location->id, $location_ids)) continue;
-					?>
-					<div class="list-group-item" data-location-id="<?=$location->id?>" data-name="<?=htmlspecialchars($location->name)?>">
-						<div class="row">
-							<div class="col-auto">
-								<?=htmlspecialchars($location->name)?><br />
-								<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]))?></small>
-							</div>
-							<div class="col align-self-center text-right">
-								<button class="btn btn-outline-danger" type="button">Deselect</button>
+
+				<div class="card">
+
+					<div class="card-body">
+						<div class="input-group">
+							<div class="input-group-prepend">
+								<span class="input-group-text">
+									Filter
+								</span>
 							</div>
 							</div>
+							<input class="form-control" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#selected-locations-list-group" />
+						</div>
+
+						<div class="alert alert-info mt-3 mb-0" id="selected-locations-alert">
+							No locations selected for testing.
 						</div>
 						</div>
 					</div>
 					</div>
+
+					<div class="list-group list-group-flush" id="selected-locations-list-group">
 					<?php
 					<?php
-				}
-				?>
-				</div>
-				<div class="alert alert-info" id="selected-locations-alert">
-					No locations selected for testing.
+					foreach($locations as $index => $location) {
+						if(!in_array($location->id, $location_ids)) continue;
+
+						$address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
+
+						$filter_parts = array_filter([
+							$address, $location->name
+						]);
+						$filter = strtolower(implode("", $filter_parts));
+						?>
+						<div class="list-group-item" data-location-id="<?=$location->id?>" data-internal-id="<?=htmlspecialchars($location->internal_id)?>" data-name="<?=htmlspecialchars($location->name)?>" data-filter-value="<?=htmlspecialchars($filter)?>">
+							<div class="row">
+								<div class="col-auto">
+									<?=htmlspecialchars($location->name)?>
+									<?php
+									if($location->internal_id) {
+										?>
+										<small>(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
+										<?php
+									}
+									?><br />
+									<small><?=htmlspecialchars($address)?></small>
+								</div>
+								<div class="col align-self-center text-right">
+									<button class="btn btn-outline-danger" type="button">Deselect</button>
+								</div>
+							</div>
+						</div>
+						<?php
+					}
+					?>
+					</div>
 				</div>
 				</div>
 			</div>
 			</div>
 			<div class="col-md mb-3">
 			<div class="col-md mb-3">
 				<h4>Not Selected</h4>
 				<h4>Not Selected</h4>
-				<div class="list-group" id="not-selected-locations-list-group">
-				<?php
-				foreach($locations as $index => $location) {
-					if(in_array($location->id, $location_ids)) continue;
-					?>
-					<div class="list-group-item" data-location-id="<?=$location->id?>" data-name="<?=htmlspecialchars($location->name)?>">
-						<div class="row">
-							<div class="col-auto">
-								<?=htmlspecialchars($location->name)?><br />
-								<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]))?></small>
-							</div>
-							<div class="col align-self-center text-right">
-								<button class="btn btn-outline-success" type="button">Select</button>
+
+
+				<div class="card">
+					<div class="card-body">
+						<div class="input-group">
+							<div class="input-group-prepend">
+								<span class="input-group-text">
+									Filter
+								</span>
 							</div>
 							</div>
+							<input class="form-control" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#not-selected-locations-list-group" />
+						</div>
+						<div class="alert alert-info mt-3 mb-0" id="not-selected-locations-alert">
+							No additional locations are available for testing.
 						</div>
 						</div>
 					</div>
 					</div>
+
+					<div class="list-group list-group-flush" id="not-selected-locations-list-group">
 					<?php
 					<?php
-				}
-				?>
-				</div>
-				<div class="alert alert-info" id="not-selected-locations-alert">
-					No additional locations are available for testing.
+					foreach($locations as $index => $location) {
+						if(in_array($location->id, $location_ids)) continue;
+
+						$address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
+
+						$filter_parts = array_filter([
+							$address, $location->name
+						]);
+						$filter = strtolower(implode("", $filter_parts));
+						?>
+						<div class="list-group-item" data-location-id="<?=$location->id?>" data-internal-id="<?=htmlspecialchars($location->internal_id)?>" data-name="<?=htmlspecialchars($location->name)?>" data-filter-value="<?=htmlspecialchars($filter)?>">
+							<div class="row">
+								<div class="col-auto">
+									<?=htmlspecialchars($location->name)?>
+									<?php
+									if($location->internal_id) {
+										?>
+										<small>(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
+										<?php
+									}
+									?>
+									<br />
+									<small><?=htmlspecialchars($address)?></small>
+								</div>
+								<div class="col align-self-center text-right">
+									<button class="btn btn-outline-success" type="button">Select</button>
+								</div>
+							</div>
+						</div>
+						<?php
+					}
+					?>
+					</div>
 				</div>
 				</div>
 			</div>
 			</div>
 		</div>
 		</div>