mirror of
https://github.com/netbox-community/netbox.git
synced 2026-02-04 14:26:25 -06:00
Remove HTMX navigation
This commit is contained in:
@@ -28,7 +28,6 @@ def preferences(request):
|
|||||||
user_preferences = request.user.config if request.user.is_authenticated else {}
|
user_preferences = request.user.config if request.user.is_authenticated else {}
|
||||||
return {
|
return {
|
||||||
'preferences': user_preferences,
|
'preferences': user_preferences,
|
||||||
'htmx_navigation': user_preferences.get('ui.htmx_navigation', False) == 'true'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,16 +26,6 @@ def get_csv_delimiters():
|
|||||||
PREFERENCES = {
|
PREFERENCES = {
|
||||||
|
|
||||||
# User interface
|
# User interface
|
||||||
'ui.htmx_navigation': UserPreference(
|
|
||||||
label=_('HTMX Navigation'),
|
|
||||||
choices=(
|
|
||||||
('', _('Disabled')),
|
|
||||||
('true', _('Enabled')),
|
|
||||||
),
|
|
||||||
description=_('Enable dynamic UI navigation'),
|
|
||||||
default=False,
|
|
||||||
warning=_('Experimental feature')
|
|
||||||
),
|
|
||||||
'locale.language': UserPreference(
|
'locale.language': UserPreference(
|
||||||
label=_('Language'),
|
label=_('Language'),
|
||||||
choices=(
|
choices=(
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ Blocks:
|
|||||||
|
|
||||||
{# Page content #}
|
{# Page content #}
|
||||||
<div class="page-wrapper">
|
<div class="page-wrapper">
|
||||||
<div id="page-content" {% htmx_boost %}>
|
<div id="page-content">
|
||||||
|
|
||||||
{# Page header #}
|
{# Page header #}
|
||||||
{% block header %}
|
{% block header %}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow" {% htmx_boost %}>
|
<div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
|
||||||
<a href="{% url 'account:profile' %}" class="dropdown-item">
|
<a href="{% url 'account:profile' %}" class="dropdown-item">
|
||||||
<i class="mdi mdi-account"></i> {% trans "Profile" %}
|
<i class="mdi mdi-account"></i> {% trans "Profile" %}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -61,8 +61,7 @@ class UserConfigFormMetaclass(forms.models.ModelFormMetaclass):
|
|||||||
class UserConfigForm(forms.ModelForm, metaclass=UserConfigFormMetaclass):
|
class UserConfigForm(forms.ModelForm, metaclass=UserConfigFormMetaclass):
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet(
|
FieldSet(
|
||||||
'locale.language', 'pagination.per_page', 'pagination.placement', 'ui.htmx_navigation',
|
'locale.language', 'pagination.per_page', 'pagination.placement', 'ui.tables.striping',
|
||||||
'ui.tables.striping',
|
|
||||||
name=_('User Interface')
|
name=_('User Interface')
|
||||||
),
|
),
|
||||||
FieldSet('data_format', 'csv_delimiter', name=_('Miscellaneous')),
|
FieldSet('data_format', 'csv_delimiter', name=_('Miscellaneous')),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load navigation %}
|
{% load navigation %}
|
||||||
|
|
||||||
<ul class="navbar-nav pt-lg-2" {% htmx_boost %}>
|
<ul class="navbar-nav pt-lg-2">
|
||||||
<li class="nav-item d-block d-lg-none">
|
<li class="nav-item d-block d-lg-none">
|
||||||
<form action="{% url 'search' %}" method="get" autocomplete="off" novalidate>
|
<form action="{% url 'search' %}" method="get" autocomplete="off" novalidate>
|
||||||
<div class="input-group mb-1 mt-2">
|
<div class="input-group mb-1 mt-2">
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from django import template
|
from django import template
|
||||||
from django.utils.safestring import mark_safe
|
|
||||||
|
|
||||||
from extras.choices import CustomFieldTypeChoices
|
from extras.choices import CustomFieldTypeChoices
|
||||||
from utilities.querydict import dict_to_querydict
|
from utilities.querydict import dict_to_querydict
|
||||||
@@ -121,9 +120,7 @@ def htmx_table(context, viewname, return_url=None, **kwargs):
|
|||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def formaction(context):
|
def formaction(context):
|
||||||
"""
|
"""
|
||||||
Replace the 'formaction' attribute on an HTML element with the appropriate HTMX attributes
|
A hook for overriding the 'formaction' attribute on an HTML element, for example to replace
|
||||||
if HTMX navigation is enabled (per the user's preferences).
|
with 'hx-push-url="true" hx-post' for HTMX navigation.
|
||||||
"""
|
"""
|
||||||
if context.get('htmx_navigation', False):
|
|
||||||
return mark_safe('hx-push-url="true" hx-post')
|
|
||||||
return 'formaction'
|
return 'formaction'
|
||||||
|
|||||||
@@ -226,7 +226,6 @@ def bulk_edit_button(context, model, action='bulk_edit', query_params=None):
|
|||||||
return {
|
return {
|
||||||
'label': _('Edit Selected'),
|
'label': _('Edit Selected'),
|
||||||
'url': url,
|
'url': url,
|
||||||
'htmx_navigation': context.get('htmx_navigation'),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -243,5 +242,4 @@ def bulk_delete_button(context, model, action='bulk_delete', query_params=None):
|
|||||||
return {
|
return {
|
||||||
'label': _('Delete Selected'),
|
'label': _('Delete Selected'),
|
||||||
'url': url,
|
'url': url,
|
||||||
'htmx_navigation': context.get('htmx_navigation'),
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
from django import template
|
from django import template
|
||||||
from django.utils.safestring import mark_safe
|
|
||||||
|
|
||||||
from netbox.navigation.menu import MENUS
|
from netbox.navigation.menu import MENUS
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'nav',
|
'nav',
|
||||||
'htmx_boost',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -43,30 +41,4 @@ def nav(context):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
'nav_items': nav_items,
|
'nav_items': nav_items,
|
||||||
'htmx_navigation': context['htmx_navigation']
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
|
||||||
def htmx_boost(context, target='#page-content', select='#page-content'):
|
|
||||||
"""
|
|
||||||
Renders the HTML attributes needed to effect HTMX boosting within an element if
|
|
||||||
HTMX navigation is enabled for the request. The target and select parameters are
|
|
||||||
rendered as `hx-target` and `hx-select`, respectively. For example:
|
|
||||||
|
|
||||||
<div id="page-content" {% htmx_boost %}>
|
|
||||||
|
|
||||||
If HTMX navigation is not enabled, the tag renders no content.
|
|
||||||
"""
|
|
||||||
if not context.get('htmx_navigation', False):
|
|
||||||
return ''
|
|
||||||
hx_params = {
|
|
||||||
'hx-boost': 'true',
|
|
||||||
'hx-target': target,
|
|
||||||
'hx-select': select,
|
|
||||||
'hx-swap': 'outerHTML show:window:top',
|
|
||||||
}
|
|
||||||
htmx_params = ' '.join([
|
|
||||||
f'{k}="{v}"' for k, v in hx_params.items()
|
|
||||||
])
|
|
||||||
return mark_safe(htmx_params)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user