Support for char and short field types; Improved UI on create/edit form, now showing the type for each input element

This commit is contained in:
Francesco 2023-10-08 10:41:29 +02:00
parent e1010a6c86
commit bf7a4c8956
3 changed files with 132 additions and 42 deletions

View File

@ -20,7 +20,6 @@
package tech.ailef.dbadmin.external.dbmapping;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

View File

@ -352,6 +352,48 @@ public enum DbFieldType {
return List.of(CompareOperator.GT, CompareOperator.EQ, CompareOperator.LT);
}
},
CHAR {
@Override
public String getFragmentName(FragmentContext c) {
return "char";
}
@Override
public Object parseValue(Object value) {
return value.toString().charAt(0);
}
@Override
public Class<?> getJavaClass() {
return char.class;
}
@Override
public List<CompareOperator> getCompareOperators() {
return List.of(CompareOperator.STRING_EQ);
}
},
BYTE {
@Override
public String getFragmentName(FragmentContext c) {
return "number";
}
@Override
public Object parseValue(Object value) {
return value.toString().getBytes()[0];
}
@Override
public Class<?> getJavaClass() {
return byte.class;
}
@Override
public List<CompareOperator> getCompareOperators() {
throw new DbAdminException("Binary fields are not comparable");
}
},
BYTE_ARRAY {
@Override
public String getFragmentName(FragmentContext c) {
@ -559,6 +601,10 @@ public enum DbFieldType {
return BYTE_ARRAY;
} else if (klass == OffsetDateTime.class) {
return OFFSET_DATE_TIME;
} else if (klass == byte.class || klass == Byte.class) {
return BYTE;
} else if (klass == char.class || klass == Character.class) {
return CHAR;
} else {
throw new DbAdminException("Unsupported field type: " + klass);
}

View File

@ -8,37 +8,75 @@
rows="5"
th:classAppend="|${field.isReadOnly() && !create ? 'disable' : ''}|"
></textarea>
<input placeholder="NULL" th:fragment="text(field, create, name, value)"
type="text"
th:value="${value}"
th:name="${name}"
class="form-control " th:id="|__id_${field.getName()}|"
th:classAppend="|${(field.isPrimaryKey() && object != null) ||
(field.isReadOnly() && !create) ? 'disable' : ''}|"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
></input>
<input placeholder="NULL" th:fragment="number(field, create, name, value)"
type="number"
th:value="${value}"
th:name="${name}"
class="form-control " th:id="|__id_${field.getName()}|"
th:classAppend="|${(field.isPrimaryKey() && object != null) ||
(field.isReadOnly() && !create) ? 'disable' : ''}|"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
step="any"
></input>
<input placeholder="NULL" th:fragment="datetime(field, create, name, value)"
type="datetime-local"
th:value="${value}"
th:name="${name}"
class="form-control " th:id="|__id_${field.getName()}|"
th:classAppend="|${create != null && ((field.isPrimaryKey() && object != null) ||
(field.isReadOnly() && !create)) ? 'disable' : ''}|"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
></input>
<th:block th:fragment="char(field, create, name, value)">
<div class="input-group">
<span class="input-group-text font-monospace">
[[ ${field.getType()} ]]
</span>
<input placeholder="NULL"
type="text"
th:value="${value}"
th:name="${name}"
class="form-control " th:id="|__id_${field.getName()}|"
th:classAppend="|${(field.isPrimaryKey() && object != null) ||
(field.isReadOnly() && !create) ? 'disable' : ''}|"
maxlength="1"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
></input>
</div>
</th:block>
<th:block th:fragment="text(field, create, name, value)">
<div class="input-group">
<span class="input-group-text font-monospace">
[[ ${field.getType()} ]]
</span>
<input placeholder="NULL"
type="text"
th:value="${value}"
th:name="${name}"
class="form-control " th:id="|__id_${field.getName()}|"
th:classAppend="|${(field.isPrimaryKey() && object != null) ||
(field.isReadOnly() && !create) ? 'disable' : ''}|"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
></input>
</div>
</th:block>
<th:block th:fragment="number(field, create, name, value)">
<div class="input-group">
<span class="input-group-text font-monospace">
[[ ${field.getType()} ]]
</span>
<input placeholder="NULL"
type="number"
th:value="${value}"
th:name="${name}"
class="form-control " th:id="|__id_${field.getName()}|"
th:classAppend="|${(field.isPrimaryKey() && object != null) ||
(field.isReadOnly() && !create) ? 'disable' : ''}|"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
step="any"
></input>
</div>
</th:block>
<th:block th:fragment="datetime(field, create, name, value)"
<span class="input-group-text font-monospace">
[[ ${field.getType()} ]]
</span>
<div class="input-group">
<input placeholder="NULL"
type="datetime-local"
th:value="${value}"
th:name="${name}"
class="form-control " th:id="|__id_${field.getName()}|"
th:classAppend="|${create != null && ((field.isPrimaryKey() && object != null) ||
(field.isReadOnly() && !create)) ? 'disable' : ''}|"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
></input>
</div>
</th:block>
<!--
<th:block th:fragment="offset_datetime(field, create, name, value)">
<div class="form-group">
@ -65,16 +103,23 @@
</div>
</th:block>
-->
<input placeholder="NULL" th:fragment="date(field, create, name, value)"
type="date"
th:value="${value}"
th:name="${name}"
class="form-control " th:id="|__id_${field.getName()}|"
th:classAppend="|${create != null && ((field.isPrimaryKey() && object != null) ||
(field.isReadOnly() && !create)) ? 'disable' : ''}|"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
></input>
<th:block th:fragment="date(field, create, name, value)">
<div class="input-group">
<span class="input-group-text font-monospace">
[[ ${field.getType()} ]]
</span>
<input placeholder="NULL"
type="date"
th:value="${value}"
th:name="${name}"
class="form-control " th:id="|__id_${field.getName()}|"
th:classAppend="|${create != null && ((field.isPrimaryKey() && object != null) ||
(field.isReadOnly() && !create)) ? 'disable' : ''}|"
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
></input>
</div>
</th:block>
<th:block th:if="${field.isBinary()}" th:fragment="file(field, create, name, value)" >
<!--/*--> Edit options <!--*/-->
<div th:if="${!create && object.get(field).getValue() != null}">