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)] 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'}) ]