Add field adornments (links, chips, widths)

This commit is contained in:
2022-09-23 17:01:42 -05:00
parent 3ac6b34963
commit d73e546c7b
4 changed files with 325 additions and 0 deletions

View File

@ -0,0 +1,88 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.backend.core.model.metadata.fields;
import java.io.Serializable;
import com.kingsrook.qqq.backend.core.utils.Pair;
/*******************************************************************************
** Types of adornments that can be added to fields - with utilities for
** constructing their values.
*******************************************************************************/
public enum AdornmentType
{
LINK,
CHIP,
SIZE;
/*******************************************************************************
**
*******************************************************************************/
public interface LinkValues
{
String TARGET = "target";
}
/*******************************************************************************
**
*******************************************************************************/
public interface ChipValues
{
/*******************************************************************************
**
*******************************************************************************/
static Pair<String, Serializable> colorValue(Serializable value, String colorName)
{
return (new Pair<>("color." + value, colorName));
}
/*******************************************************************************
**
*******************************************************************************/
static Pair<String, Serializable> iconValue(Serializable value, String iconName)
{
return (new Pair<>("icon." + value, iconName));
}
}
/*******************************************************************************
**
*******************************************************************************/
public interface SizeValues
{
String WIDTH = "width";
String XSMALL = "xsmall";
String SMALL = "small";
String MEDIUM = "medium";
String LARGE = "large";
String XLARGE = "xlarge";
}
}

View File

@ -0,0 +1,167 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.backend.core.model.metadata.fields;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import com.kingsrook.qqq.backend.core.utils.Pair;
/*******************************************************************************
** Special fancy things that fields might do in UIs.
*******************************************************************************/
public class FieldAdornment
{
private AdornmentType type;
private Map<String, Serializable> values = new HashMap<>();
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public FieldAdornment()
{
}
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public FieldAdornment(AdornmentType type)
{
this.type = type;
}
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public FieldAdornment(AdornmentType type, Map<String, Serializable> values)
{
this.type = type;
this.values = values;
}
/*******************************************************************************
** Getter for type
**
*******************************************************************************/
public AdornmentType getType()
{
return type;
}
/*******************************************************************************
** Setter for type
**
*******************************************************************************/
public void setType(AdornmentType type)
{
this.type = type;
}
/*******************************************************************************
** Fluent setter for type
**
*******************************************************************************/
public FieldAdornment withType(AdornmentType type)
{
this.type = type;
return (this);
}
/*******************************************************************************
** Getter for values
**
*******************************************************************************/
public Map<String, Serializable> getValues()
{
return values;
}
/*******************************************************************************
** Setter for values
**
*******************************************************************************/
public void setValues(Map<String, Serializable> values)
{
this.values = values;
}
/*******************************************************************************
** Fluent setter for values
**
*******************************************************************************/
public FieldAdornment withValues(Map<String, Serializable> values)
{
this.values = values;
return (this);
}
/*******************************************************************************
** Fluent setter for values
**
*******************************************************************************/
public FieldAdornment withValue(String key, Serializable value)
{
if(this.values == null)
{
this.values = new HashMap<>();
}
this.values.put(key, value);
return (this);
}
/*******************************************************************************
** Fluent setter for values
**
*******************************************************************************/
public FieldAdornment withValue(Pair<String, Serializable> value)
{
return (withValue(value.getA(), value.getB()));
}
}

View File

@ -24,6 +24,8 @@ package com.kingsrook.qqq.backend.core.model.metadata.fields;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import com.github.hervian.reflection.Fun;
import com.kingsrook.qqq.backend.core.exceptions.QException;
@ -54,6 +56,8 @@ public class QFieldMetaData
private Serializable defaultValue;
private String possibleValueSourceName;
private List<FieldAdornment> adornments;
/*******************************************************************************
@ -455,4 +459,54 @@ public class QFieldMetaData
return (this);
}
/*******************************************************************************
** Getter for adornments
**
*******************************************************************************/
public List<FieldAdornment> getAdornments()
{
return adornments;
}
/*******************************************************************************
** Setter for adornments
**
*******************************************************************************/
public void setAdornments(List<FieldAdornment> adornments)
{
this.adornments = adornments;
}
/*******************************************************************************
** Fluent setter for adornments
**
*******************************************************************************/
public QFieldMetaData withFieldAdornments(List<FieldAdornment> adornments)
{
this.adornments = adornments;
return (this);
}
/*******************************************************************************
** Fluent setter for adornments
**
*******************************************************************************/
public QFieldMetaData withFieldAdornment(FieldAdornment adornment)
{
if(this.adornments == null)
{
this.adornments = new ArrayList<>();
}
this.adornments.add(adornment);
return (this);
}
}

View File

@ -22,8 +22,10 @@
package com.kingsrook.qqq.backend.core.model.metadata.frontend;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.kingsrook.qqq.backend.core.model.metadata.fields.FieldAdornment;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
@ -44,6 +46,8 @@ public class QFrontendFieldMetaData
private String possibleValueSourceName;
private String displayFormat;
private List<FieldAdornment> adornments;
//////////////////////////////////////////////////////////////////////////////////
// do not add setters. take values from the source-object in the constructor!! //
//////////////////////////////////////////////////////////////////////////////////
@ -62,6 +66,7 @@ public class QFrontendFieldMetaData
this.isEditable = fieldMetaData.getIsEditable();
this.possibleValueSourceName = fieldMetaData.getPossibleValueSourceName();
this.displayFormat = fieldMetaData.getDisplayFormat();
this.adornments = fieldMetaData.getAdornments();
}
@ -132,6 +137,17 @@ public class QFrontendFieldMetaData
/*******************************************************************************
** Getter for adornments
**
*******************************************************************************/
public List<FieldAdornment> getAdornments()
{
return adornments;
}
/*******************************************************************************
** Getter for possibleValueSourceName
**