Skip to content

armgit / core

Public Imported from GitHub
0

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

Fix/boolean attribute marker color (#1510)

Mihaela Aleksandrovaabc3b302d546
diff --git a/ui/component/or-dashboard-builder/src/panels/thresholds-panel.ts b/ui/component/or-dashboard-builder/src/panels/thresholds-panel.ts
index cfd5ffcde..dee82bd53 100644
--- a/ui/component/or-dashboard-builder/src/panels/thresholds-panel.ts
+++ b/ui/component/or-dashboard-builder/src/panels/thresholds-panel.ts
@@ -121,6 +121,13 @@ export class ThresholdsPanel extends LitElement {
}
}
+ private get colorValue() {
+ return (color?: string) => {
+ if (!color) return "#000000";
+ return color.startsWith('#') ? color : '#' + color;
+ }
+ }
+
protected render(): TemplateResult {
return html`
<div id="thresholds-list" class="expanded-panel">
@@ -173,14 +180,12 @@ export class ThresholdsPanel extends LitElement {
` : null}
<!-- Thresholds by boolean -->
- ${(this.valueType === 'boolean') ? html`
+ ${(this.valueType === 'boolean' && this.boolColors) ? html`
<div class="threshold-list-item">
<div class="threshold-list-item-colour">
- <or-mwc-input type="${InputType.COLOUR}" value="${this.boolColors.true}"
- @or-mwc-input-changed="${(event: OrInputChangedEvent) => {
- this.boolColors.true = event.detail.value;
- this.requestUpdate('boolColors');
- }}"
+ <or-mwc-input type="${InputType.COLOUR}" value="${this.colorValue(this.boolColors?.true)}"
+ @or-mwc-input-changed="${(event: OrInputChangedEvent) => {
+ this.onBoolColorChange(true, event.detail.value)}}"
></or-mwc-input>
</div>
<or-mwc-input type="${InputType.TEXT}" comfortable .value="${'True'}" .readonly="${true}"
@@ -188,11 +193,9 @@ export class ThresholdsPanel extends LitElement {
</div>
<div class="threshold-list-item">
<div class="threshold-list-item-colour">
- <or-mwc-input type="${InputType.COLOUR}" value="${this.boolColors.false}"
+ <or-mwc-input type="${InputType.COLOUR}" value="${this.colorValue(this.boolColors?.false)}"
@or-mwc-input-changed="${(event: OrInputChangedEvent) => {
- this.boolColors.false = event.detail.value;
- this.requestUpdate('boolColors');
- }}"
+ this.onBoolColorChange(false, event.detail.value)}}"
></or-mwc-input>
</div>
<or-mwc-input type="${InputType.TEXT}" comfortable .value="${'False'}" .readonly="${true}"
@@ -245,12 +248,30 @@ export class ThresholdsPanel extends LitElement {
`
}
+ protected onBoolColorChange(isTrue: boolean, newColor: string) {
+ // in case newColor already has '#' prefix
+ const color = newColor.startsWith('#') ? newColor.substring(1) : newColor;
+
+ if (!this.boolColors) {
+ this.boolColors = {
+ type: 'boolean',
+ true: '4caf50',
+ false: 'ef5350'
+ };
+ }
+
+ this.boolColors = {
+ ...this.boolColors,
+ [isTrue ? 'true' : 'false']: color
+ };
+ }
+
protected removeThreshold(threshold: [any, string]) {
switch (typeof threshold[0]) {
case "number":
this.thresholds = (this.thresholds as [number, string][]).filter((x) => x !== threshold);
break;
- default:
+ default:
this.textColors = (this.textColors as [string, string][]).filter((x) => x !== threshold);
break;
}
diff --git a/ui/component/or-dashboard-builder/src/settings/map-settings.ts b/ui/component/or-dashboard-builder/src/settings/map-settings.ts
index bd34badc1..58a2cd171 100644
--- a/ui/component/or-dashboard-builder/src/settings/map-settings.ts
+++ b/ui/component/or-dashboard-builder/src/settings/map-settings.ts
@@ -4,7 +4,7 @@ import {AssetWidgetSettings} from "../util/or-asset-widget";
import {i18next} from "@openremote/or-translate";
import {InputType, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";
import {MapWidgetConfig} from "../widgets/map-widget";
-import {LngLatLike} from "@openremote/or-map";
+import {AttributeMarkerColours, LngLatLike, MapMarkerColours} from "@openremote/or-map";
import "../panels/assettypes-panel";
import "../panels/thresholds-panel";
import {LngLat} from "maplibre-gl"; // TODO: Replace this import
@@ -12,7 +12,7 @@ import {when} from "lit/directives/when.js";
import {AssetTypeSelectEvent, AssetTypesFilterConfig, AttributeNamesSelectEvent} from "../panels/assettypes-panel";
import manager from "@openremote/core";
import {showSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";
-import {ThresholdChangeEvent} from "../panels/thresholds-panel";
+import {BoolColorsChangeEvent, ThresholdChangeEvent} from "../panels/thresholds-panel";
const styling = css`
.switchMwcInputContainer {
@@ -97,9 +97,12 @@ export class MapSettings extends AssetWidgetSettings {
<!-- List of customizable thresholds -->
${when(this.widgetConfig.assetIds.length > 0, () => html`
<settings-panel displayName="thresholds" expanded="${true}">
- <thresholds-panel .thresholds="${this.widgetConfig.thresholds}" .valueType="${this.widgetConfig.valueType}" style="padding-bottom: 12px;"
+ <thresholds-panel .thresholds="${this.widgetConfig.thresholds}"
+ .boolColors="${this.widgetConfig.boolColors}"
+ .valueType="${this.widgetConfig.valueType}" style="padding-bottom: 12px;"
.min="${this.widgetConfig.min}" .max="${this.widgetConfig.max}"
- @threshold-change="${(ev: ThresholdChangeEvent) => this.onThresholdsChange(ev)}">
+ @threshold-change="${(ev: ThresholdChangeEvent) => this.onThresholdsChange(ev)}"
+ @bool-colors-change="${(ev: BoolColorsChangeEvent) => this.onBoolColorsChange(ev)}">
</thresholds-panel>
</settings-panel>
`)}
@@ -182,4 +185,9 @@ export class MapSettings extends AssetWidgetSettings {
this.notifyConfigUpdate();
}
+ protected onBoolColorsChange(ev: BoolColorsChangeEvent) {
+ this.widgetConfig.boolColors = ev.detail as MapMarkerColours;
+ this.notifyConfigUpdate();
+ }
+
}