feat(admin): new env var. for which sections should be open by default in the admin page.

This commit is contained in:
2025-10-02 14:27:32 +02:00
parent d1988d015e
commit b9d42c2866
3 changed files with 43 additions and 8 deletions
+7
View File
@@ -97,6 +97,13 @@
# Default: false
# BK_HIDE_ADMIN=true
# Optional: Admin sections to expand by default (comma-separated list)
# Valid sections: authentication, instructions, image, theme, retired, metadata, owner, purchase_location, status, storage, tag, database
# Default: [] (all sections collapsed)
# Examples:
# BK_ADMIN_DEFAULT_EXPANDED_SECTIONS=database,theme
# BK_ADMIN_DEFAULT_EXPANDED_SECTIONS=instructions,metadata
# Optional: Hide the 'Instructions' entry from the menu. Does not disable the route.
# Default: false
# BK_HIDE_ALL_INSTRUCTIONS=true
+1
View File
@@ -25,6 +25,7 @@ CONFIG: Final[list[dict[str, Any]]] = [
{'n': 'HIDE_ADD_SET', 'c': bool},
{'n': 'HIDE_ADD_BULK_SET', 'c': bool},
{'n': 'HIDE_ADMIN', 'c': bool},
{'n': 'ADMIN_DEFAULT_EXPANDED_SECTIONS', 'd': [], 'c': list},
{'n': 'HIDE_ALL_INSTRUCTIONS', 'c': bool},
{'n': 'HIDE_ALL_MINIFIGURES', 'c': bool},
{'n': 'HIDE_ALL_PARTS', 'c': bool},
+35 -8
View File
@@ -1,6 +1,6 @@
import logging
from flask import Blueprint, request, render_template
from flask import Blueprint, request, render_template, current_app
from flask_login import login_required
from ...configuration_list import BrickConfigurationList
@@ -102,13 +102,40 @@ def admin() -> str:
open_tag
)
open_database = (
open_image is None and
open_instructions is None and
open_logout is None and
not open_metadata and
open_retired is None and
open_theme is None
# Get configurable default expanded sections
default_expanded_sections = current_app.config.get('ADMIN_DEFAULT_EXPANDED_SECTIONS', [])
# Helper function to check if section should be expanded
def should_expand(section_name, url_param):
# URL parameter takes priority over default config
if url_param is not None:
return url_param
# Check if section is in default expanded list
return section_name in default_expanded_sections
# Apply configurable default expansion logic
open_database = should_expand('database', request.args.get('open_database', None))
open_image = should_expand('image', open_image)
open_instructions = should_expand('instructions', open_instructions)
open_logout = should_expand('authentication', open_logout)
open_retired = should_expand('retired', open_retired)
open_theme = should_expand('theme', open_theme)
# Metadata sub-sections
open_owner = should_expand('owner', open_owner)
open_purchase_location = should_expand('purchase_location', open_purchase_location)
open_status = should_expand('status', open_status)
open_storage = should_expand('storage', open_storage)
open_tag = should_expand('tag', open_tag)
# Recalculate metadata section based on sub-sections or direct config
open_metadata = (
should_expand('metadata', open_metadata) or
open_owner or
open_purchase_location or
open_status or
open_storage or
open_tag
)
return render_template(