mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-08 21:38:21 +00:00
WIP SQL console: tabs
This commit is contained in:
parent
471c5ac18a
commit
0ec0f63359
@ -20,6 +20,7 @@
|
||||
package tech.ailef.dbadmin.external.controller;
|
||||
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -548,21 +549,52 @@ public class DefaultDbAdminController {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@GetMapping("/console")
|
||||
public String console(Model model, @RequestParam(required=false) String query) {
|
||||
@GetMapping("/console/new")
|
||||
public String consoleNew(Model model) {
|
||||
model.addAttribute("activePage", "console");
|
||||
model.addAttribute("query", query == null ? "" : query);
|
||||
|
||||
ConsoleQuery q = new ConsoleQuery();
|
||||
consoleQueryRepository.save(q);
|
||||
return "redirect:/" + properties.getBaseUrl() + "/console/run/" + q.getId();
|
||||
}
|
||||
|
||||
@GetMapping("/console")
|
||||
public String console(Model model) {
|
||||
List<ConsoleQuery> tabs = consoleQueryRepository.findAll();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/console/run/{queryId}")
|
||||
public String consoleRun(Model model, @RequestParam(required = false) String query, @PathVariable String queryId) {
|
||||
ConsoleQuery activeQuery = consoleQueryRepository.findById(queryId).orElseThrow(() -> {
|
||||
return new DbAdminNotFoundException("Query with ID " + queryId + " not found.");
|
||||
});
|
||||
|
||||
if (query != null && !query.isBlank()) {
|
||||
activeQuery.setSql(query);
|
||||
}
|
||||
|
||||
activeQuery.setUpdatedAt(LocalDateTime.now());
|
||||
consoleQueryRepository.save(activeQuery);
|
||||
|
||||
model.addAttribute("activePage", "console");
|
||||
model.addAttribute("activeQuery", activeQuery);
|
||||
|
||||
List<ConsoleQuery> tabs = consoleQueryRepository.findAll();
|
||||
model.addAttribute("tabs", tabs);
|
||||
if (query != null) {
|
||||
|
||||
if (activeQuery.getSql() != null && !activeQuery.getSql().isBlank()) {
|
||||
try {
|
||||
List<DbQueryResultRow> results = jdbTemplate.query(query, (rs, rowNum) -> {
|
||||
List<DbQueryResultRow> results = jdbTemplate.query(activeQuery.getSql(), (rs, rowNum) -> {
|
||||
Map<DbQueryOutputField, Object> result = new HashMap<>();
|
||||
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
@ -585,8 +617,6 @@ public class DefaultDbAdminController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return "console";
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package tech.ailef.dbadmin.internal.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.hibernate.annotations.UuidGenerator;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
@ -17,8 +19,14 @@ public class ConsoleQuery {
|
||||
|
||||
private String title;
|
||||
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
public ConsoleQuery() {
|
||||
this.title = "Untitled Query";
|
||||
this.createdAt = LocalDateTime.now();
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@ -45,4 +53,27 @@ public class ConsoleQuery {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ConsoleQuery [id=" + id + ", sql=" + sql + ", title=" + title + ", createdAt=" + createdAt
|
||||
+ ", updatedAt=" + updatedAt + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -120,6 +120,7 @@ h1 a:hover {
|
||||
border-top-right-radius: 5px;
|
||||
border-top-left-radius: 5px;
|
||||
background-color: #FAFAFA;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.inner-navigation a:first-child {
|
||||
@ -131,6 +132,10 @@ h1 a:hover {
|
||||
border-bottom: 4px solid #F0F0F0;
|
||||
}
|
||||
|
||||
.inner-navigation .inner-navigation-border a {
|
||||
border-bottom: none !important;
|
||||
}
|
||||
|
||||
.inner-navigation a {
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
|
@ -12,22 +12,30 @@
|
||||
<div class="row mt-4">
|
||||
<div class="col">
|
||||
<div class="w-100 d-flex inner-navigation">
|
||||
<a th:each="query : ${tabs}" th:href="|/${dbadmin_baseUrl}/console/${query.getId()}|">
|
||||
<a th:each="query : ${tabs}" th:href="|/${dbadmin_baseUrl}/console/run/${query.getId()}|"
|
||||
class="d-inline-block"
|
||||
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> Untitled Query
|
||||
|
||||
</div>
|
||||
</a>
|
||||
<div class="inner-navigation-border flex-grow-1">
|
||||
<div class="inner-navigation-border flex-grow-1 align-items-center d-flex">
|
||||
<h3 class="ms-3 mt-0 mb-0">
|
||||
<a th:href="|/${dbadmin_baseUrl}/console/new|">
|
||||
<i class="bi bi-plus-square-fill align-middle"></i>
|
||||
</a>
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box with-navigation">
|
||||
<form th:action="|/${dbadmin_baseUrl}/console|" method="GET">
|
||||
<form th:action="|/${dbadmin_baseUrl}/console/run/${activeQuery.getId()}|" method="GET">
|
||||
<textarea class="form-control" rows="6" name="query"
|
||||
th:text="${query}"></textarea>
|
||||
th:text="${activeQuery.getSql()}"></textarea>
|
||||
<input class="ui-btn btn btn-primary mt-3" type="submit" value="Run">
|
||||
</form>
|
||||
|
||||
<div th:if="${query != null && !query.isBlank() && error == null}">
|
||||
<div th:if="${error == null}">
|
||||
<div class="separator mt-3 mb-3"></div>
|
||||
<div th:replace="~{fragments/generic_table :: table(results=${results})}"></div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user