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 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
|
* 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.ConsoleQuery;
|
||||||
import tech.ailef.snapadmin.internal.model.UserAction;
|
import tech.ailef.snapadmin.internal.model.UserAction;
|
||||||
import tech.ailef.snapadmin.internal.model.UserSetting;
|
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.ConsoleQueryService;
|
||||||
import tech.ailef.snapadmin.internal.service.UserActionService;
|
import tech.ailef.snapadmin.internal.service.UserActionService;
|
||||||
import tech.ailef.snapadmin.internal.service.UserSettingsService;
|
import tech.ailef.snapadmin.internal.service.UserSettingsService;
|
||||||
@ -100,9 +99,6 @@ public class SnapAdminController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserActionService userActionService;
|
private UserActionService userActionService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConsoleQueryRepository consoleQueryRepository;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ConsoleQueryService consoleService;
|
private ConsoleQueryService consoleService;
|
||||||
|
|
||||||
@ -581,7 +577,7 @@ public class SnapAdminController {
|
|||||||
throw new SnapAdminException("SQL console not enabled");
|
throw new SnapAdminException("SQL console not enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ConsoleQuery> tabs = consoleQueryRepository.findAll();
|
List<ConsoleQuery> tabs = consoleService.findAll();
|
||||||
|
|
||||||
if (tabs.isEmpty()) {
|
if (tabs.isEmpty()) {
|
||||||
ConsoleQuery q = new ConsoleQuery();
|
ConsoleQuery q = new ConsoleQuery();
|
||||||
@ -597,8 +593,7 @@ public class SnapAdminController {
|
|||||||
if (!properties.isSqlConsoleEnabled()) {
|
if (!properties.isSqlConsoleEnabled()) {
|
||||||
throw new SnapAdminException("SQL console not enabled");
|
throw new SnapAdminException("SQL console not enabled");
|
||||||
}
|
}
|
||||||
|
consoleService.delete(queryId);
|
||||||
consoleQueryRepository.deleteById(queryId);
|
|
||||||
return "redirect:/" + properties.getBaseUrl() + "/console";
|
return "redirect:/" + properties.getBaseUrl() + "/console";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,7 +612,7 @@ public class SnapAdminController {
|
|||||||
throw new SnapAdminException("SQL console not enabled");
|
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.");
|
return new SnapAdminNotFoundException("Query with ID " + queryId + " not found.");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -634,7 +629,7 @@ public class SnapAdminController {
|
|||||||
model.addAttribute("activePage", "console");
|
model.addAttribute("activePage", "console");
|
||||||
model.addAttribute("activeQuery", activeQuery);
|
model.addAttribute("activeQuery", activeQuery);
|
||||||
|
|
||||||
List<ConsoleQuery> tabs = consoleQueryRepository.findAll();
|
List<ConsoleQuery> tabs = consoleService.findAll();
|
||||||
model.addAttribute("tabs", tabs);
|
model.addAttribute("tabs", tabs);
|
||||||
|
|
||||||
DbQueryResult results = repository.executeQuery(activeQuery.getSql());
|
DbQueryResult results = repository.executeQuery(activeQuery.getSql());
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
package tech.ailef.snapadmin.internal.service;
|
package tech.ailef.snapadmin.internal.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
@ -37,6 +40,19 @@ public class ConsoleQueryService {
|
|||||||
return internalTransactionTemplate.execute((status) -> {
|
return internalTransactionTemplate.execute((status) -> {
|
||||||
return repo.save(q);
|
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 -->
|
<!-- Pagination -->
|
||||||
<nav aria-label="Results pagination">
|
<nav aria-label="Results pagination">
|
||||||
<div class="d-flex justify-content-between">
|
<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">
|
<ul class="pagination me-3">
|
||||||
<li class="page-item" th:if="${pagination.getCurrentPage() != 1}">
|
<li class="page-item" th:if="${pagination.getCurrentPage() != 1}">
|
||||||
<a class="page-link"
|
<a class="page-link"
|
||||||
@ -141,11 +141,20 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="d-flex align-items-center" th:if="${pagination.getMaxPage() > 1}">
|
<div class="d-flex align-items-center flex-grow-1" 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()} ]]
|
<i>Showing [[ ${results.size()} ]] of [[ ${pagination.getMaxElement()} ]]
|
||||||
results in [[ ${elapsedTime} ]] seconds</i>
|
results in [[ ${elapsedTime} ]] seconds</i>
|
||||||
</p>
|
</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"
|
<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">
|
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>
|
<i class="bi bi-file-earmark-spreadsheet export-icon" style="font-size: 1.6rem;"></i>
|
||||||
@ -153,11 +162,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="d-flex align-items-center" th:if="${pagination.getMaxPage() == 1}">
|
<div class="d-flex align-items-center flex-grow-1" 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()} ]]
|
<i>Showing [[ ${results.size()} ]] of [[ ${pagination.getMaxElement()} ]]
|
||||||
results in [[ ${elapsedTime} ]] seconds</i>
|
results in [[ ${elapsedTime} ]] seconds</i>
|
||||||
</p>
|
</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"
|
<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">
|
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>
|
<i class="bi bi-file-earmark-spreadsheet export-icon" style="font-size: 1.6rem;"></i>
|
||||||
@ -239,6 +257,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user