mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-09 05:48:20 +00:00
WIP SQL console: enable flag; better table output
This commit is contained in:
parent
c9a9dc6e4c
commit
ee58fa0d77
@ -19,9 +19,6 @@
|
||||
|
||||
package tech.ailef.dbadmin.external;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
@ -50,6 +47,11 @@ public class DbAdminProperties {
|
||||
*/
|
||||
private boolean testMode = false;
|
||||
|
||||
/**
|
||||
* Whether the SQL console feature is enabled
|
||||
*/
|
||||
private boolean sqlConsoleEnabled = true;
|
||||
|
||||
/**
|
||||
* Whether Spring Boot Database Admin is enabled
|
||||
* @return
|
||||
@ -62,6 +64,14 @@ public class DbAdminProperties {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isSqlConsoleEnabled() {
|
||||
return sqlConsoleEnabled;
|
||||
}
|
||||
|
||||
public void setSqlConsoleEnabled(boolean sqlConsoleEnabled) {
|
||||
this.sqlConsoleEnabled = sqlConsoleEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prefix that is prepended to all routes registered by Spring Boot Database Admin.
|
||||
* @return
|
||||
@ -94,14 +104,15 @@ public class DbAdminProperties {
|
||||
this.testMode = testMode;
|
||||
}
|
||||
|
||||
public Map<String, String> toMap() {
|
||||
Map<String, String> conf = new HashMap<>();
|
||||
conf.put("enabled", enabled + "");
|
||||
conf.put("baseUrl", baseUrl);
|
||||
conf.put("modelsPackage", modelsPackage);
|
||||
conf.put("testMode", testMode + "");
|
||||
return conf;
|
||||
}
|
||||
// public Map<String, String> toMap() {
|
||||
// Map<String, String> conf = new HashMap<>();
|
||||
// conf.put("enabled", enabled + "");
|
||||
// conf.put("baseUrl", baseUrl);
|
||||
// conf.put("modelsPackage", modelsPackage);
|
||||
// conf.put("testMode", testMode + "");
|
||||
// conf.put("sqlConsoleEnabled", sqlConsoleEnabled + "");
|
||||
// return conf;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
@ -551,6 +551,10 @@ public class DefaultDbAdminController {
|
||||
|
||||
@GetMapping("/console/new")
|
||||
public String consoleNew(Model model) {
|
||||
if (!properties.isSqlConsoleEnabled()) {
|
||||
throw new DbAdminException("SQL console not enabled");
|
||||
}
|
||||
|
||||
model.addAttribute("activePage", "console");
|
||||
|
||||
ConsoleQuery q = new ConsoleQuery();
|
||||
@ -560,6 +564,10 @@ public class DefaultDbAdminController {
|
||||
|
||||
@GetMapping("/console")
|
||||
public String console(Model model) {
|
||||
if (!properties.isSqlConsoleEnabled()) {
|
||||
throw new DbAdminException("SQL console not enabled");
|
||||
}
|
||||
|
||||
List<ConsoleQuery> tabs = consoleQueryRepository.findAll();
|
||||
|
||||
if (tabs.isEmpty()) {
|
||||
@ -574,6 +582,10 @@ public class DefaultDbAdminController {
|
||||
|
||||
@PostMapping("/console/delete/{queryId}")
|
||||
public String consoleDelete(@PathVariable String queryId, Model model) {
|
||||
if (!properties.isSqlConsoleEnabled()) {
|
||||
throw new DbAdminException("SQL console not enabled");
|
||||
}
|
||||
|
||||
consoleQueryRepository.deleteById(queryId);
|
||||
return "redirect:/" + properties.getBaseUrl() + "/console";
|
||||
}
|
||||
@ -584,6 +596,10 @@ public class DefaultDbAdminController {
|
||||
public String consoleRun(Model model, @RequestParam(required = false) String query,
|
||||
@RequestParam(required = false) String queryTitle,
|
||||
@PathVariable String queryId) {
|
||||
if (!properties.isSqlConsoleEnabled()) {
|
||||
throw new DbAdminException("SQL console not enabled");
|
||||
}
|
||||
|
||||
ConsoleQuery activeQuery = consoleQueryRepository.findById(queryId).orElseThrow(() -> {
|
||||
return new DbAdminNotFoundException("Query with ID " + queryId + " not found.");
|
||||
});
|
||||
|
@ -59,6 +59,7 @@ public class GlobalController {
|
||||
model.addAttribute("dbadmin_userConf", userConf);
|
||||
model.addAttribute("dbadmin_baseUrl", getBaseUrl());
|
||||
model.addAttribute("dbadmin_version", dbAdmin.getVersion());
|
||||
model.addAttribute("dbadmin_properties", props);
|
||||
return "other/error";
|
||||
}
|
||||
|
||||
@ -70,6 +71,7 @@ public class GlobalController {
|
||||
model.addAttribute("dbadmin_userConf", userConf);
|
||||
model.addAttribute("dbadmin_baseUrl", getBaseUrl());
|
||||
model.addAttribute("dbadmin_version", dbAdmin.getVersion());
|
||||
model.addAttribute("dbadmin_properties", props);
|
||||
response.setStatus(404);
|
||||
return "other/error";
|
||||
}
|
||||
@ -118,5 +120,11 @@ public class GlobalController {
|
||||
public UserConfiguration getUserConf() {
|
||||
return userConf;
|
||||
}
|
||||
|
||||
@ModelAttribute("dbadmin_properties")
|
||||
public DbAdminProperties getProps() {
|
||||
return props;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -41,20 +41,52 @@ public class DbQueryOutputField {
|
||||
return dbField != null && dbField.isPrimaryKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this field is a foreign key, only in the case
|
||||
* the field has been mapped to a table
|
||||
*/
|
||||
public boolean isForeignKey() {
|
||||
return dbField != null && dbField.isForeignKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this field is a binary field (BLOB, etc.), only in the case
|
||||
* the field has been mapped to a table
|
||||
* @return
|
||||
*/
|
||||
public boolean isBinary() {
|
||||
return dbField != null && dbField.isBinary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this field is mapped to a table
|
||||
* @return
|
||||
*/
|
||||
public boolean isMapped() {
|
||||
return dbField != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the field, only in the case the field
|
||||
* has been mapped to a table
|
||||
* @return
|
||||
*/
|
||||
public String getType() {
|
||||
if (dbField != null)
|
||||
return dbField.getType().toString();
|
||||
return "-";
|
||||
}
|
||||
|
||||
public String getJavaName() {
|
||||
if (dbField == null) return null;
|
||||
return dbField.getJavaName();
|
||||
}
|
||||
|
||||
public String getEntityClassName() {
|
||||
if (dbField == null) return null;
|
||||
return dbField.getSchema().getClassName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, table);
|
||||
|
@ -12,7 +12,14 @@
|
||||
|
||||
<!-- data-row-field fragment -->
|
||||
<th:block th:fragment="data_row_field(field, object)">
|
||||
<span th:text="${object.get(field)}"></span>
|
||||
<th:block th:if="${field.isBinary()}">
|
||||
<th:block th:if="${object.get(field)}">
|
||||
<span class="font-monospace null-label">BINARY</span>
|
||||
</th:block>
|
||||
</th:block>
|
||||
<th:block th:if="${!field.isBinary()}">
|
||||
<span th:text="${object.get(field)}"></span>
|
||||
</th:block>
|
||||
</th:block>
|
||||
<!-- end data-row-field fragment -->
|
||||
</body>
|
||||
|
@ -83,7 +83,8 @@
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li th:class="${#strings.equals(activePage, 'console') ? 'active' : ''}">
|
||||
<li th:if="${dbadmin_properties.isSqlConsoleEnabled()}"
|
||||
th:class="${#strings.equals(activePage, 'console') ? 'active' : ''}">
|
||||
<a th:href="|/${dbadmin_baseUrl}/console|">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="menu-icon">
|
||||
|
Loading…
x
Reference in New Issue
Block a user