From 24e271664a2e7e0792a8e313369641b350e5c3a1 Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 21 Sep 2023 15:55:03 +0200 Subject: [PATCH] WIP --- README.md | 18 +++++++++++------- src/main/java/tech/ailef/dbadmin/DbAdmin.java | 1 + .../tech/ailef/dbadmin/DbAdminProperties.java | 15 ++++++++++++++- .../dbadmin/controller/GlobalController.java | 5 +++++ .../dbadmin/dbmapping/DbAdminRepository.java | 5 ++--- .../tech/ailef/dbadmin/dto/PaginationInfo.java | 18 +++++++++--------- .../templates/fragments/resources.html | 12 ++++++------ .../templates/fragments/table_selectable.html | 6 +++--- 8 files changed, 51 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 2986be0..397fb18 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,14 @@ a sample database and already configured code. If you wish to integrate it into your project instead, the first step is adding these to your `application.properties` file: ``` -dbadmin.enabled=true # Optional, default true -dbadmin.baseUrl=admin # The first-level part of the URL path: http://localhost:8080/${baseUrl}/ -dbadmin.modelsPackage=tech.ailef.dbadmin.test.models # The package that contains your @Entity classes +# Optional, default true +dbadmin.enabled=true + +# The first-level part of the URL path: http://localhost:8080/${baseUrl}/ +dbadmin.baseUrl=admin + +# The package that contains your @Entity classes +dbadmin.modelsPackage=tech.ailef.dbadmin.test.models ``` The last step is to annotate your `@SpringBootApplication` class containing the `main` method with the following: @@ -39,14 +44,13 @@ The last step is to annotate your `@SpringBootApplication` class containing the @ImportAutoConfiguration(DbAdminAutoConfiguration.class) ``` -This tells Spring to scan the `tech.ailef.dbadmin` packages and look for components there as well. Remember to also include -your original root package as shown, or Spring will not scan it otherwise. +This will autoconfigure the various DbAdmin components when your application starts. -3. At this point, when you run your application, you should be able to visit `http://localhost:$PORT/dbadmin` and access the web interface. +3. At this point, when you run your application, you should be able to visit `http://localhost:$PORT/${baseUrl}` and access the web interface. ## Documentation -Once you are correctly running Spring Boot Database Admin you will see the web interface at `http://localhost:$PORT/dbadmin`. Most of the features are already available with the basic configuration. However, some customization to the interface might be applied by using appropriate annotations on your classes fields or methods. +Once you are correctly running Spring Boot Database Admin, you will be able to access the web interface. Most of the features are already available with the basic configuration. However, some customization to the interface might be applied by using appropriate annotations on your classes fields or methods. The following annotations are supported. ### @DisplayName diff --git a/src/main/java/tech/ailef/dbadmin/DbAdmin.java b/src/main/java/tech/ailef/dbadmin/DbAdmin.java index 9a37124..35dc295 100644 --- a/src/main/java/tech/ailef/dbadmin/DbAdmin.java +++ b/src/main/java/tech/ailef/dbadmin/DbAdmin.java @@ -66,6 +66,7 @@ public class DbAdmin { for (BeanDefinition bd : beanDefs) { schemas.add(processBeanDefinition(bd)); } + logger.info("Spring Boot Database Admin initialized. Loaded " + schemas.size() + " table definitions"); logger.info("Spring Boot Database Admin web interface at: http://YOUR_HOST:YOUR_PORT/" + properties.getBaseUrl()); } diff --git a/src/main/java/tech/ailef/dbadmin/DbAdminProperties.java b/src/main/java/tech/ailef/dbadmin/DbAdminProperties.java index 462425d..5d1bf88 100644 --- a/src/main/java/tech/ailef/dbadmin/DbAdminProperties.java +++ b/src/main/java/tech/ailef/dbadmin/DbAdminProperties.java @@ -2,12 +2,25 @@ package tech.ailef.dbadmin; import org.springframework.boot.context.properties.ConfigurationProperties; +/** + * The 'dbadmin.*' properties that can be set in the properties file + * to configure the behaviour of Spring Boot Admin Panel. + */ @ConfigurationProperties("dbadmin") public class DbAdminProperties { + /** + * Whether Spring Boot Database Admin is enabled. + */ public boolean enabled = true; + /** + * The prefix that is prepended to all routes registered by Spring Boot Database Admin. + */ private String baseUrl; - + + /** + * The path of the package that contains your JPA `@Entity` classes to be scanned. + */ private String modelsPackage; public boolean isEnabled() { diff --git a/src/main/java/tech/ailef/dbadmin/controller/GlobalController.java b/src/main/java/tech/ailef/dbadmin/controller/GlobalController.java index 7c197b8..d90239a 100644 --- a/src/main/java/tech/ailef/dbadmin/controller/GlobalController.java +++ b/src/main/java/tech/ailef/dbadmin/controller/GlobalController.java @@ -30,6 +30,11 @@ public class GlobalController { return request.getParameterMap(); } + /** + * The baseUrl as specified in the properties file by the user + * @param request + * @return + */ @ModelAttribute("baseUrl") public String getBaseUrl(HttpServletRequest request) { return props.getBaseUrl(); diff --git a/src/main/java/tech/ailef/dbadmin/dbmapping/DbAdminRepository.java b/src/main/java/tech/ailef/dbadmin/dbmapping/DbAdminRepository.java index a227ef2..d94bc46 100644 --- a/src/main/java/tech/ailef/dbadmin/dbmapping/DbAdminRepository.java +++ b/src/main/java/tech/ailef/dbadmin/dbmapping/DbAdminRepository.java @@ -36,7 +36,6 @@ public class DbAdminRepository { public DbAdminRepository(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; - } /** @@ -119,7 +118,7 @@ public class DbAdminRepository { return new PaginatedResult( - new PaginationInfo(page, maxPage, pageSize, maxElement, null, sortKey, sortOrder, new HashSet<>()), + new PaginationInfo(page, maxPage, pageSize, maxElement, null, new HashSet<>()), results ); } @@ -229,7 +228,7 @@ public class DbAdminRepository { } return new PaginatedResult( - new PaginationInfo(page, maxPage, pageSize, maxElement, query, sortKey, sortOrder, queryFilters), + new PaginationInfo(page, maxPage, pageSize, maxElement, query, queryFilters), jpaRepository.search(query, page, pageSize, sortKey, sortOrder, queryFilters).stream() .map(o -> new DbObject(o, schema)) .toList() diff --git a/src/main/java/tech/ailef/dbadmin/dto/PaginationInfo.java b/src/main/java/tech/ailef/dbadmin/dto/PaginationInfo.java index dd69835..11cc31a 100644 --- a/src/main/java/tech/ailef/dbadmin/dto/PaginationInfo.java +++ b/src/main/java/tech/ailef/dbadmin/dto/PaginationInfo.java @@ -41,20 +41,13 @@ public class PaginationInfo { private String query; - private String sortKey; - - private String sortOrder; - - public PaginationInfo(int currentPage, int maxPage, int pageSize, long maxElement, String query, - String sortKey, String sortOrder, Set queryFilters) { + public PaginationInfo(int currentPage, int maxPage, int pageSize, long maxElement, String query, Set queryFilters) { this.currentPage = currentPage; this.maxPage = maxPage; this.pageSize = pageSize; this.query = query; this.maxElement = maxElement; this.queryFilters = queryFilters; - this.sortKey = sortKey; - this.sortOrder = sortOrder; } public int getCurrentPage() { @@ -122,7 +115,14 @@ public class PaginationInfo { public List getAfterPages() { return IntStream.range(currentPage + 1, Math.min(currentPage + PAGE_RANGE, maxPage + 1)).boxed().collect(Collectors.toList()); } - +// +// public String getSortKey() { +// return sortKey; +// } +// +// public String getSortOrder() { +// return sortOrder; +// } public boolean isLastPage() { return currentPage == maxPage; diff --git a/src/main/resources/templates/fragments/resources.html b/src/main/resources/templates/fragments/resources.html index 023ed50..c51cbcb 100644 --- a/src/main/resources/templates/fragments/resources.html +++ b/src/main/resources/templates/fragments/resources.html @@ -127,7 +127,7 @@