From 8a1110abf0f0466e9310576ae947bab38e088d68 Mon Sep 17 00:00:00 2001 From: Tim Chamberlain Date: Thu, 29 Sep 2022 12:04:24 -0500 Subject: [PATCH] SPRINT-12: added stepper widget, added linkability to table widget --- .../dashboard/AbstractWidgetRenderer.java | 2 +- .../model/dashboard/widgets/StepperData.java | 302 ++++++++++++++++++ .../model/dashboard/widgets/TableData.java | 70 ++++ .../qqq/backend/core/utils/ValueUtils.java | 44 +++ 4 files changed, 417 insertions(+), 1 deletion(-) create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/StepperData.java diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/dashboard/AbstractWidgetRenderer.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/dashboard/AbstractWidgetRenderer.java index 2dd99c16..793c2e9a 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/dashboard/AbstractWidgetRenderer.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/dashboard/AbstractWidgetRenderer.java @@ -37,7 +37,7 @@ import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput; 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 dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd h:mma").withZone(ZoneId.systemDefault()); public static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()); diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/StepperData.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/StepperData.java new file mode 100644 index 00000000..ae894a20 --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/StepperData.java @@ -0,0 +1,302 @@ +/* + * 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 . + */ + +package com.kingsrook.qqq.backend.core.model.dashboard.widgets; + + +import java.util.List; + + +/******************************************************************************* + ** Model containing datastructure expected by frontend stepper widget + ** + *******************************************************************************/ +public class StepperData implements QWidget +{ + private String title; + private int activeStep; + private List steps; + + + + /******************************************************************************* + ** + *******************************************************************************/ + public StepperData(String title, int activeStep, List steps) + { + this.title = title; + this.activeStep = activeStep; + this.steps = steps; + } + + + + /******************************************************************************* + ** Getter for type + ** + *******************************************************************************/ + public String getType() + { + return "stepper"; + } + + + + /******************************************************************************* + ** Getter for title + ** + *******************************************************************************/ + public String getTitle() + { + return title; + } + + + + /******************************************************************************* + ** Setter for title + ** + *******************************************************************************/ + public void setTitle(String title) + { + this.title = title; + } + + + + /******************************************************************************* + ** Fluent setter for title + ** + *******************************************************************************/ + public StepperData withTitle(String title) + { + this.title = title; + return (this); + } + + + + /******************************************************************************* + ** Getter for activeStep + ** + *******************************************************************************/ + public int getActiveStep() + { + return activeStep; + } + + + + /******************************************************************************* + ** Setter for activeStep + ** + *******************************************************************************/ + public void setActiveStep(int activeStep) + { + this.activeStep = activeStep; + } + + + + /******************************************************************************* + ** Fluent setter for activeStep + ** + *******************************************************************************/ + public StepperData withActiveStep(int activeStep) + { + this.activeStep = activeStep; + return (this); + } + + + + /******************************************************************************* + ** Getter for steps + ** + *******************************************************************************/ + public List getSteps() + { + return steps; + } + + + + /******************************************************************************* + ** Setter for steps + ** + *******************************************************************************/ + public void setSteps(List steps) + { + this.steps = steps; + } + + + + /******************************************************************************* + ** Fluent setter for steps + ** + *******************************************************************************/ + public StepperData withSteps(List steps) + { + this.steps = steps; + return (this); + } + + + + /******************************************************************************* + ** + *******************************************************************************/ + public static class Step + { + private String label; + private String linkText; + private String linkURL; + + + + /******************************************************************************* + ** + *******************************************************************************/ + public Step() + { + this.label = label; + this.linkText = linkText; + this.linkURL = linkURL; + } + + + + /******************************************************************************* + ** + *******************************************************************************/ + public Step(String label, String linkText, String linkURL) + { + this.label = label; + this.linkText = linkText; + this.linkURL = linkURL; + } + + + + /******************************************************************************* + ** Getter for label + ** + *******************************************************************************/ + public String getLabel() + { + return label; + } + + + + /******************************************************************************* + ** Setter for label + ** + *******************************************************************************/ + public void setLabel(String label) + { + this.label = label; + } + + + + /******************************************************************************* + ** Fluent setter for label + ** + *******************************************************************************/ + public Step withLabel(String label) + { + this.label = label; + return (this); + } + + + + /******************************************************************************* + ** Getter for linkText + ** + *******************************************************************************/ + public String getLinkText() + { + return linkText; + } + + + + /******************************************************************************* + ** Setter for linkText + ** + *******************************************************************************/ + public void setLinkText(String linkText) + { + this.linkText = linkText; + } + + + + /******************************************************************************* + ** Fluent setter for linkText + ** + *******************************************************************************/ + public Step withLinkText(String linkText) + { + this.linkText = linkText; + return (this); + } + + + + /******************************************************************************* + ** Getter for linkURL + ** + *******************************************************************************/ + public String getLinkURL() + { + return linkURL; + } + + + + /******************************************************************************* + ** Setter for linkURL + ** + *******************************************************************************/ + public void setLinkURL(String linkURL) + { + this.linkURL = linkURL; + } + + + + /******************************************************************************* + ** Fluent setter for linkURL + ** + *******************************************************************************/ + public Step withLinkURL(String linkURL) + { + this.linkURL = linkURL; + return (this); + } + + } + +} diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/TableData.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/TableData.java index aa4fdf3b..f04517b2 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/TableData.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/TableData.java @@ -33,6 +33,8 @@ import java.util.Map; public class TableData implements QWidget { private String title; + private String linkText; + private String linkURL; private String noRowsFoundHTML; private List columns; private List> rows; @@ -234,6 +236,74 @@ public class TableData implements QWidget + /******************************************************************************* + ** Getter for linkText + ** + *******************************************************************************/ + public String getLinkText() + { + return linkText; + } + + + + /******************************************************************************* + ** Setter for linkText + ** + *******************************************************************************/ + public void setLinkText(String linkText) + { + this.linkText = linkText; + } + + + + /******************************************************************************* + ** Fluent setter for linkText + ** + *******************************************************************************/ + public TableData withLinkText(String linkText) + { + this.linkText = linkText; + return (this); + } + + + + /******************************************************************************* + ** Getter for linkURL + ** + *******************************************************************************/ + public String getLinkURL() + { + return linkURL; + } + + + + /******************************************************************************* + ** Setter for linkURL + ** + *******************************************************************************/ + public void setLinkURL(String linkURL) + { + this.linkURL = linkURL; + } + + + + /******************************************************************************* + ** Fluent setter for linkURL + ** + *******************************************************************************/ + public TableData withLinkURL(String linkURL) + { + this.linkURL = linkURL; + return (this); + } + + + /******************************************************************************* ** *******************************************************************************/ diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/ValueUtils.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/ValueUtils.java index 0ce8c4ab..e91ef363 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/ValueUtils.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/ValueUtils.java @@ -201,6 +201,50 @@ public class ValueUtils + /******************************************************************************* + ** Type-safely make a LocalDateTime from any Object. + ** null and empty-string inputs return null. + ** We may throw if the input can't be converted to a LocalDateTime + *******************************************************************************/ + public static LocalDateTime getValueAsLocalDateTime(Object value) throws QValueException + { + try + { + if(value == null) + { + return (null); + } + else if(value instanceof LocalDateTime ldt) + { + return (ldt); + } + else if(value instanceof java.sql.Timestamp ts) + { + return ts.toLocalDateTime(); + } + else if(value instanceof Calendar c) + { + TimeZone tz = c.getTimeZone(); + ZoneId zid = (tz == null) ? ZoneId.systemDefault() : tz.toZoneId(); + return LocalDateTime.ofInstant(c.toInstant(), zid); + } + else + { + throw (new QValueException("Unsupported class " + value.getClass().getName() + " for converting to LocalDateTime.")); + } + } + catch(QValueException qve) + { + throw (qve); + } + catch(Exception e) + { + throw (new QValueException("Value [" + value + "] could not be converted to a LocalDateTime.", e)); + } + } + + + /******************************************************************************* ** Type-safely make a LocalDate from any Object. ** null and empty-string inputs return null.