Skip to content
Draft
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
1 change: 1 addition & 0 deletions changelog.d/1557.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Split user preferences into multiple sections
26 changes: 26 additions & 0 deletions src/argus/htmx/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5187,6 +5187,11 @@ details.collapse summary::-webkit-details-marker {
margin-bottom: 1rem;
}

.mx-auto {
margin-left: auto;
margin-right: auto;
}

.-ml-2 {
margin-left: -0.5rem;
}
Expand Down Expand Up @@ -5393,6 +5398,14 @@ details.collapse summary::-webkit-details-marker {
max-width: 20rem;
}

.max-w-md {
max-width: 28rem;
}

.max-w-screen-md {
max-width: 768px;
}

.flex-1 {
flex: 1 1 0%;
}
Expand Down Expand Up @@ -5656,6 +5669,11 @@ details.collapse summary::-webkit-details-marker {
border-style: none;
}

.border-base-200 {
--tw-border-opacity: 1;
border-color: var(--fallback-b2,oklch(var(--b2)/var(--tw-border-opacity, 1)));
}

.border-neutral-content {
--tw-border-opacity: 1;
border-color: var(--fallback-nc,oklch(var(--nc)/var(--tw-border-opacity, 1)));
Expand Down Expand Up @@ -5801,6 +5819,10 @@ details.collapse summary::-webkit-details-marker {
padding: 1.5rem;
}

.p-0\.5 {
padding: 0.125rem;
}

.px-1 {
padding-left: 0.25rem;
padding-right: 0.25rem;
Expand Down Expand Up @@ -6183,6 +6205,10 @@ details.collapse summary::-webkit-details-marker {
.lg\:grid-cols-4 {
grid-template-columns: repeat(4, minmax(0, 1fr));
}

.lg\:grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}

@media (min-width: 1280px) {
Expand Down
19 changes: 19 additions & 0 deletions src/argus/htmx/templates/htmx/user/preference_form/_base_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<section id="{% block section_id %}{% endblock section_id %}"
class="card card-base border border-base-200 p-4 max-w-screen-md mx-auto space-y-2">
<h3 class="card-title text-xl">
{% block section_title %}
{% endblock section_title %}
</h3>
<form hx-post="{% url 'htmx:update-preferences' namespace='argus_htmx' %}"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
class="space-y-2">
<ul class="card-body menu">
{% block section_forms %}
{% endblock section_forms %}
</ul>
<div class="preference-form-actions flex justify-end gap-2 px-2">
<button class="btn btn-primary btn-sm">Save preferences</button>
<button type="reset" class="btn btn-sm">Reset</button>
</div>
</form>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "htmx/user/preference_form/_base_form.html" %}
{% block section_id %}
user-settings
{% endblock section_id %}
{% block section_title %}
Incident Table
{% endblock section_title %}
{% block section_forms %}
{% for form in incident_forms %}{{ form }}{% endfor %}
{% endblock section_forms %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script>
const BUTTON_SELECTOR = '.preference-form-actions button';
document.querySelectorAll('form').forEach(form => {
const getFormData = f => JSON.stringify(Object.fromEntries(new FormData(f)));
const initial = getFormData(form);

// Disable all preference buttons on initialization
form.querySelectorAll(BUTTON_SELECTOR).forEach(btn => {
btn.disabled = true;
});

const updateButtons = () => {
const current = getFormData(form);
const dirty = current !== initial;
form.querySelectorAll(BUTTON_SELECTOR).forEach(btn => {
btn.disabled = !dirty;
});
};

form.addEventListener('input', updateButtons);
form.addEventListener('change', updateButtons);
form.addEventListener('reset', () => {
setTimeout(updateButtons, 0);
});
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "htmx/user/preference_form/_base_form.html" %}
{% block section_id %}
theme-settings
{% endblock section_id %}
{% block section_title %}
Theme and Format
{% endblock section_title %}
{% block section_forms %}
{% for form in theme_forms %}{{ form }}{% endfor %}
{% endblock section_forms %}
14 changes: 6 additions & 8 deletions src/argus/htmx/templates/htmx/user/preferences_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
{% extends "htmx/base.html" %}
{% block main %}
<div class="p-4 space-y-4">
<h1 class="text-3xl">{{ page_title }}</h1>
<section id="user-settings" class="card">
<ul class="menu card-body">
{% block preferences %}
{% for form in forms.values %}{{ form }}{% endfor %}
{% endblock preferences %}
</ul>
</section>
{% include "htmx/components/_page_title.html" %}
{% block preferences %}
{% include "htmx/user/preference_form/_theme_and_format_form.html" %}
{% include "htmx/user/preference_form/_incident_table_form.html" %}
{% include "htmx/user/preference_form/_preference_form_script.html" %}
{% endblock preferences %}
</div>
{% endblock main %}
6 changes: 2 additions & 4 deletions src/argus/htmx/templates/htmx/user/radio_option.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
<input type="radio"
class="btn btn-sm btn-block btn-ghost justify-start"
{% if widget.value != None %}value="{{ widget.value|stringformat:'s' }}"{% endif %}
{% if widget.attrs.checked %}checked="checked"{% endif %}
aria-label="{{ widget.label }}"
name="{{ widget.name }}"
autocomplete="off"
hx-post="{% url 'htmx:update-preferences' namespace='argus_htmx' %}"
hx-trigger="change"
hx-headers='{"X-CSRFToken": "{{ widget.attrs.csrf_token }}"}' />
autocomplete="off" />
8 changes: 7 additions & 1 deletion src/argus/htmx/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@
from argus.htmx.user.preferences.utils import setup_preference_forms


THEME_PREFERENCES = ["theme", "datetime_format_name"]


@require_GET
def user_preferences(request) -> HttpResponse:
"""Renders the main preferences page for a user"""

forms = setup_preference_forms(request)
theme_forms = [form for name, form in forms.items() if name in THEME_PREFERENCES]
incident_forms = [form for name, form in forms.items() if name not in THEME_PREFERENCES]

context = {
"page_title": "User preferences",
"forms": forms,
"theme_forms": theme_forms,
"incident_forms": incident_forms,
}

return render(request, "htmx/user/preferences_list.html", context=context)
Expand Down
Loading