This commit is contained in:
Francesco 2023-09-25 10:10:18 +02:00
parent 0f94d5287f
commit bac5ba0861
5 changed files with 272 additions and 3 deletions

View File

@ -10,6 +10,7 @@ Features:
* List objects with pagination and sorting
* Show detailed object page which also includes `@OneToMany`, `@ManyToMany`, etc... fields
* Create/Edit objects
* Action logs (i.e. see a history of all write operations done through the web UI)
* Search
* Customization

205
docs/docs.html Normal file
View File

@ -0,0 +1,205 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.2/font/bootstrap-icons.css" integrity="sha384-b6lVK+yci+bfDmaY1u0zE8YYJt0TZxLEAFyYSLHId4xoVvsrQu3INevFKo+Xir8e" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.3/js/bootstrap.min.js" integrity="sha512-1/RvZTcCDEUjY/CypiMz+iqqtaoQfAITmNSJY17Myp4Ms5mdxPS5UV7iOfdZoxcGhzFbOm6sntTKJppjvuhg4g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<title>Documentation | Spring Boot DB Admin Panel</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/languages/java.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/languages/xml.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/languages/properties.min.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('h2, h3, h4, h5, h6').forEach(heading => {
let tag = heading.tagName.replace('H', '');
document.getElementById('toc').innerHTML +=
`<li class="ms-${tag}"><a href="#${heading.id}">${heading.innerHTML}</li>`;
});
});
</script>
</head>
<body>
<div class="bg-light">
<div class="container">
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand fw-bold" href="#">Spring Boot Database Admin Docs</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>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="https://github.com/aileftech/spring-boot-database-admin" target="_blank">Github</a>
</li>
</ul>
<!--
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
-->
</div>
</div>
</nav>
</div>
</div>
<!-- End nav -->
<div class="container">
<div class="row">
<div class="col-3 pt-3">
<ol id="toc" class="toc" style="position: fixed">
</ol>
</div>
<div class="col-9 main-content pt-3 ps-4">
<h1>Spring Boot Database Admin documentation</h1>
<h2 id="introduction">1. Introduction</h2>
<p>The following documentation outlines how to install, configure and customize Spring Boot Database Admin panel. Refer to this document for troubleshooting and if you still encounter problems, please report it as an issue on Github.</p>
<div class="separator"></div>
<h2 id="getting-started">2. Getting started</h2>
<p>Getting started with Spring Boot Database Admin requires including it as a dependency and then performing a simple configuration step.</p>
<h3 id="installation">2.1 Installation</h3>
<p>At the moment the code is not yet distributed on Maven, so it is necessary to build and install manually. Clone the Github repo and <code>mvn install</code> the project into your local repository. Then, include the dependency in your <code>pom.xml</code>:</p>
<pre>
<code class="language-xml">&lt;dependency&gt;
&lt;groupId&gt;tech.ailef&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-db-admin&lt;/artifactId&gt;
&lt;version&gt;0.0.4&lt;/version&gt;
&lt;/dependency&gt;
</code>
</pre>
<p class="tip"><span class="title"><i class="bi bi-info-circle"></i> TIP</span> The version in this snippet might be different from the one you pulled from Github. Make sure to edit it to match the version contained in the project's <code>pom.xml</code> file.</p>
<h3 id="configuration">2.2 Configuration</h3>
<p>After including the dependency, a few configuration steps are required on your end in order to integrate the library into your project. </p>
<p>The first one is configuring your <code>application.properties</code> file:</p>
<pre>
<code class="language-properties"># The first-level part of the URL path: http://localhost:8080/${baseUrl}/
dbadmin.baseUrl=admin
# The package that contains your @Entity classes
dbadmin.modelsPackage=your.models.package
# OPTIONAL PARAMETERS
# Whether to enable to web interface
# dbadmin.enabled=true
#
# Set to true if you need to run the tests, as it will customize
# the database configuration for the internal DataSource
# dbadmin.testMode=false
</code>
</pre>
<p>After this, you must tell Spring to import the Spring Boot Database Admin configuration. To do this, annotate your <code>@SpringBootApplication</code> class containing the <code>main</code> method with the following:</p>
<pre>
<code class="language-java">@ImportAutoConfiguration(DbAdminAutoConfiguration.class)
</code>
</pre>
<p>This will autoconfigure the various Spring Boot Database Admin components when your application starts.</p>
<p>If everything is setup correctly, you will see Spring Boot Database Admin confirming it in the log messages that appear when you start your application. Keep in mind that if you specify the wrong models package, it will still work but provide you an empty interface. To check, visit <a target="_blank" href="http://localhost:8080/admin">http://localhost:8080/admin</a>.</p>
<div class="separator"></div>
<h2 id="customization">3. Customization</h2>
<p>There are two ways to customize the appearance and behaviour of Spring Boot Database Admin:</p>
<ol>
<li>Applying annotations on your <code>@Entity</code> classes, fields and methods</li>
<li>Using the Settings panel through the web interface</li>
</ol>
<p>Annotations are used primarily to customize behaviour and add custom logic to your classes. If, instead, you're looking to customize appearance of the web UI, it's most likley through the Settings panel.</p>
<h3 id="supported-annotations">3.1 Supported annotations</h3>
<h4 id="display-name">3.1.1 @DisplayName</h4>
<pre>
<code class="language-java">@DisplayName
public String getFullName() {
return firstName + " " + lastName;
}
</code>
</pre>
<p>When displaying a reference to an item, by default we show its primary key. If a class has a <code>@DisplayName</code>, this method will be used in addition to the primary key whenever possible, giving the user a more readable option. <p>
<h4 id="display-format">3.1.2 @DisplayFormat</h4>
<pre>
<code class="language-java">@DisplayFormat(format = "$%.2f")
private Double price;
</code>
</pre>
<p>Specify a format string to apply when displaying the field.</p>
<h4 id="computed-column">3.1.3 @ComputedColumn</h4>
<pre>
<code class="language-java">@ComputedColumn
public double totalSpent() {
double total = 0;
for (Order o : orders) {
total += o.total();
}
return total;
}
</code>
</pre>
<p>This annotation can be used to add values computed at runtime that are shown like additional columns.</p>
<h4 id="filterable">3.1.4 @Filterable</h4>
<pre>
<code class="language-java">@Filterable
private LocalDate createdAt;
</code>
</pre>
<p>Place on one or more fields in a class to activate the faceted search feature. This will allow you to easily combine all these filters when operating on the table. Can only be placed on fields that correspond to physical columns on the table (e.g. no `@ManyToMany`/`@OneToMany`) and that are not binary (`byte[]`).</p>
<h4 id="display-image">3.1.5 @DisplayImage</h4>
<pre>
<code class="language-java">@DisplayImage
private byte[] image;
</code>
</pre>
<p>This annotation can be placed on binary fields to declare they are storing an image and that we want it displayed when possible. The image will be shown as a small thumbnail.</p>
<div class="separator"></div>
<h2>4. Security</h2>
<p>Spring Boot Database Admin does not implement authentication and/or authorization mechanisms. However, you can use a standard Spring security configuration in order to limit access to the web UI or specific parts of it.</p>
<p>All Spring Boot Database Admin routes start with the value of <code>dbadmin.baseUrl</code> property, and all write operations (edit, create, delete) are implemented as <code>POST</code> calls.</p>
</div>
</div>
</div>
<script>hljs.highlightAll();</script>
</body>
</html>

63
docs/style.css Normal file
View File

@ -0,0 +1,63 @@
.main-content {
border-left: 1px solid #EEE;
}
body {
color: #333;
background-color: #FAFAFA;
}
p {
color: #111;
}
code pre {
background-color: #DFDFDF;
padding: 5px;
border-radius: 5px;
font-size: 0.9rem;
}
h1, h2, h3, h4, h5, h6 {
font-weight: bold;
margin-top: 1.5rem;
margin-bottom: 1.5rem;
}
ol.toc {
list-style: none;
}
.separator {
border-top: 1px solid #DDD;
width: 100%;
margin: 0 auto;
margin-top: 2rem;
margin-bottom: 2rem;
}
p.tip {
border-radius: 5px;
background-color: #D0DCF0;
padding: 1rem;
padding-top: 1.5rem;
margin-top: 2rem;
position: relative;
}
p.tip span.title {
font-weight: bold;
padding: 5px;
padding-left: 10px;
padding-right: 10px;
top: 0;
transform: translateY(-50%);
position: absolute;
top: 0;
left: 20;
background-color: lightsalmon;
color: white;
}

View File

@ -11,7 +11,7 @@
</parent>
<groupId>tech.ailef</groupId>
<artifactId>spring-boot-db-admin</artifactId>
<version>0.0.4</version>
<version>0.1.0</version>
<name>spring-boot-db-admin</name>
<description>Srping Boot DB Admin Dashboard</description>
<properties>

View File

@ -20,11 +20,11 @@
<i class="bi bi-database pe-2"></i> GENERAL
</div>
</a>
<a href="#">
<!-- <a href="#">
<div class="ui-tab ps-5 pe-5 p-3">
<i class="bi bi-table pe-2"></i> DATA
</div>
</a>
</a> -->
<div class="inner-navigation-border flex-grow-1">
</div>
</div>