@openremote/or-rules 1.8.0-snapshot.20250725120002 → 1.8.0-snapshot.20250728102340
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,91 +1,18 @@
|
|
|
1
|
-
var __decorate
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
var __decorate=this&&this.__decorate||function(e,t,r,o){var a,i=arguments.length,l=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,r,o);else for(var n=e.length-1;n>=0;n--)(a=e[n])&&(l=(i<3?a(l):i>3?a(t,r,l):a(t,r))||l);return i>3&&l&&Object.defineProperty(t,r,l),l};import{html as e,LitElement as t,css as r}from"lit";import{customElement as o,property as a}from"lit/decorators.js";import"@openremote/or-mwc-components/or-mwc-input";import{InputType as i}from"@openremote/or-mwc-components/or-mwc-input";import{OrRulesJsonRuleChangedEvent as l}from"../or-rule-json-viewer";import{i18next as n}from"@openremote/or-translate";let OrRuleFormAlarm=class extends t{constructor(){super(...arguments),this.users=[]}static get styles(){return r`
|
|
2
|
+
or-mwc-input {
|
|
3
|
+
margin-bottom: 20px;
|
|
4
|
+
min-width: 420px;
|
|
5
|
+
width: 100%;
|
|
6
|
+
}
|
|
7
|
+
`}render(){let t=this.action.alarm,r=this.users.filter(e=>"manager-keycloak"!==e.username).map(e=>({value:e.id,label:e.username}));return r.unshift({value:void 0,label:n.t("none")}),e`
|
|
8
|
+
<form style="display:grid">
|
|
9
|
+
<or-mwc-input value="${t&&t.title?t.title:""}" @or-mwc-input-changed="${e=>this.setActionAlarmName(e.detail.value,"title")}" .label="title" type="${i.TEXT}" required placeholder=" "></or-mwc-input>
|
|
10
|
+
<or-mwc-input value="${t&&t.content?t.content:""}" @or-mwc-input-changed="${e=>this.setActionAlarmName(e.detail.value,"content")}" .label=content" type="${i.TEXTAREA}" required placeholder=" " ></or-mwc-input>
|
|
11
|
+
<or-mwc-input .label="${n.t("alarm.assignee")}"
|
|
12
|
+
.type="${i.SELECT}"
|
|
13
|
+
.options="${r.map(e=>e.label)}"
|
|
14
|
+
.value="${this.action.assigneeId?r.filter(e=>e.value===this.action.assigneeId).map(e=>e.label)[0]:""}"
|
|
15
|
+
@or-mwc-input-changed="${e=>{this.action.assigneeId=r.filter(t=>t.label===e.detail.value).map(e=>e.value)[0],this.setActionAlarmName(e.detail.value,void 0)}}"
|
|
16
|
+
></or-mwc-input>
|
|
17
|
+
</form>
|
|
18
|
+
`}setActionAlarmName(e,t){if(t&&this.action.alarm){let r=this.action.alarm;r[t]=e,this.action.alarm=Object.assign({},r)}t||(this.action.assigneeId=this.users.filter(t=>t.username===e).map(e=>e.id)[0]),this.dispatchEvent(new l),this.requestUpdate()}};__decorate([a({type:Object,attribute:!1})],OrRuleFormAlarm.prototype,"action",void 0),__decorate([a()],OrRuleFormAlarm.prototype,"users",void 0),OrRuleFormAlarm=__decorate([o("or-rule-form-alarm")],OrRuleFormAlarm);export{OrRuleFormAlarm};
|
|
@@ -1,51 +1,12 @@
|
|
|
1
|
-
var __decorate
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
var __decorate=this&&this.__decorate||function(e,t,r,o){var i,m=arguments.length,s=m<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,o);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(m<3?i(s):m>3?i(t,r,s):i(t,r))||s);return m>3&&s&&Object.defineProperty(t,r,s),s};import{html as e,LitElement as t,css as r}from"lit";import{customElement as o,property as i}from"lit/decorators.js";import"@openremote/or-mwc-components/or-mwc-input";import m from"i18next";import{translate as s}from"@openremote/or-translate";import"@openremote/or-mwc-components/or-mwc-input";import{InputType as a}from"@openremote/or-mwc-components/or-mwc-input";import{OrRulesJsonRuleChangedEvent as c}from"../or-rule-json-viewer";let OrRuleFormEmailMessage=class extends s(m)(t){static get styles(){return r`
|
|
2
|
+
or-mwc-input {
|
|
3
|
+
margin-bottom: 20px;
|
|
4
|
+
min-width: 420px;
|
|
5
|
+
width: 100%;
|
|
6
|
+
}
|
|
7
|
+
`}render(){return this.message?e`
|
|
8
|
+
<form style="display:grid">
|
|
9
|
+
<or-mwc-input value="${this.message.subject||""}" @or-mwc-input-changed="${e=>this.setActionNotificationName(e.detail.value,"subject")}" .label="${m.t("subject")}" type="${a.TEXT}" required placeholder=" "></or-mwc-input>
|
|
10
|
+
<or-mwc-input value="${this.message.html||""}" @or-mwc-input-changed="${e=>this.setActionNotificationName(e.detail.value,"html")}" .label="${m.t("message")}" type="${a.TEXTAREA}" required placeholder=" " ></or-mwc-input>
|
|
11
|
+
</form>
|
|
12
|
+
`:e`<or-translate .value="${"errorOccurred"}"></or-translate>`}setActionNotificationName(e,t){t&&this.message&&(this.message[t]=e),this.dispatchEvent(new c),this.requestUpdate()}};__decorate([i({type:Object})],OrRuleFormEmailMessage.prototype,"message",void 0),OrRuleFormEmailMessage=__decorate([o("or-rule-form-email-message")],OrRuleFormEmailMessage);export{OrRuleFormEmailMessage};
|
|
@@ -1,271 +1,45 @@
|
|
|
1
|
-
var __decorate = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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>`;
|
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,a,r){var i,n=arguments.length,o=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,a):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,a,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(n<3?i(o):n>3?i(t,a,o):i(t,a))||o);return n>3&&o&&Object.defineProperty(t,a,o),o},__awaiter=this&&this.__awaiter||function(e,t,a,r){return new(a||(a=Promise))(function(i,n){function o(e){try{l(r.next(e))}catch(e){n(e)}}function s(e){try{l(r.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?i(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(o,s)}l((r=r.apply(e,t||[])).next())})};import{i18next as e,translate as t}from"@openremote/or-translate";import{LitElement as a,css as r,html as i}from"lit";import{customElement as n,property as o,state as s}from"lit/decorators.js";import{InputType as l}from"@openremote/or-mwc-components/or-mwc-input";import{showSnackbar as g}from"@openremote/or-mwc-components/or-mwc-snackbar";import{OrRulesJsonRuleChangedEvent as u}from"../or-rule-json-viewer";import{when as c}from"lit/directives/when.js";import{until as d}from"lit/directives/until.js";import{guard as m}from"lit/directives/guard.js";import"./or-rule-form-email-message";import"./or-rule-form-push-notification";import h from"iso-639-1";import{DefaultColor6 as p}from"@openremote/core";let OrRuleFormLocalized=class extends t(e)(a){constructor(){super(...arguments),this.type="push",this.languages=["en"],this.defaultLang="en",this.wrongLanguage=!1,this._selectedLanguage="en"}static get styles(){return r`
|
|
2
|
+
or-mwc-input {
|
|
3
|
+
margin-bottom: 20px;
|
|
4
|
+
min-width: 420px;
|
|
5
|
+
width: 100%;
|
|
135
6
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
7
|
+
|
|
8
|
+
.divider {
|
|
9
|
+
margin-bottom: 20px;
|
|
10
|
+
border-top: 1px solid rgba(0, 0, 0, 12%);
|
|
140
11
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
<or-translate value="
|
|
169
|
-
|
|
170
|
-
|
|
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
|
|
12
|
+
`}connectedCallback(){super.connectedCallback(),this.defaultLang&&this.languages.includes(this.defaultLang)||(this.defaultLang=this.languages[0]),this._selectedLanguage=this.defaultLang}render(){var e;return i`
|
|
13
|
+
<div>
|
|
14
|
+
${c(this.wrongLanguage,()=>d(this._getWrongLanguageTemplate()))}
|
|
15
|
+
${m([this.message,this._selectedLanguage,this.languages,this.type],()=>i`
|
|
16
|
+
${d(this._getLanguageSelectForm(this._selectedLanguage,this.languages),i`Loading...`)}
|
|
17
|
+
${d(this._getNotificationForm(this.message,this._selectedLanguage),i`Loading...`)}
|
|
18
|
+
`)}
|
|
19
|
+
${c((null==(e=this.languages)?void 0:e.length)&&this._validLanguages&&this._validLanguages.length<this.languages.length,()=>d(this._getLanguageErrorTemplate(this.languages,this._validLanguages)))}
|
|
20
|
+
</div>
|
|
21
|
+
`}_getWrongLanguageTemplate(){return __awaiter(this,void 0,void 0,function*(){return i`
|
|
22
|
+
<or-mwc-input .type="${l.BUTTON}" fullWidth outlined
|
|
23
|
+
label="defaultLanguageChangedError" style="margin-top: 10px;"
|
|
24
|
+
@or-mwc-input-changed="${this._fixDefaultLanguage}"
|
|
25
|
+
></or-mwc-input>
|
|
26
|
+
`})}_fixDefaultLanguage(){this.message?(console.debug("Updating default language from "+this.message.defaultLanguage+" to "+this.defaultLang),this.message.defaultLanguage=this.defaultLang,this.wrongLanguage=!1,this.dispatchEvent(new u)):(console.warn("Could not fix language, because the message could not be found."),g(void 0,"Could not fix language, because the message could not be found."))}_getLanguageSelectForm(e){return __awaiter(this,arguments,void 0,function*(e,t=[this._selectedLanguage],a=!0){let r=t.map(e=>[e,h.getName(e)]);return i`
|
|
27
|
+
<div style="display: flex; justify-content: space-between;">
|
|
28
|
+
<or-mwc-input .type="${l.SELECT}" .options="${r}" .value="${e}"
|
|
29
|
+
@or-mwc-input-changed="${this._onLanguageChange}"
|
|
30
|
+
></or-mwc-input>
|
|
31
|
+
</div>
|
|
32
|
+
${c(a,()=>i`
|
|
33
|
+
<div class="divider"></div>`)}
|
|
34
|
+
`})}_onLanguageChange(e){this._selectedLanguage=e.detail.value}_getNotificationForm(){return __awaiter(this,arguments,void 0,function*(e=this.message,t=this._selectedLanguage){if(!(null==e?void 0:e.languages))return i`<or-translate .value="${"errorOccurred"}"></or-translate>`;e.languages[t]||(e.languages[t]={type:this.type});let a=e.languages[t];return"push"===a.type?i`
|
|
35
|
+
<or-rule-form-push-notification .message="${a}"></or-rule-form-push-notification>
|
|
36
|
+
`:"email"===a.type?i`
|
|
37
|
+
<or-rule-form-email-message .message="${a}"></or-rule-form-email-message>
|
|
38
|
+
`:i`
|
|
39
|
+
<or-translate .value="${"errorOccurred"}"></or-translate>
|
|
40
|
+
`})}_getLanguageErrorTemplate(e,t){return __awaiter(this,void 0,void 0,function*(){let a=e.filter(e=>!t.includes(e)).map(e=>h.getName(e)).join(", ");return i`
|
|
41
|
+
<div style="margin-top: 10px; display: flex; justify-content: end; color: ${p};">
|
|
42
|
+
<or-translate value="languagesInvalidError"></or-translate>
|
|
43
|
+
<span style="padding-left: 4px;">${a}</span>
|
|
44
|
+
</div>
|
|
45
|
+
`})}isValid(){var e,t,a;if((null==(e=this.message)?void 0:e.languages)&&(null==(t=this.languages)?void 0:t.length)){this._cleanNotificationMessage();let e=null==(a=this.languages)?void 0:a.filter(e=>{var t,a;if(!(null==(a=null==(t=this.message)?void 0:t.languages)?void 0:a[e]))return!0;let r=this.message.languages[e];switch(r.type){case"email":return r.subject&&r.html;case"push":return r.title&&r.body;case"localized":return!1;default:return!0}});return JSON.stringify(this._validLanguages)!==JSON.stringify(e)&&(this._validLanguages=e),e.length===this.languages.length}return!1}_cleanNotificationMessage(){var e;if(null==(e=this.message)?void 0:e.languages){let e=Object.entries(this.message.languages).filter(([e,t])=>0!==Object.entries(t).filter(e=>{if("type"===e[0]||null==e[1]||"string"==typeof e[1]&&0===e[1].length)return!1;if(Array.isArray(e[1])){if(!e[1].some(e=>Object.keys(e).length>0&&Object.values(e).some(e=>e)))return!1}else if("object"==typeof e[1]&&(0===Object.keys(e[1]).length||0===Object.values(e[1]).filter(e=>e).length))return!1;return!0}).length||(console.debug(`Removing fields of notification language '${e}', as they were all empty.`),!1));this.message.languages=Object.fromEntries(e)}}};__decorate([o({type:Object})],OrRuleFormLocalized.prototype,"message",void 0),__decorate([o({type:String})],OrRuleFormLocalized.prototype,"type",void 0),__decorate([o()],OrRuleFormLocalized.prototype,"languages",void 0),__decorate([o()],OrRuleFormLocalized.prototype,"defaultLang",void 0),__decorate([o()],OrRuleFormLocalized.prototype,"wrongLanguage",void 0),__decorate([s()],OrRuleFormLocalized.prototype,"_selectedLanguage",void 0),__decorate([s()],OrRuleFormLocalized.prototype,"_validLanguages",void 0),OrRuleFormLocalized=__decorate([n("or-rule-form-localized")],OrRuleFormLocalized);export{OrRuleFormLocalized};
|