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