mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-08 21:38:21 +00:00
Working on the SQL console
- Fixed issue with the delete action not working properly - Implementation of page size change in results (#27)
This commit is contained in:
parent
fefb803a4a
commit
6d157d2a4b
@ -87,7 +87,7 @@ public class SnapAdmin {
|
||||
|
||||
private boolean authenticated;
|
||||
|
||||
private static final String VERSION = "0.1.9";
|
||||
private static final String VERSION = "0.2.0";
|
||||
|
||||
/**
|
||||
* Builds the SnapAdmin instance by scanning the `@Entity` beans and loading
|
||||
|
@ -75,7 +75,6 @@ import tech.ailef.snapadmin.external.misc.Utils;
|
||||
import tech.ailef.snapadmin.internal.model.ConsoleQuery;
|
||||
import tech.ailef.snapadmin.internal.model.UserAction;
|
||||
import tech.ailef.snapadmin.internal.model.UserSetting;
|
||||
import tech.ailef.snapadmin.internal.repository.ConsoleQueryRepository;
|
||||
import tech.ailef.snapadmin.internal.service.ConsoleQueryService;
|
||||
import tech.ailef.snapadmin.internal.service.UserActionService;
|
||||
import tech.ailef.snapadmin.internal.service.UserSettingsService;
|
||||
@ -100,9 +99,6 @@ public class SnapAdminController {
|
||||
@Autowired
|
||||
private UserActionService userActionService;
|
||||
|
||||
@Autowired
|
||||
private ConsoleQueryRepository consoleQueryRepository;
|
||||
|
||||
@Autowired
|
||||
private ConsoleQueryService consoleService;
|
||||
|
||||
@ -581,7 +577,7 @@ public class SnapAdminController {
|
||||
throw new SnapAdminException("SQL console not enabled");
|
||||
}
|
||||
|
||||
List<ConsoleQuery> tabs = consoleQueryRepository.findAll();
|
||||
List<ConsoleQuery> tabs = consoleService.findAll();
|
||||
|
||||
if (tabs.isEmpty()) {
|
||||
ConsoleQuery q = new ConsoleQuery();
|
||||
@ -597,8 +593,7 @@ public class SnapAdminController {
|
||||
if (!properties.isSqlConsoleEnabled()) {
|
||||
throw new SnapAdminException("SQL console not enabled");
|
||||
}
|
||||
|
||||
consoleQueryRepository.deleteById(queryId);
|
||||
consoleService.delete(queryId);
|
||||
return "redirect:/" + properties.getBaseUrl() + "/console";
|
||||
}
|
||||
|
||||
@ -617,7 +612,7 @@ public class SnapAdminController {
|
||||
throw new SnapAdminException("SQL console not enabled");
|
||||
}
|
||||
|
||||
ConsoleQuery activeQuery = consoleQueryRepository.findById(queryId).orElseThrow(() -> {
|
||||
ConsoleQuery activeQuery = consoleService.findById(queryId).orElseThrow(() -> {
|
||||
return new SnapAdminNotFoundException("Query with ID " + queryId + " not found.");
|
||||
});
|
||||
|
||||
@ -634,7 +629,7 @@ public class SnapAdminController {
|
||||
model.addAttribute("activePage", "console");
|
||||
model.addAttribute("activeQuery", activeQuery);
|
||||
|
||||
List<ConsoleQuery> tabs = consoleQueryRepository.findAll();
|
||||
List<ConsoleQuery> tabs = consoleService.findAll();
|
||||
model.addAttribute("tabs", tabs);
|
||||
|
||||
DbQueryResult results = repository.executeQuery(activeQuery.getSql());
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
package tech.ailef.snapadmin.internal.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
@ -37,6 +40,19 @@ public class ConsoleQueryService {
|
||||
return internalTransactionTemplate.execute((status) -> {
|
||||
return repo.save(q);
|
||||
});
|
||||
}
|
||||
|
||||
public void delete(String id) {
|
||||
internalTransactionTemplate.executeWithoutResult((status) -> {
|
||||
repo.deleteById(id);
|
||||
});
|
||||
}
|
||||
|
||||
public List<ConsoleQuery> findAll() {
|
||||
return repo.findAll();
|
||||
}
|
||||
|
||||
public Optional<ConsoleQuery> findById(String id) {
|
||||
return repo.findById(id);
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,14 @@ 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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
@ -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">
|
||||
<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"
|
||||
@ -141,11 +141,20 @@
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="d-flex align-items-center" th:if="${pagination.getMaxPage() > 1}">
|
||||
<p class="m-0 p-0">
|
||||
<div class="d-flex align-items-center flex-grow-1" th:if="${pagination.getMaxPage() > 1}">
|
||||
<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 class="form-select page-size" name="pageSize" 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>
|
||||
<button th:if="${results != null}" title="Open export data window" type="button"
|
||||
class="btn pb-0 pt-0" data-bs-toggle="modal" data-bs-target="#csvQueryExportModal">
|
||||
<i class="bi bi-file-earmark-spreadsheet export-icon" style="font-size: 1.6rem;"></i>
|
||||
@ -153,11 +162,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex align-items-center" th:if="${pagination.getMaxPage() == 1}">
|
||||
<p class="m-0 p-0">
|
||||
<div class="d-flex align-items-center flex-grow-1" th:if="${pagination.getMaxPage() == 1}">
|
||||
<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>
|
||||
<button th:if="${results != null}" title="Open export data window" type="button"
|
||||
class="btn pb-0 pt-0" data-bs-toggle="modal" data-bs-target="#csvQueryExportModal">
|
||||
<i class="bi bi-file-earmark-spreadsheet export-icon" style="font-size: 1.6rem;"></i>
|
||||
@ -239,6 +257,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" th:src="|/${snapadmin_baseUrl}/js/console.js|"></script>
|
||||
<script type="text/javascript" th:src="|/${snapadmin_baseUrl}/snapadmin/js/console.js|"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user