From 7d0124240c78a10f3e39fa7aad42671d60c29705 Mon Sep 17 00:00:00 2001 From: Hunter Johnston Date: Sat, 18 Jun 2022 23:05:18 -0400 Subject: [PATCH 1/3] Implemented feature #9525 --- netbox/netbox/tables/tables.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/netbox/netbox/tables/tables.py b/netbox/netbox/tables/tables.py index 8c5fb039c..b2bf6e967 100644 --- a/netbox/netbox/tables/tables.py +++ b/netbox/netbox/tables/tables.py @@ -165,7 +165,14 @@ class NetBoxTable(BaseTable): linkify=True, verbose_name='ID' ) - actions = columns.ActionsColumn() + actions = columns.ActionsColumn( + extra_buttons=""" + + + + + """ + ) exempt_columns = ('pk', 'actions') From f217167123a3823fbfea5a8ad16b3dfc5d8e7f6e Mon Sep 17 00:00:00 2001 From: Hunter Johnston Date: Sat, 18 Jun 2022 23:08:06 -0400 Subject: [PATCH 2/3] Implemented feature #9525 --- netbox/netbox/tables/tables.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/netbox/netbox/tables/tables.py b/netbox/netbox/tables/tables.py index b2bf6e967..de73bf6fe 100644 --- a/netbox/netbox/tables/tables.py +++ b/netbox/netbox/tables/tables.py @@ -167,10 +167,7 @@ class NetBoxTable(BaseTable): ) actions = columns.ActionsColumn( extra_buttons=""" - - - - + """ ) From 3541636f5283a98dd1fd9a5dfd4f71724219b40d Mon Sep 17 00:00:00 2001 From: Hunter Johnston Date: Sun, 19 Jun 2022 19:12:52 -0400 Subject: [PATCH 3/3] Closes #9525: Added split button functionality to ActionsColumn --- netbox/netbox/tables/columns.py | 43 ++++++++++++++++++++++++++------- netbox/netbox/tables/tables.py | 6 +---- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/netbox/netbox/tables/columns.py b/netbox/netbox/tables/columns.py index e82e8a1ea..9067b13f2 100644 --- a/netbox/netbox/tables/columns.py +++ b/netbox/netbox/tables/columns.py @@ -175,6 +175,7 @@ class ActionsColumn(tables.Column): :param actions: The ordered list of dropdown menu items to include :param extra_buttons: A Django template string which renders additional buttons preceding the actions dropdown + :param split_actions: When True, converts the actions dropdown menu into a split button with first action as the direct button link and icon (default: True) """ attrs = {'td': {'class': 'text-end text-nowrap noprint'}} empty_values = () @@ -184,10 +185,11 @@ class ActionsColumn(tables.Column): 'changelog': ActionsItem('Changelog', 'history'), } - def __init__(self, *args, actions=('edit', 'delete', 'changelog'), extra_buttons='', **kwargs): + def __init__(self, *args, actions=('edit', 'delete', 'changelog'), extra_buttons='', split_actions=True, **kwargs): super().__init__(*args, **kwargs) self.extra_buttons = extra_buttons + self.split_actions = split_actions # Determine which actions to enable self.actions = { @@ -210,19 +212,42 @@ class ActionsColumn(tables.Column): # Compile actions menu links = [] user = getattr(request, 'user', AnonymousUser()) - for action, attrs in self.actions.items(): + for idx, (action, attrs) in enumerate(self.actions.items()): permission = f'{model._meta.app_label}.{attrs.permission}_{model._meta.model_name}' if attrs.permission is None or user.has_perm(permission): url = reverse(get_viewname(model, action), kwargs={'pk': record.pk}) - links.append( - f'
  • ' - f' {attrs.title}
  • ' - ) + + # If only a single action exists, render a regular button + if len(self.actions.items()) == 1: + html += ( + f'' + f'' + ) + + # Creates split button for the first action with direct link and icon + elif self.split_actions and idx == 0: + html += ( + f'' + f'' + f'' + ) + + # Creates standard action dropdown menu items + else: + links.append( + f'
  • ' + f' {attrs.title}
  • ' + ) + + # Create the actions dropdown menu if links: + dropdown_icon = '' if self.split_actions else '' + dropdown_class = '' if self.split_actions else '' html += ( - f'' - f'' - f'' + f'{dropdown_class}' + f'' + f'{dropdown_icon}' + f'Toggle Dropdown' f'' ) diff --git a/netbox/netbox/tables/tables.py b/netbox/netbox/tables/tables.py index de73bf6fe..8c5fb039c 100644 --- a/netbox/netbox/tables/tables.py +++ b/netbox/netbox/tables/tables.py @@ -165,11 +165,7 @@ class NetBoxTable(BaseTable): linkify=True, verbose_name='ID' ) - actions = columns.ActionsColumn( - extra_buttons=""" - - """ - ) + actions = columns.ActionsColumn() exempt_columns = ('pk', 'actions')