瀏覽代碼

Add project filter to map overview

Alan Lam 5 年之前
父節點
當前提交
dd34a08069
共有 2 個文件被更改,包括 29 次插入 和 2 次删除
  1. 20 0
      public/js/app-map-overview.js
  2. 9 2
      views/map_overview.php

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

@@ -82,6 +82,26 @@ $(function() {
 		return false;
 		return false;
 	});
 	});
 
 
+	// Filters
+	$("[data-filter-target]").on("input", event => {
+		const $element = $(event.currentTarget);
+		const value = $element.val();
+
+		const $targetElement = $($element.data("filter-target"));
+
+		$targetElement.children().each((index, element) => {
+			const filterValue = $(element).data("filter-value");
+
+			let method = "show";
+			if(value.length > 0) {
+				method = filterValue.indexOf(value.toLowerCase()) !== -1 ? "show" : "hide";
+			}
+
+			$(element)[method]();
+		});
+
+	});
+
 });
 });
 
 
 function loadCustomerLocations(customerId) {
 function loadCustomerLocations(customerId) {

+ 9 - 2
views/map_overview.php

@@ -68,7 +68,12 @@
 		</div>
 		</div>
 		<div class="col-md mb-3">
 		<div class="col-md mb-3">
 			<h3>Current/Future Projects</h3>
 			<h3>Current/Future Projects</h3>
-			<div class="list-group d-block limit-height-2">
+
+			<div class="form-group">
+				<input class="form-control" type="search" value="" placeholder="<?=htmlspecialchars(__("Type filter"))?>" data-filter-target="#project-list" />
+			</div>
+
+			<div id="project-list" class="list-group d-block limit-height-2">
 			<?php
 			<?php
 			foreach($projects as $project) {
 			foreach($projects as $project) {
 				$customer = $project->getCustomer();
 				$customer = $project->getCustomer();
@@ -80,8 +85,10 @@
 					$icon = $project->getTimeOfDayIcon();
 					$icon = $project->getTimeOfDayIcon();
 				}
 				}
 
 
+				$filter_value = mb_strtolower($customer->name . $project->name);
+
 				?>
 				?>
-				<a class="list-group-item list-group-item-action d-flex justify-content-between" data-project-id="<?=$project->id?>" data-selected="false">
+				<a class="list-group-item list-group-item-action" data-project-id="<?=$project->id?>" data-selected="false" data-filter-value="<?=htmlspecialchars($filter_value)?>">
 					<div class="w-100">
 					<div class="w-100">
 						<div class="d-flex justify-content-between">
 						<div class="d-flex justify-content-between">
 							<small><strong><?=strtoupper(htmlspecialchars($customer->name))?></strong></small>
 							<small><strong><?=strtoupper(htmlspecialchars($customer->name))?></strong></small>