sortable admin instances list

This commit is contained in:
Hendrik L 2025-01-02 15:36:46 +01:00
parent 979f3cef91
commit 6b77192b74
2 changed files with 78 additions and 31 deletions

View file

@ -1525,9 +1525,10 @@ def admin_instances():
page = request.args.get('page', 1, type=int)
search = request.args.get('search', '')
filter = request.args.get('filter', '')
sort_by = request.args.get('sort_by', 'domain ASC')
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
instances = Instance.query.order_by(Instance.domain)
instances = Instance.query
if search:
instances = instances.filter(Instance.domain.ilike(f"%{search}%"))
@ -1548,15 +1549,15 @@ def admin_instances():
elif filter == 'blocked':
instances = instances.join(BannedInstances, BannedInstances.domain == Instance.domain)
# Pagination
instances = instances.order_by(text('"instance".' + sort_by))
instances = instances.paginate(page=page,
per_page=250 if current_user.is_authenticated and not low_bandwidth else 50,
error_out=False)
next_url = url_for('admin.admin_instances', page=instances.next_num) if instances.has_next else None
prev_url = url_for('admin.admin_instances', page=instances.prev_num) if instances.has_prev and page != 1 else None
next_url = url_for('admin.admin_instances', page=instances.next_num, search=search, filter=filter, sort_by=sort_by) if instances.has_next else None
prev_url = url_for('admin.admin_instances', page=instances.prev_num, search=search, filter=filter, sort_by=sort_by) if instances.has_prev and page != 1 else None
return render_template('admin/instances.html', instances=instances,
title=_(title), search=search,
title=_(title), search=search, filter=filter, sort_by=sort_by,
next_url=next_url, prev_url=prev_url,
low_bandwidth=low_bandwidth,
moderating_communities=moderating_communities(current_user.get_id()),

View file

@ -10,8 +10,9 @@
<div class="row">
<div class="col">
<h1>{{ title }}</h1>
<form method="get">
<input type="search" name="search"> <input type="submit" name="submit" value="Search">
<form id="searchInstances" method="get">
<input type="search" name="search" placeholder="{{ _('Search') }}" value="{{ search }}">
<input type="submit" name="submit" value="{{ _('Search') }}">
</form>
Status Filter:
<a href="{{ url_for('admin.admin_instances', filter='online') }}">{{ _('Online') }}</a> |
@ -21,41 +22,86 @@
<a href="{{ url_for('admin.admin_instances', filter='blocked') }}">{{ _('Blocked') }}</a>
<table class="table table-striped">
<tr>
<th>{{ _('Domain') }}</th>
<th>{{ _('Software') }}</th>
<th>{{ _('Version') }}</th>
<th>
<button form="searchInstances" name="sort_by" value="domain{{' DESC' if sort_by == 'domain ASC' else ' ASC' }}" class="btn" title="{{ _('Domain') }}">
{{ _('Domain') }}
<span class="{{ 'fe fe-chevron-up' if sort_by == 'domain DESC' }}{{ 'fe fe-chevron-down' if sort_by == 'domain ASC' }}"></span>
</button>
</th>
<th>
<button form="searchInstances" name="sort_by" value="software{{' DESC' if sort_by == 'software ASC' else ' ASC' }}" class="btn" title="{{ _('Software') }}">
{{ _('Software') }}
<span class="{{ 'fe fe-chevron-up' if sort_by == 'software DESC' }}{{ 'fe fe-chevron-down' if sort_by == 'software ASC' }}"></span>
</button>
</th>
<th>
<button form="searchInstances" name="sort_by" value="version{{' DESC' if sort_by == 'version ASC' else ' ASC' }}" class="btn" title="{{ _('Version') }}">
{{ _('Version') }}
<span class="{{ 'fe fe-chevron-up' if sort_by == 'version DESC' }}{{ 'fe fe-chevron-down' if sort_by == 'version ASC' }}"></span>
</button>
</th>
<th title="{{ _('Known Communities') }}">{{ _('Communities') }}</th>
<th title="{{ _('Known Users') }}">{{ _('Users') }}</th>
<th>{{ _('Posts') }}</th>
<th>{{ _('Post Replies') }}</th>
<th>{{ _('Vote Weight') }}</th>
<th>{{ _('Trusted') }}</th>
<th title="{{ _('When an Activity was received from them') }}">{{ _('Seen') }}</th>
<th title="{{ _('When we successfully sent them an Activity') }}">{{ _('Sent') }}</th>
<th title="{{ _('How many times we failed to send (reset to 0 after every successful send)') }}">{{ _('Failed') }}</th>
<th title="{{ _('Instance Status - Online/Dormant/Gone Forever') }}">{{ _('Status') }}</th>
<th>
<button form="searchInstances" name="sort_by" value="vote_weight{{' ASC' if sort_by == 'vote_weight DESC' else ' DESC' }}" class="btn" title="{{ _('Vote Weight') }}">
{{ _('Vote Weight') }}
<span class="{{ 'fe fe-chevron-up' if sort_by == 'vote_weight ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'vote_weight DESC' }}"></span>
</button>
</th>
<th>
<button form="searchInstances" name="sort_by" value="trusted{{' ASC' if sort_by == 'trusted DESC' else ' DESC' }}" class="btn" title="{{ _('Trusted') }}">
{{ _('Trusted') }}
<span class="{{ 'fe fe-chevron-up' if sort_by == 'trusted ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'trusted DESC' }}"></span>
</button>
</th>
<th>
<button form="searchInstances" name="sort_by" value="last_seen{{' ASC' if sort_by == 'last_seen DESC' else ' DESC' }}" class="btn" title="{{ _('When an Activity was received from them') }}">
{{ _('Seen') }}
<span class="{{ 'fe fe-chevron-up' if sort_by == 'last_seen ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'last_seen DESC' }}"></span>
</button>
</th>
<th>
<button form="searchInstances" name="sort_by" value="last_successful_send{{' ASC' if sort_by == 'last_successful_send DESC' else ' DESC' }}" class="btn" title="{{ _('When we successfully sent them an Activity') }}">
{{ _('Sent') }}
<span class="{{ 'fe fe-chevron-up' if sort_by == 'last_successful_send ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'last_successful_send DESC' }}"></span>
</button>
</th>
<th>
<button form="searchInstances" name="sort_by" value="failures{{' ASC' if sort_by == 'failures DESC' else ' DESC' }}" class="btn" title="{{ _('How many times we failed to send (reset to 0 after every successful send)') }}">
{{ _('Failed') }}
<span class="{{ 'fe fe-chevron-up' if sort_by == 'failures ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'failures DESC' }}"></span>
</button>
</th>
<th>
<button form="searchInstances" name="sort_by" value="{{'gone_forever ASC, dormant ASC' if sort_by == 'gone_forever DESC, dormant DESC' else 'gone_forever DESC, dormant DESC' }}" class="btn" title="{{ _('Instance Status - Online/Dormant/Gone Forever') }}">
{{ _('Status') }}
<span class="{{ 'fe fe-chevron-up' if sort_by == 'gone_forever ASC, dormant ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'gone_forever DESC, dormant DESC' }}"></span>
</button>
</th>
<th> </th>
</tr>
{% for instance in instances.items %}
<tr>
<td><a href="https://{{ instance.domain }}" rel="noopener nofollow noindex noreferrer">{{ instance.domain }}</a></td>
<td>{{ instance.software }}</td>
<td>{{ instance.version if instance.version }}</td>
<td>{{ instance.known_communities_count() }}</td>
<td>{{ instance.known_users_count() }}</td>
<td>{{ instance.post_count() }}</td>
<td>{{ instance.post_replies_count() }}</td>
<td>{{ instance.vote_weight }}</td>
<td>{{ _('Yes') if instance.trusted }}</td>
<td>{{ arrow.get(instance.last_seen).humanize(locale=locale) if instance.last_seen }}</td>
<td>{{ arrow.get(instance.last_successful_send).humanize(locale=locale) if instance.last_successful_send }}</td>
<td>{{ instance.failures }}</td>
<td><span title="{{ _('Domain') }}"><a href="https://{{ instance.domain }}" rel="noopener nofollow noindex noreferrer">{{ instance.domain }}</a></span></td>
<td><span title="{{ _('Software') }}">{{ instance.software }}</span></td>
<td><span title="{{ _('Version') }}">{{ instance.version if instance.version }}</span></td>
<td><span title="{{ _('Known Communities') }}">{{ instance.known_communities_count() }}</span></td>
<td><span title="{{ _('Known Users') }}">{{ instance.known_users_count() }}</span></td>
<td><span title="{{ _('Posts') }}">{{ instance.post_count() }}</span></td>
<td><span title="{{ _('Post Replies') }}">{{ instance.post_replies_count() }}</span></td>
<td><span title="{{ _('Vote Weight') }}">{{ instance.vote_weight }}</span></td>
<td><span title="{{ _('Trusted') }}">{{ _('Yes') if instance.trusted }}</span></td>
<td><span title="{{ _('Last Seen') }}">{{ arrow.get(instance.last_seen).humanize(locale=locale) if instance.last_seen }}</span></td>
<td><span title="{{ _('Sent') }}">{{ arrow.get(instance.last_successful_send).humanize(locale=locale) if instance.last_successful_send }}</span></td>
<td><span title="{{ _('Failed') }}">{{ instance.failures }}</span></td>
{% if instance.gone_forever %}
<td>{{ _('Gone forever') }}</td>
<td><span title="{{ _('Status') }}">{{ _('Gone forever') }}</span></td>
{% elif instance.dormant %}
<td>{{ _('Dormant') }}</td>
<td><span title="{{ _('Status') }}">{{ _('Dormant') }}</span></td>
{% else %}
<td>{{ _('Online') }}</td>
<td><span title="{{ _('Status') }}">{{ _('Online') }}</span></td>
{% endif %}
<td><a href="{{ url_for('admin.admin_instance_edit', instance_id=instance.id) }}">{{ _('Edit') }}</a></td>
</tr>