Skip to content

Commit

Permalink
fix: sort hosts by type and name
Browse files Browse the repository at this point in the history
  • Loading branch information
alfg committed Feb 20, 2021
1 parent 87bff55 commit 3e36964
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
8 changes: 4 additions & 4 deletions app/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AdminView(FlaskView):
def index(self):
users_count = User.query.count()
servers_count = Server.query.count()
hosts = Host.query.order_by(Host.type.asc()).all()
hosts = Host.query.order_by(Host.type.asc(), Host.name.asc()).all()
feedback_count = Rating.query.count()
feedback_avg = Rating.get_rating_average()
tokens_count = Token.query.count()
Expand Down Expand Up @@ -167,7 +167,7 @@ class AdminPortsView(FlaskView):
@login_required
@admin_required
def index(self):
hosts = Host.query.all()
hosts = Host.query.order_by(Host.type.asc(), Host.name.asc()).all()
return render_template('admin/ports.html', hosts=hosts, title="Ports")

@login_required
Expand Down Expand Up @@ -230,14 +230,14 @@ class AdminHostsView(FlaskView):
@admin_required
def index(self):
form = CreateHostForm()
hosts = Host.query.order_by(Host.id.desc()).all()
hosts = Host.query.order_by(Host.type.asc(), Host.name.asc()).all()
return render_template('admin/hosts.html', hosts=hosts, form=form, title="Hosts")

@login_required
@admin_required
def post(self):
form = CreateHostForm()
hosts = Host.query.order_by(Host.id.desc()).all()
hosts = Host.query.order_by(Host.type.asc(), Host.name.asc()).all()
if form.validate_on_submit():
try:
# Create database entry
Expand Down
4 changes: 2 additions & 2 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ def get_hosts_by_type(type):
type = HOST_TYPE_FREE
elif type == "upgrade":
type = HOST_TYPE_UPGRADE
hosts = Host.query.filter_by(type=type).all()
hosts = Host.query.filter_by(type=type).order_by(Host.name.asc()).all()
return hosts

@staticmethod
def get_all_hosts():
hosts = Host.query.all()
hosts = Host.query.order_by(Host.type.desc(), Host.name.asc()).all()
return hosts

def __repr__(self):
Expand Down
32 changes: 17 additions & 15 deletions app/templates/admin/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
{% block title %}Admin Home{% endblock %}

{% block body %}
<h3>System Information (App Server)</h3>
<table class="pure-table pure-table-horizontal pure-table-striped" style="width:20%;">
<tbody>
<tr>
<td colspan="1"><strong>Memory</strong></td>
<td colspan="1"><strong>Disk</strong></td>
</tr>
<tr>
<td>{{ ctx.memory.percent }}%</td>
<td>{{ ctx.disk.percent }}%</td>
</tr>
</tbody>
</table>
<h3>Stats</h3>
<table class="pure-table pure-table-horizontal pure-table-striped">
<tbody>
Expand Down Expand Up @@ -41,8 +54,9 @@ <h3>Hosts</h3>
<table class="pure-table pure-table-horizontal pure-table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Hostname</th>
<th>Region</th>
<th>Type</th>
<th>Active</th>
<th>Servers</th>
Expand All @@ -54,8 +68,9 @@ <h3>Hosts</h3>
<tbody>
{% for host in ctx.hosts %}
<tr class="host" data-region="{{ host.region }}">
<td>{{ host.id }}</td>
<td><a href="/admin/ports/{{ host.id }}">{{ host.name }}</a></td>
<td><a href="/admin/ports/{{ host.id }}">{{ host.hostname }}</a></td>
<td><a href="/admin/ports/{{ host.id }}">{{ host.region }}</a></td>
<td>{{ 'Upgraded ⚡️' if host.type == 1 else 'Free' }}</td>
<td>{{ '✔️' if host.active else '❌' }}</td>
<td><span class="servers label">-</span></td>
Expand All @@ -66,19 +81,6 @@ <h3>Hosts</h3>
</tbody>
</table>

<h3>System Information (App Server)</h3>
<table class="pure-table pure-table-horizontal pure-table-striped" style="width:20%;">
<tbody>
<tr>
<td colspan="1"><strong>Memory</strong></td>
<td colspan="1"><strong>Disk</strong></td>
</tr>
<tr>
<td>{{ ctx.memory.percent }}%</td>
<td>{{ ctx.disk.percent }}%</td>
</tr>
</tbody>
</table>
<br />

{% endblock %}
Expand Down

0 comments on commit 3e36964

Please sign in to comment.