1
Fork 0
mirror of https://github.com/Quackster/Havana.git synced 2025-07-05 06:07:46 +00:00

Merge pull request #17 from GitHabbo/feature/ban-pagination

Add pagination to housekeeping ban overview
This commit is contained in:
Quackster 2022-11-27 16:46:48 +10:00 committed by GitHub
commit cd6ae3fff0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 20 deletions

View file

@ -115,16 +115,23 @@ public class BanDao {
}
}
public static List<Ban> getActiveBans() {
public static List<Ban> getActiveBans(int page, String sortBy) {
List<Ban> banList = new ArrayList<>();
int rows = 25;
int nextOffset = page * rows;
if (nextOffset >= 0) {
Connection sqlConnection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
sqlConnection = Storage.getStorage().getConnection();
preparedStatement = Storage.getStorage().prepare("SELECT * FROM users_bans WHERE is_active = 1 ORDER BY banned_at DESC", sqlConnection);
preparedStatement = Storage.getStorage().prepare("SELECT * FROM users_bans WHERE is_active = 1 ORDER BY " + sortBy + " DESC LIMIT ? OFFSET ?", sqlConnection);
preparedStatement.setInt(1, rows);
preparedStatement.setInt(2, nextOffset);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
@ -138,6 +145,7 @@ public class BanDao {
Storage.closeSilently(preparedStatement);
Storage.closeSilently(resultSet);
}
}
return banList;
}

View file

@ -15,6 +15,21 @@ public class HousekeepingBansController {
return;
}
int currentPage = 0;
if (client.get().contains("page")) {
currentPage = Integer.parseInt(client.get().getString("page"));
}
String sortBy = "banned_at";
if (client.get().contains("sort")) {
if (client.get().getString("sort").equals("banned_at") ||
client.get().getString("sort").equals("banned_until")) {
sortBy = client.get().getString("sort");
}
}
Template tpl = client.template("housekeeping/users_bans");
tpl.set("housekeepingManager", HousekeepingManager.getInstance());
@ -25,7 +40,12 @@ public class HousekeepingBansController {
return;
}
tpl.set("bans", BanDao.getActiveBans());
tpl.set("pageName", "Bans");
tpl.set("bans", BanDao.getActiveBans(currentPage, sortBy));
tpl.set("nextBans", BanDao.getActiveBans(currentPage + 1, sortBy));
tpl.set("previousBans", BanDao.getActiveBans(currentPage - 1, sortBy));
tpl.set("page", currentPage);
tpl.set("sortBy", sortBy);
tpl.render();
// Delete alert after it's been rendered

View file

@ -5,6 +5,16 @@
<h1 class="mt-4">View and manage bans</h1>
{% include "housekeeping/base/alert.tpl" %}
<p>Manage all currently active bans on the hotel</p>
<div style="margin:10px">
{% if nextBans|length > 0 %}
{% set ourNextPage = page + 1 %}
<a href="{{ site.sitePath }}/{{ site.housekeepingPath }}/bans?page={{ ourNextPage }}&sort={{ sortBy }}"><button type="button" class="btn btn-info">Next Page</button></a>
{% endif %}
{% if previousBans|length > 0 %}
{% set ourNextPage = page - 1 %}
<a href="{{ site.sitePath }}/{{ site.housekeepingPath }}/bans?page={{ ourNextPage }}&sort={{ sortBy }}"><button type="button" class="btn btn-warning">Go back</button></a>
{% endif %}
</div>
<div class="table-responsive">
<form method="post">
<table class="table table-striped">
@ -13,8 +23,8 @@
<th>Type</th>
<th>Value</th>
<th>Message</th>
<th>Banned Util</th>
<th>Banned At</th>
<th><a href="{{ site.sitePath }}/{{ site.housekeepingPath }}/bans?page={{ page }}&sort=banned_until">Banned Util</a></th>
<th><a href="{{ site.sitePath }}/{{ site.housekeepingPath }}/bans?page={{ page }}&sort=banned_at">Banned At</a></th>
<th>Banned By</th>
</tr>
</thead>