mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Merged feature/filter-json-field-improvements into dev
This commit is contained in:
@ -34,8 +34,12 @@ public class FilterAndColumnsSetupData extends QWidgetData
|
|||||||
private String tableName;
|
private String tableName;
|
||||||
private Boolean allowVariables = false;
|
private Boolean allowVariables = false;
|
||||||
private Boolean hideColumns = false;
|
private Boolean hideColumns = false;
|
||||||
|
private Boolean hidePreview = false;
|
||||||
private List<String> filterDefaultFieldNames;
|
private List<String> filterDefaultFieldNames;
|
||||||
|
|
||||||
|
private String filterFieldName = "queryFilterJson";
|
||||||
|
private String columnFieldName = "columnsJson";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -193,4 +197,97 @@ public class FilterAndColumnsSetupData extends QWidgetData
|
|||||||
return (this);
|
return (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for hidePreview
|
||||||
|
*******************************************************************************/
|
||||||
|
public Boolean getHidePreview()
|
||||||
|
{
|
||||||
|
return (this.hidePreview);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for hidePreview
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setHidePreview(Boolean hidePreview)
|
||||||
|
{
|
||||||
|
this.hidePreview = hidePreview;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for hidePreview
|
||||||
|
*******************************************************************************/
|
||||||
|
public FilterAndColumnsSetupData withHidePreview(Boolean hidePreview)
|
||||||
|
{
|
||||||
|
this.hidePreview = hidePreview;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for filterFieldName
|
||||||
|
*******************************************************************************/
|
||||||
|
public String getFilterFieldName()
|
||||||
|
{
|
||||||
|
return (this.filterFieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for filterFieldName
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setFilterFieldName(String filterFieldName)
|
||||||
|
{
|
||||||
|
this.filterFieldName = filterFieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for filterFieldName
|
||||||
|
*******************************************************************************/
|
||||||
|
public FilterAndColumnsSetupData withFilterFieldName(String filterFieldName)
|
||||||
|
{
|
||||||
|
this.filterFieldName = filterFieldName;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for columnFieldName
|
||||||
|
*******************************************************************************/
|
||||||
|
public String getColumnFieldName()
|
||||||
|
{
|
||||||
|
return (this.columnFieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for columnFieldName
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setColumnFieldName(String columnFieldName)
|
||||||
|
{
|
||||||
|
this.columnFieldName = columnFieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for columnFieldName
|
||||||
|
*******************************************************************************/
|
||||||
|
public FilterAndColumnsSetupData withColumnFieldName(String columnFieldName)
|
||||||
|
{
|
||||||
|
this.columnFieldName = columnFieldName;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,45 @@
|
|||||||
package com.kingsrook.qqq.backend.core.model.metadata.fields;
|
package com.kingsrook.qqq.backend.core.model.metadata.fields;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.values.ValueBehaviorApplier;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Interface to mark a field behavior as one to be used during generating
|
** Interface to mark a field behavior as one to be used during generating
|
||||||
** display values.
|
** display values.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public interface FieldDisplayBehavior<T extends FieldDisplayBehavior<T>> extends FieldBehavior<T>
|
public interface FieldDisplayBehavior<T extends FieldDisplayBehavior<T>> extends FieldBehavior<T>
|
||||||
{
|
{
|
||||||
|
NoopFieldDisplayBehavior NOOP = new NoopFieldDisplayBehavior();
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
default T getDefault()
|
||||||
|
{
|
||||||
|
return (T) NOOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
** a default implementation for this behavior type, which does nothing.
|
||||||
|
***************************************************************************/
|
||||||
|
class NoopFieldDisplayBehavior implements FieldDisplayBehavior<NoopFieldDisplayBehavior>
|
||||||
|
{
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
@Override
|
||||||
|
public void apply(ValueBehaviorApplier.Action action, List<QRecord> recordList, QInstance instance, QTableMetaData table, QFieldMetaData field)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* QQQ - Low-code Application Framework for Engineers.
|
||||||
|
* Copyright (C) 2021-2025. 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.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.values.ValueBehaviorApplier;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Display value formatter for fields which store a QQueryFilter as JSON.
|
||||||
|
*******************************************************************************/
|
||||||
|
public class FilterJsonFieldDisplayValueFormatter implements FieldDisplayBehavior<FilterJsonFieldDisplayValueFormatter>
|
||||||
|
{
|
||||||
|
private static Consumer<ObjectMapper> jsonMapperCustomizer = om -> om.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Override
|
||||||
|
public void apply(ValueBehaviorApplier.Action action, List<QRecord> recordList, QInstance instance, QTableMetaData table, QFieldMetaData field)
|
||||||
|
{
|
||||||
|
for(QRecord record : CollectionUtils.nonNullList(recordList))
|
||||||
|
{
|
||||||
|
String queryFilterJson = record.getValueString(field.getName());
|
||||||
|
if(StringUtils.hasContent(queryFilterJson))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
QQueryFilter qQueryFilter = JsonUtils.toObject(queryFilterJson, QQueryFilter.class, jsonMapperCustomizer);
|
||||||
|
int criteriaCount = CollectionUtils.nonNullList(qQueryFilter.getCriteria()).size();
|
||||||
|
record.setDisplayValue(field.getName(), criteriaCount + " Filter" + StringUtils.plural(criteriaCount));
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
record.setDisplayValue(field.getName(), "Invalid Filter...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user