Skip to content

armgit / core

Public Imported from GitHub
0

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

UI fixes for the asMomentary format (#1543)

Wouter Voorberg333f117a407b
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 4574bb6be..00dd98df0 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
@@ -3,7 +3,7 @@ import {until} from "lit/directives/until.js";
import {customElement, property, state} from "lit/decorators.js";
import {InputType, OrMwcInput, OrInputChangedEvent, getValueHolderInputTemplateProvider, ValueInputProviderOptions, OrInputChangedEventDetail, ValueInputProvider} from "@openremote/or-mwc-components/or-mwc-input";
import i18next from "i18next";
-import {Asset, Attribute, NameValueHolder, AssetModelUtil} from "@openremote/model";
+import {Asset, Attribute, NameValueHolder, AssetModelUtil, WellknownMetaItems} from "@openremote/model";
import { DefaultColor5, DefaultColor3, DefaultColor2, Util} from "@openremote/core";
import "@openremote/or-mwc-components/or-mwc-input";
import {OrIcon} from "@openremote/or-icon";
@@ -344,6 +344,9 @@ export class OrEditAssetPanel extends LitElement {
};
};
+ // Booleans formatted asMomentary should be read-only in modify mode
+ const formattedAsMomentary = attribute.meta && (attribute.meta.hasOwnProperty(WellknownMetaItems.MOMENTARY) || (attribute.meta.hasOwnProperty(WellknownMetaItems.FORMAT) && attribute.meta[WellknownMetaItems.FORMAT]?.asMomentary));
+
const template = 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>
@@ -351,7 +354,7 @@ export class OrEditAssetPanel extends LitElement {
<td class="padded-cell overflow-visible mdc-data-table__cell">
<or-attribute-input ${ref(attributeInputRef)}
.comfortable="${true}" .assetType="${assetType}" .label=${null}
- .readonly="${false}" .attribute="${attribute}" .assetId="${this.asset.id!}"
+ .readonly="${formattedAsMomentary}" .attribute="${attribute}" .assetId="${this.asset.id!}"
disableWrite disableSubscribe disableButton compact
@or-attribute-input-changed="${(e: OrAttributeInputChangedEvent) => this._onAttributeModified(attribute, e.detail.value)}"></or-attribute-input>
</td>
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 6d005cc82..e980496b9 100644
--- a/ui/component/or-mwc-components/src/or-mwc-input.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-input.ts
@@ -179,7 +179,7 @@ function inputTypeSupportsHelperText(inputType: InputType) {
}
function inputTypeSupportsLabel(inputType: InputType) {
- return inputTypeSupportsHelperText(inputType) || inputType === InputType.CHECKBOX;
+ return inputTypeSupportsHelperText(inputType) || inputType === InputType.CHECKBOX || inputType === InputType.BUTTON_MOMENTARY;
}
export const getValueHolderInputTemplateProvider: ValueInputProviderGenerator = (assetDescriptor, valueHolder, valueHolderDescriptor, valueDescriptor, valueChangeNotifier, options) => {
@@ -225,7 +225,7 @@ export const getValueHolderInputTemplateProvider: ValueInputProviderGenerator =
inputType = InputType.CHECKBOX;
}
- if (format && format.asMomentary) {
+ if (format && format.asMomentary || (Util.getMetaValue(WellknownMetaItems.MOMENTARY, valueHolder, valueHolderDescriptor) === true) ) {
inputType = InputType.BUTTON_MOMENTARY;
}
break;
@@ -1184,7 +1184,12 @@ export class OrMwcInput extends LitElement {
const isMomentary = this.type === InputType.BUTTON_MOMENTARY;
const isIconButton = !this.action && !this.label;
- let classes = {
+ // If no action, label or icons are given, show as a circle.
+ if (isIconButton && !this.iconTrailing && !this.icon ) {
+ this.icon = "circle"
+ }
+
+ const classes = {
"mdc-icon-button": isIconButton,
"mdc-fab": !isIconButton && this.action,
"mdc-fab--extended": !isIconButton && this.action && !!this.label,
@@ -1192,7 +1197,7 @@ export class OrMwcInput extends LitElement {
"mdc-button": !isIconButton && !this.action,
"mdc-button--raised": !isIconButton && !this.action && this.raised,
"mdc-button--unelevated": !isIconButton && !this.action && this.unElevated,
- "mdc-button--outlined": !isIconButton && !this.action && this.outlined,
+ "mdc-button--outlined": !isIconButton && !this.action && (this.outlined || isMomentary),
"mdc-button--rounded": !isIconButton && !this.action && this.rounded,
"mdc-button--fullwidth": this.fullWidth,
};