@openremote/or-rules 1.8.0-snapshot.20250725074716 → 1.8.0-snapshot.20250725120000

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.
Files changed (73) hide show
  1. package/README.md +30 -30
  2. package/custom-elements.json +13 -13
  3. package/dist/umd/index.bundle.js +4744 -4744
  4. package/dist/umd/index.bundle.js.map +1 -1
  5. package/lib/flow-viewer/components/confirmation-dialog.js +61 -24
  6. package/lib/flow-viewer/components/connection-container.js +35 -1
  7. package/lib/flow-viewer/components/connection-line.js +117 -28
  8. package/lib/flow-viewer/components/context-menu.js +140 -45
  9. package/lib/flow-viewer/components/editor-workspace.js +282 -20
  10. package/lib/flow-viewer/components/flow-editor.js +160 -47
  11. package/lib/flow-viewer/components/flow-node-socket.js +146 -31
  12. package/lib/flow-viewer/components/flow-node.js +192 -29
  13. package/lib/flow-viewer/components/internal-picker.js +271 -54
  14. package/lib/flow-viewer/components/node-menu-item.js +132 -32
  15. package/lib/flow-viewer/components/node-panel.js +104 -60
  16. package/lib/flow-viewer/components/notification-dialog.js +55 -23
  17. package/lib/flow-viewer/components/popup-modal.js +113 -54
  18. package/lib/flow-viewer/components/rule-browser.js +119 -30
  19. package/lib/flow-viewer/components/selectable-element.js +71 -1
  20. package/lib/flow-viewer/components/selection-box.js +119 -15
  21. package/lib/flow-viewer/components/top-bar.js +116 -49
  22. package/lib/flow-viewer/components/workspace-contextmenu-options.js +128 -5
  23. package/lib/flow-viewer/components/writable-dropdown.js +51 -5
  24. package/lib/flow-viewer/converters/node-converter.js +10 -1
  25. package/lib/flow-viewer/flow-viewer.js +19 -1
  26. package/lib/flow-viewer/models/camera.js +2 -1
  27. package/lib/flow-viewer/models/context-menu-button.js +2 -1
  28. package/lib/flow-viewer/models/light-node-collection.js +2 -1
  29. package/lib/flow-viewer/models/status.js +8 -1
  30. package/lib/flow-viewer/node-structure/copy.machine.js +34 -1
  31. package/lib/flow-viewer/node-structure/identity.assigner.js +10 -1
  32. package/lib/flow-viewer/node-structure/identity.dom.link.js +4 -1
  33. package/lib/flow-viewer/node-structure/index.js +5 -1
  34. package/lib/flow-viewer/node-structure/socket.type.matcher.js +50 -1
  35. package/lib/flow-viewer/node-structure/utils.js +109 -1
  36. package/lib/flow-viewer/services/copy-paste-manager.js +59 -1
  37. package/lib/flow-viewer/services/exporter.js +67 -1
  38. package/lib/flow-viewer/services/input.js +80 -1
  39. package/lib/flow-viewer/services/integration.js +27 -1
  40. package/lib/flow-viewer/services/modal.js +29 -8
  41. package/lib/flow-viewer/services/project.js +222 -1
  42. package/lib/flow-viewer/services/shortcuts.js +63 -1
  43. package/lib/flow-viewer/styles/editor-workspace-style.js +55 -53
  44. package/lib/flow-viewer/styles/flow-node-style.js +95 -93
  45. package/lib/flow-viewer/styles/picker-styles.js +31 -29
  46. package/lib/flow-viewer/utils.js +49 -1
  47. package/lib/index.js +953 -56
  48. package/lib/json-viewer/forms/or-rule-form-alarm.js +91 -18
  49. package/lib/json-viewer/forms/or-rule-form-email-message.js +51 -12
  50. package/lib/json-viewer/forms/or-rule-form-localized.js +269 -43
  51. package/lib/json-viewer/forms/or-rule-form-push-notification.js +152 -63
  52. package/lib/json-viewer/forms/or-rule-form-webhook.js +296 -101
  53. package/lib/json-viewer/modals/or-rule-alarm-modal.js +173 -17
  54. package/lib/json-viewer/modals/or-rule-notification-modal.js +196 -11
  55. package/lib/json-viewer/modals/or-rule-radial-modal.js +142 -17
  56. package/lib/json-viewer/modals/or-rule-webhook-modal.js +78 -8
  57. package/lib/json-viewer/or-rule-action-alarm.js +97 -5
  58. package/lib/json-viewer/or-rule-action-attribute.js +235 -33
  59. package/lib/json-viewer/or-rule-action-notification.js +465 -56
  60. package/lib/json-viewer/or-rule-action-webhook.js +49 -18
  61. package/lib/json-viewer/or-rule-asset-query.js +849 -126
  62. package/lib/json-viewer/or-rule-condition.js +216 -29
  63. package/lib/json-viewer/or-rule-json-viewer.js +393 -34
  64. package/lib/json-viewer/or-rule-then-otherwise.js +609 -113
  65. package/lib/json-viewer/or-rule-trigger-query.js +227 -57
  66. package/lib/json-viewer/or-rule-when.js +343 -126
  67. package/lib/or-rule-group-viewer.js +106 -12
  68. package/lib/or-rule-text-viewer.js +133 -22
  69. package/lib/or-rule-tree.js +601 -57
  70. package/lib/or-rule-validity.js +373 -62
  71. package/lib/or-rule-viewer.js +361 -81
  72. package/lib/style.js +89 -64
  73. package/package.json +11 -11
@@ -1,11 +1,196 @@
1
- var __decorate=this&&this.__decorate||function(t,o,e,i){var n,r=arguments.length,a=r<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,o,e,i);else for(var l=t.length-1;l>=0;l--)(n=t[l])&&(a=(r<3?n(a):r>3?n(o,e,a):n(o,e))||a);return r>3&&a&&Object.defineProperty(o,e,a),a};import{html as t,LitElement as o}from"lit";import{customElement as e,property as i,query as n}from"lit/decorators.js";import"@openremote/or-mwc-components/or-mwc-input";import{InputType as r}from"@openremote/or-mwc-components/or-mwc-input";import a from"i18next";import{translate as l}from"@openremote/or-translate";import{OrMwcDialogOpenedEvent as c}from"@openremote/or-mwc-components/or-mwc-dialog";import{OrRulesJsonRuleChangedEvent as s}from"../or-rule-json-viewer";let checkValidity=t=>{if(t){let o=t.querySelectorAll("or-mwc-input");return Array.prototype.slice.call(o).every(t=>{if(!t.shadowRoot)return!1;{let o=t.shadowRoot.querySelector("input, textarea, select");return!!(o&&o.checkValidity())||(t._mdcComponent&&(t._mdcComponent.valid=!1,t._mdcComponent.helperTextContent="required"),!1)}})}};export class OrRulesNotificationModalCancelEvent extends CustomEvent{constructor(){super(OrRulesNotificationModalCancelEvent.NAME,{bubbles:!0,composed:!0})}}OrRulesNotificationModalCancelEvent.NAME="or-rules-notification-modal-cancel";export class OrRulesNotificationModalOkEvent extends CustomEvent{constructor(){super(OrRulesNotificationModalOkEvent.NAME,{bubbles:!0,composed:!0})}}OrRulesNotificationModalOkEvent.NAME="or-rules-notification-modal-ok";let OrRuleNotificationModal=class extends l(a)(o){constructor(){super(),this.title="message",this.addEventListener(c.NAME,this.initDialog)}connectedCallback(){return this.addEventListener(s.NAME,this._onJsonRuleChanged),super.connectedCallback()}disconnectedCallback(){return this.removeEventListener(s.NAME,this._onJsonRuleChanged),super.disconnectedCallback()}_onJsonRuleChanged(){this.validateForm()}initDialog(){if(!this._orMwcDialog)return}renderDialogHTML(o){let e=this.shadowRoot.getElementById("notification-modal");if(!this.shadowRoot)return;let i=this.shadowRoot.querySelector(".notification-form-slot");if(e&&i){let o=document.createElement("div");i.assignedNodes({flatten:!0}).forEach(t=>{t instanceof HTMLElement&&o.appendChild(t)}),e.content=t`${o}`,e.dismissAction=null,this.requestUpdate()}}firstUpdated(t){t.has("action")&&this.renderDialogHTML(this.action),this.getUpdateComplete().finally(()=>{this.validateForm()})}validateForm(){var t,o,e;let i=this.checkForm();null==(t=this._orMwcDialog)||t.setActions(null==(e=null==(o=this._orMwcDialog)?void 0:o.actions)?void 0:e.map(t=>("ok"===t.actionName&&(t.disabled=!i),t)))}checkForm(){if(this.shadowRoot){let t=this._orMwcDialog,o=null==t?void 0:t.shadowRoot;if(t&&o){let t=o.querySelector("or-rule-form-email-message"),e=o.querySelector("or-rule-form-push-notification"),i=o.querySelector("or-rule-form-localized");if(null==e?void 0:e.shadowRoot)return checkValidity(e.shadowRoot.querySelector("form"));if(null==t?void 0:t.shadowRoot)return checkValidity(t.shadowRoot.querySelector("form"));if(null==i?void 0:i.shadowRoot)return i.isValid()}}}render(){let o=()=>{this.dispatchEvent(new OrRulesNotificationModalCancelEvent)},e=[{actionName:"cancel",content:t`<or-mwc-input class="button" .type="${r.BUTTON}" label="cancel"></or-mwc-input>`,action:o},{actionName:"ok",content:"ok",disabled:!0,action:()=>{this.dispatchEvent(new OrRulesNotificationModalOkEvent)}}],i=t`
2
- <style>
3
- .mdc-dialog__actions {
4
- justify-content: space-between !important;
5
- }
6
- </style>
7
- `;return t`
8
- <or-mwc-input .type="${r.BUTTON}" label="message" @or-mwc-input-changed="${()=>{let t=this.shadowRoot.getElementById("notification-modal");t&&t.open()}}"></or-mwc-input>
9
- <or-mwc-dialog id="notification-modal" .heading="${this.title}" .dismissAction="${{actionName:"cancel",action:o}}" .actions="${e}" .styles="${i}"></or-mwc-dialog>
10
- <slot class="notification-form-slot"></slot>
11
- `}};__decorate([i({type:Object})],OrRuleNotificationModal.prototype,"action",void 0),__decorate([i({type:String})],OrRuleNotificationModal.prototype,"title",void 0),__decorate([i({type:Object})],OrRuleNotificationModal.prototype,"query",void 0),__decorate([n("#notification-modal")],OrRuleNotificationModal.prototype,"_orMwcDialog",void 0),OrRuleNotificationModal=__decorate([e("or-rule-notification-modal")],OrRuleNotificationModal);export{OrRuleNotificationModal};
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, query } from "lit/decorators.js";
9
+ import "@openremote/or-mwc-components/or-mwc-input";
10
+ import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
11
+ import i18next from "i18next";
12
+ import { translate } from "@openremote/or-translate";
13
+ import { OrMwcDialogOpenedEvent } from "@openremote/or-mwc-components/or-mwc-dialog";
14
+ import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
15
+ const checkValidity = (form) => {
16
+ if (form) {
17
+ const inputs = form.querySelectorAll('or-mwc-input');
18
+ const elements = Array.prototype.slice.call(inputs);
19
+ return elements.every((element) => {
20
+ if (element.shadowRoot) {
21
+ const input = element.shadowRoot.querySelector('input, textarea, select');
22
+ if (input && input.checkValidity()) {
23
+ return true;
24
+ }
25
+ else {
26
+ if (element._mdcComponent) {
27
+ element._mdcComponent.valid = false;
28
+ element._mdcComponent.helperTextContent = 'required';
29
+ }
30
+ return false;
31
+ }
32
+ }
33
+ else {
34
+ return false;
35
+ }
36
+ });
37
+ }
38
+ };
39
+ export class OrRulesNotificationModalCancelEvent extends CustomEvent {
40
+ constructor() {
41
+ super(OrRulesNotificationModalCancelEvent.NAME, {
42
+ bubbles: true,
43
+ composed: true
44
+ });
45
+ }
46
+ }
47
+ OrRulesNotificationModalCancelEvent.NAME = "or-rules-notification-modal-cancel";
48
+ export class OrRulesNotificationModalOkEvent extends CustomEvent {
49
+ constructor() {
50
+ super(OrRulesNotificationModalOkEvent.NAME, {
51
+ bubbles: true,
52
+ composed: true
53
+ });
54
+ }
55
+ }
56
+ OrRulesNotificationModalOkEvent.NAME = "or-rules-notification-modal-ok";
57
+ let OrRuleNotificationModal = class OrRuleNotificationModal extends translate(i18next)(LitElement) {
58
+ constructor() {
59
+ super();
60
+ this.title = "message";
61
+ this.addEventListener(OrMwcDialogOpenedEvent.NAME, this.initDialog);
62
+ }
63
+ connectedCallback() {
64
+ this.addEventListener(OrRulesJsonRuleChangedEvent.NAME, this._onJsonRuleChanged);
65
+ return super.connectedCallback();
66
+ }
67
+ disconnectedCallback() {
68
+ this.removeEventListener(OrRulesJsonRuleChangedEvent.NAME, this._onJsonRuleChanged);
69
+ return super.disconnectedCallback();
70
+ }
71
+ _onJsonRuleChanged() {
72
+ this.validateForm();
73
+ }
74
+ initDialog() {
75
+ if (!this._orMwcDialog)
76
+ return;
77
+ }
78
+ renderDialogHTML(action) {
79
+ const dialog = this.shadowRoot.getElementById("notification-modal");
80
+ if (!this.shadowRoot)
81
+ return;
82
+ const slot = this.shadowRoot.querySelector('.notification-form-slot');
83
+ if (dialog && slot) {
84
+ let container = document.createElement("div");
85
+ slot.assignedNodes({ flatten: true }).forEach((child) => {
86
+ if (child instanceof HTMLElement) {
87
+ container.appendChild(child);
88
+ }
89
+ });
90
+ dialog.content = html `${container}`;
91
+ dialog.dismissAction = null;
92
+ this.requestUpdate();
93
+ }
94
+ }
95
+ firstUpdated(changedProperties) {
96
+ if (changedProperties.has("action")) {
97
+ this.renderDialogHTML(this.action);
98
+ }
99
+ // Possibly, a render is triggered by renderDialogHTML(), so we await the pending update. (if there is any)
100
+ this.getUpdateComplete().finally(() => {
101
+ this.validateForm();
102
+ });
103
+ }
104
+ validateForm() {
105
+ var _a, _b, _c;
106
+ const valid = this.checkForm();
107
+ (_a = this._orMwcDialog) === null || _a === void 0 ? void 0 : _a.setActions((_c = (_b = this._orMwcDialog) === null || _b === void 0 ? void 0 : _b.actions) === null || _c === void 0 ? void 0 : _c.map(action => {
108
+ if (action.actionName === "ok") {
109
+ action.disabled = !valid;
110
+ }
111
+ return action;
112
+ }));
113
+ }
114
+ checkForm() {
115
+ if (this.shadowRoot) {
116
+ const dialog = this._orMwcDialog;
117
+ const root = dialog === null || dialog === void 0 ? void 0 : dialog.shadowRoot;
118
+ if (dialog && root) {
119
+ const messageNotification = root.querySelector("or-rule-form-email-message");
120
+ const pushNotification = root.querySelector("or-rule-form-push-notification");
121
+ const localizedNotification = root.querySelector("or-rule-form-localized");
122
+ if (pushNotification === null || pushNotification === void 0 ? void 0 : pushNotification.shadowRoot) {
123
+ const form = pushNotification.shadowRoot.querySelector('form');
124
+ return checkValidity(form);
125
+ }
126
+ else if (messageNotification === null || messageNotification === void 0 ? void 0 : messageNotification.shadowRoot) {
127
+ const form = messageNotification.shadowRoot.querySelector('form');
128
+ return checkValidity(form);
129
+ }
130
+ else if (localizedNotification === null || localizedNotification === void 0 ? void 0 : localizedNotification.shadowRoot) {
131
+ return localizedNotification.isValid();
132
+ }
133
+ }
134
+ }
135
+ }
136
+ render() {
137
+ const onCancel = () => {
138
+ this.dispatchEvent(new OrRulesNotificationModalCancelEvent());
139
+ };
140
+ const onOk = () => {
141
+ this.dispatchEvent(new OrRulesNotificationModalOkEvent());
142
+ };
143
+ const dismissAction = {
144
+ actionName: "cancel",
145
+ action: onCancel
146
+ };
147
+ const actions = [
148
+ {
149
+ actionName: "cancel",
150
+ content: html `<or-mwc-input class="button" .type="${InputType.BUTTON}" label="cancel"></or-mwc-input>`,
151
+ action: onCancel
152
+ },
153
+ {
154
+ actionName: "ok",
155
+ content: "ok",
156
+ disabled: true, // (by default, can be changed in checkForm())
157
+ action: onOk
158
+ }
159
+ ];
160
+ const styles = html `
161
+ <style>
162
+ .mdc-dialog__actions {
163
+ justify-content: space-between !important;
164
+ }
165
+ </style>
166
+ `;
167
+ const notificationPickerModalOpen = () => {
168
+ const dialog = this.shadowRoot.getElementById("notification-modal");
169
+ if (dialog) {
170
+ dialog.open();
171
+ }
172
+ };
173
+ return html `
174
+ <or-mwc-input .type="${InputType.BUTTON}" label="message" @or-mwc-input-changed="${notificationPickerModalOpen}"></or-mwc-input>
175
+ <or-mwc-dialog id="notification-modal" .heading="${this.title}" .dismissAction="${dismissAction}" .actions="${actions}" .styles="${styles}"></or-mwc-dialog>
176
+ <slot class="notification-form-slot"></slot>
177
+ `;
178
+ }
179
+ };
180
+ __decorate([
181
+ property({ type: Object })
182
+ ], OrRuleNotificationModal.prototype, "action", void 0);
183
+ __decorate([
184
+ property({ type: String })
185
+ ], OrRuleNotificationModal.prototype, "title", void 0);
186
+ __decorate([
187
+ property({ type: Object })
188
+ ], OrRuleNotificationModal.prototype, "query", void 0);
189
+ __decorate([
190
+ query("#notification-modal")
191
+ ], OrRuleNotificationModal.prototype, "_orMwcDialog", void 0);
192
+ OrRuleNotificationModal = __decorate([
193
+ customElement("or-rule-notification-modal")
194
+ ], OrRuleNotificationModal);
195
+ export { OrRuleNotificationModal };
196
+ //# sourceMappingURL=or-rule-notification-modal.js.map
@@ -1,17 +1,142 @@
1
- var __decorate=this&&this.__decorate||function(e,t,a,r){var o,i=arguments.length,l=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,a):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,a,r);else for(var n=e.length-1;n>=0;n--)(o=e[n])&&(l=(i<3?o(l):i>3?o(t,a,l):o(t,a))||l);return i>3&&l&&Object.defineProperty(t,a,l),l};import{html as e,LitElement as t}from"lit";import{customElement as a,property as r}from"lit/decorators.js";import{getAssetTypeFromQuery as o}from"../../index";import"@openremote/or-mwc-components/or-mwc-input";import{InputType as i}from"@openremote/or-mwc-components/or-mwc-input";import l from"i18next";import{OrRulesJsonRuleChangedEvent as n}from"../or-rule-json-viewer";import{translate as d}from"@openremote/or-translate";import{OrMwcDialogOpenedEvent as c}from"@openremote/or-mwc-components/or-mwc-dialog";import{OrMapClickedEvent as s}from"@openremote/or-map";import"@openremote/or-map";let OrRuleRadialModal=class extends d(l)(t){constructor(){super(),this.addEventListener(c.NAME,this.initRadialMap)}initRadialMap(){let e=this.shadowRoot.getElementById("radial-modal");if(!e)return;let t=e.shadowRoot.querySelector(".or-map");if(t){t.addEventListener(s.NAME,t=>{let a=t.detail.lngLat,r=e.shadowRoot.querySelector(".location-lat"),o=e.shadowRoot.querySelector(".location-lng");r.value=a.lat,o.value=a.lng;let i=new Event("change");r.dispatchEvent(i),o.dispatchEvent(i),this.setValuePredicateProperty("lat",a.lat),this.setValuePredicateProperty("lng",a.lng)});let a=e.shadowRoot.querySelector(".location-lat"),r=e.shadowRoot.querySelector(".location-lng");if(r.value&&a.value){let e=[parseFloat(r.value),parseFloat(a.value)];t.flyTo(e,15)}else t.flyTo()}}getAttributeName(e){return e&&e.name?e.name.value:void 0}setValuePredicateProperty(e,t){this.attributePredicate&&this.attributePredicate.value&&(this.attributePredicate.value[e]=t,this.attributePredicate=Object.assign({},this.attributePredicate),this.dispatchEvent(new n),this.requestUpdate())}renderDialogHTML(t){let a=this.shadowRoot.getElementById("radial-modal");a&&(a.content=e`
2
- <div style="display:grid">
3
- <or-map class="or-map" type="VECTOR" style="border: 1px solid #d5d5d5; height: 400px; min-width: 300px; margin-bottom: 20px;">
4
- <or-map-marker active color="#FF0000" icon="information" lat="${t.lat}" lng="${t.lng}" radius="${t.radius}"></or-map-marker>
5
- </or-map>
6
-
7
- <div class="layout horizontal">
8
- <input hidden class="location-lng" required placeholder=" " type="text" .value="${t&&t.lng?t.lng:null}" />
9
- <input hidden class="location-lat" required placeholder=" " type="text" .value="${t&&t.lat?t.lat:null}" />
10
- </div>
11
-
12
- <label>${l.t("radiusMin")}</label>
13
- <input @change="${e=>this.setValuePredicateProperty("radius",parseInt(e.target.value))}" style="max-width: calc(50% - 30px);" required placeholder=" " min="100" type="number" .value="${t&&t.radius?t.radius:100}" />
14
- </div>`)}render(){if(!this.attributePredicate||!this.query)return e``;let t=this.attributePredicate.value;if(!this.assetDescriptor||!t)return e``;this.getAttributeName(this.attributePredicate),o(this.query);let a=t||void 0,r=[{actionName:"cancel",content:e`<or-mwc-input class="button" .type="${i.BUTTON}" label="cancel"></or-mwc-input>`,action:()=>{}},{actionName:"ok",default:!0,content:e`<or-mwc-input class="button" .type="${i.BUTTON}" label="ok"></or-mwc-input>`,action:()=>{}}];return this.renderDialogHTML(a),e`
15
- <or-mwc-input .type="${i.BUTTON}" label="area" @or-mwc-input-changed="${()=>{let e=this.shadowRoot.getElementById("radial-modal");e&&(e.dismissAction=null,e.open(),this.renderDialogHTML(a))}}"></or-mwc-input>
16
- <or-mwc-dialog id="radial-modal" heading="area" .actions="${r}"></or-mwc-dialog>
17
- `}};__decorate([r({type:Object})],OrRuleRadialModal.prototype,"assetDescriptor",void 0),__decorate([r({type:Object})],OrRuleRadialModal.prototype,"attributePredicate",void 0),__decorate([r({type:Object})],OrRuleRadialModal.prototype,"query",void 0),OrRuleRadialModal=__decorate([a("or-rule-radial-modal")],OrRuleRadialModal);export{OrRuleRadialModal};
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 { getAssetTypeFromQuery, } from "../../index";
10
+ import "@openremote/or-mwc-components/or-mwc-input";
11
+ import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
12
+ import i18next from "i18next";
13
+ import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
14
+ import { translate } from "@openremote/or-translate";
15
+ import { OrMwcDialogOpenedEvent } from "@openremote/or-mwc-components/or-mwc-dialog";
16
+ import { OrMapClickedEvent } from "@openremote/or-map";
17
+ import "@openremote/or-map";
18
+ let OrRuleRadialModal = class OrRuleRadialModal extends translate(i18next)(LitElement) {
19
+ constructor() {
20
+ super();
21
+ this.addEventListener(OrMwcDialogOpenedEvent.NAME, this.initRadialMap);
22
+ }
23
+ initRadialMap() {
24
+ const modal = this.shadowRoot.getElementById('radial-modal');
25
+ if (!modal)
26
+ return;
27
+ const map = modal.shadowRoot.querySelector('.or-map');
28
+ if (map) {
29
+ map.addEventListener(OrMapClickedEvent.NAME, (evt) => {
30
+ const lngLat = evt.detail.lngLat;
31
+ const latElement = modal.shadowRoot.querySelector('.location-lat');
32
+ const lngElement = modal.shadowRoot.querySelector('.location-lng');
33
+ latElement.value = lngLat.lat;
34
+ lngElement.value = lngLat.lng;
35
+ const event = new Event('change');
36
+ latElement.dispatchEvent(event);
37
+ lngElement.dispatchEvent(event);
38
+ this.setValuePredicateProperty('lat', lngLat.lat);
39
+ this.setValuePredicateProperty('lng', lngLat.lng);
40
+ });
41
+ const latElement = modal.shadowRoot.querySelector('.location-lat');
42
+ const lngElement = modal.shadowRoot.querySelector('.location-lng');
43
+ if (lngElement.value && latElement.value) {
44
+ const LngLat = [parseFloat(lngElement.value), parseFloat(latElement.value)];
45
+ map.flyTo(LngLat, 15);
46
+ }
47
+ else {
48
+ map.flyTo();
49
+ }
50
+ }
51
+ }
52
+ getAttributeName(attributePredicate) {
53
+ return attributePredicate && attributePredicate.name ? attributePredicate.name.value : undefined;
54
+ }
55
+ setValuePredicateProperty(propertyName, value) {
56
+ if (!this.attributePredicate)
57
+ return;
58
+ if (!this.attributePredicate.value)
59
+ return;
60
+ const valuePredicate = this.attributePredicate.value;
61
+ valuePredicate[propertyName] = value;
62
+ this.attributePredicate = Object.assign({}, this.attributePredicate);
63
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
64
+ this.requestUpdate();
65
+ }
66
+ renderDialogHTML(value) {
67
+ const dialog = this.shadowRoot.getElementById("radial-modal");
68
+ if (dialog) {
69
+ dialog.content = html `
70
+ <div style="display:grid">
71
+ <or-map class="or-map" type="VECTOR" style="border: 1px solid #d5d5d5; height: 400px; min-width: 300px; margin-bottom: 20px;">
72
+ <or-map-marker active color="#FF0000" icon="information" lat="${value.lat}" lng="${value.lng}" radius="${value.radius}"></or-map-marker>
73
+ </or-map>
74
+
75
+ <div class="layout horizontal">
76
+ <input hidden class="location-lng" required placeholder=" " type="text" .value="${value && value.lng ? value.lng : null}" />
77
+ <input hidden class="location-lat" required placeholder=" " type="text" .value="${value && value.lat ? value.lat : null}" />
78
+ </div>
79
+
80
+ <label>${i18next.t("radiusMin")}</label>
81
+ <input @change="${(e) => this.setValuePredicateProperty("radius", parseInt(e.target.value))}" style="max-width: calc(50% - 30px);" required placeholder=" " min="100" type="number" .value="${value && value.radius ? value.radius : 100}" />
82
+ </div>`;
83
+ }
84
+ }
85
+ render() {
86
+ if (!this.attributePredicate)
87
+ return html ``;
88
+ if (!this.query)
89
+ return html ``;
90
+ const valuePredicate = this.attributePredicate.value;
91
+ if (!this.assetDescriptor || !valuePredicate) {
92
+ return html ``;
93
+ }
94
+ const attributeName = this.getAttributeName(this.attributePredicate);
95
+ const assetType = getAssetTypeFromQuery(this.query);
96
+ // @ts-ignore
97
+ const value = valuePredicate ? valuePredicate : undefined;
98
+ const radiusPickerModalActions = [
99
+ {
100
+ actionName: "cancel",
101
+ content: html `<or-mwc-input class="button" .type="${InputType.BUTTON}" label="cancel"></or-mwc-input>`,
102
+ action: () => {
103
+ // Nothing to do here
104
+ }
105
+ },
106
+ {
107
+ actionName: "ok",
108
+ default: true,
109
+ content: html `<or-mwc-input class="button" .type="${InputType.BUTTON}" label="ok"></or-mwc-input>`,
110
+ action: () => {
111
+ }
112
+ }
113
+ ];
114
+ const radialPickerModalOpen = () => {
115
+ const dialog = this.shadowRoot.getElementById("radial-modal");
116
+ if (dialog) {
117
+ dialog.dismissAction = null;
118
+ dialog.open();
119
+ this.renderDialogHTML(value);
120
+ }
121
+ };
122
+ this.renderDialogHTML(value);
123
+ return html `
124
+ <or-mwc-input .type="${InputType.BUTTON}" label="area" @or-mwc-input-changed="${radialPickerModalOpen}"></or-mwc-input>
125
+ <or-mwc-dialog id="radial-modal" heading="area" .actions="${radiusPickerModalActions}"></or-mwc-dialog>
126
+ `;
127
+ }
128
+ };
129
+ __decorate([
130
+ property({ type: Object })
131
+ ], OrRuleRadialModal.prototype, "assetDescriptor", void 0);
132
+ __decorate([
133
+ property({ type: Object })
134
+ ], OrRuleRadialModal.prototype, "attributePredicate", void 0);
135
+ __decorate([
136
+ property({ type: Object })
137
+ ], OrRuleRadialModal.prototype, "query", void 0);
138
+ OrRuleRadialModal = __decorate([
139
+ customElement("or-rule-radial-modal")
140
+ ], OrRuleRadialModal);
141
+ export { OrRuleRadialModal };
142
+ //# sourceMappingURL=or-rule-radial-modal.js.map
@@ -1,8 +1,78 @@
1
- var __decorate=this&&this.__decorate||function(e,o,t,r){var l,i=arguments.length,a=i<3?o:null===r?r=Object.getOwnPropertyDescriptor(o,t):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,o,t,r);else for(var n=e.length-1;n>=0;n--)(l=e[n])&&(a=(i<3?l(a):i>3?l(o,t,a):l(o,t))||a);return i>3&&a&&Object.defineProperty(o,t,a),a};import{InputType as e}from"@openremote/or-mwc-components/or-mwc-input";import{i18next as o}from"@openremote/or-translate";import{html as t,LitElement as r}from"lit";import{customElement as l,property as i}from"lit/decorators.js";let OrRuleWebhookModal=class extends r{constructor(){super(),this.title=o.t("message")}firstUpdated(e){e.has("action")&&this.renderDialogHTML(this.action)}renderDialogHTML(e){let o=this.shadowRoot.getElementById("webhook-modal");if(!this.shadowRoot)return;let r=this.shadowRoot.querySelector(".webhook-form-slot");if(o&&r){let e=document.createElement("div");r.assignedNodes({flatten:!0}).forEach(o=>{o instanceof HTMLElement&&e.appendChild(o)}),o.content=t`${e}`,o.dismissAction=null,this.requestUpdate()}}closeForm(e){this.shadowRoot.host.close()}render(){if(!this.action)return t`${o.t("errorOccurred")}`;let r=[{actionName:"",content:t`
2
- <or-mwc-input .type="${e.BUTTON}" label="ok"
3
- @or-mwc-input-changed="${this.closeForm}"></or-mwc-input>`}];return t`
4
- <or-mwc-input type="${e.BUTTON}" label="message"
5
- @or-mwc-input-changed="${()=>{let e=this.shadowRoot.getElementById("webhook-modal");e&&e.open()}}"></or-mwc-input>
6
- <or-mwc-dialog id="webhook-modal" heading="${this.title}" .actions="${r}"></or-mwc-dialog>
7
- <slot class="webhook-form-slot"></slot>
8
- `}};__decorate([i({type:Object})],OrRuleWebhookModal.prototype,"action",void 0),__decorate([i({type:String})],OrRuleWebhookModal.prototype,"title",void 0),OrRuleWebhookModal=__decorate([l("or-rule-webhook-modal")],OrRuleWebhookModal);export{OrRuleWebhookModal};
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 { InputType } from "@openremote/or-mwc-components/or-mwc-input";
8
+ import { i18next } from "@openremote/or-translate";
9
+ import { html, LitElement } from "lit";
10
+ import { customElement, property } from "lit/decorators.js";
11
+ let OrRuleWebhookModal = class OrRuleWebhookModal extends LitElement {
12
+ constructor() {
13
+ super();
14
+ this.title = i18next.t('message');
15
+ }
16
+ /* ----------------------- */
17
+ firstUpdated(changedProperties) {
18
+ if (changedProperties.has("action")) {
19
+ this.renderDialogHTML(this.action);
20
+ }
21
+ }
22
+ renderDialogHTML(action) {
23
+ const dialog = this.shadowRoot.getElementById("webhook-modal");
24
+ if (!this.shadowRoot)
25
+ return;
26
+ const slot = this.shadowRoot.querySelector('.webhook-form-slot');
27
+ if (dialog && slot) {
28
+ let container = document.createElement("div");
29
+ slot.assignedNodes({ flatten: true }).forEach((child) => {
30
+ if (child instanceof HTMLElement) {
31
+ container.appendChild(child);
32
+ }
33
+ });
34
+ dialog.content = html `${container}`;
35
+ dialog.dismissAction = null;
36
+ this.requestUpdate();
37
+ }
38
+ }
39
+ closeForm(event) {
40
+ const dialog = this.shadowRoot.host;
41
+ dialog.close();
42
+ }
43
+ render() {
44
+ if (!this.action) {
45
+ return html `${i18next.t('errorOccurred')}`;
46
+ }
47
+ const webhookModalActions = [
48
+ {
49
+ actionName: "", content: html `
50
+ <or-mwc-input .type="${InputType.BUTTON}" label="ok"
51
+ @or-mwc-input-changed="${this.closeForm}"></or-mwc-input>`
52
+ }
53
+ ];
54
+ const webhookModalOpen = () => {
55
+ const dialog = this.shadowRoot.getElementById("webhook-modal");
56
+ if (dialog) {
57
+ dialog.open();
58
+ }
59
+ };
60
+ return html `
61
+ <or-mwc-input type="${InputType.BUTTON}" label="message"
62
+ @or-mwc-input-changed="${webhookModalOpen}"></or-mwc-input>
63
+ <or-mwc-dialog id="webhook-modal" heading="${this.title}" .actions="${webhookModalActions}"></or-mwc-dialog>
64
+ <slot class="webhook-form-slot"></slot>
65
+ `;
66
+ }
67
+ };
68
+ __decorate([
69
+ property({ type: Object })
70
+ ], OrRuleWebhookModal.prototype, "action", void 0);
71
+ __decorate([
72
+ property({ type: String })
73
+ ], OrRuleWebhookModal.prototype, "title", void 0);
74
+ OrRuleWebhookModal = __decorate([
75
+ customElement("or-rule-webhook-modal")
76
+ ], OrRuleWebhookModal);
77
+ export { OrRuleWebhookModal };
78
+ //# sourceMappingURL=or-rule-webhook-modal.js.map
@@ -1,5 +1,97 @@
1
- var __decorate=this&&this.__decorate||function(e,t,r,o){var a,i=arguments.length,l=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,r,o);else for(var c=e.length-1;c>=0;c--)(a=e[c])&&(l=(i<3?a(l):i>3?a(t,r,l):a(t,r))||l);return i>3&&l&&Object.defineProperty(t,r,l),l},__awaiter=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))(function(a,i){function l(e){try{n(o.next(e))}catch(e){i(e)}}function c(e){try{n(o.throw(e))}catch(e){i(e)}}function n(e){var t;e.done?a(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(l,c)}n((o=o.apply(e,t||[])).next())})};import{html as e,LitElement as t}from"lit";import{customElement as r,property as o}from"lit/decorators.js";import"./modals/or-rule-alarm-modal";import"./forms/or-rule-form-alarm";import a from"@openremote/core";let OrRuleActionAlarm=class extends t{constructor(){super(...arguments),this._loadedUsers=[]}connectedCallback(){let e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});return __awaiter(this,void 0,void 0,function*(){yield this.loadUsers(),e.connectedCallback.call(this)})}loadUsers(){return __awaiter(this,void 0,void 0,function*(){let e=yield a.rest.api.UserResource.query({realmPredicate:{name:a.displayRealm}});200===e.status&&(this._loadedUsers=e.data.filter(e=>e.enabled&&!e.serviceAccount))})}render(){if(!this.action.alarm||!this.action.alarm.title)return e``;let t=this.action.alarm,r="";return t&&(r=e`
2
- <or-rule-alarm-modal title="alarm." .action="${this.action}">
3
- <or-rule-form-alarm .users="${this._loadedUsers}" .action="${this.action}"></or-rule-form-alarm>
4
- </or-rule-alarm-modal>
5
- `),e`${r}`}};__decorate([o({type:Object,attribute:!1})],OrRuleActionAlarm.prototype,"rule",void 0),__decorate([o({type:Object,attribute:!1})],OrRuleActionAlarm.prototype,"action",void 0),__decorate([o({type:String,attribute:!1})],OrRuleActionAlarm.prototype,"actionType",void 0),__decorate([o({type:Object})],OrRuleActionAlarm.prototype,"config",void 0),OrRuleActionAlarm=__decorate([r("or-rule-action-alarm")],OrRuleActionAlarm);export{OrRuleActionAlarm};
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ /*
17
+ * Copyright 2024, OpenRemote Inc.
18
+ *
19
+ * See the CONTRIBUTORS.txt file in the distribution for a
20
+ * full listing of individual contributors.
21
+ *
22
+ * This program is free software: you can redistribute it and/or modify
23
+ * it under the terms of the GNU Affero General Public License as
24
+ * published by the Free Software Foundation, either version 3 of the
25
+ * License, or (at your option) any later version.
26
+ *
27
+ * This program is distributed in the hope that it will be useful,
28
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
+ * GNU Affero General Public License for more details.
31
+ *
32
+ * You should have received a copy of the GNU Affero General Public License
33
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
34
+ */
35
+ import { html, LitElement } from "lit";
36
+ import { customElement, property } from "lit/decorators.js";
37
+ import "./modals/or-rule-alarm-modal";
38
+ import "./forms/or-rule-form-alarm";
39
+ import manager from "@openremote/core";
40
+ let OrRuleActionAlarm = class OrRuleActionAlarm extends LitElement {
41
+ constructor() {
42
+ super(...arguments);
43
+ this._loadedUsers = [];
44
+ }
45
+ connectedCallback() {
46
+ const _super = Object.create(null, {
47
+ connectedCallback: { get: () => super.connectedCallback }
48
+ });
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ yield this.loadUsers();
51
+ _super.connectedCallback.call(this);
52
+ });
53
+ }
54
+ loadUsers() {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const usersResponse = yield manager.rest.api.UserResource.query({
57
+ realmPredicate: { name: manager.displayRealm },
58
+ });
59
+ if (usersResponse.status !== 200) {
60
+ return;
61
+ }
62
+ this._loadedUsers = usersResponse.data.filter((user) => user.enabled && !user.serviceAccount);
63
+ });
64
+ }
65
+ render() {
66
+ if (!this.action.alarm || !this.action.alarm.title) {
67
+ return html ``;
68
+ }
69
+ const alarm = this.action.alarm;
70
+ let modalTemplate = ``;
71
+ if (alarm) {
72
+ modalTemplate = html `
73
+ <or-rule-alarm-modal title="alarm." .action="${this.action}">
74
+ <or-rule-form-alarm .users="${this._loadedUsers}" .action="${this.action}"></or-rule-form-alarm>
75
+ </or-rule-alarm-modal>
76
+ `;
77
+ }
78
+ return html `${modalTemplate}`;
79
+ }
80
+ };
81
+ __decorate([
82
+ property({ type: Object, attribute: false })
83
+ ], OrRuleActionAlarm.prototype, "rule", void 0);
84
+ __decorate([
85
+ property({ type: Object, attribute: false })
86
+ ], OrRuleActionAlarm.prototype, "action", void 0);
87
+ __decorate([
88
+ property({ type: String, attribute: false })
89
+ ], OrRuleActionAlarm.prototype, "actionType", void 0);
90
+ __decorate([
91
+ property({ type: Object })
92
+ ], OrRuleActionAlarm.prototype, "config", void 0);
93
+ OrRuleActionAlarm = __decorate([
94
+ customElement("or-rule-action-alarm")
95
+ ], OrRuleActionAlarm);
96
+ export { OrRuleActionAlarm };
97
+ //# sourceMappingURL=or-rule-action-alarm.js.map