From 47811c293aae47c538eeaead52c17c255f543621 Mon Sep 17 00:00:00 2001 From: shenshan Date: Fri, 16 Jul 2021 10:42:54 -0400 Subject: [PATCH 1/4] refresh data when loading new tab --- datajoint_dashboard/templates.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/datajoint_dashboard/templates.py b/datajoint_dashboard/templates.py index 4527d48..dfa8a88 100644 --- a/datajoint_dashboard/templates.py +++ b/datajoint_dashboard/templates.py @@ -26,8 +26,6 @@ def __init__(self, filter_id, filter_name, multi=False, - table=None, - field_name=None, default_value=None, filter_style=None): """Filter object that is able to update its options @@ -43,10 +41,6 @@ def __init__(self, based on the table status. multi (boolean, optional): this filter is a single or multi option filter. Default is False. - table (DataJoint table object, optional): the table where - field_name comes from. Mandatory if options are not specified - field_name (str, optional): field name in table that serves as - the filter. Mandatory if options are not specified. default_value (single value or list): the default value of this filter for the first load. Single value if multi=False, list if multi=True @@ -75,7 +69,6 @@ def __init__(self, ) self.update_restrictor(default_value) - def update_restrictor(self, values): self.restrictor = self.query_function(values) @@ -193,12 +186,15 @@ def construct_layout( self, main_display_table=None, add_modal=None, - update_modal=None + update_modal=None, + refresh_data=True ): if main_display_table: self.main_display_table = main_display_table else: + if refresh_data: + self.main_table_data = self.query.fetch(as_dict=True) self.main_display_table = component_utils.create_display_table( self.table, f'{self.table_name}-table', height=self.table_height, width=self.table_width, @@ -310,9 +306,9 @@ def construct_layout( self.delete_message_box, self.filter_collection_layout, ], - + style={'marginRight': '2em', #Select Table style - 'marginLeft': '-3.75em', + 'marginLeft': '-3.75em', 'display': 'inline-block'} ), @@ -321,7 +317,7 @@ def construct_layout( self.display_table ], style={'marginRight': '2em', #Select Table style - 'marginLeft': '-2.75em', + 'marginLeft': '-2.75em', 'display': 'inline-block'}) ] From c39431cf106e8d30ae1c96640efca4cfa6e7af60 Mon Sep 17 00:00:00 2001 From: shenshan Date: Mon, 19 Jul 2021 12:09:20 -0400 Subject: [PATCH 2/4] debug --- datajoint_dashboard/templates.py | 1 + 1 file changed, 1 insertion(+) diff --git a/datajoint_dashboard/templates.py b/datajoint_dashboard/templates.py index dfa8a88..8b94b63 100644 --- a/datajoint_dashboard/templates.py +++ b/datajoint_dashboard/templates.py @@ -194,6 +194,7 @@ def construct_layout( self.main_display_table = main_display_table else: if refresh_data: + print(self.query) self.main_table_data = self.query.fetch(as_dict=True) self.main_display_table = component_utils.create_display_table( self.table, f'{self.table_name}-table', From e7e15095b739c3396d3fc27281afcd4385404b07 Mon Sep 17 00:00:00 2001 From: shenshan Date: Mon, 19 Jul 2021 18:23:39 -0400 Subject: [PATCH 3/4] remove print message --- datajoint_dashboard/templates.py | 1 - 1 file changed, 1 deletion(-) diff --git a/datajoint_dashboard/templates.py b/datajoint_dashboard/templates.py index 8b94b63..dfa8a88 100644 --- a/datajoint_dashboard/templates.py +++ b/datajoint_dashboard/templates.py @@ -194,7 +194,6 @@ def construct_layout( self.main_display_table = main_display_table else: if refresh_data: - print(self.query) self.main_table_data = self.query.fetch(as_dict=True) self.main_display_table = component_utils.create_display_table( self.table, f'{self.table_name}-table', From 0c11acccb6cc017a11d45ca6b301fe127eb79ed4 Mon Sep 17 00:00:00 2001 From: shenshan Date: Sat, 31 Jul 2021 11:03:16 -0400 Subject: [PATCH 4/4] add limit to dropdown list --- datajoint_dashboard/component_utils.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/datajoint_dashboard/component_utils.py b/datajoint_dashboard/component_utils.py index 84241f5..995eb76 100644 --- a/datajoint_dashboard/component_utils.py +++ b/datajoint_dashboard/component_utils.py @@ -97,7 +97,7 @@ def create_display_table( table_style['style_header'].update( { - + 'height': '40px', } ) @@ -118,16 +118,32 @@ def create_display_table( def create_edit_record_table( table, table_id, dropdown_fields=[], excluded_fields=[], + dropdown_limit=200, height='100px', width='1200px', n_rows=1, pk_editable=False, deletable=False, defaults={}): + """Create edit record table + Args: + table [DataJoint table object]: datajoint table that needs to be edited + table_id [str]: id in dash app + dropdown_fields [list]: list of dropdown fields, defaults [], if not specified, get all the dropdown fields, + which is either enum fields or foreign key references. + dropdown_limit [int]: limit number of entries in dropdown fields. + """ + if not dropdown_fields: dropdown_fields = dj_utils.get_dropdown_fields(table) - dropdown_fields = [f for f in dropdown_fields if f not in excluded_fields] + if dropdown_limit: + dropdown_fields = [f for f in dropdown_fields + if f not in excluded_fields and + len(dj_utils.get_options(table, f)) < dropdown_limit] + else: + dropdown_fields = [f for f in dropdown_fields + if f not in excluded_fields] required_fields = dj_utils.get_required_fields(table) @@ -224,7 +240,7 @@ def create_modal(table, id=None, dropdown_fields=[], extra_tables=[], style={'marginLeft': '2em', 'marginTop': '0.5em'} ) ) - + # TODO: allow defaults in part table as well if extra_tables: @@ -256,7 +272,7 @@ def create_modal(table, id=None, dropdown_fields=[], extra_tables=[], ), ) tables = [dbc.Row(master_table), dbc.Row(part_tables)] - + else: tables = [dbc.Row(master_table)]