@@ -41,6 +41,11 @@ def load_params(default: bool = False) -> dict[str, Any]:
4141 Returns:
4242 dict[str, Any]: A dictionary containing the parameters.
4343 """
44+
45+ # Check if workspace is enabled. If not, load default parameters.
46+ if not st .session_state .settings ["enable_workspaces" ]:
47+ default = True
48+
4449 # Construct the path to the parameter file
4550 path = Path (st .session_state .workspace , "params.json" )
4651
@@ -75,6 +80,11 @@ def save_params(params: dict[str, Any]) -> None:
7580 Returns:
7681 dict[str, Any]: Updated parameters.
7782 """
83+
84+ # Check if the workspace is enabled and if a 'params.json' file exists in the workspace directory
85+ if not st .session_state .settings ["enable_workspaces" ]:
86+ return
87+
7888 # Update the parameter dictionary with any modified parameters from the current session
7989 for key , value in st .session_state .items ():
8090 if key in params .keys ():
@@ -199,21 +209,28 @@ def page_setup(page: str = "") -> dict[str, Any]:
199209 os .chdir ("../streamlit-template" )
200210 # Define the directory where all workspaces will be stored
201211 workspaces_dir = Path (".." , "workspaces-" + st .session_state .settings ["repository-name" ])
202- if "workspace" in st .query_params :
203- st .session_state .workspace = Path (workspaces_dir , st .query_params .workspace )
204- elif st .session_state .location == "online" :
205- workspace_id = str (uuid .uuid1 ())
206- st .session_state .workspace = Path (workspaces_dir , workspace_id )
207- st .query_params .workspace = workspace_id
212+ # Check if workspace logic is enabled
213+ if st .session_state .settings ["enable_workspaces" ]:
214+ if "workspace" in st .query_params :
215+ st .session_state .workspace = Path (workspaces_dir , st .query_params .workspace )
216+ elif st .session_state .location == "online" :
217+ workspace_id = str (uuid .uuid1 ())
218+ st .session_state .workspace = Path (workspaces_dir , workspace_id )
219+ st .query_params .workspace = workspace_id
220+ else :
221+ st .session_state .workspace = Path (workspaces_dir , "default" )
222+ st .query_params .workspace = "default"
223+
208224 else :
225+ # Use default workspace when workspace feature is disabled
209226 st .session_state .workspace = Path (workspaces_dir , "default" )
210- st .query_params .workspace = "default"
211227
212228 if st .session_state .location != "online" :
213229 # not any captcha so, controllo should be true
214230 st .session_state ["controllo" ] = True
215231
216- if "workspace" not in st .query_params :
232+ # If no workspace is specified and workspace feature is enabled, set default workspace and query param
233+ if "workspace" not in st .query_params and st .session_state .settings ["enable_workspaces" ]:
217234 st .query_params .workspace = st .session_state .workspace .name
218235
219236 # Make sure the necessary directories exist
@@ -259,51 +276,53 @@ def render_sidebar(page: str = "") -> None:
259276 params = load_params ()
260277 with st .sidebar :
261278 # The main page has workspace switcher
262- with st .expander ("🖥️ **Workspaces**" ):
263- # Define workspaces directory outside of repository
264- workspaces_dir = Path (".." , "workspaces-" + st .session_state .settings ["repository-name" ])
265- # Online: show current workspace name in info text and option to change to other existing workspace
266- if st .session_state .location == "local" :
267- # Define callback function to change workspace
268- def change_workspace ():
269- for key in params .keys ():
270- if key in st .session_state .keys ():
271- del st .session_state [key ]
272- st .session_state .workspace = Path (
273- workspaces_dir , st .session_state ["chosen-workspace" ]
279+ # Display workspace switcher if workspace is enabled in local mode
280+ if st .session_state .settings ["enable_workspaces" ]:
281+ with st .expander ("🖥️ **Workspaces**" ):
282+ # Define workspaces directory outside of repository
283+ workspaces_dir = Path (".." , "workspaces-" + st .session_state .settings ["repository-name" ])
284+ # Online: show current workspace name in info text and option to change to other existing workspace
285+ if st .session_state .location == "local" :
286+ # Define callback function to change workspace
287+ def change_workspace ():
288+ for key in params .keys ():
289+ if key in st .session_state .keys ():
290+ del st .session_state [key ]
291+ st .session_state .workspace = Path (
292+ workspaces_dir , st .session_state ["chosen-workspace" ]
293+ )
294+ st .query_params .workspace = st .session_state ["chosen-workspace" ]
295+
296+ # Get all available workspaces as options
297+ options = [
298+ file .name for file in workspaces_dir .iterdir () if file .is_dir ()
299+ ]
300+ # Let user chose an already existing workspace
301+ st .selectbox (
302+ "choose existing workspace" ,
303+ options ,
304+ index = options .index (str (st .session_state .workspace .stem )),
305+ on_change = change_workspace ,
306+ key = "chosen-workspace" ,
274307 )
275- st .query_params .workspace = st .session_state ["chosen-workspace" ]
276-
277- # Get all available workspaces as options
278- options = [
279- file .name for file in workspaces_dir .iterdir () if file .is_dir ()
280- ]
281- # Let user chose an already existing workspace
282- st .selectbox (
283- "choose existing workspace" ,
284- options ,
285- index = options .index (str (st .session_state .workspace .stem )),
286- on_change = change_workspace ,
287- key = "chosen-workspace" ,
288- )
289- # Create or Remove workspaces
290- create_remove = st .text_input ("create/remove workspace" , "" )
291- path = Path (workspaces_dir , create_remove )
292- # Create new workspace
293- if st .button ("**Create Workspace**" ):
294- path .mkdir (parents = True , exist_ok = True )
295- st .session_state .workspace = path
296- st .query_params .workspace = create_remove
297- # Temporary as the query update takes a short amount of time
298- time .sleep (1 )
299- st .rerun ()
300- # Remove existing workspace and fall back to default
301- if st .button ("⚠️ Delete Workspace" ):
302- if path .exists ():
303- shutil .rmtree (path )
304- st .session_state .workspace = Path (workspaces_dir , "default" )
305- st .query_params .workspace = "default"
308+ # Create or Remove workspaces
309+ create_remove = st .text_input ("create/remove workspace" , "" )
310+ path = Path (workspaces_dir , create_remove )
311+ # Create new workspace
312+ if st .button ("**Create Workspace**" ):
313+ path .mkdir (parents = True , exist_ok = True )
314+ st .session_state .workspace = path
315+ st .query_params .workspace = create_remove
316+ # Temporary as the query update takes a short amount of time
317+ time .sleep (1 )
306318 st .rerun ()
319+ # Remove existing workspace and fall back to default
320+ if st .button ("⚠️ Delete Workspace" ):
321+ if path .exists ():
322+ shutil .rmtree (path )
323+ st .session_state .workspace = Path (workspaces_dir , "default" )
324+ st .query_params .workspace = "default"
325+ st .rerun ()
307326
308327 # All pages have settings, workflow indicator and logo
309328 with st .expander ("⚙️ **Settings**" ):
@@ -322,6 +341,28 @@ def change_workspace():
322341 )
323342 else :
324343 st .session_state ["spectrum_num_bins" ] = 50
344+
345+ # Display OpenMS WebApp Template Version from settings.json
346+ with st .container ():
347+ st .markdown (
348+ """
349+ <style>
350+ .version-box {
351+ border: 1px solid #a4a5ad;
352+ padding: 10px;
353+ border-radius: 0.5rem;
354+ text-align: center;
355+ display: flex;
356+ justify-content: center;
357+ align-items: center;
358+ }
359+ </style>
360+ """ ,
361+ unsafe_allow_html = True
362+ )
363+ version_info = st .session_state .settings ["version" ]
364+ app_name = st .session_state .settings ["app-name" ]
365+ st .markdown (f'<div class="version-box">{ app_name } <br>Version: { version_info } </div>' , unsafe_allow_html = True )
325366 return params
326367
327368
0 commit comments