mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-08-06 12:11:13 +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.dto.CompareOperator;
|
||||
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.PaginatedResult;
|
||||
import tech.ailef.dbadmin.external.dto.QueryFilter;
|
||||
@@ -278,7 +277,6 @@ public class DefaultDbAdminController {
|
||||
model.addAttribute("title", "Entities | " + schema.getJavaClass().getSimpleName() + " | Create");
|
||||
model.addAttribute("activePage", "entities");
|
||||
model.addAttribute("create", true);
|
||||
model.addAttribute("fragmentContext", FragmentContext.CREATE);
|
||||
|
||||
return "model/create";
|
||||
}
|
||||
@@ -305,7 +303,6 @@ public class DefaultDbAdminController {
|
||||
model.addAttribute("schema", schema);
|
||||
model.addAttribute("activePage", "entities");
|
||||
model.addAttribute("create", false);
|
||||
model.addAttribute("fragmentContext", FragmentContext.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.FilterableType;
|
||||
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.
|
||||
@@ -183,22 +182,13 @@ public class DbField {
|
||||
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
|
||||
* the input for this field.
|
||||
* @return
|
||||
*/
|
||||
public String getFragmentName() {
|
||||
return type.getFragmentName(FragmentContext.DEFAULT);
|
||||
return type.getFragmentName();
|
||||
}
|
||||
|
||||
public boolean isFilterable() {
|
||||
|
@@ -37,7 +37,6 @@ import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import tech.ailef.dbadmin.external.dto.CompareOperator;
|
||||
import tech.ailef.dbadmin.external.dto.FragmentContext;
|
||||
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
|
||||
|
||||
/**
|
||||
@@ -46,7 +45,7 @@ import tech.ailef.dbadmin.external.exceptions.DbAdminException;
|
||||
public enum DbFieldType {
|
||||
SHORT {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "number";
|
||||
}
|
||||
|
||||
@@ -67,7 +66,7 @@ public enum DbFieldType {
|
||||
},
|
||||
BIG_INTEGER {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "number";
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ public enum DbFieldType {
|
||||
},
|
||||
INTEGER {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "number";
|
||||
}
|
||||
|
||||
@@ -110,7 +109,7 @@ public enum DbFieldType {
|
||||
},
|
||||
DOUBLE {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "number";
|
||||
}
|
||||
|
||||
@@ -131,7 +130,7 @@ public enum DbFieldType {
|
||||
},
|
||||
LONG {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "number";
|
||||
}
|
||||
|
||||
@@ -152,7 +151,7 @@ public enum DbFieldType {
|
||||
},
|
||||
FLOAT {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "number";
|
||||
}
|
||||
|
||||
@@ -173,7 +172,7 @@ public enum DbFieldType {
|
||||
},
|
||||
OFFSET_DATE_TIME {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "datetime";
|
||||
}
|
||||
|
||||
@@ -196,7 +195,7 @@ public enum DbFieldType {
|
||||
},
|
||||
DATE {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "date";
|
||||
}
|
||||
|
||||
@@ -223,7 +222,7 @@ public enum DbFieldType {
|
||||
},
|
||||
LOCAL_DATE {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "date";
|
||||
}
|
||||
|
||||
@@ -245,7 +244,7 @@ public enum DbFieldType {
|
||||
},
|
||||
LOCAL_DATE_TIME {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "datetime";
|
||||
}
|
||||
|
||||
@@ -267,7 +266,7 @@ public enum DbFieldType {
|
||||
},
|
||||
STRING {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "text";
|
||||
}
|
||||
|
||||
@@ -288,10 +287,8 @@ public enum DbFieldType {
|
||||
},
|
||||
TEXT {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
if (c == FragmentContext.CREATE)
|
||||
return "textarea";
|
||||
return "text";
|
||||
public String getFragmentName() {
|
||||
return "textarea";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -312,7 +309,7 @@ public enum DbFieldType {
|
||||
},
|
||||
BOOLEAN {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "text";
|
||||
}
|
||||
|
||||
@@ -333,7 +330,7 @@ public enum DbFieldType {
|
||||
},
|
||||
BIG_DECIMAL {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "number";
|
||||
}
|
||||
|
||||
@@ -354,7 +351,7 @@ public enum DbFieldType {
|
||||
},
|
||||
CHAR {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "char";
|
||||
}
|
||||
|
||||
@@ -375,7 +372,7 @@ public enum DbFieldType {
|
||||
},
|
||||
BYTE {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "number";
|
||||
}
|
||||
|
||||
@@ -396,7 +393,7 @@ public enum DbFieldType {
|
||||
},
|
||||
BYTE_ARRAY {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
return "file";
|
||||
}
|
||||
|
||||
@@ -421,7 +418,7 @@ public enum DbFieldType {
|
||||
},
|
||||
ONE_TO_MANY {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -452,7 +449,7 @@ public enum DbFieldType {
|
||||
},
|
||||
ONE_TO_ONE {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -483,7 +480,7 @@ public enum DbFieldType {
|
||||
},
|
||||
MANY_TO_MANY {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -514,7 +511,7 @@ public enum DbFieldType {
|
||||
},
|
||||
COMPUTED {
|
||||
@Override
|
||||
public String getFragmentName(FragmentContext c) {
|
||||
public String getFragmentName() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -543,7 +540,7 @@ public enum DbFieldType {
|
||||
*
|
||||
* @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
|
||||
|
@@ -1,39 +1,39 @@
|
||||
/*
|
||||
* Spring Boot Database Admin - An automatically generated CRUD admin UI for Spring Boot apps
|
||||
* Copyright (C) 2023 Ailef (http://ailef.tech)
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package tech.ailef.dbadmin.external.dto;
|
||||
|
||||
|
||||
/**
|
||||
* Some fragments might need to be rendered differently depending
|
||||
* 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
|
||||
* 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
|
||||
* query).
|
||||
*
|
||||
* This enum indicates the possible contexts and it is passed to the
|
||||
* getFragmentName() method which determines which actual fragment
|
||||
* to use.
|
||||
*
|
||||
*/
|
||||
public enum FragmentContext {
|
||||
DEFAULT,
|
||||
CREATE,
|
||||
SEARCH
|
||||
}
|
||||
// * Spring Boot Database Admin - An automatically generated CRUD admin UI for Spring Boot apps
|
||||
// * Copyright (C) 2023 Ailef (http://ailef.tech)
|
||||
// *
|
||||
// * 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
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// */
|
||||
//
|
||||
//package tech.ailef.dbadmin.external.dto;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * Some fragments might need to be rendered differently depending
|
||||
// * 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
|
||||
// * 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
|
||||
// * query).
|
||||
// *
|
||||
// * This enum indicates the possible contexts and it is passed to the
|
||||
// * getFragmentName() method which determines which actual fragment
|
||||
// * to use.
|
||||
// *
|
||||
// */
|
||||
//public enum FragmentContext {
|
||||
// DEFAULT,
|
||||
// CREATE,
|
||||
// SEARCH
|
||||
//}
|
||||
|
@@ -90,7 +90,7 @@
|
||||
<option th:value="${op}" th:each="op : ${field.getType().getCompareOperators()}"
|
||||
th:text="${op.getDisplayName()}">
|
||||
</select>
|
||||
<input th:replace="~{fragments/inputs ::
|
||||
<input th:replace="~{fragments/search_inputs ::
|
||||
__${field.getFragmentName()}__(
|
||||
field=${field},
|
||||
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