@openremote/or-rules 1.8.0-snapshot.20250725074716 → 1.8.0-snapshot.20250725120000
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,18 +1,91 @@
|
|
|
1
|
-
var __decorate=this&&this.__decorate
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
/*
|
|
8
|
+
* Copyright 2024, OpenRemote Inc.
|
|
9
|
+
*
|
|
10
|
+
* See the CONTRIBUTORS.txt file in the distribution for a
|
|
11
|
+
* full listing of individual contributors.
|
|
12
|
+
*
|
|
13
|
+
* This program is free software: you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU Affero General Public License as
|
|
15
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
16
|
+
* License, or (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU Affero General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
24
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
25
|
+
*/
|
|
26
|
+
import { html, LitElement, css } from "lit";
|
|
27
|
+
import { customElement, property } from "lit/decorators.js";
|
|
28
|
+
import "@openremote/or-mwc-components/or-mwc-input";
|
|
29
|
+
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
|
|
30
|
+
import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
|
|
31
|
+
import { i18next } from "@openremote/or-translate";
|
|
32
|
+
let OrRuleFormAlarm = class OrRuleFormAlarm extends LitElement {
|
|
33
|
+
constructor() {
|
|
34
|
+
super(...arguments);
|
|
35
|
+
this.users = [];
|
|
36
|
+
}
|
|
37
|
+
static get styles() {
|
|
38
|
+
return css `
|
|
39
|
+
or-mwc-input {
|
|
40
|
+
margin-bottom: 20px;
|
|
41
|
+
min-width: 420px;
|
|
42
|
+
width: 100%;
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
render() {
|
|
47
|
+
const alarm = this.action.alarm;
|
|
48
|
+
const options = this.users.filter((u) => u.username !== 'manager-keycloak').map((u) => {
|
|
49
|
+
return { value: u.id, label: u.username };
|
|
50
|
+
});
|
|
51
|
+
options.unshift({ value: undefined, label: i18next.t("none") });
|
|
52
|
+
return html `
|
|
53
|
+
<form style="display:grid">
|
|
54
|
+
<or-mwc-input value="${alarm && alarm.title ? alarm.title : ""}" @or-mwc-input-changed="${(e) => this.setActionAlarmName(e.detail.value, "title")}" .label="title" type="${InputType.TEXT}" required placeholder=" "></or-mwc-input>
|
|
55
|
+
<or-mwc-input value="${alarm && alarm.content ? alarm.content : ""}" @or-mwc-input-changed="${(e) => this.setActionAlarmName(e.detail.value, "content")}" .label=content" type="${InputType.TEXTAREA}" required placeholder=" " ></or-mwc-input>
|
|
56
|
+
<or-mwc-input .label="${i18next.t("alarm.assignee")}"
|
|
57
|
+
.type="${InputType.SELECT}"
|
|
58
|
+
.options="${options.map((obj) => obj.label)}"
|
|
59
|
+
.value="${this.action.assigneeId ? options.filter((obj) => obj.value === this.action.assigneeId).map((obj) => obj.label)[0] : ""}"
|
|
60
|
+
@or-mwc-input-changed="${(e) => {
|
|
61
|
+
this.action.assigneeId = options.filter((obj) => obj.label === e.detail.value).map((obj) => obj.value)[0];
|
|
62
|
+
this.setActionAlarmName(e.detail.value, undefined);
|
|
63
|
+
}}"
|
|
64
|
+
></or-mwc-input>
|
|
65
|
+
</form>
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
setActionAlarmName(value, key) {
|
|
69
|
+
if (key && this.action.alarm) {
|
|
70
|
+
const alarm = this.action.alarm;
|
|
71
|
+
alarm[key] = value;
|
|
72
|
+
this.action.alarm = Object.assign({}, alarm);
|
|
73
|
+
}
|
|
74
|
+
if (!key) {
|
|
75
|
+
this.action.assigneeId = this.users.filter((obj) => obj.username === value).map((obj) => obj.id)[0];
|
|
76
|
+
}
|
|
77
|
+
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
78
|
+
this.requestUpdate();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
__decorate([
|
|
82
|
+
property({ type: Object, attribute: false })
|
|
83
|
+
], OrRuleFormAlarm.prototype, "action", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
property()
|
|
86
|
+
], OrRuleFormAlarm.prototype, "users", void 0);
|
|
87
|
+
OrRuleFormAlarm = __decorate([
|
|
88
|
+
customElement("or-rule-form-alarm")
|
|
89
|
+
], OrRuleFormAlarm);
|
|
90
|
+
export { OrRuleFormAlarm };
|
|
91
|
+
//# sourceMappingURL=or-rule-form-alarm.js.map
|
|
@@ -1,12 +1,51 @@
|
|
|
1
|
-
var __decorate=this&&this.__decorate
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html, LitElement, css } from "lit";
|
|
8
|
+
import { customElement, property } from "lit/decorators.js";
|
|
9
|
+
import "@openremote/or-mwc-components/or-mwc-input";
|
|
10
|
+
import i18next from "i18next";
|
|
11
|
+
import { translate } from "@openremote/or-translate";
|
|
12
|
+
import "@openremote/or-mwc-components/or-mwc-input";
|
|
13
|
+
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
|
|
14
|
+
import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
|
|
15
|
+
let OrRuleFormEmailMessage = class OrRuleFormEmailMessage extends translate(i18next)(LitElement) {
|
|
16
|
+
static get styles() {
|
|
17
|
+
return css `
|
|
18
|
+
or-mwc-input {
|
|
19
|
+
margin-bottom: 20px;
|
|
20
|
+
min-width: 420px;
|
|
21
|
+
width: 100%;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
render() {
|
|
26
|
+
if (!this.message) {
|
|
27
|
+
return html `<or-translate .value="${"errorOccurred"}"></or-translate>`;
|
|
28
|
+
}
|
|
29
|
+
return html `
|
|
30
|
+
<form style="display:grid">
|
|
31
|
+
<or-mwc-input value="${this.message.subject || ''}" @or-mwc-input-changed="${(e) => this.setActionNotificationName(e.detail.value, "subject")}" .label="${i18next.t("subject")}" type="${InputType.TEXT}" required placeholder=" "></or-mwc-input>
|
|
32
|
+
<or-mwc-input value="${this.message.html || ""}" @or-mwc-input-changed="${(e) => this.setActionNotificationName(e.detail.value, "html")}" .label="${i18next.t("message")}" type="${InputType.TEXTAREA}" required placeholder=" " ></or-mwc-input>
|
|
33
|
+
</form>
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
setActionNotificationName(value, key) {
|
|
37
|
+
if (key && this.message) {
|
|
38
|
+
this.message[key] = value;
|
|
39
|
+
}
|
|
40
|
+
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
41
|
+
this.requestUpdate();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
__decorate([
|
|
45
|
+
property({ type: Object })
|
|
46
|
+
], OrRuleFormEmailMessage.prototype, "message", void 0);
|
|
47
|
+
OrRuleFormEmailMessage = __decorate([
|
|
48
|
+
customElement("or-rule-form-email-message")
|
|
49
|
+
], OrRuleFormEmailMessage);
|
|
50
|
+
export { OrRuleFormEmailMessage };
|
|
51
|
+
//# sourceMappingURL=or-rule-form-email-message.js.map
|
|
@@ -1,45 +1,271 @@
|
|
|
1
|
-
var __decorate
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 { i18next, translate } from "@openremote/or-translate";
|
|
17
|
+
import { LitElement, css, html } from "lit";
|
|
18
|
+
import { customElement, property, state } from "lit/decorators.js";
|
|
19
|
+
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
|
|
20
|
+
import { showSnackbar } from "@openremote/or-mwc-components/or-mwc-snackbar";
|
|
21
|
+
import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
|
|
22
|
+
import { when } from "lit/directives/when.js";
|
|
23
|
+
import { until } from "lit/directives/until.js";
|
|
24
|
+
import { guard } from "lit/directives/guard.js";
|
|
25
|
+
import "./or-rule-form-email-message";
|
|
26
|
+
import "./or-rule-form-push-notification";
|
|
27
|
+
import ISO6391 from "iso-639-1";
|
|
28
|
+
import { DefaultColor6 } from "@openremote/core";
|
|
29
|
+
let OrRuleFormLocalized = class OrRuleFormLocalized extends translate(i18next)(LitElement) {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.type = "push";
|
|
33
|
+
this.languages = ["en"];
|
|
34
|
+
this.defaultLang = "en";
|
|
35
|
+
this.wrongLanguage = false;
|
|
36
|
+
this._selectedLanguage = "en";
|
|
37
|
+
}
|
|
38
|
+
static get styles() {
|
|
39
|
+
return css `
|
|
40
|
+
or-mwc-input {
|
|
41
|
+
margin-bottom: 20px;
|
|
42
|
+
min-width: 420px;
|
|
43
|
+
width: 100%;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.divider {
|
|
47
|
+
margin-bottom: 20px;
|
|
48
|
+
border-top: 1px solid rgba(0, 0, 0, 12%);
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
connectedCallback() {
|
|
53
|
+
super.connectedCallback();
|
|
54
|
+
if (!this.defaultLang || !this.languages.includes(this.defaultLang)) {
|
|
55
|
+
this.defaultLang = this.languages[0];
|
|
56
|
+
}
|
|
57
|
+
this._selectedLanguage = this.defaultLang;
|
|
58
|
+
}
|
|
59
|
+
render() {
|
|
60
|
+
var _a;
|
|
61
|
+
return html `
|
|
62
|
+
<div>
|
|
63
|
+
${when(this.wrongLanguage, () => until(this._getWrongLanguageTemplate()))}
|
|
64
|
+
${guard([this.message, this._selectedLanguage, this.languages, this.type], () => html `
|
|
65
|
+
${until(this._getLanguageSelectForm(this._selectedLanguage, this.languages), html `Loading...`)}
|
|
66
|
+
${until(this._getNotificationForm(this.message, this._selectedLanguage), html `Loading...`)}
|
|
67
|
+
`)}
|
|
68
|
+
${when(((_a = this.languages) === null || _a === void 0 ? void 0 : _a.length) && this._validLanguages && (this._validLanguages.length < this.languages.length), () => until(this._getLanguageErrorTemplate(this.languages, this._validLanguages)))}
|
|
69
|
+
</div>
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Internal function that returns we "the default language has changed! Fix here" warning. (using {@link TemplateResult})
|
|
74
|
+
* This template includes a button that will update the default language to the correct one.
|
|
75
|
+
*/
|
|
76
|
+
_getWrongLanguageTemplate() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
return html `
|
|
79
|
+
<or-mwc-input .type="${InputType.BUTTON}" fullWidth outlined
|
|
80
|
+
label="defaultLanguageChangedError" style="margin-top: 10px;"
|
|
81
|
+
@or-mwc-input-changed="${this._fixDefaultLanguage}"
|
|
82
|
+
></or-mwc-input>
|
|
83
|
+
`;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Function that corrects the default language in the {@link LocalizedNotificationMessage},
|
|
88
|
+
* to the one provided by parent elements using {@link defaultLang}.
|
|
89
|
+
* The {@link wrongLanguage} property will be updated to 'false'.
|
|
90
|
+
*/
|
|
91
|
+
_fixDefaultLanguage() {
|
|
92
|
+
if (this.message) {
|
|
93
|
+
console.debug("Updating default language from " + this.message.defaultLanguage + " to " + this.defaultLang);
|
|
94
|
+
this.message.defaultLanguage = this.defaultLang;
|
|
95
|
+
this.wrongLanguage = false;
|
|
96
|
+
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
console.warn("Could not fix language, because the message could not be found.");
|
|
100
|
+
showSnackbar(undefined, "Could not fix language, because the message could not be found.");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Internal function that returns the "select language" controls form. (using {@link TemplateResult})
|
|
105
|
+
* Based on {@link languageCodes}, it lists all languages of the ISO6391 specification.
|
|
106
|
+
*/
|
|
107
|
+
_getLanguageSelectForm(selected_1) {
|
|
108
|
+
return __awaiter(this, arguments, void 0, function* (selected, languageCodes = [this._selectedLanguage], divider = true) {
|
|
109
|
+
const languages = languageCodes.map(key => [key, ISO6391.getName(key)]);
|
|
110
|
+
return html `
|
|
111
|
+
<div style="display: flex; justify-content: space-between;">
|
|
112
|
+
<or-mwc-input .type="${InputType.SELECT}" .options="${languages}" .value="${selected}"
|
|
113
|
+
@or-mwc-input-changed="${this._onLanguageChange}"
|
|
114
|
+
></or-mwc-input>
|
|
115
|
+
</div>
|
|
116
|
+
${when(divider, () => html `
|
|
117
|
+
<div class="divider"></div>`)}
|
|
118
|
+
`;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* HTML callback for when the selected language changes.
|
|
123
|
+
*/
|
|
124
|
+
_onLanguageChange(ev) {
|
|
125
|
+
this._selectedLanguage = ev.detail.value;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Internal function that returns the correct notification form, based on the type.
|
|
129
|
+
* Based on {@link lang}, it uses the Notification configured for that language.
|
|
130
|
+
*/
|
|
131
|
+
_getNotificationForm() {
|
|
132
|
+
return __awaiter(this, arguments, void 0, function* (message = this.message, lang = this._selectedLanguage) {
|
|
133
|
+
if (!(message === null || message === void 0 ? void 0 : message.languages)) {
|
|
134
|
+
return html `<or-translate .value="${"errorOccurred"}"></or-translate>`;
|
|
6
135
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
136
|
+
if (!message.languages[lang]) {
|
|
137
|
+
message.languages[lang] = {
|
|
138
|
+
type: this.type
|
|
139
|
+
};
|
|
11
140
|
}
|
|
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
|
-
<or-translate
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
141
|
+
const msg = message.languages[lang];
|
|
142
|
+
if (msg.type === "push") {
|
|
143
|
+
return html `
|
|
144
|
+
<or-rule-form-push-notification .message="${msg}"></or-rule-form-push-notification>
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
147
|
+
else if (msg.type === "email") {
|
|
148
|
+
return html `
|
|
149
|
+
<or-rule-form-email-message .message="${msg}"></or-rule-form-email-message>
|
|
150
|
+
`;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
return html `
|
|
154
|
+
<or-translate .value="${"errorOccurred"}"></or-translate>
|
|
155
|
+
`;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Internal function that returns the "language error" text, if a message is invalid. (using {@link TemplateResult})
|
|
161
|
+
* Based on {@link validLanguages} and the listed {@link languages}, it shows a string of which ones are invalid.
|
|
162
|
+
*/
|
|
163
|
+
_getLanguageErrorTemplate(languages, validLanguages) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
const invalidLocalesStr = languages.filter(l => !validLanguages.includes(l)).map(l => ISO6391.getName(l)).join(", ");
|
|
166
|
+
return html `
|
|
167
|
+
<div style="margin-top: 10px; display: flex; justify-content: end; color: ${DefaultColor6};">
|
|
168
|
+
<or-translate value="languagesInvalidError"></or-translate>
|
|
169
|
+
<span style="padding-left: 4px;">${invalidLocalesStr}</span>
|
|
170
|
+
</div>
|
|
171
|
+
`;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* A public function that checks if the localized {@link message} is valid.
|
|
176
|
+
* By looping through the languages, we verify for each email- and push notification if some required variables are empty.
|
|
177
|
+
* Returns true, or false if ANY language is not valid.
|
|
178
|
+
*/
|
|
179
|
+
isValid() {
|
|
180
|
+
var _a, _b, _c;
|
|
181
|
+
if (((_a = this.message) === null || _a === void 0 ? void 0 : _a.languages) && ((_b = this.languages) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
182
|
+
// First, cleanup the message
|
|
183
|
+
this._cleanNotificationMessage();
|
|
184
|
+
const validLanguages = (_c = this.languages) === null || _c === void 0 ? void 0 : _c.filter(lang => {
|
|
185
|
+
var _a, _b;
|
|
186
|
+
if (!((_b = (_a = this.message) === null || _a === void 0 ? void 0 : _a.languages) === null || _b === void 0 ? void 0 : _b[lang])) {
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
const msg = this.message.languages[lang];
|
|
190
|
+
switch (msg.type) {
|
|
191
|
+
case "email":
|
|
192
|
+
return msg.subject && msg.html;
|
|
193
|
+
case "push":
|
|
194
|
+
return msg.title && msg.body;
|
|
195
|
+
case "localized":
|
|
196
|
+
return false;
|
|
197
|
+
default:
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
// Update cached list of valid languages
|
|
202
|
+
if (JSON.stringify(this._validLanguages) !== JSON.stringify(validLanguages)) {
|
|
203
|
+
this._validLanguages = validLanguages;
|
|
204
|
+
}
|
|
205
|
+
return validLanguages.length === this.languages.length;
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Function that cleans up the localized notification message, by removing empty (or not filled in-) messages.
|
|
211
|
+
* By looping through the languages, checking the amount of keys in the JS object, we delete languages that can be cleared.
|
|
212
|
+
*/
|
|
213
|
+
_cleanNotificationMessage() {
|
|
214
|
+
var _a;
|
|
215
|
+
if ((_a = this.message) === null || _a === void 0 ? void 0 : _a.languages) {
|
|
216
|
+
const languageEntries = Object.entries(this.message.languages).filter(([lang, msg]) => {
|
|
217
|
+
const userDefinedFields = Object.entries(msg).filter(entry => {
|
|
218
|
+
if (entry[0] === "type")
|
|
219
|
+
return false;
|
|
220
|
+
if (entry[1] == null)
|
|
221
|
+
return false; // key has no value
|
|
222
|
+
if (typeof entry[1] === "string" && entry[1].length === 0)
|
|
223
|
+
return false;
|
|
224
|
+
if (Array.isArray(entry[1])) {
|
|
225
|
+
// Check if any object in the array has at least one key-value pair with a truthy value
|
|
226
|
+
const arrayHasValue = entry[1].some(obj => Object.keys(obj).length > 0 && Object.values(obj).some(value => value));
|
|
227
|
+
if (!arrayHasValue)
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
else if (typeof entry[1] === "object") {
|
|
231
|
+
if (Object.keys(entry[1]).length === 0 || Object.values(entry[1]).filter(value => value).length === 0)
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
return true;
|
|
235
|
+
});
|
|
236
|
+
if (userDefinedFields.length === 0) {
|
|
237
|
+
console.debug(`Removing fields of notification language '${lang}', as they were all empty.`);
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
});
|
|
242
|
+
this.message.languages = Object.fromEntries(languageEntries);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
__decorate([
|
|
247
|
+
property({ type: Object })
|
|
248
|
+
], OrRuleFormLocalized.prototype, "message", void 0);
|
|
249
|
+
__decorate([
|
|
250
|
+
property({ type: String })
|
|
251
|
+
], OrRuleFormLocalized.prototype, "type", void 0);
|
|
252
|
+
__decorate([
|
|
253
|
+
property()
|
|
254
|
+
], OrRuleFormLocalized.prototype, "languages", void 0);
|
|
255
|
+
__decorate([
|
|
256
|
+
property()
|
|
257
|
+
], OrRuleFormLocalized.prototype, "defaultLang", void 0);
|
|
258
|
+
__decorate([
|
|
259
|
+
property()
|
|
260
|
+
], OrRuleFormLocalized.prototype, "wrongLanguage", void 0);
|
|
261
|
+
__decorate([
|
|
262
|
+
state()
|
|
263
|
+
], OrRuleFormLocalized.prototype, "_selectedLanguage", void 0);
|
|
264
|
+
__decorate([
|
|
265
|
+
state()
|
|
266
|
+
], OrRuleFormLocalized.prototype, "_validLanguages", void 0);
|
|
267
|
+
OrRuleFormLocalized = __decorate([
|
|
268
|
+
customElement("or-rule-form-localized")
|
|
269
|
+
], OrRuleFormLocalized);
|
|
270
|
+
export { OrRuleFormLocalized };
|
|
271
|
+
//# sourceMappingURL=or-rule-form-localized.js.map
|