Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard: Add documentation sidebar #836

Merged
Merged
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
23 changes: 22 additions & 1 deletion src/python/impactx/dashboard/Input/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

server, state, ctrl = setup_server()

state.documentation_drawer_open = False
state.documentation_url = ""


class CardComponents:
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;",
)
8 changes: 8 additions & 0 deletions src/python/impactx/dashboard/Input/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
32 changes: 11 additions & 21 deletions src/python/impactx/dashboard/Input/generalFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
"""

import inspect
import os
import re
import subprocess
import webbrowser

from .. import setup_server
from .defaults import DashboardDefaults
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions src/python/impactx/dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"html",
"JupyterApp",
"setup_server",
"html",
"vuetify",
"AnalyzeSimulation",
"NavigationComponents",
Expand Down
1 change: 1 addition & 0 deletions src/python/impactx/dashboard/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading