mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-12-15 04:41:58 +09:00
@ReadOnly fields (#4)
This commit is contained in:
35
src/main/java/tech/ailef/dbadmin/external/annotations/ReadOnly.java
vendored
Normal file
35
src/main/java/tech/ailef/dbadmin/external/annotations/ReadOnly.java
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks a field as read-only. The field can be filled at creation time, but
|
||||
* it will be shown as disabled during edits, making it impossible to change its
|
||||
* value after creation.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface ReadOnly {
|
||||
}
|
||||
@@ -110,6 +110,7 @@ public class CustomJpaRepository extends SimpleJpaRepository {
|
||||
|
||||
for (DbField field : schema.getSortedFields()) {
|
||||
if (field.isPrimaryKey()) continue;
|
||||
if (field.isReadOnly()) continue;
|
||||
|
||||
boolean keepValue = params.getOrDefault("__keep_" + field.getName(), "off").equals("on");
|
||||
if (keepValue) continue;
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Represent a field on the database, generated from an Entity class instance variable.
|
||||
@@ -190,6 +191,10 @@ public class DbField {
|
||||
return filterable != null && filterable.type() == FilterableType.CATEGORICAL;
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return getPrimitiveField().getAnnotation(ReadOnly.class) != null;
|
||||
}
|
||||
|
||||
public Set<DbFieldValue> getAllValues() {
|
||||
List<?> findAll = schema.getJpaRepository().findAll();
|
||||
return findAll.stream()
|
||||
|
||||
Reference in New Issue
Block a user