Skip to content

armgit / core

Public Imported from GitHub
0

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

Styling update to json-viewer input fields, attribute sorting, read-only icon color (#498)

DonWillems030e4352a7d0
diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.ts
index 2850f94fa..5331f0be5 100644
--- a/ui/component/or-map/src/index.ts
+++ b/ui/component/or-map/src/index.ts
@@ -301,7 +301,7 @@ export const geoJsonPointInputTemplateProvider: ValueInputProviderGenerator = (a
}
</style>
<div id="geo-json-point-input-compact-wrapper">
- <or-mwc-input .comfortable="${comfortable}" .type="${InputType.TEXT}" .value="${centerStr}" .pattern="${CoordinatesRegexPattern}" @keyup="${(e: KeyboardEvent) => getCoordinatesInputKeyHandler(valueChangeHandler)(e)}"></or-mwc-input>
+ <or-mwc-input style="width: auto;" .comfortable="${comfortable}" .type="${InputType.TEXT}" .value="${centerStr}" .pattern="${CoordinatesRegexPattern}" @keyup="${(e: KeyboardEvent) => getCoordinatesInputKeyHandler(valueChangeHandler)(e)}"></or-mwc-input>
<or-mwc-input style="width: auto;" .type="${InputType.BUTTON}" compact icon="crosshairs-gps" @click="${onClick}"></or-mwc-input>
</div>
`;
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
index 4f83ab983..cb2988d6f 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
@@ -31,6 +31,10 @@ const style = css`
:host > * {
margin: 0 3px 6px;
}
+
+ .min-width {
+ min-width: 200px;
+ }
`;
@customElement("or-rule-action-attribute")
@@ -127,19 +131,21 @@ export class OrRuleActionAttribute extends translate(i18next)(LitElement) {
});
}
+ attributes.sort(Util.sortByString((attr) => attr[1]));
+
let attributeInput: TemplateResult | undefined;
if (this.action.attributeName) {
const label = descriptors[1] && (descriptors[1].name === WellknownValueTypes.BOOLEAN) ? "" : i18next.t("value");
let inputType;
if(descriptors[0]?.format?.asSlider) inputType = InputType.NUMBER;
- attributeInput = html`<or-attribute-input .inputType="${ifDefined(inputType)}" @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setActionAttributeValue(ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="${label}" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${this.action.value}" .readonly="${this.readonly || false}"></or-attribute-input>`;
+ attributeInput = html`<or-attribute-input ?compact=${descriptors[1] && (descriptors[1].name === WellknownValueTypes.GEOJSONPOINT)} .inputType="${ifDefined(inputType)}" @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setActionAttributeValue(ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="${label}" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${this.action.value}" .readonly="${this.readonly || false}"></or-attribute-input>`;
}
return html`
- <or-mwc-input id="matchSelect" .label="${i18next.t("asset")}" .type="${InputType.SELECT}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" .readonly="${this.readonly || false}" .options="${idOptions}" .value="${idValue}"></or-mwc-input>
+ <or-mwc-input id="matchSelect" class="min-width" .label="${i18next.t("asset")}" .type="${InputType.SELECT}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" .readonly="${this.readonly || false}" .options="${idOptions}" .value="${idValue}"></or-mwc-input>
${attributes.length > 0 ? html`
- <or-mwc-input id="attributeSelect" .label="${i18next.t("attribute")}" .type="${InputType.SELECT}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setActionAttributeName(e.detail.value)}" .readonly="${this.readonly || false}" .options="${attributes}" .value="${this.action.attributeName}"></or-mwc-input>
+ <or-mwc-input id="attributeSelect" class="min-width" .label="${i18next.t("attribute")}" .type="${InputType.SELECT}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setActionAttributeName(e.detail.value)}" .readonly="${this.readonly || false}" .options="${attributes}" .value="${this.action.attributeName}"></or-mwc-input>
${attributeInput}
` : html`
<or-translate value="No attributes with write permission"></or-translate>
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts
index 66cfd0419..23df50bd1 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts
@@ -29,7 +29,11 @@ const style = css`
}
:host > * {
- margin-right: 10px;
+ margin: 0 3px 6px;
+ }
+
+ .min-width {
+ min-width: 200px;
}
`;
@@ -104,7 +108,7 @@ export class OrRuleActionNotification extends LitElement {
if (targetType === ActionTargetType.CUSTOM) {
const template = html`
- <or-mwc-input .type="${InputType.TEXT}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => onTargetChangedCallback(targetType!, e.detail.value)}" ?readonly="${readonly}" .value="${action.target!.custom}" ></or-mwc-input>
+ <or-mwc-input class="min-width" .type="${InputType.TEXT}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => onTargetChangedCallback(targetType!, e.detail.value)}" ?readonly="${readonly}" .value="${action.target!.custom}" ></or-mwc-input>
`;
targetValueTemplate = Promise.resolve(template);
@@ -193,6 +197,7 @@ export class OrRuleActionNotification extends LitElement {
return html`
<or-mwc-input type="${InputType.SELECT}"
+ class="min-width"
.options="${values}"
.label="${label}"
.value="${value}"
@@ -205,11 +210,12 @@ export class OrRuleActionNotification extends LitElement {
targetValueTemplate = targetValueTemplate.then((valueTemplate) => {
return html`
<or-mwc-input type="${InputType.SELECT}"
- .options="${allowedTargetTypes}"
- .value="${targetType}"
- .label="${i18next.t("recipients")}"
- @or-mwc-input-changed="${(e: OrInputChangedEvent) => onTargetTypeChangedCallback(e.detail.value as ActionTargetType)}"
- ?readonly="${readonly}"></or-mwc-input>
+ class="min-width"
+ .options="${allowedTargetTypes}"
+ .value="${targetType}"
+ .label="${i18next.t("recipients")}"
+ @or-mwc-input-changed="${(e: OrInputChangedEvent) => onTargetTypeChangedCallback(e.detail.value as ActionTargetType)}"
+ ?readonly="${readonly}"></or-mwc-input>
${valueTemplate}
`;
});
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts b/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
index f019a1eec..c3630ec45 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
@@ -49,7 +49,7 @@ const style = css`
}
.min-width {
- min-width: 140px;
+ min-width: 200px;
}
.attribute-group > * {
@@ -170,15 +170,15 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {
const label = Util.getAttributeLabel(undefined, descriptors ? descriptors[0] : undefined, assetDescriptor.name, false);
return [ad.name!, label];
});
- }
+ }
+
+ attributes.sort(Util.sortByString((attr) => attr[1]));
const operators = attributeName ? this.getOperators(assetDescriptor, descriptors ? descriptors[0] : undefined, descriptors ? descriptors[1] : undefined, attribute, attributeName) : [];
return html`
<or-mwc-input type="${InputType.SELECT}" class="min-width" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setAttributeName(attributePredicate, e.detail.value)}" .readonly="${this.readonly || false}" .options="${attributes}" .value="${attributeName}" .label="${i18next.t("attribute")}"></or-mwc-input>
-
${attributeName ? html`<or-mwc-input type="${InputType.SELECT}" class="min-width" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this.setOperator(assetDescriptor, attribute, attributeName, attributePredicate, e.detail.value)}" .readonly="${this.readonly || false}" .options="${operators}" .value="${operator}" .label="${i18next.t("operator")}"></or-mwc-input>` : ``}
-
${attributePredicate ? this.attributePredicateValueEditorTemplate(assetDescriptor, asset, attributePredicate) : ``}
`;
}
@@ -202,7 +202,7 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {
switch (valuePredicate.predicateType) {
case "string":
- return html`<or-attribute-input @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${value}" .readonly="${this.readonly || false}" .fullWidth="${true}"></or-attribute-input>`;
+ return html`<or-attribute-input class="min-width" @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${value}" .readonly="${this.readonly || false}" .fullWidth="${true}"></or-attribute-input>`;
case "boolean":
return html ``; // Handled by the operator IS_TRUE or IS_FALSE
case "datetime":
@@ -217,7 +217,7 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {
}
let inputType;
if(descriptors[0]?.format?.asSlider) inputType = InputType.NUMBER;
- return html`<or-attribute-input .inputType="${ifDefined(inputType)}" @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${value}" .readonly="${this.readonly || false}" .fullWidth="${true}"></or-attribute-input>`;
+ return html`<or-attribute-input .inputType="${ifDefined(inputType)}" @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${value}" .readonly="${this.readonly || false}" .fullWidth="${true}"></or-attribute-input>`;
case "radial":
return html`<or-rule-radial-modal .query="${this.query}" .assetDescriptor="${assetDescriptor}" .attributePredicate="${attributePredicate}"></or-rule-radial-modal>`;
case "rect":
@@ -292,7 +292,7 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {
return html`
<div class="attribute-group">
- <or-mwc-input id="idSelect" type="${InputType.SELECT}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" .readonly="${this.readonly || false}" .options="${idOptions}" .value="${idValue}" .label="${i18next.t("asset")}"></or-mwc-input>
+ <or-mwc-input id="idSelect" class="min-width" type="${InputType.SELECT}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" .readonly="${this.readonly || false}" .options="${idOptions}" .value="${idValue}" .label="${i18next.t("asset")}"></or-mwc-input>
${this.query.attributes && this.query.attributes.items ? this.query.attributes.items.map((attributePredicate) => {
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-condition.ts b/ui/component/or-rules/src/json-viewer/or-rule-condition.ts
index 6d9e7e8f6..f8af2a453 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-condition.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-condition.ts
@@ -149,7 +149,9 @@ class OrRuleCondition extends translate(i18next)(LitElement) {
}
if(this.readonly) {
typeTemplate = html`
+ <div id="type" style="--or-mwc-input-color: #${buttonColor}">
<or-mwc-input readonly type="${InputType.BUTTON}" .icon="${buttonIcon || ""}"></or-mwc-input>
+ </div>
`;
} else {
typeTemplate = html`
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts b/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts
index c3880b389..85f38d170 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts
@@ -235,11 +235,13 @@ class OrRuleThenOtherwise extends translate(i18next)(LitElement) {
}
if(readonly) {
recurrenceTemplate = html`
- <or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t(value)}"></or-mwc-input>
+ <div style="--or-mwc-input-color: ${buttonColor}; margin-right: 6px;">
+ <or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t(value)}"></or-mwc-input>
+ </div>
`;
} else {
recurrenceTemplate = html`
- <div style="--or-mwc-input-color: #${buttonColor}; margin-right: 6px;">
+ <div style="--or-mwc-input-color: ${buttonColor}; margin-right: 6px;">
${getContentWithMenuTemplate(
html`<or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t(value)}"></or-mwc-input>`,
getRecurrenceMenu(this.config),
@@ -299,7 +301,9 @@ class OrRuleThenOtherwise extends translate(i18next)(LitElement) {
if(readonly) {
typeTemplate = html`
- <or-mwc-input type="${InputType.BUTTON}" .icon="${buttonIcon || ""}"></or-mwc-input>
+ <div id="type" style="--or-mwc-input-color: #${buttonColor}">
+ <or-mwc-input type="${InputType.BUTTON}" .icon="${buttonIcon || ""}"></or-mwc-input>
+ </div>
`;
} else {
typeTemplate = html`