mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
SPRINT-12: updated to define widgets at table level, refactoring of some of the widget stuff to match other "Action"s
This commit is contained in:
@ -22,10 +22,12 @@
|
|||||||
package com.kingsrook.qqq.backend.core.actions.dashboard;
|
package com.kingsrook.qqq.backend.core.actions.dashboard;
|
||||||
|
|
||||||
|
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.values.QValueFormatter;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -34,20 +36,15 @@ import com.kingsrook.qqq.backend.core.model.session.QSession;
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public abstract class AbstractWidgetRenderer
|
public abstract class AbstractWidgetRenderer
|
||||||
{
|
{
|
||||||
|
public static final QValueFormatter valueFormatter = new QValueFormatter();
|
||||||
/*******************************************************************************
|
public static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd H:mma").withZone(ZoneId.systemDefault());
|
||||||
**
|
public static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault());
|
||||||
*******************************************************************************/
|
|
||||||
public abstract Object render(QInstance qInstance, QSession session, QWidgetMetaDataInterface qWidgetMetaData) throws QException;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public String getWidgetName()
|
public abstract RenderWidgetOutput render(RenderWidgetInput input) throws QException;
|
||||||
{
|
|
||||||
return this.getClass().getSimpleName();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,11 @@ package com.kingsrook.qqq.backend.core.actions.dashboard;
|
|||||||
|
|
||||||
|
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.QWidget;
|
||||||
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.QuickSightChart;
|
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.QuickSightChart;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QuickSightChartMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QuickSightChartMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
|
||||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||||
import software.amazon.awssdk.regions.Region;
|
import software.amazon.awssdk.regions.Region;
|
||||||
@ -49,11 +49,11 @@ public class QuickSightChartRenderer extends AbstractWidgetRenderer
|
|||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@Override
|
@Override
|
||||||
public Object render(QInstance qInstance, QSession session, QWidgetMetaDataInterface metaData) throws QException
|
public RenderWidgetOutput render(RenderWidgetInput input) throws QException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QuickSightChartMetaData quickSightMetaData = (QuickSightChartMetaData) metaData;
|
QuickSightChartMetaData quickSightMetaData = (QuickSightChartMetaData) input.getWidgetMetaData();
|
||||||
QuickSightClient quickSightClient = getQuickSightClient(quickSightMetaData);
|
QuickSightClient quickSightClient = getQuickSightClient(quickSightMetaData);
|
||||||
|
|
||||||
final RegisteredUserEmbeddingExperienceConfiguration experienceConfiguration = RegisteredUserEmbeddingExperienceConfiguration.builder()
|
final RegisteredUserEmbeddingExperienceConfiguration experienceConfiguration = RegisteredUserEmbeddingExperienceConfiguration.builder()
|
||||||
@ -72,7 +72,8 @@ public class QuickSightChartRenderer extends AbstractWidgetRenderer
|
|||||||
final GenerateEmbedUrlForRegisteredUserResponse generateEmbedUrlForRegisteredUserResponse = quickSightClient.generateEmbedUrlForRegisteredUser(generateEmbedUrlForRegisteredUserRequest);
|
final GenerateEmbedUrlForRegisteredUserResponse generateEmbedUrlForRegisteredUserResponse = quickSightClient.generateEmbedUrlForRegisteredUser(generateEmbedUrlForRegisteredUserRequest);
|
||||||
|
|
||||||
String embedUrl = generateEmbedUrlForRegisteredUserResponse.embedUrl();
|
String embedUrl = generateEmbedUrlForRegisteredUserResponse.embedUrl();
|
||||||
return (new QuickSightChart(metaData.getName(), quickSightMetaData.getLabel(), embedUrl));
|
QWidget widget = new QuickSightChart(input.getWidgetMetaData().getName(), quickSightMetaData.getLabel(), embedUrl);
|
||||||
|
return (new RenderWidgetOutput(widget));
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
@ -24,26 +24,23 @@ package com.kingsrook.qqq.backend.core.actions.dashboard;
|
|||||||
|
|
||||||
import com.kingsrook.qqq.backend.core.actions.customizers.QCodeLoader;
|
import com.kingsrook.qqq.backend.core.actions.customizers.QCodeLoader;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Class for loading widget implementation code and rendering of widgets
|
** Class for loading widget implementation code and rendering of widgets
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class WidgetDataLoader
|
public class RenderWidgetAction
|
||||||
{
|
{
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public Object execute(QInstance qInstance, QSession session, String name) throws QException
|
public RenderWidgetOutput execute(RenderWidgetInput input) throws QException
|
||||||
{
|
{
|
||||||
QWidgetMetaDataInterface widget = qInstance.getWidget(name);
|
AbstractWidgetRenderer widgetRenderer = QCodeLoader.getAdHoc(AbstractWidgetRenderer.class, input.getWidgetMetaData().getCodeReference());
|
||||||
AbstractWidgetRenderer widgetRenderer = QCodeLoader.getAdHoc(AbstractWidgetRenderer.class, widget.getCodeReference());
|
return (widgetRenderer.render(input));
|
||||||
Object w = widgetRenderer.render(qInstance, session, widget);
|
|
||||||
return (widgetRenderer.render(qInstance, session, widget));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,171 @@
|
|||||||
|
/*
|
||||||
|
* 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.actions.widgets;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Input data container for the RenderWidget action
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public class RenderWidgetInput extends AbstractActionInput
|
||||||
|
{
|
||||||
|
private QSession session;
|
||||||
|
private QWidgetMetaDataInterface widgetMetaData;
|
||||||
|
private Map<String, String> queryParams;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public RenderWidgetInput(QInstance instance)
|
||||||
|
{
|
||||||
|
super(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for session
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public QSession getSession()
|
||||||
|
{
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for session
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setSession(QSession session)
|
||||||
|
{
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for session
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public RenderWidgetInput withSession(QSession session)
|
||||||
|
{
|
||||||
|
this.session = session;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for widgetMetaData
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public QWidgetMetaDataInterface getWidgetMetaData()
|
||||||
|
{
|
||||||
|
return widgetMetaData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for widgetMetaData
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setWidgetMetaData(QWidgetMetaDataInterface widgetMetaData)
|
||||||
|
{
|
||||||
|
this.widgetMetaData = widgetMetaData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for widgetMetaData
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public RenderWidgetInput withWidgetMetaData(QWidgetMetaDataInterface widgetMetaData)
|
||||||
|
{
|
||||||
|
this.widgetMetaData = widgetMetaData;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for urlParams
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public Map<String, String> getQueryParams()
|
||||||
|
{
|
||||||
|
return queryParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for urlParams
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setQueryParams(Map<String, String> queryParams)
|
||||||
|
{
|
||||||
|
this.queryParams = queryParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for urlParams
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public RenderWidgetInput withUrlParams(Map<String, String> urlParams)
|
||||||
|
{
|
||||||
|
this.queryParams = urlParams;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** adds a query param value
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public void addQueryParam(String name, String value)
|
||||||
|
{
|
||||||
|
if(this.queryParams == null)
|
||||||
|
{
|
||||||
|
this.queryParams = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.queryParams.put(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* 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.actions.widgets;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Output for an Export action
|
||||||
|
*******************************************************************************/
|
||||||
|
public class RenderWidgetOutput implements Serializable
|
||||||
|
{
|
||||||
|
public Object widgetData;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** constructor taking in widget data
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public RenderWidgetOutput(Object widgetData)
|
||||||
|
{
|
||||||
|
this.widgetData = widgetData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for widgetData
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public Object getWidgetData()
|
||||||
|
{
|
||||||
|
return widgetData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for widgetData
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setWidgetData(Object widgetData)
|
||||||
|
{
|
||||||
|
this.widgetData = widgetData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for widgetData
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public RenderWidgetOutput withWidgetData(Object widgetData)
|
||||||
|
{
|
||||||
|
this.widgetData = widgetData;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -229,6 +229,7 @@ public class TableData implements QWidget
|
|||||||
private String accessor;
|
private String accessor;
|
||||||
private String width;
|
private String width;
|
||||||
private String align;
|
private String align;
|
||||||
|
private String verticalAlign;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -413,5 +414,40 @@ public class TableData implements QWidget
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for verticalAlign
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public String getVerticalAlign()
|
||||||
|
{
|
||||||
|
return verticalAlign;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for verticalAlign
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setVerticalAlign(String verticalAlign)
|
||||||
|
{
|
||||||
|
this.verticalAlign = verticalAlign;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for verticalAlign
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public Column withVerticalAlign(String verticalAlign)
|
||||||
|
{
|
||||||
|
this.verticalAlign = verticalAlign;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class QWidgetMetaData implements QWidgetMetaDataInterface
|
public class QWidgetMetaData implements QWidgetMetaDataInterface
|
||||||
{
|
{
|
||||||
|
private String id;
|
||||||
protected String name;
|
protected String name;
|
||||||
protected QCodeReference codeReference;
|
protected QCodeReference codeReference;
|
||||||
|
|
||||||
@ -102,4 +103,38 @@ public class QWidgetMetaData implements QWidgetMetaDataInterface
|
|||||||
return (this);
|
return (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for id
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public String getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for id
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setId(String id)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for id
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public QWidgetMetaData withId(String id)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
|||||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QFieldSection;
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.QFieldSection;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -50,6 +51,8 @@ public class QFrontendTableMetaData
|
|||||||
private Map<String, QFrontendFieldMetaData> fields;
|
private Map<String, QFrontendFieldMetaData> fields;
|
||||||
private List<QFieldSection> sections;
|
private List<QFieldSection> sections;
|
||||||
|
|
||||||
|
private List<String> widgets;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
// do not add setters. take values from the source-object in the constructor!! //
|
// do not add setters. take values from the source-object in the constructor!! //
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -81,6 +84,11 @@ public class QFrontendTableMetaData
|
|||||||
{
|
{
|
||||||
this.iconName = tableMetaData.getIcon().getName();
|
this.iconName = tableMetaData.getIcon().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(CollectionUtils.nullSafeHasContents(tableMetaData.getWidgets()))
|
||||||
|
{
|
||||||
|
this.widgets = tableMetaData.getWidgets();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -159,4 +167,15 @@ public class QFrontendTableMetaData
|
|||||||
{
|
{
|
||||||
return iconName;
|
return iconName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for widgets
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public List<String> getWidgets()
|
||||||
|
{
|
||||||
|
return widgets;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,8 @@ public class QTableMetaData implements QAppChildMetaData, Serializable
|
|||||||
|
|
||||||
private List<QFieldSection> sections;
|
private List<QFieldSection> sections;
|
||||||
|
|
||||||
|
private List<String> widgets;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -715,4 +717,38 @@ public class QTableMetaData implements QAppChildMetaData, Serializable
|
|||||||
return (this);
|
return (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for widgets
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public List<String> getWidgets()
|
||||||
|
{
|
||||||
|
return widgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for widgets
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setWidgets(List<String> widgets)
|
||||||
|
{
|
||||||
|
this.widgets = widgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for widgets
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public QTableMetaData withWidgets(List<String> widgets)
|
||||||
|
{
|
||||||
|
this.widgets = widgets;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,9 @@ package com.kingsrook.qqq.backend.core.actions.dashboard;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -40,7 +39,7 @@ public class PersonsByCreateDateBarChart extends AbstractWidgetRenderer
|
|||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@Override
|
@Override
|
||||||
public Object render(QInstance qInstance, QSession session, QWidgetMetaDataInterface metaData) throws QException
|
public RenderWidgetOutput render(RenderWidgetInput input) throws QException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -62,7 +61,7 @@ public class PersonsByCreateDateBarChart extends AbstractWidgetRenderer
|
|||||||
labels.add("May 2022");
|
labels.add("May 2022");
|
||||||
data.add(64);
|
data.add(64);
|
||||||
|
|
||||||
return (new ChartData("Persons created per Month", null, "Person records", labels, data));
|
return (new RenderWidgetOutput(new ChartData("Persons created per Month", null, "Person records", labels, data)));
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
@ -24,8 +24,7 @@ package com.kingsrook.qqq.backend.core.actions.dashboard;
|
|||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData;
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QuickSightChartMetaData;
|
|
||||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
@ -43,7 +42,7 @@ class QuickSightChartRendererTest
|
|||||||
@Test
|
@Test
|
||||||
void testWrongMetaDataClass() throws QException
|
void testWrongMetaDataClass() throws QException
|
||||||
{
|
{
|
||||||
assertThatThrownBy(() -> new QuickSightChartRenderer().render(TestUtils.defineInstance(), TestUtils.getMockSession(), new QWidgetMetaData()))
|
assertThatThrownBy(() -> new QuickSightChartRenderer().render(new RenderWidgetInput(TestUtils.defineInstance())))
|
||||||
.hasRootCauseInstanceOf(ClassCastException.class);
|
.hasRootCauseInstanceOf(ClassCastException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ class QuickSightChartRendererTest
|
|||||||
@Test
|
@Test
|
||||||
void testNoCredentials() throws QException
|
void testNoCredentials() throws QException
|
||||||
{
|
{
|
||||||
assertThatThrownBy(() -> new QuickSightChartRenderer().render(TestUtils.defineInstance(), TestUtils.getMockSession(), new QuickSightChartMetaData()))
|
assertThatThrownBy(() -> new QuickSightChartRenderer().render(new RenderWidgetInput(TestUtils.defineInstance())))
|
||||||
.hasRootCauseInstanceOf(NullPointerException.class);
|
.hasRootCauseInstanceOf(NullPointerException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,13 +66,7 @@ class QuickSightChartRendererTest
|
|||||||
@Test
|
@Test
|
||||||
void testBadCredentials() throws QException
|
void testBadCredentials() throws QException
|
||||||
{
|
{
|
||||||
assertThatThrownBy(() -> new QuickSightChartRenderer().render(TestUtils.defineInstance(), TestUtils.getMockSession(),
|
assertThatThrownBy(() -> new QuickSightChartRenderer().render(new RenderWidgetInput(TestUtils.defineInstance())
|
||||||
new QuickSightChartMetaData()
|
|
||||||
.withName("test")
|
|
||||||
.withAccessKey("FAIL")
|
|
||||||
.withSecretKey("FAIL")
|
|
||||||
.withRegion("FAIL")
|
|
||||||
.withAccountId("FAIL")
|
|
||||||
)).hasRootCauseInstanceOf(UnknownHostException.class);
|
)).hasRootCauseInstanceOf(UnknownHostException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,10 @@ package com.kingsrook.qqq.backend.core.actions.dashboard;
|
|||||||
|
|
||||||
|
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@ -32,9 +35,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Unit test for WidgetDataLoader
|
** Unit test for RenderWidgetAction
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
class WidgetDataLoaderTest
|
class RenderWidgetActionTest
|
||||||
{
|
{
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
@ -42,9 +45,14 @@ class WidgetDataLoaderTest
|
|||||||
@Test
|
@Test
|
||||||
void test() throws QException
|
void test() throws QException
|
||||||
{
|
{
|
||||||
Object widgetData = new WidgetDataLoader().execute(TestUtils.defineInstance(), TestUtils.getMockSession(), PersonsByCreateDateBarChart.class.getSimpleName());
|
QInstance testQInstance = TestUtils.defineInstance();
|
||||||
assertThat(widgetData).isInstanceOf(ChartData.class);
|
RenderWidgetInput input = new RenderWidgetInput(testQInstance)
|
||||||
ChartData chartData = (ChartData) widgetData;
|
.withSession(TestUtils.getMockSession())
|
||||||
|
.withWidgetMetaData(testQInstance.getWidget(PersonsByCreateDateBarChart.class.getSimpleName()));
|
||||||
|
|
||||||
|
RenderWidgetOutput output = new RenderWidgetAction().execute(input);
|
||||||
|
assertThat(output.getWidgetData()).isInstanceOf(ChartData.class);
|
||||||
|
ChartData chartData = (ChartData) output.getWidgetData();
|
||||||
assertEquals("barChart", chartData.getType());
|
assertEquals("barChart", chartData.getType());
|
||||||
assertThat(chartData.getTitle()).isNotBlank();
|
assertThat(chartData.getTitle()).isNotBlank();
|
||||||
assertNotNull(chartData.getChartData());
|
assertNotNull(chartData.getChartData());
|
@ -36,7 +36,7 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import com.kingsrook.qqq.backend.core.actions.async.AsyncJobManager;
|
import com.kingsrook.qqq.backend.core.actions.async.AsyncJobManager;
|
||||||
import com.kingsrook.qqq.backend.core.actions.dashboard.WidgetDataLoader;
|
import com.kingsrook.qqq.backend.core.actions.dashboard.RenderWidgetAction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.metadata.MetaDataAction;
|
import com.kingsrook.qqq.backend.core.actions.metadata.MetaDataAction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.metadata.ProcessMetaDataAction;
|
import com.kingsrook.qqq.backend.core.actions.metadata.ProcessMetaDataAction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.metadata.TableMetaDataAction;
|
import com.kingsrook.qqq.backend.core.actions.metadata.TableMetaDataAction;
|
||||||
@ -76,6 +76,8 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
|
|||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateOutput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateOutput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
|
||||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
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.QInstance;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||||
@ -83,6 +85,7 @@ import com.kingsrook.qqq.backend.core.model.session.QSession;
|
|||||||
import com.kingsrook.qqq.backend.core.modules.authentication.Auth0AuthenticationModule;
|
import com.kingsrook.qqq.backend.core.modules.authentication.Auth0AuthenticationModule;
|
||||||
import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleDispatcher;
|
import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleDispatcher;
|
||||||
import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleInterface;
|
import com.kingsrook.qqq.backend.core.modules.authentication.QAuthenticationModuleInterface;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||||
import com.kingsrook.qqq.backend.core.utils.ExceptionUtils;
|
import com.kingsrook.qqq.backend.core.utils.ExceptionUtils;
|
||||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||||
@ -681,8 +684,25 @@ public class QJavalinImplementation
|
|||||||
InsertInput insertInput = new InsertInput(qInstance);
|
InsertInput insertInput = new InsertInput(qInstance);
|
||||||
setupSession(context, insertInput);
|
setupSession(context, insertInput);
|
||||||
|
|
||||||
Object widgetData = new WidgetDataLoader().execute(qInstance, insertInput.getSession(), context.pathParam("name"));
|
RenderWidgetInput input = new RenderWidgetInput(qInstance)
|
||||||
context.result(JsonUtils.toJson(widgetData));
|
.withSession(insertInput.getSession())
|
||||||
|
.withWidgetMetaData(qInstance.getWidget(context.pathParam("name")));
|
||||||
|
|
||||||
|
//////////////////////////
|
||||||
|
// process query string //
|
||||||
|
//////////////////////////
|
||||||
|
for(Map.Entry<String, List<String>> queryParam : context.queryParamMap().entrySet())
|
||||||
|
{
|
||||||
|
String fieldName = queryParam.getKey();
|
||||||
|
List<String> values = queryParam.getValue();
|
||||||
|
if(CollectionUtils.nullSafeHasContents(values))
|
||||||
|
{
|
||||||
|
input.addQueryParam(fieldName, values.get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderWidgetOutput output = new RenderWidgetAction().execute(input);
|
||||||
|
context.result(JsonUtils.toJson(output.getWidgetData()));
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
@ -26,10 +26,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.kingsrook.qqq.backend.core.actions.dashboard.AbstractWidgetRenderer;
|
import com.kingsrook.qqq.backend.core.actions.dashboard.AbstractWidgetRenderer;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -41,7 +39,7 @@ public class PersonsByCreateDateBarChart extends AbstractWidgetRenderer
|
|||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@Override
|
@Override
|
||||||
public Object render(QInstance qInstance, QSession session, QWidgetMetaDataInterface metaData) throws QException
|
public Object render(RenderWidgetInput input) throws QException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -26,10 +26,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.kingsrook.qqq.backend.core.actions.dashboard.AbstractWidgetRenderer;
|
import com.kingsrook.qqq.backend.core.actions.dashboard.AbstractWidgetRenderer;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||||
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
|
||||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -41,7 +39,7 @@ public class PersonsByCreateDateBarChart extends AbstractWidgetRenderer
|
|||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@Override
|
@Override
|
||||||
public Object render(QInstance qInstance, QSession session, QWidgetMetaDataInterface metaData) throws QException
|
public Object render(RenderWidgetInput input) throws QException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,6 @@ package com.kingsrook.sampleapp.dashboard.widgets;
|
|||||||
|
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
||||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
|
||||||
import com.kingsrook.sampleapp.SampleMetaDataProvider;
|
import com.kingsrook.sampleapp.SampleMetaDataProvider;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@ -44,7 +43,7 @@ class PersonsByCreateDateBarChartTest
|
|||||||
@Test
|
@Test
|
||||||
void test() throws QException
|
void test() throws QException
|
||||||
{
|
{
|
||||||
Object widgetData = new PersonsByCreateDateBarChart().render(SampleMetaDataProvider.defineInstance(), new QSession(), null);
|
Object widgetData = new PersonsByCreateDateBarChart().render(SampleMetaDataProvider.defineInstance());
|
||||||
assertThat(widgetData).isInstanceOf(ChartData.class);
|
assertThat(widgetData).isInstanceOf(ChartData.class);
|
||||||
ChartData chartData = (ChartData) widgetData;
|
ChartData chartData = (ChartData) widgetData;
|
||||||
assertEquals("barChart", chartData.getType());
|
assertEquals("barChart", chartData.getType());
|
||||||
|
Reference in New Issue
Block a user