mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-08 21:38:21 +00:00
Fixed lower page size change
This commit is contained in:
parent
32751552d4
commit
1f6d79cf6c
@ -28,6 +28,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -581,6 +582,16 @@ public class SnapAdminController {
|
||||
|
||||
if (tabs.isEmpty()) {
|
||||
ConsoleQuery q = new ConsoleQuery();
|
||||
|
||||
int randomIndex = new Random().nextInt(0, snapAdmin.getSchemas().size());
|
||||
String randomTable = snapAdmin.getSchemas().get(randomIndex).getTableName();
|
||||
|
||||
q.setSql(
|
||||
"-- It's recommended to always include a LIMIT clause in your query\n"
|
||||
+ "-- Although the SQL Console supports pagination, it retrieves the entire ResultSet\n\n"
|
||||
+ "-- SELECT * FROM " + randomTable + " LIMIT 1000;\n"
|
||||
);
|
||||
|
||||
consoleService.save(q);
|
||||
return "redirect:/" + properties.getBaseUrl() + "/console/run/" + q.getId();
|
||||
} else {
|
||||
@ -645,6 +656,9 @@ public class SnapAdminController {
|
||||
results.crop(startOffset, endOffset);
|
||||
model.addAttribute("pagination", pagination);
|
||||
model.addAttribute("results", results);
|
||||
} else {
|
||||
PaginationInfo pagination = new PaginationInfo(page, 0, pageSize, results.size(), null, null);
|
||||
model.addAttribute("pagination", pagination);
|
||||
}
|
||||
|
||||
model.addAttribute("title", "SQL Console | " + activeQuery.getTitle());
|
||||
|
@ -31,6 +31,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@ -294,29 +295,33 @@ public class SnapAdminRepository {
|
||||
public DbQueryResult executeQuery(String sql) {
|
||||
List<DbQueryResultRow> results = new ArrayList<>();
|
||||
if (sql != null && !sql.isBlank()) {
|
||||
results = jdbcTemplate.query(sql, (rs, rowNum) -> {
|
||||
Map<DbQueryOutputField, Object> result = new HashMap<>();
|
||||
try {
|
||||
results = jdbcTemplate.query(sql, (rs, rowNum) -> {
|
||||
Map<DbQueryOutputField, Object> result = new HashMap<>();
|
||||
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
int cols = metaData.getColumnCount();
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
int cols = metaData.getColumnCount();
|
||||
|
||||
for (int i = 0; i < cols; i++) {
|
||||
Object o = rs.getObject(i + 1);
|
||||
String columnName = metaData.getColumnName(i + 1);
|
||||
String tableName = metaData.getTableName(i + 1);
|
||||
DbQueryOutputField field = new DbQueryOutputField(columnName, tableName, snapAdmin);
|
||||
for (int i = 0; i < cols; i++) {
|
||||
Object o = rs.getObject(i + 1);
|
||||
String columnName = metaData.getColumnName(i + 1);
|
||||
String tableName = metaData.getTableName(i + 1);
|
||||
DbQueryOutputField field = new DbQueryOutputField(columnName, tableName, snapAdmin);
|
||||
|
||||
result.put(field, o);
|
||||
}
|
||||
result.put(field, o);
|
||||
}
|
||||
|
||||
DbQueryResultRow row = new DbQueryResultRow(result, sql);
|
||||
DbQueryResultRow row = new DbQueryResultRow(result, sql);
|
||||
|
||||
result.keySet().forEach(f -> {
|
||||
f.setResult(row);
|
||||
result.keySet().forEach(f -> {
|
||||
f.setResult(row);
|
||||
});
|
||||
|
||||
return row;
|
||||
});
|
||||
|
||||
return row;
|
||||
});
|
||||
} catch (TransientDataAccessResourceException e) {
|
||||
// If there's an exception we leave the results as empty
|
||||
}
|
||||
}
|
||||
return new DbQueryResult(results);
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
});
|
||||
|
||||
if (document.querySelector("nav select.page-size") != null) {
|
||||
document.querySelector("nav select.page-size").addEventListener('change', function(e) {
|
||||
console.log(e.target.parentElement);
|
||||
e.target.parentElement.submit();
|
||||
// this.parentElement.querySelector("input[name=\"pageSize\"]").value = e.target.value;
|
||||
// this.parentElement.submit();
|
||||
document.querySelectorAll("nav select.page-size").forEach(e => {
|
||||
e.addEventListener('change', function(e) {
|
||||
console.log(e.target.parentElement);
|
||||
e.target.parentElement.submit();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@
|
||||
<!-- Pagination -->
|
||||
<nav aria-label="Results pagination">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div th:if="${pagination != null && pagination.getMaxPage() != 1}" class="d-flex w-100">
|
||||
<div th:if="${pagination != null && pagination.getMaxPage() > 1}" class="d-flex w-100">
|
||||
<ul class="pagination me-3">
|
||||
<li class="page-item" th:if="${pagination.getCurrentPage() != 1}">
|
||||
<a class="page-link"
|
||||
@ -193,7 +193,7 @@
|
||||
<!-- Pagination -->
|
||||
<nav aria-label="Results pagination">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div th:if="${pagination != null && pagination.getMaxPage() != 1}" class="d-flex">
|
||||
<div th:if="${pagination != null && pagination.getMaxPage() > 1}" class="d-flex">
|
||||
<ul class="pagination me-3">
|
||||
<li class="page-item" th:if="${pagination.getCurrentPage() != 1}">
|
||||
<a class="page-link"
|
||||
@ -229,18 +229,36 @@
|
||||
</li>
|
||||
</ul>
|
||||
<div class="d-flex align-items-center" th:if="${pagination.getMaxPage() > 1}">
|
||||
<p class="m-0 p-0">
|
||||
<p class="m-0 p-0 me-2">
|
||||
<i>Showing [[ ${results.size()} ]] of [[ ${pagination.getMaxElement()} ]]
|
||||
results in [[ ${elapsedTime} ]] seconds</i>
|
||||
</p>
|
||||
<form method="GET" th:action="|/${snapadmin_baseUrl}/console/run/${activeQuery.getId()}|">
|
||||
<select name="pageSize" class="form-select page-size" style="width: 200px">
|
||||
<option disabled>Page size</option>
|
||||
<option th:selected="${pagination.getPageSize() == 50}">50</option>
|
||||
<option th:selected="${pagination.getPageSize() == 100}">100</option>
|
||||
<option th:selected="${pagination.getPageSize() == 150}">150</option>
|
||||
<option th:selected="${pagination.getPageSize() == 200}">200</option>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex align-items-center" th:if="${pagination.getMaxPage() == 1}">
|
||||
<p class="m-0 p-0">
|
||||
<p class="m-0 p-0 me-2">
|
||||
<i>Showing [[ ${results.size()} ]] of [[ ${pagination.getMaxElement()} ]]
|
||||
results in [[ ${elapsedTime} ]] seconds</i>
|
||||
</p>
|
||||
<form method="GET" th:action="|/${snapadmin_baseUrl}/console/run/${activeQuery.getId()}|">
|
||||
<select name="pageSize" class="form-select page-size" style="width: 200px">
|
||||
<option disabled>Page size</option>
|
||||
<option th:selected="${pagination.getPageSize() == 50}">50</option>
|
||||
<option th:selected="${pagination.getPageSize() == 100}">100</option>
|
||||
<option th:selected="${pagination.getPageSize() == 150}">150</option>
|
||||
<option th:selected="${pagination.getPageSize() == 200}">200</option>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user