Replace sidebar menu with collapsible category tree showing items

This commit is contained in:
2025-11-12 08:36:40 +01:00
parent 8f072292c1
commit 5549c67eb5
96 changed files with 95 additions and 10 deletions

View File

@@ -45,3 +45,32 @@ $twig->addGlobal('app_name', APP_NAME);
// Add translated confirm messages for JS
$twig->addGlobal('delete_part_confirm', $translator->trans('Are you sure you want to delete this part?'));
$twig->addGlobal('delete_category_confirm', $translator->trans('Are you sure you want to delete this category?'));
// Build category tree for sidebar
$db = App\Database\Database::getInstance();
$categories = App\Models\Category::getAll($db);
$items = App\Models\Item::getAll($db);
function buildTree($categories, $items, $parentId = null) {
$tree = [];
foreach ($categories as $cat) {
if ($cat['parent_id'] == $parentId) {
$node = [
'id' => $cat['id'],
'name' => $cat['name'],
'children' => buildTree($categories, $items, $cat['id']),
'items' => []
];
foreach ($items as $item) {
if ($item['category_id'] == $cat['id']) {
$node['items'][] = $item;
}
}
$tree[] = $node;
}
}
return $tree;
}
$categoryTree = buildTree($categories, $items);
$twig->addGlobal('category_tree', $categoryTree);

View File

@@ -2,6 +2,22 @@ document.addEventListener('DOMContentLoaded', function() {
const mainContent = document.getElementById('main-content');
const appName = document.querySelector('.navbar-brand').textContent;
// Global function for editing item from tree
window.editItem = function(id) {
// Create a mock button to reuse handleEditItem
const mockBtn = { getAttribute: (attr) => attr === 'data-id' ? id : null };
handleEditItem.call(mockBtn);
};
// Function to toggle category children
window.toggleCategory = function(span) {
const li = span.parentElement;
const ul = li.querySelector('ul'); // First ul is children
if (ul) {
ul.style.display = ul.style.display === 'none' ? 'block' : 'none';
}
};
// --- Helper Functions ---
function setPageTitle(title) {
document.title = `${appName} - ${title}`;

View File

@@ -0,0 +1,26 @@
.category-tree, .category-tree ul {
list-style: none;
padding-left: 20px;
}
.category-tree li {
margin: 5px 0;
}
.category {
font-weight: bold;
cursor: pointer;
}
.items {
padding-left: 10px;
}
.item-link {
color: #007bff;
text-decoration: none;
}
.item-link:hover {
text-decoration: underline;
}

View File

@@ -1,13 +1,27 @@
{% autoescape %}
<ul class="nav flex-column nav-pills">
<li class="nav-item">
<a class="nav-link {% if active_page == 'overview' %}active{% endif %}" href="#" data-route="/">{{ trans('Overview') }}</a>
</li>
<li class="nav-item">
<a class="nav-link {% if active_page == 'categories' %}active{% endif %}" href="#" data-route="/categories">{{ trans('Categories') }}</a>
</li>
<li class="nav-item">
<a class="nav-link {% if active_page == 'parts' %}active{% endif %}" href="#" data-route="/parts">{{ trans('Parts') }}</a>
</li>
{% macro render_node(node) %}
<li>
<span class="category" onclick="toggleCategory(this)">{{ node.name }}</span>
{% if node.children %}
<ul style="display: none;">
{% for child in node.children %}
{{ _self.render_node(child) }}
{% endfor %}
</ul>
{% endif %}
{% if node.items %}
<ul class="items">
{% for item in node.items %}
<li><a href="#" onclick="editItem({{ item.id }})" class="item-link">{{ item.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endmacro %}
<ul class="category-tree">
{% for node in category_tree %}
{{ _self.render_node(node) }}
{% endfor %}
</ul>
{% endautoescape %}

0
vendor/chillerlan/php-qrcode/.idea/inspectionProfiles/Project_Default.xml generated vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/LICENSE vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/README.md vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/composer.json vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Data/AlphaNum.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Data/Byte.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Data/Kanji.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Data/MaskPatternTester.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Data/Number.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Data/QRCodeDataException.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Data/QRDataAbstract.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Data/QRDataInterface.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Helpers/BitBuffer.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Helpers/Polynomial.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Output/QRCodeOutputException.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Output/QRFpdf.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Output/QRImage.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Output/QRImagick.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Output/QRMarkup.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Output/QROutputInterface.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/Output/QRString.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/QRCodeException.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/QROptions.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-qrcode/src/QROptionsTrait.php vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-settings-container/LICENSE vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-settings-container/README.md vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-settings-container/composer.json vendored Normal file → Executable file
View File

0
vendor/chillerlan/php-settings-container/rules-magic-access.neon vendored Normal file → Executable file
View File

View File

View File

0
vendor/guzzlehttp/psr7/CHANGELOG.md vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/LICENSE vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/README.md vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/composer.json vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/AppendStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/BufferStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/CachingStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/DroppingStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/Exception/MalformedUriException.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/FnStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/Header.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/HttpFactory.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/InflateStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/LazyOpenStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/LimitStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/Message.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/MessageTrait.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/MimeType.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/MultipartStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/NoSeekStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/PumpStream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/Query.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/Request.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/Response.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/Rfc7230.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/ServerRequest.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/Stream.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/StreamDecoratorTrait.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/StreamWrapper.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/UploadedFile.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/Uri.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/UriComparator.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/UriNormalizer.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/UriResolver.php vendored Normal file → Executable file
View File

0
vendor/guzzlehttp/psr7/src/Utils.php vendored Normal file → Executable file
View File

0
vendor/psr/http-factory/LICENSE vendored Normal file → Executable file
View File

0
vendor/psr/http-factory/README.md vendored Normal file → Executable file
View File

0
vendor/psr/http-factory/composer.json vendored Normal file → Executable file
View File

0
vendor/psr/http-factory/src/RequestFactoryInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-factory/src/ResponseFactoryInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-factory/src/ServerRequestFactoryInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-factory/src/StreamFactoryInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-factory/src/UploadedFileFactoryInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-factory/src/UriFactoryInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-message/CHANGELOG.md vendored Normal file → Executable file
View File

0
vendor/psr/http-message/LICENSE vendored Normal file → Executable file
View File

0
vendor/psr/http-message/README.md vendored Normal file → Executable file
View File

0
vendor/psr/http-message/composer.json vendored Normal file → Executable file
View File

0
vendor/psr/http-message/docs/PSR7-Interfaces.md vendored Normal file → Executable file
View File

0
vendor/psr/http-message/docs/PSR7-Usage.md vendored Normal file → Executable file
View File

0
vendor/psr/http-message/src/MessageInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-message/src/RequestInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-message/src/ResponseInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-message/src/ServerRequestInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-message/src/StreamInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-message/src/UploadedFileInterface.php vendored Normal file → Executable file
View File

0
vendor/psr/http-message/src/UriInterface.php vendored Normal file → Executable file
View File

0
vendor/ralouphie/getallheaders/LICENSE vendored Normal file → Executable file
View File

0
vendor/ralouphie/getallheaders/README.md vendored Normal file → Executable file
View File

0
vendor/ralouphie/getallheaders/composer.json vendored Normal file → Executable file
View File

0
vendor/ralouphie/getallheaders/src/getallheaders.php vendored Normal file → Executable file
View File