WIP SQL console: foreign key resolution

This commit is contained in:
Francesco 2023-10-23 11:09:02 +02:00
parent 24c6972df7
commit 0ef44cbfb9
5 changed files with 24 additions and 7 deletions

View File

@ -557,15 +557,13 @@ public class DefaultDbAdminController {
throw new DbAdminException("SQL console not enabled");
}
model.addAttribute("activePage", "console");
ConsoleQuery q = new ConsoleQuery();
consoleQueryRepository.save(q);
return "redirect:/" + properties.getBaseUrl() + "/console/run/" + q.getId();
}
@GetMapping("/console")
public String console(Model model) {
public String console() {
if (!properties.isSqlConsoleEnabled()) {
throw new DbAdminException("SQL console not enabled");
}
@ -575,7 +573,6 @@ public class DefaultDbAdminController {
if (tabs.isEmpty()) {
ConsoleQuery q = new ConsoleQuery();
consoleQueryRepository.save(q);
tabs.add(q);
return "redirect:/" + properties.getBaseUrl() + "/console/run/" + q.getId();
} else {
return "redirect:/" + properties.getBaseUrl() + "/console/run/" + tabs.get(0).getId();
@ -600,7 +597,6 @@ public class DefaultDbAdminController {
@RequestParam(required = false) Integer page,
@RequestParam(required = false) Integer pageSize,
@PathVariable String queryId) {
if (page == null || page <= 0) page = 1;
if (pageSize == null) pageSize = 50;
@ -674,6 +670,7 @@ public class DefaultDbAdminController {
model.addAttribute("results", new DbQueryResult(results));
}
model.addAttribute("title", "SQL Console | " + activeQuery.getTitle());
double elapsedTime = (System.currentTimeMillis() - startTime) / 1000.0;
model.addAttribute("elapsedTime", new DecimalFormat("0.0#").format(elapsedTime));
return "console";

View File

@ -64,6 +64,11 @@ public class DbQueryOutputField {
public boolean isForeignKey() {
return dbField != null && dbField.isForeignKey();
}
public Class<?> getConnectedType() {
if (dbField == null) return null;
return dbField.getConnectedType();
}
/**
* Returns true if this field is a binary field (BLOB, etc.), only in the case

View File

@ -123,6 +123,10 @@ h1 a:hover {
overflow-x: auto;
}
.inner-navigation .query-tab {
min-width: 128px;
}
.inner-navigation a:first-child {
border-top-left-radius: 5px;
background-color: #FAFAFA;

View File

@ -13,7 +13,7 @@
<div class="col">
<div class="w-100 d-flex inner-navigation">
<a th:each="query : ${tabs}" th:href="|/${dbadmin_baseUrl}/console/run/${query.getId()}|"
class="d-inline-block"
class="d-inline-block query-tab"
th:classAppend="${query.getId() == activeQuery.getId() ? 'active' : ''}">
<div class="ui-tab ps-5 pe-5 p-3">
<i class="bi bi-filetype-sql pe-2"></i>

View File

@ -19,7 +19,18 @@
</th:block>
<th:block th:if="${!field.isBinary()}">
<span th:if="${object.get(field) != null}" th:text="${object.get(field)}"></span>
<span th:if="${object.get(field) != null}">
<th:block th:if="${field.isForeignKey()}">
<a th:href="|/${dbadmin_baseUrl}/model/${field.getConnectedType().getName()}/show/${object.get(field)}|">
<span th:text="${object.get(field)}"></span>
</a>
<p class="p-0 m-0"
th:text="${object.traverse(field).getDisplayName()}"></p>
</th:block>
<th:block th:if="${!field.isForeignKey()}">
<span th:text="${object.get(field)}"></span>
</th:block>
</span>
<span th:if="${object.get(field) == null}" class="null-label font-monospace">NULL</span>
</th:block>
</th:block>