mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-08-07 04:31:12 +00:00
Removed FragmentContext
and instead created multiple versions of input fields fragments for different contexts (search, create)
This commit is contained in:
@@ -53,7 +53,6 @@ import tech.ailef.dbadmin.external.dbmapping.DbObject;
|
|||||||
import tech.ailef.dbadmin.external.dbmapping.DbObjectSchema;
|
import tech.ailef.dbadmin.external.dbmapping.DbObjectSchema;
|
||||||
import tech.ailef.dbadmin.external.dto.CompareOperator;
|
import tech.ailef.dbadmin.external.dto.CompareOperator;
|
||||||
import tech.ailef.dbadmin.external.dto.FacetedSearchRequest;
|
import tech.ailef.dbadmin.external.dto.FacetedSearchRequest;
|
||||||
import tech.ailef.dbadmin.external.dto.FragmentContext;
|
|
||||||
import tech.ailef.dbadmin.external.dto.LogsSearchRequest;
|
import tech.ailef.dbadmin.external.dto.LogsSearchRequest;
|
||||||
import tech.ailef.dbadmin.external.dto.PaginatedResult;
|
import tech.ailef.dbadmin.external.dto.PaginatedResult;
|
||||||
import tech.ailef.dbadmin.external.dto.QueryFilter;
|
import tech.ailef.dbadmin.external.dto.QueryFilter;
|
||||||
@@ -278,7 +277,6 @@ public class DefaultDbAdminController {
|
|||||||
model.addAttribute("title", "Entities | " + schema.getJavaClass().getSimpleName() + " | Create");
|
model.addAttribute("title", "Entities | " + schema.getJavaClass().getSimpleName() + " | Create");
|
||||||
model.addAttribute("activePage", "entities");
|
model.addAttribute("activePage", "entities");
|
||||||
model.addAttribute("create", true);
|
model.addAttribute("create", true);
|
||||||
model.addAttribute("fragmentContext", FragmentContext.CREATE);
|
|
||||||
|
|
||||||
return "model/create";
|
return "model/create";
|
||||||
}
|
}
|
||||||
@@ -305,7 +303,6 @@ public class DefaultDbAdminController {
|
|||||||
model.addAttribute("schema", schema);
|
model.addAttribute("schema", schema);
|
||||||
model.addAttribute("activePage", "entities");
|
model.addAttribute("activePage", "entities");
|
||||||
model.addAttribute("create", false);
|
model.addAttribute("create", false);
|
||||||
model.addAttribute("fragmentContext", FragmentContext.CREATE);
|
|
||||||
|
|
||||||
return "model/create";
|
return "model/create";
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,6 @@ import tech.ailef.dbadmin.external.annotations.DisplayImage;
|
|||||||
import tech.ailef.dbadmin.external.annotations.Filterable;
|
import tech.ailef.dbadmin.external.annotations.Filterable;
|
||||||
import tech.ailef.dbadmin.external.annotations.FilterableType;
|
import tech.ailef.dbadmin.external.annotations.FilterableType;
|
||||||
import tech.ailef.dbadmin.external.annotations.ReadOnly;
|
import tech.ailef.dbadmin.external.annotations.ReadOnly;
|
||||||
import tech.ailef.dbadmin.external.dto.FragmentContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represent a field on the database, generated from an Entity class instance variable.
|
* Represent a field on the database, generated from an Entity class instance variable.
|
||||||
@@ -183,22 +182,13 @@ public class DbField {
|
|||||||
return type == DbFieldType.TEXT;
|
return type == DbFieldType.TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name of the Thymeleaf fragment used to render
|
|
||||||
* the input for this field.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getFragmentName(FragmentContext c) {
|
|
||||||
return type.getFragmentName(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the Thymeleaf fragment used to render
|
* Returns the name of the Thymeleaf fragment used to render
|
||||||
* the input for this field.
|
* the input for this field.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getFragmentName() {
|
public String getFragmentName() {
|
||||||
return type.getFragmentName(FragmentContext.DEFAULT);
|
return type.getFragmentName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFilterable() {
|
public boolean isFilterable() {
|
||||||
|
@@ -37,7 +37,6 @@ import jakarta.persistence.ManyToMany;
|
|||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
import tech.ailef.dbadmin.external.dto.CompareOperator;
|
import tech.ailef.dbadmin.external.dto.CompareOperator;
|
||||||
import tech.ailef.dbadmin.external.dto.FragmentContext;
|
|
||||||
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
|
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +45,7 @@ import tech.ailef.dbadmin.external.exceptions.DbAdminException;
|
|||||||
public enum DbFieldType {
|
public enum DbFieldType {
|
||||||
SHORT {
|
SHORT {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "number";
|
return "number";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +66,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
BIG_INTEGER {
|
BIG_INTEGER {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "number";
|
return "number";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +88,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
INTEGER {
|
INTEGER {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "number";
|
return "number";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +109,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
DOUBLE {
|
DOUBLE {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "number";
|
return "number";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +130,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
LONG {
|
LONG {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "number";
|
return "number";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +151,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
FLOAT {
|
FLOAT {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "number";
|
return "number";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +172,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
OFFSET_DATE_TIME {
|
OFFSET_DATE_TIME {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "datetime";
|
return "datetime";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +195,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
DATE {
|
DATE {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "date";
|
return "date";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +222,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
LOCAL_DATE {
|
LOCAL_DATE {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "date";
|
return "date";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +244,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
LOCAL_DATE_TIME {
|
LOCAL_DATE_TIME {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "datetime";
|
return "datetime";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +266,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
STRING {
|
STRING {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "text";
|
return "text";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,10 +287,8 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
TEXT {
|
TEXT {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
if (c == FragmentContext.CREATE)
|
return "textarea";
|
||||||
return "textarea";
|
|
||||||
return "text";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -312,7 +309,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
BOOLEAN {
|
BOOLEAN {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "text";
|
return "text";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,7 +330,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
BIG_DECIMAL {
|
BIG_DECIMAL {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "number";
|
return "number";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,7 +351,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
CHAR {
|
CHAR {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "char";
|
return "char";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,7 +372,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
BYTE {
|
BYTE {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "number";
|
return "number";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,7 +393,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
BYTE_ARRAY {
|
BYTE_ARRAY {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
return "file";
|
return "file";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,7 +418,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
ONE_TO_MANY {
|
ONE_TO_MANY {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,7 +449,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
ONE_TO_ONE {
|
ONE_TO_ONE {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,7 +480,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
MANY_TO_MANY {
|
MANY_TO_MANY {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,7 +511,7 @@ public enum DbFieldType {
|
|||||||
},
|
},
|
||||||
COMPUTED {
|
COMPUTED {
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentName(FragmentContext c) {
|
public String getFragmentName() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -543,7 +540,7 @@ public enum DbFieldType {
|
|||||||
*
|
*
|
||||||
* @param c the context in which this fragment has to be rendered
|
* @param c the context in which this fragment has to be rendered
|
||||||
*/
|
*/
|
||||||
public abstract String getFragmentName(FragmentContext c);
|
public abstract String getFragmentName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the value received through an HTML form into a instance
|
* Parse the value received through an HTML form into a instance
|
||||||
|
@@ -1,39 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
* Spring Boot Database Admin - An automatically generated CRUD admin UI for Spring Boot apps
|
// * Spring Boot Database Admin - An automatically generated CRUD admin UI for Spring Boot apps
|
||||||
* Copyright (C) 2023 Ailef (http://ailef.tech)
|
// * Copyright (C) 2023 Ailef (http://ailef.tech)
|
||||||
*
|
// *
|
||||||
* This program is free software: you can redistribute it and/or modify
|
// * This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
// * it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
// * the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
// * (at your option) any later version.
|
||||||
*
|
// *
|
||||||
* This program is distributed in the hope that it will be useful,
|
// * This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
*
|
// *
|
||||||
* You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
package tech.ailef.dbadmin.external.dto;
|
//package tech.ailef.dbadmin.external.dto;
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Some fragments might need to be rendered differently depending
|
// * Some fragments might need to be rendered differently depending
|
||||||
* on their context. For example a TEXT field is usually rendered
|
// * on their context. For example a TEXT field is usually rendered
|
||||||
* as a text area, but if it has to fit in the faceted search right
|
// * as a text area, but if it has to fit in the faceted search right
|
||||||
* bar it's rendered as a normal input type "text" field for space
|
// * bar it's rendered as a normal input type "text" field for space
|
||||||
* reasons (and because the user just needs to search with a short
|
// * reasons (and because the user just needs to search with a short
|
||||||
* query).
|
// * query).
|
||||||
*
|
// *
|
||||||
* This enum indicates the possible contexts and it is passed to the
|
// * This enum indicates the possible contexts and it is passed to the
|
||||||
* getFragmentName() method which determines which actual fragment
|
// * getFragmentName() method which determines which actual fragment
|
||||||
* to use.
|
// * to use.
|
||||||
*
|
// *
|
||||||
*/
|
// */
|
||||||
public enum FragmentContext {
|
//public enum FragmentContext {
|
||||||
DEFAULT,
|
// DEFAULT,
|
||||||
CREATE,
|
// CREATE,
|
||||||
SEARCH
|
// SEARCH
|
||||||
}
|
//}
|
||||||
|
@@ -90,7 +90,7 @@
|
|||||||
<option th:value="${op}" th:each="op : ${field.getType().getCompareOperators()}"
|
<option th:value="${op}" th:each="op : ${field.getType().getCompareOperators()}"
|
||||||
th:text="${op.getDisplayName()}">
|
th:text="${op.getDisplayName()}">
|
||||||
</select>
|
</select>
|
||||||
<input th:replace="~{fragments/inputs ::
|
<input th:replace="~{fragments/search_inputs ::
|
||||||
__${field.getFragmentName()}__(
|
__${field.getFragmentName()}__(
|
||||||
field=${field},
|
field=${field},
|
||||||
create=${create},
|
create=${create},
|
||||||
|
75
src/main/resources/templates/fragments/search_inputs.html
Normal file
75
src/main/resources/templates/fragments/search_inputs.html
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
|
||||||
|
|
||||||
|
<input placeholder="NULL" th:fragment="textarea(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="char(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' : ''}|"
|
||||||
|
maxlength="1"
|
||||||
|
th:required="${!field.isNullable() && !field.isPrimaryKey()}"
|
||||||
|
></input>
|
||||||
|
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
</html>
|
Reference in New Issue
Block a user