@openremote/or-rules 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.
- package/README.md +30 -30
- package/custom-elements.json +13 -13
- package/dist/umd/index.bundle.js +4744 -4744
- package/dist/umd/index.bundle.js.map +1 -1
- package/lib/flow-viewer/components/confirmation-dialog.js +61 -24
- package/lib/flow-viewer/components/connection-container.js +35 -1
- package/lib/flow-viewer/components/connection-line.js +117 -28
- package/lib/flow-viewer/components/context-menu.js +140 -45
- package/lib/flow-viewer/components/editor-workspace.js +282 -20
- package/lib/flow-viewer/components/flow-editor.js +160 -47
- package/lib/flow-viewer/components/flow-node-socket.js +146 -31
- package/lib/flow-viewer/components/flow-node.js +192 -29
- package/lib/flow-viewer/components/internal-picker.js +271 -54
- package/lib/flow-viewer/components/node-menu-item.js +132 -32
- package/lib/flow-viewer/components/node-panel.js +104 -60
- package/lib/flow-viewer/components/notification-dialog.js +55 -23
- package/lib/flow-viewer/components/popup-modal.js +113 -54
- package/lib/flow-viewer/components/rule-browser.js +119 -30
- package/lib/flow-viewer/components/selectable-element.js +71 -1
- package/lib/flow-viewer/components/selection-box.js +119 -15
- package/lib/flow-viewer/components/top-bar.js +116 -49
- package/lib/flow-viewer/components/workspace-contextmenu-options.js +128 -5
- package/lib/flow-viewer/components/writable-dropdown.js +51 -5
- package/lib/flow-viewer/converters/node-converter.js +10 -1
- package/lib/flow-viewer/flow-viewer.js +19 -1
- package/lib/flow-viewer/models/camera.js +2 -1
- package/lib/flow-viewer/models/context-menu-button.js +2 -1
- package/lib/flow-viewer/models/light-node-collection.js +2 -1
- package/lib/flow-viewer/models/status.js +8 -1
- package/lib/flow-viewer/node-structure/copy.machine.js +34 -1
- package/lib/flow-viewer/node-structure/identity.assigner.js +10 -1
- package/lib/flow-viewer/node-structure/identity.dom.link.js +4 -1
- package/lib/flow-viewer/node-structure/index.js +5 -1
- package/lib/flow-viewer/node-structure/socket.type.matcher.js +50 -1
- package/lib/flow-viewer/node-structure/utils.js +109 -1
- package/lib/flow-viewer/services/copy-paste-manager.js +59 -1
- package/lib/flow-viewer/services/exporter.js +67 -1
- package/lib/flow-viewer/services/input.js +80 -1
- package/lib/flow-viewer/services/integration.js +27 -1
- package/lib/flow-viewer/services/modal.js +29 -8
- package/lib/flow-viewer/services/project.js +222 -1
- package/lib/flow-viewer/services/shortcuts.js +63 -1
- package/lib/flow-viewer/styles/editor-workspace-style.js +55 -53
- package/lib/flow-viewer/styles/flow-node-style.js +95 -93
- package/lib/flow-viewer/styles/picker-styles.js +31 -29
- package/lib/flow-viewer/utils.js +49 -1
- package/lib/index.js +953 -56
- package/lib/json-viewer/forms/or-rule-form-alarm.js +91 -18
- package/lib/json-viewer/forms/or-rule-form-email-message.js +51 -12
- package/lib/json-viewer/forms/or-rule-form-localized.js +269 -43
- package/lib/json-viewer/forms/or-rule-form-push-notification.js +152 -63
- package/lib/json-viewer/forms/or-rule-form-webhook.js +296 -101
- package/lib/json-viewer/modals/or-rule-alarm-modal.js +173 -17
- package/lib/json-viewer/modals/or-rule-notification-modal.js +196 -11
- package/lib/json-viewer/modals/or-rule-radial-modal.js +142 -17
- package/lib/json-viewer/modals/or-rule-webhook-modal.js +78 -8
- package/lib/json-viewer/or-rule-action-alarm.js +97 -5
- package/lib/json-viewer/or-rule-action-attribute.js +235 -33
- package/lib/json-viewer/or-rule-action-notification.js +465 -56
- package/lib/json-viewer/or-rule-action-webhook.js +49 -18
- package/lib/json-viewer/or-rule-asset-query.js +849 -126
- package/lib/json-viewer/or-rule-condition.js +216 -29
- package/lib/json-viewer/or-rule-json-viewer.js +393 -34
- package/lib/json-viewer/or-rule-then-otherwise.js +609 -113
- package/lib/json-viewer/or-rule-trigger-query.js +227 -57
- package/lib/json-viewer/or-rule-when.js +343 -126
- package/lib/or-rule-group-viewer.js +106 -12
- package/lib/or-rule-text-viewer.js +133 -22
- package/lib/or-rule-tree.js +601 -57
- package/lib/or-rule-validity.js +373 -62
- package/lib/or-rule-viewer.js +361 -81
- package/lib/style.js +89 -64
- package/package.json +11 -11
|
@@ -1,113 +1,609 @@
|
|
|
1
|
-
var __decorate=
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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 { css, html, LitElement } from "lit";
|
|
8
|
+
import { customElement, property } from "lit/decorators.js";
|
|
9
|
+
import { buttonStyle } from "../style";
|
|
10
|
+
import "./or-rule-asset-query";
|
|
11
|
+
import { getAssetTypeFromQuery } from "../index";
|
|
12
|
+
import { OrRulesJsonRuleChangedEvent } from "./or-rule-json-viewer";
|
|
13
|
+
import { AssetModelUtil } from "@openremote/model";
|
|
14
|
+
import i18next from "i18next";
|
|
15
|
+
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
|
|
16
|
+
import { getContentWithMenuTemplate } from "@openremote/or-mwc-components/or-mwc-menu";
|
|
17
|
+
import { manager, Util } from "@openremote/core";
|
|
18
|
+
import "./or-rule-action-attribute";
|
|
19
|
+
import "./or-rule-action-notification";
|
|
20
|
+
import "./or-rule-action-webhook";
|
|
21
|
+
import "./or-rule-action-alarm";
|
|
22
|
+
import { translate } from "@openremote/or-translate";
|
|
23
|
+
const NOTIFICATION_COLOR = "4B87EA";
|
|
24
|
+
const WAIT_COLOR = "EACC54";
|
|
25
|
+
const ALARM_COLOR = "FC2D2D";
|
|
26
|
+
function getActionTypesMenu(config, assetInfos) {
|
|
27
|
+
let addAssetTypes = true;
|
|
28
|
+
let addWait = true;
|
|
29
|
+
let addAlarm = true;
|
|
30
|
+
let addEmailNotification = true;
|
|
31
|
+
let addEmailLocalizedNotification = true;
|
|
32
|
+
let addPushNotification = true;
|
|
33
|
+
let addPushLocalizedNotification = true;
|
|
34
|
+
let addWebhook = true;
|
|
35
|
+
let multiLanguage = false;
|
|
36
|
+
if (config && config.controls && config.controls.allowedActionTypes) {
|
|
37
|
+
addAssetTypes = config.controls.allowedActionTypes.indexOf("attribute" /* ActionType.ATTRIBUTE */) >= 0;
|
|
38
|
+
addWait = config.controls.allowedActionTypes.indexOf("wait" /* ActionType.WAIT */) >= 0;
|
|
39
|
+
addAlarm = config.controls.allowedActionTypes.indexOf("alarm" /* ActionType.ALARM */) >= 0;
|
|
40
|
+
addEmailNotification = config.controls.allowedActionTypes.indexOf("email" /* ActionType.EMAIL */) >= 0;
|
|
41
|
+
addEmailLocalizedNotification = config.controls.allowedActionTypes.indexOf("email_localized" /* ActionType.EMAIL_LOCALIZED */) >= 0;
|
|
42
|
+
addPushNotification = config.controls.allowedActionTypes.indexOf("push" /* ActionType.PUSH_NOTIFICATION */) >= 0;
|
|
43
|
+
addPushLocalizedNotification = config.controls.allowedActionTypes.indexOf("push_localized" /* ActionType.PUSH_LOCALIZED */) >= 0;
|
|
44
|
+
addWebhook = config.controls.allowedActionTypes.indexOf("webhook" /* ActionType.WEBHOOK */) >= 0;
|
|
45
|
+
}
|
|
46
|
+
// If the RulesConfig has an entry for notifications, check if there are languages configured.
|
|
47
|
+
// When there are, new notifications will be a "multi-language notification", with a different modal form.
|
|
48
|
+
if (config === null || config === void 0 ? void 0 : config.notifications) {
|
|
49
|
+
multiLanguage = Object.entries(config.notifications).filter(x => (x[0] === manager.displayRealm || x[0] === "default") && x[1] !== undefined).length > 0;
|
|
50
|
+
}
|
|
51
|
+
const menu = [];
|
|
52
|
+
if (addAssetTypes && assetInfos) {
|
|
53
|
+
menu.push(...assetInfos.filter((assetInfo) => assetInfo.assetDescriptor.descriptorType !== "agent").map((assetTypeInfo) => {
|
|
54
|
+
const color = AssetModelUtil.getAssetDescriptorColour(assetTypeInfo);
|
|
55
|
+
const icon = AssetModelUtil.getAssetDescriptorIcon(assetTypeInfo);
|
|
56
|
+
const styleMap = color ? { "--or-icon-fill": "#" + color } : undefined;
|
|
57
|
+
return {
|
|
58
|
+
text: Util.getAssetTypeLabel(assetTypeInfo.assetDescriptor),
|
|
59
|
+
value: assetTypeInfo.assetDescriptor.name,
|
|
60
|
+
icon: icon ? icon : AssetModelUtil.getAssetDescriptorIcon("ThingAsset" /* WellknownAssets.THINGASSET */),
|
|
61
|
+
styleMap: styleMap
|
|
62
|
+
};
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
menu.sort(Util.sortByString((listItem) => listItem === null || listItem === void 0 ? void 0 : listItem.value));
|
|
66
|
+
menu.push(null); // divider
|
|
67
|
+
if (addEmailNotification) {
|
|
68
|
+
menu.push({
|
|
69
|
+
text: i18next.t("email"),
|
|
70
|
+
icon: "email",
|
|
71
|
+
value: multiLanguage && addEmailLocalizedNotification ? "email_localized" /* ActionType.EMAIL_LOCALIZED */ : "email" /* ActionType.EMAIL */,
|
|
72
|
+
styleMap: { "--or-icon-fill": "#" + NOTIFICATION_COLOR }
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (addPushNotification) {
|
|
76
|
+
menu.push({
|
|
77
|
+
text: i18next.t("push-notification"),
|
|
78
|
+
icon: "cellphone-message",
|
|
79
|
+
value: multiLanguage && addPushLocalizedNotification ? "push_localized" /* ActionType.PUSH_LOCALIZED */ : "push" /* ActionType.PUSH_NOTIFICATION */,
|
|
80
|
+
styleMap: { "--or-icon-fill": "#" + NOTIFICATION_COLOR }
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (addWait) {
|
|
84
|
+
menu.push({
|
|
85
|
+
text: i18next.t("wait"),
|
|
86
|
+
icon: "timer",
|
|
87
|
+
value: "wait" /* ActionType.WAIT */,
|
|
88
|
+
styleMap: { "--or-icon-fill": "#" + WAIT_COLOR }
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (addAlarm) {
|
|
92
|
+
menu.push({
|
|
93
|
+
text: i18next.t("alarm."),
|
|
94
|
+
icon: "bell-outline",
|
|
95
|
+
value: "alarm" /* ActionType.ALARM */,
|
|
96
|
+
styleMap: { "--or-icon-fill": "#" + ALARM_COLOR }
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (addWebhook) {
|
|
100
|
+
menu.push({
|
|
101
|
+
text: i18next.t("webhook"),
|
|
102
|
+
icon: "webhook",
|
|
103
|
+
value: "webhook" /* ActionType.WEBHOOK */,
|
|
104
|
+
styleMap: { "--or-icon-fill": "#" + NOTIFICATION_COLOR }
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return menu;
|
|
108
|
+
}
|
|
109
|
+
export var RecurrenceOption;
|
|
110
|
+
(function (RecurrenceOption) {
|
|
111
|
+
RecurrenceOption["ALWAYS"] = "always";
|
|
112
|
+
RecurrenceOption["ONCE"] = "once";
|
|
113
|
+
RecurrenceOption["ONCE_PER_HOUR"] = "oncePerHour";
|
|
114
|
+
RecurrenceOption["ONCE_PER_DAY"] = "oncePerDay";
|
|
115
|
+
RecurrenceOption["ONCE_PER_WEEK"] = "oncePerWeek";
|
|
116
|
+
})(RecurrenceOption || (RecurrenceOption = {}));
|
|
117
|
+
function getRecurrenceMenu(config) {
|
|
118
|
+
if (config && config.controls && config.controls.allowedRecurrenceOptions) {
|
|
119
|
+
return config.controls.allowedRecurrenceOptions.map((value) => {
|
|
120
|
+
return {
|
|
121
|
+
text: i18next.t(value),
|
|
122
|
+
value: value
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return Object.values(RecurrenceOption).map((value) => {
|
|
127
|
+
return {
|
|
128
|
+
text: i18next.t(value),
|
|
129
|
+
value: value
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
// language=CSS
|
|
134
|
+
const style = css `
|
|
135
|
+
|
|
136
|
+
:host {
|
|
137
|
+
display: flex;
|
|
138
|
+
width: 100%;
|
|
139
|
+
flex-direction: column;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
${buttonStyle}
|
|
143
|
+
|
|
144
|
+
.rule-action {
|
|
145
|
+
display: flex;
|
|
146
|
+
margin: 10px 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.rule-action-wrapper {
|
|
150
|
+
flex-grow: 1;
|
|
151
|
+
display: flex;
|
|
152
|
+
align-items: baseline;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.rule-action > button {
|
|
156
|
+
flex-grow: 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.rule-action:hover .button-clear {
|
|
160
|
+
visibility: visible;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
or-panel:hover .remove-button.button-clear {
|
|
164
|
+
visibility: visible;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
or-panel {
|
|
168
|
+
position: relative;
|
|
169
|
+
margin: 10px 10px 20px 10px;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
#type-selector {
|
|
173
|
+
margin-top: 10px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.add-button-wrapper {
|
|
177
|
+
display: flex;
|
|
178
|
+
align-items: center;
|
|
179
|
+
white-space: nowrap;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.add-button-wrapper > * {
|
|
183
|
+
margin-right: 6px;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.add-button-wrapper or-mwc-menu {
|
|
187
|
+
text-transform: capitalize;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#type {
|
|
191
|
+
white-space: nowrap;
|
|
192
|
+
margin: 4px 3px auto 0;
|
|
193
|
+
text-transform: capitalize;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.rule-recurrence {
|
|
197
|
+
position: absolute;
|
|
198
|
+
top: 5px;
|
|
199
|
+
right: 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
`;
|
|
203
|
+
let OrRuleThenOtherwise = class OrRuleThenOtherwise extends translate(i18next)(LitElement) {
|
|
204
|
+
static get styles() {
|
|
205
|
+
return style;
|
|
206
|
+
}
|
|
207
|
+
get thenAllowAdd() {
|
|
208
|
+
return !this.config || !this.config.controls || this.config.controls.hideThenAddAction !== true;
|
|
209
|
+
}
|
|
210
|
+
ruleRecurrenceTemplate(reset, readonly) {
|
|
211
|
+
let recurrenceTemplate = ``;
|
|
212
|
+
const buttonColor = "inherit";
|
|
213
|
+
let value = RecurrenceOption.ONCE;
|
|
214
|
+
if (reset) {
|
|
215
|
+
if (reset.mins === undefined || reset.mins === null) {
|
|
216
|
+
value = RecurrenceOption.ONCE;
|
|
217
|
+
}
|
|
218
|
+
else if (reset.mins === 0) {
|
|
219
|
+
value = RecurrenceOption.ALWAYS;
|
|
220
|
+
}
|
|
221
|
+
else if (reset.mins === 60) {
|
|
222
|
+
value = RecurrenceOption.ONCE_PER_HOUR;
|
|
223
|
+
}
|
|
224
|
+
else if (reset.mins === 1440) {
|
|
225
|
+
value = RecurrenceOption.ONCE_PER_DAY;
|
|
226
|
+
}
|
|
227
|
+
else if (reset.mins === 10080) {
|
|
228
|
+
value = RecurrenceOption.ONCE_PER_WEEK;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (readonly) {
|
|
232
|
+
recurrenceTemplate = html `
|
|
233
|
+
<div style="--or-mwc-input-color: ${buttonColor}; margin-right: 6px;">
|
|
234
|
+
<or-mwc-input .type="${InputType.BUTTON}" label="${value}"></or-mwc-input>
|
|
235
|
+
</div>
|
|
236
|
+
`;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
recurrenceTemplate = html `
|
|
240
|
+
<div style="--or-mwc-input-color: ${buttonColor}; margin-right: 6px;">
|
|
241
|
+
${getContentWithMenuTemplate(html `<or-mwc-input .type="${InputType.BUTTON}" label="${value}"></or-mwc-input>`, getRecurrenceMenu(this.config), value, (value) => this.setRecurrenceOption(value))}
|
|
242
|
+
</div>
|
|
243
|
+
`;
|
|
244
|
+
}
|
|
245
|
+
return html `
|
|
246
|
+
<div class="rule-recurrence">
|
|
247
|
+
${recurrenceTemplate}
|
|
248
|
+
</div>
|
|
249
|
+
`;
|
|
250
|
+
}
|
|
251
|
+
ruleActionTemplate(actions, action, readonly) {
|
|
252
|
+
const showTypeSelect = !this.config || !this.config.controls || this.config.controls.hideActionTypeOptions !== true;
|
|
253
|
+
const type = this.getActionType(action);
|
|
254
|
+
if (!type && !showTypeSelect) {
|
|
255
|
+
return html `<span>INVALID CONFIG - NO TYPE SPECIFIED AND TYPE SELECTOR DISABLED</span>`;
|
|
256
|
+
}
|
|
257
|
+
let typeTemplate = ``;
|
|
258
|
+
let template = ``;
|
|
259
|
+
const thenAllowRemove = !this.readonly && (this.thenAllowAdd || this.rule.then.length > 1);
|
|
260
|
+
if (showTypeSelect) {
|
|
261
|
+
let buttonIcon;
|
|
262
|
+
let buttonColor = "inherit";
|
|
263
|
+
if (action.action) {
|
|
264
|
+
switch (action.action) {
|
|
265
|
+
case "wait" /* ActionType.WAIT */:
|
|
266
|
+
buttonIcon = "timer";
|
|
267
|
+
buttonColor = WAIT_COLOR;
|
|
268
|
+
break;
|
|
269
|
+
case "webhook" /* ActionType.WEBHOOK */:
|
|
270
|
+
buttonIcon = "webhook";
|
|
271
|
+
buttonColor = NOTIFICATION_COLOR;
|
|
272
|
+
break;
|
|
273
|
+
case "notification":
|
|
274
|
+
action = action;
|
|
275
|
+
if (type === "push" /* ActionType.PUSH_NOTIFICATION */ || type === "push_localized" /* ActionType.PUSH_LOCALIZED */) {
|
|
276
|
+
buttonIcon = "cellphone-message";
|
|
277
|
+
buttonColor = NOTIFICATION_COLOR;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
buttonIcon = "email";
|
|
281
|
+
buttonColor = NOTIFICATION_COLOR;
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
case "alarm" /* ActionType.ALARM */:
|
|
285
|
+
buttonIcon = "bell-outline";
|
|
286
|
+
buttonColor = ALARM_COLOR;
|
|
287
|
+
break;
|
|
288
|
+
default:
|
|
289
|
+
const ad = AssetModelUtil.getAssetDescriptor(type);
|
|
290
|
+
buttonIcon = AssetModelUtil.getAssetDescriptorIcon(ad);
|
|
291
|
+
buttonColor = AssetModelUtil.getAssetDescriptorColour(ad) || buttonColor;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (readonly) {
|
|
296
|
+
typeTemplate = html `
|
|
297
|
+
<div id="type" style="--or-mwc-input-color: #${buttonColor}">
|
|
298
|
+
<or-mwc-input type="${InputType.BUTTON}" .icon="${buttonIcon || ""}"></or-mwc-input>
|
|
299
|
+
</div>
|
|
300
|
+
`;
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
typeTemplate = html `
|
|
304
|
+
<div id="type" style="--or-mwc-input-color: #${buttonColor}">
|
|
305
|
+
${getContentWithMenuTemplate(html `<or-mwc-input type="${InputType.BUTTON}" .icon="${buttonIcon || ""}"></or-mwc-input>`, getActionTypesMenu(this.config, this.assetInfos), action.action, (value) => this.setActionType(actions, action, value))}
|
|
306
|
+
</div>
|
|
307
|
+
`;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (type) {
|
|
311
|
+
switch (type) {
|
|
312
|
+
case "wait" /* ActionType.WAIT */:
|
|
313
|
+
template = html `<span>WAIT NOT IMPLEMENTED</span>`;
|
|
314
|
+
break;
|
|
315
|
+
case "push" /* ActionType.PUSH_NOTIFICATION */:
|
|
316
|
+
case "push_localized" /* ActionType.PUSH_LOCALIZED */:
|
|
317
|
+
case "email" /* ActionType.EMAIL */:
|
|
318
|
+
case "email_localized" /* ActionType.EMAIL_LOCALIZED */:
|
|
319
|
+
const id = type + "-notification";
|
|
320
|
+
template = html `<or-rule-action-notification id="${id}" .rule="${this.rule}" .action="${action}" .actionType="${type}" .config="${this.config}" .assetInfos="${this.assetInfos}" .readonly="${this.readonly}"></or-rule-action-notification>`;
|
|
321
|
+
break;
|
|
322
|
+
case "webhook" /* ActionType.WEBHOOK */:
|
|
323
|
+
template = html `<or-rule-action-webhook .rule="${this.rule}" .action="${action}" .actionType="${"webhook" /* ActionType.WEBHOOK */}"></or-rule-action-webhook>`;
|
|
324
|
+
break;
|
|
325
|
+
case "alarm" /* ActionType.ALARM */:
|
|
326
|
+
template = html `<or-rule-action-alarm .rule="${this.rule}" .action="${action}" .actionType="${"alarm" /* ActionType.ALARM */}"></or-rule-action-alarm>`;
|
|
327
|
+
break;
|
|
328
|
+
default:
|
|
329
|
+
template = html `<or-rule-action-attribute .action="${action}" .targetTypeMap="${this.targetTypeMap}" .config="${this.config}" .assetInfos="${this.assetInfos}" .assetProvider="${this.assetProvider}" .readonly="${this.readonly}"></or-rule-action-attribute>`;
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return html `
|
|
334
|
+
<div class="rule-action">
|
|
335
|
+
<div class="rule-action-wrapper">
|
|
336
|
+
${typeTemplate}
|
|
337
|
+
${template}
|
|
338
|
+
</div>
|
|
339
|
+
${thenAllowRemove ? html `
|
|
340
|
+
<button class="button-clear" @click="${() => this.removeAction(action)}"><or-icon icon="close-circle"></or-icon></input>
|
|
341
|
+
` : ``}
|
|
342
|
+
</div>
|
|
343
|
+
`;
|
|
344
|
+
}
|
|
345
|
+
render() {
|
|
346
|
+
const thenAllowAdd = !this.readonly && (this.thenAllowAdd || this.rule.then.length > 1);
|
|
347
|
+
return html `
|
|
348
|
+
<div>
|
|
349
|
+
<or-panel .heading="${i18next.t("then")}...">
|
|
350
|
+
${this.ruleRecurrenceTemplate(this.rule.recurrence, this.readonly)}
|
|
351
|
+
|
|
352
|
+
${!this.rule.then ? `` : this.rule.then.map((action) => this.ruleActionTemplate(this.rule.then, action, this.readonly))}
|
|
353
|
+
${thenAllowAdd ? html `
|
|
354
|
+
<span class="add-button-wrapper">
|
|
355
|
+
${getContentWithMenuTemplate(html `<or-mwc-input class="plus-button" type="${InputType.BUTTON}" icon="plus"
|
|
356
|
+
.label="${i18next.t("rulesEditorAddAction")}"></or-mwc-input>`, getActionTypesMenu(this.config, this.assetInfos), undefined, (value) => this.addAction(value))}
|
|
357
|
+
</span>
|
|
358
|
+
` : ``}
|
|
359
|
+
</or-panel>
|
|
360
|
+
</div>
|
|
361
|
+
`;
|
|
362
|
+
}
|
|
363
|
+
getActionType(action) {
|
|
364
|
+
switch (action.action) {
|
|
365
|
+
case "wait":
|
|
366
|
+
break;
|
|
367
|
+
case "webhook":
|
|
368
|
+
return action.action;
|
|
369
|
+
break;
|
|
370
|
+
case "notification":
|
|
371
|
+
const type = action.notification && action.notification.message && action.notification.message.type ? action.notification.message.type : action.action;
|
|
372
|
+
if (type === "localized") {
|
|
373
|
+
const messages = Object.values(action.notification.message.languages);
|
|
374
|
+
if (messages && messages.length > 0) {
|
|
375
|
+
return messages[0].type + "_localized";
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return type;
|
|
379
|
+
break;
|
|
380
|
+
case "alarm":
|
|
381
|
+
return action.action;
|
|
382
|
+
break;
|
|
383
|
+
case "write-attribute":
|
|
384
|
+
case "update-attribute":
|
|
385
|
+
if (!action.target) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (action.target.matchedAssets) {
|
|
389
|
+
return getAssetTypeFromQuery(action.target.matchedAssets);
|
|
390
|
+
}
|
|
391
|
+
if (action.target.assets) {
|
|
392
|
+
return getAssetTypeFromQuery(action.target.assets);
|
|
393
|
+
}
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
setRecurrenceOption(value) {
|
|
398
|
+
switch (value) {
|
|
399
|
+
case RecurrenceOption.ALWAYS:
|
|
400
|
+
this.rule.recurrence = { mins: 0 };
|
|
401
|
+
break;
|
|
402
|
+
case RecurrenceOption.ONCE_PER_HOUR:
|
|
403
|
+
this.rule.recurrence = { mins: 60 };
|
|
404
|
+
break;
|
|
405
|
+
case RecurrenceOption.ONCE_PER_DAY:
|
|
406
|
+
this.rule.recurrence = { mins: 1440 };
|
|
407
|
+
break;
|
|
408
|
+
case RecurrenceOption.ONCE_PER_WEEK:
|
|
409
|
+
this.rule.recurrence = { mins: 10080 };
|
|
410
|
+
break;
|
|
411
|
+
case RecurrenceOption.ONCE:
|
|
412
|
+
default:
|
|
413
|
+
delete this.rule.recurrence;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
417
|
+
this.requestUpdate();
|
|
418
|
+
}
|
|
419
|
+
setActionType(actions, action, value) {
|
|
420
|
+
var _a, _b, _c, _d, _e, _f;
|
|
421
|
+
action.target = undefined;
|
|
422
|
+
switch (action.action) {
|
|
423
|
+
case "wait":
|
|
424
|
+
action.millis = undefined;
|
|
425
|
+
break;
|
|
426
|
+
case "webhook":
|
|
427
|
+
break;
|
|
428
|
+
case "write-attribute":
|
|
429
|
+
action.value = undefined;
|
|
430
|
+
action.attributeName = undefined;
|
|
431
|
+
break;
|
|
432
|
+
case "notification":
|
|
433
|
+
action.notification = undefined;
|
|
434
|
+
break;
|
|
435
|
+
case "alarm":
|
|
436
|
+
action.alarm = undefined;
|
|
437
|
+
action.assigneeId = undefined;
|
|
438
|
+
break;
|
|
439
|
+
case "update-attribute":
|
|
440
|
+
action.value = undefined;
|
|
441
|
+
action.attributeName = undefined;
|
|
442
|
+
action.index = undefined;
|
|
443
|
+
action.key = undefined;
|
|
444
|
+
action.updateAction = undefined;
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
if (value === "wait" /* ActionType.WAIT */) {
|
|
448
|
+
action.action = "wait";
|
|
449
|
+
}
|
|
450
|
+
else if (value == "alarm" /* ActionType.ALARM */) {
|
|
451
|
+
action = action;
|
|
452
|
+
action.action = "alarm";
|
|
453
|
+
action.alarm = {
|
|
454
|
+
title: "%RULESET_NAME%",
|
|
455
|
+
content: "%TRIGGER_ASSETS%",
|
|
456
|
+
severity: "LOW" /* AlarmSeverity.LOW */,
|
|
457
|
+
status: "OPEN" /* AlarmStatus.OPEN */
|
|
458
|
+
};
|
|
459
|
+
action.assigneeId = undefined;
|
|
460
|
+
}
|
|
461
|
+
else if (value == "webhook" /* ActionType.WEBHOOK */) {
|
|
462
|
+
action = action;
|
|
463
|
+
action.action = "webhook";
|
|
464
|
+
action.webhook = {
|
|
465
|
+
httpMethod: "POST" /* HTTPMethod.POST */,
|
|
466
|
+
payload: JSON.stringify({
|
|
467
|
+
rule: "%RULESET_NAME%",
|
|
468
|
+
assets: "%TRIGGER_ASSETS%"
|
|
469
|
+
}, null, 4)
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
else if (value === "email" /* ActionType.EMAIL */) {
|
|
473
|
+
action = action;
|
|
474
|
+
action.action = "notification";
|
|
475
|
+
action.notification = {
|
|
476
|
+
name: this.rule.name,
|
|
477
|
+
message: {
|
|
478
|
+
type: "email",
|
|
479
|
+
subject: "%RULESET_NAME%",
|
|
480
|
+
html: "%TRIGGER_ASSETS%"
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
else if (value === "push" /* ActionType.PUSH_NOTIFICATION */) {
|
|
485
|
+
action = action;
|
|
486
|
+
action.action = "notification";
|
|
487
|
+
action.notification = {
|
|
488
|
+
name: this.rule.name,
|
|
489
|
+
message: {
|
|
490
|
+
type: "push",
|
|
491
|
+
title: "%RULESET_NAME%",
|
|
492
|
+
body: "%TRIGGER_ASSETS%",
|
|
493
|
+
action: {
|
|
494
|
+
openInBrowser: false
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
else if (value === "email_localized" /* ActionType.EMAIL_LOCALIZED */ || value === "push_localized" /* ActionType.PUSH_LOCALIZED */) {
|
|
500
|
+
action = action;
|
|
501
|
+
action.action = "notification";
|
|
502
|
+
const locale = ((_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.notifications) === null || _b === void 0 ? void 0 : _b[manager.displayRealm]) === null || _c === void 0 ? void 0 : _c.defaultLanguage) || ((_f = (_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.notifications) === null || _e === void 0 ? void 0 : _e["default"]) === null || _f === void 0 ? void 0 : _f.defaultLanguage) || manager.config.defaultLanguage || "en";
|
|
503
|
+
const languages = {};
|
|
504
|
+
if (value === "email_localized" /* ActionType.EMAIL_LOCALIZED */) {
|
|
505
|
+
languages[locale] = {
|
|
506
|
+
type: "email",
|
|
507
|
+
subject: "%RULESET_NAME%",
|
|
508
|
+
html: "%TRIGGER_ASSETS%"
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
languages[locale] = {
|
|
513
|
+
type: "push",
|
|
514
|
+
title: "%RULESET_NAME%",
|
|
515
|
+
body: "%TRIGGER_ASSETS%",
|
|
516
|
+
action: {
|
|
517
|
+
openInBrowser: false
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
action.notification = {
|
|
522
|
+
name: this.rule.name,
|
|
523
|
+
message: {
|
|
524
|
+
type: "localized",
|
|
525
|
+
defaultLanguage: locale,
|
|
526
|
+
languages: languages
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
action.action = "write-attribute";
|
|
532
|
+
action.target = {
|
|
533
|
+
matchedAssets: {
|
|
534
|
+
types: [
|
|
535
|
+
value
|
|
536
|
+
]
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
const index = actions.indexOf(action);
|
|
541
|
+
actions[index] = Object.assign({}, action);
|
|
542
|
+
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
543
|
+
this.requestUpdate();
|
|
544
|
+
}
|
|
545
|
+
removeAction(action) {
|
|
546
|
+
if (!this.rule || !this.rule.then || !action) {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
const index = this.rule.then.indexOf(action);
|
|
550
|
+
if (index >= 0) {
|
|
551
|
+
this.rule.then.splice(index, 1);
|
|
552
|
+
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
553
|
+
this.requestUpdate();
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
addAction(type, otherwise) {
|
|
557
|
+
if (!this.rule) {
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
let actionArray;
|
|
561
|
+
let newAction = {
|
|
562
|
+
action: "write-attribute"
|
|
563
|
+
};
|
|
564
|
+
let template;
|
|
565
|
+
const templateConfig = this.config && this.config.json ? this.config.json : undefined;
|
|
566
|
+
if (!otherwise) {
|
|
567
|
+
if (!this.rule.then) {
|
|
568
|
+
this.rule.then = [];
|
|
569
|
+
}
|
|
570
|
+
actionArray = this.rule.then;
|
|
571
|
+
template = templateConfig && templateConfig.then ? templateConfig.then : undefined;
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
if (!this.rule.otherwise) {
|
|
575
|
+
this.rule.otherwise = [];
|
|
576
|
+
}
|
|
577
|
+
actionArray = this.rule.otherwise;
|
|
578
|
+
template = templateConfig && templateConfig.otherwise ? templateConfig.otherwise : undefined;
|
|
579
|
+
}
|
|
580
|
+
if (template) {
|
|
581
|
+
newAction = JSON.parse(JSON.stringify(template));
|
|
582
|
+
}
|
|
583
|
+
if (type) {
|
|
584
|
+
this.setActionType(actionArray, newAction, type);
|
|
585
|
+
}
|
|
586
|
+
actionArray.push(newAction);
|
|
587
|
+
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
588
|
+
this.requestUpdate();
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
__decorate([
|
|
592
|
+
property({ type: Array, attribute: false })
|
|
593
|
+
], OrRuleThenOtherwise.prototype, "targetTypeMap", void 0);
|
|
594
|
+
__decorate([
|
|
595
|
+
property({ type: Object, attribute: false })
|
|
596
|
+
], OrRuleThenOtherwise.prototype, "rule", void 0);
|
|
597
|
+
__decorate([
|
|
598
|
+
property({ type: Boolean })
|
|
599
|
+
], OrRuleThenOtherwise.prototype, "readonly", void 0);
|
|
600
|
+
__decorate([
|
|
601
|
+
property({ type: Object, attribute: false })
|
|
602
|
+
], OrRuleThenOtherwise.prototype, "assetInfos", void 0);
|
|
603
|
+
__decorate([
|
|
604
|
+
property({ type: Object })
|
|
605
|
+
], OrRuleThenOtherwise.prototype, "assetProvider", void 0);
|
|
606
|
+
OrRuleThenOtherwise = __decorate([
|
|
607
|
+
customElement("or-rule-then-otherwise")
|
|
608
|
+
], OrRuleThenOtherwise);
|
|
609
|
+
//# sourceMappingURL=or-rule-then-otherwise.js.map
|