mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 05:30:43 +00:00
Merge branch 'feature/QQQ-38-app-home-widgets' into feature/sprint-10
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
package com.kingsrook.qqq.backend.core.actions.dashboard;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.BarChart;
|
||||
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;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Sample bar chart widget
|
||||
*******************************************************************************/
|
||||
public class PersonsByCreateDateBarChart extends AbstractWidgetRenderer
|
||||
{
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public Object render(QInstance qInstance, QSession session, QWidgetMetaDataInterface metaData) throws QException
|
||||
{
|
||||
try
|
||||
{
|
||||
List<String> labels = new ArrayList<>();
|
||||
List<Number> data = new ArrayList<>();
|
||||
|
||||
labels.add("Jan. 2022");
|
||||
data.add(17);
|
||||
|
||||
labels.add("Feb. 2022");
|
||||
data.add(42);
|
||||
|
||||
labels.add("Mar. 2022");
|
||||
data.add(47);
|
||||
|
||||
labels.add("Apr. 2022");
|
||||
data.add(0);
|
||||
|
||||
labels.add("May 2022");
|
||||
data.add(64);
|
||||
|
||||
return (new BarChart("Persons created per Month", "Person records", labels, data));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw (new QException("Error rendering widget", e));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.kingsrook.qqq.backend.core.actions.dashboard;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.BarChart;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for WidgetDataLoader
|
||||
*******************************************************************************/
|
||||
class WidgetDataLoaderTest
|
||||
{
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void test() throws QException
|
||||
{
|
||||
Object widgetData = new WidgetDataLoader().execute(TestUtils.defineInstance(), TestUtils.getMockSession(), PersonsByCreateDateBarChart.class.getSimpleName());
|
||||
assertThat(widgetData).isInstanceOf(BarChart.class);
|
||||
BarChart barChart = (BarChart) widgetData;
|
||||
assertEquals("barChart", barChart.getType());
|
||||
assertThat(barChart.getTitle()).isNotBlank();
|
||||
assertNotNull(barChart.getBarChartData());
|
||||
}
|
||||
|
||||
}
|
@ -102,7 +102,7 @@ class QMetaDataVariableInterpreterTest
|
||||
QMetaDataVariableInterpreter secretReader = new QMetaDataVariableInterpreter();
|
||||
String key = "CUSTOM_PROPERTY";
|
||||
String value = "ABCD-9876";
|
||||
secretReader.setCustomEnvironment(Map.of(key, value));
|
||||
secretReader.setEnvironmentOverrides(Map.of(key, value));
|
||||
|
||||
assertNull(secretReader.interpret(null));
|
||||
assertEquals("foo", secretReader.interpret("foo"));
|
||||
@ -278,4 +278,4 @@ class QMetaDataVariableInterpreterTest
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.actions.automation.AutomationStatus;
|
||||
import com.kingsrook.qqq.backend.core.actions.automation.RecordAutomationHandler;
|
||||
import com.kingsrook.qqq.backend.core.actions.dashboard.PersonsByCreateDateBarChart;
|
||||
import com.kingsrook.qqq.backend.core.actions.processes.person.addtopeoplesage.AddAge;
|
||||
import com.kingsrook.qqq.backend.core.actions.processes.person.addtopeoplesage.GetAgeStatistics;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||
@ -52,6 +53,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.automation.QAutomationProvi
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeUsage;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData;
|
||||
@ -147,6 +149,7 @@ public class TestUtils
|
||||
|
||||
qInstance.addAutomationProvider(definePollingAutomationProvider());
|
||||
|
||||
defineWidgets(qInstance);
|
||||
defineApps(qInstance);
|
||||
|
||||
return (qInstance);
|
||||
@ -154,6 +157,19 @@ public class TestUtils
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static void defineWidgets(QInstance qInstance)
|
||||
{
|
||||
qInstance.addWidget(new QWidgetMetaData()
|
||||
.withName(PersonsByCreateDateBarChart.class.getSimpleName())
|
||||
.withCodeReference(new QCodeReference(PersonsByCreateDateBarChart.class, null)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@ -180,7 +196,8 @@ public class TestUtils
|
||||
.withName(APP_NAME_PEOPLE)
|
||||
.withChild(qInstance.getTable(TABLE_NAME_PERSON))
|
||||
.withChild(qInstance.getTable(TABLE_NAME_PERSON_FILE))
|
||||
.withChild(qInstance.getApp(APP_NAME_GREETINGS)));
|
||||
.withChild(qInstance.getApp(APP_NAME_GREETINGS))
|
||||
.withWidgets(List.of(PersonsByCreateDateBarChart.class.getSimpleName())));
|
||||
|
||||
qInstance.addApp(new QAppMetaData()
|
||||
.withName(APP_NAME_MISCELLANEOUS)
|
||||
|
Reference in New Issue
Block a user