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: Work on or-json-forms

Rich Turner407685d5c3d5
diff --git a/manager/src/web/shared/locales/en/or.json b/manager/src/web/shared/locales/en/or.json
index 8ca468a1d..589fda619 100644
--- a/manager/src/web/shared/locales/en/or.json
+++ b/manager/src/web/shared/locales/en/or.json
@@ -407,5 +407,6 @@
"agentTypeMismatch": "Agent type mismatch",
"loadFailedRoles": "Failed to load roles",
"loadFailedUsers": "Failed to load users",
- "loadFailedServiceUsers": "Failed to load service users"
+ "loadFailedServiceUsers": "Failed to load service users",
+ "key": "Key"
}
diff --git a/model/src/main/java/org/openremote/model/value/RegexValueFilter.java b/model/src/main/java/org/openremote/model/value/RegexValueFilter.java
index a41d997a5..a63e20807 100644
--- a/model/src/main/java/org/openremote/model/value/RegexValueFilter.java
+++ b/model/src/main/java/org/openremote/model/value/RegexValueFilter.java
@@ -22,6 +22,7 @@ package org.openremote.model.value;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.openremote.model.util.ValueUtil;
import java.util.Optional;
@@ -33,6 +34,7 @@ public class RegexValueFilter extends ValueFilter {
public static final String NAME = "regex";
+ @JsonSerialize(as=String.class)
public Pattern pattern;
public Integer matchGroup;
public Integer matchIndex;
diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.ts
index 2b8918f4f..b34534e6e 100644
--- a/ui/component/core/src/util.ts
+++ b/ui/component/core/src/util.ts
@@ -657,7 +657,7 @@ function mergeObjectKey(destination: object, path: string[], key: string, value:
return;
}
- if (dest.hasOwnProperty(key)) {
+ if (!dest.hasOwnProperty(key)) {
if (value === null || value === undefined) {
delete dest[key];
} else if (Array.isArray(value)) {
@@ -883,3 +883,47 @@ export function dispatchCancellableEvent<T>(target: EventTarget, event: CustomEv
return deferred.promise;
}
+
+// left: 37, up: 38, right: 39, down: 40,
+// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
+const keys = {37: 1, 38: 1, 39: 1, 40: 1};
+function preventDefault(e: Event) {
+ e.preventDefault();
+}
+function preventDefaultForScrollKeys(e: KeyboardEvent) {
+ if ((keys as any)[e.keyCode]) {
+ preventDefault(e);
+ return false;
+ }
+}
+
+// modern Chrome requires { passive: false } when adding event
+let supportsPassive = false;
+try {
+ // @ts-ignore
+ window.addEventListener("test", null, Object.defineProperty({}, 'passive', {
+ get: () => { supportsPassive = true; }
+ }));
+// tslint:disable-next-line:no-empty
+} catch(e) {}
+
+const wheelOpt = supportsPassive ? { passive: false } : false;
+const wheelEvent = "onwheel" in document.createElement("div") ? "wheel" : "mousewheel";
+
+// call this to Disable
+export function disableScroll() {
+ window.addEventListener('DOMMouseScroll', preventDefault, false); // older FF
+ window.addEventListener(wheelEvent, preventDefault, wheelOpt); // modern desktop
+ window.addEventListener('touchmove', preventDefault, wheelOpt); // mobile
+ window.addEventListener('keydown', preventDefaultForScrollKeys, false);
+}
+
+// call this to Enable
+export function enableScroll() {
+ window.removeEventListener('DOMMouseScroll', preventDefault, false);
+ // @ts-ignore
+ window.removeEventListener(wheelEvent, preventDefault, wheelOpt);
+ // @ts-ignore
+ window.removeEventListener('touchmove', preventDefault, wheelOpt);
+ window.removeEventListener('keydown', preventDefaultForScrollKeys, false);
+}
diff --git a/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts b/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts
index d1f3f2c64..2f07c2773 100644
--- a/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts
+++ b/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts
@@ -83,15 +83,36 @@ const style = css`
padding-right: 5px;
}
.meta-item-container {
+ display: flex;
overflow: hidden;
- max-height: 0;
- transition: max-height 0.25s ease-out;
padding: 0 16px 0 36px;
}
- .attribute-meta-row.expanded .meta-item-container {
- max-height: 1000px;
- transition: max-height 1s ease-in;
+ .meta-item-container:after {
+ content: '';
+ height: 50px;
+ transition: height 1s linear, max-height 0s 1s linear;
+ max-height: 0;
+ }
+ .meta-item-container .collapsible {
+ flex: 1;
+ transition: margin-bottom 1s cubic-bezier(0, 0, 0, 1);
+ margin-bottom: 0;
+ max-height: 1000000px;
+ }
+ .meta-item-container.collapsed > .collapsible {
+ margin-bottom: -2000px;
+ transition: margin-bottom 1s cubic-bezier(1, 0, 1, 1),
+ visibility 0s 1s, max-height 0s 1s;
+ visibility: hidden;
+ max-height: 0;
+ }
+ .meta-item-container.collapsed:after
+ {
+ height: 0;
+ transition: height 1s linear;
+ max-height: 50px;
}
+
.meta-item-container or-mwc-input {
width: 100%;
}
@@ -191,15 +212,14 @@ export class OrEditAssetPanel extends LitElement {
return;
}
const expanderIcon = tdElem.getElementsByTagName("or-icon")[0] as OrIcon;
- const headerRow = tdElem.parentElement! as HTMLTableRowElement;
- const metaRow = (headerRow.parentElement! as HTMLTableElement).rows[headerRow.rowIndex];
+ const metaExpander = this.shadowRoot!.getElementById("attribute-meta-"+tdElem.getAttribute("data-name")) as HTMLElement;
if (expanderIcon.icon === "chevron-right") {
expanderIcon.icon = "chevron-down";
- metaRow.classList.add("expanded");
+ metaExpander.classList.remove("collapsed");
} else {
expanderIcon.icon = "chevron-right";
- metaRow.classList.remove("expanded");
+ metaExpander.classList.add("collapsed");
}
};
@@ -248,7 +268,7 @@ export class OrEditAssetPanel extends LitElement {
return html`
<tr class="mdc-data-table__row">
- <td class="padded-cell mdc-data-table__cell expander-cell"><or-icon icon="chevron-right"></or-icon><span>${attribute.name}</span></td>
+ <td class="padded-cell mdc-data-table__cell expander-cell" data-name="${attribute.name}"><or-icon icon="chevron-right"></or-icon><span>${attribute.name}</span></td>
<td class="padded-cell mdc-data-table__cell">${Util.getValueDescriptorLabel(attribute.type!)}</td>
<td class="padded-cell overflow-visible mdc-data-table__cell">
<or-attribute-input compact .comfortable="${true}" .assetType="${assetType}" .label=${null} .readonly="${false}" .attribute="${attribute}" .assetId="${this.asset.id!}" disableWrite disableSubscribe disableButton @or-attribute-input-changed="${(e: OrAttributeInputChangedEvent) => this._onAttributeModified(attribute, e.detail.value)}"></or-attribute-input>
@@ -257,12 +277,14 @@ export class OrEditAssetPanel extends LitElement {
</tr>
<tr class="attribute-meta-row">
<td colspan="4">
- <div class="meta-item-container">
- <div>
- ${!attribute.meta ? `` : Object.entries(attribute.meta).sort(Util.sortByString(([name, value]) => name!)).map(([name, value]) => this._getMetaItemTemplate(attribute, Util.getMetaItemNameValueHolder(name, value)))}
- </div>
- <div class="item-add">
- <or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t("addMetaItems")}" icon="plus" @click="${() => this._addMetaItems(attribute)}"></or-mwc-input>
+ <div id="attribute-meta-${attribute.name!}" class="meta-item-container collapsed">
+ <div class="collapsible">
+ <div>
+ ${!attribute.meta ? `` : Object.entries(attribute.meta).sort(Util.sortByString(([name, value]) => name!)).map(([name, value]) => this._getMetaItemTemplate(attribute, Util.getMetaItemNameValueHolder(name, value)))}
+ </div>
+ <div class="item-add">
+ <or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t("addMetaItems")}" icon="plus" @click="${() => this._addMetaItems(attribute)}"></or-mwc-input>
+ </div>
</div>
</div>
</td>
diff --git a/ui/component/or-attribute-input/src/agent-link-json-forms-renderer.ts b/ui/component/or-attribute-input/src/agent-link-json-forms-renderer.ts
index aeee17757..87e650d47 100644
--- a/ui/component/or-attribute-input/src/agent-link-json-forms-renderer.ts
+++ b/ui/component/or-attribute-input/src/agent-link-json-forms-renderer.ts
@@ -1,7 +1,6 @@
import {
RankedTester,
rankWith,
- isStringControl,
and,
ControlProps,
mapStateToControlProps,
@@ -95,16 +94,30 @@ const agentIdRenderer = (state: JsonFormsStateContext, props: ControlProps) => {
const options: [string, string][] = agents.map(agent => [agent.id!, agent.name + " (" + agent.id + ")"]);
return html`
- <or-mwc-input .label="${i18next.t("agentId")}" @or-mwc-input-changed="${(ev: OrInputChangedEvent) => onAgentChanged(agents.find((agent) => agent.id === ev.detail.value))}" type="${InputType.SELECT}" .value="${props.data}" .placeholder="${i18next.t("selectAgent")}" .options="${options}"></or-mwc-input>
+ <or-mwc-input .label="${i18next.t("agentId")}" class="agent-id-picker" @or-mwc-input-changed="${(ev: OrInputChangedEvent) => onAgentChanged(agents.find((agent) => agent.id === ev.detail.value))}" type="${InputType.SELECT}" .value="${props.data}" .placeholder="${i18next.t("selectAgent")}" .options="${options}"></or-mwc-input>
`;
});
const template = html`
- <div>
- ${until(loadedTemplatePromise, html`<or-mwc-input .type="${InputType.SELECT}"></or-mwc-input>`)}
- </div>`;
+ <style>
+ .agent-id-picker {
+ min-width: 300px;
+ max-width: 600px;
+ width: 100%;
+ }
+ </style>
+ ${until(loadedTemplatePromise, html`<or-mwc-input class="agent-id-picker" .type="${InputType.SELECT}"></or-mwc-input>`)}
+ `;
+
+ let deleteHandler: undefined | (() => void);
+ if (!props.required && props.path) {
+ const { handleChange } = mapDispatchToControlProps(state.dispatch);
+ deleteHandler = () => {
+ handleChange(props.path, undefined);
+ }
+ }
- return getTemplateWrapper(template, state, props);
+ return getTemplateWrapper(template, deleteHandler);
};
export const agentIdRendererRegistryEntry: JsonFormsRendererRegistryEntry = {
diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.ts
index 849529c1c..3b72b6740 100644
--- a/ui/component/or-attribute-input/src/index.ts
+++ b/ui/component/or-attribute-input/src/index.ts
@@ -170,6 +170,10 @@ export const jsonFormsInputTemplateProvider: (assetDescriptor: AssetDescriptor |
// Apply a custom UI schema to remove the outer VerticalLayout
const uiSchema: any = {type: "Control", scope: "#"};
+ const config: any = {
+ hideAnyOfPicker: false
+ };
+
// 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\"}}}]}]}");
@@ -184,8 +188,8 @@ export const jsonFormsInputTemplateProvider: (assetDescriptor: AssetDescriptor |
containerDiv.value!.classList.remove("disabled");
return html`
- <or-json-forms .renderers="${jsonFormsAttributeRenderers}" ${ref(jsonForms)}
- .schema="${schema}" .uischema="${uiSchema}" .onChange="${onAgentLinkChanged}"
+ <or-json-forms .renderers="${jsonFormsAttributeRenderers}" ${ref(jsonForms)} .config="${config}"
+ .schema="${schema}" label="Agent link" .uischema="${uiSchema}" .onChange="${onAgentLinkChanged}"
.data="${agentLink}"></or-json-forms>
`;
});
diff --git a/ui/component/or-json-forms/src/base-element.ts b/ui/component/or-json-forms/src/base-element.ts
index 304c6962b..3b7058306 100644
--- a/ui/component/or-json-forms/src/base-element.ts
+++ b/ui/component/or-json-forms/src/base-element.ts
@@ -8,10 +8,17 @@ import {
OwnPropsOfRenderer,
UISchemaElement
} from '@jsonforms/core';
-import "./unknown-element";
import {JsonFormsStateContext} from "./index";
-export abstract class BaseElement<T extends UISchemaElement, P extends OwnPropsOfRenderer> extends LitElement implements OwnPropsOfRenderer {
+/**
+ * Adds label and required fields to layouts as well as controls
+ */
+export interface WithLabelAndRequired {
+ label: string;
+ required: boolean;
+}
+
+export abstract class BaseElement<T extends UISchemaElement, P extends OwnPropsOfRenderer> extends LitElement implements OwnPropsOfRenderer, WithLabelAndRequired {
@property({type: Object})
public state!: JsonFormsStateContext;
@@ -47,7 +54,10 @@ export abstract class BaseElement<T extends UISchemaElement, P extends OwnPropsO
public path!: string;
@property({type: String})
- public title!: string;
+ public label!: string;
+
+ @property({type: Boolean})
+ public required!: boolean;
public set props(props: P) {
delete (props as any).id;
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 110828d2a..66b10ffec 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
@@ -11,7 +11,7 @@ import {
} from "@jsonforms/core";
import {css, html, PropertyValues, TemplateResult, unsafeCSS} from "lit";
import {customElement} from "lit/decorators.js";
-import {AnyOfInfo, getAnyOfInfos, getTemplateFromProps} from "../util";
+import {CombinatorInfo, 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";
@@ -22,17 +22,31 @@ import {DefaultColor4, DefaultColor5} from "@openremote/core";
import "../json-editor";
import {JsonEditor} from "../json-editor";
import {ControlBaseElement} from "./control-base-element";
-import {WithRequired} from "..";
+import {getTemplateWrapper} from "../index";
+import {WithLabelAndRequired} from "../base-element";
// language=CSS
const style = css`
- :host, .drag-wrapper {
- position: relative;
+ :host, .item-border, .drag-handle {
border-color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
border-radius: 4px;
border-width: 1px;
border-style: solid;
}
+
+ .item-wrapper {
+ display: flex;
+ }
+
+ .item-container {
+ flex: 1;
+ }
+
+ .item-border {
+ flex: 1;
+ border-top-left-radius: 0;
+ border-bottom-left-radius: 0;
+ }
#expander {
--or-icon-width: 20px;
@@ -69,32 +83,22 @@ const style = css`
:host, .padded {
padding: 10px 16px;
}
-
- .element-container {
- flex: 1;
- border-left-width: 1px;
- border-left-style: solid;
- border-left-color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
- }
-
- .element-container > .item-container > or-json-forms-array-control, .element-container > .item-container > or-json-forms-vertical-layout {
- border: none;
- }
- .element-container > .item-container {
+ .item-border > .item-container {
margin: 0;
- flex: 1;
}
-
- .element-container > .item-container > .delete-container {
+
+ .item-border > .item-container > .delete-container {
display: none;
}
- .drag-wrapper {
- flex: 1 1 auto;
- display: flex;
+ .item-border > .item-container :first-child {
+ border: 0;
+ padding: 0;
+ margin: 0;
+ flex: 1;
}
-
+
.draggable.dragging {
opacity: 0.5;
}
@@ -112,11 +116,18 @@ const style = css`
}
.drag-handle {
- margin: 3px;
+ border-top-right-radius: 0;
+ border-bottom-right-radius: 0;
+ border-right: 0;
cursor: grab;
- background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Cg%3E%3Cellipse fill='%23cecece' cx='5' cy='5' rx='2.5' ry='2.5'/%3E%3C/g%3E%3C/svg%3E");
flex: 0 0 auto;
width: 20px;
+ padding: 3px;
+ }
+
+ .drag-handle > div {
+ height: 100%;
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Cg%3E%3Cellipse fill='%23cecece' cx='5' cy='5' rx='2.5' ry='2.5'/%3E%3C/g%3E%3C/svg%3E");
}
`;
@@ -130,7 +141,7 @@ const controlWithoutLabel = (scope: string): ControlElement => ({
export class ControlArrayElement extends ControlBaseElement {
protected resolvedSchema!: JsonSchema;
- protected itemInfos: AnyOfInfo[] | undefined;
+ protected itemInfos: CombinatorInfo[] | undefined;
protected addItem!: (value: any) => void;
protected removeItem!: (index: number) => void;
protected moveItem!: (fromIndex: number, toIndex: number) => void;
@@ -148,7 +159,7 @@ export class ControlArrayElement extends ControlBaseElement {
this.resolvedSchema = Resolve.schema(this.schema, 'items', this.rootSchema);
if (Array.isArray(this.resolvedSchema.anyOf)) {
- this.itemInfos = getAnyOfInfos(this.resolvedSchema.anyOf, this.rootSchema);
+ this.itemInfos = getCombinatorInfos(this.resolvedSchema.anyOf, this.rootSchema);
}
}
@@ -186,7 +197,7 @@ 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.title || this.label}</span></div>
+ <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)}">
@@ -194,14 +205,19 @@ export class ControlArrayElement extends ControlBaseElement {
${!Array.isArray(this.data) ? `` : (this.data as any[]).map((item, 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;
+ const childLabel = childMatchedItemInfo ? childMatchedItemInfo.title : "";
- const props: RendererProps & WithRequired = {
+ const props: RendererProps & WithLabelAndRequired = {
renderers: this.renderers,
uischema: controlWithoutLabel("#"),
enabled: this.enabled,
visible: this.visible,
path: childPath,
schema: this.resolvedSchema,
+ label: childLabel,
required: false
};
@@ -218,17 +234,19 @@ export class ControlArrayElement extends ControlBaseElement {
}
protected getArrayItemWrapper(elementTemplate: TemplateResult, index: number) {
+
+ elementTemplate = html`
+ <div class="drag-handle">
+ <div></div>
+ </div>
+ <div class="item-border padded">
+ ${elementTemplate}
+ </div>
+ `;
+
return html`
- <div class="item-container draggable" data-index="${index}" draggable="true" @dragstart="${(ev: DragEvent) => this._onDragStart(ev)}" @dragend="${(ev: DragEvent) => this._onDragEnd(ev)}">
- <div class="drag-wrapper">
- <div class="drag-handle"></div>
- <div class="element-container">
- ${elementTemplate}
- </div>
- </div>
- <div class="delete-container">
- <button class="button-clear" @click="${() => this.removeItem(index)}"><or-icon icon="close-circle"></or-icon></input>
- </div>
+ <div class="item-wrapper draggable" data-index="${index}" draggable="true" @dragstart="${(ev: DragEvent) => this._onDragStart(ev)}" @dragend="${(ev: DragEvent) => this._onDragEnd(ev)}">
+ ${getTemplateWrapper(elementTemplate, () => this.removeItem(index))}
</div>
`;
}
@@ -359,7 +377,7 @@ export class ControlArrayElement extends ControlBaseElement {
protected showAddDialog() {
- let selectedItemInfo: AnyOfInfo | undefined;
+ let selectedItemInfo: CombinatorInfo | undefined;
const listItems: ListItem[] = this.itemInfos!.map((itemInfo, index) => {
const labelStr = itemInfo.title ? computeLabel(itemInfo.title, false, true) : "";
@@ -370,7 +388,7 @@ export class ControlArrayElement extends ControlBaseElement {
}
});
- const onParamChanged = (itemInfo: AnyOfInfo) => {
+ const onParamChanged = (itemInfo: CombinatorInfo) => {
selectedItemInfo = itemInfo;
const descElem = dialog.shadowRoot!.getElementById("parameter-desc") as HTMLDivElement;
descElem.innerHTML = itemInfo.description || "";
@@ -382,7 +400,7 @@ export class ControlArrayElement extends ControlBaseElement {
<div class="col">
<form id="mdc-dialog-form-add" class="row">
<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 AnyOfInfo); }}" .listItems="${listItems.sort((a,b) => a.text!.localeCompare(b.text!))}" id="parameter-list"></or-mwc-list>
+ <or-mwc-list @or-mwc-list-changed="${(evt: OrMwcListChangedEvent) => {if (evt.detail.length === 1) onParamChanged((evt.detail[0] as ListItem).data as CombinatorInfo); }}" .listItems="${listItems.sort((a, b) => a.text!.localeCompare(b.text!))}" id="parameter-list"></or-mwc-list>
</div>
<div id="parameter-desc" class="col"></div>
</form>
diff --git a/ui/component/or-json-forms/src/controls/control-base-element.ts b/ui/component/or-json-forms/src/controls/control-base-element.ts
index 7e80d037a..aa666fd3a 100644
--- a/ui/component/or-json-forms/src/controls/control-base-element.ts
+++ b/ui/component/or-json-forms/src/controls/control-base-element.ts
@@ -14,15 +14,9 @@ import {BaseElement} from "../base-element";
export abstract class ControlBaseElement extends BaseElement<ControlElement, ControlProps> implements OwnPropsOfControl, ControlProps {
- @property()
- public label!: string;
-
@property()
public description?: string | undefined;
- @property()
- public required?: boolean | undefined;
-
@property()
public errors!: string;
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 3dc5ad379..5bb9e2929 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
@@ -1,11 +1,18 @@
-import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";
-import {css, html, PropertyValues } from "lit";
-import { customElement, property } from "lit/decorators.js";
+import {InputType, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";
+import {css, html} from "lit";
+import {customElement} from "lit/decorators.js";
import {ControlBaseElement} from "./control-base-element";
import {baseStyle} from "../styles";
-import { isBooleanControl,
- isEnumControl, isIntegerControl, isNumberControl, isOneOfEnumControl, isRangeControl, isStringControl, JsonSchema, JsonSchema7 } from "@jsonforms/core";
-import {isEnumArray} from "../standardRenderers";
+import {
+ isBooleanControl,
+ isEnumControl,
+ isIntegerControl,
+ isNumberControl,
+ isOneOfEnumControl,
+ isStringControl,
+ JsonSchema
+} from "@jsonforms/core";
+import {isEnumArray} from "../standard-renderers";
// language=CSS
const style = css`
diff --git a/ui/component/or-json-forms/src/index.ts b/ui/component/or-json-forms/src/index.ts
index bed2cc6d0..99b8bfa7a 100644
--- a/ui/component/or-json-forms/src/index.ts
+++ b/ui/component/or-json-forms/src/index.ts
@@ -13,20 +13,23 @@ import {
generateDefaultUISchema,
generateJsonSchema,
JsonFormsCellRendererRegistryEntry,
+ JsonFormsProps,
JsonFormsRendererRegistryEntry,
JsonFormsSubStates,
JsonFormsUISchemaRegistryEntry,
JsonSchema,
+ mapDispatchToControlProps,
mapStateToJsonFormsRendererProps,
OwnPropsOfJsonFormsRenderer,
StatePropsOfJsonFormsRenderer,
UISchemaElement
} from "@jsonforms/core";
-import {getTemplateWrapper, StandardRenderers} from "./standardRenderers";
-import {getTemplateFromProps} from "./util";
+import {getTemplateWrapper, StandardRenderers} from "./standard-renderers";
+import {getLabel, getTemplateFromProps} from "./util";
import {useEffect, useMemo, useReducer, useRef} from "haunted";
import {baseStyle} from "./styles";
-import { Util } from "@openremote/core";
+import {Util} from "@openremote/core";
+import {WithLabelAndRequired} from "./base-element";
declare global {
interface SymbolConstructor {
@@ -46,14 +49,6 @@ export interface JsonFormsStateContext extends JsonFormsSubStates {
dispatch: Dispatch<CoreActions>;
}
-export interface WithTitle {
- title?: string;
-}
-
-export interface WithRequired {
- required?: boolean;
-}
-
// language=CSS
const styles = css`
.delete-container {
@@ -84,7 +79,7 @@ const useEffectAfterFirstRender = (
};
@customElement("or-json-forms")
-export class OrJSONForms extends HauntedLitElement implements OwnPropsOfJsonFormsRenderer {
+export class OrJSONForms extends HauntedLitElement implements OwnPropsOfJsonFormsRenderer, WithLabelAndRequired {
@property({type: Object})
public uischema?: UISchemaElement;
@@ -113,6 +108,12 @@ export class OrJSONForms extends HauntedLitElement implements OwnPropsOfJsonForm
@property({type: Boolean})
public readonly: boolean = false;
+ @property({type: String})
+ public label!: string;
+
+ @property({type: Boolean})
+ public required: boolean = false;
+
public static get styles() {
return [
baseStyle,
@@ -162,15 +163,13 @@ export class OrJSONForms extends HauntedLitElement implements OwnPropsOfJsonForm
configDispatch(Actions.setConfig(this.config));
}, [this.config]);
- // @ts-ignore
- const contextValue: JsonFormsStateContext = useMemo(() => ({
+ const contextValue: JsonFormsSubStates = useMemo(() => ({
core,
renderers: this.renderers,
cells: this.cells,
config: config,
uischemas: this.uischemas,
readonly: this.readonly,
- // only core dispatch available
dispatch: coreDispatch
}), [core, this.renderers, this.cells, config, this.readonly]);
@@ -181,11 +180,11 @@ export class OrJSONForms extends HauntedLitElement implements OwnPropsOfJsonForm
}, [core.data, core.errors]);
return html`${guard([contextValue], () => {
- let props: StatePropsOfJsonFormsRenderer & WithTitle = mapStateToJsonFormsRendererProps({jsonforms: {...contextValue}}, this);
- props = {
- ...props,
- title: this.title
- }
+ const props: JsonFormsProps & WithLabelAndRequired = {
+ ...mapStateToJsonFormsRendererProps({jsonforms: {...contextValue}}, this),
+ label: getLabel(schemaToUse, schemaToUse, this.label, undefined) || "",
+ required: this.required
+ };
return getTemplateFromProps(contextValue, props);
})}`;
}
diff --git a/ui/component/or-json-forms/src/layouts/layout-base-element.ts b/ui/component/or-json-forms/src/layouts/layout-base-element.ts
index 5fcbb43f0..c87f7513c 100644
--- a/ui/component/or-json-forms/src/layouts/layout-base-element.ts
+++ b/ui/component/or-json-forms/src/layouts/layout-base-element.ts
@@ -5,7 +5,7 @@ import {BaseElement} from "../base-element";
export abstract class LayoutBaseElement<T extends Layout> extends BaseElement<T, LayoutProps> implements OwnPropsOfLayout {
@property({type: String})
- public direction: 'row' | 'column' = "column";
+ public direction: "row" | "column" = "column";
protected getChildProps(): OwnPropsOfRenderer[] {
return (this.uischema && this.uischema.elements ? this.uischema.elements : []).map(
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 eb3a9f913..53b0044de 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
@@ -1,23 +1,35 @@
-import {computeLabel, createDefaultValue, isControl, JsonFormsState, LayoutProps, mapStateToControlProps,
- OwnPropsOfControl, OwnPropsOfRenderer, RankedTester, rankWith, StatePropsOfControl, uiTypeIs, update, VerticalLayout} from "@jsonforms/core";
-import {css, html, PropertyValues, TemplateResult, unsafeCSS} from "lit";
+import {
+ computeLabel,
+ ControlElement,
+ createDefaultValue,
+ getSchema,
+ GroupLayout,
+ isControl,
+ mapStateToControlProps,
+ OwnPropsOfControl,
+ OwnPropsOfRenderer,
+ StatePropsOfControl,
+ VerticalLayout
+} from "@jsonforms/core";
+import {css, html, TemplateResult, unsafeCSS} from "lit";
import {customElement} from "lit/decorators.js";
import {LayoutBaseElement} from "./layout-base-element";
-import {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 {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 {ListItem, OrMwcListChangedEvent } from "@openremote/or-mwc-components/or-mwc-list";
-import { DefaultColor5 } from "@openremote/core";
+import {ListItem, OrMwcListChangedEvent} from "@openremote/or-mwc-components/or-mwc-list";
+import {DefaultColor5} from "@openremote/core";
import "../json-editor";
import {JsonEditor} from "../json-editor";
+import {WithLabelAndRequired} from "../base-element";
// language=CSS
const style = css`
:host {
- border-color: rgba(0,0,0,0.12);
+ border-color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
border-radius: 4px;
border-width: 1px;
border-style: solid;
@@ -56,10 +68,40 @@ const style = css`
:host, .padded {
padding: 10px 16px;
}
+
+ #dynamic-wrapper {
+ display: table;
+ }
+
+ #dynamic-wrapper .row {
+ display: table-row;
+ }
+
+ #dynamic-wrapper .row:hover .button-clear {
+ visibility: visible;
+ }
+
+ #dynamic-wrapper .row > div {
+ display: table-cell;
+ }
+
+ .key-container, .value-container {
+ padding: 10px;
+ }
+
+ .key-container or-mwc-input, .value-container or-mwc-input {
+ display: block;
+ }
+
+ .delete-container {
+ vertical-align: middle;
+ }
`;
@customElement("or-json-forms-vertical-layout")
-export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout> {
+export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | GroupLayout> {
+
+ public handleChange!: (path: string, data: any) => void;
public static get styles() {
return [
@@ -68,40 +110,108 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout> {
];
}
+ 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;
+
+ 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;
+ }
+ }
return html`
<div id="panel">
<div id="header">
- <div id="expander"><or-icon icon="chevron-right"></or-icon><span>${this.title || this.schema.title || ""}</span></div>
+ <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">
- ${this.getChildProps().map((props) => {
+ ${dynamic ?
+ this._getDynamicContentTemplate(dynamicValueType)
+ : this.getChildProps().map((props: OwnPropsOfRenderer) => {
+
+ const contentProps: OwnPropsOfRenderer & WithLabelAndRequired = {
+ ...props,
+ label: "",
+ required: false
+ };
if (isControl(props.uischema)) {
+
const controlProps = props as OwnPropsOfControl;
- const stateControlProps = mapStateToControlProps({jsonforms: {...this.state}}, controlProps);
+ const stateControlProps = mapStateToControlProps(jsonFormsState, controlProps);
+ stateControlProps.label = stateControlProps.label || getLabel(this.schema, rootSchema, undefined, (props.uischema as ControlElement).scope) || "";
+ contentProps.label = stateControlProps.label;
+ contentProps.required = !!stateControlProps.required;
if (!stateControlProps.required && stateControlProps.data === undefined) {
- // Optional property with no data so show this in the dialog
+ // Optional property with no data so show this in the add parameter dialog
optionalProps.push(stateControlProps);
return html``;
}
}
- return getTemplateFromProps(this.state, props);
+ return getTemplateFromProps(this.state, contentProps);
})}
</div>
- ${optionalProps.length === 0 ? html`` : html`
- <div id="add-parameter">
- <or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t("addParameter")}" icon="plus" @click="${() => this._addParameter(optionalProps)}"></or-mwc-input>
- </div>
- `}
+ <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>
+ </div>
+ </div>
+ `;
+ }
+
+ protected _getDynamicContentTemplate(dynamicValueType: InputType): TemplateResult {
+ if (!this.data) {
+ return html``;
+ }
+
+ const deleteHandler = (key: string) => {
+ const data = this.data || {};
+ delete data[key];
+ this.handleChange(this.path, data);
+ };
+
+ 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>
+ </div>
+ <div class="value-container">
+ <or-mwc-input .type="${dynamicValueType}" .value="${value}"></or-mwc-input>
+ </div>
+ <div class="delete-container">
+ <button class="button-clear" @click="${() => deleteHandler(key)}"><or-icon icon="close-circle"></or-icon></input>
+ </div>
+ </div>
+ `;
+ })}
</div>
`;
}
@@ -124,11 +234,7 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout> {
const editor = dialog.shadowRoot!.getElementById("json-editor") as JsonEditor;
if (editor.validate()) {
const data = !!editor.getValue() ? JSON.parse(editor.getValue()!) : undefined;
- this.state.dispatch(
- update(this.path || "", (d) => {
- return data;
- })
- )
+ this.handleChange(this.path || "", data);
}
},
content: html`<or-mwc-input id="add-btn" .type="${InputType.BUTTON}" .label="${i18next.t("update")}"></or-mwc-input>`
@@ -159,8 +265,9 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout> {
)
}
- protected _addParameter(optionalProps: StatePropsOfControl[]) {
+ protected _addParameter(optionalProps: StatePropsOfControl[], dynamicValueType: InputType) {
+ const dynamic = optionalProps.length === 0;
let selectedParameter: StatePropsOfControl | undefined;
const listItems: ListItem[] = optionalProps.map(props => {
@@ -179,14 +286,34 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout> {
(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;
+ (dialog.shadowRoot!.getElementById("add-btn") as OrMwcInput).disabled = !valid;
+ };
+
const dialog = showDialog({
content: html`
<div class="col">
<form id="mdc-dialog-form-add" class="row">
<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>
+ ${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>
+ <div id="parameter-desc" class="col">
+ ${!dynamic ? `` : html`
+ <style>
+ #dynamic-wrapper > or-mwc-input {
+ display: block;
+ margin: 10px;
+ }
+ </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>
+ </div>
+ `}
</div>
- <div id="parameter-desc" class="col"></div>
</form>
</div>
`,
@@ -220,6 +347,7 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout> {
display: flex;
}
#parameter-desc {
+ flex: 1;
padding: 5px;
}
</style>
@@ -234,15 +362,10 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout> {
default: true,
actionName: "add",
action: () => {
- if (selectedParameter) {
- this.state.dispatch(
- update(this.path || "", (data) => {
- data = data || {};
- data[selectedParameter!.path.split(".").pop()!] = createDefaultValue(selectedParameter!.schema);
- return data;
- })
- )
- }
+ const data = {...this.data};
+ const key = dynamic ? keyValue[0] as string : selectedParameter!.path.split(".").pop()!;
+ data[key] = dynamic ? keyValue[1] : createDefaultValue(selectedParameter!.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/standardRenderers.ts b/ui/component/or-json-forms/src/standard-renderers.ts
similarity index 51%
rename from ui/component/or-json-forms/src/standardRenderers.ts
rename to ui/component/or-json-forms/src/standard-renderers.ts
index 971218110..6fb4ff41f 100644
--- a/ui/component/or-json-forms/src/standardRenderers.ts
+++ b/ui/component/or-json-forms/src/standard-renderers.ts
@@ -1,6 +1,5 @@
import {
and,
- computeLabel,
ControlElement,
ControlProps,
createCombinatorRenderInfos,
@@ -21,14 +20,12 @@ import {
isTimeControl,
JsonFormsRendererRegistryEntry,
JsonSchema,
- Layout,
mapDispatchToControlProps,
- mapDispatchToMultiEnumProps,
- mapStateToAllOfProps,
- mapStateToAnyOfProps,
mapStateToControlProps,
+ mapStateToControlWithDetailProps,
mapStateToLayoutProps,
or,
+ OwnPropsOfJsonFormsRenderer,
OwnPropsOfRenderer,
RankedTester,
rankWith,
@@ -41,11 +38,15 @@ import {
} from "@jsonforms/core";
import {html, TemplateResult} from "lit";
import "@openremote/or-mwc-components/or-mwc-input";
-import {JsonFormsStateContext, WithRequired, WithTitle} from "./index";
-import {findSchemaTitleAndDescription, getTemplateFromProps, mapStateToCombinatorRendererProps, toControlDetailProps} from "./util";
+import {JsonFormsStateContext} from "./index";
+import {getCombinatorInfos, getLabel, getTemplateFromProps, mapStateToCombinatorRendererProps} from "./util";
import "./layouts/layout-vertical-element";
import "./controls/control-input-element";
import "./controls/control-array-element";
+import {InputType, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";
+import {i18next} from "@openremote/or-translate";
+import {WithLabelAndRequired} from "./base-element";
+import {Util} from "@openremote/core";
const hasOneOfItems = (schema: JsonSchema): boolean =>
schema.oneOf !== undefined &&
@@ -72,21 +73,30 @@ export const isEnumArray: Tester = and(
)
);
-export const verticalLayoutTester: RankedTester = rankWith(
+export const verticalOrGroupLayoutTester: RankedTester = rankWith(
1,
- uiTypeIs('VerticalLayout')
+ or(
+ uiTypeIs("VerticalLayout"),
+ uiTypeIs("Group")
+ )
);
-export const verticalLayoutRenderer = (state: JsonFormsStateContext, props: RendererProps & WithTitle & WithRequired) => {
- const p: RendererProps & WithTitle & WithRequired & DispatchPropsOfControl = {
+export const verticalLayoutRenderer = (state: JsonFormsStateContext, props: OwnPropsOfJsonFormsRenderer & WithLabelAndRequired) => {
+ const contentProps: RendererProps & DispatchPropsOfControl & WithLabelAndRequired = {
...mapStateToLayoutProps({jsonforms: {...state}}, props),
...mapDispatchToControlProps(state.dispatch),
- title: props.title,
+ label: props.label,
required: props.required
};
- const template = html`<or-json-forms-vertical-layout data-title="${p.title || ""}" .state="${state}" .props="${p}"></or-json-forms-vertical-layout>`;
- return getTemplateWrapper(template, state, p);
+ const template = html`<or-json-forms-vertical-layout .state="${state}" .props="${contentProps}"></or-json-forms-vertical-layout>`;
+ let deleteHandler: undefined | (() => void);
+ if (!contentProps.required && contentProps.path) {
+ deleteHandler = () => {
+ contentProps.handleChange(contentProps.path || "", undefined);
+ }
+ }
+ return getTemplateWrapper(template, deleteHandler);
};
export const inputControlTester: RankedTester = rankWith(
@@ -105,15 +115,22 @@ export const inputControlTester: RankedTester = rankWith(
)
);
export const inputControlRenderer = (state: JsonFormsStateContext, props: ControlProps) => {
- props = {
- ...props,
+ const contentProps: ControlProps = {
...mapStateToControlProps({jsonforms: {...state}}, props),
- ...mapDispatchToControlProps(state.dispatch),
- ...mapDispatchToMultiEnumProps(state.dispatch)
+ ...mapDispatchToControlProps(state.dispatch)
};
- const template = html`<or-json-forms-input-control .state="${state}" .props="${props}"></or-json-forms-input-control>`;
- return getTemplateWrapper(template, state, props);
+ contentProps.label = props.label || contentProps.label;
+ contentProps.required = !!props.required || contentProps.required;
+
+ const template = html`<or-json-forms-input-control .state="${state}" .props="${contentProps}"></or-json-forms-input-control>`;
+ let deleteHandler: undefined | (() => void);
+ if (!contentProps.required && contentProps.path) {
+ deleteHandler = () => {
+ contentProps.handleChange(contentProps.path, undefined);
+ }
+ }
+ return getTemplateWrapper(template, deleteHandler);
};
export const objectControlTester: RankedTester = rankWith(
@@ -133,40 +150,41 @@ export const objectControlRenderer = (state: JsonFormsStateContext, props: Contr
enabled,
uischema,
rootSchema
- } = toControlDetailProps(state, props);
+ } = mapStateToControlWithDetailProps({jsonforms: {...state}}, props);
const detailUiSchema = findUISchema(
uischemas!,
schema,
uischema.scope,
path,
- 'VerticalLayout',
+ "VerticalLayout",
uischema,
rootSchema
);
- const labelStr = computeLabel(label, !!required, false);
- const contentProps: OwnPropsOfRenderer & WithTitle & WithRequired & DispatchPropsOfControl = {
- title: labelStr,
+ const contentProps: OwnPropsOfRenderer & WithLabelAndRequired = {
visible: visible,
enabled: enabled,
schema: schema,
uischema: detailUiSchema,
path: path,
- handleChange: props.handleChange,
renderers: renderers,
cells: cells,
- required: required
+ label: props.label || getLabel(schema, rootSchema, label) || "",
+ required: !!props.required || !!required
};
return getTemplateFromProps(state, contentProps);
}
+
export const anyOfControlTester: RankedTester = rankWith(
4,
isAnyOfControl
);
export const anyOfControlRenderer = (state: JsonFormsStateContext, props: ControlProps) => {
+ const jsonFormsContext = {jsonforms: {...state}};
+
const {
required,
renderers,
@@ -179,25 +197,10 @@ export const anyOfControlRenderer = (state: JsonFormsStateContext, props: Contro
enabled,
uischema,
rootSchema
- } = toControlDetailProps(state, props);
+ } = mapStateToControlWithDetailProps(jsonFormsContext, props);
const anyOfSchema = resolveSubSchemas(schema, rootSchema, "anyOf");
-
- const anyOfProps = mapStateToCombinatorRendererProps({jsonforms: {...state}}, {
- schema: anyOfSchema,
- path: path,
- visible: visible,
- enabled: enabled,
- uischema: uischema,
- renderers: renderers,
- cells: cells,
- uischemas: uischemas
- }, "anyOf");
-
- if (anyOfProps.indexOfFittingSchema === undefined) {
- console.warn("Cannot match anyOf schema to instance data");
- return html`<or-json-forms-unknown class="item-container"></or-json-forms-unknown>`;
- }
+ const anyOfProps = mapStateToCombinatorRendererProps(jsonFormsContext, props, "anyOf");
const anyOfRenderInfos = createCombinatorRenderInfos(
anyOfSchema.anyOf!,
@@ -208,12 +211,32 @@ export const anyOfControlRenderer = (state: JsonFormsStateContext, props: Contro
anyOfProps.uischemas
);
+ if (anyOfProps.indexOfFittingSchema === undefined || anyOfProps.indexOfFittingSchema < 0) {
+ if (props.data !== undefined) {
+ // We have data that doesn't match a schema so show invalid template
+ console.warn("Cannot match anyOf schema to instance data");
+ return invalidTemplate();
+ } else {
+ // We have no data so show a schema picker
+ const { handleChange } = mapDispatchToControlProps(state.dispatch);
+ const combinatorInfos = getCombinatorInfos(anyOfSchema.anyOf!, rootSchema);
+ const options: [string, string][] = combinatorInfos.map((combinatorInfo, index) => [index+"", combinatorInfo.title || i18next.t("Item ") + (index+1)]);
+ const pickerUpdater = (index: number) => {
+ const matchedInfo = combinatorInfos[index];
+ handleChange(path, matchedInfo.defaultValueCreator());
+ };
+ return html`
+ <or-mwc-input .type="${InputType.SELECT}" .options="${options}" @or-mwc-input-changed="${(ev: OrInputChangedEvent) => pickerUpdater(Number(ev.detail.value))}"></or-mwc-input>
+ `;
+ }
+ }
+
// Return template for the anyOf schema that matches the data
const matchedSchema = anyOfRenderInfos[anyOfProps.indexOfFittingSchema].schema;
let matchedUischema = anyOfRenderInfos[anyOfProps.indexOfFittingSchema].uischema;
if (matchedSchema.allOf) {
- // Force the uischema to be a simple control so that the allOf renderer gets used
+ // Force the uischema to be a simple control so it goes through the allOf renderer
matchedUischema = {
type: 'Control',
scope: "#",
@@ -221,81 +244,39 @@ export const anyOfControlRenderer = (state: JsonFormsStateContext, props: Contro
} as ControlElement;
}
- return getTemplateFromProps(state, {
+ const contentProps: OwnPropsOfRenderer & WithLabelAndRequired = {
schema: matchedSchema,
uischema: matchedUischema,
path: path,
renderers: renderers,
- cells: cells
- } as OwnPropsOfRenderer);
+ cells: cells,
+ label: props.label || getLabel(matchedSchema, rootSchema, label) || "",
+ required: props.required || !!required
+ }
+
+ return getTemplateFromProps(state, contentProps);
}
export const allOfControlTester: RankedTester = rankWith(
4,
isAllOfControl
);
-export const allOfControlRenderer = (state: JsonFormsStateContext, props: ControlProps) => {
-
- const {
- required,
- renderers,
- cells,
- uischemas,
- schema,
- label,
- path,
- visible,
- enabled,
- uischema,
- rootSchema
- } = toControlDetailProps(state, props);
+export const allOfControlRenderer = (state: JsonFormsStateContext, props: ControlProps & WithLabelAndRequired) => {
+ const jsonFormsContext = {jsonforms: {...state}};
+ const contentProps = {
+ ...mapStateToControlWithDetailProps(jsonFormsContext, props)
+ };
- const allOfSchema = resolveSubSchemas(schema, rootSchema, 'allOf');
+ // Merge the schemas
+ const allOfSchema = resolveSubSchemas(contentProps.schema, contentProps.rootSchema, "allOf");
+ contentProps.schema = (allOfSchema.allOf! as JsonSchema[]).reduce((accumulator, value) => Util.mergeObjects(accumulator, value, false));
+ // Reset the uischema scope
+ contentProps.uischema.scope = "#";
- const allOfProps = mapStateToCombinatorRendererProps({jsonforms: {...state}}, {
- schema: allOfSchema,
- path: path,
- visible: visible,
- enabled: enabled,
- uischema: uischema,
- renderers: renderers,
- cells: cells,
- uischemas: uischemas
- }, "allOf");
+ contentProps.label = props.label || contentProps.label;
+ contentProps.required = !!props.required || contentProps.required;
- const allOfRenderInfos = createCombinatorRenderInfos(
- allOfSchema.allOf!,
- rootSchema,
- "allOf",
- allOfProps.uischema || uischema,
- path,
- allOfProps.uischemas
- );
-
- if (allOfRenderInfos.every(renderInfo => renderInfo.uischema.type === "VerticalLayout")) {
- const titleAndDescription = findSchemaTitleAndDescription(allOfSchema, rootSchema);
-
- // Combine into a single layout
- (allOfRenderInfos[0].uischema as Layout).elements = allOfRenderInfos.map(renderInfo => (renderInfo.uischema as Layout).elements).flat();
- allOfRenderInfos[0].schema.title = titleAndDescription[0];
- allOfRenderInfos[0].schema.description = titleAndDescription[1];
-
- return getTemplateFromProps(state, {
- schema: allOfRenderInfos[0].schema,
- uischema: allOfRenderInfos[0].uischema,
- path: path,
- renderers: renderers,
- cells: cells
- } as OwnPropsOfRenderer);
- }
-
- return allOfRenderInfos.map(renderInfo => getTemplateFromProps(state, {
- schema: renderInfo.schema,
- uischema: renderInfo.uischema,
- path: path,
- renderers: renderers,
- cells: cells
- } as OwnPropsOfRenderer));
+ return getTemplateFromProps(state, contentProps);
}
@@ -305,24 +286,30 @@ 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 & WithTitle) => {
- props = {
- ...props,
+export const arrayControlRenderer = (state: JsonFormsStateContext, props: ControlProps) => {
+ const contentProps: ControlProps = {
...mapStateToControlProps({jsonforms: {...state}}, props),
...mapDispatchToControlProps(state.dispatch)
};
- const template = html`<or-json-forms-array-control .state="${state}" .props="${props}"></or-json-forms-array-control>`;
- return getTemplateWrapper(template, state, props);
-};
+ contentProps.label = props.label || contentProps.label;
+ contentProps.required = !!props.required || contentProps.required;
+ const template = html`<or-json-forms-array-control .state="${state}" .props="${contentProps}"></or-json-forms-array-control>`;
+ let deleteHandler: undefined | (() => void);
+ if (!contentProps.required && contentProps.path) {
+ deleteHandler = () => {
+ contentProps.handleChange(contentProps.path, undefined);
+ }
+ }
+ return getTemplateWrapper(template, deleteHandler);
+};
-export function getTemplateWrapper(elementTemplate: TemplateResult, state: JsonFormsStateContext, props: RendererProps & WithRequired): TemplateResult {
- const { handleChange } = mapDispatchToControlProps(state.dispatch);
+export function getTemplateWrapper(elementTemplate: TemplateResult, deleteHandler?: () => void): TemplateResult {
- const deleteTemplate = props.required || !props.path ? `` : html`
- <button class="button-clear" @click="${() => handleChange(props.path, undefined)}"><or-icon icon="close-circle"></or-icon></input>
+ const deleteTemplate = !deleteHandler ? `` : html`
+ <button class="button-clear" @click="${deleteHandler}"><or-icon icon="close-circle"></or-icon></input>
`;
return html`
<div class="item-container">
@@ -334,9 +321,17 @@ export function getTemplateWrapper(elementTemplate: TemplateResult, state: JsonF
`;
}
+export function invalidTemplate() {
+ return html`<span>No applicable renderer found!</span>`;
+}
+
+export function unknownTemplate() {
+ return html`<span>No applicable renderer found!</span>`;
+}
+
export const StandardRenderers: JsonFormsRendererRegistryEntry[] = [
- {tester: verticalLayoutTester, renderer: verticalLayoutRenderer},
+ {tester: verticalOrGroupLayoutTester, renderer: verticalLayoutRenderer},
{tester: inputControlTester, renderer: inputControlRenderer},
{tester: objectControlTester, renderer: objectControlRenderer},
{tester: arrayControlTester, renderer: arrayControlRenderer},
diff --git a/ui/component/or-json-forms/src/unknown-element.ts b/ui/component/or-json-forms/src/unknown-element.ts
deleted file mode 100644
index 8bd5350a3..000000000
--- a/ui/component/or-json-forms/src/unknown-element.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import {html, LitElement } from "lit";
-import {customElement} from "lit/decorators.js";
-
-@customElement("or-json-forms-unknown")
-export class UnknownElement extends LitElement {
-
- public render() {
- return html`<span>No applicable renderer found!</span>`;
- }
-}
diff --git a/ui/component/or-json-forms/src/util.ts b/ui/component/or-json-forms/src/util.ts
index 464c26289..2ec1b6109 100644
--- a/ui/component/or-json-forms/src/util.ts
+++ b/ui/component/or-json-forms/src/util.ts
@@ -1,6 +1,7 @@
import {
CombinatorKeyword,
composeWithUi,
+ createCleanLabel,
createDefaultValue,
deriveTypes,
getAjv,
@@ -11,6 +12,7 @@ import {
isVisible,
JsonFormsRendererRegistryEntry,
JsonFormsState,
+ JsonFormsSubStates,
JsonSchema,
JsonSchema4,
mapStateToControlProps,
@@ -23,11 +25,14 @@ import {
StatePropsOfCombinator,
StatePropsOfControl,
StatePropsOfControlWithDetail,
+ UISchemaElement,
} from "@jsonforms/core";
+import { Util } from "@openremote/core";
import {html, TemplateResult} from "lit";
import {ErrorObject, JsonFormsStateContext} from "./index";
+import { unknownTemplate } from "./standard-renderers";
-export function getTemplateFromProps<T extends OwnPropsOfRenderer>(state: JsonFormsStateContext | undefined, props: T | undefined): TemplateResult {
+export function getTemplateFromProps<T extends OwnPropsOfRenderer>(state: JsonFormsSubStates | undefined, props: T | undefined): TemplateResult {
if (!state || !props) {
return html``;
}
@@ -44,24 +49,18 @@ export function getTemplateFromProps<T extends OwnPropsOfRenderer>(state: JsonFo
if (renderer && renderer[1] !== -1) {
template = renderer[0].renderer(state, props) as TemplateResult;
} else {
- template = html`<or-json-forms-unknown class="item-container"></or-json-forms-unknown>`;
+ template = unknownTemplate();
}
}
return template || html``;
}
-export function toControlDetailProps(context: JsonFormsStateContext, props: OwnPropsOfControl): StatePropsOfControlWithDetail {
- return mapStateToControlWithDetailProps({ jsonforms: { ...context } }, props);
-}
-
-export function toControlProps(context: JsonFormsStateContext, props: OwnPropsOfControl): StatePropsOfControl {
- return mapStateToControlProps({ jsonforms: { ...context } }, props)
-}
-
-export interface AnyOfInfo {
+export interface CombinatorInfo {
title: string;
description: string;
+ constProperty?: string;
+ constValue?: any;
defaultValueCreator: () => any;
}
@@ -69,12 +68,13 @@ export interface AnyOfInfo {
* For a given anyOf schema array this will try and extract a common const property which can be used as a discriminator
* when creating instances
*/
-export function getAnyOfInfos(anyOfSchemas: JsonSchema[], rootSchema: JsonSchema): AnyOfInfo[] {
- // Find const properties of first schema
+export function getCombinatorInfos(schemas: JsonSchema[], rootSchema: JsonSchema): CombinatorInfo[] {
- return anyOfSchemas.map(schema => {
- const titleAndDescription = findSchemaTitleAndDescription(schema, rootSchema);
+ return schemas.map(schema => {
+ let constProperty: string | undefined;
+ let constValue: any | undefined;
let creator: () => any;
+ const titleAndDescription = findSchemaTitleAndDescription(schema, rootSchema);
if (schema.$ref) {
schema = Resolve.schema(rootSchema, schema.$ref);
@@ -88,11 +88,18 @@ export function getAnyOfInfos(anyOfSchemas: JsonSchema[], rootSchema: JsonSchema
const props = getSchemaObjectProperties(schema);
const constProp = props.find(([propName, propSchema]) => propSchema.const !== undefined);
if (constProp) {
+ constProperty = constProp[0];
+ constValue = constProp[1].const;
+
creator = () => {
const obj: any = {};
obj[constProp[0]] = constProp[1].const;
return obj;
}
+
+ if (!titleAndDescription[0]) {
+ titleAndDescription[0] = constProp[1].const;
+ }
} else {
creator = () => createDefaultValue(schema);
}
@@ -104,16 +111,18 @@ export function getAnyOfInfos(anyOfSchemas: JsonSchema[], rootSchema: JsonSchema
return {
title: titleAndDescription[0],
description: titleAndDescription[1],
- defaultValueCreator: creator
- } as AnyOfInfo;
+ defaultValueCreator: creator,
+ constProperty: constProperty,
+ constValue: constValue
+ } as CombinatorInfo;
});
}
export function findSchemaTitleAndDescription(schema: JsonSchema, rootSchema: JsonSchema): [string | undefined, string | undefined] {
- let refTitle: string | undefined;
+ let title: string | undefined;
if (schema.$ref) {
- refTitle = schema.$ref.substr(schema.$ref.lastIndexOf("/")+1);
+ title = getLabelFromScopeOrRef(schema.$ref);
schema = Resolve.schema(rootSchema, schema.$ref);
}
@@ -129,9 +138,15 @@ export function findSchemaTitleAndDescription(schema: JsonSchema, rootSchema: Js
if (titledSchema) {
return [titledSchema.title, titledSchema.description];
}
+
+
}
- return [refTitle, undefined];
+ return [title, undefined];
+}
+
+function getLabelFromScopeOrRef(scopeOrRef: string) {
+ return scopeOrRef.substr(scopeOrRef.lastIndexOf("/")+1);
}
function getSchemaObjectProperties(schema: JsonSchema): [string, JsonSchema][] {
@@ -222,6 +237,24 @@ export function mapStateToCombinatorRendererProps(
};
}
+export function getLabel(schema: JsonSchema, rootSchema: JsonSchema, uiElementLabel?: string, uiElementScope?: string): string | undefined {
+ if (uiElementLabel) {
+ return uiElementLabel;
+ }
+
+ const titleAndDesc = findSchemaTitleAndDescription(schema, rootSchema);
+
+ if (titleAndDesc[0]) {
+ return titleAndDesc[0];
+ }
+
+ if (uiElementScope) {
+ return Util.camelCaseToSentenceCase(getLabelFromScopeOrRef(uiElementScope));
+ }
+
+ return undefined;
+}
+
export function resolveSubSchemasRecursive(
schema: JsonSchema,
rootSchema: JsonSchema,
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 07a870fc7..96753dbb9 100644
--- a/ui/component/or-mwc-components/src/or-mwc-input.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-input.ts
@@ -890,7 +890,7 @@ export class OrMwcInput extends LitElement {
};
const menuCloseHandler = () => {
-
+ Util.enableScroll();
const v = (this._tempValue ?? this.value);
window.setTimeout(() => {
if (this._mdcComponent) {
@@ -907,6 +907,10 @@ export class OrMwcInput extends LitElement {
this.onValueChange(undefined, val);
};
+ const menuOpenedHandler = () => {
+ Util.disableScroll();
+ };
+
return html`
<div id="component"
class="mdc-select ${classMap(classes)}"
@@ -940,7 +944,7 @@ export class OrMwcInput extends LitElement {
</span>
${!outlined ? html`<div class="mdc-line-ripple"></div>` : ``}
</div>
- <div id="mdc-select-menu" class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fixed" @MDCMenuSurface:closed="${menuCloseHandler}">
+ <div id="mdc-select-menu" class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fixed" @MDCMenuSurface:opened="${menuOpenedHandler}" @MDCMenuSurface:closed="${menuCloseHandler}">
${getListTemplate(
this.multiple ? ListType.MULTI_TICK : ListType.SELECT,
opts ? html`${opts.map(([optValue, optDisplay], index) => {
@@ -1449,19 +1453,13 @@ export class OrMwcInput extends LitElement {
let previousValue = this.value;
- if (previousValue === undefined) {
- previousValue = null;
- }
-
if (newValue === "undefined") {
+ previousValue = null;
newValue = undefined;
}
- if (newValue === undefined) {
- newValue = null;
- }
-
if (newValue === "null") {
+ previousValue = undefined;
newValue = null;
}