Move categories and tag types to a left side nav instead of top nav

This commit is contained in:
johnnyq
2026-08-03 12:54:33 -04:00
parent 315768d651
commit ffe32adbd3
2 changed files with 277 additions and 277 deletions

View File

@@ -23,104 +23,106 @@ $sql = mysqli_query(
); );
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
// Category types shown in the left nav
$category_types = [
'Expense' => ['label' => 'Expense', 'icon' => 'fa-shopping-cart'],
'Income' => ['label' => 'Income', 'icon' => 'fa-hand-holding-usd'],
'Referral' => ['label' => 'Referral', 'icon' => 'fa-share-alt'],
'Ticket' => ['label' => 'Ticket', 'icon' => 'fa-life-ring'],
'network_interface' => ['label' => 'Network Interface', 'icon' => 'fa-ethernet'],
'asset_status' => ['label' => 'Asset Status', 'icon' => 'fa-heartbeat'],
'software_type' => ['label' => 'Software Type', 'icon' => 'fa-cube'],
'rack_type' => ['label' => 'Rack Type', 'icon' => 'fa-server'],
'contact_note_type' => ['label' => 'Contact Note Type', 'icon' => 'fa-address-book'],
'asset_note_type' => ['label' => 'Asset Note Type', 'icon' => 'fa-desktop'],
];
// Label for the selected type, falling back for anything not in the map
$category_label = $category_types[$category]['label'] ?? ucwords(str_replace('_', ' ', $category));
// Row count per type for the nav badges, respecting the archived view
$category_type_counts = [];
$sql_category_type_counts = mysqli_query(
$mysqli,
"SELECT category_type, COUNT(category_id) AS category_type_count FROM categories
WHERE category_$archive_query
GROUP BY category_type"
);
while ($row = mysqli_fetch_assoc($sql_category_type_counts)) {
$category_type_counts[$row['category_type']] = intval($row['category_type_count']);
}
// Archived nav item toggles the view while holding the selected type/search
$archive_toggle_query = $_GET;
unset($archive_toggle_query['page']);
$archive_toggle_query['category'] = $category;
if ($archived) {
unset($archive_toggle_query['archived']);
} else {
$archive_toggle_query['archived'] = 1;
}
$archive_toggle_url = '?' . http_build_query($archive_toggle_query);
?> ?>
<div class="card card-dark"> <div class="card card-dark">
<div class="card-header py-2"> <div class="card-header py-2">
<h3 class="card-title mt-2"><i class="fa fa-fw fa-list-ul mr-2"></i> <h3 class="card-title mt-2"><i class="fa fa-fw fa-list-ul mr-2"></i>
<?= escapeHtml(ucwords(str_replace('_', ' ', $category))); ?> Categories <?= escapeHtml($category_label) ?> Categories
</h3> </h3>
<?php <?php
if (!isset($_GET['archived'])) { if (!isset($_GET['archived'])) {
?> ?>
<div class="card-tools"> <div class="card-tools">
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/category/category_add.php?category=<?= escapeHtml($category) ?>"><i <button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/category/category_add.php?category=<?= escapeHtml($category) ?>"><i
class="fas fa-plus mr-2"></i>New <?= escapeHtml(ucwords(str_replace('_', ' ', $category))); ?> Category</button> class="fas fa-plus mr-2"></i>New <?= escapeHtml($category_label) ?> Category</button>
</div> </div>
<?php <?php
} }
?> ?>
</div> </div>
<div class="card-body"> <div class="card-body">
<div class="row">
<!-- Category types -->
<div class="col-md-3 border-right mb-3">
<ul class="nav nav-pills flex-column bg-light">
<?php foreach ($category_types as $category_type => $category_type_details) { ?>
<li class="nav-item">
<a class="nav-link<?php if ($category == $category_type) {
echo ' active';
} ?>" href="?category=<?= urlencode($category_type) ?>">
<i class="fa fa-fw <?= $category_type_details['icon'] ?> mr-2"></i><?= escapeHtml($category_type_details['label']) ?>
<span class="badge badge-pill badge-dark float-right mt-1"><?= $category_type_counts[$category_type] ?? 0 ?></span>
</a>
</li>
<?php } ?>
</ul>
</div>
<!-- Categories -->
<div class="col-md-9">
<form autocomplete="off"> <form autocomplete="off">
<input type="hidden" name="category" value="<?= escapeHtml($category) ?>"> <input type="hidden" name="category" value="<?= escapeHtml($category) ?>">
<?php if ($archived) { ?>
<input type="hidden" name="archived" value="1">
<?php } ?>
<div class="row"> <div class="row">
<div class="col-sm-4 mb-2"> <div class="col-sm-6 mb-2">
<div class="input-group"> <div class="input-group">
<input type="search" class="form-control" name="q" <input type="search" class="form-control" name="q"
value="<?php if (isset($q)) { value="<?php if (isset($q)) {
echo stripslashes(escapeHtml($q)); echo stripslashes(escapeHtml($q));
} ?>" } ?>"
placeholder="Search <?= escapeHtml(ucwords(str_replace('_', ' ', $category))); ?> Categories "> placeholder="Search <?= escapeHtml($category_label) ?> Categories ">
<div class="input-group-append"> <div class="input-group-append">
<button class="btn btn-primary"><i class="fa fa-search"></i></button> <button class="btn btn-primary"><i class="fa fa-search"></i></button>
</div> </div>
</div> </div>
</div> </div>
<div class="col-sm-8"> <div class="col-sm-6 mb-2">
<div class="btn-group float-right"> <a href="<?= $archive_toggle_url ?>"
<a href="?category=Expense" class="btn float-right <?php if ($archived) {
class="btn <?php if ($category == 'Expense') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Expense</a>
<a href="?category=Income"
class="btn <?php if ($category == 'Income') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Income</a>
<a href="?category=Referral"
class="btn <?php if ($category == 'Referral') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Referral</a>
<a href="?category=Ticket"
class="btn <?php if ($category == 'Ticket') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Ticket</a>
<a href="?category=network_interface"
class="btn <?php if ($category == 'network_interface') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Network Interface</a>
<a href="?category=asset_status"
class="btn <?php if ($category == 'asset_status') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Asset Status</a>
<a href="?category=software_type"
class="btn <?php if ($category == 'software_type') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Software Type</a>
<a href="?category=rack_type"
class="btn <?php if ($category == 'rack_type') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Rack Type</a>
<a href="?category=contact_note_type"
class="btn <?php if ($category == 'contact_note_type') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Contact Note Type</a>
<a href="?category=asset_note_type"
class="btn <?php if ($category == 'asset_note_type') {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Asset Note Type</a>
<a href="?<?= $url_query_strings_sort ?>&archived=1"
class="btn <?php if (isset($_GET['archived'])) {
echo 'btn-primary'; echo 'btn-primary';
} else { } else {
echo 'btn-default'; echo 'btn-default';
@@ -128,7 +130,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
class="fas fa-fw fa-archive mr-2"></i>Archived</a> class="fas fa-fw fa-archive mr-2"></i>Archived</a>
</div> </div>
</div> </div>
</div>
</form> </form>
<hr> <hr>
<div class="table-responsive-sm"> <div class="table-responsive-sm">
@@ -208,8 +209,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
</tbody> </tbody>
</table> </table>
</div> </div>
<?php require_once "../includes/filter_footer.php"; <?php require_once "../includes/filter_footer.php"; ?>
?> </div>
</div>
</div> </div>
</div> </div>

View File

@@ -12,19 +12,17 @@ if (isset($_GET['type'])) {
$type_filter = 1; $type_filter = 1;
} }
if ($type_filter == 1) { // Tag types shown in the left nav
$tag_type_display = "Client"; $tag_types = [
} elseif ( $type_filter == 2) { 1 => ['label' => 'Client', 'icon' => 'fa-users'],
$tag_type_display = "Location"; 2 => ['label' => 'Location', 'icon' => 'fa-map-marker-alt'],
} elseif ( $type_filter == 3) { 3 => ['label' => 'Contact', 'icon' => 'fa-address-book'],
$tag_type_display = "Contact"; 4 => ['label' => 'Credential', 'icon' => 'fa-key'],
} elseif ( $type_filter == 4) { 5 => ['label' => 'Asset', 'icon' => 'fa-desktop'],
$tag_type_display = "Credential"; ];
} elseif ( $type_filter == 5) {
$tag_type_display = "Asset"; // Label for the selected type
} else { $tag_type_display = $tag_types[$type_filter]['label'] ?? 'Unknown';
$tag_type_display = "Unknown";
}
$sql = mysqli_query( $sql = mysqli_query(
$mysqli, $mysqli,
@@ -36,6 +34,13 @@ $sql = mysqli_query(
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
// Row count per type for the nav badges
$tag_type_counts = [];
$sql_tag_type_counts = mysqli_query($mysqli, "SELECT tag_type, COUNT(tag_id) AS tag_type_count FROM tags GROUP BY tag_type");
while ($row = mysqli_fetch_assoc($sql_tag_type_counts)) {
$tag_type_counts[intval($row['tag_type'])] = intval($row['tag_type_count']);
}
?> ?>
<div class="card card-dark"> <div class="card card-dark">
@@ -48,50 +53,42 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">
<div class="col-sm-4 mb-2">
<!-- Tag types -->
<div class="col-md-3 border-right mb-3">
<ul class="nav nav-pills flex-column bg-light">
<?php foreach ($tag_types as $tag_type => $tag_type_details) { ?>
<li class="nav-item">
<a class="nav-link<?php if ($type_filter == $tag_type) {
echo ' active';
} ?>" href="?type=<?= $tag_type ?>">
<i class="fa fa-fw <?= $tag_type_details['icon'] ?> mr-2"></i><?= escapeHtml($tag_type_details['label']) ?>
<span class="badge badge-pill badge-dark float-right mt-1"><?= $tag_type_counts[$tag_type] ?? 0 ?></span>
</a>
</li>
<?php } ?>
</ul>
</div>
<!-- Tags -->
<div class="col-md-9">
<form autocomplete="off"> <form autocomplete="off">
<input type="hidden" name="type" value="<?= $type_filter ?>">
<?php if ($archived) { ?>
<input type="hidden" name="archived" value="1">
<?php } ?>
<div class="row">
<div class="col-sm-6 mb-2">
<div class="input-group"> <div class="input-group">
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search <?= $tag_type_display ?> Tags"> <input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search <?= $tag_type_display ?> Tags">
<div class="input-group-append"> <div class="input-group-append">
<button class="btn btn-primary"><i class="fa fa-search"></i></button> <button class="btn btn-primary"><i class="fa fa-search"></i></button>
</div> </div>
</div> </div>
</form>
</div> </div>
<div class="col-sm-8"> <div class="col-sm-6 mb-2">
<div class="btn-group float-right">
<a href="?type=1"
class="btn <?php if ($type_filter == 1) {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Client</a>
<a href="?type=2"
class="btn <?php if ($type_filter == 2) {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Location</a>
<a href="?type=3"
class="btn <?php if ($type_filter == 3) {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Contact</a>
<a href="?type=4"
class="btn <?php if ($type_filter == 4) {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Credential</a>
<a href="?type=5"
class="btn <?php if ($type_filter == 5) {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>">Asset</a>
<a href="?<?= $url_query_strings_sort ?>&archived=1" <a href="?<?= $url_query_strings_sort ?>&archived=1"
class="btn <?php if (isset($_GET['archived'])) { class="btn float-right <?php if (isset($_GET['archived'])) {
echo 'btn-primary'; echo 'btn-primary';
} else { } else {
echo 'btn-default'; echo 'btn-default';
@@ -99,8 +96,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
class="fas fa-fw fa-archive mr-2"></i>Archived</a> class="fas fa-fw fa-archive mr-2"></i>Archived</a>
</div> </div>
</div> </div>
</div> </form>
<hr> <hr>
<div class="table-responsive-sm"> <div class="table-responsive-sm">
<table class="table table-striped table-borderless table-hover"> <table class="table table-striped table-borderless table-hover">
@@ -162,6 +158,8 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<?php require_once "../includes/filter_footer.php"; ?> <?php require_once "../includes/filter_footer.php"; ?>
</div> </div>
</div> </div>
</div>
</div>
<?php <?php