Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Reintroduce allowedValueNames into allowed values constraint (#1166)

Rich Turnerfd78a1399360
diff --git a/model/src/main/java/org/openremote/model/value/ValueConstraint.java b/model/src/main/java/org/openremote/model/value/ValueConstraint.java
index 470717b4c..743874e98 100644
--- a/model/src/main/java/org/openremote/model/value/ValueConstraint.java
+++ b/model/src/main/java/org/openremote/model/value/ValueConstraint.java
@@ -349,9 +349,13 @@ public abstract class ValueConstraint implements Serializable {
@JsonTypeName("allowedValues")
public static class AllowedValues extends ValueConstraint {
Object[] allowedValues;
+ String[] allowedValueNames;
+
@JsonCreator
- protected AllowedValues() {
+ public AllowedValues(@JsonProperty("allowedValueNames") String[] allowedValueNames, @JsonProperty("allowedValues") Object[] allowedValues) {
super(ALLOWED_VALUES_MESSAGE_TEMPLATE);
+ this.allowedValueNames = allowedValueNames;
+ this.allowedValues = allowedValues;
}
public AllowedValues(Object...allowedValues) {
@@ -368,6 +372,10 @@ public abstract class ValueConstraint implements Serializable {
return Map.of("values", Arrays.toString(allowedValues));
}
+ public String[] getAllowedValueNames() {
+ return allowedValueNames;
+ }
+
@Override
public boolean evaluate(Object value, Instant now) {
if (value == null) {
diff --git a/ui/component/or-mwc-components/src/or-mwc-input.ts b/ui/component/or-mwc-components/src/or-mwc-input.ts
index 07d5844e6..6127f10d0 100644
--- a/ui/component/or-mwc-components/src/or-mwc-input.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-input.ts
@@ -346,7 +346,7 @@ export const getValueHolderInputTemplateProvider: ValueInputProviderGenerator =
pattern = ".+";
}
if (allowedValuesConstraint && allowedValuesConstraint.allowedValues) {
- const allowedLabels = allowedValuesConstraint.allowedValues;
+ const allowedLabels = allowedValuesConstraint.allowedValueNames && allowedValuesConstraint.allowedValueNames.length === allowedValuesConstraint.allowedValues.length ? allowedValuesConstraint.allowedValueNames : undefined;
selectOptions = allowedValuesConstraint.allowedValues.map((v, i) => {
let label = allowedLabels ? allowedLabels[i] : "" + v;
label = Util.getAllowedValueLabel(label)!;