Add module detection for dynamic navbar rendering
This commit is contained in:
Binary file not shown.
+24
@@ -113,6 +113,26 @@ def _get_asset_version():
|
||||
return APP_VERSION
|
||||
|
||||
|
||||
def _is_library_module_path(path):
|
||||
"""Return True when the current request path belongs to the library module."""
|
||||
if not path:
|
||||
return False
|
||||
|
||||
library_prefixes = (
|
||||
'/library',
|
||||
'/library_',
|
||||
'/student_cards',
|
||||
)
|
||||
return path.startswith(library_prefixes)
|
||||
|
||||
|
||||
def _get_current_module(path):
|
||||
"""Resolve the active UI module for navbar separation."""
|
||||
if cfg.LIBRARY_MODULE_ENABLED and _is_library_module_path(path):
|
||||
return 'library'
|
||||
return 'inventory'
|
||||
|
||||
|
||||
def _parse_money_value(value):
|
||||
"""Parse a user-facing money value into a float when possible."""
|
||||
if value is None:
|
||||
@@ -318,9 +338,13 @@ def inject_version():
|
||||
is_admin = us.check_admin(session['username'])
|
||||
except Exception:
|
||||
is_admin = False
|
||||
|
||||
current_module = _get_current_module(request.path)
|
||||
|
||||
return {
|
||||
'APP_VERSION': APP_VERSION,
|
||||
'ASSET_VERSION': asset_version,
|
||||
'CURRENT_MODULE': current_module,
|
||||
'school_periods': SCHOOL_PERIODS,
|
||||
'library_module_enabled': cfg.LIBRARY_MODULE_ENABLED,
|
||||
'student_cards_module_enabled': cfg.STUDENT_CARDS_MODULE_ENABLED,
|
||||
|
||||
+7
-64
@@ -7,7 +7,7 @@
|
||||
For commercial licensing inquiries: https://github.com/AIIrondev
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-module="inventory">
|
||||
<html lang="en" data-module="{{ CURRENT_MODULE }}">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes">
|
||||
@@ -369,7 +369,7 @@
|
||||
<span class="module-label">Module:</span>
|
||||
<div class="module-tabs">
|
||||
<a href="{{ url_for('home') }}"
|
||||
class="module-tab"
|
||||
class="module-tab {% if CURRENT_MODULE == 'inventory' %}active{% endif %}"
|
||||
id="inventoryModule"
|
||||
data-module="inventory">
|
||||
📦 Inventarsystem
|
||||
@@ -377,7 +377,7 @@
|
||||
{% if library_module_enabled %}
|
||||
<div class="module-separator"></div>
|
||||
<a href="{{ url_for('library_view') }}"
|
||||
class="module-tab"
|
||||
class="module-tab {% if CURRENT_MODULE == 'library' %}active{% endif %}"
|
||||
id="libraryModule"
|
||||
data-module="library">
|
||||
📚 Bibliothek
|
||||
@@ -386,48 +386,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
// Detect current module based on URL and update data-module attribute
|
||||
const currentPath = window.location.pathname;
|
||||
const htmlTag = document.documentElement;
|
||||
|
||||
// Detect module and pages
|
||||
const isLibraryModule = currentPath.includes('/library') ||
|
||||
currentPath.includes('/library_admin') ||
|
||||
currentPath.includes('/library_loans') ||
|
||||
currentPath.includes('/student_cards');
|
||||
|
||||
const currentModule = isLibraryModule ? 'library' : 'inventory';
|
||||
htmlTag.setAttribute('data-module', currentModule);
|
||||
|
||||
// Update module selector tabs
|
||||
const invModule = document.getElementById('inventoryModule');
|
||||
const libModule = document.getElementById('libraryModule');
|
||||
|
||||
if (currentModule === 'library') {
|
||||
if (libModule) libModule.classList.add('active');
|
||||
if (invModule) invModule.classList.remove('active');
|
||||
} else {
|
||||
if (invModule) invModule.classList.add('active');
|
||||
if (libModule) libModule.classList.remove('active');
|
||||
}
|
||||
|
||||
// Show/hide appropriate navbar based on current module
|
||||
const invNavbar = document.getElementById('inventoryNavbar');
|
||||
const libNavbar = document.getElementById('libraryNavbar');
|
||||
|
||||
if (currentModule === 'library') {
|
||||
if (invNavbar) invNavbar.style.display = 'none';
|
||||
if (libNavbar) libNavbar.style.display = '';
|
||||
} else {
|
||||
if (invNavbar) invNavbar.style.display = '';
|
||||
if (libNavbar) libNavbar.style.display = 'none';
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
|
||||
{% if CURRENT_MODULE != 'library' %}
|
||||
<nav class="navbar navbar-expand-lg navbar-dark" id="inventoryNavbar">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="{{ url_for('home') }}" data-icon="📦">Inventarsystem</a>
|
||||
@@ -490,9 +449,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
{% endif %}
|
||||
|
||||
{% if library_module_enabled %}
|
||||
<nav class="navbar navbar-expand-lg navbar-dark" id="libraryNavbar" style="display: none;">
|
||||
{% if library_module_enabled and CURRENT_MODULE == 'library' %}
|
||||
<nav class="navbar navbar-expand-lg navbar-dark" id="libraryNavbar">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="{{ url_for('library_view') }}" data-icon="📚">Bibliothek</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#libraryNavContent">
|
||||
@@ -555,23 +515,6 @@
|
||||
</div>
|
||||
</nav>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
// Show/hide appropriate navbar based on current module
|
||||
const currentPath = window.location.pathname;
|
||||
const invNavbar = document.getElementById('inventoryNavbar');
|
||||
const libNavbar = document.getElementById('libraryNavbar');
|
||||
|
||||
if (currentPath.includes('/library')) {
|
||||
if (invNavbar) invNavbar.style.display = 'none';
|
||||
if (libNavbar) libNavbar.style.display = '';
|
||||
} else {
|
||||
if (invNavbar) invNavbar.style.display = '';
|
||||
if (libNavbar) libNavbar.style.display = 'none';
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<div class="container">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
|
||||
Reference in New Issue
Block a user