Added global version variable

This commit is contained in:
Francesco 2023-10-11 11:34:51 +02:00
parent 821bbd98ef
commit 90aae69daf
4 changed files with 26 additions and 2 deletions

View File

@ -79,7 +79,9 @@ public class DbAdmin {
private DbAdminProperties properties; private DbAdminProperties properties;
/** private final String version = "0.1.6";
/**
* Builds the DbAdmin instance by scanning the `@Entity` beans and loading * Builds the DbAdmin instance by scanning the `@Entity` beans and loading
* the schemas. * the schemas.
* @param entityManager the entity manager * @param entityManager the entity manager
@ -112,11 +114,21 @@ public class DbAdmin {
} }
boolean hasErrors = schemas.stream().flatMap(s -> s.getErrors().stream()).count() > 0; boolean hasErrors = schemas.stream().flatMap(s -> s.getErrors().stream()).count() > 0;
logger.info("Spring Boot Database Admin initialized. Loaded " + schemas.size() logger.info("Spring Boot Database Admin initialized. Loaded " + schemas.size()
+ " schemas from " + modelsPackage.size() + " packages" + (hasErrors ? " (with errors)" : "")); + " schemas from " + modelsPackage.size() + " packages" + (hasErrors ? " (with errors)" : ""));
logger.info("Spring Boot Database Admin web interface at: http://YOUR_HOST:YOUR_PORT/" + properties.getBaseUrl()); logger.info("Spring Boot Database Admin web interface at: http://YOUR_HOST:YOUR_PORT/" + properties.getBaseUrl());
} }
/**
* Returns the current version
* @return
*/
public String getVersion() {
return version;
}
/** /**
* Returns all the loaded schemas (i.e. entity classes) * Returns all the loaded schemas (i.e. entity classes)
* @return the list of loaded schemas from the `@Entity` classes * @return the list of loaded schemas from the `@Entity` classes
@ -352,4 +364,6 @@ public class DbAdmin {
throw new DbAdminException(e); throw new DbAdminException(e);
} }
} }
} }

View File

@ -258,7 +258,6 @@ public class DefaultDbAdminController {
); );
}); });
model.addAttribute("title", "Entities | " + schema.getJavaClass().getSimpleName() + " | " + object.getDisplayName()); model.addAttribute("title", "Entities | " + schema.getJavaClass().getSimpleName() + " | " + object.getDisplayName());
model.addAttribute("object", object); model.addAttribute("object", object);
model.addAttribute("activePage", "entities"); model.addAttribute("activePage", "entities");

View File

@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import tech.ailef.dbadmin.external.DbAdmin;
import tech.ailef.dbadmin.external.DbAdminProperties; import tech.ailef.dbadmin.external.DbAdminProperties;
import tech.ailef.dbadmin.external.exceptions.DbAdminNotFoundException; import tech.ailef.dbadmin.external.exceptions.DbAdminNotFoundException;
import tech.ailef.dbadmin.internal.UserConfiguration; import tech.ailef.dbadmin.internal.UserConfiguration;
@ -45,6 +46,9 @@ public class GlobalController {
@Autowired @Autowired
private UserConfiguration userConf; private UserConfiguration userConf;
@Autowired
private DbAdmin dbAdmin;
@ExceptionHandler(DbAdminNotFoundException.class) @ExceptionHandler(DbAdminNotFoundException.class)
public String handleNotFound(Exception e, Model model) { public String handleNotFound(Exception e, Model model) {
model.addAttribute("status", "404"); model.addAttribute("status", "404");
@ -52,9 +56,15 @@ public class GlobalController {
model.addAttribute("message", e.getMessage()); model.addAttribute("message", e.getMessage());
model.addAttribute("dbadmin_userConf", userConf); model.addAttribute("dbadmin_userConf", userConf);
model.addAttribute("dbadmin_baseUrl", getBaseUrl()); model.addAttribute("dbadmin_baseUrl", getBaseUrl());
model.addAttribute("dbadmin_version", dbAdmin.getVersion());
return "other/error"; return "other/error";
} }
@ModelAttribute("dbadmin_version")
public String getVersion() {
return dbAdmin.getVersion();
}
/** /**
* A multi valued map containing the query parameters. It is used primarily * A multi valued map containing the query parameters. It is used primarily
* in building complex URL when performing faceted search with multiple filters. * in building complex URL when performing faceted search with multiple filters.

View File

@ -122,6 +122,7 @@
<div class="menu-entry-text d-none d-md-block"> <div class="menu-entry-text d-none d-md-block">
Help Help
</div> </div>
<div th:text="|v${dbadmin_version}|" class="text-muted ms-5"></div>
</div> </div>
</a> </a>
</li> </li>