@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,126 +1,849 @@
|
|
|
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
|
-
|
|
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
|
+
import { css, html, LitElement } from "lit";
|
|
17
|
+
import { customElement, property, state } from "lit/decorators.js";
|
|
18
|
+
import { AssetModelUtil } from "@openremote/model";
|
|
19
|
+
import { AssetQueryOperator, getAssetIdsFromQuery, getAssetTypeFromQuery } from "../index";
|
|
20
|
+
import "@openremote/or-mwc-components/or-mwc-input";
|
|
21
|
+
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
|
|
22
|
+
import "@openremote/or-attribute-input";
|
|
23
|
+
import { Util } from "@openremote/core";
|
|
24
|
+
import i18next from "i18next";
|
|
25
|
+
import { buttonStyle } from "../style";
|
|
26
|
+
import { OrRulesJsonRuleChangedEvent } from "./or-rule-json-viewer";
|
|
27
|
+
import { translate } from "@openremote/or-translate";
|
|
28
|
+
import "./modals/or-rule-radial-modal";
|
|
29
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
30
|
+
import { when } from 'lit/directives/when.js';
|
|
31
|
+
import moment from "moment";
|
|
32
|
+
// language=CSS
|
|
33
|
+
const style = css `
|
|
34
|
+
|
|
35
|
+
${buttonStyle}
|
|
36
|
+
|
|
37
|
+
:host {
|
|
38
|
+
display: block;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.attribute-group {
|
|
42
|
+
flex-grow: 1;
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: start;
|
|
45
|
+
flex-direction: row;
|
|
46
|
+
flex-wrap: wrap;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.min-width {
|
|
50
|
+
min-width: 200px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.attribute-group > * {
|
|
54
|
+
margin: 10px 3px 6px 3px;
|
|
55
|
+
}
|
|
56
|
+
.attributes {
|
|
57
|
+
flex: 1 1 min-content;
|
|
58
|
+
display: flex;
|
|
59
|
+
flex-direction: column;
|
|
60
|
+
row-gap: 10px;
|
|
61
|
+
}
|
|
62
|
+
or-icon.small {
|
|
63
|
+
--or-icon-width: 14px;
|
|
64
|
+
--or-icon-height: 14px;
|
|
65
|
+
}
|
|
66
|
+
.attribute {
|
|
67
|
+
display: flex;
|
|
68
|
+
align-items: center;
|
|
69
|
+
}
|
|
70
|
+
.attribute > div {
|
|
71
|
+
display: flex;
|
|
72
|
+
flex-direction: row;
|
|
73
|
+
flex-wrap: wrap;
|
|
74
|
+
align-items: center;
|
|
75
|
+
gap: 6px;
|
|
76
|
+
}
|
|
77
|
+
.attribute > div > or-rule-radial-modal {
|
|
78
|
+
min-width: auto;
|
|
79
|
+
}
|
|
80
|
+
.attribute > div > or-mwc-input[type="button"] {
|
|
81
|
+
min-width: auto;
|
|
82
|
+
}
|
|
83
|
+
.attribute > div > or-mwc-input:not([type="button"]) {
|
|
84
|
+
width: 200px;
|
|
85
|
+
}
|
|
86
|
+
.attribute > div > or-attribute-input {
|
|
87
|
+
width: 200px;
|
|
88
|
+
}
|
|
89
|
+
.attribute > div > * {
|
|
90
|
+
min-width: 200px;
|
|
91
|
+
}
|
|
92
|
+
.button-clear {
|
|
93
|
+
margin-left: auto;
|
|
94
|
+
}
|
|
95
|
+
.attribute:hover .button-clear {
|
|
96
|
+
visibility: visible;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.invalidLabel {
|
|
100
|
+
display: flex;
|
|
101
|
+
align-items: center;
|
|
102
|
+
margin: 14px 3px auto 0;
|
|
103
|
+
height: 48px; /* Same as the icon size */
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
let OrRuleAssetQuery = class OrRuleAssetQuery extends translate(i18next)(LitElement) {
|
|
107
|
+
constructor() {
|
|
108
|
+
super();
|
|
109
|
+
// Value predicates for specific value descriptors
|
|
110
|
+
this._queryOperatorsMap = {};
|
|
111
|
+
this._queryOperatorsMap["GEO_JSONPoint" /* WellknownValueTypes.GEOJSONPOINT */] = [
|
|
112
|
+
AssetQueryOperator.EQUALS,
|
|
113
|
+
AssetQueryOperator.NOT_EQUALS,
|
|
114
|
+
AssetQueryOperator.WITHIN_RADIUS,
|
|
115
|
+
AssetQueryOperator.OUTSIDE_RADIUS,
|
|
116
|
+
AssetQueryOperator.WITHIN_RECTANGLE,
|
|
117
|
+
AssetQueryOperator.OUTSIDE_RECTANGLE,
|
|
118
|
+
AssetQueryOperator.VALUE_EMPTY,
|
|
119
|
+
AssetQueryOperator.VALUE_NOT_EMPTY,
|
|
120
|
+
AssetQueryOperator.NOT_UPDATED_FOR
|
|
121
|
+
];
|
|
122
|
+
this._queryOperatorsMap["string"] = [
|
|
123
|
+
AssetQueryOperator.EQUALS,
|
|
124
|
+
AssetQueryOperator.NOT_EQUALS,
|
|
125
|
+
AssetQueryOperator.CONTAINS,
|
|
126
|
+
AssetQueryOperator.NOT_CONTAINS,
|
|
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
|