Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 50 additions & 32 deletions src/ssb_dash_framework/setup/main_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import dash_bootstrap_components as dbc
from dash import html
from dash import dcc

from ..utils.alert_handler import AlertHandler
from ..utils.functions import sidebar_button
Expand All @@ -12,6 +13,17 @@

logger = logging.getLogger(__name__)

STANDARD_LAYOUT = None


def get_standard_layout():
if globals()["STANDARD_LAYOUT"]:
return globals()["STANDARD_LAYOUT"]
else:
raise ValueError(
"'STANDARD_LAYOUT' not defined, should exist after running 'main_layout()'"
)


def main_layout(
window_list: list[WindowModule],
Expand Down Expand Up @@ -74,8 +86,43 @@ def main_layout(
(tab if isinstance(tab, dbc.Tab) else dbc.Tab(tab.layout(), label=tab.label))
for tab in tab_list
]

globals()["STANDARD_LAYOUT"] = [
html.Div(
id="main-layout-sidebar",
className="main-layout-sidebar bg-secondary",
children=window_modules_list,
),
html.Div(
children=[
html.Div(
id="main-layout-offcanvas",
children=[
dbc.Offcanvas(
html.Div(
children=variable_selector.layout(),
),
id="variable-selector-offcanvas",
className="main-layout-offcanvas-variable-selector",
title="Variabler",
is_open=False,
placement="end",
backdrop=False,
),
],
),
html.Div(
id="main-layout-tab-div",
className="main-layout-tab-container",
children=dbc.Tabs(selected_tab_list),
),
],
),
]

layout = dbc.Container(
[
dcc.Location(id="url", refresh=False),
html.Div(
id="notifications-container",
className="main-layout-notifications-container",
Expand All @@ -87,42 +134,13 @@ def main_layout(
html.Div(
id="main-layout",
className="main-layout",
children=[
html.Div(
id="main-layout-sidebar",
className="main-layout-sidebar bg-secondary",
children=window_modules_list,
),
html.Div(
children=[
html.Div(
id="main-layout-offcanvas",
children=[
dbc.Offcanvas(
html.Div(
children=variable_selector.layout(),
),
id="variable-selector-offcanvas",
className="main-layout-offcanvas-variable-selector",
title="Variabler",
is_open=False,
placement="end",
backdrop=False,
),
],
),
html.Div(
id="main-layout-tab-div",
className="main-layout-tab-container",
children=dbc.Tabs(selected_tab_list),
),
],
),
],
children=globals()["STANDARD_LAYOUT"],
),
],
fluid=True,
className="dbc dbc-ag-grid",
)
logger.debug("Generated layout.")
from .urls import add_urls
add_urls()
return layout
27 changes: 27 additions & 0 deletions src/ssb_dash_framework/setup/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logging
import re

from dash import callback
from dash import Output
from dash import Input
from dash.exceptions import PreventUpdate

from .main_layout import get_standard_layout

logger = logging.getLogger(__name__)


def add_urls():
logger.debug("Adding urls.")
@callback(
Output("main-layout", "children"),
Input("url", "pathname")
)
def routing(path):
logger.info(f"Routing input: {path}")
if bool(re.fullmatch(r'/proxy/\d{4}/', path)):
logger.debug("Returning standard layout.")
return get_standard_layout()
else:
logger.debug("Preventing update.")
raise PreventUpdate
Loading