From b9d42c2866b5f4aa4e6da2a4d542f4d3d85ac324 Mon Sep 17 00:00:00 2001 From: Frederik Baerentsen Date: Thu, 2 Oct 2025 14:27:32 +0200 Subject: [PATCH] feat(admin): new env var. for which sections should be open by default in the admin page. --- .env.sample | 7 +++++ bricktracker/config.py | 1 + bricktracker/views/admin/admin.py | 43 +++++++++++++++++++++++++------ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/.env.sample b/.env.sample index 5bf4014..58b2ce4 100644 --- a/.env.sample +++ b/.env.sample @@ -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 diff --git a/bricktracker/config.py b/bricktracker/config.py index 824a49e..3ebd747 100644 --- a/bricktracker/config.py +++ b/bricktracker/config.py @@ -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}, diff --git a/bricktracker/views/admin/admin.py b/bricktracker/views/admin/admin.py index 9835548..b25e783 100644 --- a/bricktracker/views/admin/admin.py +++ b/bricktracker/views/admin/admin.py @@ -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(