Skip to content

armgit / core

Public Imported from GitHub
0

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

UI updates for json forms and also backend schema generation updates

Rich Turner02527db5e5a2
diff --git a/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketHTTPSubscription.java b/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketHTTPSubscription.java
index 4dbd738b5..66004d3cc 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketHTTPSubscription.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketHTTPSubscription.java
@@ -19,9 +19,13 @@
*/
package org.openremote.agent.protocol.websocket;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import org.openremote.model.value.ValueType;
+
import java.util.List;
import java.util.Map;
+@JsonTypeName(WebsocketHTTPSubscription.TYPE)
public class WebsocketHTTPSubscription extends WebsocketSubscription {
public enum Method {
@@ -38,7 +42,6 @@ public class WebsocketHTTPSubscription extends WebsocketSubscription {
public String uri;
public WebsocketHTTPSubscription() {
- super(TYPE);
}
public WebsocketHTTPSubscription method(Method method) {
@@ -51,7 +54,7 @@ public class WebsocketHTTPSubscription extends WebsocketSubscription {
return this;
}
- public WebsocketHTTPSubscription headers(Map<String, List<String>> headers) {
+ public WebsocketHTTPSubscription headers(ValueType.MultivaluedStringMap headers) {
this.headers = headers;
return this;
}
@@ -61,6 +64,11 @@ public class WebsocketHTTPSubscription extends WebsocketSubscription {
return this;
}
+ public WebsocketHTTPSubscription body(Object body) {
+ super.body(body);
+ return this;
+ }
+
@Override
public String toString() {
return WebsocketHTTPSubscription.class.getSimpleName() + "{" +
diff --git a/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketSubscription.java b/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketSubscription.java
index 8b4a8fd65..d4a2ae639 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketSubscription.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketSubscription.java
@@ -25,28 +25,18 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
import java.io.Serializable;
@JsonSubTypes({
- @JsonSubTypes.Type(value = WebsocketSubscription.class, name = WebsocketSubscription.TYPE),
+ @JsonSubTypes.Type(value = WebsocketSubscriptionImpl.class, name = WebsocketSubscriptionImpl.TYPE),
@JsonSubTypes.Type(value = WebsocketHTTPSubscription.class, name = WebsocketHTTPSubscription.TYPE)
})
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type",
- defaultImpl = WebsocketSubscription.class
+ defaultImpl = WebsocketSubscriptionImpl.class
)
-public class WebsocketSubscription implements Serializable {
+public abstract class WebsocketSubscription implements Serializable {
- public static final String TYPE = "websocket";
-
- public String type = TYPE;
public Object body;
- public WebsocketSubscription() {
- }
-
- protected WebsocketSubscription(String type) {
- this.type = type;
- }
-
public WebsocketSubscription body(Object body) {
this.body = body;
return this;
diff --git a/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketSubscriptionImpl.java b/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketSubscriptionImpl.java
new file mode 100644
index 000000000..fec9aff84
--- /dev/null
+++ b/agent/src/main/java/org/openremote/agent/protocol/websocket/WebsocketSubscriptionImpl.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2019, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.agent.protocol.websocket;
+
+import com.fasterxml.jackson.annotation.JsonTypeName;
+
+// This is just here because json schema doesn't support self references for types
+@JsonTypeName(WebsocketSubscriptionImpl.TYPE)
+public class WebsocketSubscriptionImpl extends WebsocketSubscription {
+
+ public static final String TYPE = "websocket";
+
+ public WebsocketSubscriptionImpl() {
+ }
+
+ public WebsocketSubscriptionImpl body(Object body) {
+ super.body(body);
+ return this;
+ }
+}
diff --git a/manager/src/web/shared/locales/en/or.json b/manager/src/web/shared/locales/en/or.json
index 43f90681b..8bae30c9c 100644
--- a/manager/src/web/shared/locales/en/or.json
+++ b/manager/src/web/shared/locales/en/or.json
@@ -409,5 +409,10 @@
"loadFailedUsers": "Failed to load users",
"loadFailedServiceUsers": "Failed to load service users",
"key": "Key",
- "anyOfPickerLabel": "{{label}} type"
+ "anyOfPickerLabel": "{{label}} type",
+ "validation": {
+ "invalidNumber": "Invalid number",
+ "invalidJSON": "Invalid JSON",
+ "invalidDate": "Invalid date"
+ }
}
diff --git a/model/build.gradle b/model/build.gradle
index f1defe128..977690f02 100644
--- a/model/build.gradle
+++ b/model/build.gradle
@@ -30,10 +30,7 @@ dependencies {
compile "io.swagger.core.v3:swagger-annotations:$swaggerVersion"
- compile "com.github.victools:jsonschema-generator:$jsonSchemaVersion"
- compile "com.github.victools:jsonschema-module-jackson:$jsonSchemaVersion"
- compile "com.github.victools:jsonschema-module-swagger-2:$jsonSchemaVersion"
- compile "com.github.victools:jsonschema-module-javax-validation:$jsonSchemaVersion"
+ compile "com.kjetland:mbknor-jackson-jsonschema_2.12:1.0.39"
}
jar {
diff --git a/model/src/main/java/org/openremote/model/asset/agent/AgentLink.java b/model/src/main/java/org/openremote/model/asset/agent/AgentLink.java
index cdbb4e1df..a94a1e44f 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/AgentLink.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/AgentLink.java
@@ -23,11 +23,13 @@ import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import io.swagger.v3.oas.annotations.media.Schema;
+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaFormat;
+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject;
import org.openremote.model.attribute.Attribute;
import org.openremote.model.query.filter.ValuePredicate;
-import org.openremote.model.value.ValueFilter;
+import org.openremote.model.util.JSONSchemaUtil;
import org.openremote.model.util.ValueUtil;
+import org.openremote.model.value.ValueFilter;
import java.io.Serializable;
import java.util.Optional;
@@ -40,10 +42,12 @@ import java.util.Optional;
@JsonTypeInfo(property = "type", use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, defaultImpl = DefaultAgentLink.class)
public abstract class AgentLink<T extends AgentLink<?>> implements Serializable {
- @Schema(format = "or-agent-id")
+ @JsonSchemaFormat("or-agent-id")
protected String id;
protected ValueFilter[] valueFilters;
+ @JsonSchemaInject(merge = false, jsonSupplierViaLookup = JSONSchemaUtil.SCHEMA_SUPPLIER_NAME_PATTERN_PROPERTIES_ANY_KEY_ANY_TYPE)
protected ObjectNode valueConverter;
+ @JsonSchemaInject(merge = false, jsonSupplierViaLookup = JSONSchemaUtil.SCHEMA_SUPPLIER_NAME_PATTERN_PROPERTIES_ANY_KEY_ANY_TYPE)
protected ObjectNode writeValueConverter;
protected String writeValue;
protected ValuePredicate messageMatchPredicate;
diff --git a/model/src/main/java/org/openremote/model/util/JSONSchemaUtil.java b/model/src/main/java/org/openremote/model/util/JSONSchemaUtil.java
new file mode 100644
index 000000000..e32222cd6
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/util/JSONSchemaUtil.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2021, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.model.util;
+
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.databind.node.TextNode;
+import com.kjetland.jackson.jsonSchema.JsonSchemaConfig;
+import com.kjetland.jackson.jsonSchema.JsonSchemaDraft;
+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Optional;
+import java.util.function.Supplier;
+
+public class JSONSchemaUtil {
+
+ @JsonSchemaInject(jsonSupplierViaLookup = JSONSchemaUtil.SCHEMA_SUPPLIER_NAME_PATTERN_PROPERTIES_ANY_KEY_ANY_TYPE)
+ static class PatternPropertiesAnyKeyAnyType {}
+ @JsonSchemaInject(jsonSupplierViaLookup = JSONSchemaUtil.SCHEMA_SUPPLIER_NAME_PATTERN_PROPERTIES_SIMPLE_KEY_ANY_TYPE)
+ static class PatternPropertiesSimpleKeyAnyType {}
+ @JsonSchemaInject(jsonSupplierViaLookup = JSONSchemaUtil.SCHEMA_SUPPLIER_NAME_ANY_TYPE)
+ static class AnyType {}
+
+ private JSONSchemaUtil() {}
+
+ public static final String SCHEMA_SUPPLIER_NAME_ANY_TYPE = "anyType";
+ public static final String SCHEMA_SUPPLIER_NAME_PATTERN_PROPERTIES_ANY_KEY_ANY_TYPE = "patternPropertiesAnyKeyAnyType";
+ public static final String SCHEMA_SUPPLIER_NAME_PATTERN_PROPERTIES_SIMPLE_KEY_ANY_TYPE = "patternPropertiesSimpleKeyAnyType";
+ public static final String PATTERN_PROPERTIES_MATCH_ANY = ".+";
+ public static final String PATTERN_PROPERTIES_MATCH_SIMPLE = "^[a-zA-Z][a-zA-Z0-9]*";
+ public static final String TYPE_NULL = "null";
+ public static final String TYPE_NUMBER = "number";
+ public static final String TYPE_INTEGER = "integer";
+ public static final String TYPE_BOOLEAN = "boolean";
+ public static final String TYPE_STRING = "string";
+ public static final String TYPE_ARRAY = "array";
+ public static final String TYPE_OBJECT = "object";
+ public static final String[] TYPES_ALL = new String[]{
+ TYPE_NULL,
+ TYPE_NUMBER,
+ TYPE_INTEGER,
+ TYPE_BOOLEAN,
+ TYPE_STRING,
+ TYPE_ARRAY,
+ TYPE_OBJECT
+ };
+
+ public static JsonNode getSchemaPatternPropertiesAnyKeyAnyType() {
+ return getSchemaPatternProperties(PATTERN_PROPERTIES_MATCH_ANY, TYPES_ALL);
+ }
+
+ public static JsonNode getSchemaPatternPropertiesSimpleKeyAnyType() {
+ return getSchemaPatternProperties(PATTERN_PROPERTIES_MATCH_SIMPLE, TYPES_ALL);
+ }
+
+ public static JsonNode getSchemaPatternPropertiesAnyType(String keyPattern) {
+ return getSchemaPatternProperties(keyPattern, TYPES_ALL);
+ }
+
+ public static JsonNode getSchemaPatternProperties(String keyPattern, String...types) {
+ ObjectNode node = ValueUtil.JSON.createObjectNode();
+ node.put("type", "object");
+ ObjectNode patternNode = node.putObject("patternProperties").putObject(keyPattern);
+ patternNode.set("type", getSchemaType(false, types));
+ return node;
+ }
+
+ public static JsonNode getSchemaType(boolean wrapped, String...types) {
+ JsonNode typesNode;
+
+ if (types.length == 1) {
+ typesNode = new TextNode(types[0]);
+ } else {
+ ArrayNode arrNode = ValueUtil.JSON.createArrayNode();
+ Arrays.stream(types).forEach(arrNode::add);
+ typesNode = arrNode;
+ }
+
+ return wrapped ? ValueUtil.JSON.createObjectNode().set("types", typesNode) : typesNode;
+ }
+
+ public static JsonSchemaConfig getJsonSchemaConfig() {
+ return JsonSchemaConfig.create(
+ false,
+ Optional.empty(),
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ Collections.emptyMap(),
+ false,
+ Collections.emptySet(),
+ new HashMap<Class<?>, Class<?>>(){{
+ put(Object.class, PatternPropertiesSimpleKeyAnyType.class);
+ put(ObjectNode.class, PatternPropertiesSimpleKeyAnyType.class);
+ }},
+ new HashMap<String, Supplier<JsonNode>>() {{
+ put(SCHEMA_SUPPLIER_NAME_ANY_TYPE, () -> getSchemaType(true, TYPES_ALL));
+ put(SCHEMA_SUPPLIER_NAME_PATTERN_PROPERTIES_ANY_KEY_ANY_TYPE, JSONSchemaUtil::getSchemaPatternPropertiesAnyKeyAnyType);
+ put(SCHEMA_SUPPLIER_NAME_PATTERN_PROPERTIES_SIMPLE_KEY_ANY_TYPE, JSONSchemaUtil::getSchemaPatternPropertiesSimpleKeyAnyType);
+ }},
+ null,
+ false,
+ null
+ ).withJsonSchemaDraft(JsonSchemaDraft.DRAFT_07);
+ }
+}
diff --git a/model/src/main/java/org/openremote/model/util/ValueUtil.java b/model/src/main/java/org/openremote/model/util/ValueUtil.java
index 490160a4a..4128c00e9 100644
--- a/model/src/main/java/org/openremote/model/util/ValueUtil.java
+++ b/model/src/main/java/org/openremote/model/util/ValueUtil.java
@@ -28,10 +28,11 @@ import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
-import com.github.victools.jsonschema.generator.*;
-import com.github.victools.jsonschema.module.jackson.JacksonModule;
-import com.github.victools.jsonschema.module.jackson.JacksonOption;
-import com.github.victools.jsonschema.module.swagger2.Swagger2Module;
+import com.kjetland.jackson.jsonSchema.JsonSchemaConfig;
+import com.kjetland.jackson.jsonSchema.JsonSchemaDraft;
+import com.kjetland.jackson.jsonSchema.JsonSchemaGenerator;
+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject;
+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaString;
import org.hibernate.internal.util.SerializationHelper;
import org.openremote.model.AssetModelProvider;
import org.openremote.model.ModelDescriptor;
@@ -138,7 +139,7 @@ public class ValueUtil {
protected static List<MetaItemDescriptor<?>> metaItemDescriptors;
protected static List<ValueDescriptor<?>> valueDescriptors;
protected static Validator validator;
- protected static SchemaGenerator generator;
+ protected static JsonSchemaGenerator generator;
static {
// Find all service loader registered asset model providers
@@ -830,32 +831,10 @@ public class ValueUtil {
}
protected static void doSchemaInit() {
- SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(JSON, SchemaVersion.DRAFT_7, OptionPreset.PLAIN_JSON)
- .with(
- new JacksonModule(
- JacksonOption.FLATTENED_ENUMS_FROM_JSONVALUE
- )
- )
- .with(
- new Swagger2Module()
- );
-// .with(new JavaxValidationModule());
-
- configBuilder.forTypesInGeneral()
- .withSubtypeResolver((declaredType, generationContext) -> {
- if (declaredType.getErasedType() == AgentLink.class) {
- TypeContext typeContext = generationContext.getTypeContext();
- return Arrays.stream(getAgentLinkClasses())
- .map(agentLinkClass -> typeContext.resolveSubtype(declaredType, agentLinkClass))
- .collect(Collectors.toList());
- }
- return null;
- });
-
- SchemaGeneratorConfig config = configBuilder.build();
- generator = new SchemaGenerator(config);
+ generator = new JsonSchemaGenerator(JSON, JSONSchemaUtil.getJsonSchemaConfig());
}
+
protected static Class<?>[] getAgentLinkClasses() {
return Arrays.stream(getAssetDescriptors(null))
.filter(descriptor -> descriptor instanceof AgentDescriptor)
@@ -894,7 +873,7 @@ public class ValueUtil {
if (generator == null) {
return JSON.createObjectNode();
}
- return generator.generateSchema(clazz);
+ return generator.generateJsonSchema(clazz);
}
public static void initialiseAssetAttributes(Asset<?> asset) throws IllegalStateException {
diff --git a/model/src/main/java/org/openremote/model/value/JsonPathFilter.java b/model/src/main/java/org/openremote/model/value/JsonPathFilter.java
index 8073e05eb..23d6dfdcc 100644
--- a/model/src/main/java/org/openremote/model/value/JsonPathFilter.java
+++ b/model/src/main/java/org/openremote/model/value/JsonPathFilter.java
@@ -32,6 +32,8 @@ import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import org.openremote.model.util.TextUtil;
import org.openremote.model.util.ValueUtil;
+import javax.validation.constraints.NotNull;
+
/**
* This filter works on any type of data; when applying the filter the data should be converted to JSON representation
* using a tool like Jackson and then the JSON path expression should be applied to this JSON string.
@@ -49,6 +51,7 @@ public class JsonPathFilter extends ValueFilter {
public static final String NAME = "jsonPath";
+ @NotNull
@JsonProperty
public String path;
diff --git a/model/src/main/java/org/openremote/model/value/ValueType.java b/model/src/main/java/org/openremote/model/value/ValueType.java
index 77f2c9b81..16d606f47 100644
--- a/model/src/main/java/org/openremote/model/value/ValueType.java
+++ b/model/src/main/java/org/openremote/model/value/ValueType.java
@@ -20,6 +20,8 @@
package org.openremote.model.value;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject;
+import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaString;
import org.openremote.model.Constants;
import org.openremote.model.asset.agent.AgentLink;
import org.openremote.model.asset.agent.ConnectionStatus;
@@ -52,7 +54,6 @@ public final class ValueType {
public static class IntegerMap extends HashMap<String, Integer> {}
public static class DoubleMap extends HashMap<String, Double> {}
public static class BooleanMap extends HashMap<String, Double> {}
-
public static class MultivaluedStringMap extends HashMap<String, List<String>> {}
public static final ValueDescriptor<Boolean> BOOLEAN = new ValueDescriptor<>("boolean", Boolean.class);
diff --git a/test/src/test/groovy/org/openremote/test/model/AssetModelTest.groovy b/test/src/test/groovy/org/openremote/test/model/AssetModelTest.groovy
index 1cc41993e..d5708f9e2 100644
--- a/test/src/test/groovy/org/openremote/test/model/AssetModelTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/model/AssetModelTest.groovy
@@ -108,9 +108,13 @@ class AssetModelTest extends Specification implements ManagerContainerTrait {
and: "the descriptor should contain an agent link schema"
def schema = ValueUtil.getSchema(AgentLink.class)
+ def schema2 = ValueUtil.getSchema(ValueType.IntegerMap.class)
assert schema != null
- assert schema.get("anyOf") != null
- assert schema.get("anyOf").size() == ValueUtil.getAssetDescriptors(null).findAll {it instanceof AgentDescriptor}.collect {(it as AgentDescriptor).getAgentLinkClass()}.unique {it.getSimpleName()}.size()
+ assert schema.get("oneOf") != null
+ assert schema.get("oneOf").size() == ValueUtil.getAssetDescriptors(null).findAll {it instanceof AgentDescriptor}.collect {(it as AgentDescriptor).getAgentLinkClass()}.unique {it.getSimpleName()}.size()
+ assert schema2 != null
+ assert schema2.get("additionalProperties") != null
+ assert schema2.get("additionalProperties").get(".+") != null
}
def "Serialize/Deserialize asset model"() {
diff --git a/test/src/test/groovy/org/openremote/test/protocol/websocket/WebsocketClientProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/websocket/WebsocketClientProtocolTest.groovy
index bbfa48f03..383c20552 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/websocket/WebsocketClientProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/websocket/WebsocketClientProtocolTest.groovy
@@ -20,17 +20,12 @@
package org.openremote.test.protocol.websocket
import org.openremote.agent.protocol.simulator.SimulatorProtocol
-import org.openremote.agent.protocol.websocket.WebsocketAgent
-import org.openremote.agent.protocol.websocket.WebsocketAgentLink
-import org.openremote.agent.protocol.websocket.WebsocketAgentProtocol
-import org.openremote.agent.protocol.websocket.WebsocketHTTPSubscription
-import org.openremote.agent.protocol.websocket.WebsocketSubscription
+import org.openremote.agent.protocol.websocket.*
import org.openremote.manager.agent.AgentService
import org.openremote.manager.asset.AssetProcessingService
import org.openremote.manager.asset.AssetStorageService
import org.openremote.manager.event.ClientEventService
import org.openremote.manager.setup.SetupService
-import org.openremote.test.setup.ManagerTestSetup
import org.openremote.model.Constants
import org.openremote.model.asset.AssetFilter
import org.openremote.model.asset.ReadAttributeEvent
@@ -47,12 +42,13 @@ import org.openremote.model.event.shared.EventSubscription
import org.openremote.model.event.shared.SharedEvent
import org.openremote.model.query.AssetQuery
import org.openremote.model.query.filter.StringPredicate
+import org.openremote.model.util.ValueUtil
import org.openremote.model.value.JsonPathFilter
import org.openremote.model.value.RegexValueFilter
import org.openremote.model.value.SubStringValueFilter
import org.openremote.model.value.ValueFilter
-import org.openremote.model.util.ValueUtil
import org.openremote.test.ManagerContainerTrait
+import org.openremote.test.setup.ManagerTestSetup
import spock.lang.Shared
import spock.lang.Specification
import spock.util.concurrent.PollingConditions
@@ -152,7 +148,7 @@ class WebsocketClientProtocolTest extends Specification implements ManagerContai
MASTER_REALM_ADMIN_USER,
getString(container.getConfig(), SETUP_ADMIN_PASSWORD, SETUP_ADMIN_PASSWORD_DEFAULT)))
.setConnectSubscriptions([
- new WebsocketSubscription().body(EventSubscription.SUBSCRIBE_MESSAGE_PREFIX + ValueUtil.asJSON(
+ new WebsocketSubscriptionImpl().body(EventSubscription.SUBSCRIBE_MESSAGE_PREFIX + ValueUtil.asJSON(
new EventSubscription(
AttributeEvent.class,
new AssetFilter<AttributeEvent>().setAssetIds(managerTestSetup.apartment1LivingroomId),
@@ -219,7 +215,7 @@ class WebsocketClientProtocolTest extends Specification implements ManagerContai
)
.setWebsocketSubscriptions(
[
- new WebsocketSubscription().body(SharedEvent.MESSAGE_PREFIX + ValueUtil.asJSON(
+ new WebsocketSubscriptionImpl().body(SharedEvent.MESSAGE_PREFIX + ValueUtil.asJSON(
new ReadAttributeEvent(managerTestSetup.apartment1LivingroomId, "targetTemperature")
).orElse(null)),
new WebsocketHTTPSubscription()
@@ -249,7 +245,7 @@ class WebsocketClientProtocolTest extends Specification implements ManagerContai
)
.setWebsocketSubscriptions(
[
- new WebsocketSubscription().body(SharedEvent.MESSAGE_PREFIX + ValueUtil.asJSON(
+ new WebsocketSubscriptionImpl().body(SharedEvent.MESSAGE_PREFIX + ValueUtil.asJSON(
new ReadAttributeEvent(managerTestSetup.apartment1LivingroomId, "co2Level")
).orElse(null)),
new WebsocketHTTPSubscription()
diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.ts
index cb183bb93..f35e4d786 100644
--- a/ui/component/or-attribute-input/src/index.ts
+++ b/ui/component/or-attribute-input/src/index.ts
@@ -149,13 +149,6 @@ export const jsonFormsInputTemplateProvider: (fallback: ValueInputProvider) => V
const newAgentDescriptor = AssetModelUtil.getAssetDescriptor(agent.type) as AgentDescriptor;
if (!newAgentDescriptor) {
newAgentLink = undefined;
- } else {
- if (!agentLink || newAgentDescriptor.agentLinkType !== agentLink.type) {
- newAgentLink = {
- id: agent.id,
- type: newAgentDescriptor.agentLinkType!
- };
- }
}
}
}
@@ -173,7 +166,7 @@ export const jsonFormsInputTemplateProvider: (fallback: ValueInputProvider) => V
};
// TODO: Load agent link schema from AssetModelUtil
- const schema = JSON.parse("{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"definitions\":{\"ArrayPredicate-1\":{\"type\":\"object\",\"properties\":{\"index\":{\"type\":\"integer\"},\"lengthEquals\":{\"type\":\"integer\"},\"lengthGreaterThan\":{\"type\":\"integer\"},\"lengthLessThan\":{\"type\":\"integer\"},\"negated\":{\"type\":\"boolean\"},\"value\":{}}},\"ArrayPredicate-2\":{\"allOf\":[{\"$ref\":\"#/definitions/ArrayPredicate-1\"},{\"type\":\"object\",\"properties\":{\"predicateType\":{\"const\":\"ArrayPredicate\"}}}]},\"BooleanPredicate-1\":{\"type\":\"object\",\"properties\":{\"value\":{\"type\":\"boolean\"}}},\"BooleanPredicate-2\":{\"allOf\":[{\"$ref\":\"#/definitions/BooleanPredicate-1\"},{\"type\":\"object\",\"properties\":{\"predicateType\":{\"const\":\"BooleanPredicate\"}}}]},\"CalendarEventPredicate-1\":{\"type\":\"object\",\"properties\":{\"timestamp\":{\"type\":\"string\"}}},\"CalendarEventPredicate-2\":{\"allOf\":[{\"$ref\":\"#/definitions/CalendarEventPredicate-1\"},{\"type\":\"object\",\"properties\":{\"predicateType\":{\"const\":\"CalendarEventPredicate\"}}}]},\"DateTimePredicate-1\":{\"type\":\"object\",\"properties\":{\"negate\":{\"type\":\"boolean\"},\"operator\":{\"$ref\":\"#/definitions/Operator\"},\"rangeValue\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"}}},\"DateTimePredicate-2\":{\"allOf\":[{\"$ref\":\"#/definitions/DateTimePredicate-1\"},{\"type\":\"object\",\"properties\":{\"predicateType\":{\"const\":\"DateTimePredicate\"}}}]},\"JsonPathFilter-1\":{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"},\"returnFirst\":{\"type\":\"boolean\"},\"returnLast\":{\"type\":\"boolean\"}}},\"JsonPathFilter-2\":{\"allOf\":[{\"$ref\":\"#/definitions/JsonPathFilter-1\"},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"jsonPath\"}}}]},\"Map(String,List(String))\":{\"type\":\"object\"},\"NumberPredicate-1\":{\"type\":\"object\",\"properties\":{\"negate\":{\"type\":\"boolean\"},\"operator\":{\"$ref\":\"#/definitions/Operator\"},\"rangeValue\":{\"type\":\"number\"},\"value\":{\"type\":\"number\"}}},\"NumberPredicate-2\":{\"allOf\":[{\"$ref\":\"#/definitions/NumberPredicate-1\"},{\"type\":\"object\",\"properties\":{\"predicateType\":{\"const\":\"NumberPredicate\"}}}]},\"ObjectNode\":{\"type\":\"object\"},\"Operator\":{\"type\":\"string\",\"enum\":[\"EQUALS\",\"GREATER_THAN\",\"GREATER_EQUALS\",\"LESS_THAN\",\"LESS_EQUALS\",\"BETWEEN\"]},\"RadialGeofencePredicate-1\":{\"type\":\"object\",\"properties\":{\"lat\":{\"type\":\"number\"},\"lng\":{\"type\":\"number\"},\"negated\":{\"type\":\"boolean\"},\"radius\":{\"type\":\"integer\"}}},\"RadialGeofencePredicate-2\":{\"allOf\":[{\"$ref\":\"#/definitions/RadialGeofencePredicate-1\"},{\"type\":\"object\",\"properties\":{\"predicateType\":{\"const\":\"RadialGeofencePredicate\"}}}]},\"RectangularGeofencePredicate-1\":{\"type\":\"object\",\"properties\":{\"latMax\":{\"type\":\"number\"},\"latMin\":{\"type\":\"number\"},\"lngMax\":{\"type\":\"number\"},\"lngMin\":{\"type\":\"number\"},\"negated\":{\"type\":\"boolean\"}}},\"RectangularGeofencePredicate-2\":{\"allOf\":[{\"$ref\":\"#/definitions/RectangularGeofencePredicate-1\"},{\"type\":\"object\",\"properties\":{\"predicateType\":{\"const\":\"RectangularGeofencePredicate\"}}}]},\"RegexValueFilter-1\":{\"type\":\"object\",\"properties\":{\"matchGroup\":{\"type\":\"integer\"},\"matchIndex\":{\"type\":\"integer\"},\"pattern\":{\"type\":\"object\",\"properties\":{\"flags\":{\"type\":\"integer\"},\"pattern\":{\"type\":\"string\"}}}}},\"RegexValueFilter-2\":{\"allOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-1\"},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"regex\"}}}]},\"StringPredicate-1\":{\"type\":\"object\",\"properties\":{\"caseSensitive\":{\"type\":\"boolean\"},\"match\":{\"type\":\"string\",\"enum\":[\"EXACT\",\"BEGIN\",\"END\",\"CONTAINS\"]},\"negate\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"}}},\"StringPredicate-2\":{\"allOf\":[{\"$ref\":\"#/definitions/StringPredicate-1\"},{\"type\":\"object\",\"properties\":{\"predicateType\":{\"const\":\"StringPredicate\"}}}]},\"SubStringValueFilter-1\":{\"type\":\"object\",\"properties\":{\"beginIndex\":{\"type\":\"integer\"},\"endIndex\":{\"type\":\"integer\"}}},\"SubStringValueFilter-2\":{\"allOf\":[{\"$ref\":\"#/definitions/SubStringValueFilter-1\"},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"substring\"}}}]},\"ValueEmptyPredicate-1\":{\"type\":\"object\"},\"ValueEmptyPredicate-2\":{\"allOf\":[{\"$ref\":\"#/definitions/ValueEmptyPredicate-1\"},{\"type\":\"object\",\"properties\":{\"predicateType\":{\"const\":\"ValueEmptyPredicate\"}}}]},\"ValueNotEmptyPredicate-1\":{\"type\":\"object\"},\"ValueNotEmptyPredicate-2\":{\"allOf\":[{\"$ref\":\"#/definitions/ValueNotEmptyPredicate-1\"},{\"type\":\"object\",\"properties\":{\"predicateType\":{\"const\":\"ValueNotEmptyPredicate\"}}}]},\"WebsocketHTTPSubscription-1\":{\"type\":\"object\",\"properties\":{\"body\":{},\"contentType\":{\"type\":\"string\"},\"headers\":{\"$ref\":\"#/definitions/Map(String,List(String))\"},\"method\":{\"type\":\"string\",\"enum\":[\"GET\",\"PUT\",\"POST\"]},\"type\":{\"type\":\"string\"},\"uri\":{\"type\":\"string\"}}},\"WebsocketHTTPSubscription-2\":{\"allOf\":[{\"$ref\":\"#/definitions/WebsocketHTTPSubscription-1\"},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"WebsocketHTTPSubscription\"}}}]},\"WebsocketSubscription\":{\"anyOf\":[{\"$ref\":\"#/definitions/WebsocketSubscription\"},{\"$ref\":\"#/definitions/WebsocketHTTPSubscription-2\"}]}},\"anyOf\":[{\"allOf\":[{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"messageMatchFilters\":{\"description\":\"ValueFilters to apply to incoming messages prior to comparison with the messageMatchPredicate\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"messageMatchPredicate\":{\"anyOf\":[{\"$ref\":\"#/definitions/StringPredicate-2\"},{\"$ref\":\"#/definitions/BooleanPredicate-2\"},{\"$ref\":\"#/definitions/DateTimePredicate-2\"},{\"$ref\":\"#/definitions/NumberPredicate-2\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate-2\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate-2\"},{\"$ref\":\"#/definitions/ArrayPredicate-2\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate-2\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate-2\"},{\"$ref\":\"#/definitions/CalendarEventPredicate-2\"}]},\"oid\":{\"type\":\"string\"},\"valueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Defines a value converter map to allow for basic value type conversion; the incoming value will be converted to JSON and if this string matches a key in the converter then the value of that key will be pushed through to the attribute. An example use case is an API that returns 'ACTIVE'/'DISABLED' strings but you want to connect this to a Boolean attribute\"}]},\"valueFilters\":{\"description\":\"Defines ValueFilters to apply to an incoming value before it is written to a protocol linked attribute; this is particularly useful for generic protocols. The message should pass through the filters in array order\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"writeValue\":{\"type\":\"string\",\"description\":\"String to be used for attribute writes and can contain '{$value}' placeholders to allow the written value to be injected into the string or to even hardcode the value written to the protocol\"},\"writeValueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Similar to valueConverter but will be applied to outgoing values allowing for the opposite conversion\"}]}}},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"SNMPAgentLink\"}}}]},{\"allOf\":[{\"type\":\"object\",\"properties\":{\"deviceEndpoint\":{\"type\":\"integer\"},\"deviceNodeId\":{\"type\":\"integer\"},\"deviceValue\":{\"type\":\"string\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"messageMatchFilters\":{\"description\":\"ValueFilters to apply to incoming messages prior to comparison with the messageMatchPredicate\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"messageMatchPredicate\":{\"anyOf\":[{\"$ref\":\"#/definitions/StringPredicate-2\"},{\"$ref\":\"#/definitions/BooleanPredicate-2\"},{\"$ref\":\"#/definitions/DateTimePredicate-2\"},{\"$ref\":\"#/definitions/NumberPredicate-2\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate-2\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate-2\"},{\"$ref\":\"#/definitions/ArrayPredicate-2\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate-2\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate-2\"},{\"$ref\":\"#/definitions/CalendarEventPredicate-2\"}]},\"valueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Defines a value converter map to allow for basic value type conversion; the incoming value will be converted to JSON and if this string matches a key in the converter then the value of that key will be pushed through to the attribute. An example use case is an API that returns 'ACTIVE'/'DISABLED' strings but you want to connect this to a Boolean attribute\"}]},\"valueFilters\":{\"description\":\"Defines ValueFilters to apply to an incoming value before it is written to a protocol linked attribute; this is particularly useful for generic protocols. The message should pass through the filters in array order\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"writeValue\":{\"type\":\"string\",\"description\":\"String to be used for attribute writes and can contain '{$value}' placeholders to allow the written value to be injected into the string or to even hardcode the value written to the protocol\"},\"writeValueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Similar to valueConverter but will be applied to outgoing values allowing for the opposite conversion\"}]}}},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"ZWaveAgentLink\"}}}]},{\"allOf\":[{\"type\":\"object\",\"properties\":{\"deviceAddress\":{\"type\":\"integer\"},\"deviceValueLink\":{\"type\":\"string\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"messageMatchFilters\":{\"description\":\"ValueFilters to apply to incoming messages prior to comparison with the messageMatchPredicate\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"messageMatchPredicate\":{\"anyOf\":[{\"$ref\":\"#/definitions/StringPredicate-2\"},{\"$ref\":\"#/definitions/BooleanPredicate-2\"},{\"$ref\":\"#/definitions/DateTimePredicate-2\"},{\"$ref\":\"#/definitions/NumberPredicate-2\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate-2\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate-2\"},{\"$ref\":\"#/definitions/ArrayPredicate-2\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate-2\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate-2\"},{\"$ref\":\"#/definitions/CalendarEventPredicate-2\"}]},\"valueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Defines a value converter map to allow for basic value type conversion; the incoming value will be converted to JSON and if this string matches a key in the converter then the value of that key will be pushed through to the attribute. An example use case is an API that returns 'ACTIVE'/'DISABLED' strings but you want to connect this to a Boolean attribute\"}]},\"valueFilters\":{\"description\":\"Defines ValueFilters to apply to an incoming value before it is written to a protocol linked attribute; this is particularly useful for generic protocols. The message should pass through the filters in array order\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"writeValue\":{\"type\":\"string\",\"description\":\"String to be used for attribute writes and can contain '{$value}' placeholders to allow the written value to be injected into the string or to even hardcode the value written to the protocol\"},\"writeValueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Similar to valueConverter but will be applied to outgoing values allowing for the opposite conversion\"}]}}},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"VelbusAgentLink\"}}}]},{\"allOf\":[{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"messageMatchFilters\":{\"description\":\"ValueFilters to apply to incoming messages prior to comparison with the messageMatchPredicate\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"messageMatchPredicate\":{\"anyOf\":[{\"$ref\":\"#/definitions/StringPredicate-2\"},{\"$ref\":\"#/definitions/BooleanPredicate-2\"},{\"$ref\":\"#/definitions/DateTimePredicate-2\"},{\"$ref\":\"#/definitions/NumberPredicate-2\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate-2\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate-2\"},{\"$ref\":\"#/definitions/ArrayPredicate-2\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate-2\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate-2\"},{\"$ref\":\"#/definitions/CalendarEventPredicate-2\"}]},\"valueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Defines a value converter map to allow for basic value type conversion; the incoming value will be converted to JSON and if this string matches a key in the converter then the value of that key will be pushed through to the attribute. An example use case is an API that returns 'ACTIVE'/'DISABLED' strings but you want to connect this to a Boolean attribute\"}]},\"valueFilters\":{\"description\":\"Defines ValueFilters to apply to an incoming value before it is written to a protocol linked attribute; this is particularly useful for generic protocols. The message should pass through the filters in array order\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"writeValue\":{\"type\":\"string\",\"description\":\"String to be used for attribute writes and can contain '{$value}' placeholders to allow the written value to be injected into the string or to even hardcode the value written to the protocol\"},\"writeValueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Similar to valueConverter but will be applied to outgoing values allowing for the opposite conversion\"}]}}},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"DefaultAgentLink\"}}}]},{\"allOf\":[{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"messageMatchFilters\":{\"description\":\"ValueFilters to apply to incoming messages prior to comparison with the messageMatchPredicate\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"messageMatchPredicate\":{\"anyOf\":[{\"$ref\":\"#/definitions/StringPredicate-2\"},{\"$ref\":\"#/definitions/BooleanPredicate-2\"},{\"$ref\":\"#/definitions/DateTimePredicate-2\"},{\"$ref\":\"#/definitions/NumberPredicate-2\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate-2\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate-2\"},{\"$ref\":\"#/definitions/ArrayPredicate-2\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate-2\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate-2\"},{\"$ref\":\"#/definitions/CalendarEventPredicate-2\"}]},\"replayData\":{\"description\":\"Used to store 24h dataset of values that should be replayed (i.e. written to the linked attribute) in a continuous loop.\",\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"timestamp\":{\"type\":\"integer\"},\"value\":{}}}},\"valueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Defines a value converter map to allow for basic value type conversion; the incoming value will be converted to JSON and if this string matches a key in the converter then the value of that key will be pushed through to the attribute. An example use case is an API that returns 'ACTIVE'/'DISABLED' strings but you want to connect this to a Boolean attribute\"}]},\"valueFilters\":{\"description\":\"Defines ValueFilters to apply to an incoming value before it is written to a protocol linked attribute; this is particularly useful for generic protocols. The message should pass through the filters in array order\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"writeValue\":{\"type\":\"string\",\"description\":\"String to be used for attribute writes and can contain '{$value}' placeholders to allow the written value to be injected into the string or to even hardcode the value written to the protocol\"},\"writeValueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Similar to valueConverter but will be applied to outgoing values allowing for the opposite conversion\"}]}}},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"SimulatorAgentLink\"}}}]},{\"allOf\":[{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"messageMatchFilters\":{\"description\":\"ValueFilters to apply to incoming messages prior to comparison with the messageMatchPredicate\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"messageMatchPredicate\":{\"anyOf\":[{\"$ref\":\"#/definitions/StringPredicate-2\"},{\"$ref\":\"#/definitions/BooleanPredicate-2\"},{\"$ref\":\"#/definitions/DateTimePredicate-2\"},{\"$ref\":\"#/definitions/NumberPredicate-2\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate-2\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate-2\"},{\"$ref\":\"#/definitions/ArrayPredicate-2\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate-2\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate-2\"},{\"$ref\":\"#/definitions/CalendarEventPredicate-2\"}]},\"valueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Defines a value converter map to allow for basic value type conversion; the incoming value will be converted to JSON and if this string matches a key in the converter then the value of that key will be pushed through to the attribute. An example use case is an API that returns 'ACTIVE'/'DISABLED' strings but you want to connect this to a Boolean attribute\"}]},\"valueFilters\":{\"description\":\"Defines ValueFilters to apply to an incoming value before it is written to a protocol linked attribute; this is particularly useful for generic protocols. The message should pass through the filters in array order\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"websocketSubscriptions\":{\"description\":\"Array of WebsocketSubscriptions that should be executed when the linked attribute is linked; the subscriptions are executed in the order specified in the array.\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/WebsocketSubscription\"},{\"$ref\":\"#/definitions/WebsocketHTTPSubscription-2\"}]}},\"writeValue\":{\"type\":\"string\",\"description\":\"String to be used for attribute writes and can contain '{$value}' placeholders to allow the written value to be injected into the string or to even hardcode the value written to the protocol\"},\"writeValueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Similar to valueConverter but will be applied to outgoing values allowing for the opposite conversion\"}]}}},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"WebsocketAgentLink\"}}}]},{\"allOf\":[{\"type\":\"object\",\"properties\":{\"contentType\":{\"type\":\"string\"},\"headers\":{\"$ref\":\"#/definitions/Map(String,List(String))\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"messageMatchFilters\":{\"description\":\"ValueFilters to apply to incoming messages prior to comparison with the messageMatchPredicate\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"messageMatchPredicate\":{\"anyOf\":[{\"$ref\":\"#/definitions/StringPredicate-2\"},{\"$ref\":\"#/definitions/BooleanPredicate-2\"},{\"$ref\":\"#/definitions/DateTimePredicate-2\"},{\"$ref\":\"#/definitions/NumberPredicate-2\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate-2\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate-2\"},{\"$ref\":\"#/definitions/ArrayPredicate-2\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate-2\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate-2\"},{\"$ref\":\"#/definitions/CalendarEventPredicate-2\"}]},\"method\":{\"type\":\"string\",\"enum\":[\"GET\",\"POST\",\"PUT\",\"DELETE\",\"OPTIONS\",\"PATCH\"]},\"pagingMode\":{\"type\":\"boolean\"},\"path\":{\"type\":\"string\"},\"pollingAttribute\":{\"type\":\"string\"},\"pollingMillis\":{\"type\":\"integer\"},\"queryParameters\":{\"$ref\":\"#/definitions/Map(String,List(String))\"},\"valueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Defines a value converter map to allow for basic value type conversion; the incoming value will be converted to JSON and if this string matches a key in the converter then the value of that key will be pushed through to the attribute. An example use case is an API that returns 'ACTIVE'/'DISABLED' strings but you want to connect this to a Boolean attribute\"}]},\"valueFilters\":{\"description\":\"Defines ValueFilters to apply to an incoming value before it is written to a protocol linked attribute; this is particularly useful for generic protocols. The message should pass through the filters in array order\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"writeValue\":{\"type\":\"string\",\"description\":\"String to be used for attribute writes and can contain '{$value}' placeholders to allow the written value to be injected into the string or to even hardcode the value written to the protocol\"},\"writeValueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Similar to valueConverter but will be applied to outgoing values allowing for the opposite conversion\"}]}}},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"HTTPAgentLink\"}}}]},{\"allOf\":[{\"type\":\"object\",\"properties\":{\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"messageMatchFilters\":{\"description\":\"ValueFilters to apply to incoming messages prior to comparison with the messageMatchPredicate\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"messageMatchPredicate\":{\"anyOf\":[{\"$ref\":\"#/definitions/StringPredicate-2\"},{\"$ref\":\"#/definitions/BooleanPredicate-2\"},{\"$ref\":\"#/definitions/DateTimePredicate-2\"},{\"$ref\":\"#/definitions/NumberPredicate-2\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate-2\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate-2\"},{\"$ref\":\"#/definitions/ArrayPredicate-2\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate-2\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate-2\"},{\"$ref\":\"#/definitions/CalendarEventPredicate-2\"}]},\"requiredValue\":{\"type\":\"string\"},\"valueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Defines a value converter map to allow for basic value type conversion; the incoming value will be converted to JSON and if this string matches a key in the converter then the value of that key will be pushed through to the attribute. An example use case is an API that returns 'ACTIVE'/'DISABLED' strings but you want to connect this to a Boolean attribute\"}]},\"valueFilters\":{\"description\":\"Defines ValueFilters to apply to an incoming value before it is written to a protocol linked attribute; this is particularly useful for generic protocols. The message should pass through the filters in array order\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"writeValue\":{\"type\":\"string\",\"description\":\"String to be used for attribute writes and can contain '{$value}' placeholders to allow the written value to be injected into the string or to even hardcode the value written to the protocol\"},\"writeValueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Similar to valueConverter but will be applied to outgoing values allowing for the opposite conversion\"}]}}},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"MockAgentLink\"}}}]},{\"allOf\":[{\"type\":\"object\",\"properties\":{\"actionGroupAddress\":{\"type\":\"string\"},\"dpt\":{\"type\":\"string\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"messageMatchFilters\":{\"description\":\"ValueFilters to apply to incoming messages prior to comparison with the messageMatchPredicate\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"messageMatchPredicate\":{\"anyOf\":[{\"$ref\":\"#/definitions/StringPredicate-2\"},{\"$ref\":\"#/definitions/BooleanPredicate-2\"},{\"$ref\":\"#/definitions/DateTimePredicate-2\"},{\"$ref\":\"#/definitions/NumberPredicate-2\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate-2\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate-2\"},{\"$ref\":\"#/definitions/ArrayPredicate-2\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate-2\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate-2\"},{\"$ref\":\"#/definitions/CalendarEventPredicate-2\"}]},\"statusGroupAddress\":{\"type\":\"string\"},\"valueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Defines a value converter map to allow for basic value type conversion; the incoming value will be converted to JSON and if this string matches a key in the converter then the value of that key will be pushed through to the attribute. An example use case is an API that returns 'ACTIVE'/'DISABLED' strings but you want to connect this to a Boolean attribute\"}]},\"valueFilters\":{\"description\":\"Defines ValueFilters to apply to an incoming value before it is written to a protocol linked attribute; this is particularly useful for generic protocols. The message should pass through the filters in array order\",\"type\":\"array\",\"items\":{\"anyOf\":[{\"$ref\":\"#/definitions/RegexValueFilter-2\"},{\"$ref\":\"#/definitions/SubStringValueFilter-2\"},{\"$ref\":\"#/definitions/JsonPathFilter-2\"}]}},\"writeValue\":{\"type\":\"string\",\"description\":\"String to be used for attribute writes and can contain '{$value}' placeholders to allow the written value to be injected into the string or to even hardcode the value written to the protocol\"},\"writeValueConverter\":{\"allOf\":[{\"$ref\":\"#/definitions/ObjectNode\"},{\"description\":\"Similar to valueConverter but will be applied to outgoing values allowing for the opposite conversion\"}]}}},{\"type\":\"object\",\"properties\":{\"type\":{\"const\":\"KNXAgentLink\"}}}]}]}");
+ const schema = JSON.parse("{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"title\":\"Agent Link\",\"oneOf\":[{\"$ref\":\"#/definitions/SNMPAgentLink\"},{\"$ref\":\"#/definitions/DefaultAgentLink\"},{\"$ref\":\"#/definitions/HTTPAgentLink\"},{\"$ref\":\"#/definitions/MockAgentLink\"},{\"$ref\":\"#/definitions/WebsocketAgentLink\"},{\"$ref\":\"#/definitions/KNXAgentLink\"},{\"$ref\":\"#/definitions/ZWaveAgentLink\"},{\"$ref\":\"#/definitions/SimulatorAgentLink\"},{\"$ref\":\"#/definitions/VelbusAgentLink\"}],\"definitions\":{\"SNMPAgentLink\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"SNMPAgentLink\"],\"default\":\"SNMPAgentLink\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"valueFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"valueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValue\":{\"type\":\"string\"},\"messageMatchPredicate\":{\"oneOf\":[{\"$ref\":\"#/definitions/StringPredicate\"},{\"$ref\":\"#/definitions/BooleanPredicate\"},{\"$ref\":\"#/definitions/DateTimePredicate\"},{\"$ref\":\"#/definitions/NumberPredicate\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate\"},{\"$ref\":\"#/definitions/ArrayPredicate\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate\"},{\"$ref\":\"#/definitions/CalendarEventPredicate\"}]},\"messageMatchFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"oid\":{\"type\":\"string\"}},\"title\":\"SNMPAgentLink\",\"required\":[\"type\",\"oid\"]},\"regex\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"regex\"],\"default\":\"regex\"},\"pattern\":{\"type\":\"string\"},\"matchGroup\":{\"type\":\"integer\"},\"matchIndex\":{\"type\":\"integer\"}},\"title\":\"regex\",\"required\":[\"type\"]},\"substring\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"substring\"],\"default\":\"substring\"},\"beginIndex\":{\"type\":\"integer\"},\"endIndex\":{\"type\":\"integer\"}},\"title\":\"substring\",\"required\":[\"type\",\"beginIndex\"]},\"jsonPath\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"jsonPath\"],\"default\":\"jsonPath\"},\"path\":{\"type\":\"string\"},\"returnFirst\":{\"type\":\"boolean\"},\"returnLast\":{\"type\":\"boolean\"}},\"title\":\"jsonPath\",\"required\":[\"type\",\"returnFirst\",\"returnLast\"]},\"PatternPropertiesSimpleKeyAnyType\":{\"type\":\"object\",\"additionalProperties\":true,\"patternProperties\":{\"^[a-zA-Z][a-zA-Z0-9]*\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}},\"properties\":{}},\"StringPredicate\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"predicateType\":{\"type\":\"string\",\"enum\":[\"string\"],\"default\":\"string\"},\"match\":{\"type\":\"string\",\"enum\":[\"EXACT\",\"BEGIN\",\"END\",\"CONTAINS\"]},\"caseSensitive\":{\"type\":\"boolean\"},\"value\":{\"type\":\"string\"},\"negate\":{\"type\":\"boolean\"}},\"title\":\"string\",\"required\":[\"predicateType\",\"caseSensitive\",\"negate\"]},\"BooleanPredicate\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"predicateType\":{\"type\":\"string\",\"enum\":[\"boolean\"],\"default\":\"boolean\"},\"value\":{\"type\":\"boolean\"}},\"title\":\"boolean\",\"required\":[\"predicateType\",\"value\"]},\"DateTimePredicate\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"predicateType\":{\"type\":\"string\",\"enum\":[\"datetime\"],\"default\":\"datetime\"},\"value\":{\"type\":\"string\"},\"rangeValue\":{\"type\":\"string\"},\"operator\":{\"type\":\"string\",\"enum\":[\"EQUALS\",\"GREATER_THAN\",\"GREATER_EQUALS\",\"LESS_THAN\",\"LESS_EQUALS\",\"BETWEEN\"]},\"negate\":{\"type\":\"boolean\"}},\"title\":\"datetime\",\"required\":[\"predicateType\",\"negate\"]},\"NumberPredicate\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"predicateType\":{\"type\":\"string\",\"enum\":[\"number\"],\"default\":\"number\"},\"value\":{\"type\":\"number\"},\"rangeValue\":{\"type\":\"number\"},\"operator\":{\"type\":\"string\",\"enum\":[\"EQUALS\",\"GREATER_THAN\",\"GREATER_EQUALS\",\"LESS_THAN\",\"LESS_EQUALS\",\"BETWEEN\"]},\"negate\":{\"type\":\"boolean\"}},\"title\":\"number\",\"required\":[\"predicateType\",\"negate\"]},\"RadialGeofencePredicate\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"predicateType\":{\"type\":\"string\",\"enum\":[\"radial\"],\"default\":\"radial\"},\"radius\":{\"type\":\"integer\"},\"lat\":{\"type\":\"number\"},\"lng\":{\"type\":\"number\"},\"negated\":{\"type\":\"boolean\"}},\"title\":\"radial\",\"required\":[\"predicateType\",\"radius\",\"lat\",\"lng\",\"negated\"]},\"RectangularGeofencePredicate\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"predicateType\":{\"type\":\"string\",\"enum\":[\"rect\"],\"default\":\"rect\"},\"latMin\":{\"type\":\"number\"},\"lngMin\":{\"type\":\"number\"},\"latMax\":{\"type\":\"number\"},\"lngMax\":{\"type\":\"number\"},\"negated\":{\"type\":\"boolean\"}},\"title\":\"rect\",\"required\":[\"predicateType\",\"latMin\",\"lngMin\",\"latMax\",\"lngMax\",\"negated\"]},\"ArrayPredicate\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"predicateType\":{\"type\":\"string\",\"enum\":[\"array\"],\"default\":\"array\"},\"value\":{\"$ref\":\"#/definitions/PatternPropertiesSimpleKeyAnyType\"},\"index\":{\"type\":\"integer\"},\"lengthEquals\":{\"type\":\"integer\"},\"lengthGreaterThan\":{\"type\":\"integer\"},\"lengthLessThan\":{\"type\":\"integer\"},\"negated\":{\"type\":\"boolean\"}},\"title\":\"array\",\"required\":[\"predicateType\",\"negated\"]},\"ValueEmptyPredicate\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"predicateType\":{\"type\":\"string\",\"enum\":[\"value-empty\"],\"default\":\"value-empty\"}},\"title\":\"value-empty\",\"required\":[\"predicateType\"]},\"ValueNotEmptyPredicate\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"predicateType\":{\"type\":\"string\",\"enum\":[\"value-not-empty\"],\"default\":\"value-not-empty\"}},\"title\":\"value-not-empty\",\"required\":[\"predicateType\"]},\"CalendarEventPredicate\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"predicateType\":{\"type\":\"string\",\"enum\":[\"calendar-event\"],\"default\":\"calendar-event\"},\"timestamp\":{\"type\":\"integer\",\"format\":\"utc-millisec\"}},\"title\":\"calendar-event\",\"required\":[\"predicateType\"]},\"DefaultAgentLink\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"DefaultAgentLink\"],\"default\":\"DefaultAgentLink\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"valueFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"valueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValue\":{\"type\":\"string\"},\"messageMatchPredicate\":{\"oneOf\":[{\"$ref\":\"#/definitions/StringPredicate\"},{\"$ref\":\"#/definitions/BooleanPredicate\"},{\"$ref\":\"#/definitions/DateTimePredicate\"},{\"$ref\":\"#/definitions/NumberPredicate\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate\"},{\"$ref\":\"#/definitions/ArrayPredicate\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate\"},{\"$ref\":\"#/definitions/CalendarEventPredicate\"}]},\"messageMatchFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}}},\"title\":\"DefaultAgentLink\",\"required\":[\"type\"]},\"HTTPAgentLink\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"HTTPAgentLink\"],\"default\":\"HTTPAgentLink\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"valueFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"valueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValue\":{\"type\":\"string\"},\"messageMatchPredicate\":{\"oneOf\":[{\"$ref\":\"#/definitions/StringPredicate\"},{\"$ref\":\"#/definitions/BooleanPredicate\"},{\"$ref\":\"#/definitions/DateTimePredicate\"},{\"$ref\":\"#/definitions/NumberPredicate\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate\"},{\"$ref\":\"#/definitions/ArrayPredicate\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate\"},{\"$ref\":\"#/definitions/CalendarEventPredicate\"}]},\"messageMatchFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"headers\":{\"type\":\"object\",\"additionalProperties\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"queryParameters\":{\"type\":\"object\",\"additionalProperties\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"pollingMillis\":{\"type\":\"integer\"},\"pagingMode\":{\"type\":\"boolean\"},\"path\":{\"type\":\"string\"},\"method\":{\"type\":\"string\",\"enum\":[\"GET\",\"POST\",\"PUT\",\"DELETE\",\"OPTIONS\",\"PATCH\"]},\"contentType\":{\"type\":\"string\"},\"pollingAttribute\":{\"type\":\"string\"}},\"title\":\"HTTPAgentLink\",\"required\":[\"type\"]},\"MockAgentLink\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"MockAgentLink\"],\"default\":\"MockAgentLink\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"valueFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"valueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValue\":{\"type\":\"string\"},\"messageMatchPredicate\":{\"oneOf\":[{\"$ref\":\"#/definitions/StringPredicate\"},{\"$ref\":\"#/definitions/BooleanPredicate\"},{\"$ref\":\"#/definitions/DateTimePredicate\"},{\"$ref\":\"#/definitions/NumberPredicate\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate\"},{\"$ref\":\"#/definitions/ArrayPredicate\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate\"},{\"$ref\":\"#/definitions/CalendarEventPredicate\"}]},\"messageMatchFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"requiredValue\":{\"type\":\"string\"}},\"title\":\"MockAgentLink\",\"required\":[\"type\"]},\"WebsocketAgentLink\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"WebsocketAgentLink\"],\"default\":\"WebsocketAgentLink\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"valueFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"valueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValue\":{\"type\":\"string\"},\"messageMatchPredicate\":{\"oneOf\":[{\"$ref\":\"#/definitions/StringPredicate\"},{\"$ref\":\"#/definitions/BooleanPredicate\"},{\"$ref\":\"#/definitions/DateTimePredicate\"},{\"$ref\":\"#/definitions/NumberPredicate\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate\"},{\"$ref\":\"#/definitions/ArrayPredicate\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate\"},{\"$ref\":\"#/definitions/CalendarEventPredicate\"}]},\"messageMatchFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"websocketSubscriptions\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/websocket\"},{\"$ref\":\"#/definitions/http\"}]}}},\"title\":\"WebsocketAgentLink\",\"required\":[\"type\"]},\"websocket\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"websocket\"],\"default\":\"websocket\"},\"body\":{\"$ref\":\"#/definitions/PatternPropertiesSimpleKeyAnyType\"}},\"title\":\"websocket\",\"required\":[\"type\"]},\"http\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"http\"],\"default\":\"http\"},\"body\":{\"$ref\":\"#/definitions/PatternPropertiesSimpleKeyAnyType\"},\"method\":{\"type\":\"string\",\"enum\":[\"GET\",\"PUT\",\"POST\"]},\"contentType\":{\"type\":\"string\"},\"headers\":{\"type\":\"object\",\"additionalProperties\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"uri\":{\"type\":\"string\"}},\"title\":\"http\",\"required\":[\"type\"]},\"KNXAgentLink\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"KNXAgentLink\"],\"default\":\"KNXAgentLink\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"valueFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"valueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValue\":{\"type\":\"string\"},\"messageMatchPredicate\":{\"oneOf\":[{\"$ref\":\"#/definitions/StringPredicate\"},{\"$ref\":\"#/definitions/BooleanPredicate\"},{\"$ref\":\"#/definitions/DateTimePredicate\"},{\"$ref\":\"#/definitions/NumberPredicate\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate\"},{\"$ref\":\"#/definitions/ArrayPredicate\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate\"},{\"$ref\":\"#/definitions/CalendarEventPredicate\"}]},\"messageMatchFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"dpt\":{\"type\":\"string\",\"pattern\":\"^\\\\d{1,3}\\\\.\\\\d{1,3}$\"},\"actionGroupAddress\":{\"type\":\"string\",\"pattern\":\"^\\\\d{1,3}/\\\\d{1,3}/\\\\d{1,3}$\"},\"statusGroupAddress\":{\"type\":\"string\",\"pattern\":\"^\\\\d{1,3}/\\\\d{1,3}/\\\\d{1,3}$\"}},\"title\":\"KNXAgentLink\",\"required\":[\"type\",\"dpt\"]},\"ZWaveAgentLink\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"ZWaveAgentLink\"],\"default\":\"ZWaveAgentLink\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"valueFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"valueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValue\":{\"type\":\"string\"},\"messageMatchPredicate\":{\"oneOf\":[{\"$ref\":\"#/definitions/StringPredicate\"},{\"$ref\":\"#/definitions/BooleanPredicate\"},{\"$ref\":\"#/definitions/DateTimePredicate\"},{\"$ref\":\"#/definitions/NumberPredicate\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate\"},{\"$ref\":\"#/definitions/ArrayPredicate\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate\"},{\"$ref\":\"#/definitions/CalendarEventPredicate\"}]},\"messageMatchFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"deviceNodeId\":{\"type\":\"integer\"},\"deviceEndpoint\":{\"type\":\"integer\"},\"deviceValue\":{\"type\":\"string\"}},\"title\":\"ZWaveAgentLink\",\"required\":[\"type\"]},\"SimulatorAgentLink\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"SimulatorAgentLink\"],\"default\":\"SimulatorAgentLink\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"valueFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"valueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValue\":{\"type\":\"string\"},\"messageMatchPredicate\":{\"oneOf\":[{\"$ref\":\"#/definitions/StringPredicate\"},{\"$ref\":\"#/definitions/BooleanPredicate\"},{\"$ref\":\"#/definitions/DateTimePredicate\"},{\"$ref\":\"#/definitions/NumberPredicate\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate\"},{\"$ref\":\"#/definitions/ArrayPredicate\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate\"},{\"$ref\":\"#/definitions/CalendarEventPredicate\"}]},\"messageMatchFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"replayData\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/SimulatorReplayDatapoint\"},\"description\":\"Used to store 24h dataset of values that should be replayed (i.e. written to the linked attribute) in a continuous loop.\"}},\"title\":\"SimulatorAgentLink\",\"required\":[\"type\"]},\"SimulatorReplayDatapoint\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"timestamp\":{\"type\":\"integer\"},\"value\":{\"$ref\":\"#/definitions/PatternPropertiesSimpleKeyAnyType\"}},\"required\":[\"timestamp\"]},\"VelbusAgentLink\":{\"type\":\"object\",\"additionalProperties\":true,\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"VelbusAgentLink\"],\"default\":\"VelbusAgentLink\"},\"id\":{\"type\":\"string\",\"format\":\"or-agent-id\"},\"deviceAddress\":{\"type\":\"integer\",\"minimum\":1,\"maximum\":255},\"deviceValueLink\":{\"type\":\"string\",\"pattern\":\"^.*\\\\S+.*$\",\"minLength\":1},\"valueFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}},\"valueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValueConverter\":{\"type\":\"object\",\"patternProperties\":{\".+\":{\"type\":[\"null\",\"number\",\"integer\",\"boolean\",\"string\",\"array\",\"object\"]}}},\"writeValue\":{\"type\":\"string\"},\"messageMatchPredicate\":{\"oneOf\":[{\"$ref\":\"#/definitions/StringPredicate\"},{\"$ref\":\"#/definitions/BooleanPredicate\"},{\"$ref\":\"#/definitions/DateTimePredicate\"},{\"$ref\":\"#/definitions/NumberPredicate\"},{\"$ref\":\"#/definitions/RadialGeofencePredicate\"},{\"$ref\":\"#/definitions/RectangularGeofencePredicate\"},{\"$ref\":\"#/definitions/ArrayPredicate\"},{\"$ref\":\"#/definitions/ValueEmptyPredicate\"},{\"$ref\":\"#/definitions/ValueNotEmptyPredicate\"},{\"$ref\":\"#/definitions/CalendarEventPredicate\"}]},\"messageMatchFilters\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/regex\"},{\"$ref\":\"#/definitions/substring\"},{\"$ref\":\"#/definitions/jsonPath\"}]}}},\"title\":\"VelbusAgentLink\",\"required\":[\"type\",\"deviceAddress\",\"deviceValueLink\"]}}}");
if (!agent || !agentLink) {
agentLink = {
diff --git a/ui/component/or-json-forms/src/base-element.ts b/ui/component/or-json-forms/src/base-element.ts
index 0b0990d0e..9b9112aac 100644
--- a/ui/component/or-json-forms/src/base-element.ts
+++ b/ui/component/or-json-forms/src/base-element.ts
@@ -14,9 +14,10 @@ import {JsonFormsStateContext} from "./index";
* Adds additional props for layouts which are normally only available for controls
*/
export interface AdditionalProps {
- label: string;
- required: boolean;
+ label?: string;
+ required?: boolean;
errors?: string;
+ minimal?: boolean;
}
export abstract class BaseElement<T extends UISchemaElement, P extends OwnPropsOfRenderer> extends LitElement implements OwnPropsOfRenderer, AdditionalProps {
diff --git a/ui/component/or-json-forms/src/controls/control-array-element.ts b/ui/component/or-json-forms/src/controls/control-array-element.ts
index 7ff3febff..b4d85c978 100644
--- a/ui/component/or-json-forms/src/controls/control-array-element.ts
+++ b/ui/component/or-json-forms/src/controls/control-array-element.ts
@@ -1,6 +1,5 @@
import {
computeLabel,
- ControlElement,
createDefaultValue,
JsonSchema,
mapDispatchToArrayControlProps,
@@ -10,13 +9,13 @@ import {
update
} from "@jsonforms/core";
import {css, html, PropertyValues, TemplateResult, unsafeCSS} from "lit";
-import {customElement} from "lit/decorators.js";
-import {CombinatorInfo, getCombinatorInfos, getTemplateFromProps} from "../util";
+import {customElement, property} from "lit/decorators.js";
+import {CombinatorInfo, controlWithoutLabel, getCombinatorInfos, getTemplateFromProps} from "../util";
import {InputType, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";
import {i18next} from "@openremote/or-translate";
import {showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";
import "@openremote/or-mwc-components/or-mwc-list";
-import {baseStyle} from "../styles";
+import {addItemOrParameterDialogStyle, baseStyle} from "../styles";
import {ListItem, OrMwcListChangedEvent} from "@openremote/or-mwc-components/or-mwc-list";
import {DefaultColor4, DefaultColor5} from "@openremote/core";
import "../json-editor";
@@ -75,6 +74,10 @@ const style = css`
display: flex;
flex-direction: column;
}
+
+ #content .item-container:first-child {
+ margin-top: 0;
+ }
#add-parameter {
margin: 10px 0 0 4px;
@@ -131,15 +134,11 @@ const style = css`
}
`;
-const controlWithoutLabel = (scope: string): ControlElement => ({
- type: 'Control',
- scope: scope,
- label: false
-});
-
@customElement("or-json-forms-array-control")
export class ControlArrayElement extends ControlBaseElement {
+ @property()
+ protected minimal?: boolean;
protected resolvedSchema!: JsonSchema;
protected itemInfos: CombinatorInfo[] | undefined;
protected addItem!: (value: any) => void;
@@ -160,6 +159,8 @@ export class ControlArrayElement extends ControlBaseElement {
if (Array.isArray(this.resolvedSchema.anyOf)) {
this.itemInfos = getCombinatorInfos(this.resolvedSchema.anyOf, this.rootSchema);
+ } else if (Array.isArray(this.resolvedSchema.oneOf)) {
+ this.itemInfos = getCombinatorInfos(this.resolvedSchema.oneOf, this.rootSchema);
}
}
@@ -196,15 +197,17 @@ export class ControlArrayElement extends ControlBaseElement {
return html`
<div id="panel">
- <div id="header">
- <div id="expander"><or-icon icon="chevron-right"></or-icon><span>${this.label ? computeLabel(this.label, this.required, false) : ""}</span></div>
- <div id="header-buttons"><or-mwc-input .type="${InputType.BUTTON}" outlined .label="${i18next.t("json")}" icon="pencil" @click="${() => this._showJson()}"></or-mwc-input></div>
- </div>
+ ${this.minimal ? html`` : html`
+ <div id="header">
+ <div id="expander"><or-icon icon="chevron-right"></or-icon><span>${this.label ? computeLabel(this.label, this.required, false) : ""}</span></div>
+ <div id="header-buttons"><or-mwc-input .type="${InputType.BUTTON}" outlined .label="${i18next.t("json")}" icon="pencil" @click="${() => this._showJson()}"></or-mwc-input></div>
+ </div>
+ `}
<div id="content" @dragover="${(ev: DragEvent) => this._onDragOver(ev)}">
${!Array.isArray(this.data) ? `` : (this.data as any[]).map((item, index) => {
- const childPath = Paths.compose(this.path, `${index}`);
+ const childPath = Paths.compose(this.path, "" + index);
const constProp = this.itemInfos && this.itemInfos.length > 0 ? this.itemInfos[0].constProperty : undefined;
const childConstValue = constProp ? item[constProp] : undefined;
const childMatchedItemInfo = childConstValue ? this.itemInfos?.find(itemInfo => itemInfo.constValue === childConstValue) : undefined;
@@ -274,8 +277,13 @@ export class ControlArrayElement extends ControlBaseElement {
}
protected _onDragOver(ev: DragEvent) {
- ev.preventDefault();
+ const dragging = this.shadowRoot!.querySelector(".dragging") as HTMLDivElement;
+
+ if (!dragging) {
+ return;
+ }
+ ev.preventDefault();
const container = ev.currentTarget as HTMLDivElement;
const draggables = [...((this.shadowRoot!.querySelectorAll(".draggable:not(.dragging)") as any) as HTMLDivElement[])];
const initial = {offset: Number.NEGATIVE_INFINITY, element: null} as {
@@ -293,7 +301,6 @@ export class ControlArrayElement extends ControlBaseElement {
}
}, initial).element;
- const dragging = this.shadowRoot!.querySelector(".dragging") as HTMLDivElement;
draggables.forEach(draggable => draggable.classList.remove("indicator-before", "indicator-after"));
if (afterItem === null) {
@@ -406,41 +413,8 @@ export class ControlArrayElement extends ControlBaseElement {
</form>
</div>
`,
- styles: html`
- <style>
- .mdc-dialog__surface {
- width: 800px;
- overflow-x: visible !important;
- overflow-y: visible !important;
- }
- #dialog-content {
- border-color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
- border-top-width: 1px;
- border-top-style: solid;
- border-bottom-width: 1px;
- border-bottom-style: solid;
- padding: 0;
- overflow: visible;
- }
- form {
- display: flex;
- }
- #type-list {
- overflow: auto;
- min-width: 150px;
- max-width: 300px;
- flex: 0 0 40%;
- border-right: 1px solid var(--or-app-color5, #CCC);
- }
- #parameter-list {
- display: flex;
- }
- #parameter-desc {
- padding: 5px;
- }
- </style>
- `,
- title: i18next.t("addItem"),
+ styles: addItemOrParameterDialogStyle,
+ title: (this.label ? computeLabel(this.label, this.required, false) + " - " : "") + i18next.t("addItem"),
actions: [
{
actionName: "cancel",
diff --git a/ui/component/or-json-forms/src/controls/control-input-element.ts b/ui/component/or-json-forms/src/controls/control-input-element.ts
index 5bb9e2929..c799c8eb9 100644
--- a/ui/component/or-json-forms/src/controls/control-input-element.ts
+++ b/ui/component/or-json-forms/src/controls/control-input-element.ts
@@ -13,6 +13,7 @@ import {
JsonSchema
} from "@jsonforms/core";
import {isEnumArray} from "../standard-renderers";
+import {getSchemaConst} from "../util";
// language=CSS
const style = css`
@@ -50,7 +51,9 @@ export class ControlInputElement extends ControlBaseElement {
let multiple = false;
let value: any = this.data ?? schema.default;
- if (isBooleanControl(uischema, schema)) {
+ if (Array.isArray(schema.type)) {
+ this.inputType = InputType.JSON;
+ } else if (isBooleanControl(uischema, schema)) {
this.inputType = InputType.CHECKBOX;
} else if (isNumberControl(uischema, schema) || isIntegerControl(uischema, schema)) {
step = isNumberControl(uischema, schema) ? 0.1 : 1;
@@ -75,7 +78,7 @@ export class ControlInputElement extends ControlBaseElement {
this.inputType = InputType.SELECT;
if (isEnumControl(uischema, schema)) {
- if (schema.const) {
+ if (getSchemaConst(schema) !== undefined) {
// Don't show const
return html``;
}
diff --git a/ui/component/or-json-forms/src/layouts/layout-vertical-element.ts b/ui/component/or-json-forms/src/layouts/layout-vertical-element.ts
index df2da75d6..7858e9e71 100644
--- a/ui/component/or-json-forms/src/layouts/layout-vertical-element.ts
+++ b/ui/component/or-json-forms/src/layouts/layout-vertical-element.ts
@@ -5,21 +5,24 @@ import {
getSchema,
GroupLayout,
isControl,
+ JsonSchema,
mapStateToControlProps,
OwnPropsOfControl,
OwnPropsOfRenderer,
+ Paths,
+ RendererProps,
StatePropsOfControl,
VerticalLayout
} from "@jsonforms/core";
import {css, html, TemplateResult, unsafeCSS} from "lit";
-import {customElement} from "lit/decorators.js";
+import {customElement, property} from "lit/decorators.js";
import {LayoutBaseElement} from "./layout-base-element";
-import {getLabel, getTemplateFromProps} from "../util";
+import {controlWithoutLabel, getLabel, getTemplateFromProps} from "../util";
import {InputType, OrInputChangedEvent, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";
import {i18next} from "@openremote/or-translate";
import {showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";
import "@openremote/or-mwc-components/or-mwc-list";
-import {baseStyle} from "../styles";
+import {addItemOrParameterDialogStyle, baseStyle} from "../styles";
import {ListItem, OrMwcListChangedEvent} from "@openremote/or-mwc-components/or-mwc-list";
import {DefaultColor5} from "@openremote/core";
import "../json-editor";
@@ -96,6 +99,7 @@ const style = css`
.key-container, .value-container {
padding: 10px;
+ vertical-align: top;
}
.key-container or-mwc-input, .value-container or-mwc-input {
@@ -105,11 +109,32 @@ const style = css`
.delete-container {
vertical-align: middle;
}
+
+ .value-container > .item-container {
+ margin: 0;
+ }
+
+ .value-container > .item-container > .delete-container {
+ display: none;
+ }
+
+ .value-container > .item-container :first-child {
+ border: 0;
+ padding: 0;
+ margin: 0;
+ flex: 1;
+ }
`;
+function isDynamic(schema: JsonSchema): boolean {
+ return schema.allOf === undefined && schema.anyOf === undefined && (schema.properties === undefined || Object.keys(schema.properties).length === 0);
+}
+
@customElement("or-json-forms-vertical-layout")
export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | GroupLayout> {
+ @property()
+ protected minimal?: boolean;
public handleChange!: (path: string, data: any) => void;
public static get styles() {
@@ -119,51 +144,44 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | Gr
];
}
- get dynamic(): boolean {
- return this.schema.allOf === undefined && this.schema.anyOf === undefined && this.schema.properties === undefined;
- }
-
render() {
const optionalProps: StatePropsOfControl[] = [];
const jsonFormsState = {jsonforms: {...this.state}};
const rootSchema = getSchema(jsonFormsState);
- const dynamic = this.dynamic;
- let dynamicValueType: InputType = InputType.JSON;
+ const dynamic = isDynamic(this.schema);
+ let dynamicPropertyRegex = ".+";
+ let dynamicValueSchema: JsonSchema | undefined;
- if (this.schema.patternProperties && this.schema.patternProperties.hasOwnProperty("*") && this.schema.patternProperties["*"].type && !Array.isArray(this.schema.patternProperties["*"].type)) {
- switch(this.schema.patternProperties["*"].type) {
- case "boolean":
- dynamicValueType = InputType.CHECKBOX;
- break;
- case "string":
- dynamicValueType = InputType.TEXT;
- break;
- case "array":
- // TODO: Implement array if required
- console.log("Array support not implemented.");
- break;
- case "number":
- dynamicValueType = InputType.NUMBER;
- break;
+ if (dynamic) {
+ if (typeof this.schema.patternProperties === "object") {
+ const patternObjs = Object.entries(this.schema.patternProperties);
+ if (patternObjs.length === 1) {
+ dynamicPropertyRegex = patternObjs[0][0];
+ dynamicValueSchema = (patternObjs[0][1] as JsonSchema);
+ }
+ } else if (typeof this.schema.additionalProperties === "object") {
+ dynamicValueSchema = this.schema.additionalProperties;
}
}
return html`
<div id="panel">
- <div id="header">
- <div id="expander">
- <or-icon icon="chevron-right"></or-icon>
- <span>${this.label ? computeLabel(this.label, this.required, false) : ""}</span>
+ ${this.minimal ? html`` : html`
+ <div id="header">
+ <div id="expander">
+ <or-icon icon="chevron-right"></or-icon>
+ <span>${this.label ? computeLabel(this.label, this.required, false) : ""}</span>
+ </div>
+ ${!this.errors ? `` : html`<div id="errors"><or-icon icon="alert"></or-icon><span>${this.errors}</span></div>`}
+ <div id="header-buttons"><or-mwc-input .type="${InputType.BUTTON}" outlined .label="${i18next.t("json")}" icon="pencil" @click="${() => this._showJson()}"></or-mwc-input></div>
</div>
- ${!this.errors ? `` : html`<div id="errors"><or-icon icon="alert"></or-icon><span>${this.errors}</span></div>`}
- <div id="header-buttons"><or-mwc-input .type="${InputType.BUTTON}" outlined .label="${i18next.t("json")}" icon="pencil" @click="${() => this._showJson()}"></or-mwc-input></div>
- </div>
+ `}
<div id="content">
${this.errors ? ``
- : dynamic ?
- this._getDynamicContentTemplate(dynamicValueType)
+ : dynamic && dynamicValueSchema ?
+ this._getDynamicContentTemplate(dynamicPropertyRegex, dynamicValueSchema)
: this.getChildProps().map((props: OwnPropsOfRenderer) => {
const contentProps: OwnPropsOfRenderer & AdditionalProps = {
@@ -192,33 +210,63 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | Gr
${this.errors ? `` : html`
<div id="add-parameter">
- <or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t("addParameter")}" icon="plus" .disabled="${!dynamic && optionalProps.length === 0}" @click="${() => this._addParameter(optionalProps, dynamicValueType)}"></or-mwc-input>
+ <or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t("addParameter")}" icon="plus" .disabled="${!dynamic && optionalProps.length === 0}" @click="${() => this._addParameter(optionalProps, dynamicPropertyRegex, dynamicValueSchema)}"></or-mwc-input>
</div>`}
</div>
`;
}
- protected _getDynamicContentTemplate(dynamicValueType: InputType): TemplateResult {
+ protected _getDynamicContentTemplate(dynamicPropertyRegex: string, dynamicValueSchema: JsonSchema): TemplateResult {
if (!this.data) {
return html``;
}
const deleteHandler = (key: string) => {
- const data = this.data || {};
+ const data = {...this.data};
delete data[key];
this.handleChange(this.path, data);
};
+ const keyChangeHandler = (orInput: OrMwcInput, oldKey: string, newKey: string) => {
+
+ if (!orInput.valid) {
+ return;
+ }
+
+ const data = {...this.data};
+ const value = data[oldKey];
+ delete data[oldKey];
+ data[newKey] = value;
+ this.handleChange(this.path, data);
+ };
+
+ const props: RendererProps & AdditionalProps = {
+ renderers: this.renderers,
+ uischema: controlWithoutLabel("#"),
+ enabled: this.enabled,
+ visible: this.visible,
+ path: "",
+ schema: dynamicValueSchema,
+ minimal: true,
+ required: false,
+ label: ""
+ };
+
+ const getDynamicValueTemplate: (key: string, value: any) => TemplateResult = (key, value) => {
+ props.path = Paths.compose(this.path, key);
+ return getTemplateFromProps(this.state, props);
+ };
+
return html`
<div id="dynamic-wrapper">
${Object.entries(this.data).map(([key, value]) => {
return html`
<div class="row">
<div class="key-container">
- <or-mwc-input .type="${InputType.TEXT}" .value="${key}"></or-mwc-input>
+ <or-mwc-input .type="${InputType.TEXT}" @or-mwc-input-changed="${(ev:OrInputChangedEvent) => keyChangeHandler(ev.currentTarget as OrMwcInput, key, ev.detail.value)}" required .pattern="${dynamicPropertyRegex}" .value="${key}"></or-mwc-input>
</div>
<div class="value-container">
- <or-mwc-input .type="${dynamicValueType}" .value="${value}"></or-mwc-input>
+ ${getDynamicValueTemplate(key, value)}
</div>
<div class="delete-container">
<button class="button-clear" @click="${() => deleteHandler(key)}"><or-icon icon="close-circle"></or-icon></input>
@@ -279,7 +327,7 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | Gr
)
}
- protected _addParameter(optionalProps: StatePropsOfControl[], dynamicValueType: InputType) {
+ protected _addParameter(optionalProps: StatePropsOfControl[], dynamicPropertyRegex?: string, dynamicValueSchema?: JsonSchema) {
const dynamic = optionalProps.length === 0;
let selectedParameter: StatePropsOfControl | undefined;
@@ -300,10 +348,23 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | Gr
(dialog.shadowRoot!.getElementById("add-btn") as OrMwcInput).disabled = false;
};
- const keyValue: [any, any] = [undefined, undefined];
- const onKeyValueChanged = (value: any, index: 0 | 1) => {
- keyValue[index] = value;
- const valid = keyValue[0] && keyValue[1] !== undefined;
+ // const keyValue: [any, any] = [undefined, undefined];
+ // const onKeyValueChanged = (value: any, index: 0 | 1) => {
+ // keyValue[index] = value;
+ // const valid = keyValue[0] && keyValue[1] !== undefined;
+ // (dialog.shadowRoot!.getElementById("add-btn") as OrMwcInput).disabled = !valid;
+ // };
+ let keyValue: string | undefined;
+ const onKeyChanged = (event: OrInputChangedEvent) => {
+ const keyInput = event.currentTarget as OrMwcInput;
+ keyInput.setCustomValidity(undefined);
+ keyValue = event.detail.value as string;
+ let valid = keyInput.valid;
+
+ if (this.data[keyValue] !== undefined) {
+ valid = false;
+ keyInput.setCustomValidity(i18next.t("keyAlreadyExists"));
+ }
(dialog.shadowRoot!.getElementById("add-btn") as OrMwcInput).disabled = !valid;
};
@@ -311,9 +372,11 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | Gr
content: html`
<div class="col">
<form id="mdc-dialog-form-add" class="row">
- <div id="type-list" class="col">
- ${dynamic ? `` : html`<or-mwc-list @or-mwc-list-changed="${(evt: OrMwcListChangedEvent) => {if (evt.detail.length === 1) onParamChanged((evt.detail[0] as ListItem).data as StatePropsOfControl); }}" .listItems="${listItems}" id="parameter-list"></or-mwc-list>`}
- </div>
+ ${dynamic ? `` : html`
+ <div id="type-list" class="col">
+ <or-mwc-list @or-mwc-list-changed="${(evt: OrMwcListChangedEvent) => {if (evt.detail.length === 1) onParamChanged((evt.detail[0] as ListItem).data as StatePropsOfControl); }}" .listItems="${listItems}" id="parameter-list"></or-mwc-list>
+ </div>
+ `}
<div id="parameter-desc" class="col">
${!dynamic ? `` : html`
<style>
@@ -323,50 +386,15 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | Gr
}
</style>
<div id="dynamic-wrapper">
- <or-mwc-input .type="${InputType.TEXT}" .label="${i18next.t("key")}" @or-mwc-input-changed="${(evt: OrInputChangedEvent) => onKeyValueChanged(evt.detail.value, 0)}"></or-mwc-input>
- <or-mwc-input .type="${dynamicValueType}" .label="${i18next.t("value")}" @or-mwc-input-changed="${(evt: OrInputChangedEvent) => onKeyValueChanged(evt.detail.value, 1)}"></or-mwc-input>
+ <or-mwc-input required .type="${InputType.TEXT}" .pattern="${dynamicPropertyRegex}" .label="${i18next.t("key")}" @or-mwc-input-changed="${(evt: OrInputChangedEvent) => onKeyChanged(evt)}"></or-mwc-input>
</div>
`}
</div>
</form>
</div>
`,
- styles: html`
- <style>
- .mdc-dialog__surface {
- width: 800px;
- overflow-x: visible !important;
- overflow-y: visible !important;
- }
- #dialog-content {
- border-color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
- border-top-width: 1px;
- border-top-style: solid;
- border-bottom-width: 1px;
- border-bottom-style: solid;
- padding: 0;
- overflow: visible;
- }
- form {
- display: flex;
- }
- #type-list {
- overflow: auto;
- min-width: 150px;
- max-width: 300px;
- flex: 0 0 40%;
- border-right: 1px solid var(--or-app-color5, #CCC);
- }
- #parameter-list {
- display: flex;
- }
- #parameter-desc {
- flex: 1;
- padding: 5px;
- }
- </style>
- `,
- title: i18next.t("addParameter"),
+ styles: addItemOrParameterDialogStyle,
+ title: (this.label ? computeLabel(this.label, this.required, false) + " - " : "") + i18next.t("addParameter"),
actions: [
{
actionName: "cancel",
@@ -376,9 +404,10 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | Gr
default: true,
actionName: "add",
action: () => {
+ const key = dynamic ? keyValue as string : selectedParameter!.path.split(".").pop()!;
const data = {...this.data};
- const key = dynamic ? keyValue[0] as string : selectedParameter!.path.split(".").pop()!;
- data[key] = dynamic ? keyValue[1] : createDefaultValue(selectedParameter!.schema);
+ const schema = dynamic ? dynamicValueSchema! : selectedParameter!.schema;
+ data[key] = Array.isArray(schema.type) ? null : createDefaultValue(schema);
this.handleChange(this.path || "", data);
},
content: html`<or-mwc-input id="add-btn" .type="${InputType.BUTTON}" disabled .label="${i18next.t("add")}"></or-mwc-input>`
diff --git a/ui/component/or-json-forms/src/standard-renderers.ts b/ui/component/or-json-forms/src/standard-renderers.ts
index 3395374d1..b0b4045c7 100644
--- a/ui/component/or-json-forms/src/standard-renderers.ts
+++ b/ui/component/or-json-forms/src/standard-renderers.ts
@@ -15,6 +15,7 @@ import {
isIntegerControl,
isNumberControl,
isObjectControl,
+ isOneOfControl,
isOneOfEnumControl,
isStringControl,
isTimeControl,
@@ -33,13 +34,20 @@ import {
resolveSubSchemas,
schemaMatches,
schemaSubPathMatches,
+ StatePropsOfControlWithDetail,
Tester,
uiTypeIs
} from "@jsonforms/core";
import {html, TemplateResult} from "lit";
import "@openremote/or-mwc-components/or-mwc-input";
import {JsonFormsStateContext} from "./index";
-import {getCombinatorInfos, getLabel, getTemplateFromProps, mapStateToCombinatorRendererProps} from "./util";
+import {
+ getCombinatorInfos,
+ getLabel,
+ getSchemaConst,
+ getTemplateFromProps,
+ mapStateToCombinatorRendererProps
+} from "./util";
import "./layouts/layout-vertical-element";
import "./controls/control-input-element";
import "./controls/control-array-element";
@@ -52,7 +60,7 @@ const hasOneOfItems = (schema: JsonSchema): boolean =>
schema.oneOf !== undefined &&
schema.oneOf.length > 0 &&
(schema.oneOf as JsonSchema[]).every((entry: JsonSchema) => {
- return entry.const !== undefined;
+ return getSchemaConst(entry) !== undefined;
});
const hasEnumItems = (schema: JsonSchema): boolean =>
@@ -87,7 +95,8 @@ export const verticalLayoutRenderer = (state: JsonFormsStateContext, props: OwnP
...mapDispatchToControlProps(state.dispatch),
label: props.label,
required: props.required,
- errors: props.errors
+ errors: props.errors,
+ minimal: props.minimal
};
const template = html`<or-json-forms-vertical-layout .state="${state}" .props="${contentProps}"></or-json-forms-vertical-layout>`;
@@ -138,7 +147,7 @@ export const objectControlTester: RankedTester = rankWith(
2,
isObjectControl
);
-export const objectControlRenderer = (state: JsonFormsStateContext, props: ControlProps) => {
+export const objectControlRenderer = (state: JsonFormsStateContext, props: ControlProps & AdditionalProps) => {
const {
required,
renderers,
@@ -174,17 +183,21 @@ export const objectControlRenderer = (state: JsonFormsStateContext, props: Contr
cells: cells,
label: props.label || getLabel(schema, rootSchema, label) || "",
required: !!props.required || !!required,
- errors: errors
+ errors: errors,
+ minimal: props.minimal
};
return getTemplateFromProps(state, contentProps);
}
-export const anyOfControlTester: RankedTester = rankWith(
+export const anyOfOneOfControlTester: RankedTester = rankWith(
4,
- isAnyOfControl
+ or(
+ isAnyOfControl,
+ isOneOfControl
+ )
);
-export const anyOfControlRenderer = (state: JsonFormsStateContext, props: ControlProps) => {
+export const anyOfOneOfControlRenderer = (state: JsonFormsStateContext, props: ControlProps & AdditionalProps) => {
const jsonFormsContext = {jsonforms: {...state}};
@@ -203,38 +216,39 @@ export const anyOfControlRenderer = (state: JsonFormsStateContext, props: Contro
data
} = mapStateToControlWithDetailProps(jsonFormsContext, props);
- const anyOfSchema = resolveSubSchemas(schema, rootSchema, "anyOf");
- const anyOfProps = mapStateToCombinatorRendererProps(jsonFormsContext, props, "anyOf");
+ const keyword = schema.anyOf !== undefined ? "anyOf" : "oneOf";
+ const resolvedSchema = resolveSubSchemas(schema, rootSchema, keyword);
+ const resolvedProps = mapStateToCombinatorRendererProps(jsonFormsContext, props, keyword);
- const anyOfRenderInfos = createCombinatorRenderInfos(
- anyOfSchema.anyOf!,
+ const renderInfos = createCombinatorRenderInfos(
+ resolvedSchema[keyword]!,
rootSchema,
- "anyOf",
- anyOfProps.uischema || uischema,
+ keyword,
+ resolvedProps.uischema || uischema,
path,
- anyOfProps.uischemas
+ resolvedProps.uischemas
);
- if (data !== undefined && (anyOfProps.indexOfFittingSchema === undefined || anyOfProps.indexOfFittingSchema < 0)) {
+ if (data !== undefined && (resolvedProps.indexOfFittingSchema === undefined || resolvedProps.indexOfFittingSchema < 0)) {
// Try and match the data using our own combinator info objects
- const combinatorInfos = getCombinatorInfos(anyOfSchema.anyOf!, rootSchema);
+ const combinatorInfos = getCombinatorInfos(resolvedSchema[keyword]!, rootSchema);
const constProp = combinatorInfos.length > 0 ? combinatorInfos[0].constProperty : undefined;
if (constProp && typeof data === "object" && data[constProp]) {
const dataType = data[constProp];
- anyOfProps.indexOfFittingSchema = combinatorInfos.findIndex((combinatorInfo) => combinatorInfo.constValue === dataType);
+ resolvedProps.indexOfFittingSchema = combinatorInfos.findIndex((combinatorInfo) => combinatorInfo.constValue === dataType);
}
}
- if (anyOfProps.indexOfFittingSchema === undefined || anyOfProps.indexOfFittingSchema < 0) {
+ if (resolvedProps.indexOfFittingSchema === undefined || resolvedProps.indexOfFittingSchema < 0) {
if (data !== undefined) {
// We have data that doesn't match a schema so show invalid template
- console.warn("Cannot match anyOf schema to instance data");
+ console.warn("Cannot match " + keyword + " schema to instance data");
return invalidTemplate(props.label || label);
} else {
// We have no data so show a schema picker
const { handleChange } = mapDispatchToControlProps(state.dispatch);
- const combinatorInfos = getCombinatorInfos(anyOfSchema.anyOf!, rootSchema);
+ const combinatorInfos = getCombinatorInfos(resolvedSchema[keyword]!, rootSchema);
const options: [string, string][] = combinatorInfos.map((combinatorInfo, index) => [index+"", Util.camelCaseToSentenceCase(combinatorInfo.title) || i18next.t("Item ") + (index+1)]);
const pickerUpdater = (index: number) => {
const matchedInfo = combinatorInfos[index];
@@ -247,9 +261,9 @@ export const anyOfControlRenderer = (state: JsonFormsStateContext, props: Contro
}
}
- // Return template for the anyOf schema that matches the data
- const matchedSchema = anyOfRenderInfos[anyOfProps.indexOfFittingSchema].schema;
- let matchedUischema = anyOfRenderInfos[anyOfProps.indexOfFittingSchema].uischema;
+ // Return template for the anyOf/oneOf schema that matches the data
+ const matchedSchema = renderInfos[resolvedProps.indexOfFittingSchema].schema;
+ let matchedUischema = renderInfos[resolvedProps.indexOfFittingSchema].uischema;
if (matchedSchema.allOf) {
// Force the uischema to be a simple control so it goes through the allOf renderer
@@ -268,7 +282,8 @@ export const anyOfControlRenderer = (state: JsonFormsStateContext, props: Contro
cells: cells,
label: props.label || getLabel(matchedSchema, rootSchema, label) || "",
required: props.required || !!required,
- errors: errors
+ errors: errors,
+ minimal: props.minimal
}
return getTemplateFromProps(state, contentProps);
@@ -280,7 +295,7 @@ export const allOfControlTester: RankedTester = rankWith(
);
export const allOfControlRenderer = (state: JsonFormsStateContext, props: ControlProps & AdditionalProps) => {
const jsonFormsContext = {jsonforms: {...state}};
- const contentProps = {
+ const contentProps: StatePropsOfControlWithDetail & AdditionalProps = {
...mapStateToControlWithDetailProps(jsonFormsContext, props)
};
@@ -292,6 +307,7 @@ export const allOfControlRenderer = (state: JsonFormsStateContext, props: Contro
contentProps.label = props.label || contentProps.label;
contentProps.required = !!props.required || contentProps.required;
+ contentProps.minimal = props.minimal;
return getTemplateFromProps(state, contentProps);
}
@@ -303,14 +319,15 @@ export const arrayControlTester: RankedTester = rankWith(
schema => hasType(schema, 'array') && !Array.isArray(schema.items) // we don't care about tuples
)
);
-export const arrayControlRenderer = (state: JsonFormsStateContext, props: ControlProps) => {
- const contentProps: ControlProps = {
+export const arrayControlRenderer = (state: JsonFormsStateContext, props: ControlProps & AdditionalProps) => {
+ const contentProps: ControlProps & AdditionalProps = {
...mapStateToControlProps({jsonforms: {...state}}, props),
...mapDispatchToControlProps(state.dispatch)
};
contentProps.label = props.label || contentProps.label;
contentProps.required = !!props.required || contentProps.required;
+ contentProps.minimal = props.minimal;
const template = html`<or-json-forms-array-control .state="${state}" .props="${contentProps}"></or-json-forms-array-control>`;
let deleteHandler: undefined | (() => void);
@@ -352,6 +369,6 @@ export const StandardRenderers: JsonFormsRendererRegistryEntry[] = [
{tester: inputControlTester, renderer: inputControlRenderer},
{tester: objectControlTester, renderer: objectControlRenderer},
{tester: arrayControlTester, renderer: arrayControlRenderer},
- {tester: anyOfControlTester, renderer: anyOfControlRenderer},
+ {tester: anyOfOneOfControlTester, renderer: anyOfOneOfControlRenderer},
{tester: allOfControlTester, renderer: allOfControlRenderer}
];
diff --git a/ui/component/or-json-forms/src/styles.ts b/ui/component/or-json-forms/src/styles.ts
index f0f1bb622..d39f2dbab 100644
--- a/ui/component/or-json-forms/src/styles.ts
+++ b/ui/component/or-json-forms/src/styles.ts
@@ -1,5 +1,5 @@
import {DefaultColor4, DefaultColor5 } from "@openremote/core";
-import { css, unsafeCSS } from "lit";
+import { css, html, unsafeCSS } from "lit";
// language=CSS
export const baseStyle = css`
@@ -46,3 +46,40 @@ export const baseStyle = css`
min-width: 200px;
}
`;
+
+// language=HTML
+export const addItemOrParameterDialogStyle = html`
+ <style>
+ .mdc-dialog__surface {
+ width: 800px;
+ overflow-x: visible !important;
+ overflow-y: visible !important;
+ }
+ #dialog-content {
+ border-color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
+ border-top-width: 1px;
+ border-top-style: solid;
+ border-bottom-width: 1px;
+ border-bottom-style: solid;
+ padding: 0;
+ overflow: visible;
+ }
+ form {
+ display: flex;
+ }
+ #type-list {
+ overflow: auto;
+ min-width: 150px;
+ max-width: 300px;
+ flex: 0 0 40%;
+ border-right: 1px solid var(--or-app-color5, #CCC);
+ }
+ #parameter-list {
+ display: block;
+ }
+ #parameter-desc {
+ padding: 5px;
+ flex: 1;
+ }
+ </style>
+`;
diff --git a/ui/component/or-json-forms/src/util.ts b/ui/component/or-json-forms/src/util.ts
index 2ec1b6109..1a1679838 100644
--- a/ui/component/or-json-forms/src/util.ts
+++ b/ui/component/or-json-forms/src/util.ts
@@ -1,7 +1,7 @@
import {
CombinatorKeyword,
composeWithUi,
- createCleanLabel,
+ ControlElement,
createDefaultValue,
deriveTypes,
getAjv,
@@ -15,22 +15,17 @@ import {
JsonFormsSubStates,
JsonSchema,
JsonSchema4,
- mapStateToControlProps,
- mapStateToControlWithDetailProps,
OwnPropsOfControl,
OwnPropsOfRenderer,
Resolve,
resolveSchema,
resolveSubSchemas,
StatePropsOfCombinator,
- StatePropsOfControl,
- StatePropsOfControlWithDetail,
- UISchemaElement,
} from "@jsonforms/core";
-import { Util } from "@openremote/core";
+import {Util} from "@openremote/core";
import {html, TemplateResult} from "lit";
-import {ErrorObject, JsonFormsStateContext} from "./index";
-import { unknownTemplate } from "./standard-renderers";
+import {ErrorObject} from "./index";
+import {unknownTemplate} from "./standard-renderers";
export function getTemplateFromProps<T extends OwnPropsOfRenderer>(state: JsonFormsSubStates | undefined, props: T | undefined): TemplateResult {
if (!state || !props) {
@@ -86,19 +81,19 @@ export function getCombinatorInfos(schemas: JsonSchema[], rootSchema: JsonSchema
if (deriveTypes(schema).every(type => type === "object")) {
const props = getSchemaObjectProperties(schema);
- const constProp = props.find(([propName, propSchema]) => propSchema.const !== undefined);
+ const constProp = props.find(([propName, propSchema]) => getSchemaConst(propSchema) !== undefined);
if (constProp) {
constProperty = constProp[0];
- constValue = constProp[1].const;
+ constValue = getSchemaConst(constProp[1]);
creator = () => {
const obj: any = {};
- obj[constProp[0]] = constProp[1].const;
+ obj[constProp[0]] = getSchemaConst(constProp[1]);
return obj;
}
if (!titleAndDescription[0]) {
- titleAndDescription[0] = constProp[1].const;
+ titleAndDescription[0] = getSchemaConst(constProp[1]);
}
} else {
creator = () => createDefaultValue(schema);
@@ -109,7 +104,7 @@ export function getCombinatorInfos(schemas: JsonSchema[], rootSchema: JsonSchema
}
return {
- title: titleAndDescription[0],
+ title: Util.camelCaseToSentenceCase(titleAndDescription[0]),
description: titleAndDescription[1],
defaultValueCreator: creator,
constProperty: constProperty,
@@ -118,6 +113,20 @@ export function getCombinatorInfos(schemas: JsonSchema[], rootSchema: JsonSchema
});
}
+export function getSchemaConst(schema: JsonSchema): any {
+ if (!schema) {
+ return;
+ }
+
+ if (schema.const !== undefined) {
+ return schema.const;
+ }
+
+ if (Array.isArray(schema.enum) && schema.enum!.length === 1) {
+ return schema.enum[0];
+ }
+}
+
export function findSchemaTitleAndDescription(schema: JsonSchema, rootSchema: JsonSchema): [string | undefined, string | undefined] {
let title: string | undefined;
@@ -138,8 +147,6 @@ export function findSchemaTitleAndDescription(schema: JsonSchema, rootSchema: Js
if (titledSchema) {
return [titledSchema.title, titledSchema.description];
}
-
-
}
return [title, undefined];
@@ -293,3 +300,8 @@ export function resolveSubSchemasRecursive(
return schema;
}
+export const controlWithoutLabel = (scope: string): ControlElement => ({
+ type: 'Control',
+ scope: scope,
+ label: false
+});
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 077a3fe16..bd0e59773 100644
--- a/ui/component/or-mwc-components/src/or-mwc-input.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-input.ts
@@ -1080,7 +1080,18 @@ export class OrMwcInput extends LitElement {
if (valMinMax.some((v) => typeof (v) !== "string")) {
if (this.type === InputType.JSON) {
- valMinMax[0] = valMinMax[0] !== undefined && valMinMax[0] !== null ? (typeof valMinMax[0] === "string" ? valMinMax[0] : JSON.stringify(valMinMax[0], null, 2)) : "";
+ if (valMinMax[0] !== undefined) {
+ if (typeof valMinMax[0] !== "string" || valMinMax[0] === null) {
+ try {
+ valMinMax[0] = JSON.stringify(valMinMax[0], null, 2);
+ } catch (e) {
+ console.warn("Failed to parse JSON expression for input control");
+ valMinMax[0] = "";
+ }
+ }
+ } else {
+ valMinMax[0] = "";
+ }
} else {
const format = this.format ? {...this.format} : {};
@@ -1165,7 +1176,7 @@ export class OrMwcInput extends LitElement {
if ((e.code === "Enter" || e.code === "NumpadEnter")) {
this.onValueChange((e.target as HTMLInputElement), (e.target as HTMLInputElement).value, true);
}}}"
- @blur="${(e: Event) => this.reportValidity()}"
+ @blur="${(e: Event) => {if ((e.target as HTMLInputElement).value === "") this.reportValidity()}}"
@change="${(e: Event) => this.onValueChange((e.target as HTMLInputElement), (e.target as HTMLInputElement).value)}" />`;
inputElem = html`
@@ -1258,10 +1269,6 @@ export class OrMwcInput extends LitElement {
protected updated(_changedProperties: PropertyValues): void {
super.updated(_changedProperties);
- if (this.autoValidate) {
- this.reportValidity();
- }
-
if (_changedProperties.has("type")) {
const component = this.shadowRoot!.getElementById("component");
if (this._mdcComponent) {
@@ -1397,6 +1404,10 @@ export class OrMwcInput extends LitElement {
(this._mdcComponent as any).required = this.required;
}
+
+ if (this.autoValidate) {
+ this.reportValidity();
+ }
}
protected renderOutlined(labelTemplate: TemplateResult | undefined) {
@@ -1424,11 +1435,20 @@ export class OrMwcInput extends LitElement {
public checkValidity(): boolean {
const elem = this.shadowRoot!.getElementById("elem") as any;
+ let valid = true;
if (elem && elem.validity) {
const nativeValidity = elem.validity as ValidityState;
- return nativeValidity.valid;
+ valid = nativeValidity.valid;
}
- return true;
+
+ if (valid && this.type === InputType.JSON) {
+ // JSON needs special validation - if no text value but this.value then parsing failed
+ if (this.value !== undefined && (this._mdcComponent as MDCTextField).value === "") {
+ valid = false;
+ }
+ }
+
+ return valid;
}
public reportValidity(): boolean {
@@ -1444,9 +1464,8 @@ export class OrMwcInput extends LitElement {
protected onValueChange(elem: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | undefined, newValue: any | undefined, enterPressed?: boolean) {
- this.reportValidity();
-
let previousValue = this.value;
+ let errorMsg: string | undefined;
if (newValue === "undefined") {
previousValue = null;
@@ -1467,21 +1486,37 @@ export class OrMwcInput extends LitElement {
case InputType.JSON:
case InputType.NUMBER:
case InputType.RANGE:
- newValue = newValue !== "" ? JSON.parse(newValue) : null;
+ if (newValue === "") {
+ newValue = null;
+ } else {
+ try {
+ newValue = JSON.parse(newValue);
+ } catch (e) {
+ newValue = this.value;
+ errorMsg = this.type === InputType.JSON ? i18next.t("validation.invalidJSON") : i18next.t("validation.invalidNumber");
+ }
+ }
break;
case InputType.DATETIME:
if (newValue === "") {
newValue = null;
} else {
- const date = Date.parse(newValue);
- const offset = (new Date()).getTimezoneOffset() * 60000;
- newValue = date + offset;
+ try {
+ const date = Date.parse(newValue);
+ const offset = (new Date()).getTimezoneOffset() * 60000;
+ newValue = date + offset;
+ } catch (e) {
+ newValue = this.value;
+ errorMsg = i18next.t("validation.invalidDate");
+ }
}
break;
}
}
this.value = newValue;
+ this.setCustomValidity(errorMsg);
+ this.reportValidity();
if (newValue !== previousValue) {
if (this.type === InputType.RANGE) {