@openremote/or-rules 1.8.0-snapshot.20250725120001 → 1.8.0-snapshot.20250725123024
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 +24 -61
- package/lib/flow-viewer/components/connection-container.js +1 -35
- package/lib/flow-viewer/components/connection-line.js +28 -117
- package/lib/flow-viewer/components/context-menu.js +45 -140
- package/lib/flow-viewer/components/editor-workspace.js +20 -282
- package/lib/flow-viewer/components/flow-editor.js +47 -160
- package/lib/flow-viewer/components/flow-node-socket.js +31 -146
- package/lib/flow-viewer/components/flow-node.js +29 -192
- package/lib/flow-viewer/components/internal-picker.js +54 -271
- package/lib/flow-viewer/components/node-menu-item.js +32 -132
- package/lib/flow-viewer/components/node-panel.js +60 -104
- package/lib/flow-viewer/components/notification-dialog.js +23 -55
- package/lib/flow-viewer/components/popup-modal.js +54 -113
- package/lib/flow-viewer/components/rule-browser.js +30 -119
- package/lib/flow-viewer/components/selectable-element.js +1 -71
- package/lib/flow-viewer/components/selection-box.js +15 -119
- package/lib/flow-viewer/components/top-bar.js +49 -116
- package/lib/flow-viewer/components/workspace-contextmenu-options.js +5 -128
- package/lib/flow-viewer/components/writable-dropdown.js +5 -51
- package/lib/flow-viewer/converters/node-converter.js +1 -10
- package/lib/flow-viewer/flow-viewer.js +1 -19
- package/lib/flow-viewer/models/camera.js +1 -2
- package/lib/flow-viewer/models/context-menu-button.js +1 -2
- package/lib/flow-viewer/models/light-node-collection.js +1 -2
- package/lib/flow-viewer/models/status.js +1 -8
- package/lib/flow-viewer/node-structure/copy.machine.js +1 -34
- package/lib/flow-viewer/node-structure/identity.assigner.js +1 -10
- package/lib/flow-viewer/node-structure/identity.dom.link.js +1 -4
- package/lib/flow-viewer/node-structure/index.js +1 -5
- package/lib/flow-viewer/node-structure/socket.type.matcher.js +1 -50
- package/lib/flow-viewer/node-structure/utils.js +1 -109
- package/lib/flow-viewer/services/copy-paste-manager.js +1 -59
- package/lib/flow-viewer/services/exporter.js +1 -67
- package/lib/flow-viewer/services/input.js +1 -80
- package/lib/flow-viewer/services/integration.js +1 -27
- package/lib/flow-viewer/services/modal.js +8 -29
- package/lib/flow-viewer/services/project.js +1 -222
- package/lib/flow-viewer/services/shortcuts.js +1 -63
- package/lib/flow-viewer/styles/editor-workspace-style.js +53 -55
- package/lib/flow-viewer/styles/flow-node-style.js +93 -95
- package/lib/flow-viewer/styles/picker-styles.js +29 -31
- package/lib/flow-viewer/utils.js +1 -49
- package/lib/index.js +56 -953
- package/lib/json-viewer/forms/or-rule-form-alarm.js +18 -91
- package/lib/json-viewer/forms/or-rule-form-email-message.js +12 -51
- package/lib/json-viewer/forms/or-rule-form-localized.js +43 -269
- package/lib/json-viewer/forms/or-rule-form-push-notification.js +63 -152
- package/lib/json-viewer/forms/or-rule-form-webhook.js +101 -296
- package/lib/json-viewer/modals/or-rule-alarm-modal.js +17 -173
- package/lib/json-viewer/modals/or-rule-notification-modal.js +11 -196
- package/lib/json-viewer/modals/or-rule-radial-modal.js +17 -142
- package/lib/json-viewer/modals/or-rule-webhook-modal.js +8 -78
- package/lib/json-viewer/or-rule-action-alarm.js +5 -97
- package/lib/json-viewer/or-rule-action-attribute.js +33 -235
- package/lib/json-viewer/or-rule-action-notification.js +56 -465
- package/lib/json-viewer/or-rule-action-webhook.js +18 -49
- package/lib/json-viewer/or-rule-asset-query.js +126 -849
- package/lib/json-viewer/or-rule-condition.js +29 -216
- package/lib/json-viewer/or-rule-json-viewer.js +34 -393
- package/lib/json-viewer/or-rule-then-otherwise.js +113 -609
- package/lib/json-viewer/or-rule-trigger-query.js +57 -227
- package/lib/json-viewer/or-rule-when.js +126 -343
- package/lib/or-rule-group-viewer.js +12 -106
- package/lib/or-rule-text-viewer.js +22 -133
- package/lib/or-rule-tree.js +57 -601
- package/lib/or-rule-validity.js +62 -373
- package/lib/or-rule-viewer.js +81 -361
- package/lib/style.js +64 -89
- package/package.json +11 -11
|
@@ -1,849 +1,126 @@
|
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
AssetQueryOperator.STARTS_WITH,
|
|
128
|
-
AssetQueryOperator.NOT_STARTS_WITH,
|
|
129
|
-
AssetQueryOperator.ENDS_WITH,
|
|
130
|
-
AssetQueryOperator.NOT_ENDS_WITH,
|
|
131
|
-
AssetQueryOperator.VALUE_EMPTY,
|
|
132
|
-
AssetQueryOperator.VALUE_NOT_EMPTY,
|
|
133
|
-
AssetQueryOperator.NOT_UPDATED_FOR
|
|
134
|
-
];
|
|
135
|
-
this._queryOperatorsMap["number"] = [
|
|
136
|
-
AssetQueryOperator.EQUALS,
|
|
137
|
-
AssetQueryOperator.NOT_EQUALS,
|
|
138
|
-
AssetQueryOperator.GREATER_THAN,
|
|
139
|
-
AssetQueryOperator.GREATER_EQUALS,
|
|
140
|
-
AssetQueryOperator.LESS_THAN,
|
|
141
|
-
AssetQueryOperator.LESS_EQUALS,
|
|
142
|
-
AssetQueryOperator.BETWEEN,
|
|
143
|
-
AssetQueryOperator.NOT_BETWEEN,
|
|
144
|
-
AssetQueryOperator.VALUE_EMPTY,
|
|
145
|
-
AssetQueryOperator.VALUE_NOT_EMPTY,
|
|
146
|
-
AssetQueryOperator.NOT_UPDATED_FOR
|
|
147
|
-
];
|
|
148
|
-
this._queryOperatorsMap["boolean"] = [
|
|
149
|
-
AssetQueryOperator.IS_TRUE,
|
|
150
|
-
AssetQueryOperator.IS_FALSE,
|
|
151
|
-
AssetQueryOperator.VALUE_EMPTY,
|
|
152
|
-
AssetQueryOperator.VALUE_NOT_EMPTY,
|
|
153
|
-
AssetQueryOperator.NOT_UPDATED_FOR
|
|
154
|
-
];
|
|
155
|
-
this._queryOperatorsMap["array"] = [
|
|
156
|
-
AssetQueryOperator.CONTAINS,
|
|
157
|
-
AssetQueryOperator.NOT_CONTAINS,
|
|
158
|
-
AssetQueryOperator.INDEX_CONTAINS,
|
|
159
|
-
AssetQueryOperator.NOT_INDEX_CONTAINS,
|
|
160
|
-
AssetQueryOperator.LENGTH_EQUALS,
|
|
161
|
-
AssetQueryOperator.NOT_LENGTH_EQUALS,
|
|
162
|
-
AssetQueryOperator.LENGTH_LESS_THAN,
|
|
163
|
-
AssetQueryOperator.LENGTH_GREATER_THAN,
|
|
164
|
-
AssetQueryOperator.VALUE_EMPTY,
|
|
165
|
-
AssetQueryOperator.VALUE_NOT_EMPTY,
|
|
166
|
-
AssetQueryOperator.NOT_UPDATED_FOR
|
|
167
|
-
];
|
|
168
|
-
this._queryOperatorsMap["object"] = [
|
|
169
|
-
AssetQueryOperator.CONTAINS_KEY,
|
|
170
|
-
AssetQueryOperator.NOT_CONTAINS_KEY,
|
|
171
|
-
AssetQueryOperator.VALUE_EMPTY,
|
|
172
|
-
AssetQueryOperator.VALUE_NOT_EMPTY,
|
|
173
|
-
AssetQueryOperator.NOT_UPDATED_FOR
|
|
174
|
-
];
|
|
175
|
-
}
|
|
176
|
-
refresh() {
|
|
177
|
-
// Clear assets
|
|
178
|
-
this._assets = undefined;
|
|
179
|
-
}
|
|
180
|
-
attributePredicateEditorTemplate(assetTypeInfo, asset, attributePredicate) {
|
|
181
|
-
const assetDescriptor = assetTypeInfo.assetDescriptor;
|
|
182
|
-
const operator = this.getOperator(attributePredicate);
|
|
183
|
-
const attributeName = this.getAttributeName(attributePredicate);
|
|
184
|
-
let attribute = asset && asset.attributes && attributeName ? asset.attributes[attributeName] : undefined;
|
|
185
|
-
let attributes = [];
|
|
186
|
-
const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(asset ? asset.type : assetDescriptor.name, attribute || attributeName, attribute);
|
|
187
|
-
if (asset && asset.attributes) {
|
|
188
|
-
attributes = Object.values(asset.attributes)
|
|
189
|
-
.filter((attribute) => attribute.meta && (attribute.meta.hasOwnProperty("ruleState" /* WellknownMetaItems.RULESTATE */) ? attribute.meta["ruleState" /* WellknownMetaItems.RULESTATE */] : attribute.meta.hasOwnProperty("agentLink" /* WellknownMetaItems.AGENTLINK */)))
|
|
190
|
-
.map((attr) => {
|
|
191
|
-
const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(asset.type, attr.name, attr);
|
|
192
|
-
const label = Util.getAttributeLabel(attr, descriptors[0], asset.type, false);
|
|
193
|
-
return [attr.name, label];
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
attributes = !assetTypeInfo || !assetTypeInfo.attributeDescriptors ? [] :
|
|
198
|
-
assetTypeInfo.attributeDescriptors
|
|
199
|
-
.map((ad) => {
|
|
200
|
-
const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(assetDescriptor.name, ad);
|
|
201
|
-
const label = Util.getAttributeLabel(undefined, descriptors ? descriptors[0] : undefined, assetDescriptor.name, false);
|
|
202
|
-
return [ad.name, label];
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
attributes.sort(Util.sortByString((attr) => attr[1]));
|
|
206
|
-
const operators = attributeName ? this.getOperators(assetDescriptor, descriptors ? descriptors[0] : undefined, descriptors ? descriptors[1] : undefined, attribute, attributeName) : [];
|
|
207
|
-
return html `
|
|
208
|
-
<or-mwc-input type="${InputType.SELECT}" @or-mwc-input-changed="${(e) => this.setAttributeName(attributePredicate, e.detail.value)}" .readonly="${this.readonly || false}" .options="${attributes}" .value="${attributeName}" .label="${i18next.t("attribute")}"></or-mwc-input>
|
|
209
|
-
${attributeName ? html `<or-mwc-input type="${InputType.SELECT}" @or-mwc-input-changed="${(e) => this.setOperator(assetDescriptor, attribute, attributeName, attributePredicate, e.detail.value)}" .readonly="${this.readonly || false}" .options="${operators}" .value="${operator}" .label="${i18next.t("operator")}"></or-mwc-input>` : ``}
|
|
210
|
-
${attributePredicate ? this.attributePredicateValueEditorTemplate(assetDescriptor, asset, attributePredicate) : ``}
|
|
211
|
-
`;
|
|
212
|
-
}
|
|
213
|
-
attributePredicateValueEditorTemplate(assetDescriptor, asset, attributePredicate) {
|
|
214
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
215
|
-
const operator = this.getOperator(attributePredicate);
|
|
216
|
-
if (operator === AssetQueryOperator.NOT_UPDATED_FOR) {
|
|
217
|
-
const duration = attributePredicate.timestampOlderThan ?
|
|
218
|
-
moment.duration(attributePredicate.timestampOlderThan) : undefined;
|
|
219
|
-
return html `
|
|
220
|
-
<or-mwc-input type="${InputType.NUMBER}"
|
|
221
|
-
min="0"
|
|
222
|
-
.value="${duration === null || duration === void 0 ? void 0 : duration.asMinutes()}"
|
|
223
|
-
label="${i18next.t("rulesEditorDuration")}"
|
|
224
|
-
@or-mwc-input-changed="${(ev) => {
|
|
225
|
-
const minutes = ev.detail.value;
|
|
226
|
-
const newDuration = moment.duration(minutes, "minutes");
|
|
227
|
-
attributePredicate.timestampOlderThan = minutes > 0 ?
|
|
228
|
-
newDuration.toISOString() : undefined;
|
|
229
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
230
|
-
}}">
|
|
231
|
-
</or-mwc-input>`;
|
|
232
|
-
}
|
|
233
|
-
const valuePredicate = attributePredicate.value;
|
|
234
|
-
if (!assetDescriptor || !valuePredicate) {
|
|
235
|
-
return ``;
|
|
236
|
-
}
|
|
237
|
-
const attributeName = this.getAttributeName(attributePredicate);
|
|
238
|
-
const assetType = getAssetTypeFromQuery(this.query);
|
|
239
|
-
const attribute = asset && asset.attributes && attributeName ? asset.attributes[attributeName] : undefined;
|
|
240
|
-
const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(assetType, attributeName, attribute);
|
|
241
|
-
// @ts-ignore
|
|
242
|
-
const value = valuePredicate ? valuePredicate.value : undefined;
|
|
243
|
-
switch (valuePredicate.predicateType) {
|
|
244
|
-
case "string":
|
|
245
|
-
return html `<or-attribute-input @or-attribute-input-changed="${(ev) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${(_a = this.config) === null || _a === void 0 ? void 0 : _a.inputProvider}" .label="${i18next.t("value")}" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${value}" .readonly="${this.readonly || false}" .fullWidth="${true}"></or-attribute-input>`;
|
|
246
|
-
case "boolean":
|
|
247
|
-
return html ``; // Handled by the operator IS_TRUE or IS_FALSE
|
|
248
|
-
case "datetime":
|
|
249
|
-
return html `<span>NOT IMPLEMENTED</span>`;
|
|
250
|
-
case "number":
|
|
251
|
-
if (valuePredicate.operator === "BETWEEN" /* AQO.BETWEEN */) {
|
|
252
|
-
return html `
|
|
253
|
-
<or-attribute-input .inputType="${InputType.NUMBER}" @or-attribute-input-changed="${(ev) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${(_b = this.config) === null || _b === void 0 ? void 0 : _b.inputProvider}" .label="${i18next.t("between")}" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${value}" .readonly="${this.readonly || false}" .fullWidth="${true}"></or-attribute-input>
|
|
254
|
-
<span style="display: inline-flex; align-items: center;">&</span>
|
|
255
|
-
<or-attribute-input .inputType="${InputType.NUMBER}" @or-attribute-input-changed="${(ev) => this.setValuePredicateProperty(valuePredicate, "rangeValue", ev.detail.value)}" .customProvider="${(_c = this.config) === null || _c === void 0 ? void 0 : _c.inputProvider}" .label="${i18next.t("and")}" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${valuePredicate.rangeValue}" .readonly="${this.readonly || false}" .fullWidth="${true}"></or-attribute-input>
|
|
256
|
-
`;
|
|
257
|
-
}
|
|
258
|
-
let inputType;
|
|
259
|
-
if ((_e = (_d = descriptors[0]) === null || _d === void 0 ? void 0 : _d.format) === null || _e === void 0 ? void 0 : _e.asSlider)
|
|
260
|
-
inputType = InputType.NUMBER;
|
|
261
|
-
return html `<or-attribute-input .inputType="${ifDefined(inputType)}" @or-attribute-input-changed="${(ev) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${(_f = this.config) === null || _f === void 0 ? void 0 : _f.inputProvider}" .label="" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${value}" .readonly="${this.readonly || false}" .fullWidth="${true}"></or-attribute-input>`;
|
|
262
|
-
case "radial":
|
|
263
|
-
return html `<or-rule-radial-modal .query="${this.query}" .assetDescriptor="${assetDescriptor}" .attributePredicate="${attributePredicate}"></or-rule-radial-modal>`;
|
|
264
|
-
case "rect":
|
|
265
|
-
return html `<span>NOT IMPLEMENTED</span>`;
|
|
266
|
-
case "value-empty":
|
|
267
|
-
return ``;
|
|
268
|
-
case "array":
|
|
269
|
-
// TODO: Update once we can determine inner type of array
|
|
270
|
-
// Assume string array
|
|
271
|
-
return html `<or-attribute-input @or-attribute-input-changed="${(ev) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${(_g = this.config) === null || _g === void 0 ? void 0 : _g.inputProvider}" .label="" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${value}" .readonly="${this.readonly || false}" .fullWidth="${true}></or-attribute-input>`;
|
|
272
|
-
default:
|
|
273
|
-
return html `<span>NOT IMPLEMENTED</span>`;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
attributeDurationTemplate(durationMap, index, onAdd, onChange) {
|
|
277
|
-
var _a, _b;
|
|
278
|
-
const attributePredicate = (_b = (_a = this.query.attributes) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b[index];
|
|
279
|
-
const operator = attributePredicate ? this.getOperator(attributePredicate) : undefined;
|
|
280
|
-
// Don't show duration button if NOT_UPDATED_FOR is selected
|
|
281
|
-
if (operator === AssetQueryOperator.NOT_UPDATED_FOR) {
|
|
282
|
-
return html ``;
|
|
283
|
-
}
|
|
284
|
-
if (durationMap.has(index)) {
|
|
285
|
-
const isoDuration = durationMap.get(index);
|
|
286
|
-
const duration = isoDuration ? moment.duration(isoDuration) : undefined;
|
|
287
|
-
return html `
|
|
288
|
-
<or-mwc-input type="${InputType.NUMBER}" min="0" .readonly="${this.readonly || false}"
|
|
289
|
-
.value="${duration === null || duration === void 0 ? void 0 : duration.asMinutes()}" label="${i18next.t("rulesEditorDuration")}"
|
|
290
|
-
@or-mwc-input-changed="${(ev) => {
|
|
291
|
-
const newDuration = moment.duration(ev.detail.value, "minutes");
|
|
292
|
-
if (newDuration.asMinutes() > 0) {
|
|
293
|
-
onChange(index, newDuration.toISOString());
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
onChange(index, undefined);
|
|
297
|
-
}
|
|
298
|
-
}}"
|
|
299
|
-
></or-mwc-input>
|
|
300
|
-
`;
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
return html `
|
|
304
|
-
<or-mwc-input type="${InputType.BUTTON}" .readonly="${this.readonly || false}" icon="clock-plus-outline"
|
|
305
|
-
title="${i18next.t("rulesEditorAddDuration")}" @or-mwc-input-changed="${() => onAdd(index)}"
|
|
306
|
-
></or-mwc-input>
|
|
307
|
-
`;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
static get styles() {
|
|
311
|
-
return style;
|
|
312
|
-
}
|
|
313
|
-
shouldUpdate(_changedProperties) {
|
|
314
|
-
if (_changedProperties.has("condition")) {
|
|
315
|
-
this._assets = undefined;
|
|
316
|
-
}
|
|
317
|
-
return super.shouldUpdate(_changedProperties);
|
|
318
|
-
}
|
|
319
|
-
get query() {
|
|
320
|
-
return this.condition.assets;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Returns a Map<number, string> with all configured durations of a {@link RuleCondition}.
|
|
324
|
-
* The number represents an index of the attribute array, and the string an ISO8601 duration expression.
|
|
325
|
-
*/
|
|
326
|
-
get duration() {
|
|
327
|
-
var _a;
|
|
328
|
-
if ((_a = this.condition) === null || _a === void 0 ? void 0 : _a.duration) {
|
|
329
|
-
return new Map(Object.entries(this.condition.duration).map(([key, value]) => [Number(key), value]));
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
return new Map();
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Updates the duration property in {@link condition}, based on the {@link durationMap} parameter.
|
|
337
|
-
* The number represents an index of the attribute array, and the string an ISO8601 duration expression.
|
|
338
|
-
*/
|
|
339
|
-
set duration(durationMap) {
|
|
340
|
-
if (durationMap.size > 0) {
|
|
341
|
-
this.condition.duration = Object.fromEntries(durationMap);
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
this.condition.duration = undefined;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
render() {
|
|
348
|
-
const assetType = getAssetTypeFromQuery(this.query);
|
|
349
|
-
if (!assetType) {
|
|
350
|
-
return html `<span class="invalidLabel">${i18next.t('errorOccurred')}</span>`;
|
|
351
|
-
}
|
|
352
|
-
const assetTypeInfo = this.assetInfos ? this.assetInfos.find((assetTypeInfo) => assetTypeInfo.assetDescriptor.name === assetType) : undefined;
|
|
353
|
-
if (!assetTypeInfo) {
|
|
354
|
-
return html `<span class="invalidLabel">${i18next.t('errorOccurred')}</span>`;
|
|
355
|
-
}
|
|
356
|
-
if (!this._assets) {
|
|
357
|
-
this.loadAssets(assetType);
|
|
358
|
-
}
|
|
359
|
-
if (!this.query.attributes) {
|
|
360
|
-
this.query.attributes = {};
|
|
361
|
-
}
|
|
362
|
-
if (!this.query.attributes.items || this.query.attributes.items.length === 0) {
|
|
363
|
-
this.query.attributes.items = [{}];
|
|
364
|
-
}
|
|
365
|
-
const showRemoveAttribute = !this.readonly && this.query.attributes && this.query.attributes.items && this.query.attributes.items.length > 1;
|
|
366
|
-
// TODO: Add multiselect support
|
|
367
|
-
const ids = getAssetIdsFromQuery(this.query);
|
|
368
|
-
const idValue = ids && ids.length > 0 ? ids[0] : "*";
|
|
369
|
-
const idOptions = [
|
|
370
|
-
["*", i18next.t("anyOfThisType")]
|
|
371
|
-
];
|
|
372
|
-
let searchProvider;
|
|
373
|
-
return html `
|
|
374
|
-
<div class="attribute-group">
|
|
375
|
-
|
|
376
|
-
<!-- Show SELECT input with 'loading' until the assets are retrieved -->
|
|
377
|
-
${when((!this._assets), () => html `
|
|
378
|
-
<or-mwc-input id="idSelect" class="min-width" type="${InputType.SELECT}" .readonly="${true}" .label="${i18next.t('loading')}"></or-mwc-input>
|
|
379
|
-
`, () => {
|
|
380
|
-
// Set list of displayed assets, and filtering assets out if needed.
|
|
381
|
-
// If <= 25 assets: display everything
|
|
382
|
-
// If between 25 and 100 assets: display everything with search functionality
|
|
383
|
-
// If > 100 assets: only display if in line with search input
|
|
384
|
-
if (this._assets.length <= 25) {
|
|
385
|
-
idOptions.push(...this._assets.map((asset) => [asset.id, asset.name]));
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
searchProvider = (search) => __awaiter(this, void 0, void 0, function* () {
|
|
389
|
-
var _a;
|
|
390
|
-
if (search) {
|
|
391
|
-
return this._assets.filter((asset) => { var _a; return (_a = asset.name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(search.toLowerCase()); }).map((asset) => [asset.id, asset.name]);
|
|
392
|
-
}
|
|
393
|
-
else if (this._assets.length <= 100) {
|
|
394
|
-
idOptions.push(...this._assets.map((asset) => [asset.id, asset.name]));
|
|
395
|
-
return idOptions;
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
const asset = (_a = this._assets) === null || _a === void 0 ? void 0 : _a.find((asset) => asset.id == idValue);
|
|
399
|
-
if (asset && idOptions.find(([id, _value]) => id == asset.id) == undefined) {
|
|
400
|
-
idOptions.push([asset.id, asset.name]); // add selected asset if there is one.
|
|
401
|
-
}
|
|
402
|
-
return idOptions;
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
const showAddAttribute = !this.readonly && (!this.config || !this.config.controls || this.config.controls.hideWhenAddAttribute !== true);
|
|
407
|
-
const onDurationAdd = (index) => {
|
|
408
|
-
this.duration = this.duration.set(index, undefined);
|
|
409
|
-
this.requestUpdate();
|
|
410
|
-
};
|
|
411
|
-
const onDurationChange = (index, duration) => {
|
|
412
|
-
console.debug("Updating duration of rule condition to ", duration);
|
|
413
|
-
this.duration = this.duration.set(index, duration);
|
|
414
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
415
|
-
this.requestUpdate();
|
|
416
|
-
};
|
|
417
|
-
return html `
|
|
418
|
-
<or-mwc-input id="idSelect" class="min-width filledSelect" type="${InputType.SELECT}" .readonly="${this.readonly || false}" .label="${i18next.t("asset")}"
|
|
419
|
-
.options="${idOptions}" .value="${idValue}" .searchProvider="${searchProvider}"
|
|
420
|
-
@or-mwc-input-changed="${(e) => { this._assetId = (e.detail.value); this.refresh(); }}"
|
|
421
|
-
></or-mwc-input>
|
|
422
|
-
<div class="attributes">
|
|
423
|
-
${this.query.attributes && this.query.attributes.items ? this.query.attributes.items.map((attributePredicate, index) => {
|
|
424
|
-
return html `
|
|
425
|
-
${index > 0 ? html `<or-icon class="small" icon="ampersand"></or-icon>` : ``}
|
|
426
|
-
<div class="attribute">
|
|
427
|
-
<div>
|
|
428
|
-
${this.attributePredicateEditorTemplate(assetTypeInfo, idValue !== "*" ? this._assets.find((asset) => asset.id === idValue) : undefined, attributePredicate)}
|
|
429
|
-
${this.attributeDurationTemplate(this.duration, index, onDurationAdd, onDurationChange)}
|
|
430
|
-
</div>
|
|
431
|
-
${showRemoveAttribute ? html `
|
|
432
|
-
<button class="button-clear" @click="${() => this.removeAttributePredicate(this.query.attributes, attributePredicate)}"><or-icon icon="close-circle"></or-icon></input>
|
|
433
|
-
</div>` : ``}
|
|
434
|
-
`;
|
|
435
|
-
}) : ``}
|
|
436
|
-
${showAddAttribute ? html `
|
|
437
|
-
<or-mwc-input class="plus-button" type="${InputType.BUTTON}" icon="plus"
|
|
438
|
-
label="rulesEditorAddAttribute" @or-mwc-input-changed="${(ev) => this.addAttributePredicate(this.query.attributes)}"></or-mwc-input>
|
|
439
|
-
` : ``}
|
|
440
|
-
</div>
|
|
441
|
-
`;
|
|
442
|
-
})}
|
|
443
|
-
</div>
|
|
444
|
-
`;
|
|
445
|
-
}
|
|
446
|
-
set _assetId(assetId) {
|
|
447
|
-
!assetId || assetId === "*" ? this.query.ids = undefined : this.query.ids = [assetId];
|
|
448
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
449
|
-
this.requestUpdate();
|
|
450
|
-
}
|
|
451
|
-
getAttributeName(attributePredicate) {
|
|
452
|
-
return attributePredicate && attributePredicate.name ? attributePredicate.name.value : undefined;
|
|
453
|
-
}
|
|
454
|
-
setAttributeName(attributePredicate, attributeName) {
|
|
455
|
-
if (!attributePredicate.name) {
|
|
456
|
-
attributePredicate.name = {
|
|
457
|
-
predicateType: "string"
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
attributePredicate.name.match = "EXACT" /* AssetQueryMatch.EXACT */;
|
|
461
|
-
attributePredicate.name.value = attributeName;
|
|
462
|
-
attributePredicate.value = undefined;
|
|
463
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
464
|
-
this.requestUpdate();
|
|
465
|
-
}
|
|
466
|
-
getOperatorMapValue(operatorMap, assetType, attributeName, attributeDescriptor, valueDescriptor) {
|
|
467
|
-
let assetAttributeMatch;
|
|
468
|
-
let attributeDescriptorMatch;
|
|
469
|
-
let attributeValueDescriptorMatch;
|
|
470
|
-
if (assetType && attributeName) {
|
|
471
|
-
if (operatorMap[assetType + ":" + attributeName]) {
|
|
472
|
-
return operatorMap[assetType + ":" + attributeName];
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
if (valueDescriptor) {
|
|
476
|
-
if (operatorMap[valueDescriptor.name]) {
|
|
477
|
-
return operatorMap[valueDescriptor.name];
|
|
478
|
-
}
|
|
479
|
-
if (operatorMap[valueDescriptor.jsonType]) {
|
|
480
|
-
return operatorMap[valueDescriptor.jsonType];
|
|
481
|
-
}
|
|
482
|
-
if (valueDescriptor.arrayDimensions) {
|
|
483
|
-
return operatorMap["array"];
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
getOperators(assetDescriptor, attributeDescriptor, valueDescriptor, attribute, attributeName) {
|
|
488
|
-
let operators;
|
|
489
|
-
if (this.config && this.config.controls && this.config.controls.allowedAssetQueryOperators) {
|
|
490
|
-
operators = this.getOperatorMapValue(this.config.controls.allowedAssetQueryOperators, getAssetTypeFromQuery(this.query), attributeName, attributeDescriptor, valueDescriptor);
|
|
491
|
-
}
|
|
492
|
-
if (!operators) {
|
|
493
|
-
operators = this.getOperatorMapValue(this._queryOperatorsMap, getAssetTypeFromQuery(this.query), attributeName, attributeDescriptor, valueDescriptor);
|
|
494
|
-
}
|
|
495
|
-
return operators ? operators.map((v) => [v, i18next.t(v)]) : [];
|
|
496
|
-
}
|
|
497
|
-
getOperator(attributePredicate) {
|
|
498
|
-
if (!attributePredicate) {
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
// Check for timestampOlderThan, it's independent of value predicate
|
|
502
|
-
if (attributePredicate.timestampOlderThan !== undefined) {
|
|
503
|
-
return AssetQueryOperator.NOT_UPDATED_FOR;
|
|
504
|
-
}
|
|
505
|
-
if (!attributePredicate.value) {
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
const valuePredicate = attributePredicate.value;
|
|
509
|
-
switch (valuePredicate.predicateType) {
|
|
510
|
-
case "string":
|
|
511
|
-
switch (valuePredicate.match) {
|
|
512
|
-
case "EXACT" /* AssetQueryMatch.EXACT */:
|
|
513
|
-
return valuePredicate.negate ? AssetQueryOperator.NOT_EQUALS : AssetQueryOperator.EQUALS;
|
|
514
|
-
case "BEGIN" /* AssetQueryMatch.BEGIN */:
|
|
515
|
-
return valuePredicate.negate ? AssetQueryOperator.NOT_STARTS_WITH : AssetQueryOperator.STARTS_WITH;
|
|
516
|
-
case "END" /* AssetQueryMatch.END */:
|
|
517
|
-
return valuePredicate.negate ? AssetQueryOperator.NOT_ENDS_WITH : AssetQueryOperator.ENDS_WITH;
|
|
518
|
-
case "CONTAINS" /* AssetQueryMatch.CONTAINS */:
|
|
519
|
-
return valuePredicate.negate ? AssetQueryOperator.NOT_CONTAINS : AssetQueryOperator.CONTAINS;
|
|
520
|
-
}
|
|
521
|
-
return;
|
|
522
|
-
case "boolean":
|
|
523
|
-
return valuePredicate.value ? AssetQueryOperator.IS_TRUE : AssetQueryOperator.IS_FALSE;
|
|
524
|
-
case "datetime":
|
|
525
|
-
case "number":
|
|
526
|
-
switch (valuePredicate.operator) {
|
|
527
|
-
case "EQUALS" /* AQO.EQUALS */:
|
|
528
|
-
return valuePredicate.negate ? AssetQueryOperator.NOT_EQUALS : AssetQueryOperator.EQUALS;
|
|
529
|
-
case "GREATER_THAN" /* AQO.GREATER_THAN */:
|
|
530
|
-
return valuePredicate.negate ? AssetQueryOperator.LESS_EQUALS : AssetQueryOperator.GREATER_THAN;
|
|
531
|
-
case "GREATER_EQUALS" /* AQO.GREATER_EQUALS */:
|
|
532
|
-
return valuePredicate.negate ? AssetQueryOperator.LESS_THAN : AssetQueryOperator.GREATER_EQUALS;
|
|
533
|
-
case "LESS_THAN" /* AQO.LESS_THAN */:
|
|
534
|
-
return valuePredicate.negate ? AssetQueryOperator.GREATER_EQUALS : AssetQueryOperator.LESS_THAN;
|
|
535
|
-
case "LESS_EQUALS" /* AQO.LESS_EQUALS */:
|
|
536
|
-
return valuePredicate.negate ? AssetQueryOperator.GREATER_THAN : AssetQueryOperator.LESS_EQUALS;
|
|
537
|
-
case "BETWEEN" /* AQO.BETWEEN */:
|
|
538
|
-
return valuePredicate.negate ? AssetQueryOperator.NOT_BETWEEN : AssetQueryOperator.BETWEEN;
|
|
539
|
-
}
|
|
540
|
-
return;
|
|
541
|
-
case "radial":
|
|
542
|
-
return valuePredicate.negated ? AssetQueryOperator.OUTSIDE_RADIUS : AssetQueryOperator.WITHIN_RADIUS;
|
|
543
|
-
case "rect":
|
|
544
|
-
return valuePredicate.negated ? AssetQueryOperator.OUTSIDE_RECTANGLE : AssetQueryOperator.WITHIN_RECTANGLE;
|
|
545
|
-
case "array":
|
|
546
|
-
if (valuePredicate.value && valuePredicate.index) {
|
|
547
|
-
return valuePredicate.negated ? AssetQueryOperator.NOT_INDEX_CONTAINS : AssetQueryOperator.INDEX_CONTAINS;
|
|
548
|
-
}
|
|
549
|
-
if (valuePredicate.lengthEquals) {
|
|
550
|
-
return valuePredicate.negated ? AssetQueryOperator.NOT_LENGTH_EQUALS : AssetQueryOperator.LENGTH_EQUALS;
|
|
551
|
-
}
|
|
552
|
-
if (valuePredicate.lengthGreaterThan) {
|
|
553
|
-
return valuePredicate.negated ? AssetQueryOperator.LENGTH_LESS_THAN : AssetQueryOperator.LENGTH_GREATER_THAN;
|
|
554
|
-
}
|
|
555
|
-
if (valuePredicate.lengthLessThan) {
|
|
556
|
-
return valuePredicate.negated ? AssetQueryOperator.LENGTH_GREATER_THAN : AssetQueryOperator.LENGTH_LESS_THAN;
|
|
557
|
-
}
|
|
558
|
-
return valuePredicate.negated ? AssetQueryOperator.NOT_CONTAINS : AssetQueryOperator.CONTAINS;
|
|
559
|
-
case "value-empty":
|
|
560
|
-
return valuePredicate.negate ? AssetQueryOperator.VALUE_NOT_EMPTY : AssetQueryOperator.VALUE_EMPTY;
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
updateDurationMap(index) {
|
|
564
|
-
if (this.duration) {
|
|
565
|
-
// re-assign durations by filtering out the index and adjusting remaining indices
|
|
566
|
-
const newDurationEntries = Array.from(this.duration.entries())
|
|
567
|
-
.filter(([k, _]) => k !== index)
|
|
568
|
-
.map(([k, v]) => {
|
|
569
|
-
const newIndex = k > index ? k - 1 : k;
|
|
570
|
-
return [newIndex, v]; // adjust indices after the removed index
|
|
571
|
-
});
|
|
572
|
-
this.duration = new Map(newDurationEntries);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
setOperator(assetDescriptor, attribute, attributeName, attributePredicate, operator) {
|
|
576
|
-
if (!this.query
|
|
577
|
-
|| !this.query.attributes
|
|
578
|
-
|| !this.query.attributes.items
|
|
579
|
-
|| this.query.attributes.items.length === 0) {
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
if (!operator) {
|
|
583
|
-
attributePredicate.value = undefined;
|
|
584
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
585
|
-
this.requestUpdate();
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(assetDescriptor.name, attribute || attributeName);
|
|
589
|
-
const value = operator;
|
|
590
|
-
if (!descriptors || !descriptors[1] || !value) {
|
|
591
|
-
attributePredicate.value = undefined;
|
|
592
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
593
|
-
this.requestUpdate();
|
|
594
|
-
return;
|
|
595
|
-
}
|
|
596
|
-
attributePredicate.timestampOlderThan = undefined;
|
|
597
|
-
const valueDescriptor = descriptors[1];
|
|
598
|
-
let predicate;
|
|
599
|
-
switch (value) {
|
|
600
|
-
// // object
|
|
601
|
-
// case AssetQueryOperator.NOT_CONTAINS_KEY:
|
|
602
|
-
// case AssetQueryOperator.CONTAINS_KEY:
|
|
603
|
-
// if (valueType === ValueType.OBJECT) {
|
|
604
|
-
// predicate = {
|
|
605
|
-
// predicateType: "object-value-key",
|
|
606
|
-
// negated: value === AssetQueryOperator.NOT_CONTAINS_KEY
|
|
607
|
-
// };
|
|
608
|
-
// }
|
|
609
|
-
// break;
|
|
610
|
-
// array
|
|
611
|
-
case AssetQueryOperator.INDEX_CONTAINS:
|
|
612
|
-
case AssetQueryOperator.NOT_INDEX_CONTAINS:
|
|
613
|
-
case AssetQueryOperator.LENGTH_EQUALS:
|
|
614
|
-
case AssetQueryOperator.NOT_LENGTH_EQUALS:
|
|
615
|
-
case AssetQueryOperator.LENGTH_LESS_THAN:
|
|
616
|
-
case AssetQueryOperator.LENGTH_GREATER_THAN:
|
|
617
|
-
if (valueDescriptor.arrayDimensions) {
|
|
618
|
-
predicate = {
|
|
619
|
-
predicateType: "array",
|
|
620
|
-
negated: value === AssetQueryOperator.NOT_INDEX_CONTAINS || value === AssetQueryOperator.NOT_LENGTH_EQUALS,
|
|
621
|
-
index: value === AssetQueryOperator.INDEX_CONTAINS || value === AssetQueryOperator.NOT_INDEX_CONTAINS ? 0 : undefined,
|
|
622
|
-
lengthEquals: value === AssetQueryOperator.LENGTH_EQUALS || value === AssetQueryOperator.NOT_LENGTH_EQUALS ? 0 : undefined,
|
|
623
|
-
lengthGreaterThan: value === AssetQueryOperator.LENGTH_GREATER_THAN ? 0 : undefined,
|
|
624
|
-
lengthLessThan: value === AssetQueryOperator.LENGTH_GREATER_THAN ? 0 : undefined,
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
break;
|
|
628
|
-
// geo point
|
|
629
|
-
case AssetQueryOperator.WITHIN_RADIUS:
|
|
630
|
-
case AssetQueryOperator.OUTSIDE_RADIUS:
|
|
631
|
-
predicate = {
|
|
632
|
-
predicateType: "radial",
|
|
633
|
-
negated: value === AssetQueryOperator.OUTSIDE_RADIUS,
|
|
634
|
-
lat: 0,
|
|
635
|
-
lng: 0,
|
|
636
|
-
radius: 50
|
|
637
|
-
};
|
|
638
|
-
break;
|
|
639
|
-
case AssetQueryOperator.WITHIN_RECTANGLE:
|
|
640
|
-
case AssetQueryOperator.OUTSIDE_RECTANGLE:
|
|
641
|
-
predicate = {
|
|
642
|
-
predicateType: "rect",
|
|
643
|
-
negated: value === AssetQueryOperator.OUTSIDE_RECTANGLE,
|
|
644
|
-
latMin: -0.1,
|
|
645
|
-
lngMin: -0.1,
|
|
646
|
-
latMax: 0.1,
|
|
647
|
-
lngMax: 0.1
|
|
648
|
-
};
|
|
649
|
-
break;
|
|
650
|
-
// boolean
|
|
651
|
-
case AssetQueryOperator.IS_TRUE:
|
|
652
|
-
case AssetQueryOperator.IS_FALSE:
|
|
653
|
-
if (valueDescriptor.jsonType === "boolean") {
|
|
654
|
-
predicate = {
|
|
655
|
-
predicateType: "boolean",
|
|
656
|
-
value: value === AssetQueryOperator.IS_TRUE
|
|
657
|
-
};
|
|
658
|
-
break;
|
|
659
|
-
}
|
|
660
|
-
// string
|
|
661
|
-
case AssetQueryOperator.STARTS_WITH:
|
|
662
|
-
case AssetQueryOperator.NOT_STARTS_WITH:
|
|
663
|
-
if (valueDescriptor.jsonType === "string") {
|
|
664
|
-
predicate = {
|
|
665
|
-
predicateType: "string",
|
|
666
|
-
negate: value === AssetQueryOperator.NOT_STARTS_WITH,
|
|
667
|
-
match: "BEGIN" /* AssetQueryMatch.BEGIN */
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
break;
|
|
671
|
-
case AssetQueryOperator.ENDS_WITH:
|
|
672
|
-
case AssetQueryOperator.NOT_ENDS_WITH:
|
|
673
|
-
if (valueDescriptor.jsonType === "string") {
|
|
674
|
-
predicate = {
|
|
675
|
-
predicateType: "string",
|
|
676
|
-
negate: value === AssetQueryOperator.NOT_ENDS_WITH,
|
|
677
|
-
match: "END" /* AssetQueryMatch.END */
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
break;
|
|
681
|
-
// number or datetime
|
|
682
|
-
case AssetQueryOperator.NOT_BETWEEN:
|
|
683
|
-
if (valueDescriptor.jsonType === "number" || valueDescriptor.jsonType === "bigint") {
|
|
684
|
-
predicate = {
|
|
685
|
-
predicateType: "number",
|
|
686
|
-
operator: "BETWEEN" /* AQO.BETWEEN */,
|
|
687
|
-
negate: true
|
|
688
|
-
};
|
|
689
|
-
}
|
|
690
|
-
else {
|
|
691
|
-
// Assume datetime
|
|
692
|
-
predicate = {
|
|
693
|
-
predicateType: "datetime",
|
|
694
|
-
operator: "BETWEEN" /* AQO.BETWEEN */,
|
|
695
|
-
negate: true
|
|
696
|
-
};
|
|
697
|
-
}
|
|
698
|
-
break;
|
|
699
|
-
case AssetQueryOperator.GREATER_THAN:
|
|
700
|
-
case AssetQueryOperator.GREATER_EQUALS:
|
|
701
|
-
case AssetQueryOperator.LESS_THAN:
|
|
702
|
-
case AssetQueryOperator.LESS_EQUALS:
|
|
703
|
-
case AssetQueryOperator.BETWEEN:
|
|
704
|
-
const key = Util.getEnumKeyAsString(AssetQueryOperator, value);
|
|
705
|
-
if (valueDescriptor.jsonType === "number") {
|
|
706
|
-
predicate = {
|
|
707
|
-
predicateType: "number",
|
|
708
|
-
operator: key
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
else {
|
|
712
|
-
// Assume datetime
|
|
713
|
-
predicate = {
|
|
714
|
-
predicateType: "datetime",
|
|
715
|
-
operator: key
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
break;
|
|
719
|
-
// multiple
|
|
720
|
-
case AssetQueryOperator.EQUALS:
|
|
721
|
-
case AssetQueryOperator.NOT_EQUALS:
|
|
722
|
-
if (valueDescriptor.jsonType === "date") {
|
|
723
|
-
predicate = {
|
|
724
|
-
predicateType: "datetime",
|
|
725
|
-
negate: value === AssetQueryOperator.NOT_EQUALS,
|
|
726
|
-
operator: "EQUALS" /* AQO.EQUALS */
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
else if (valueDescriptor.jsonType === "number") {
|
|
730
|
-
predicate = {
|
|
731
|
-
predicateType: "number",
|
|
732
|
-
negate: value === AssetQueryOperator.NOT_EQUALS,
|
|
733
|
-
operator: "EQUALS" /* AQO.EQUALS */
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
else if (valueDescriptor.jsonType === "string") {
|
|
737
|
-
predicate = {
|
|
738
|
-
predicateType: "string",
|
|
739
|
-
negate: value === AssetQueryOperator.NOT_EQUALS,
|
|
740
|
-
match: "EXACT" /* AssetQueryMatch.EXACT */
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
break;
|
|
744
|
-
case AssetQueryOperator.VALUE_EMPTY:
|
|
745
|
-
predicate = {
|
|
746
|
-
predicateType: "value-empty"
|
|
747
|
-
};
|
|
748
|
-
break;
|
|
749
|
-
case AssetQueryOperator.VALUE_NOT_EMPTY:
|
|
750
|
-
predicate = {
|
|
751
|
-
predicateType: "value-empty",
|
|
752
|
-
negate: true
|
|
753
|
-
};
|
|
754
|
-
break;
|
|
755
|
-
case AssetQueryOperator.CONTAINS:
|
|
756
|
-
case AssetQueryOperator.NOT_CONTAINS:
|
|
757
|
-
if (valueDescriptor.arrayDimensions) {
|
|
758
|
-
predicate = {
|
|
759
|
-
predicateType: "array",
|
|
760
|
-
negated: value === AssetQueryOperator.NOT_CONTAINS
|
|
761
|
-
};
|
|
762
|
-
}
|
|
763
|
-
else if (valueDescriptor.jsonType === "string") {
|
|
764
|
-
predicate = {
|
|
765
|
-
predicateType: "string",
|
|
766
|
-
negate: value === AssetQueryOperator.NOT_CONTAINS,
|
|
767
|
-
match: "CONTAINS" /* AssetQueryMatch.CONTAINS */
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
break;
|
|
771
|
-
// operator without value predicate - since timestamp is being used rather than attribute value
|
|
772
|
-
case AssetQueryOperator.NOT_UPDATED_FOR:
|
|
773
|
-
attributePredicate.timestampOlderThan = "";
|
|
774
|
-
const index = this.query.attributes.items.indexOf(attributePredicate);
|
|
775
|
-
this.updateDurationMap(index);
|
|
776
|
-
break;
|
|
777
|
-
}
|
|
778
|
-
attributePredicate.value = predicate;
|
|
779
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
780
|
-
this.requestUpdate();
|
|
781
|
-
}
|
|
782
|
-
get attributePredicate() {
|
|
783
|
-
return this.query
|
|
784
|
-
&& this.query.attributes
|
|
785
|
-
&& this.query.attributes.items
|
|
786
|
-
&& this.query.attributes.items.length > 0
|
|
787
|
-
? this.query.attributes.items[0] : undefined;
|
|
788
|
-
}
|
|
789
|
-
setValuePredicateProperty(valuePredicate, propertyName, value) {
|
|
790
|
-
if (!valuePredicate) {
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
valuePredicate[propertyName] = value;
|
|
794
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
795
|
-
this.requestUpdate();
|
|
796
|
-
}
|
|
797
|
-
removeAttributePredicate(group, attributePredicate) {
|
|
798
|
-
const index = group.items.indexOf(attributePredicate);
|
|
799
|
-
if (index >= 0) {
|
|
800
|
-
group.items.splice(index, 1);
|
|
801
|
-
this.updateDurationMap(index);
|
|
802
|
-
}
|
|
803
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
804
|
-
this.requestUpdate();
|
|
805
|
-
}
|
|
806
|
-
addAttributePredicate(group) {
|
|
807
|
-
if (!group.items) {
|
|
808
|
-
group.items = [];
|
|
809
|
-
}
|
|
810
|
-
group.items.push({});
|
|
811
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
812
|
-
this.requestUpdate();
|
|
813
|
-
}
|
|
814
|
-
toggleAttributeGroup(group) {
|
|
815
|
-
if (group.operator === "OR" /* LogicGroupOperator.OR */) {
|
|
816
|
-
group.operator = "AND" /* LogicGroupOperator.AND */;
|
|
817
|
-
}
|
|
818
|
-
else {
|
|
819
|
-
group.operator = "OR" /* LogicGroupOperator.OR */;
|
|
820
|
-
}
|
|
821
|
-
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
822
|
-
this.requestUpdate();
|
|
823
|
-
}
|
|
824
|
-
loadAssets(type) {
|
|
825
|
-
this.assetProvider(type).then(assets => {
|
|
826
|
-
this._assets = assets;
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
};
|
|
830
|
-
__decorate([
|
|
831
|
-
property({ type: Object, attribute: false })
|
|
832
|
-
], OrRuleAssetQuery.prototype, "condition", void 0);
|
|
833
|
-
__decorate([
|
|
834
|
-
property({ type: Object })
|
|
835
|
-
], OrRuleAssetQuery.prototype, "config", void 0);
|
|
836
|
-
__decorate([
|
|
837
|
-
property({ type: Object })
|
|
838
|
-
], OrRuleAssetQuery.prototype, "assetInfos", void 0);
|
|
839
|
-
__decorate([
|
|
840
|
-
property({ type: Object })
|
|
841
|
-
], OrRuleAssetQuery.prototype, "assetProvider", void 0);
|
|
842
|
-
__decorate([
|
|
843
|
-
state()
|
|
844
|
-
], OrRuleAssetQuery.prototype, "_assets", void 0);
|
|
845
|
-
OrRuleAssetQuery = __decorate([
|
|
846
|
-
customElement("or-rule-asset-query")
|
|
847
|
-
], OrRuleAssetQuery);
|
|
848
|
-
export { OrRuleAssetQuery };
|
|
849
|
-
//# sourceMappingURL=or-rule-asset-query.js.map
|
|
1
|
+
var __decorate=this&&this.__decorate||function(t,e,r,i){var a,s=arguments.length,n=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,r,i);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(s<3?a(n):s>3?a(e,r,n):a(e,r))||n);return s>3&&n&&Object.defineProperty(e,r,n),n},__awaiter=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))(function(a,s){function n(t){try{u(i.next(t))}catch(t){s(t)}}function o(t){try{u(i.throw(t))}catch(t){s(t)}}function u(t){var e;t.done?a(t.value):((e=t.value)instanceof r?e:new r(function(t){t(e)})).then(n,o)}u((i=i.apply(t,e||[])).next())})};import{css as t,html as e,LitElement as r}from"lit";import{customElement as i,property as a,state as s}from"lit/decorators.js";import{AssetModelUtil as n}from"@openremote/model";import{AssetQueryOperator as o,getAssetIdsFromQuery as u,getAssetTypeFromQuery as l}from"../index";import"@openremote/or-mwc-components/or-mwc-input";import{InputType as d}from"@openremote/or-mwc-components/or-mwc-input";import"@openremote/or-attribute-input";import{Util as p}from"@openremote/core";import c from"i18next";import{buttonStyle as T}from"../style";import{OrRulesJsonRuleChangedEvent as E}from"./or-rule-json-viewer";import{translate as h}from"@openremote/or-translate";import"./modals/or-rule-radial-modal";import{ifDefined as _}from"lit/directives/if-defined.js";import{when as m}from"lit/directives/when.js";import N from"moment";let style=t`
|
|
2
|
+
|
|
3
|
+
${T}
|
|
4
|
+
|
|
5
|
+
:host {
|
|
6
|
+
display: block;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.attribute-group {
|
|
10
|
+
flex-grow: 1;
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: start;
|
|
13
|
+
flex-direction: row;
|
|
14
|
+
flex-wrap: wrap;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.min-width {
|
|
18
|
+
min-width: 200px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.attribute-group > * {
|
|
22
|
+
margin: 10px 3px 6px 3px;
|
|
23
|
+
}
|
|
24
|
+
.attributes {
|
|
25
|
+
flex: 1 1 min-content;
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
row-gap: 10px;
|
|
29
|
+
}
|
|
30
|
+
or-icon.small {
|
|
31
|
+
--or-icon-width: 14px;
|
|
32
|
+
--or-icon-height: 14px;
|
|
33
|
+
}
|
|
34
|
+
.attribute {
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
}
|
|
38
|
+
.attribute > div {
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-direction: row;
|
|
41
|
+
flex-wrap: wrap;
|
|
42
|
+
align-items: center;
|
|
43
|
+
gap: 6px;
|
|
44
|
+
}
|
|
45
|
+
.attribute > div > or-rule-radial-modal {
|
|
46
|
+
min-width: auto;
|
|
47
|
+
}
|
|
48
|
+
.attribute > div > or-mwc-input[type="button"] {
|
|
49
|
+
min-width: auto;
|
|
50
|
+
}
|
|
51
|
+
.attribute > div > or-mwc-input:not([type="button"]) {
|
|
52
|
+
width: 200px;
|
|
53
|
+
}
|
|
54
|
+
.attribute > div > or-attribute-input {
|
|
55
|
+
width: 200px;
|
|
56
|
+
}
|
|
57
|
+
.attribute > div > * {
|
|
58
|
+
min-width: 200px;
|
|
59
|
+
}
|
|
60
|
+
.button-clear {
|
|
61
|
+
margin-left: auto;
|
|
62
|
+
}
|
|
63
|
+
.attribute:hover .button-clear {
|
|
64
|
+
visibility: visible;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.invalidLabel {
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
margin: 14px 3px auto 0;
|
|
71
|
+
height: 48px; /* Same as the icon size */
|
|
72
|
+
}
|
|
73
|
+
`,OrRuleAssetQuery=class extends h(c)(r){constructor(){super(),this._queryOperatorsMap={},this._queryOperatorsMap.GEO_JSONPoint=[o.EQUALS,o.NOT_EQUALS,o.WITHIN_RADIUS,o.OUTSIDE_RADIUS,o.WITHIN_RECTANGLE,o.OUTSIDE_RECTANGLE,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR],this._queryOperatorsMap.string=[o.EQUALS,o.NOT_EQUALS,o.CONTAINS,o.NOT_CONTAINS,o.STARTS_WITH,o.NOT_STARTS_WITH,o.ENDS_WITH,o.NOT_ENDS_WITH,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR],this._queryOperatorsMap.number=[o.EQUALS,o.NOT_EQUALS,o.GREATER_THAN,o.GREATER_EQUALS,o.LESS_THAN,o.LESS_EQUALS,o.BETWEEN,o.NOT_BETWEEN,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR],this._queryOperatorsMap.boolean=[o.IS_TRUE,o.IS_FALSE,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR],this._queryOperatorsMap.array=[o.CONTAINS,o.NOT_CONTAINS,o.INDEX_CONTAINS,o.NOT_INDEX_CONTAINS,o.LENGTH_EQUALS,o.NOT_LENGTH_EQUALS,o.LENGTH_LESS_THAN,o.LENGTH_GREATER_THAN,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR],this._queryOperatorsMap.object=[o.CONTAINS_KEY,o.NOT_CONTAINS_KEY,o.VALUE_EMPTY,o.VALUE_NOT_EMPTY,o.NOT_UPDATED_FOR]}refresh(){this._assets=void 0}attributePredicateEditorTemplate(t,r,i){let a=t.assetDescriptor,s=this.getOperator(i),o=this.getAttributeName(i),u=r&&r.attributes&&o?r.attributes[o]:void 0,l=[],T=n.getAttributeAndValueDescriptors(r?r.type:a.name,u||o,u);(l=r&&r.attributes?Object.values(r.attributes).filter(t=>t.meta&&(t.meta.hasOwnProperty("ruleState")?t.meta.ruleState:t.meta.hasOwnProperty("agentLink"))).map(t=>{let e=n.getAttributeAndValueDescriptors(r.type,t.name,t),i=p.getAttributeLabel(t,e[0],r.type,!1);return[t.name,i]}):t&&t.attributeDescriptors?t.attributeDescriptors.map(t=>{let e=n.getAttributeAndValueDescriptors(a.name,t),r=p.getAttributeLabel(void 0,e?e[0]:void 0,a.name,!1);return[t.name,r]}):[]).sort(p.sortByString(t=>t[1]));let E=o?this.getOperators(a,T?T[0]:void 0,T?T[1]:void 0,u,o):[];return e`
|
|
74
|
+
<or-mwc-input type="${d.SELECT}" @or-mwc-input-changed="${t=>this.setAttributeName(i,t.detail.value)}" .readonly="${this.readonly||!1}" .options="${l}" .value="${o}" .label="${c.t("attribute")}"></or-mwc-input>
|
|
75
|
+
${o?e`<or-mwc-input type="${d.SELECT}" @or-mwc-input-changed="${t=>this.setOperator(a,u,o,i,t.detail.value)}" .readonly="${this.readonly||!1}" .options="${E}" .value="${s}" .label="${c.t("operator")}"></or-mwc-input>`:""}
|
|
76
|
+
${i?this.attributePredicateValueEditorTemplate(a,r,i):""}
|
|
77
|
+
`}attributePredicateValueEditorTemplate(t,r,i){var a,s,u,p,T,h,m;if(this.getOperator(i)===o.NOT_UPDATED_FOR){let t=i.timestampOlderThan?N.duration(i.timestampOlderThan):void 0;return e`
|
|
78
|
+
<or-mwc-input type="${d.NUMBER}"
|
|
79
|
+
min="0"
|
|
80
|
+
.value="${null==t?void 0:t.asMinutes()}"
|
|
81
|
+
label="${c.t("rulesEditorDuration")}"
|
|
82
|
+
@or-mwc-input-changed="${t=>{let e=t.detail.value,r=N.duration(e,"minutes");i.timestampOlderThan=e>0?r.toISOString():void 0,this.dispatchEvent(new E)}}">
|
|
83
|
+
</or-mwc-input>`}let A=i.value;if(!t||!A)return"";let y=this.getAttributeName(i),b=l(this.query),O=r&&r.attributes&&y?r.attributes[y]:void 0,v=n.getAttributeAndValueDescriptors(b,y,O),S=A?A.value:void 0;switch(A.predicateType){case"string":return e`<or-attribute-input @or-attribute-input-changed="${t=>this.setValuePredicateProperty(A,"value",t.detail.value)}" .customProvider="${null==(a=this.config)?void 0:a.inputProvider}" .label="${c.t("value")}" .assetType="${b}" .attributeDescriptor="${v[0]}" .attributeValueDescriptor="${v[1]}" .value="${S}" .readonly="${this.readonly||!1}" .fullWidth="${!0}"></or-attribute-input>`;case"boolean":return e``;case"datetime":case"rect":default:return e`<span>NOT IMPLEMENTED</span>`;case"number":let g;if("BETWEEN"===A.operator)return e`
|
|
84
|
+
<or-attribute-input .inputType="${d.NUMBER}" @or-attribute-input-changed="${t=>this.setValuePredicateProperty(A,"value",t.detail.value)}" .customProvider="${null==(s=this.config)?void 0:s.inputProvider}" .label="${c.t("between")}" .assetType="${b}" .attributeDescriptor="${v[0]}" .attributeValueDescriptor="${v[1]}" .value="${S}" .readonly="${this.readonly||!1}" .fullWidth="${!0}"></or-attribute-input>
|
|
85
|
+
<span style="display: inline-flex; align-items: center;">&</span>
|
|
86
|
+
<or-attribute-input .inputType="${d.NUMBER}" @or-attribute-input-changed="${t=>this.setValuePredicateProperty(A,"rangeValue",t.detail.value)}" .customProvider="${null==(u=this.config)?void 0:u.inputProvider}" .label="${c.t("and")}" .assetType="${b}" .attributeDescriptor="${v[0]}" .attributeValueDescriptor="${v[1]}" .value="${A.rangeValue}" .readonly="${this.readonly||!1}" .fullWidth="${!0}"></or-attribute-input>
|
|
87
|
+
`;return(null==(T=null==(p=v[0])?void 0:p.format)?void 0:T.asSlider)&&(g=d.NUMBER),e`<or-attribute-input .inputType="${_(g)}" @or-attribute-input-changed="${t=>this.setValuePredicateProperty(A,"value",t.detail.value)}" .customProvider="${null==(h=this.config)?void 0:h.inputProvider}" .label="" .assetType="${b}" .attributeDescriptor="${v[0]}" .attributeValueDescriptor="${v[1]}" .value="${S}" .readonly="${this.readonly||!1}" .fullWidth="${!0}"></or-attribute-input>`;case"radial":return e`<or-rule-radial-modal .query="${this.query}" .assetDescriptor="${t}" .attributePredicate="${i}"></or-rule-radial-modal>`;case"value-empty":return"";case"array":return e`<or-attribute-input @or-attribute-input-changed="${t=>this.setValuePredicateProperty(A,"value",t.detail.value)}" .customProvider="${null==(m=this.config)?void 0:m.inputProvider}" .label="" .assetType="${b}" .attributeDescriptor="${v[0]}" .attributeValueDescriptor="${v[1]}" .value="${S}" .readonly="${this.readonly||!1}" .fullWidth="${!0}></or-attribute-input>`}}attributeDurationTemplate(t,r,i,a){var s,n;let u=null==(n=null==(s=this.query.attributes)?void 0:s.items)?void 0:n[r];if((u?this.getOperator(u):void 0)===o.NOT_UPDATED_FOR)return e``;if(!t.has(r))return e`
|
|
88
|
+
<or-mwc-input type="${d.BUTTON}" .readonly="${this.readonly||!1}" icon="clock-plus-outline"
|
|
89
|
+
title="${c.t("rulesEditorAddDuration")}" @or-mwc-input-changed="${()=>i(r)}"
|
|
90
|
+
></or-mwc-input>
|
|
91
|
+
`;{let i=t.get(r),s=i?N.duration(i):void 0;return e`
|
|
92
|
+
<or-mwc-input type="${d.NUMBER}" min="0" .readonly="${this.readonly||!1}"
|
|
93
|
+
.value="${null==s?void 0:s.asMinutes()}" label="${c.t("rulesEditorDuration")}"
|
|
94
|
+
@or-mwc-input-changed="${t=>{let e=N.duration(t.detail.value,"minutes");e.asMinutes()>0?a(r,e.toISOString()):a(r,void 0)}}"
|
|
95
|
+
></or-mwc-input>
|
|
96
|
+
`}}static get styles(){return style}shouldUpdate(t){return t.has("condition")&&(this._assets=void 0),super.shouldUpdate(t)}get query(){return this.condition.assets}get duration(){var t;return(null==(t=this.condition)?void 0:t.duration)?new Map(Object.entries(this.condition.duration).map(([t,e])=>[Number(t),e])):new Map}set duration(t){t.size>0?this.condition.duration=Object.fromEntries(t):this.condition.duration=void 0}render(){let t,r=l(this.query);if(!r)return e`<span class="invalidLabel">${c.t("errorOccurred")}</span>`;let i=this.assetInfos?this.assetInfos.find(t=>t.assetDescriptor.name===r):void 0;if(!i)return e`<span class="invalidLabel">${c.t("errorOccurred")}</span>`;this._assets||this.loadAssets(r),this.query.attributes||(this.query.attributes={}),this.query.attributes.items&&0!==this.query.attributes.items.length||(this.query.attributes.items=[{}]);let a=!this.readonly&&this.query.attributes&&this.query.attributes.items&&this.query.attributes.items.length>1,s=u(this.query),n=s&&s.length>0?s[0]:"*",o=[["*",c.t("anyOfThisType")]];return e`
|
|
97
|
+
<div class="attribute-group">
|
|
98
|
+
|
|
99
|
+
<!-- Show SELECT input with 'loading' until the assets are retrieved -->
|
|
100
|
+
${m(!this._assets,()=>e`
|
|
101
|
+
<or-mwc-input id="idSelect" class="min-width" type="${d.SELECT}" .readonly="${!0}" .label="${c.t("loading")}"></or-mwc-input>
|
|
102
|
+
`,()=>{this._assets.length<=25?o.push(...this._assets.map(t=>[t.id,t.name])):t=t=>__awaiter(this,void 0,void 0,function*(){var e;if(t)return this._assets.filter(e=>{var r;return null==(r=e.name)?void 0:r.toLowerCase().includes(t.toLowerCase())}).map(t=>[t.id,t.name]);if(this._assets.length<=100)return o.push(...this._assets.map(t=>[t.id,t.name])),o;{let t=null==(e=this._assets)?void 0:e.find(t=>t.id==n);return t&&void 0==o.find(([e,r])=>e==t.id)&&o.push([t.id,t.name]),o}});let r=!this.readonly&&(!this.config||!this.config.controls||!0!==this.config.controls.hideWhenAddAttribute),s=t=>{this.duration=this.duration.set(t,void 0),this.requestUpdate()},u=(t,e)=>{console.debug("Updating duration of rule condition to ",e),this.duration=this.duration.set(t,e),this.dispatchEvent(new E),this.requestUpdate()};return e`
|
|
103
|
+
<or-mwc-input id="idSelect" class="min-width filledSelect" type="${d.SELECT}" .readonly="${this.readonly||!1}" .label="${c.t("asset")}"
|
|
104
|
+
.options="${o}" .value="${n}" .searchProvider="${t}"
|
|
105
|
+
@or-mwc-input-changed="${t=>{this._assetId=t.detail.value,this.refresh()}}"
|
|
106
|
+
></or-mwc-input>
|
|
107
|
+
<div class="attributes">
|
|
108
|
+
${this.query.attributes&&this.query.attributes.items?this.query.attributes.items.map((t,r)=>e`
|
|
109
|
+
${r>0?e`<or-icon class="small" icon="ampersand"></or-icon>`:""}
|
|
110
|
+
<div class="attribute">
|
|
111
|
+
<div>
|
|
112
|
+
${this.attributePredicateEditorTemplate(i,"*"!==n?this._assets.find(t=>t.id===n):void 0,t)}
|
|
113
|
+
${this.attributeDurationTemplate(this.duration,r,s,u)}
|
|
114
|
+
</div>
|
|
115
|
+
${a?e`
|
|
116
|
+
<button class="button-clear" @click="${()=>this.removeAttributePredicate(this.query.attributes,t)}"><or-icon icon="close-circle"></or-icon></input>
|
|
117
|
+
</div>`:""}
|
|
118
|
+
`):""}
|
|
119
|
+
${r?e`
|
|
120
|
+
<or-mwc-input class="plus-button" type="${d.BUTTON}" icon="plus"
|
|
121
|
+
label="rulesEditorAddAttribute" @or-mwc-input-changed="${t=>this.addAttributePredicate(this.query.attributes)}"></or-mwc-input>
|
|
122
|
+
`:""}
|
|
123
|
+
</div>
|
|
124
|
+
`})}
|
|
125
|
+
</div>
|
|
126
|
+
`}set _assetId(t){t&&"*"!==t?this.query.ids=[t]:this.query.ids=void 0,this.dispatchEvent(new E),this.requestUpdate()}getAttributeName(t){return t&&t.name?t.name.value:void 0}setAttributeName(t,e){t.name||(t.name={predicateType:"string"}),t.name.match="EXACT",t.name.value=e,t.value=void 0,this.dispatchEvent(new E),this.requestUpdate()}getOperatorMapValue(t,e,r,i,a){if(e&&r&&t[e+":"+r])return t[e+":"+r];if(a){if(t[a.name])return t[a.name];if(t[a.jsonType])return t[a.jsonType];if(a.arrayDimensions)return t.array}}getOperators(t,e,r,i,a){let s;return this.config&&this.config.controls&&this.config.controls.allowedAssetQueryOperators&&(s=this.getOperatorMapValue(this.config.controls.allowedAssetQueryOperators,l(this.query),a,e,r)),s||(s=this.getOperatorMapValue(this._queryOperatorsMap,l(this.query),a,e,r)),s?s.map(t=>[t,c.t(t)]):[]}getOperator(t){if(!t)return;if(void 0!==t.timestampOlderThan)return o.NOT_UPDATED_FOR;if(!t.value)return;let e=t.value;switch(e.predicateType){case"string":switch(e.match){case"EXACT":return e.negate?o.NOT_EQUALS:o.EQUALS;case"BEGIN":return e.negate?o.NOT_STARTS_WITH:o.STARTS_WITH;case"END":return e.negate?o.NOT_ENDS_WITH:o.ENDS_WITH;case"CONTAINS":return e.negate?o.NOT_CONTAINS:o.CONTAINS}return;case"boolean":return e.value?o.IS_TRUE:o.IS_FALSE;case"datetime":case"number":switch(e.operator){case"EQUALS":return e.negate?o.NOT_EQUALS:o.EQUALS;case"GREATER_THAN":return e.negate?o.LESS_EQUALS:o.GREATER_THAN;case"GREATER_EQUALS":return e.negate?o.LESS_THAN:o.GREATER_EQUALS;case"LESS_THAN":return e.negate?o.GREATER_EQUALS:o.LESS_THAN;case"LESS_EQUALS":return e.negate?o.GREATER_THAN:o.LESS_EQUALS;case"BETWEEN":return e.negate?o.NOT_BETWEEN:o.BETWEEN}return;case"radial":return e.negated?o.OUTSIDE_RADIUS:o.WITHIN_RADIUS;case"rect":return e.negated?o.OUTSIDE_RECTANGLE:o.WITHIN_RECTANGLE;case"array":if(e.value&&e.index)return e.negated?o.NOT_INDEX_CONTAINS:o.INDEX_CONTAINS;if(e.lengthEquals)return e.negated?o.NOT_LENGTH_EQUALS:o.LENGTH_EQUALS;if(e.lengthGreaterThan)return e.negated?o.LENGTH_LESS_THAN:o.LENGTH_GREATER_THAN;if(e.lengthLessThan)return e.negated?o.LENGTH_GREATER_THAN:o.LENGTH_LESS_THAN;return e.negated?o.NOT_CONTAINS:o.CONTAINS;case"value-empty":return e.negate?o.VALUE_NOT_EMPTY:o.VALUE_EMPTY}}updateDurationMap(t){if(this.duration){let e=Array.from(this.duration.entries()).filter(([e,r])=>e!==t).map(([e,r])=>[e>t?e-1:e,r]);this.duration=new Map(e)}}setOperator(t,e,r,i,a){let s;if(!this.query||!this.query.attributes||!this.query.attributes.items||0===this.query.attributes.items.length)return;if(!a){i.value=void 0,this.dispatchEvent(new E),this.requestUpdate();return}let u=n.getAttributeAndValueDescriptors(t.name,e||r);if(!u||!u[1]||!a){i.value=void 0,this.dispatchEvent(new E),this.requestUpdate();return}i.timestampOlderThan=void 0;let l=u[1];switch(a){case o.INDEX_CONTAINS:case o.NOT_INDEX_CONTAINS:case o.LENGTH_EQUALS:case o.NOT_LENGTH_EQUALS:case o.LENGTH_LESS_THAN:case o.LENGTH_GREATER_THAN:l.arrayDimensions&&(s={predicateType:"array",negated:a===o.NOT_INDEX_CONTAINS||a===o.NOT_LENGTH_EQUALS,index:a===o.INDEX_CONTAINS||a===o.NOT_INDEX_CONTAINS?0:void 0,lengthEquals:a===o.LENGTH_EQUALS||a===o.NOT_LENGTH_EQUALS?0:void 0,lengthGreaterThan:a===o.LENGTH_GREATER_THAN?0:void 0,lengthLessThan:a===o.LENGTH_GREATER_THAN?0:void 0});break;case o.WITHIN_RADIUS:case o.OUTSIDE_RADIUS:s={predicateType:"radial",negated:a===o.OUTSIDE_RADIUS,lat:0,lng:0,radius:50};break;case o.WITHIN_RECTANGLE:case o.OUTSIDE_RECTANGLE:s={predicateType:"rect",negated:a===o.OUTSIDE_RECTANGLE,latMin:-.1,lngMin:-.1,latMax:.1,lngMax:.1};break;case o.IS_TRUE:case o.IS_FALSE:if("boolean"===l.jsonType){s={predicateType:"boolean",value:a===o.IS_TRUE};break}case o.STARTS_WITH:case o.NOT_STARTS_WITH:"string"===l.jsonType&&(s={predicateType:"string",negate:a===o.NOT_STARTS_WITH,match:"BEGIN"});break;case o.ENDS_WITH:case o.NOT_ENDS_WITH:"string"===l.jsonType&&(s={predicateType:"string",negate:a===o.NOT_ENDS_WITH,match:"END"});break;case o.NOT_BETWEEN:s="number"===l.jsonType||"bigint"===l.jsonType?{predicateType:"number",operator:"BETWEEN",negate:!0}:{predicateType:"datetime",operator:"BETWEEN",negate:!0};break;case o.GREATER_THAN:case o.GREATER_EQUALS:case o.LESS_THAN:case o.LESS_EQUALS:case o.BETWEEN:let d=p.getEnumKeyAsString(o,a);s="number"===l.jsonType?{predicateType:"number",operator:d}:{predicateType:"datetime",operator:d};break;case o.EQUALS:case o.NOT_EQUALS:"date"===l.jsonType?s={predicateType:"datetime",negate:a===o.NOT_EQUALS,operator:"EQUALS"}:"number"===l.jsonType?s={predicateType:"number",negate:a===o.NOT_EQUALS,operator:"EQUALS"}:"string"===l.jsonType&&(s={predicateType:"string",negate:a===o.NOT_EQUALS,match:"EXACT"});break;case o.VALUE_EMPTY:s={predicateType:"value-empty"};break;case o.VALUE_NOT_EMPTY:s={predicateType:"value-empty",negate:!0};break;case o.CONTAINS:case o.NOT_CONTAINS:l.arrayDimensions?s={predicateType:"array",negated:a===o.NOT_CONTAINS}:"string"===l.jsonType&&(s={predicateType:"string",negate:a===o.NOT_CONTAINS,match:"CONTAINS"});break;case o.NOT_UPDATED_FOR:i.timestampOlderThan="";let c=this.query.attributes.items.indexOf(i);this.updateDurationMap(c)}i.value=s,this.dispatchEvent(new E),this.requestUpdate()}get attributePredicate(){return this.query&&this.query.attributes&&this.query.attributes.items&&this.query.attributes.items.length>0?this.query.attributes.items[0]:void 0}setValuePredicateProperty(t,e,r){t&&(t[e]=r,this.dispatchEvent(new E),this.requestUpdate())}removeAttributePredicate(t,e){let r=t.items.indexOf(e);r>=0&&(t.items.splice(r,1),this.updateDurationMap(r)),this.dispatchEvent(new E),this.requestUpdate()}addAttributePredicate(t){t.items||(t.items=[]),t.items.push({}),this.dispatchEvent(new E),this.requestUpdate()}toggleAttributeGroup(t){"OR"===t.operator?t.operator="AND":t.operator="OR",this.dispatchEvent(new E),this.requestUpdate()}loadAssets(t){this.assetProvider(t).then(t=>{this._assets=t})}};__decorate([a({type:Object,attribute:!1})],OrRuleAssetQuery.prototype,"condition",void 0),__decorate([a({type:Object})],OrRuleAssetQuery.prototype,"config",void 0),__decorate([a({type:Object})],OrRuleAssetQuery.prototype,"assetInfos",void 0),__decorate([a({type:Object})],OrRuleAssetQuery.prototype,"assetProvider",void 0),__decorate([s()],OrRuleAssetQuery.prototype,"_assets",void 0),OrRuleAssetQuery=__decorate([i("or-rule-asset-query")],OrRuleAssetQuery);export{OrRuleAssetQuery};
|