@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,56 +1,465 @@
|
|
|
1
|
-
var
|
|
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
|
-
|
|
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
|
+
var OrRuleActionNotification_1;
|
|
17
|
+
import { css, html, LitElement } from "lit";
|
|
18
|
+
import { customElement, property } from "lit/decorators.js";
|
|
19
|
+
import { until } from "lit/directives/until.js";
|
|
20
|
+
import { OrRulesRuleUnsupportedEvent } from "../index";
|
|
21
|
+
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
|
|
22
|
+
import { getTargetTypeMap, OrRulesJsonRuleChangedEvent } from "./or-rule-json-viewer";
|
|
23
|
+
import "./modals/or-rule-notification-modal";
|
|
24
|
+
import "./forms/or-rule-form-email-message";
|
|
25
|
+
import "./forms/or-rule-form-push-notification";
|
|
26
|
+
import "./forms/or-rule-form-localized";
|
|
27
|
+
import "./or-rule-action-attribute";
|
|
28
|
+
import { i18next } from "@openremote/or-translate";
|
|
29
|
+
import manager, { Util } from "@openremote/core";
|
|
30
|
+
// language=CSS
|
|
31
|
+
const style = css `
|
|
32
|
+
:host {
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
:host > * {
|
|
38
|
+
margin: 0 3px 6px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.min-width {
|
|
42
|
+
min-width: 200px;
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
let OrRuleActionNotification = OrRuleActionNotification_1 = class OrRuleActionNotification extends LitElement {
|
|
46
|
+
static get styles() {
|
|
47
|
+
return style;
|
|
48
|
+
}
|
|
49
|
+
connectedCallback() {
|
|
50
|
+
this.addEventListener(OrRulesJsonRuleChangedEvent.NAME, this._onJsonRuleChanged);
|
|
51
|
+
this._initialAction = structuredClone(this.action);
|
|
52
|
+
return super.connectedCallback();
|
|
53
|
+
}
|
|
54
|
+
willUpdate(changedProps) {
|
|
55
|
+
// If the rule property changes, we assume it is a "new rule".
|
|
56
|
+
// For example when the SAVE button is pressed in the JSON editor (which triggers an update of this 'rule' property),
|
|
57
|
+
// we want to reset the _initialAction cache variable.
|
|
58
|
+
if (changedProps.has("rule") && changedProps.get("rule") !== undefined) {
|
|
59
|
+
this._initialAction = structuredClone(this.action);
|
|
60
|
+
}
|
|
61
|
+
return super.willUpdate(changedProps);
|
|
62
|
+
}
|
|
63
|
+
disconnectedCallback() {
|
|
64
|
+
this.removeEventListener(OrRulesJsonRuleChangedEvent.NAME, this._onJsonRuleChanged);
|
|
65
|
+
return super.disconnectedCallback();
|
|
66
|
+
}
|
|
67
|
+
_onJsonRuleChanged() {
|
|
68
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
69
|
+
// Upon rule change, we update the name of the "Notification action" to a sensible value, for example with the subject of an email
|
|
70
|
+
// This is to prevent the NAME (for example showing up in the logs) being NULL or not identifiable.
|
|
71
|
+
if (this.action.notification) {
|
|
72
|
+
const message = this.action.notification.message;
|
|
73
|
+
if ((message === null || message === void 0 ? void 0 : message.type) === "localized") {
|
|
74
|
+
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;
|
|
75
|
+
const msg = (_g = message.languages) === null || _g === void 0 ? void 0 : _g[locale]; // if localized, we use the default language
|
|
76
|
+
if ((msg === null || msg === void 0 ? void 0 : msg.type) === "push") {
|
|
77
|
+
this.action.notification.name = msg.title;
|
|
78
|
+
}
|
|
79
|
+
else if ((msg === null || msg === void 0 ? void 0 : msg.type) === "email") {
|
|
80
|
+
this.action.notification.name = msg.subject;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if ((message === null || message === void 0 ? void 0 : message.type) === "push") {
|
|
84
|
+
this.action.notification.name = message.title;
|
|
85
|
+
}
|
|
86
|
+
else if ((message === null || message === void 0 ? void 0 : message.type) === "email") {
|
|
87
|
+
this.action.notification.name = message.subject;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
static getActionTargetTemplate(targetTypeMap, action, actionType, readonly, config, baseAssetQuery, onTargetTypeChangedCallback, onTargetChangedCallback) {
|
|
92
|
+
let allowedTargetTypes = [
|
|
93
|
+
["USER" /* NotificationTargetType.USER */, i18next.t("user_plural")],
|
|
94
|
+
["ASSET" /* NotificationTargetType.ASSET */, i18next.t("asset_plural")],
|
|
95
|
+
["REALM" /* NotificationTargetType.REALM */, i18next.t("realm_plural")],
|
|
96
|
+
["CUSTOM" /* NotificationTargetType.CUSTOM */, i18next.t("custom")]
|
|
97
|
+
];
|
|
98
|
+
if (config && config.controls && config.controls.allowedActionTargetTypes) {
|
|
99
|
+
let configTypes;
|
|
100
|
+
if (config.controls.allowedActionTargetTypes.actions) {
|
|
101
|
+
configTypes = config.controls.allowedActionTargetTypes.actions[actionType];
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
configTypes = config.controls.allowedActionTargetTypes.default;
|
|
105
|
+
}
|
|
106
|
+
if (configTypes) {
|
|
107
|
+
allowedTargetTypes = allowedTargetTypes.filter((allowedType) => configTypes === null || configTypes === void 0 ? void 0 : configTypes.includes(allowedType[0]));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (allowedTargetTypes.length === 0) {
|
|
111
|
+
console.warn("Rule action config doesn't allow any action target types for this type of action");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
let targetType = "ASSET" /* NotificationTargetType.ASSET */;
|
|
115
|
+
if (action.target) {
|
|
116
|
+
if (action.target.users && !action.target.conditionAssets && !action.target.matchedAssets && !action.target.assets) {
|
|
117
|
+
targetType = "USER" /* NotificationTargetType.USER */;
|
|
118
|
+
}
|
|
119
|
+
else if (action.target.linkedUsers) {
|
|
120
|
+
targetType = "USER" /* NotificationTargetType.USER */;
|
|
121
|
+
}
|
|
122
|
+
else if (action.target.custom !== undefined && !action.target.conditionAssets && !action.target.matchedAssets && !action.target.assets) {
|
|
123
|
+
targetType = "CUSTOM" /* NotificationTargetType.CUSTOM */;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
let targetValueTemplate;
|
|
127
|
+
if (!allowedTargetTypes.find((allowedTargetType) => allowedTargetType[0] === targetType)) {
|
|
128
|
+
targetType = undefined;
|
|
129
|
+
}
|
|
130
|
+
if (targetType === "CUSTOM" /* NotificationTargetType.CUSTOM */) {
|
|
131
|
+
const template = html `
|
|
132
|
+
<or-mwc-input class="min-width" .type="${InputType.TEXT}" @or-mwc-input-changed="${(e) => onTargetChangedCallback(targetType, e.detail.value)}" ?readonly="${readonly}" .value="${action.target.custom}" ></or-mwc-input>
|
|
133
|
+
`;
|
|
134
|
+
targetValueTemplate = Promise.resolve(template);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
let targetValuesGenerator;
|
|
138
|
+
let label;
|
|
139
|
+
let value;
|
|
140
|
+
if (targetType === "USER" /* NotificationTargetType.USER */) {
|
|
141
|
+
// Get users excluding system accounts and service users
|
|
142
|
+
const query = {
|
|
143
|
+
realmPredicate: { name: manager.displayRealm },
|
|
144
|
+
select: { basic: true },
|
|
145
|
+
serviceUsers: false,
|
|
146
|
+
attributes: [{ name: { value: "systemAccount", predicateType: "string" }, negated: true }]
|
|
147
|
+
};
|
|
148
|
+
targetValuesGenerator = manager.rest.api.UserResource.query(query).then((usersResponse) => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const linkedLabel = i18next.t("linked");
|
|
150
|
+
// Get realm roles and add as options
|
|
151
|
+
const realm = yield manager.rest.api.RealmResource.get(manager.displayRealm);
|
|
152
|
+
let realmRoleOpts = realm.data.realmRoles.map(r => ["linked-" + r.name, linkedLabel + ": " + i18next.t("realmRole." + r.name, Util.camelCaseToSentenceCase(r.name.replace("_", " ").replace("-", " ")))]);
|
|
153
|
+
let values = usersResponse.data.map((user) => [user.id, user.username]);
|
|
154
|
+
return [["linkedUsers", linkedLabel], ...realmRoleOpts, ...values.sort(Util.sortByString(user => user[1]))];
|
|
155
|
+
}));
|
|
156
|
+
label = i18next.t("user_plural");
|
|
157
|
+
const userQuery = action.target.users;
|
|
158
|
+
if (action.target.linkedUsers) {
|
|
159
|
+
if (userQuery && userQuery.realmRoles) {
|
|
160
|
+
if (userQuery.realmRoles.length > 1) {
|
|
161
|
+
console.warn("Rule action user target query is unsupported: " + JSON.stringify(userQuery, null, 2));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
value = "linked-" + userQuery.realmRoles[0].value;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
value = "linkedUsers";
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (userQuery) {
|
|
171
|
+
if ((userQuery.ids && userQuery.ids.length > 1)
|
|
172
|
+
|| userQuery.usernames
|
|
173
|
+
|| userQuery.assets
|
|
174
|
+
|| userQuery.limit
|
|
175
|
+
|| userQuery.pathPredicate
|
|
176
|
+
|| userQuery.realmPredicate) {
|
|
177
|
+
console.warn("Rule action user target query is unsupported: " + JSON.stringify(userQuery, null, 2));
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (userQuery.ids && userQuery.ids.length === 1) {
|
|
181
|
+
value = userQuery.ids[0];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
console.warn("Rule action user target query is unsupported: " + JSON.stringify(userQuery, null, 2));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const assetQuery = baseAssetQuery ? Object.assign({}, baseAssetQuery) : {};
|
|
191
|
+
assetQuery.orderBy = {
|
|
192
|
+
property: "NAME" /* AssetQueryOrderBy$Property.NAME */
|
|
193
|
+
};
|
|
194
|
+
targetValuesGenerator = manager.rest.api.AssetResource.queryAssets(assetQuery).then((response) => {
|
|
195
|
+
let values = response.data.map((asset) => [asset.id, asset.name + " (" + asset.id + ")"]);
|
|
196
|
+
// Add additional options for assets
|
|
197
|
+
const additionalValues = [["allMatched", i18next.t("matched")]];
|
|
198
|
+
if (targetTypeMap && targetTypeMap.length > 1) {
|
|
199
|
+
targetTypeMap.forEach((typeAndTag) => {
|
|
200
|
+
if (!additionalValues.find((av) => av[0] === typeAndTag[0])) {
|
|
201
|
+
additionalValues.push([typeAndTag[0], i18next.t("matchedOfType", { type: Util.getAssetTypeLabel(typeAndTag[0]) })]);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return [...additionalValues, ...values];
|
|
206
|
+
});
|
|
207
|
+
label = i18next.t("asset_plural");
|
|
208
|
+
if (!action.target) {
|
|
209
|
+
value = "allMatched";
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
if (action.target.conditionAssets) {
|
|
213
|
+
console.warn("Rule action asset target, conditionAssets is unsupported: " + JSON.stringify(action.target, null, 2));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (action.target.matchedAssets) {
|
|
217
|
+
if (action.target.matchedAssets.types && action.target.matchedAssets.types.length > 1) {
|
|
218
|
+
console.warn("Rule action asset target, matchedAssets query unsupported: " + JSON.stringify(action.target, null, 2));
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (action.target.matchedAssets.types && action.target.matchedAssets.types.length === 1) {
|
|
222
|
+
value = action.target.matchedAssets.types[0];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else if (action.target.assets) {
|
|
226
|
+
if (action.target.assets.ids && action.target.assets.ids.length > 1) {
|
|
227
|
+
console.warn("Rule action asset target, assets query unsupported: " + JSON.stringify(action.target, null, 2));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (action.target.assets.ids && action.target.assets.ids.length === 1) {
|
|
231
|
+
value = action.target.assets.ids[0];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
targetValueTemplate = targetValuesGenerator.then((values) => {
|
|
237
|
+
return html `
|
|
238
|
+
<or-mwc-input type="${InputType.SELECT}"
|
|
239
|
+
class="min-width"
|
|
240
|
+
.options="${values}"
|
|
241
|
+
.label="${label}"
|
|
242
|
+
.value="${value}"
|
|
243
|
+
@or-mwc-input-changed="${(e) => onTargetChangedCallback(targetType, e.detail.value)}"
|
|
244
|
+
?readonly="${readonly}"></or-mwc-input>
|
|
245
|
+
`;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
targetValueTemplate = targetValueTemplate.then((valueTemplate) => {
|
|
249
|
+
return html `
|
|
250
|
+
<or-mwc-input type="${InputType.SELECT}"
|
|
251
|
+
class="min-width"
|
|
252
|
+
.options="${allowedTargetTypes}"
|
|
253
|
+
.value="${targetType}"
|
|
254
|
+
.label="${i18next.t("recipients")}"
|
|
255
|
+
@or-mwc-input-changed="${(e) => onTargetTypeChangedCallback(e.detail.value)}"
|
|
256
|
+
?readonly="${readonly}"></or-mwc-input>
|
|
257
|
+
${valueTemplate}
|
|
258
|
+
`;
|
|
259
|
+
});
|
|
260
|
+
return targetValueTemplate;
|
|
261
|
+
}
|
|
262
|
+
render() {
|
|
263
|
+
var _a, _b, _c, _d;
|
|
264
|
+
if (!this.action.notification || !this.action.notification.message) {
|
|
265
|
+
return html ``;
|
|
266
|
+
}
|
|
267
|
+
const message = this.action.notification.message;
|
|
268
|
+
const messageType = message.type;
|
|
269
|
+
let baseAssetQuery;
|
|
270
|
+
if (messageType === "push") {
|
|
271
|
+
baseAssetQuery = {
|
|
272
|
+
types: [
|
|
273
|
+
"ConsoleAsset" /* WellknownAssets.CONSOLEASSET */
|
|
274
|
+
]
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
baseAssetQuery = {
|
|
279
|
+
attributes: {
|
|
280
|
+
items: [
|
|
281
|
+
{
|
|
282
|
+
name: { "predicateType": "string", "value": "email" },
|
|
283
|
+
value: { "predicateType": "value-empty", negate: true }
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
let targetTemplate = OrRuleActionNotification_1.getActionTargetTemplate(getTargetTypeMap(this.rule), this.action, this.actionType, !!this.readonly, this.config, baseAssetQuery, (type) => this._onTargetTypeChanged(type), (type, value) => this._onTargetChanged(type, value));
|
|
290
|
+
let modalTemplate = ``;
|
|
291
|
+
if (!targetTemplate) {
|
|
292
|
+
this.dispatchEvent(new OrRulesRuleUnsupportedEvent());
|
|
293
|
+
return ``;
|
|
294
|
+
}
|
|
295
|
+
// When 'cancel' is pressed, reset ACTION to the initial state (all changes get removed)
|
|
296
|
+
const onModalCancel = (ev) => {
|
|
297
|
+
var _a, _b;
|
|
298
|
+
if (this._initialAction && this.action.notification) {
|
|
299
|
+
const newAction = structuredClone(this._initialAction);
|
|
300
|
+
// Check if anything in the message has changed
|
|
301
|
+
if (JSON.stringify(this.action.notification.message) !== JSON.stringify((_a = newAction.notification) === null || _a === void 0 ? void 0 : _a.message)) {
|
|
302
|
+
console.debug("Rolling back the notification to former state...");
|
|
303
|
+
this.action.notification.message = (_b = newAction.notification) === null || _b === void 0 ? void 0 : _b.message;
|
|
304
|
+
this.requestUpdate('action');
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
console.debug("Rolling back was not necessary, as no changes have been done.");
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
console.warn("Could not rollback notification form.");
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
const onModalOk = (ev) => {
|
|
315
|
+
this._initialAction = structuredClone(this.action); // update initial action for opening the modal in the future
|
|
316
|
+
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
317
|
+
};
|
|
318
|
+
if (message) {
|
|
319
|
+
if (messageType === "push") {
|
|
320
|
+
modalTemplate = html `
|
|
321
|
+
<or-rule-notification-modal title="push-notification" .action="${this.action}"
|
|
322
|
+
@or-rules-notification-modal-cancel="${onModalCancel}"
|
|
323
|
+
@or-rules-notification-modal-ok="${onModalOk}">
|
|
324
|
+
<or-rule-form-push-notification .message="${message}"></or-rule-form-push-notification>
|
|
325
|
+
</or-rule-notification-modal>
|
|
326
|
+
`;
|
|
327
|
+
}
|
|
328
|
+
else if (messageType === "email") {
|
|
329
|
+
modalTemplate = html `
|
|
330
|
+
<or-rule-notification-modal title="email" .action="${this.action}"
|
|
331
|
+
@or-rules-notification-modal-cancel="${onModalCancel}"
|
|
332
|
+
@or-rules-notification-modal-ok="${onModalOk}">
|
|
333
|
+
<or-rule-form-email-message .message="${message}"></or-rule-form-email-message>
|
|
334
|
+
</or-rule-notification-modal>
|
|
335
|
+
`;
|
|
336
|
+
}
|
|
337
|
+
else if (messageType === "localized") {
|
|
338
|
+
const notificationConfig = ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.notifications) === null || _b === void 0 ? void 0 : _b[manager.displayRealm]) || ((_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.notifications) === null || _d === void 0 ? void 0 : _d["default"]);
|
|
339
|
+
const languages = [...new Set([
|
|
340
|
+
...((notificationConfig === null || notificationConfig === void 0 ? void 0 : notificationConfig.languages) || []),
|
|
341
|
+
...(Object.keys(message.languages || {}) || [])
|
|
342
|
+
])];
|
|
343
|
+
const defaultLang = (notificationConfig === null || notificationConfig === void 0 ? void 0 : notificationConfig.defaultLanguage) || manager.config.defaultLanguage;
|
|
344
|
+
if (languages.length === 0 && defaultLang) {
|
|
345
|
+
languages.push(defaultLang);
|
|
346
|
+
}
|
|
347
|
+
const defaultLangHasChanged = defaultLang !== message.defaultLanguage;
|
|
348
|
+
const type = this.actionType === "email_localized" /* ActionType.EMAIL_LOCALIZED */ ? "email" : "push";
|
|
349
|
+
const title = this.actionType === "email_localized" /* ActionType.EMAIL_LOCALIZED */ ? "email" : "push-notification";
|
|
350
|
+
modalTemplate = html `
|
|
351
|
+
<or-rule-notification-modal title="${title}" .action="${this.action}"
|
|
352
|
+
@or-rules-notification-modal-cancel="${onModalCancel}"
|
|
353
|
+
@or-rules-notification-modal-ok="${onModalOk}">
|
|
354
|
+
<or-rule-form-localized .message="${message}" .type="${type}" .languages="${languages}" .defaultLang="${defaultLang}"
|
|
355
|
+
.wrongLanguage="${defaultLangHasChanged}"
|
|
356
|
+
></or-rule-form-localized>
|
|
357
|
+
</or-rule-notification-modal>
|
|
358
|
+
`;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
targetTemplate = targetTemplate.then((targetTemplate) => html `
|
|
362
|
+
${targetTemplate}
|
|
363
|
+
${modalTemplate}
|
|
364
|
+
`);
|
|
365
|
+
return html `${until(targetTemplate, html ``)}`;
|
|
366
|
+
}
|
|
367
|
+
_onTargetTypeChanged(targetType) {
|
|
368
|
+
if (targetType === "ASSET" /* NotificationTargetType.ASSET */) {
|
|
369
|
+
delete this.action.target;
|
|
370
|
+
}
|
|
371
|
+
else if (targetType === "USER" /* NotificationTargetType.USER */) {
|
|
372
|
+
this.action.target = {
|
|
373
|
+
users: {
|
|
374
|
+
ids: []
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
else if (targetType === "CUSTOM" /* NotificationTargetType.CUSTOM */) {
|
|
379
|
+
this.action.target = {
|
|
380
|
+
custom: ""
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
384
|
+
this.requestUpdate();
|
|
385
|
+
}
|
|
386
|
+
_onTargetChanged(targetType, value) {
|
|
387
|
+
switch (targetType) {
|
|
388
|
+
case "USER" /* NotificationTargetType.USER */:
|
|
389
|
+
if (value === "linkedUsers") {
|
|
390
|
+
this.action.target = {
|
|
391
|
+
linkedUsers: true
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
else if (value === null || value === void 0 ? void 0 : value.startsWith("linked-")) {
|
|
395
|
+
this.action.target = {
|
|
396
|
+
users: {
|
|
397
|
+
realmRoles: [
|
|
398
|
+
{
|
|
399
|
+
predicateType: "string",
|
|
400
|
+
value: value === null || value === void 0 ? void 0 : value.substring(7)
|
|
401
|
+
}
|
|
402
|
+
]
|
|
403
|
+
},
|
|
404
|
+
linkedUsers: true
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
else if (value) {
|
|
408
|
+
this.action.target = {
|
|
409
|
+
users: { ids: [value] }
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
break;
|
|
413
|
+
case "CUSTOM" /* NotificationTargetType.CUSTOM */:
|
|
414
|
+
this.action.target = {
|
|
415
|
+
custom: value
|
|
416
|
+
};
|
|
417
|
+
break;
|
|
418
|
+
case "ASSET" /* NotificationTargetType.ASSET */:
|
|
419
|
+
if (!value || value === "allMatched") {
|
|
420
|
+
delete this.action.target;
|
|
421
|
+
}
|
|
422
|
+
else if (value.endsWith("Asset")) {
|
|
423
|
+
// This is an asset type
|
|
424
|
+
this.action.target = {
|
|
425
|
+
matchedAssets: {
|
|
426
|
+
types: [
|
|
427
|
+
value
|
|
428
|
+
]
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
this.action.target = {
|
|
434
|
+
assets: {
|
|
435
|
+
ids: [
|
|
436
|
+
value
|
|
437
|
+
]
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
__decorate([
|
|
447
|
+
property({ type: Object, attribute: false })
|
|
448
|
+
], OrRuleActionNotification.prototype, "rule", void 0);
|
|
449
|
+
__decorate([
|
|
450
|
+
property({ type: Object, attribute: false })
|
|
451
|
+
], OrRuleActionNotification.prototype, "action", void 0);
|
|
452
|
+
__decorate([
|
|
453
|
+
property({ type: String, attribute: false })
|
|
454
|
+
], OrRuleActionNotification.prototype, "actionType", void 0);
|
|
455
|
+
__decorate([
|
|
456
|
+
property({ type: Object })
|
|
457
|
+
], OrRuleActionNotification.prototype, "assetInfos", void 0);
|
|
458
|
+
__decorate([
|
|
459
|
+
property({ type: Object })
|
|
460
|
+
], OrRuleActionNotification.prototype, "config", void 0);
|
|
461
|
+
OrRuleActionNotification = OrRuleActionNotification_1 = __decorate([
|
|
462
|
+
customElement("or-rule-action-notification")
|
|
463
|
+
], OrRuleActionNotification);
|
|
464
|
+
export { OrRuleActionNotification };
|
|
465
|
+
//# sourceMappingURL=or-rule-action-notification.js.map
|
|
@@ -1,20 +1,51 @@
|
|
|
1
|
-
var __decorate=this&&this.__decorate
|
|
2
|
-
:
|
|
3
|
-
|
|
4
|
-
|
|
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 "./modals/or-rule-webhook-modal";
|
|
10
|
+
import "./forms/or-rule-form-webhook";
|
|
11
|
+
// language=CSS
|
|
12
|
+
const style = css `
|
|
13
|
+
:host {
|
|
14
|
+
height: 100%;
|
|
15
|
+
margin: 2px 3px auto 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
:host > * {
|
|
19
|
+
margin: 0 3px 6px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.min-width {
|
|
23
|
+
min-width: 200px;
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
let OrRuleActionWebhook = class OrRuleActionWebhook extends LitElement {
|
|
27
|
+
static get styles() {
|
|
28
|
+
return style;
|
|
5
29
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
30
|
+
/* ---------------------- */
|
|
31
|
+
render() {
|
|
32
|
+
return html `
|
|
33
|
+
<div style="display: flex; align-items: center; height: 100%;">
|
|
34
|
+
<or-rule-webhook-modal .action="${this.action}">
|
|
35
|
+
<or-rule-form-webhook .webhook="${this.action.webhook}"></or-rule-form-webhook>
|
|
36
|
+
</or-rule-webhook-modal>
|
|
37
|
+
</div>
|
|
38
|
+
`;
|
|
9
39
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
40
|
+
};
|
|
41
|
+
__decorate([
|
|
42
|
+
property({ type: Object, attribute: false })
|
|
43
|
+
], OrRuleActionWebhook.prototype, "rule", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
property({ type: Object, attribute: false })
|
|
46
|
+
], OrRuleActionWebhook.prototype, "action", void 0);
|
|
47
|
+
OrRuleActionWebhook = __decorate([
|
|
48
|
+
customElement("or-rule-action-webhook")
|
|
49
|
+
], OrRuleActionWebhook);
|
|
50
|
+
export { OrRuleActionWebhook };
|
|
51
|
+
//# sourceMappingURL=or-rule-action-webhook.js.map
|