Add count, totalRows to child record lists

This commit is contained in:
2023-05-02 15:52:15 -05:00
parent 80ae3e1e0c
commit b0dbede6fe
2 changed files with 56 additions and 4 deletions

View File

@ -30,10 +30,12 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.kingsrook.qqq.backend.core.actions.tables.CountAction;
import com.kingsrook.qqq.backend.core.actions.tables.GetAction; import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction; import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
import com.kingsrook.qqq.backend.core.exceptions.QException; import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.exceptions.QNotFoundException; import com.kingsrook.qqq.backend.core.exceptions.QNotFoundException;
import com.kingsrook.qqq.backend.core.model.actions.tables.count.CountInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetInput; import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetOutput; import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetOutput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator; import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
@ -168,6 +170,10 @@ public class ChildRecordListRenderer extends AbstractWidgetRenderer
{ {
maxRows = ValueUtils.getValueAsInteger(input.getQueryParams().get("maxRows")); maxRows = ValueUtils.getValueAsInteger(input.getQueryParams().get("maxRows"));
} }
else if(input.getWidgetMetaData().getDefaultValues().containsKey("maxRows"))
{
maxRows = ValueUtils.getValueAsInteger(input.getWidgetMetaData().getDefaultValues().containsKey("maxRows"));
}
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// fetch the record that we're getting children for. // // fetch the record that we're getting children for. //
@ -203,11 +209,24 @@ public class ChildRecordListRenderer extends AbstractWidgetRenderer
queryInput.setFilter(filter); queryInput.setFilter(filter);
QueryOutput queryOutput = new QueryAction().execute(queryInput); QueryOutput queryOutput = new QueryAction().execute(queryInput);
int totalRows = queryOutput.getRecords().size();
if(maxRows != null && (queryOutput.getRecords().size() == maxRows))
{
/////////////////////////////////////////////////////////////////////////////////////
// if the input said to only do some max, and the # of results we got is that max, //
// then do a count query, for displaying 1-n of <count> //
/////////////////////////////////////////////////////////////////////////////////////
CountInput countInput = new CountInput();
countInput.setTableName(join.getRightTable());
countInput.setFilter(filter);
totalRows = new CountAction().execute(countInput).getCount();
}
QTableMetaData table = input.getInstance().getTable(join.getRightTable()); QTableMetaData table = input.getInstance().getTable(join.getRightTable());
String tablePath = input.getInstance().getTablePath(table.getName()); String tablePath = input.getInstance().getTablePath(table.getName());
String viewAllLink = tablePath == null ? null : (tablePath + "?filter=" + URLEncoder.encode(JsonUtils.toJson(filter), Charset.defaultCharset())); String viewAllLink = tablePath == null ? null : (tablePath + "?filter=" + URLEncoder.encode(JsonUtils.toJson(filter), Charset.defaultCharset()));
ChildRecordListData widgetData = new ChildRecordListData(widgetLabel, queryOutput, table, tablePath, viewAllLink); ChildRecordListData widgetData = new ChildRecordListData(widgetLabel, queryOutput, table, tablePath, viewAllLink, totalRows);
if(BooleanUtils.isTrue(ValueUtils.getValueAsBoolean(input.getQueryParams().get("canAddChildRecord")))) if(BooleanUtils.isTrue(ValueUtils.getValueAsBoolean(input.getQueryParams().get("canAddChildRecord"))))
{ {

View File

@ -41,6 +41,7 @@ public class ChildRecordListData extends QWidgetData
private String tablePath; private String tablePath;
private String viewAllLink; private String viewAllLink;
private Integer totalRows;
private boolean canAddChildRecord = false; private boolean canAddChildRecord = false;
private Map<String, Serializable> defaultValuesForNewChildRecords; private Map<String, Serializable> defaultValuesForNewChildRecords;
@ -51,13 +52,14 @@ public class ChildRecordListData extends QWidgetData
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
public ChildRecordListData(String title, QueryOutput queryOutput, QTableMetaData childTableMetaData, String tablePath, String viewAllLink) public ChildRecordListData(String title, QueryOutput queryOutput, QTableMetaData childTableMetaData, String tablePath, String viewAllLink, Integer totalRows)
{ {
this.title = title; this.title = title;
this.queryOutput = queryOutput; this.queryOutput = queryOutput;
this.childTableMetaData = childTableMetaData; this.childTableMetaData = childTableMetaData;
this.tablePath = tablePath; this.tablePath = tablePath;
this.viewAllLink = viewAllLink; this.viewAllLink = viewAllLink;
this.totalRows = totalRows;
} }
@ -319,4 +321,35 @@ public class ChildRecordListData extends QWidgetData
return (this); return (this);
} }
/*******************************************************************************
** Getter for totalRows
*******************************************************************************/
public Integer getTotalRows()
{
return (this.totalRows);
}
/*******************************************************************************
** Setter for totalRows
*******************************************************************************/
public void setTotalRows(Integer totalRows)
{
this.totalRows = totalRows;
}
/*******************************************************************************
** Fluent setter for totalRows
*******************************************************************************/
public ChildRecordListData withTotalRows(Integer totalRows)
{
this.totalRows = totalRows;
return (this);
}
} }