From 0641ac41d601ffeaa8b301a99f0210f798a0c35a Mon Sep 17 00:00:00 2001 From: Tim Chamberlain Date: Fri, 12 Apr 2024 15:28:33 -0500 Subject: [PATCH] CE-1107: added alert widget type and datepicker dropdown type --- .../widgets/AbstractWidgetRenderer.java | 147 ++++++++++-------- .../model/dashboard/widgets/AlertData.java | 139 +++++++++++++++++ .../model/dashboard/widgets/WidgetType.java | 1 + .../dashboard/WidgetDropdownData.java | 65 ++++++++ .../dashboard/WidgetDropdownType.java | 33 ++++ 5 files changed, 324 insertions(+), 61 deletions(-) create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/AlertData.java create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/dashboard/WidgetDropdownType.java diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/dashboard/widgets/AbstractWidgetRenderer.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/dashboard/widgets/AbstractWidgetRenderer.java index 2afb5f69..2bb15cfc 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/dashboard/widgets/AbstractWidgetRenderer.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/dashboard/widgets/AbstractWidgetRenderer.java @@ -42,6 +42,7 @@ import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput; import com.kingsrook.qqq.backend.core.model.dashboard.widgets.QWidgetData; import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData; import com.kingsrook.qqq.backend.core.model.metadata.dashboard.WidgetDropdownData; +import com.kingsrook.qqq.backend.core.model.metadata.dashboard.WidgetDropdownType; import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValue; import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSource; import com.kingsrook.qqq.backend.core.utils.CollectionUtils; @@ -72,80 +73,104 @@ public abstract class AbstractWidgetRenderer *******************************************************************************/ protected boolean setupDropdowns(RenderWidgetInput input, QWidgetMetaData metaData, QWidgetData widgetData) throws QException { - List>> pvsData = new ArrayList<>(); - List pvsLabels = new ArrayList<>(); - List pvsNames = new ArrayList<>(); + List>> dataList = new ArrayList<>(); + List labelList = new ArrayList<>(); + List nameList = new ArrayList<>(); List missingRequiredSelections = new ArrayList<>(); for(WidgetDropdownData dropdownData : CollectionUtils.nonNullList(metaData.getDropdowns())) { - String possibleValueSourceName = dropdownData.getPossibleValueSourceName(); - QPossibleValueSource possibleValueSource = input.getInstance().getPossibleValueSource(possibleValueSourceName); - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // this looks complicated, but is just look for a label in the dropdown data and if found use it, // - // otherwise look for label in PVS and if found use that, otherwise just use the PVS name // - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - String pvsLabel = dropdownData.getLabel() != null ? dropdownData.getLabel() : (possibleValueSource.getLabel() != null ? possibleValueSource.getLabel() : possibleValueSourceName); - pvsLabels.add(pvsLabel); - pvsNames.add(possibleValueSourceName); - - SearchPossibleValueSourceInput pvsInput = new SearchPossibleValueSourceInput(); - pvsInput.setPossibleValueSourceName(possibleValueSourceName); - - if(dropdownData.getForeignKeyFieldName() != null) + if(WidgetDropdownType.DATE_PICKER.equals(dropdownData.getType())) { - //////////////////////////////////////// - // look for an id in the query params // - //////////////////////////////////////// - Integer id = null; - if(input.getQueryParams() != null && input.getQueryParams().containsKey("id") && StringUtils.hasContent(input.getQueryParams().get("id"))) + String name = dropdownData.getName(); + nameList.add(name); + labelList.add(dropdownData.getLabel()); + dataList.add(new ArrayList<>()); + + //////////////////////////////////////////////////////////////////////////////////////////////////////////// + // sure that something has been selected, and if not, display a message that a selection needs made // + //////////////////////////////////////////////////////////////////////////////////////////////////////////// + if(dropdownData.getIsRequired()) { - id = Integer.parseInt(input.getQueryParams().get("id")); - } - if(id != null) - { - pvsInput.setDefaultQueryFilter(new QQueryFilter().withCriteria( - new QFilterCriteria( - dropdownData.getForeignKeyFieldName(), - QCriteriaOperator.EQUALS, - id))); + if(!input.getQueryParams().containsKey(name) || !StringUtils.hasContent(input.getQueryParams().get(name))) + { + missingRequiredSelections.add(dropdownData.getLabel()); + } } } - - SearchPossibleValueSourceOutput output = new SearchPossibleValueSourceAction().execute(pvsInput); - - List> dropdownOptionList = new ArrayList<>(); - pvsData.add(dropdownOptionList); - - ////////////////////////////////////////// - // sort results, dedupe, and add to map // - ////////////////////////////////////////// - Set exists = new HashSet<>(); - output.getResults().removeIf(pvs -> !exists.add(pvs.getLabel())); - for(QPossibleValue possibleValue : output.getResults()) + else { - dropdownOptionList.add(MapBuilder.of( - "id", String.valueOf(possibleValue.getId()), - "label", possibleValue.getLabel() - )); - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////// - // because we know the dropdowns and what the field names will be when something is selected, we can make // - // sure that something has been selected, and if not, display a message that a selection needs made // - //////////////////////////////////////////////////////////////////////////////////////////////////////////// - if(dropdownData.getIsRequired()) - { - if(!input.getQueryParams().containsKey(possibleValueSourceName) || !StringUtils.hasContent(input.getQueryParams().get(possibleValueSourceName))) + String possibleValueSourceName = dropdownData.getPossibleValueSourceName(); + if(possibleValueSourceName != null) { - missingRequiredSelections.add(pvsLabel); + QPossibleValueSource possibleValueSource = input.getInstance().getPossibleValueSource(possibleValueSourceName); + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // this looks complicated, but is just look for a label in the dropdown data and if found use it, // + // otherwise look for label in PVS and if found use that, otherwise just use the PVS name // + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + String pvsLabel = dropdownData.getLabel() != null ? dropdownData.getLabel() : (possibleValueSource.getLabel() != null ? possibleValueSource.getLabel() : possibleValueSourceName); + labelList.add(pvsLabel); + nameList.add(possibleValueSourceName); + + SearchPossibleValueSourceInput pvsInput = new SearchPossibleValueSourceInput(); + pvsInput.setPossibleValueSourceName(possibleValueSourceName); + + if(dropdownData.getForeignKeyFieldName() != null) + { + //////////////////////////////////////// + // look for an id in the query params // + //////////////////////////////////////// + Integer id = null; + if(input.getQueryParams() != null && input.getQueryParams().containsKey("id") && StringUtils.hasContent(input.getQueryParams().get("id"))) + { + id = Integer.parseInt(input.getQueryParams().get("id")); + } + if(id != null) + { + pvsInput.setDefaultQueryFilter(new QQueryFilter().withCriteria( + new QFilterCriteria( + dropdownData.getForeignKeyFieldName(), + QCriteriaOperator.EQUALS, + id))); + } + } + + SearchPossibleValueSourceOutput output = new SearchPossibleValueSourceAction().execute(pvsInput); + + List> dropdownOptionList = new ArrayList<>(); + dataList.add(dropdownOptionList); + + ////////////////////////////////////////// + // sort results, dedupe, and add to map // + ////////////////////////////////////////// + Set exists = new HashSet<>(); + output.getResults().removeIf(pvs -> !exists.add(pvs.getLabel())); + for(QPossibleValue possibleValue : output.getResults()) + { + dropdownOptionList.add(MapBuilder.of( + "id", String.valueOf(possibleValue.getId()), + "label", possibleValue.getLabel() + )); + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////// + // because we know the dropdowns and what the field names will be when something is selected, we can make // + // sure that something has been selected, and if not, display a message that a selection needs made // + //////////////////////////////////////////////////////////////////////////////////////////////////////////// + if(dropdownData.getIsRequired()) + { + if(!input.getQueryParams().containsKey(possibleValueSourceName) || !StringUtils.hasContent(input.getQueryParams().get(possibleValueSourceName))) + { + missingRequiredSelections.add(pvsLabel); + } + } } } } - widgetData.setDropdownNameList(pvsNames); - widgetData.setDropdownLabelList(pvsLabels); - widgetData.setDropdownDataList(pvsData); + widgetData.setDropdownNameList(nameList); + widgetData.setDropdownLabelList(labelList); + widgetData.setDropdownDataList(dataList); //////////////////////////////////////////////////////////////////////////////// // if there are any missing required dropdowns, build up a message to display // diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/AlertData.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/AlertData.java new file mode 100644 index 00000000..28b60929 --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/AlertData.java @@ -0,0 +1,139 @@ +/* + * 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; + + +/******************************************************************************* + ** Model containing datastructure expected by frontend alert widget + ** + *******************************************************************************/ +public class AlertData extends QWidgetData +{ + public enum AlertType + { + ERROR, + SUCCESS, + WARNING + } + + + + private String html; + private AlertType alertType; + + + + /******************************************************************************* + ** + *******************************************************************************/ + public AlertData() + { + } + + + + /******************************************************************************* + ** + *******************************************************************************/ + public AlertData(AlertType alertType, String html) + { + setHtml(html); + setAlertType(alertType); + } + + + + /******************************************************************************* + ** Getter for type + ** + *******************************************************************************/ + public String getType() + { + return WidgetType.ALERT.getType(); + } + + + + /******************************************************************************* + ** Getter for html + ** + *******************************************************************************/ + public String getHtml() + { + return html; + } + + + + /******************************************************************************* + ** Setter for html + ** + *******************************************************************************/ + public void setHtml(String html) + { + this.html = html; + } + + + + /******************************************************************************* + ** Fluent setter for html + ** + *******************************************************************************/ + public AlertData withHtml(String html) + { + this.html = html; + return (this); + } + + + + /******************************************************************************* + ** Getter for alertType + *******************************************************************************/ + public AlertType getAlertType() + { + return (this.alertType); + } + + + + /******************************************************************************* + ** Setter for alertType + *******************************************************************************/ + public void setAlertType(AlertType alertType) + { + this.alertType = alertType; + } + + + + /******************************************************************************* + ** Fluent setter for alertType + *******************************************************************************/ + public AlertData withAlertType(AlertType alertType) + { + this.alertType = alertType; + return (this); + } + +} diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/WidgetType.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/WidgetType.java index 421164a5..9a2a453e 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/WidgetType.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/dashboard/widgets/WidgetType.java @@ -27,6 +27,7 @@ package com.kingsrook.qqq.backend.core.model.dashboard.widgets; *******************************************************************************/ public enum WidgetType { + ALERT("alert"), BAR_CHART("barChart"), CHART("chart"), CHILD_RECORD_LIST("childRecordList"), diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/dashboard/WidgetDropdownData.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/dashboard/WidgetDropdownData.java index d5446dea..37bd9d23 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/dashboard/WidgetDropdownData.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/dashboard/WidgetDropdownData.java @@ -28,6 +28,7 @@ package com.kingsrook.qqq.backend.core.model.metadata.dashboard; *******************************************************************************/ public class WidgetDropdownData { + private String name; private String possibleValueSourceName; private String foreignKeyFieldName; private String label; @@ -44,6 +45,9 @@ public class WidgetDropdownData //////////////////////////////////////////////////////////////////////////////////////////////// private String labelForNullValue; + private WidgetDropdownType type = WidgetDropdownType.POSSIBLE_VALUE_SOURCE; + + /******************************************************************************* ** Getter for possibleValueSourceName @@ -366,4 +370,65 @@ public class WidgetDropdownData } + + /******************************************************************************* + ** Getter for type + *******************************************************************************/ + public WidgetDropdownType getType() + { + return (this.type); + } + + + + /******************************************************************************* + ** Setter for type + *******************************************************************************/ + public void setType(WidgetDropdownType type) + { + this.type = type; + } + + + + /******************************************************************************* + ** Fluent setter for type + *******************************************************************************/ + public WidgetDropdownData withType(WidgetDropdownType type) + { + this.type = type; + return (this); + } + + + + /******************************************************************************* + ** Getter for name + *******************************************************************************/ + public String getName() + { + return (this.name); + } + + + + /******************************************************************************* + ** Setter for name + *******************************************************************************/ + public void setName(String name) + { + this.name = name; + } + + + + /******************************************************************************* + ** Fluent setter for name + *******************************************************************************/ + public WidgetDropdownData withName(String name) + { + this.name = name; + return (this); + } + } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/dashboard/WidgetDropdownType.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/dashboard/WidgetDropdownType.java new file mode 100644 index 00000000..be47959f --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/dashboard/WidgetDropdownType.java @@ -0,0 +1,33 @@ +/* + * 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.metadata.dashboard; + + +/******************************************************************************* + ** Possible types for widget dropdowns + ** + *******************************************************************************/ +public enum WidgetDropdownType +{ + POSSIBLE_VALUE_SOURCE, + DATE_PICKER +}