Răsfoiți Sursa

Added filters.

Alan Lam 8 ani în urmă
părinte
comite
4790dfe887
4 a modificat fișierele cu 108 adăugiri și 6 ștergeri
  1. 12 2
      controllers/locations.php
  2. 11 2
      controllers/projects.php
  3. 43 1
      views/locations.php
  4. 42 1
      views/projects.php

+ 12 - 2
controllers/locations.php

@@ -11,10 +11,20 @@ $page_title = "$customer->name Locations";
 
 Core::addBreadcrumb("/account/locations?customer_id=$customer->id", $page_title);
 
-$locations = $customer->getLocations();
+$nvp = ["customer_id" => $customer->id];
+
+$id = http::value("id", "int");
+$name = http::value("name", "trim");
+
+if($id) $nvp["id"] = $id;
+if($name) $nvp["name"] = (new Constraint("CONTAINS"))->setValues($name);
+
+$locations = Location::query($nvp, ["sort" => "name", "order" => "asc"]);
+
+$filter_count = count($nvp) - 1;
 
 View::includeOnce("header", compact("page_title"));
-View::include("locations", compact("customer", "locations"));
+View::include("locations", compact("customer", "filter_count", "locations"));
 View::includeOnce("footer");
 
 ?>

+ 11 - 2
controllers/projects.php

@@ -10,11 +10,20 @@ $page_title = "$customer->name Projects";
 
 Core::addBreadcrumb("/account/projects?customer_id=$customer->id", $page_title);
 
+$nvp = ["customer_id" => $customer->id];
 
-$projects = $customer->getProjects();
+$id = http::value("id", "int");
+$name = http::value("name", "trim");
+
+if($id) $nvp["id"] = $id;
+if($name) $nvp["name"] = (new Constraint("CONTAINS"))->setValues($name);
+
+$projects = Project::query($nvp, ["sort" => "dts_deadline", "order" => "desc"]);
+
+$filter_count = count($nvp) - 1;
 
 View::includeOnce("header", compact("page_title"));
-View::include("projects", compact("customer", "projects"));
+View::include("projects", compact("customer", "filter_count", "projects"));
 View::includeOnce("footer");
 
 ?>

+ 43 - 1
views/locations.php

@@ -4,9 +4,51 @@
 			<h2><?=htmlspecialchars($customer->name)?> Locations</h2>
 		</div>
 		<div class="col-auto">
-			<a class="btn btn-outline-primary" href="/account/locations/add?customer_id=<?=$customer->id?>">Add</a>
+			<button type="button" class="btn btn-outline-primary" data-toggle="collapse" data-target="#project-filters">
+				Toggle Filters
+				<?php
+				if($filter_count > 0) {
+					?>
+					<span class="badge badge-pill badge-danger"><?=$filter_count?></span>
+					<?php
+				}
+				?>
+			</button>
+			<a class="btn btn-outline-success" href="/account/locations/add?customer_id=<?=$customer->id?>">Add</a>
 		</div>
 	</div>
+
+	<?php
+	$filters_show = $filter_count > 0 ? "show" : "";
+	?>
+
+	<div class="collapse <?=$filters_show?>" id="project-filters">
+		<div class="card mb-3">
+			<div class="card-header">
+				Filters
+			</div>
+			<div class="card-body">
+				<form method="get">
+					<input type="hidden" name="customer_id" value="<?=http::value("customer_id", "int")?>" />
+					<div class="row mb-1">
+						<label class="col-sm-4 col-form-label" for="id">ID</label>
+						<div class="col-sm">
+							<input class="form-control" type="number" name="id" id="id" placeholder="Enter ID" value="<?=htmlspecialchars(http::value("id", "int"))?>" />
+						</div>
+					</div>
+					<div class="row mb-1">
+						<label class="col-sm-4 col-form-label" for="name">Name</label>
+						<div class="col-sm">
+							<input class="form-control" type="text" name="name" id="name" placeholder="Enter name" value="<?=htmlspecialchars(http::value("name"))?>" />
+						</div>
+					</div>
+					<button class="btn btn-primary mt-3" type="submit">Submit</button>
+					<a class="btn btn-secondary mt-3" href="/account/locations?customer_id=<?=$customer->id?>">Clear Filters</a>
+				</form>
+			</div>
+		</div>
+	</div>
+
 	<?php
 	View::include("location_list", compact("locations"));
 	?>

+ 42 - 1
views/projects.php

@@ -7,7 +7,48 @@
 			</h2>
 		</div>
 		<div class="col text-right">
-			<a class="btn btn-outline-primary" href="/account/projects/add?customer_id=<?=$customer->id?>">Add</a>
+			<button type="button" class="btn btn-outline-primary" data-toggle="collapse" data-target="#project-filters">
+				Toggle Filters
+				<?php
+				if($filter_count > 0) {
+					?>
+					<span class="badge badge-pill badge-danger"><?=$filter_count?></span>
+					<?php
+				}
+				?>
+			</button>
+			<a class="btn btn-outline-success" href="/account/projects/add?customer_id=<?=$customer->id?>">Add</a>
+		</div>
+	</div>
+
+	<?php
+	$filters_show = $filter_count > 0 ? "show" : "";
+	?>
+
+	<div class="collapse <?=$filters_show?>" id="project-filters">
+		<div class="card mb-3">
+			<div class="card-header">
+				Filters
+			</div>
+			<div class="card-body">
+				<form method="get">
+					<input type="hidden" name="customer_id" value="<?=http::value("customer_id", "int")?>" />
+					<div class="row mb-1">
+						<label class="col-sm-4 col-form-label" for="id">ID</label>
+						<div class="col-sm">
+							<input class="form-control" type="number" name="id" id="id" placeholder="Enter ID" value="<?=htmlspecialchars(http::value("id", "int"))?>" />
+						</div>
+					</div>
+					<div class="row mb-1">
+						<label class="col-sm-4 col-form-label" for="name">Name</label>
+						<div class="col-sm">
+							<input class="form-control" type="text" name="name" id="name" placeholder="Enter name" value="<?=htmlspecialchars(http::value("name"))?>" />
+						</div>
+					</div>
+					<button class="btn btn-primary mt-3" type="submit">Submit</button>
+					<a class="btn btn-secondary mt-3" href="/account/projects?customer_id=<?=$customer->id?>">Clear Filters</a>
+				</form>
+			</div>
 		</div>
 	</div>