feat: add collapsible resizable navigation
This commit is contained in:
@@ -1,5 +1,32 @@
|
||||
from netbox.navigation.menu import get_menus
|
||||
|
||||
SIDEBAR_WIDTH_MIN = 216
|
||||
SIDEBAR_WIDTH_MAX = 408
|
||||
SIDEBAR_WIDTH_STEP = 24
|
||||
SIDEBAR_WIDTH_DEFAULT = 288
|
||||
|
||||
|
||||
def normalize_sidebar_width(value):
|
||||
try:
|
||||
width = int(value)
|
||||
except (TypeError, ValueError):
|
||||
return SIDEBAR_WIDTH_DEFAULT
|
||||
|
||||
width = min(SIDEBAR_WIDTH_MAX, max(SIDEBAR_WIDTH_MIN, width))
|
||||
steps = (width - SIDEBAR_WIDTH_MIN + SIDEBAR_WIDTH_STEP // 2) // SIDEBAR_WIDTH_STEP
|
||||
return SIDEBAR_WIDTH_MIN + steps * SIDEBAR_WIDTH_STEP
|
||||
|
||||
|
||||
def update_sidebar_layout(collapsed, width, action):
|
||||
width = normalize_sidebar_width(width)
|
||||
if action == "toggle":
|
||||
return not collapsed, width
|
||||
if action == "smaller":
|
||||
return collapsed, max(SIDEBAR_WIDTH_MIN, width - SIDEBAR_WIDTH_STEP)
|
||||
if action == "larger":
|
||||
return collapsed, min(SIDEBAR_WIDTH_MAX, width + SIDEBAR_WIDTH_STEP)
|
||||
raise ValueError("Unbekannte Navigationsaktion.")
|
||||
|
||||
|
||||
def _permitted_menu_items(menu, user):
|
||||
for group in menu.groups:
|
||||
|
||||
Reference in New Issue
Block a user