@openremote/or-map 1.8.0-snapshot.20250725074716 → 1.8.0-snapshot.20250725120001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,167 @@
1
- var __decorate=this&&this.__decorate||function(t,e,s,r){var a,o=arguments.length,i=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,s,r);else for(var n=t.length-1;n>=0;n--)(a=t[n])&&(i=(o<3?a(i):o>3?a(e,s,i):a(e,s))||i);return o>3&&i&&Object.defineProperty(e,s,i),i};import{html as t,LitElement as e}from"lit";import{customElement as s,property as r}from"lit/decorators.js";import{classMap as a}from"lit-html/directives/class-map.js";import{AssetModelUtil as o}from"@openremote/model";import i,{subscribe as n,Util as d}from"@openremote/core";import"@openremote/or-icon";import{mapAssetCardStyle as p}from"./style";import{InputType as c}from"@openremote/or-mwc-components/or-mwc-input";import{getMarkerIconAndColorFromAssetType as l}from"./util";import{getMarkerConfigAttributeName as u}from"./markers/or-map-marker-asset";export class OrMapAssetCardLoadAssetEvent extends CustomEvent{constructor(t){super(OrMapAssetCardLoadAssetEvent.NAME,{bubbles:!0,composed:!0,detail:t})}}OrMapAssetCardLoadAssetEvent.NAME="or-map-asset-card-load-asset";export const DefaultConfig={default:{exclude:["notes"]},assetTypes:{}};let OrMapAssetCard=class extends n(i)(e){constructor(){super(...arguments),this.useAssetColor=!0}static get styles(){return p}shouldUpdate(t){return(!t.has("assetId")||(this.title="",this.assetIds=this.assetId&&this.assetId.length>0?[this.assetId]:void 0,1!==t.size))&&super.shouldUpdate(t)}_onEvent(t){if("asset"===t.eventType)switch(t.cause){case"READ":case"CREATE":case"UPDATE":this.asset=t.asset;break;case"DELETE":this.asset=void 0}"attribute"===t.eventType&&this.asset&&(this.asset=d.updateAsset(this.asset,t),this.requestUpdate())}getCardConfig(){let t=this.config||DefaultConfig;return this.asset&&t.assetTypes&&t.assetTypes.hasOwnProperty(this.asset.type)?t.assetTypes[this.asset.type]:t.default}render(){if(!this.asset)return t``;let e=this.getIcon(),s=this.getColor(),r=this.getCardConfig(),i=Object.values(this.asset.attributes).filter(t=>"location"!==t.name),n=r&&r.include?r.include:void 0,p=r&&r.exclude?r.exclude:[],l=i.filter(t=>(!n||n.indexOf(t.name)>=0)&&(!p||0>p.indexOf(t.name))&&(!t.meta||!t.meta.hasOwnProperty("showOnDashboard")||!!d.getMetaValue("showOnDashboard",t))).sort(d.sortByString(t=>t.name)),h=u(this.markerconfig,this.asset.type);return t`
2
- <div id="card-container" style="${s?"--internal-or-map-asset-card-header-color: #"+s+";":""}">
3
- <div id="header">
4
- ${e?t`<or-icon icon="${e}"></or-icon>`:""}
5
- <span id="title">${this.asset.name}</span>
6
- </div>
7
- <div id="attribute-list">
8
- <ul>
9
- ${l.map(e=>{if(!this.asset||!this.asset.type)return;let s=o.getAttributeAndValueDescriptors(this.asset.type,e.name,e);if(s&&s.length){let r=d.getAttributeLabel(e,s[0],this.asset.type,!0),o=d.getAttributeValueAsString(e,s[0],this.asset.type,!1,"-"),i={highlighted:h===e.name};return t`<li class="${a(i)}"><span class="attribute-name">${r}</span><span class="attribute-value">${o}</span></li>`}})}
10
- </ul>
11
- </div>
12
- ${r&&r.hideViewAsset?t``:t`
13
- <div id="footer">
14
- <or-mwc-input .type="${c.BUTTON}" label="viewAsset" @or-mwc-input-changed="${t=>{t.preventDefault(),this._loadAsset(this.asset.id)}}"></or-mwc-input>
15
- </div>
16
- `}
17
- </div>
18
- `}_loadAsset(t){this.dispatchEvent(new OrMapAssetCardLoadAssetEvent(t))}getIcon(){var t;if(this.asset)return(null==(t=l(o.getAssetDescriptor(this.asset.type)))?void 0:t.icon)||void 0}getColor(){var t;if(this.asset){let e=null==(t=l(o.getAssetDescriptor(this.asset.type)))?void 0:t.color;if(e)return"string"==typeof e?e:e[0].colour}}};__decorate([r({type:String,reflect:!0,attribute:!0})],OrMapAssetCard.prototype,"assetId",void 0),__decorate([r({type:Object,attribute:!0})],OrMapAssetCard.prototype,"asset",void 0),__decorate([r({type:Object})],OrMapAssetCard.prototype,"config",void 0),__decorate([r({type:Object})],OrMapAssetCard.prototype,"markerconfig",void 0),__decorate([r({type:Boolean,attribute:!0})],OrMapAssetCard.prototype,"useAssetColor",void 0),OrMapAssetCard=__decorate([s("or-map-asset-card")],OrMapAssetCard);export{OrMapAssetCard};
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, LitElement } from "lit";
8
+ import { customElement, property } from "lit/decorators.js";
9
+ import { classMap } from 'lit-html/directives/class-map.js';
10
+ import { AssetModelUtil } from "@openremote/model";
11
+ import manager, { subscribe, Util } from "@openremote/core";
12
+ import "@openremote/or-icon";
13
+ import { mapAssetCardStyle } from "./style";
14
+ import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
15
+ import { getMarkerIconAndColorFromAssetType } from "./util";
16
+ import { getMarkerConfigAttributeName } from "./markers/or-map-marker-asset";
17
+ export class OrMapAssetCardLoadAssetEvent extends CustomEvent {
18
+ constructor(assetId) {
19
+ super(OrMapAssetCardLoadAssetEvent.NAME, {
20
+ bubbles: true,
21
+ composed: true,
22
+ detail: assetId
23
+ });
24
+ }
25
+ }
26
+ OrMapAssetCardLoadAssetEvent.NAME = "or-map-asset-card-load-asset";
27
+ export const DefaultConfig = {
28
+ default: {
29
+ exclude: ["notes"]
30
+ },
31
+ assetTypes: {}
32
+ };
33
+ let OrMapAssetCard = class OrMapAssetCard extends subscribe(manager)(LitElement) {
34
+ constructor() {
35
+ super(...arguments);
36
+ this.useAssetColor = true;
37
+ }
38
+ static get styles() {
39
+ return mapAssetCardStyle;
40
+ }
41
+ shouldUpdate(_changedProperties) {
42
+ if (_changedProperties.has("assetId")) {
43
+ this.title = "";
44
+ this.assetIds = this.assetId && this.assetId.length > 0 ? [this.assetId] : undefined;
45
+ if (_changedProperties.size === 1) {
46
+ return false;
47
+ }
48
+ }
49
+ return super.shouldUpdate(_changedProperties);
50
+ }
51
+ _onEvent(event) {
52
+ if (event.eventType === "asset") {
53
+ const assetEvent = event;
54
+ switch (assetEvent.cause) {
55
+ case "READ" /* AssetEventCause.READ */:
56
+ case "CREATE" /* AssetEventCause.CREATE */:
57
+ case "UPDATE" /* AssetEventCause.UPDATE */:
58
+ this.asset = assetEvent.asset;
59
+ break;
60
+ case "DELETE" /* AssetEventCause.DELETE */:
61
+ this.asset = undefined;
62
+ break;
63
+ }
64
+ }
65
+ if (event.eventType === "attribute") {
66
+ if (this.asset) {
67
+ this.asset = Util.updateAsset(this.asset, event);
68
+ this.requestUpdate();
69
+ }
70
+ }
71
+ }
72
+ getCardConfig() {
73
+ let cardConfig = this.config || DefaultConfig;
74
+ if (!this.asset) {
75
+ return cardConfig.default;
76
+ }
77
+ return cardConfig.assetTypes && cardConfig.assetTypes.hasOwnProperty(this.asset.type) ? cardConfig.assetTypes[this.asset.type] : cardConfig.default;
78
+ }
79
+ render() {
80
+ if (!this.asset) {
81
+ return html ``;
82
+ }
83
+ const icon = this.getIcon();
84
+ const color = this.getColor();
85
+ const styleStr = color ? "--internal-or-map-asset-card-header-color: #" + color + ";" : "";
86
+ const cardConfig = this.getCardConfig();
87
+ const attributes = Object.values(this.asset.attributes).filter((attr) => attr.name !== "location" /* WellknownAttributes.LOCATION */);
88
+ const includedAttributes = cardConfig && cardConfig.include ? cardConfig.include : undefined;
89
+ const excludedAttributes = cardConfig && cardConfig.exclude ? cardConfig.exclude : [];
90
+ const attrs = attributes.filter((attr) => (!includedAttributes || includedAttributes.indexOf(attr.name) >= 0)
91
+ && (!excludedAttributes || excludedAttributes.indexOf(attr.name) < 0)
92
+ && (!attr.meta || !attr.meta.hasOwnProperty("showOnDashboard" /* WellknownMetaItems.SHOWONDASHBOARD */) || !!Util.getMetaValue("showOnDashboard" /* WellknownMetaItems.SHOWONDASHBOARD */, attr)))
93
+ .sort(Util.sortByString((listItem) => listItem.name));
94
+ const highlightedAttr = getMarkerConfigAttributeName(this.markerconfig, this.asset.type);
95
+ return html `
96
+ <div id="card-container" style="${styleStr}">
97
+ <div id="header">
98
+ ${icon ? html `<or-icon icon="${icon}"></or-icon>` : ``}
99
+ <span id="title">${this.asset.name}</span>
100
+ </div>
101
+ <div id="attribute-list">
102
+ <ul>
103
+ ${attrs.map((attr) => {
104
+ if (!this.asset || !this.asset.type) {
105
+ return;
106
+ }
107
+ const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(this.asset.type, attr.name, attr);
108
+ if (descriptors && descriptors.length) {
109
+ const label = Util.getAttributeLabel(attr, descriptors[0], this.asset.type, true);
110
+ const value = Util.getAttributeValueAsString(attr, descriptors[0], this.asset.type, false, "-");
111
+ const classes = { highlighted: highlightedAttr === attr.name };
112
+ return html `<li class="${classMap(classes)}"><span class="attribute-name">${label}</span><span class="attribute-value">${value}</span></li>`;
113
+ }
114
+ })}
115
+ </ul>
116
+ </div>
117
+ ${cardConfig && cardConfig.hideViewAsset ? html `` : html `
118
+ <div id="footer">
119
+ <or-mwc-input .type="${InputType.BUTTON}" label="viewAsset" @or-mwc-input-changed="${(e) => { e.preventDefault(); this._loadAsset(this.asset.id); }}"></or-mwc-input>
120
+ </div>
121
+ `}
122
+ </div>
123
+ `;
124
+ }
125
+ _loadAsset(assetId) {
126
+ this.dispatchEvent(new OrMapAssetCardLoadAssetEvent(assetId));
127
+ }
128
+ getIcon() {
129
+ var _a;
130
+ if (this.asset) {
131
+ const descriptor = AssetModelUtil.getAssetDescriptor(this.asset.type);
132
+ const icon = (_a = getMarkerIconAndColorFromAssetType(descriptor)) === null || _a === void 0 ? void 0 : _a.icon;
133
+ return icon ? icon : undefined;
134
+ }
135
+ }
136
+ getColor() {
137
+ var _a;
138
+ if (this.asset) {
139
+ const descriptor = AssetModelUtil.getAssetDescriptor(this.asset.type);
140
+ const color = (_a = getMarkerIconAndColorFromAssetType(descriptor)) === null || _a === void 0 ? void 0 : _a.color;
141
+ if (color) {
142
+ // check if range
143
+ return (typeof color === 'string') ? color : color[0].colour;
144
+ }
145
+ }
146
+ }
147
+ };
148
+ __decorate([
149
+ property({ type: String, reflect: true, attribute: true })
150
+ ], OrMapAssetCard.prototype, "assetId", void 0);
151
+ __decorate([
152
+ property({ type: Object, attribute: true })
153
+ ], OrMapAssetCard.prototype, "asset", void 0);
154
+ __decorate([
155
+ property({ type: Object })
156
+ ], OrMapAssetCard.prototype, "config", void 0);
157
+ __decorate([
158
+ property({ type: Object })
159
+ ], OrMapAssetCard.prototype, "markerconfig", void 0);
160
+ __decorate([
161
+ property({ type: Boolean, attribute: true })
162
+ ], OrMapAssetCard.prototype, "useAssetColor", void 0);
163
+ OrMapAssetCard = __decorate([
164
+ customElement("or-map-asset-card")
165
+ ], OrMapAssetCard);
166
+ export { OrMapAssetCard };
167
+ //# sourceMappingURL=or-map-asset-card.js.map