Skip to content

Commit 3c4eb0d

Browse files
committed
Config - format actions, add missing buttons
1 parent cd497f7 commit 3c4eb0d

File tree

7 files changed

+82
-28
lines changed

7 files changed

+82
-28
lines changed

src/hope/apps/administration/panels/console.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
from django.utils.translation import gettext_lazy as _
2727
from django.views.decorators.cache import cache_page
2828

29+
# Unfold-compatible CSS classes for form widgets
30+
_INPUT_CSS = (
31+
"border border-base-200 bg-white font-medium rounded-default shadow-xs "
32+
"text-font-default-light text-sm px-3 py-2 w-full max-w-2xl "
33+
"focus:outline-2 focus:-outline-offset-2 focus:outline-primary-600 "
34+
"dark:bg-base-900 dark:border-base-700 dark:text-font-default-dark"
35+
)
36+
_SELECT_CSS = _INPUT_CSS + " appearance-none pr-8"
37+
2938
logger = logging.getLogger(__name__)
3039

3140

@@ -81,8 +90,11 @@ def _sysinfo(request: Any) -> HttpResponse:
8190

8291

8392
class RedisCLIForm(forms.Form):
84-
command = forms.CharField()
85-
connection = forms.ChoiceField(choices=zip(settings.CACHES.keys(), settings.CACHES.keys(), strict=False))
93+
command = forms.CharField(widget=forms.TextInput(attrs={"class": _INPUT_CSS}))
94+
connection = forms.ChoiceField(
95+
choices=zip(settings.CACHES.keys(), settings.CACHES.keys(), strict=False),
96+
widget=forms.Select(attrs={"class": _SELECT_CSS}),
97+
)
8698

8799

88100
def panel_redis(self: Any, request: Any, extra_context: Any = None) -> HttpResponse:
@@ -161,7 +173,10 @@ class SentryForm(forms.Form):
161173
("404", "Error 404"),
162174
("500", "Error 500"),
163175
]
164-
action = forms.ChoiceField(choices=ACTIONS, widget=forms.RadioSelect)
176+
action = forms.ChoiceField(
177+
choices=ACTIONS,
178+
widget=forms.RadioSelect(attrs={"class": "accent-primary-600"}),
179+
)
165180

166181

167182
def panel_sentry(self: Any, request: Any, extra_context: Any = None) -> HttpResponse:
@@ -236,7 +251,10 @@ class ErrorPageForm(forms.Form):
236251
("404", "Error 404"),
237252
("500", "Error 500"),
238253
]
239-
action = forms.ChoiceField(choices=ACTIONS, widget=forms.RadioSelect)
254+
action = forms.ChoiceField(
255+
choices=ACTIONS,
256+
widget=forms.RadioSelect(attrs={"class": "accent-primary-600"}),
257+
)
240258

241259

242260
def panel_error_page(self: Any, request: Any, extra_context: Any = None) -> HttpResponse:

src/hope/apps/administration/panels/es.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class EsForm(forms.Form):
2525
("rebuild_search_index", "rebuild_search_index()"),
2626
("populate_all_indexes", "populate_all_indexes()"),
2727
]
28-
action = forms.ChoiceField(choices=ACTIONS, widget=forms.RadioSelect)
28+
action = forms.ChoiceField(
29+
choices=ACTIONS,
30+
widget=forms.RadioSelect(attrs={"class": "accent-primary-600"}),
31+
)
2932

3033

3134
class ElasticsearchPanel:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{# Reusable Unfold-styled form card for console panels. #}
2+
{# Pass `form` — renders visible fields with labels inside a bordered card. #}
3+
<div class="border border-base-200 dark:border-base-700 rounded-default bg-white dark:bg-base-900 shadow-xs overflow-hidden mb-4">
4+
<div class="p-4 space-y-5">
5+
{% for field in form.visible_fields %}
6+
<div>
7+
{% if field.label %}
8+
<label for="{{ field.id_for_label }}" class="block font-semibold mb-2 text-font-important-light dark:text-font-important-dark text-sm">
9+
{{ field.label }}
10+
</label>
11+
{% endif %}
12+
13+
<div class="text-sm [&_ul]:space-y-2.5 [&_ul]:list-none [&_ul]:p-0 [&_ul]:m-0 [&_li]:flex [&_li]:items-center [&_li]:gap-2.5 [&_label]:flex [&_label]:items-center [&_label]:gap-2.5 [&_label]:cursor-pointer [&_input[type=radio]]:accent-primary-600 [&_input[type=radio]]:w-4 [&_input[type=radio]]:h-4">
14+
{{ field }}
15+
</div>
16+
17+
{% if field.errors %}
18+
<div class="mt-1">
19+
{% for error in field.errors %}
20+
<p class="text-red-600 text-xs">{{ error }}</p>
21+
{% endfor %}
22+
</div>
23+
{% endif %}
24+
25+
{% if field.help_text %}
26+
<p class="text-font-subtle-light dark:text-font-subtle-dark text-xs mt-1">{{ field.help_text }}</p>
27+
{% endif %}
28+
</div>
29+
{% endfor %}
30+
</div>
31+
</div>

src/hope/apps/administration/templates/administration/panels/elasticsearch.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
{% include "administration/_kv_table.html" with items=config.items %}
44
<form method="post">
55
{% csrf_token %}
6-
<div class="border border-base-200 dark:border-base-700 rounded-default bg-white dark:bg-base-900 shadow-xs overflow-hidden mb-4">
7-
<table class="w-full text-sm">
8-
{{ form }}
9-
</table>
10-
</div>
6+
{% include "administration/_form_card.html" %}
117
<div class="mt-4">
128
<button type="submit" class="font-medium text-sm px-3 py-2 rounded-default border shadow-xs inline-flex items-center justify-center gap-1.5 bg-primary-600 border-transparent text-white hover:bg-primary-600/80">
139
<span class="material-symbols-outlined !text-[18px]">play_arrow</span> {% translate 'Execute' %}

src/hope/apps/administration/templates/administration/panels/email.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
{% include "administration/_kv_table.html" with items=smtp.items %}
1515
<form method="POST">
1616
{% csrf_token %}
17-
<div class="border border-base-200 dark:border-base-700 rounded-default bg-white dark:bg-base-900 shadow-xs overflow-hidden mb-4">
18-
<table class="w-full text-sm">
19-
{{ form }}
20-
</table>
21-
</div>
2217
<div class="mt-4">
2318
<button type="submit" class="font-medium text-sm px-3 py-2 rounded-default border shadow-xs inline-flex items-center justify-center gap-1.5 bg-primary-600 border-transparent text-white hover:bg-primary-600/80">
24-
<span class="material-symbols-outlined !text-[18px]">send</span> {% translate 'Test' %}
19+
<span class="material-symbols-outlined !text-[18px]">send</span> {% translate 'Send Test Email' %}
2520
</button>
2621
</div>
2722
</form>

src/hope/apps/administration/templates/administration/panels/redis.html

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
<div class="redis-cli">
44
<form method="POST" id="redisForm">
55
{% csrf_token %}
6-
<div class="border border-base-200 dark:border-base-700 rounded-default bg-white dark:bg-base-900 shadow-xs overflow-hidden mb-4">
7-
<table class="w-full text-sm">
8-
{{ form.connection }}
9-
{{ form.command }}
10-
</table>
11-
</div>
12-
<div class="mt-4 mb-6">
6+
{% include "administration/_form_card.html" %}
7+
<div class="flex flex-wrap items-center gap-2 mt-4 mb-6">
138
<button type="submit" class="font-medium text-sm px-3 py-2 rounded-default border shadow-xs inline-flex items-center justify-center gap-1.5 bg-primary-600 border-transparent text-white hover:bg-primary-600/80">
149
<span class="material-symbols-outlined !text-[18px]">play_arrow</span> {% translate 'Execute' %}
1510
</button>
11+
<span class="text-font-subtle-light dark:text-font-subtle-dark text-sm mx-1">|</span>
12+
<a href="#" class="redis-cli-command font-medium text-sm px-3 py-2 rounded-default border shadow-xs inline-flex items-center justify-center gap-1.5 border-base-200 bg-white text-important dark:border-base-700 dark:bg-transparent hover:bg-base-100/80 dark:hover:bg-base-800/80">FLUSHALL ASYNC</a>
13+
<a href="#" class="redis-cli-command font-medium text-sm px-3 py-2 rounded-default border shadow-xs inline-flex items-center justify-center gap-1.5 border-base-200 bg-white text-important dark:border-base-700 dark:bg-transparent hover:bg-base-100/80 dark:hover:bg-base-800/80">KEYS *</a>
14+
<a href="#" class="redis-cli-command font-medium text-sm px-3 py-2 rounded-default border shadow-xs inline-flex items-center justify-center gap-1.5 border-base-200 bg-white text-important dark:border-base-700 dark:bg-transparent hover:bg-base-100/80 dark:hover:bg-base-800/80">CONFIG GET *</a>
15+
<a href="https://redis.io/commands/" target="_blank" rel="noopener" class="font-medium text-sm px-3 py-2 rounded-default border shadow-xs inline-flex items-center justify-center gap-1.5 border-base-200 bg-white text-important dark:border-base-700 dark:bg-transparent hover:bg-base-100/80 dark:hover:bg-base-800/80">
16+
<span class="material-symbols-outlined !text-[18px]">open_in_new</span> {% translate 'Commands' %}
17+
</a>
1618
</div>
1719
</form>
1820
{% if stdout %}
@@ -25,3 +27,16 @@
2527
{% endif %}
2628
</div>
2729
{% endblock left %}
30+
31+
{% block footer %}
32+
<script src="{% static 'admin/js/jquery.init.js' %}"></script>
33+
<script>
34+
(function($) {
35+
$(".redis-cli-command").on("click", function(e) {
36+
e.preventDefault();
37+
$("#id_command").val($(this).text());
38+
$("#redisForm").submit();
39+
});
40+
})(django.jQuery);
41+
</script>
42+
{% endblock footer %}

src/hope/apps/administration/templates/administration/panels/sentry.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
<form method="POST">
66
{% csrf_token %}
7-
<div class="border border-base-200 dark:border-base-700 rounded-default bg-white dark:bg-base-900 shadow-xs overflow-hidden mb-4">
8-
<table class="w-full text-sm">
9-
{{ form }}
10-
</table>
11-
</div>
7+
{% include "administration/_form_card.html" %}
128
<div class="mt-4">
139
<button type="submit" class="font-medium text-sm px-3 py-2 rounded-default border shadow-xs inline-flex items-center justify-center gap-1.5 bg-primary-600 border-transparent text-white hover:bg-primary-600/80">
1410
<span class="material-symbols-outlined !text-[18px]">play_arrow</span> {% translate 'Execute' %}

0 commit comments

Comments
 (0)