mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-09 05:48:20 +00:00
Fixed implementation of search with enum fields
This commit is contained in:
parent
baf6822faf
commit
b6cfe37c84
@ -40,6 +40,7 @@ import jakarta.annotation.PostConstruct;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
@ -328,7 +329,9 @@ public class DbAdmin {
|
||||
if (fieldType == null) {
|
||||
Enumerated enumerated = f.getAnnotation(Enumerated.class);
|
||||
if (enumerated != null) {
|
||||
fieldType = new EnumFieldType(f.getType());
|
||||
EnumType type = enumerated.value();
|
||||
|
||||
fieldType = new EnumFieldType(f.getType(), type);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,19 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.persistence.EnumType;
|
||||
import tech.ailef.dbadmin.external.dto.CompareOperator;
|
||||
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
|
||||
|
||||
public class EnumFieldType extends DbFieldType {
|
||||
|
||||
private EnumType type;
|
||||
|
||||
private Class<?> klass;
|
||||
|
||||
public EnumFieldType(Class<?> klass) {
|
||||
public EnumFieldType(Class<?> klass, EnumType type) {
|
||||
this.klass = klass;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,6 +59,7 @@ public class EnumFieldType extends DbFieldType {
|
||||
@Override
|
||||
public Object parseValue(Object value) {
|
||||
if (value == null || value.toString().isBlank()) return null;
|
||||
|
||||
try {
|
||||
Method valueOf = getJavaClass().getMethod("valueOf", String.class);
|
||||
return valueOf.invoke(null, value.toString());
|
||||
@ -75,6 +80,10 @@ public class EnumFieldType extends DbFieldType {
|
||||
|
||||
@Override
|
||||
public List<CompareOperator> getCompareOperators() {
|
||||
return List.of(CompareOperator.STRING_EQ);
|
||||
return List.of(CompareOperator.EQ);
|
||||
}
|
||||
|
||||
public EnumType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
@ -61,6 +61,20 @@
|
||||
></input>
|
||||
|
||||
|
||||
<th:block th:fragment="select(field, create, name, value)">
|
||||
<select th:name="${name}" class="form-select">
|
||||
<option value=""
|
||||
th:selected="${value == null}">NULL</option>
|
||||
<option th:each="v : ${field.getType().getValues()}"
|
||||
th:text="${v}"
|
||||
th:value="${v}"
|
||||
th:selected="${value == v}">
|
||||
|
||||
</option>
|
||||
</select>
|
||||
</th:block>
|
||||
|
||||
|
||||
<input placeholder="NULL" th:fragment="date(field, create, name, value)"
|
||||
type="date"
|
||||
th:value="${value}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user