Development

This commit is contained in:
Matthew Grotke 2026-05-29 22:16:56 -04:00
parent 263639eb95
commit aff93abf5f
2 changed files with 69 additions and 5 deletions

View file

@ -884,7 +884,7 @@ def collect_tokens():
# Layout renderer ===================================================
def render_layout(view_id, content_html, tokens):
def render_layout(view_id, content_html, tokens, page_name=None):
css = _load_css()
level = client_level()
has_pending_alert = not _apply_changes_immediately() and bool(get_dashboard_pending())
@ -1008,7 +1008,7 @@ def render_layout(view_id, content_html, tokens):
f'<main class="main-content">\n{pending_bar}{problem_bars}{other_bars}{content_html}\n</main>\n'
f'{footer_html}\n'
f'<script>var CONFIG_HASH="{page_hash}";var LAN_IFACE="{lan_iface}";var VPN_VLAN_COUNT={vpn_count};var APPLY_UUID={json.dumps(my_uuid)};</script>\n'
f'<script>{_inline_js()}</script>\n'
f'<script>{_inline_js(page_name)}</script>\n'
'</body>\n</html>'
)
@ -1076,7 +1076,7 @@ def build_nav_item(item, active_view, level, in_dropdown=False, inherited_req=No
# Inline JavaScript =================================================
def _inline_js():
def _inline_js(page_name=None):
try:
with open(VALIDATION_FILE) as f:
val_js = f.read()
@ -1087,7 +1087,15 @@ def _inline_js():
app_js = f.read()
except Exception:
app_js = ''
return val_js + '\n' + app_js
page_js = ''
if page_name:
page_js_path = os.path.join(PAGES_DIR, page_name, 'page.js')
try:
with open(page_js_path) as f:
page_js = f.read()
except Exception:
pass
return val_js + '\n' + app_js + ('\n' + page_js if page_js else '')
# Routes ============================================================
@ -1121,4 +1129,4 @@ def serve_view(page_name):
flash_html += f'<div class="info-bar info-bar-{variant} info-bar-flash"><span>{msg_html}</span></div>'
content_html = flash_html + build_items(view_def.get('items', []), tokens, view_req)
return render_layout(page_name, content_html, tokens)
return render_layout(page_name, content_html, tokens, page_name=page_name)