Skip to content

Commit 2762eed

Browse files
committed
Refactor Create Buttons in servers.html
1 parent 55bd764 commit 2762eed

File tree

5 files changed

+47
-25
lines changed

5 files changed

+47
-25
lines changed

homelab_operator/static/css/base.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ html {
8282

8383
a {
8484
margin: 0;
85+
text-decoration: none;
86+
color: inherit;
8587
}
8688

8789
.login {

homelab_operator/templates/html/dashboard-sections/servers.html

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@ <h2 style="margin-bottom: 0.25rem;">Servers</h2>
99
</span>
1010
<div style="width: 1rem;"></div>
1111
<span style="margin: auto 0 0 0;">
12-
{% include 'html_components/inline_button.html' with label='Server' fa_icon='fa-plus' href='/create/server/' %}
13-
</span>
14-
<div style="width: 1rem;"></div>
15-
<span style="margin: auto 0 0 0;">
16-
{% include 'html_components/inline_button.html' with label='Service' fa_icon='fa-plus' href='/create/service/' %}
17-
</span>
18-
<div style="width: 1rem;"></div>
19-
<span style="margin: auto 0 0 0;">
20-
{% include 'html_components/inline_button.html' with label='Schedule' fa_icon='fa-plus' href='/create/schedule' %}
12+
{% include 'html_components/dropdown_select_button.html' with label='Create' fa_icon='fa-plus' select=server_select select_label='Select Action' %}
2113
</span>
2214
</span>
2315
</div>

homelab_operator/templates/html/dashboard.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ <h2>Welcome to Homelab Operator!</h2>
7171
{% include 'html/dashboard-sections/wiki.html' with servers=servers wiki=wiki %}
7272
{% endif %}
7373

74+
{# ByteBuddies #}
75+
7476
{# Ingress #}
7577
{% if user.profile.show_ingress %}
7678
{% include 'html/dashboard-sections/ingress.html' with ingresses=ingresses %}

homelab_operator/templates/html_components/dropdown_select_button.html

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,39 @@
1515
</div>
1616
<div class="spacer" style="height: .5rem;"></div>
1717
{% for option in select %}
18-
<form method="post" action="/confirm">
19-
{% csrf_token %}
20-
<input type="hidden" name="redirect_url_confirmed" value="{{ option.redirect_url_confirmed }}">
21-
<input type="hidden" name="redirect_url_declined" value="{{ option.redirect_url_declined }}">
22-
<input type="hidden" name="title" value="{{ option.title }}">
23-
<input type="hidden" name="message" value="{{ option.message }}">
18+
{% if option.confirm %}
19+
<form method="post" action="/confirm">
20+
{% csrf_token %}
21+
<input type="hidden" name="redirect_url_confirmed" value="{{ option.redirect_url_confirmed }}">
22+
<input type="hidden" name="redirect_url_declined" value="{{ option.redirect_url_declined }}">
23+
<input type="hidden" name="title" value="{{ option.title }}">
24+
<input type="hidden" name="message" value="{{ option.message }}">
2425

25-
<div class="dropdown-item" style="display: block; padding: .1rem .1rem .1rem .5rem; cursor: pointer;" onclick="event.preventDefault(); this.closest('form').submit();">
26-
<div>
27-
{{ option.name }}
26+
<div class="dropdown-item" style="display: block; padding: .1rem .1rem .1rem .5rem; cursor: pointer;" onclick="event.preventDefault(); this.closest('form'). submit();">
27+
<div>
28+
{{ option.name }}
29+
</div>
30+
{% if option.subname %}
31+
<span class="soft">{{ option.subname }}</span>
32+
{% else %}
33+
<span class="soft">No subname defined</span>
34+
{% endif %}
2835
</div>
29-
{% if option.subname %}
30-
<span class="soft">{{ option.subname }}</span>
31-
{% else %}
32-
<span class="soft">No subname defined</span>
33-
{% endif %}
34-
</div>
35-
</form>
36+
</form>
37+
{% else %}
38+
<a href="{{ option.href|default_if_none:'#' }}">
39+
<div class="dropdown-item" style="display: block; padding: .1rem .1rem .1rem .5rem; cursor: pointer;">
40+
<div>
41+
{{ option.name }}
42+
</div>
43+
{% if option.subname %}
44+
<span class="soft">{{ option.subname }}</span>
45+
{% else %}
46+
<span class="soft">No subname defined</span>
47+
{% endif %}
48+
</div>
49+
</a>
50+
{% endif %}
3651
{% endfor %}
3752
{% else %}
3853
<div class="soft dropdown-item" style="display: block; padding: .1rem .1rem .1rem .5rem;">

homelab_operator/webui/views.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def dashboard(request, homelab_id=None):
125125
networks_select = [{'name': network.name,
126126
'id': network.id,
127127
'subname': network.subnet or 'No subnet defined',
128+
'confirm': True,
128129
'title': 'Performing Auto-Discover',
129130
'message': 'Do you want to auto-discover servers and services in ' + \
130131
f'your homelab on <u>{network.subnet}</u>?<br><br>After confirming, ' + \
@@ -133,11 +134,21 @@ def dashboard(request, homelab_id=None):
133134
'as a background task.<br><br>Do not refresh this page.',
134135
'redirect_url_confirmed': f'/auto_discover/{network.id}/',
135136
'redirect_url_declined': '/dashboard/',} for network in networks]
137+
server_select = [{'name': 'Server',
138+
'subname': 'Create a Server',
139+
'href': '/create/server/'},
140+
{'name': 'Service',
141+
'subname': 'Create a Service',
142+
'href': '/create/service/'},
143+
{'name': 'Schedule',
144+
'subname': 'Create a Schedule',
145+
'href': '/create/schedule/'},]
136146

137147
context = {
138148
'servers': servers,
139149
'networks': networks,
140150
'networks_select': networks_select,
151+
'server_select': server_select,
141152
'homelabs': homelabs,
142153
'homelab': homelab,
143154
'wiki': homelab.wiki.first() if homelab.wiki.exists() else None,

0 commit comments

Comments
 (0)