mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-08 21:38:21 +00:00
WIP
This commit is contained in:
parent
89c8d93ca4
commit
06bd4bf5b1
@ -162,6 +162,11 @@ public class AdvancedJpaRepository extends SimpleJpaRepository {
|
||||
for (DbField field : schema.getSortedFields()) {
|
||||
if (field.isPrimaryKey()) continue;
|
||||
|
||||
if (params.getOrDefault("__keep_" + field.getJavaName(), "off").equals("on")) {
|
||||
System.out.println("SKIPPING: " + field);
|
||||
continue;
|
||||
}
|
||||
|
||||
String stringValue = params.get(field.getName());
|
||||
Object value = null;
|
||||
if (stringValue != null && stringValue.isBlank()) stringValue = null;
|
||||
@ -169,7 +174,7 @@ public class AdvancedJpaRepository extends SimpleJpaRepository {
|
||||
value = field.getType().parseValue(stringValue);
|
||||
} else {
|
||||
try {
|
||||
MultipartFile file = files.get(field.getJavaName());
|
||||
MultipartFile file = files.get(field.getName());
|
||||
if (file != null)
|
||||
value = file.getBytes();
|
||||
} catch (IOException e) {
|
||||
|
@ -147,26 +147,6 @@ public class DbObject {
|
||||
}
|
||||
}
|
||||
|
||||
// public void initializeFromMap(Map<String, String> values) {
|
||||
//// String pkValue = values.get(schema.getPrimaryKey().getName());
|
||||
//
|
||||
// List<String> fields =
|
||||
// values.keySet().stream().filter(f -> !f.startsWith("__dbadmin_")).collect(Collectors.toList());
|
||||
//
|
||||
// for (String field : fields) {
|
||||
// String fieldJavaName = Utils.snakeToCamel(field);
|
||||
// Method setter = findSetter(fieldJavaName);
|
||||
// if (setter == null)
|
||||
// throw new DbAdminException("Unable to find setter for field " + fieldJavaName + " in class " + schema.getClassName());
|
||||
//
|
||||
// try {
|
||||
// setter.invoke(instance, values.get(field));
|
||||
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
// throw new DbAdminException(e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public void set(String fieldName, Object value) {
|
||||
Method setter = findSetter(fieldName);
|
||||
|
||||
|
28
src/main/resources/static/js/create.js
Normal file
28
src/main/resources/static/js/create.js
Normal file
@ -0,0 +1,28 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
let checkboxes = document.querySelectorAll(".binary-field-checkbox");
|
||||
|
||||
checkboxes.forEach(checkbox => {
|
||||
let fieldName = checkbox.dataset.fieldname;
|
||||
|
||||
if (!checkbox.checked) {
|
||||
document.querySelector(`input[name="${fieldName}"]`).classList.add('d-block');
|
||||
document.querySelector(`input[name="${fieldName}"]`).classList.remove('d-none');
|
||||
document.querySelector(`input[name="${fieldName}"]`).value = '';
|
||||
} else {
|
||||
document.querySelector(`input[name="${fieldName}"]`).classList.add('d-none');
|
||||
document.querySelector(`input[name="${fieldName}"]`).classList.remove('d-block');
|
||||
}
|
||||
|
||||
checkbox.addEventListener('change', function(e) {
|
||||
if (!e.target.checked) {
|
||||
document.querySelector(`input[name="${fieldName}"]`).classList.add('d-block');
|
||||
document.querySelector(`input[name="${fieldName}"]`).classList.remove('d-none');
|
||||
document.querySelector(`input[name="${fieldName}"]`).value = '';
|
||||
} else {
|
||||
document.querySelector(`input[name="${fieldName}"]`).classList.add('d-none');
|
||||
document.querySelector(`input[name="${fieldName}"]`).classList.remove('d-block');
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
});
|
@ -62,7 +62,7 @@
|
||||
<span th:unless="${!field.isBinary()}">
|
||||
<th:block th:if="${object.get(field).getValue()}">
|
||||
<a class="text-decoration-none null-label"
|
||||
th:href="|/dbadmin/download/${schema.getJavaClass().getName()}/${field.getName()}/${object.get(schema.getPrimaryKey()).getValue()}|">
|
||||
th:href="|/dbadmin/download/${schema.getJavaClass().getName()}/${field.getJavaName()}/${object.get(schema.getPrimaryKey()).getValue()}|">
|
||||
<i class="align-middle bi bi-box-arrow-down"></i><span class="align-middle"> Download
|
||||
<!--/*--> <span class="text-muted">([[ ${object.get(field).getValue().length} ]] bytes)</span> <!--*/-->
|
||||
</span>
|
||||
|
@ -10,6 +10,7 @@
|
||||
<script type="text/javascript" src="/js/autocomplete.js"></script>
|
||||
<script type="text/javascript" src="/js/autocomplete-multi.js"></script>
|
||||
<script type="text/javascript" src="/js/filters.js"></script>
|
||||
<script type="text/javascript" src="/js/create.js"></script>
|
||||
<title th:text="${title != null ? title + ' | Spring Boot DB Admin Panel' : 'Spring Boot DB Admin Panel'}"></title>
|
||||
</head>
|
||||
|
||||
|
@ -39,15 +39,14 @@
|
||||
: (object != null ? object.traverse(field).getPrimaryKeyValue() : '' )
|
||||
})}">
|
||||
</div>
|
||||
<!-- <input type="hidden" th:value="${field.getType()}" th:name="|__dbadmin_${field.getName()}_type|"> -->
|
||||
</th:block>
|
||||
<th:block th:unless="${field.isForeignKey()}">
|
||||
<input placeholder="NULL" th:type="${field.getType().getHTMLName()}"
|
||||
|
||||
<input th:if="${!field.isBinary()}" placeholder="NULL" th:type="${field.getType().getHTMLName()}"
|
||||
th:name="${field.getName()}"
|
||||
th:value="
|
||||
${create ? (params != null ? params.getOrDefault(field.getName(), '') : '')
|
||||
: (object != null ? object.get(field).getValue() : '' )}
|
||||
|
||||
"
|
||||
class="form-control" th:id="|__id_${field.getName()}|"
|
||||
th:classAppend="${field.isPrimaryKey() && object != null ? 'disable' : ''}"
|
||||
@ -55,7 +54,25 @@
|
||||
step="any"
|
||||
oninvalid="this.setCustomValidity('This field is not nullable.')"
|
||||
oninput="this.setCustomValidity('')">
|
||||
<!-- <input type="hidden" th:value="${field.getType()}" th:name="|__dbadmin_${field.getName()}_type|"> -->
|
||||
<!--/*--> Binary field flag <!--*/-->
|
||||
<th:block th:if="${field.isBinary()}">
|
||||
<div th:if="${object.get(field).getValue() != null}">
|
||||
<input type="checkbox"
|
||||
class="binary-field-checkbox"
|
||||
th:data-fieldname="${field.getName()}"
|
||||
th:id="|__keep_${field.getName()}|"
|
||||
checked
|
||||
th:name="|__keep_${field.getName()}|">
|
||||
<span>Keep current data</span>
|
||||
</div>
|
||||
<input th:if="${field.isBinary()}" placeholder="NULL" th:type="${field.getType().getHTMLName()}"
|
||||
th:name="${field.getName()}"
|
||||
class="form-control mt-2" th:id="|__id_${field.getName()}|"
|
||||
th:classAppend="${object.get(field).getValue() == null ? '' : ''}"
|
||||
th:required="${!field.isNullable()}"
|
||||
oninvalid="this.setCustomValidity('This field is not nullable.')"
|
||||
oninput="this.setCustomValidity('')">
|
||||
</th:block>
|
||||
</th:block>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user