diff --git a/src/python/impactx/dashboard/Input/components.py b/src/python/impactx/dashboard/Input/components.py index 13884270e..3d9d6b498 100644 --- a/src/python/impactx/dashboard/Input/components.py +++ b/src/python/impactx/dashboard/Input/components.py @@ -6,6 +6,9 @@ server, state, ctrl = setup_server() +state.documentation_drawer_open = False +state.documentation_url = "" + class CardComponents: """ @@ -41,7 +44,7 @@ def documentation_icon(section_name: str) -> vuetify.VIcon: return vuetify.VIcon( "mdi-information", style="color: #00313C;", - click=lambda: generalFunctions.documentation(section_name), + click=lambda: generalFunctions.open_documentation(section_name), ) @staticmethod @@ -187,3 +190,21 @@ def create_dialog_tabs(name: str, num_tabs: int, tab_names: list[str]) -> None: for tab_name in tab_names: vuetify.VTab(tab_name) vuetify.VDivider() + + @staticmethod + def create_documentation_drawer(): + with vuetify.VNavigationDrawer( + v_model=("documentation_drawer_open",), + absolute=True, + right=True, + hide_overlay=True, + style="width: 30vw; top: 64px !important; position: fixed;", + ): + with vuetify.VContainer( + fluid=True, + classes="pa-0 fill-height", + ): + html.Iframe( + src=("documentation_url",), + style="width: 100%; height: 100%; border: none;", + ) diff --git a/src/python/impactx/dashboard/Input/defaults.py b/src/python/impactx/dashboard/Input/defaults.py index 398f63f60..1266efd9f 100644 --- a/src/python/impactx/dashboard/Input/defaults.py +++ b/src/python/impactx/dashboard/Input/defaults.py @@ -119,6 +119,14 @@ class DashboardDefaults: "emitt": "m", } + DOCUMENTATION = { + "input_parameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#impactx.ImpactX", + "lattice_configuration": "https://impactx.readthedocs.io/en/latest/usage/python.html#lattice-elements", + "distribution_parameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#initial-beam-distributions", + "space_charge": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#space-charge", + "csr": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#coherent-synchrotron-radiation-csr", + } + class TooltipDefaults: """ diff --git a/src/python/impactx/dashboard/Input/generalFunctions.py b/src/python/impactx/dashboard/Input/generalFunctions.py index b02ebd91d..a58507f33 100644 --- a/src/python/impactx/dashboard/Input/generalFunctions.py +++ b/src/python/impactx/dashboard/Input/generalFunctions.py @@ -7,10 +7,7 @@ """ import inspect -import os import re -import subprocess -import webbrowser from .. import setup_server from .defaults import DashboardDefaults @@ -24,27 +21,20 @@ class generalFunctions: @staticmethod - def documentation(section_name): + def open_documentation(section_name): """ - Opens a tab to the specified section link in the documentation. - :param section_name (str): The name of the documentation section to open. + Retrieves the documentation link with the provided section_name + and opens the documentation sidebar on the dashoard. + + :param section_name: The name for the input section. """ - url_dict = { - "input_parameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#general", - "lattice_configuration": "https://impactx.readthedocs.io/en/latest/usage/python.html#lattice-elements", - "distribution_parameters": "https://impactx.readthedocs.io/en/latest/usage/python.html#initial-beam-distributions", - "space_charge": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#space-charge", - "csr": "https://impactx.readthedocs.io/en/latest/usage/parameters.html#coherent-synchrotron-radiation-csr", - } - - url = url_dict.get(section_name) - if url is None: - raise ValueError(f"Invalid section name: {section_name}") - - if "WSL_DISTRO_NAME" in os.environ: - subprocess.run(["explorer.exe", url]) + + new_url = DashboardDefaults.DOCUMENTATION.get(section_name) + if state.documentation_drawer_open and state.documentation_url == new_url: + state.documentation_drawer_open = False else: - webbrowser.open_new_tab(url) + state.documentation_url = new_url + state.documentation_drawer_open = True @staticmethod def get_default(parameter, type): diff --git a/src/python/impactx/dashboard/__init__.py b/src/python/impactx/dashboard/__init__.py index 0b73e2e2b..fe6d85916 100644 --- a/src/python/impactx/dashboard/__init__.py +++ b/src/python/impactx/dashboard/__init__.py @@ -22,6 +22,7 @@ "html", "JupyterApp", "setup_server", + "html", "vuetify", "AnalyzeSimulation", "NavigationComponents", diff --git a/src/python/impactx/dashboard/__main__.py b/src/python/impactx/dashboard/__main__.py index b31b89358..b66624ed7 100644 --- a/src/python/impactx/dashboard/__main__.py +++ b/src/python/impactx/dashboard/__main__.py @@ -90,6 +90,7 @@ def application(): NavigationComponents.create_route("Analyze", "mdi-chart-box-multiple") with layout.content: + NavigationComponents.create_documentation_drawer() router.RouterView() init_terminal() return layout