mirror of
https://github.com/Quackster/Havana.git
synced 2025-07-03 13:17:46 +00:00
Add pagination to housekeeping ban overview page
This commit is contained in:
parent
e4ccf404a1
commit
8fa86cfb2b
3 changed files with 54 additions and 18 deletions
|
@ -115,28 +115,36 @@ public class BanDao {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Ban> getActiveBans() {
|
public static List<Ban> getActiveBans(int page, String sortBy) {
|
||||||
List<Ban> banList = new ArrayList<>();
|
List<Ban> banList = new ArrayList<>();
|
||||||
|
|
||||||
Connection sqlConnection = null;
|
int rows = 1;
|
||||||
PreparedStatement preparedStatement = null;
|
int nextOffset = page * rows;
|
||||||
ResultSet resultSet = null;
|
|
||||||
|
|
||||||
try {
|
if (nextOffset >= 0) {
|
||||||
sqlConnection = Storage.getStorage().getConnection();
|
Connection sqlConnection = null;
|
||||||
preparedStatement = Storage.getStorage().prepare("SELECT * FROM users_bans WHERE is_active = 1 ORDER BY banned_at DESC", sqlConnection);
|
PreparedStatement preparedStatement = null;
|
||||||
resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
while (resultSet.next()) {
|
try {
|
||||||
banList.add(new Ban(BanType.valueOf(resultSet.getString("ban_type")), resultSet.getString("banned_value"), resultSet.getString("message"), resultSet.getTime("banned_until").getTime() / 1000L,
|
sqlConnection = Storage.getStorage().getConnection();
|
||||||
resultSet.getTime("banned_at").getTime() / 1000L, resultSet.getInt("banned_by")));
|
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()) {
|
||||||
|
banList.add(new Ban(BanType.valueOf(resultSet.getString("ban_type")), resultSet.getString("banned_value"), resultSet.getString("message"), resultSet.getTime("banned_until").getTime() / 1000L,
|
||||||
|
resultSet.getTime("banned_at").getTime() / 1000L, resultSet.getInt("banned_by")));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Storage.logError(e);
|
||||||
|
} finally {
|
||||||
|
Storage.closeSilently(sqlConnection);
|
||||||
|
Storage.closeSilently(preparedStatement);
|
||||||
|
Storage.closeSilently(resultSet);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
Storage.logError(e);
|
|
||||||
} finally {
|
|
||||||
Storage.closeSilently(sqlConnection);
|
|
||||||
Storage.closeSilently(preparedStatement);
|
|
||||||
Storage.closeSilently(resultSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return banList;
|
return banList;
|
||||||
|
|
|
@ -15,6 +15,21 @@ public class HousekeepingBansController {
|
||||||
return;
|
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");
|
Template tpl = client.template("housekeeping/users_bans");
|
||||||
tpl.set("housekeepingManager", HousekeepingManager.getInstance());
|
tpl.set("housekeepingManager", HousekeepingManager.getInstance());
|
||||||
|
|
||||||
|
@ -25,7 +40,12 @@ public class HousekeepingBansController {
|
||||||
return;
|
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();
|
tpl.render();
|
||||||
|
|
||||||
// Delete alert after it's been rendered
|
// Delete alert after it's been rendered
|
||||||
|
|
|
@ -5,6 +5,14 @@
|
||||||
<h1 class="mt-4">View and manage bans</h1>
|
<h1 class="mt-4">View and manage bans</h1>
|
||||||
{% include "housekeeping/base/alert.tpl" %}
|
{% include "housekeeping/base/alert.tpl" %}
|
||||||
<p>Manage all currently active bans on the hotel</p>
|
<p>Manage all currently active bans on the hotel</p>
|
||||||
|
{% 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 class="table-responsive">
|
<div class="table-responsive">
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
|
|
Loading…
Add table
Reference in a new issue