mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-09 05:48:20 +00:00
WIP
This commit is contained in:
parent
2d2f24f1e3
commit
0f94d5287f
@ -40,10 +40,11 @@ public class DbAdminAutoConfiguration {
|
||||
public DataSource internalDataSource() {
|
||||
DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
|
||||
dataSourceBuilder.driverClassName("org.h2.Driver");
|
||||
if (props.isTestMode())
|
||||
if (props.isTestMode()) {
|
||||
dataSourceBuilder.url("jdbc:h2:mem:test");
|
||||
else
|
||||
} else {
|
||||
dataSourceBuilder.url("jdbc:h2:file:./dbadmin_internal");
|
||||
}
|
||||
|
||||
dataSourceBuilder.username("sa");
|
||||
dataSourceBuilder.password("password");
|
||||
|
@ -19,6 +19,7 @@ import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -39,6 +40,8 @@ import tech.ailef.dbadmin.external.dto.QueryFilter;
|
||||
import tech.ailef.dbadmin.external.exceptions.InvalidPageException;
|
||||
import tech.ailef.dbadmin.external.misc.Utils;
|
||||
import tech.ailef.dbadmin.internal.model.UserAction;
|
||||
import tech.ailef.dbadmin.internal.model.UserSetting;
|
||||
import tech.ailef.dbadmin.internal.repository.UserSettingsRepository;
|
||||
import tech.ailef.dbadmin.internal.service.UserActionService;
|
||||
|
||||
/**
|
||||
@ -59,12 +62,9 @@ public class DefaultDbAdminController {
|
||||
@Autowired
|
||||
private UserActionService userActionService;
|
||||
|
||||
// @Autowired
|
||||
// private ActionRepository repo;
|
||||
//
|
||||
// @Autowired
|
||||
// private CustomActionRepositoryImpl customRepo;
|
||||
|
||||
@Autowired
|
||||
private UserSettingsRepository userSettingsRepo;
|
||||
|
||||
/**
|
||||
* Home page with list of schemas
|
||||
@ -456,7 +456,15 @@ public class DefaultDbAdminController {
|
||||
return "settings";
|
||||
}
|
||||
|
||||
// @Transactional("internalTransactionManager")
|
||||
@PostMapping("/settings")
|
||||
public String settings(@RequestParam Map<String, String> params, Model model) {
|
||||
for (String paramName : params.keySet()) {
|
||||
userSettingsRepo.save(new UserSetting(paramName, params.get(paramName)));
|
||||
}
|
||||
model.addAttribute("activePage", "settings");
|
||||
return "settings";
|
||||
}
|
||||
|
||||
private UserAction saveAction(UserAction action) {
|
||||
return userActionService.save(action);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import tech.ailef.dbadmin.external.DbAdminProperties;
|
||||
import tech.ailef.dbadmin.internal.UserConfiguration;
|
||||
|
||||
/**
|
||||
* This class registers some ModelAttribute objects that are
|
||||
@ -19,6 +20,9 @@ public class GlobalController {
|
||||
@Autowired
|
||||
private DbAdminProperties props;
|
||||
|
||||
@Autowired
|
||||
private UserConfiguration userConf;
|
||||
|
||||
/**
|
||||
* A multi valued map containing the query parameters. It is used primarily
|
||||
* in building complex URL when performing faceted search with multiple filters.
|
||||
@ -44,4 +48,10 @@ public class GlobalController {
|
||||
public String getRequestUrl(HttpServletRequest request) {
|
||||
return request.getRequestURI();
|
||||
}
|
||||
|
||||
@ModelAttribute("userConf")
|
||||
public UserConfiguration getUserConf() {
|
||||
return userConf;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
package tech.ailef.dbadmin.internal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import tech.ailef.dbadmin.internal.model.UserSetting;
|
||||
import tech.ailef.dbadmin.internal.repository.UserSettingsRepository;
|
||||
|
||||
@Component
|
||||
public class UserConfiguration {
|
||||
@Autowired
|
||||
private UserSettingsRepository repo;
|
||||
|
||||
public String get(String settingName) {
|
||||
Optional<UserSetting> setting = repo.findById(settingName);
|
||||
if (setting.isPresent())
|
||||
return setting.get().getSettingValue();
|
||||
return defaultValues().get(settingName);
|
||||
}
|
||||
|
||||
private Map<String, String> defaultValues() {
|
||||
Map<String, String> values = new HashMap<>();
|
||||
values.put("brandName", "Spring Boot Database Admin");
|
||||
return values;
|
||||
}
|
||||
}
|
@ -8,7 +8,15 @@ public class UserSetting {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String value;
|
||||
private String settingValue;
|
||||
|
||||
public UserSetting() {
|
||||
}
|
||||
|
||||
public UserSetting(String id, String settingValue) {
|
||||
this.id = id;
|
||||
this.settingValue = settingValue;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
@ -18,12 +26,12 @@ public class UserSetting {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
public String getSettingValue() {
|
||||
return settingValue;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
public void setSettingValue(String settingValue) {
|
||||
this.settingValue = settingValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ import org.springframework.stereotype.Repository;
|
||||
import tech.ailef.dbadmin.internal.model.UserSetting;
|
||||
|
||||
@Repository
|
||||
public interface UserSettingsRepository extends JpaRepository<UserSetting, Integer> {
|
||||
public interface UserSettingsRepository extends JpaRepository<UserSetting, String> {
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,9 @@
|
||||
|
||||
<nav class="navbar fixed-top navbar-expand-lg bg-accent color-white" th:fragment="navbar">
|
||||
<div class="container-fluid">
|
||||
<a class=" fw-bold navbar-brand" href="/"><i class="bi bi-hexagon-fill"></i> Spring Boot DB Admin Panel</a>
|
||||
<a class=" fw-bold navbar-brand" href="/"><i class="bi bi-hexagon-fill"></i>
|
||||
[[ ${userConf.get('brandName')} ]]
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
@ -77,7 +79,18 @@
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li th:class="${#strings.equals(activePage, 'settings') ? 'active' : ''}">
|
||||
<a th:href="|/${baseUrl}/settings|">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="menu-icon">
|
||||
<i class="bi bi-gear"></i>
|
||||
</div>
|
||||
<div class="menu-entry-text d-none d-md-block">
|
||||
Settings
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
<!--
|
||||
<li th:class="${#strings.equals(activePage, 'console') ? 'active' : ''}">
|
||||
<a href="/live">
|
||||
@ -103,18 +116,6 @@
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
<li th:class="${#strings.equals(activePage, 'settings') ? 'active' : ''}">
|
||||
<a th:href="|/${baseUrl}/settings|">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="menu-icon">
|
||||
<i class="bi bi-gear"></i>
|
||||
</div>
|
||||
<div class="menu-entry-text d-none d-md-block">
|
||||
Settings
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
-->
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<div class="w-100 d-flex inner-navigation">
|
||||
<a href="#" class="active">
|
||||
<div class="ui-tab ps-5 pe-5 p-3">
|
||||
<i class="bi bi-database pe-2"></i> APPEARANCE
|
||||
<i class="bi bi-database pe-2"></i> GENERAL
|
||||
</div>
|
||||
</a>
|
||||
<a href="#">
|
||||
@ -29,7 +29,15 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="box with-navigation">
|
||||
SETTINGS
|
||||
<h3 class="fw-bold">General</h3>
|
||||
<form th:action="|/${baseUrl}/settings|" method="POST">
|
||||
<label for="brandName">Brand name</label>
|
||||
<span class="m-0 p-0 text-muted">What appears in the top bar</span>
|
||||
<input class="form-control mt-2" type="text"
|
||||
id="brandName" name="brandName"
|
||||
th:value="${userConf.get('brandName')}">
|
||||
<button class="ui-btn btn btn-primary mt-3">Save</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user