Flag HTMX navigation as an experimental feature

This commit is contained in:
Jeremy Stretch 2024-04-23 10:38:49 -04:00
parent c32dff5649
commit e05ca710ae
4 changed files with 44 additions and 29 deletions

View File

@ -22,6 +22,7 @@ PREFERENCES = {
('dark', _('Dark')),
),
default='light',
description=_('Preferred default UI theme')
),
'ui.htmx_navigation': UserPreference(
label=_('HTMX Navigation'),
@ -29,14 +30,17 @@ PREFERENCES = {
('', _('Disabled')),
('true', _('Enabled')),
),
default=False
description=_('Enable dynamic UI navigation'),
default=False,
experimental=True
),
'locale.language': UserPreference(
label=_('Language'),
choices=(
('', _('Auto')),
*settings.LANGUAGES,
)
),
description=_('Forces UI translation to the specified language.')
),
'pagination.per_page': UserPreference(
label=_('Page length'),
@ -51,8 +55,8 @@ PREFERENCES = {
('top', _('Top')),
('both', _('Both')),
),
description=_('Where the paginator controls will be displayed relative to a table'),
default='bottom'
default='bottom',
description=_('Where the paginator controls will be displayed relative to a table')
),
# Miscellaneous
@ -62,6 +66,7 @@ PREFERENCES = {
('json', 'JSON'),
('yaml', 'YAML'),
),
description=_('The preferred syntax for displaying generic data within the UI')
),
}

View File

@ -39,30 +39,32 @@
{% trans "Clear table preferences" %}
</label>
<div class="col-sm-9">
<table class="table table-hover object-list">
<thead>
<tr>
<th>
<input type="checkbox" class="toggle form-check-input" title="{% trans "Toggle All" %}">
</th>
<th>{% trans "Table" %}</th>
<th>{% trans "Ordering" %}</th>
<th>{% trans "Columns" %}</th>
</tr>
</thead>
<tbody>
{% for table, prefs in request.user.config.data.tables.items %}
<div class="card">
<table class="table table-hover object-list">
<thead>
<tr>
<td>
<input type="checkbox" name="pk" value="tables.{{ table }}" class="form-check-input" />
</td>
<td>{{ table }}</td>
<td>{{ prefs.ordering|join:", "|placeholder }}</td>
<td>{{ prefs.columns|join:", "|placeholder }}</td>
<th>
<input type="checkbox" class="toggle form-check-input" title="{% trans "Toggle All" %}">
</th>
<th>{% trans "Table" %}</th>
<th>{% trans "Ordering" %}</th>
<th>{% trans "Columns" %}</th>
</tr>
{% endfor %}
</tbody>
</table>
</thead>
<tbody>
{% for table, prefs in request.user.config.data.tables.items %}
<tr>
<td>
<input type="checkbox" name="pk" value="tables.{{ table }}" class="form-check-input" />
</td>
<td>{{ table }}</td>
<td>{{ prefs.ordering|join:", "|placeholder }}</td>
<td>{{ prefs.columns|join:", "|placeholder }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% else %}
<div class="col-9 offset-3">

View File

@ -3,7 +3,7 @@ from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.postgres.forms import SimpleArrayField
from django.core.exceptions import FieldError
from django.utils.html import mark_safe
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from core.models import ObjectType
@ -37,7 +37,14 @@ class UserConfigFormMetaclass(forms.models.ModelFormMetaclass):
preference_fields = {}
for field_name, preference in PREFERENCES.items():
description = f'{preference.description}<br />' if preference.description else ''
help_text = f'{description}<code>{field_name}</code>'
help_text = f'<code>{field_name}</code>'
if preference.description:
help_text = f'{preference.description}<br />{help_text}'
if preference.experimental:
help_text = (
f'<span class="text-danger"><i class="mdi mdi-alert"></i> Experimental feature</span><br />'
f'{help_text}'
)
field_kwargs = {
'label': preference.label,
'choices': preference.choices,

View File

@ -2,9 +2,10 @@ class UserPreference:
"""
Represents a configurable user preference.
"""
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x):
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x, experimental=False):
self.label = label
self.choices = choices
self.default = default if default is not None else choices[0]
self.description = description
self.coerce = coerce
self.experimental = experimental