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
|
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):
|
def _parse_money_value(value):
|
||||||
"""Parse a user-facing money value into a float when possible."""
|
"""Parse a user-facing money value into a float when possible."""
|
||||||
if value is None:
|
if value is None:
|
||||||
@@ -318,9 +338,13 @@ def inject_version():
|
|||||||
is_admin = us.check_admin(session['username'])
|
is_admin = us.check_admin(session['username'])
|
||||||
except Exception:
|
except Exception:
|
||||||
is_admin = False
|
is_admin = False
|
||||||
|
|
||||||
|
current_module = _get_current_module(request.path)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'APP_VERSION': APP_VERSION,
|
'APP_VERSION': APP_VERSION,
|
||||||
'ASSET_VERSION': asset_version,
|
'ASSET_VERSION': asset_version,
|
||||||
|
'CURRENT_MODULE': current_module,
|
||||||
'school_periods': SCHOOL_PERIODS,
|
'school_periods': SCHOOL_PERIODS,
|
||||||
'library_module_enabled': cfg.LIBRARY_MODULE_ENABLED,
|
'library_module_enabled': cfg.LIBRARY_MODULE_ENABLED,
|
||||||
'student_cards_module_enabled': cfg.STUDENT_CARDS_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
|
For commercial licensing inquiries: https://github.com/AIIrondev
|
||||||
-->
|
-->
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" data-module="inventory">
|
<html lang="en" data-module="{{ CURRENT_MODULE }}">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes">
|
<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>
|
<span class="module-label">Module:</span>
|
||||||
<div class="module-tabs">
|
<div class="module-tabs">
|
||||||
<a href="{{ url_for('home') }}"
|
<a href="{{ url_for('home') }}"
|
||||||
class="module-tab"
|
class="module-tab {% if CURRENT_MODULE == 'inventory' %}active{% endif %}"
|
||||||
id="inventoryModule"
|
id="inventoryModule"
|
||||||
data-module="inventory">
|
data-module="inventory">
|
||||||
📦 Inventarsystem
|
📦 Inventarsystem
|
||||||
@@ -377,7 +377,7 @@
|
|||||||
{% if library_module_enabled %}
|
{% if library_module_enabled %}
|
||||||
<div class="module-separator"></div>
|
<div class="module-separator"></div>
|
||||||
<a href="{{ url_for('library_view') }}"
|
<a href="{{ url_for('library_view') }}"
|
||||||
class="module-tab"
|
class="module-tab {% if CURRENT_MODULE == 'library' %}active{% endif %}"
|
||||||
id="libraryModule"
|
id="libraryModule"
|
||||||
data-module="library">
|
data-module="library">
|
||||||
📚 Bibliothek
|
📚 Bibliothek
|
||||||
@@ -386,48 +386,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if CURRENT_MODULE != 'library' %}
|
||||||
<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>
|
|
||||||
|
|
||||||
<nav class="navbar navbar-expand-lg navbar-dark" id="inventoryNavbar">
|
<nav class="navbar navbar-expand-lg navbar-dark" id="inventoryNavbar">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" href="{{ url_for('home') }}" data-icon="📦">Inventarsystem</a>
|
<a class="navbar-brand" href="{{ url_for('home') }}" data-icon="📦">Inventarsystem</a>
|
||||||
@@ -490,9 +449,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if library_module_enabled %}
|
{% if library_module_enabled and CURRENT_MODULE == 'library' %}
|
||||||
<nav class="navbar navbar-expand-lg navbar-dark" id="libraryNavbar" style="display: none;">
|
<nav class="navbar navbar-expand-lg navbar-dark" id="libraryNavbar">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" href="{{ url_for('library_view') }}" data-icon="📚">Bibliothek</a>
|
<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">
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#libraryNavContent">
|
||||||
@@ -555,23 +515,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
{% endif %}
|
{% 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">
|
<div class="container">
|
||||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
|
|||||||
Reference in New Issue
Block a user