From 82311fd23e4ba7b74e837e356e8bec67ad33a615 Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 20 Sep 2023 20:18:56 +0200 Subject: [PATCH] WIP --- .../controller/DefaultDbAdminController.java | 11 ++++++----- .../controller/DownloadController.java | 14 +++++++++++++- .../ailef/dbadmin/dbmapping/DbObject.java | 5 ++++- src/main/resources/static/css/dbadmin.css | 6 ++++-- src/main/resources/static/js/table.js | 14 +++++++++++--- .../templates/fragments/data_row.html | 19 +++++++++---------- .../resources/templates/fragments/table.html | 1 + .../templates/fragments/table_selectable.html | 6 +++--- 8 files changed, 51 insertions(+), 25 deletions(-) diff --git a/src/main/java/tech/ailef/dbadmin/controller/DefaultDbAdminController.java b/src/main/java/tech/ailef/dbadmin/controller/DefaultDbAdminController.java index be5a78f..944e039 100644 --- a/src/main/java/tech/ailef/dbadmin/controller/DefaultDbAdminController.java +++ b/src/main/java/tech/ailef/dbadmin/controller/DefaultDbAdminController.java @@ -39,19 +39,23 @@ import tech.ailef.dbadmin.misc.Utils; @Controller @RequestMapping("/dbadmin") /** + * FOR 0.0.3: + * @DisplayImage DONE TODO: write docs in README + * Fixed/improved edit page for binary fields (files) DONE + * + * TODO * - double data source for internal database and settings * - role based authorization (PRO) * - Pagination in one to many results? - * - BLOB upload (WIP: check edit not working) * - AI console (PRO) * - Action logs * - Boolean icons * - Boolean in create/edit is checkbox + * - Documentation * - SQL console (PRO) * - JPA Validation (PRO) * - Logging * - Selenium tests - * - @DisplayImage * - Logs in web ui * - Tests: AutocompleteController, REST API, create/edit */ @@ -81,7 +85,6 @@ public class DefaultDbAdminController { model.addAttribute("activePage", "home"); model.addAttribute("title", "Entities | Index"); - return "home"; } @@ -272,8 +275,6 @@ public class DefaultDbAdminController { @RequestParam MultiValueMap formParams, @RequestParam Map files, RedirectAttributes attr) { - - // Extract all parameters that have exactly 1 value, // as these will be the raw values for the object that is being // created. diff --git a/src/main/java/tech/ailef/dbadmin/controller/DownloadController.java b/src/main/java/tech/ailef/dbadmin/controller/DownloadController.java index 354b1a2..7b43588 100644 --- a/src/main/java/tech/ailef/dbadmin/controller/DownloadController.java +++ b/src/main/java/tech/ailef/dbadmin/controller/DownloadController.java @@ -22,6 +22,7 @@ import tech.ailef.dbadmin.dbmapping.DbAdminRepository; import tech.ailef.dbadmin.dbmapping.DbFieldValue; import tech.ailef.dbadmin.dbmapping.DbObject; import tech.ailef.dbadmin.dbmapping.DbObjectSchema; +import tech.ailef.dbadmin.exceptions.DbAdminException; @Controller @RequestMapping("/dbadmin/download") @@ -65,7 +66,18 @@ public class DownloadController { if (object.isPresent()) { DbObject dbObject = object.get(); - DbFieldValue dbFieldValue = dbObject.get(fieldName); + + DbFieldValue dbFieldValue; + try { + dbFieldValue = dbObject.get(fieldName); + } catch (DbAdminException e) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Field not found", e); + } + + if (dbFieldValue.getValue() == null) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "There's no file attached to this item"); + } + byte[] file = (byte[])dbFieldValue.getValue(); String filename = schema.getClassName() + "_" + id + "_" + fieldName; diff --git a/src/main/java/tech/ailef/dbadmin/dbmapping/DbObject.java b/src/main/java/tech/ailef/dbadmin/dbmapping/DbObject.java index 801b887..7fd4406 100644 --- a/src/main/java/tech/ailef/dbadmin/dbmapping/DbObject.java +++ b/src/main/java/tech/ailef/dbadmin/dbmapping/DbObject.java @@ -179,8 +179,11 @@ public class DbObject { String capitalize = Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); Method[] methods = instance.getClass().getDeclaredMethods(); + DbField dbField = schema.getFieldByJavaName(fieldName); + if (dbField == null) return null; + String prefix = "get"; - if (schema.getFieldByJavaName(fieldName).getType() == DbFieldType.BOOLEAN) { + if (dbField.getType() == DbFieldType.BOOLEAN) { prefix = "is"; } diff --git a/src/main/resources/static/css/dbadmin.css b/src/main/resources/static/css/dbadmin.css index b2876a5..ddc1e93 100644 --- a/src/main/resources/static/css/dbadmin.css +++ b/src/main/resources/static/css/dbadmin.css @@ -56,7 +56,7 @@ tr.table-data-row td:last-child, tr.table-data-row th:last-child { .row-icons { font-size: 1.2rem; - width: 128px; + width: 96px; } h1 .bi { @@ -116,6 +116,8 @@ h1 a:hover { max-height: 300px; overflow: auto; z-index: 999; + -webkit-box-shadow: 0px 11px 12px -1px rgba(0,0,0,0.13); + box-shadow: 0px 11px 12px -1px rgba(0,0,0,0.13); } .suggestion { @@ -128,7 +130,7 @@ h1 a:hover { .suggestion:hover { cursor: pointer; - background-color: #FFF; + background-color: #EBF7FF; border-bottom: 2px solid #ADDEFF; } diff --git a/src/main/resources/static/js/table.js b/src/main/resources/static/js/table.js index cfd3557..9790e92 100644 --- a/src/main/resources/static/js/table.js +++ b/src/main/resources/static/js/table.js @@ -1,15 +1,23 @@ function updateBulkActions(table, selected) { let divs = document.querySelectorAll(".bulk-actions"); divs.forEach(div => { - div.innerHTML = `${selected} items selected `; + div.innerHTML = `${selected} items selected `; }); } document.addEventListener("DOMContentLoaded", () => { let selected = 0; - if (document.getElementById('delete-form') != null) { - document.getElementById('delete-form').addEventListener('submit', function(e) { + document.querySelectorAll(".delete-form").forEach(form => { + form.addEventListener('submit', function(e) { + if (!confirm('Are you sure you want to delete this item?')) { + e.preventDefault(); + } + }); + }); + + if (document.getElementById('multi-delete-form') != null) { + document.getElementById('multi-delete-form').addEventListener('submit', function(e) { if (selected == 0) { e.preventDefault(); alert('No items selected'); diff --git a/src/main/resources/templates/fragments/data_row.html b/src/main/resources/templates/fragments/data_row.html index e1de7f5..c59b035 100644 --- a/src/main/resources/templates/fragments/data_row.html +++ b/src/main/resources/templates/fragments/data_row.html @@ -5,7 +5,15 @@ + th:value="${row.getPrimaryKeyValue()}" form="multi-delete-form"> + + + + +
+ +
@@ -20,15 +28,6 @@ - - - - -
- -
- diff --git a/src/main/resources/templates/fragments/table.html b/src/main/resources/templates/fragments/table.html index 7e6f1a0..f02ba5b 100644 --- a/src/main/resources/templates/fragments/table.html +++ b/src/main/resources/templates/fragments/table.html @@ -9,6 +9,7 @@
+
diff --git a/src/main/resources/templates/fragments/table_selectable.html b/src/main/resources/templates/fragments/table_selectable.html index 8bd5262..ae5b4ea 100644 --- a/src/main/resources/templates/fragments/table_selectable.html +++ b/src/main/resources/templates/fragments/table_selectable.html @@ -2,18 +2,19 @@ -
+

This table contains no data.

-
+
+ -
@@ -56,7 +57,6 @@

COMPUTED