From 86199d3dcff064bde7cb1ed73df0a00d8415bfdd Mon Sep 17 00:00:00 2001 From: niksirbi Date: Thu, 30 Mar 2023 16:55:50 +0100 Subject: [PATCH] added callback for updating event dropdown --- wazp/callbacks/events.py | 55 ++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/wazp/callbacks/events.py b/wazp/callbacks/events.py index 305c0e0..53fac37 100644 --- a/wazp/callbacks/events.py +++ b/wazp/callbacks/events.py @@ -1,5 +1,3 @@ -from typing import Optional - import dash from dash import Input, Output @@ -23,17 +21,15 @@ def get_callbacks(app: dash.Dash) -> None: ) def update_events_video_select( app_storage: dict, - ) -> tuple[list, Optional[str]]: + ) -> tuple[list, str]: """Update the video selection dropdown with the videos defined in the project configuration file. Parameters ---------- app_storage : dict - dictionary with the following keys and values: - - 'config': a dict with the project configuration parameters - - 'metadata_fields': a dict with a set of attributes - - 'video_paths': a dict storing paths to the video files + data held in temporary memory storage, + accessible to all tabs in the app Returns ------- @@ -45,10 +41,49 @@ def update_events_video_select( Currently selected video name """ - options = [] if "video_paths" in app_storage: options = [ {"label": v, "value": v} for v in app_storage["video_paths"] ] - value = options[0]["value"] if options else None - return options, value + value = options[0]["value"] + return options, value + else: + return dash.no_update, dash.no_update + + @app.callback( + [ + Output("event-select", "options"), + Output("event-select", "value"), + ], + Input("session-storage", "data"), + ) + def update_event_select_options( + app_storage: dict, + ) -> tuple[list, str]: + """Update the options of the event select dropdown with + the event tags defined in the project configuration file. + + Parameters + ---------- + app_storage : dict + data held in temporary memory storage, + accessible to all tabs in the app + + Returns + ------- + options : list + list of dictionaries with the following keys and values: + - 'label': event tag + - 'value': event tag + value : str + Currently selected event tag + """ + if "config" in app_storage.keys(): + # Get ROI names from stored config + config = app_storage["config"] + event_tags = config["event_tags"] + options = [{"label": t, "value": t} for t in event_tags] + value = event_tags[0] + return options, value + else: + return dash.no_update, dash.no_update