Explorar el Código

Hide archived/closed locations by default on "Locations" page

Alan Lam hace 5 años
padre
commit
5005a0d5a9
Se han modificado 4 ficheros con 83 adiciones y 14 borrados
  1. 9 1
      controllers/customer_ajax.php
  2. 42 9
      controllers/locations.php
  3. 5 0
      public/js/app-locations.js
  4. 27 4
      views/locations.php

+ 9 - 1
controllers/customer_ajax.php

@@ -15,17 +15,25 @@ if(!Core::$user->hasPermission($customer)) throw new Exception(__("No permission
 switch($action) {
 	case "get-locations":
 
-		$nvp = ["customer_id" => $customer->id];
+		$nvp = [
+			"customer_id" => $customer->id,
+			"archived" => 0,
+			"closed" => 0
+		];
 
 		$id = http::value("id", "int");
 		$internal_id = http::value("internal_id", "trim");
 		$name = http::value("name", "trim");
 		$legal_entity_name = http::value("legal_entity_name", "trim");
+		$include_archived = http::value("include_archived", "int");
+		$include_closed = http::value("include_closed", "int");
 
 		if($id) $nvp["id"] = $id;
 		if($internal_id) $nvp["internal_id"] = db::escape($internal_id);
 		if($name) $nvp["name"] = Constraint::contains($name);
 		if($legal_entity_name) $nvp["$legal_entity_name"] = Constraint::contains($legal_entity_name);
+		if($include_archived) unset($nvp["archived"]);
+		if($include_closed) unset($nvp["closed"]);
 
 		$locations = Location::query($nvp, ["sort" => "name", "order" => "asc"]);
 

+ 42 - 9
controllers/locations.php

@@ -20,19 +20,54 @@ $page_title = "$customer->name Locations";
 
 Core::addBreadcrumb("/account/locations?customer_id=$customer->id", $page_title);
 
-$nvp = ["customer_id" => $customer->id];
+$nvp = [
+	"customer_id" => $customer->id,
+	"archived" => 0,
+	"closed" => 0,
+];
 
 $id = http::value("id", "int");
 $ids = http::value("ids", "int");
 $internal_id = http::value("internal_id", "trim");
 $name = http::value("name", "trim");
 $legal_entity_name = http::value("legal_entity_name", "trim");
+$include_archived = (int) http::value("include_archived");
+$include_closed = (int) http::value("include_closed");
+
+$filter_count = 0;
+
+if($id) {
+	$nvp["id"] = $id;
+	$filter_count++;
+}
 
-if($id) $nvp["id"] = $id;
-if($ids) $nvp["id"] = $ids;
-if($internal_id) $nvp["internal_id"] = Constraint::contains($internal_id);
-if($name) $nvp["name"] = Constraint::contains($name);
-if($legal_entity_name) $nvp["legal_entity_name"] = Constraint::contains($legal_entity_name);
+if($ids) {
+	$nvp["id"] = $ids;
+}
+
+if($internal_id) {
+	$nvp["internal_id"] = Constraint::contains($internal_id);
+	$filter_count++;
+}
+
+if($name) {
+	$nvp["name"] = Constraint::contains($name);
+	$filter_count++;
+}
+if($legal_entity_name) {
+	$nvp["legal_entity_name"] = Constraint::contains($legal_entity_name);
+	$filter_count++;
+}
+
+if($include_archived) {
+	unset($nvp["archived"]);
+	$filter_count++;
+}
+
+if($include_closed) {
+	unset($nvp["closed"]);
+	$filter_count++;
+}
 
 $sort = http::value("sort");
 switch($sort) {
@@ -123,9 +158,7 @@ if(!empty($action)) {
 	}
 }
 
-$filter_count = count($nvp) - 1;
-
 View::includeOnce("header", compact("page_title"));
-View::include("locations", compact("customer", "filter_count", "sorts", "sort", "locations"));
+View::include("locations", compact("customer", "include_archived", "include_closed", "filter_count", "sorts", "sort", "locations"));
 View::include("modal_add_locations_to_project", compact("customer"));
 View::includeOnce("footer");

+ 5 - 0
public/js/app-locations.js

@@ -9,11 +9,16 @@ function initialiseLocations() {
 		infoWindow = new google.maps.InfoWindow();
 	}
 
+	const includeArchived = $("#include-archived").prop("checked") ? 1 : 0;
+	const includeClosed = $("#include-closed").prop("checked") ? 1 : 0;
+
 	$.get(`/api/customers/${customerId}/get-locations`, {
 		id: $("#id").val(),
 		internal_id: $("#internal-id").val(),
 		name: $("#name").val(),
 		legal_entity_name: $("#legal-entity-name").val(),
+		include_archived: includeArchived,
+		include_closed: includeClosed
 	}, function(response) {
 		if(!response.success) return false;
 		if(!response.locations) return false;

+ 27 - 4
views/locations.php

@@ -2,6 +2,8 @@
 
 /**
  * @var Customer $customer
+ * @var int $include_archived
+ * @var int $include_closed
  * @var int $filter_count
  * @var array $sorts
  * @var string $sort
@@ -11,6 +13,10 @@
 $query = $_GET;
 unset($query["path"]);
 $query["sort"] = "SORT";
+
+$include_archived_checked = $include_archived ? "checked" : "";
+$include_closed_checked = $include_closed ? "checked" : "";
+
 ?>
 
 <script>
@@ -71,7 +77,7 @@ var customerId = <?=$customer->id?>;
 				<input type="hidden" name="customer_id" value="<?=http::value("customer_id", "int")?>" />
 				<div class="row">
 					<div class="col-lg-6">
-						<div class="row mb-1">
+						<div class="row form-group">
 							<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"))?>" />
@@ -79,7 +85,7 @@ var customerId = <?=$customer->id?>;
 						</div>
 					</div>
 					<div class="col-lg-6">
-						<div class="row mb-1">
+						<div class="row form-group">
 							<label class="col-sm-4 col-form-label" for="internal-id">Internal ID</label>
 							<div class="col-sm">
 								<input class="form-control" type="text" name="internal_id" id="internal-id" placeholder="Enter internal ID" value="<?=htmlspecialchars(http::value("internal_id", "trim"))?>" />
@@ -87,7 +93,7 @@ var customerId = <?=$customer->id?>;
 						</div>
 					</div>
 					<div class="col-lg-6">
-						<div class="row mb-1">
+						<div class="row form-group">
 							<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"))?>" />
@@ -95,7 +101,7 @@ var customerId = <?=$customer->id?>;
 						</div>
 					</div>
 					<div class="col-lg-6">
-						<div class="row mb-1">
+						<div class="row form-group">
 							<label class="col-sm-4 col-form-label" for="legal-entity-name">Legal Entity Name</label>
 							<div class="col-sm">
 								<input class="form-control" type="text" name="legal_entity_name" id="legal-entity-name" placeholder="Enter legal entity name" value="<?=htmlspecialchars(http::value("legal_entity_name"))?>" />
@@ -107,6 +113,23 @@ var customerId = <?=$customer->id?>;
 					<div class="col-lg">
 						<div class="row">
 							<div class="col-sm offset-sm-4">
+
+								<div class="form-group">
+									<div class="custom-control custom-switch">
+										<input class="custom-control-input" id="include-archived" name="include_archived"
+											   type="checkbox" value="1" <?=$include_archived_checked?> />
+										<label class="custom-control-label"
+											   for="include-archived"><?= htmlspecialchars(__("Include Archived")) ?></label>
+									</div>
+									<div class="custom-control custom-switch">
+										<input class="custom-control-input" id="include-closed" name="include_closed"
+											   type="checkbox"
+											   value="1" <?=$include_closed_checked?> />
+										<label class="custom-control-label"
+											   for="include-closed"><?= htmlspecialchars(__("Include Closed")) ?></label>
+									</div>
+								</div>
+
 								<button class="btn btn-primary" type="submit">Submit</button>
 								<a class="btn btn-secondary" href="/account/locations?customer_id=<?=$customer->id?>">Clear Filters</a>
 							</div>