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

Add dropdown limit #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 20 additions & 4 deletions datajoint_dashboard/component_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def create_display_table(

table_style['style_header'].update(
{

'height': '40px',
}
)
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)]

Expand Down
18 changes: 7 additions & 11 deletions datajoint_dashboard/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -75,7 +69,6 @@ def __init__(self,
)
self.update_restrictor(default_value)


def update_restrictor(self, values):
self.restrictor = self.query_function(values)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'}
),

Expand All @@ -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'})

]
Expand Down