This commit is contained in:
Francesco 2023-09-21 14:22:01 +02:00
parent 710843bf0b
commit c776a2ca57
4 changed files with 58 additions and 1 deletions

View File

@ -0,0 +1,14 @@
package tech.ailef.dbadmin;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
//@ConditionalOnProperty(name = "crudadmin.enabled", matchIfMissing = true)
@ComponentScan
@EnableConfigurationProperties(DbAdminProperties.class)
@Configuration
public class DbAdminAutoConfiguration {
}

View File

@ -0,0 +1,28 @@
package tech.ailef.dbadmin;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("dbadmin")
public class DbAdminProperties {
public boolean enabled = true;
private String baseUrl;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getBaseUrl() {
return baseUrl;
}
public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
}

View File

@ -20,6 +20,7 @@ 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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;
@ -28,6 +29,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import tech.ailef.dbadmin.DbAdmin;
import tech.ailef.dbadmin.DbAdminProperties;
import tech.ailef.dbadmin.dbmapping.DbAdminRepository;
import tech.ailef.dbadmin.dbmapping.DbObject;
import tech.ailef.dbadmin.dbmapping.DbObjectSchema;
@ -41,8 +43,11 @@ import tech.ailef.dbadmin.misc.Utils;
* The main DbAdmin controller that register most of the routes of the web interface.
*/
@Controller
@RequestMapping("/dbadmin")
@RequestMapping(value= {"/${dbadmin.baseUrl}", "/${dbadmin.baseUrl}/"}, method=RequestMethod.GET)
public class DefaultDbAdminController {
@Autowired
private DbAdminProperties properties;
@Autowired
private DbAdminRepository repository;

View File

@ -2,10 +2,12 @@ package tech.ailef.dbadmin.controller;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;
import jakarta.servlet.http.HttpServletRequest;
import tech.ailef.dbadmin.DbAdminProperties;
/**
* This class registers some ModelAttribute objects that are
@ -14,6 +16,9 @@ import jakarta.servlet.http.HttpServletRequest;
@ControllerAdvice
public class GlobalController {
@Autowired
private DbAdminProperties props;
/**
* A multi valued map containing the query parameters. It is used primarily
* in building complex URL when performing faceted search with multiple filters.
@ -24,4 +29,9 @@ public class GlobalController {
public Map<String, String[]> getQueryParams(HttpServletRequest request) {
return request.getParameterMap();
}
@ModelAttribute("baseUrl")
public String getBaseUrl(HttpServletRequest request) {
return props.getBaseUrl();
}
}