@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,113 +1,609 @@
1
- var __decorate=this&&this.__decorate||function(e,t,i,o){var r,n=arguments.length,a=n<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,o);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(n<3?r(a):n>3?r(t,i,a):r(t,i))||a);return n>3&&a&&Object.defineProperty(t,i,a),a};import{css as e,html as t,LitElement as i}from"lit";import{customElement as o,property as r}from"lit/decorators.js";import{buttonStyle as n}from"../style";import"./or-rule-asset-query";import{getAssetTypeFromQuery as a}from"../index";import{OrRulesJsonRuleChangedEvent as s}from"./or-rule-json-viewer";import{AssetModelUtil as l}from"@openremote/model";import c from"i18next";import{InputType as u}from"@openremote/or-mwc-components/or-mwc-input";import{getContentWithMenuTemplate as p}from"@openremote/or-mwc-components/or-mwc-menu";import{manager as h,Util as d}from"@openremote/core";import"./or-rule-action-attribute";import"./or-rule-action-notification";import"./or-rule-action-webhook";import"./or-rule-action-alarm";import{translate as m}from"@openremote/or-translate";let NOTIFICATION_COLOR="4B87EA",WAIT_COLOR="EACC54",ALARM_COLOR="FC2D2D";function getActionTypesMenu(e,t){let i=!0,o=!0,r=!0,n=!0,a=!0,s=!0,u=!0,p=!0,m=!1;e&&e.controls&&e.controls.allowedActionTypes&&(i=e.controls.allowedActionTypes.indexOf("attribute")>=0,o=e.controls.allowedActionTypes.indexOf("wait")>=0,r=e.controls.allowedActionTypes.indexOf("alarm")>=0,n=e.controls.allowedActionTypes.indexOf("email")>=0,a=e.controls.allowedActionTypes.indexOf("email_localized")>=0,s=e.controls.allowedActionTypes.indexOf("push")>=0,u=e.controls.allowedActionTypes.indexOf("push_localized")>=0,p=e.controls.allowedActionTypes.indexOf("webhook")>=0),(null==e?void 0:e.notifications)&&(m=Object.entries(e.notifications).filter(e=>(e[0]===h.displayRealm||"default"===e[0])&&void 0!==e[1]).length>0);let f=[];return i&&t&&f.push(...t.filter(e=>"agent"!==e.assetDescriptor.descriptorType).map(e=>{let t=l.getAssetDescriptorColour(e),i=l.getAssetDescriptorIcon(e);return{text:d.getAssetTypeLabel(e.assetDescriptor),value:e.assetDescriptor.name,icon:i||l.getAssetDescriptorIcon("ThingAsset"),styleMap:t?{"--or-icon-fill":"#"+t}:void 0}})),f.sort(d.sortByString(e=>null==e?void 0:e.value)),f.push(null),n&&f.push({text:c.t("email"),icon:"email",value:m&&a?"email_localized":"email",styleMap:{"--or-icon-fill":"#"+NOTIFICATION_COLOR}}),s&&f.push({text:c.t("push-notification"),icon:"cellphone-message",value:m&&u?"push_localized":"push",styleMap:{"--or-icon-fill":"#"+NOTIFICATION_COLOR}}),o&&f.push({text:c.t("wait"),icon:"timer",value:"wait",styleMap:{"--or-icon-fill":"#"+WAIT_COLOR}}),r&&f.push({text:c.t("alarm."),icon:"bell-outline",value:"alarm",styleMap:{"--or-icon-fill":"#"+ALARM_COLOR}}),p&&f.push({text:c.t("webhook"),icon:"webhook",value:"webhook",styleMap:{"--or-icon-fill":"#"+NOTIFICATION_COLOR}}),f}export var RecurrenceOption;function getRecurrenceMenu(e){return e&&e.controls&&e.controls.allowedRecurrenceOptions?e.controls.allowedRecurrenceOptions.map(e=>({text:c.t(e),value:e})):Object.values(RecurrenceOption).map(e=>({text:c.t(e),value:e}))}!function(e){e.ALWAYS="always",e.ONCE="once",e.ONCE_PER_HOUR="oncePerHour",e.ONCE_PER_DAY="oncePerDay",e.ONCE_PER_WEEK="oncePerWeek"}(RecurrenceOption||(RecurrenceOption={}));let style=e`
2
-
3
- :host {
4
- display: flex;
5
- width: 100%;
6
- flex-direction: column;
7
- }
8
-
9
- ${n}
10
-
11
- .rule-action {
12
- display: flex;
13
- margin: 10px 0;
14
- }
15
-
16
- .rule-action-wrapper {
17
- flex-grow: 1;
18
- display: flex;
19
- align-items: baseline;
20
- }
21
-
22
- .rule-action > button {
23
- flex-grow: 0;
24
- }
25
-
26
- .rule-action:hover .button-clear {
27
- visibility: visible;
28
- }
29
-
30
- or-panel:hover .remove-button.button-clear {
31
- visibility: visible;
32
- }
33
-
34
- or-panel {
35
- position: relative;
36
- margin: 10px 10px 20px 10px;
37
- }
38
-
39
- #type-selector {
40
- margin-top: 10px;
41
- }
42
-
43
- .add-button-wrapper {
44
- display: flex;
45
- align-items: center;
46
- white-space: nowrap;
47
- }
48
-
49
- .add-button-wrapper > * {
50
- margin-right: 6px;
51
- }
52
-
53
- .add-button-wrapper or-mwc-menu {
54
- text-transform: capitalize;
55
- }
56
-
57
- #type {
58
- white-space: nowrap;
59
- margin: 4px 3px auto 0;
60
- text-transform: capitalize;
61
- }
62
-
63
- .rule-recurrence {
64
- position: absolute;
65
- top: 5px;
66
- right: 0;
67
- }
68
-
69
- `,OrRuleThenOtherwise=class extends m(c)(i){static get styles(){return style}get thenAllowAdd(){return!this.config||!this.config.controls||!0!==this.config.controls.hideThenAddAction}ruleRecurrenceTemplate(e,i){let o="",r="inherit",n=RecurrenceOption.ONCE;return e&&(void 0===e.mins||null===e.mins?n=RecurrenceOption.ONCE:0===e.mins?n=RecurrenceOption.ALWAYS:60===e.mins?n=RecurrenceOption.ONCE_PER_HOUR:1440===e.mins?n=RecurrenceOption.ONCE_PER_DAY:10080===e.mins&&(n=RecurrenceOption.ONCE_PER_WEEK)),o=i?t`
70
- <div style="--or-mwc-input-color: ${r}; margin-right: 6px;">
71
- <or-mwc-input .type="${u.BUTTON}" label="${n}"></or-mwc-input>
72
- </div>
73
- `:t`
74
- <div style="--or-mwc-input-color: ${r}; margin-right: 6px;">
75
- ${p(t`<or-mwc-input .type="${u.BUTTON}" label="${n}"></or-mwc-input>`,getRecurrenceMenu(this.config),n,e=>this.setRecurrenceOption(e))}
76
- </div>
77
- `,t`
78
- <div class="rule-recurrence">
79
- ${o}
80
- </div>
81
- `}ruleActionTemplate(e,i,o){let r=!this.config||!this.config.controls||!0!==this.config.controls.hideActionTypeOptions,n=this.getActionType(i);if(!n&&!r)return t`<span>INVALID CONFIG - NO TYPE SPECIFIED AND TYPE SELECTOR DISABLED</span>`;let a="",s="",c=!this.readonly&&(this.thenAllowAdd||this.rule.then.length>1);if(r){let r,s="inherit";if(i.action)switch(i.action){case"wait":r="timer",s=WAIT_COLOR;break;case"webhook":r="webhook",s=NOTIFICATION_COLOR;break;case"notification":r="push"===n||"push_localized"===n?"cellphone-message":"email",s=NOTIFICATION_COLOR;break;case"alarm":r="bell-outline",s=ALARM_COLOR;break;default:let c=l.getAssetDescriptor(n);r=l.getAssetDescriptorIcon(c),s=l.getAssetDescriptorColour(c)||s}a=o?t`
82
- <div id="type" style="--or-mwc-input-color: #${s}">
83
- <or-mwc-input type="${u.BUTTON}" .icon="${r||""}"></or-mwc-input>
84
- </div>
85
- `:t`
86
- <div id="type" style="--or-mwc-input-color: #${s}">
87
- ${p(t`<or-mwc-input type="${u.BUTTON}" .icon="${r||""}"></or-mwc-input>`,getActionTypesMenu(this.config,this.assetInfos),i.action,t=>this.setActionType(e,i,t))}
88
- </div>
89
- `}if(n)switch(n){case"wait":s=t`<span>WAIT NOT IMPLEMENTED</span>`;break;case"push":case"push_localized":case"email":case"email_localized":let h=n+"-notification";s=t`<or-rule-action-notification id="${h}" .rule="${this.rule}" .action="${i}" .actionType="${n}" .config="${this.config}" .assetInfos="${this.assetInfos}" .readonly="${this.readonly}"></or-rule-action-notification>`;break;case"webhook":s=t`<or-rule-action-webhook .rule="${this.rule}" .action="${i}" .actionType="${"webhook"}"></or-rule-action-webhook>`;break;case"alarm":s=t`<or-rule-action-alarm .rule="${this.rule}" .action="${i}" .actionType="${"alarm"}"></or-rule-action-alarm>`;break;default:s=t`<or-rule-action-attribute .action="${i}" .targetTypeMap="${this.targetTypeMap}" .config="${this.config}" .assetInfos="${this.assetInfos}" .assetProvider="${this.assetProvider}" .readonly="${this.readonly}"></or-rule-action-attribute>`}return t`
90
- <div class="rule-action">
91
- <div class="rule-action-wrapper">
92
- ${a}
93
- ${s}
94
- </div>
95
- ${c?t`
96
- <button class="button-clear" @click="${()=>this.removeAction(i)}"><or-icon icon="close-circle"></or-icon></input>
97
- `:""}
98
- </div>
99
- `}render(){let e=!this.readonly&&(this.thenAllowAdd||this.rule.then.length>1);return t`
100
- <div>
101
- <or-panel .heading="${c.t("then")}...">
102
- ${this.ruleRecurrenceTemplate(this.rule.recurrence,this.readonly)}
103
-
104
- ${!this.rule.then?"":this.rule.then.map(e=>this.ruleActionTemplate(this.rule.then,e,this.readonly))}
105
- ${e?t`
106
- <span class="add-button-wrapper">
107
- ${p(t`<or-mwc-input class="plus-button" type="${u.BUTTON}" icon="plus"
108
- .label="${c.t("rulesEditorAddAction")}"></or-mwc-input>`,getActionTypesMenu(this.config,this.assetInfos),void 0,e=>this.addAction(e))}
109
- </span>
110
- `:""}
111
- </or-panel>
112
- </div>
113
- `}getActionType(e){switch(e.action){case"wait":break;case"webhook":case"alarm":return e.action;case"notification":let t=e.notification&&e.notification.message&&e.notification.message.type?e.notification.message.type:e.action;if("localized"===t){let t=Object.values(e.notification.message.languages);if(t&&t.length>0)return t[0].type+"_localized"}return t;case"write-attribute":case"update-attribute":if(!e.target)return;if(e.target.matchedAssets)return a(e.target.matchedAssets);if(e.target.assets)return a(e.target.assets)}}setRecurrenceOption(e){switch(e){case RecurrenceOption.ALWAYS:this.rule.recurrence={mins:0};break;case RecurrenceOption.ONCE_PER_HOUR:this.rule.recurrence={mins:60};break;case RecurrenceOption.ONCE_PER_DAY:this.rule.recurrence={mins:1440};break;case RecurrenceOption.ONCE_PER_WEEK:this.rule.recurrence={mins:10080};break;case RecurrenceOption.ONCE:default:delete this.rule.recurrence}this.dispatchEvent(new s),this.requestUpdate()}setActionType(e,t,i){var o,r,n,a,l,c;switch(t.target=void 0,t.action){case"wait":t.millis=void 0;break;case"webhook":break;case"write-attribute":t.value=void 0,t.attributeName=void 0;break;case"notification":t.notification=void 0;break;case"alarm":t.alarm=void 0,t.assigneeId=void 0;break;case"update-attribute":t.value=void 0,t.attributeName=void 0,t.index=void 0,t.key=void 0,t.updateAction=void 0}if("wait"===i)t.action="wait";else if("alarm"==i)t.action="alarm",t.alarm={title:"%RULESET_NAME%",content:"%TRIGGER_ASSETS%",severity:"LOW",status:"OPEN"},t.assigneeId=void 0;else if("webhook"==i)t.action="webhook",t.webhook={httpMethod:"POST",payload:JSON.stringify({rule:"%RULESET_NAME%",assets:"%TRIGGER_ASSETS%"},null,4)};else if("email"===i)t.action="notification",t.notification={name:this.rule.name,message:{type:"email",subject:"%RULESET_NAME%",html:"%TRIGGER_ASSETS%"}};else if("push"===i)t.action="notification",t.notification={name:this.rule.name,message:{type:"push",title:"%RULESET_NAME%",body:"%TRIGGER_ASSETS%",action:{openInBrowser:!1}}};else if("email_localized"===i||"push_localized"===i){t.action="notification";let e=(null==(n=null==(r=null==(o=this.config)?void 0:o.notifications)?void 0:r[h.displayRealm])?void 0:n.defaultLanguage)||(null==(c=null==(l=null==(a=this.config)?void 0:a.notifications)?void 0:l.default)?void 0:c.defaultLanguage)||h.config.defaultLanguage||"en",s={};"email_localized"===i?s[e]={type:"email",subject:"%RULESET_NAME%",html:"%TRIGGER_ASSETS%"}:s[e]={type:"push",title:"%RULESET_NAME%",body:"%TRIGGER_ASSETS%",action:{openInBrowser:!1}},t.notification={name:this.rule.name,message:{type:"localized",defaultLanguage:e,languages:s}}}else t.action="write-attribute",t.target={matchedAssets:{types:[i]}};let u=e.indexOf(t);e[u]=Object.assign({},t),this.dispatchEvent(new s),this.requestUpdate()}removeAction(e){if(!this.rule||!this.rule.then||!e)return;let t=this.rule.then.indexOf(e);t>=0&&(this.rule.then.splice(t,1),this.dispatchEvent(new s),this.requestUpdate())}addAction(e,t){let i,o;if(!this.rule)return;let r={action:"write-attribute"},n=this.config&&this.config.json?this.config.json:void 0;t?(this.rule.otherwise||(this.rule.otherwise=[]),i=this.rule.otherwise,o=n&&n.otherwise?n.otherwise:void 0):(this.rule.then||(this.rule.then=[]),i=this.rule.then,o=n&&n.then?n.then:void 0),o&&(r=JSON.parse(JSON.stringify(o))),e&&this.setActionType(i,r,e),i.push(r),this.dispatchEvent(new s),this.requestUpdate()}};__decorate([r({type:Array,attribute:!1})],OrRuleThenOtherwise.prototype,"targetTypeMap",void 0),__decorate([r({type:Object,attribute:!1})],OrRuleThenOtherwise.prototype,"rule",void 0),__decorate([r({type:Boolean})],OrRuleThenOtherwise.prototype,"readonly",void 0),__decorate([r({type:Object,attribute:!1})],OrRuleThenOtherwise.prototype,"assetInfos",void 0),__decorate([r({type:Object})],OrRuleThenOtherwise.prototype,"assetProvider",void 0),OrRuleThenOtherwise=__decorate([o("or-rule-then-otherwise")],OrRuleThenOtherwise);
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 { buttonStyle } from "../style";
10
+ import "./or-rule-asset-query";
11
+ import { getAssetTypeFromQuery } from "../index";
12
+ import { OrRulesJsonRuleChangedEvent } from "./or-rule-json-viewer";
13
+ import { AssetModelUtil } from "@openremote/model";
14
+ import i18next from "i18next";
15
+ import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
16
+ import { getContentWithMenuTemplate } from "@openremote/or-mwc-components/or-mwc-menu";
17
+ import { manager, Util } from "@openremote/core";
18
+ import "./or-rule-action-attribute";
19
+ import "./or-rule-action-notification";
20
+ import "./or-rule-action-webhook";
21
+ import "./or-rule-action-alarm";
22
+ import { translate } from "@openremote/or-translate";
23
+ const NOTIFICATION_COLOR = "4B87EA";
24
+ const WAIT_COLOR = "EACC54";
25
+ const ALARM_COLOR = "FC2D2D";
26
+ function getActionTypesMenu(config, assetInfos) {
27
+ let addAssetTypes = true;
28
+ let addWait = true;
29
+ let addAlarm = true;
30
+ let addEmailNotification = true;
31
+ let addEmailLocalizedNotification = true;
32
+ let addPushNotification = true;
33
+ let addPushLocalizedNotification = true;
34
+ let addWebhook = true;
35
+ let multiLanguage = false;
36
+ if (config && config.controls && config.controls.allowedActionTypes) {
37
+ addAssetTypes = config.controls.allowedActionTypes.indexOf("attribute" /* ActionType.ATTRIBUTE */) >= 0;
38
+ addWait = config.controls.allowedActionTypes.indexOf("wait" /* ActionType.WAIT */) >= 0;
39
+ addAlarm = config.controls.allowedActionTypes.indexOf("alarm" /* ActionType.ALARM */) >= 0;
40
+ addEmailNotification = config.controls.allowedActionTypes.indexOf("email" /* ActionType.EMAIL */) >= 0;
41
+ addEmailLocalizedNotification = config.controls.allowedActionTypes.indexOf("email_localized" /* ActionType.EMAIL_LOCALIZED */) >= 0;
42
+ addPushNotification = config.controls.allowedActionTypes.indexOf("push" /* ActionType.PUSH_NOTIFICATION */) >= 0;
43
+ addPushLocalizedNotification = config.controls.allowedActionTypes.indexOf("push_localized" /* ActionType.PUSH_LOCALIZED */) >= 0;
44
+ addWebhook = config.controls.allowedActionTypes.indexOf("webhook" /* ActionType.WEBHOOK */) >= 0;
45
+ }
46
+ // If the RulesConfig has an entry for notifications, check if there are languages configured.
47
+ // When there are, new notifications will be a "multi-language notification", with a different modal form.
48
+ if (config === null || config === void 0 ? void 0 : config.notifications) {
49
+ multiLanguage = Object.entries(config.notifications).filter(x => (x[0] === manager.displayRealm || x[0] === "default") && x[1] !== undefined).length > 0;
50
+ }
51
+ const menu = [];
52
+ if (addAssetTypes && assetInfos) {
53
+ menu.push(...assetInfos.filter((assetInfo) => assetInfo.assetDescriptor.descriptorType !== "agent").map((assetTypeInfo) => {
54
+ const color = AssetModelUtil.getAssetDescriptorColour(assetTypeInfo);
55
+ const icon = AssetModelUtil.getAssetDescriptorIcon(assetTypeInfo);
56
+ const styleMap = color ? { "--or-icon-fill": "#" + color } : undefined;
57
+ return {
58
+ text: Util.getAssetTypeLabel(assetTypeInfo.assetDescriptor),
59
+ value: assetTypeInfo.assetDescriptor.name,
60
+ icon: icon ? icon : AssetModelUtil.getAssetDescriptorIcon("ThingAsset" /* WellknownAssets.THINGASSET */),
61
+ styleMap: styleMap
62
+ };
63
+ }));
64
+ }
65
+ menu.sort(Util.sortByString((listItem) => listItem === null || listItem === void 0 ? void 0 : listItem.value));
66
+ menu.push(null); // divider
67
+ if (addEmailNotification) {
68
+ menu.push({
69
+ text: i18next.t("email"),
70
+ icon: "email",
71
+ value: multiLanguage && addEmailLocalizedNotification ? "email_localized" /* ActionType.EMAIL_LOCALIZED */ : "email" /* ActionType.EMAIL */,
72
+ styleMap: { "--or-icon-fill": "#" + NOTIFICATION_COLOR }
73
+ });
74
+ }
75
+ if (addPushNotification) {
76
+ menu.push({
77
+ text: i18next.t("push-notification"),
78
+ icon: "cellphone-message",
79
+ value: multiLanguage && addPushLocalizedNotification ? "push_localized" /* ActionType.PUSH_LOCALIZED */ : "push" /* ActionType.PUSH_NOTIFICATION */,
80
+ styleMap: { "--or-icon-fill": "#" + NOTIFICATION_COLOR }
81
+ });
82
+ }
83
+ if (addWait) {
84
+ menu.push({
85
+ text: i18next.t("wait"),
86
+ icon: "timer",
87
+ value: "wait" /* ActionType.WAIT */,
88
+ styleMap: { "--or-icon-fill": "#" + WAIT_COLOR }
89
+ });
90
+ }
91
+ if (addAlarm) {
92
+ menu.push({
93
+ text: i18next.t("alarm."),
94
+ icon: "bell-outline",
95
+ value: "alarm" /* ActionType.ALARM */,
96
+ styleMap: { "--or-icon-fill": "#" + ALARM_COLOR }
97
+ });
98
+ }
99
+ if (addWebhook) {
100
+ menu.push({
101
+ text: i18next.t("webhook"),
102
+ icon: "webhook",
103
+ value: "webhook" /* ActionType.WEBHOOK */,
104
+ styleMap: { "--or-icon-fill": "#" + NOTIFICATION_COLOR }
105
+ });
106
+ }
107
+ return menu;
108
+ }
109
+ export var RecurrenceOption;
110
+ (function (RecurrenceOption) {
111
+ RecurrenceOption["ALWAYS"] = "always";
112
+ RecurrenceOption["ONCE"] = "once";
113
+ RecurrenceOption["ONCE_PER_HOUR"] = "oncePerHour";
114
+ RecurrenceOption["ONCE_PER_DAY"] = "oncePerDay";
115
+ RecurrenceOption["ONCE_PER_WEEK"] = "oncePerWeek";
116
+ })(RecurrenceOption || (RecurrenceOption = {}));
117
+ function getRecurrenceMenu(config) {
118
+ if (config && config.controls && config.controls.allowedRecurrenceOptions) {
119
+ return config.controls.allowedRecurrenceOptions.map((value) => {
120
+ return {
121
+ text: i18next.t(value),
122
+ value: value
123
+ };
124
+ });
125
+ }
126
+ return Object.values(RecurrenceOption).map((value) => {
127
+ return {
128
+ text: i18next.t(value),
129
+ value: value
130
+ };
131
+ });
132
+ }
133
+ // language=CSS
134
+ const style = css `
135
+
136
+ :host {
137
+ display: flex;
138
+ width: 100%;
139
+ flex-direction: column;
140
+ }
141
+
142
+ ${buttonStyle}
143
+
144
+ .rule-action {
145
+ display: flex;
146
+ margin: 10px 0;
147
+ }
148
+
149
+ .rule-action-wrapper {
150
+ flex-grow: 1;
151
+ display: flex;
152
+ align-items: baseline;
153
+ }
154
+
155
+ .rule-action > button {
156
+ flex-grow: 0;
157
+ }
158
+
159
+ .rule-action:hover .button-clear {
160
+ visibility: visible;
161
+ }
162
+
163
+ or-panel:hover .remove-button.button-clear {
164
+ visibility: visible;
165
+ }
166
+
167
+ or-panel {
168
+ position: relative;
169
+ margin: 10px 10px 20px 10px;
170
+ }
171
+
172
+ #type-selector {
173
+ margin-top: 10px;
174
+ }
175
+
176
+ .add-button-wrapper {
177
+ display: flex;
178
+ align-items: center;
179
+ white-space: nowrap;
180
+ }
181
+
182
+ .add-button-wrapper > * {
183
+ margin-right: 6px;
184
+ }
185
+
186
+ .add-button-wrapper or-mwc-menu {
187
+ text-transform: capitalize;
188
+ }
189
+
190
+ #type {
191
+ white-space: nowrap;
192
+ margin: 4px 3px auto 0;
193
+ text-transform: capitalize;
194
+ }
195
+
196
+ .rule-recurrence {
197
+ position: absolute;
198
+ top: 5px;
199
+ right: 0;
200
+ }
201
+
202
+ `;
203
+ let OrRuleThenOtherwise = class OrRuleThenOtherwise extends translate(i18next)(LitElement) {
204
+ static get styles() {
205
+ return style;
206
+ }
207
+ get thenAllowAdd() {
208
+ return !this.config || !this.config.controls || this.config.controls.hideThenAddAction !== true;
209
+ }
210
+ ruleRecurrenceTemplate(reset, readonly) {
211
+ let recurrenceTemplate = ``;
212
+ const buttonColor = "inherit";
213
+ let value = RecurrenceOption.ONCE;
214
+ if (reset) {
215
+ if (reset.mins === undefined || reset.mins === null) {
216
+ value = RecurrenceOption.ONCE;
217
+ }
218
+ else if (reset.mins === 0) {
219
+ value = RecurrenceOption.ALWAYS;
220
+ }
221
+ else if (reset.mins === 60) {
222
+ value = RecurrenceOption.ONCE_PER_HOUR;
223
+ }
224
+ else if (reset.mins === 1440) {
225
+ value = RecurrenceOption.ONCE_PER_DAY;
226
+ }
227
+ else if (reset.mins === 10080) {
228
+ value = RecurrenceOption.ONCE_PER_WEEK;
229
+ }
230
+ }
231
+ if (readonly) {
232
+ recurrenceTemplate = html `
233
+ <div style="--or-mwc-input-color: ${buttonColor}; margin-right: 6px;">
234
+ <or-mwc-input .type="${InputType.BUTTON}" label="${value}"></or-mwc-input>
235
+ </div>
236
+ `;
237
+ }
238
+ else {
239
+ recurrenceTemplate = html `
240
+ <div style="--or-mwc-input-color: ${buttonColor}; margin-right: 6px;">
241
+ ${getContentWithMenuTemplate(html `<or-mwc-input .type="${InputType.BUTTON}" label="${value}"></or-mwc-input>`, getRecurrenceMenu(this.config), value, (value) => this.setRecurrenceOption(value))}
242
+ </div>
243
+ `;
244
+ }
245
+ return html `
246
+ <div class="rule-recurrence">
247
+ ${recurrenceTemplate}
248
+ </div>
249
+ `;
250
+ }
251
+ ruleActionTemplate(actions, action, readonly) {
252
+ const showTypeSelect = !this.config || !this.config.controls || this.config.controls.hideActionTypeOptions !== true;
253
+ const type = this.getActionType(action);
254
+ if (!type && !showTypeSelect) {
255
+ return html `<span>INVALID CONFIG - NO TYPE SPECIFIED AND TYPE SELECTOR DISABLED</span>`;
256
+ }
257
+ let typeTemplate = ``;
258
+ let template = ``;
259
+ const thenAllowRemove = !this.readonly && (this.thenAllowAdd || this.rule.then.length > 1);
260
+ if (showTypeSelect) {
261
+ let buttonIcon;
262
+ let buttonColor = "inherit";
263
+ if (action.action) {
264
+ switch (action.action) {
265
+ case "wait" /* ActionType.WAIT */:
266
+ buttonIcon = "timer";
267
+ buttonColor = WAIT_COLOR;
268
+ break;
269
+ case "webhook" /* ActionType.WEBHOOK */:
270
+ buttonIcon = "webhook";
271
+ buttonColor = NOTIFICATION_COLOR;
272
+ break;
273
+ case "notification":
274
+ action = action;
275
+ if (type === "push" /* ActionType.PUSH_NOTIFICATION */ || type === "push_localized" /* ActionType.PUSH_LOCALIZED */) {
276
+ buttonIcon = "cellphone-message";
277
+ buttonColor = NOTIFICATION_COLOR;
278
+ }
279
+ else {
280
+ buttonIcon = "email";
281
+ buttonColor = NOTIFICATION_COLOR;
282
+ }
283
+ break;
284
+ case "alarm" /* ActionType.ALARM */:
285
+ buttonIcon = "bell-outline";
286
+ buttonColor = ALARM_COLOR;
287
+ break;
288
+ default:
289
+ const ad = AssetModelUtil.getAssetDescriptor(type);
290
+ buttonIcon = AssetModelUtil.getAssetDescriptorIcon(ad);
291
+ buttonColor = AssetModelUtil.getAssetDescriptorColour(ad) || buttonColor;
292
+ break;
293
+ }
294
+ }
295
+ if (readonly) {
296
+ typeTemplate = html `
297
+ <div id="type" style="--or-mwc-input-color: #${buttonColor}">
298
+ <or-mwc-input type="${InputType.BUTTON}" .icon="${buttonIcon || ""}"></or-mwc-input>
299
+ </div>
300
+ `;
301
+ }
302
+ else {
303
+ typeTemplate = html `
304
+ <div id="type" style="--or-mwc-input-color: #${buttonColor}">
305
+ ${getContentWithMenuTemplate(html `<or-mwc-input type="${InputType.BUTTON}" .icon="${buttonIcon || ""}"></or-mwc-input>`, getActionTypesMenu(this.config, this.assetInfos), action.action, (value) => this.setActionType(actions, action, value))}
306
+ </div>
307
+ `;
308
+ }
309
+ }
310
+ if (type) {
311
+ switch (type) {
312
+ case "wait" /* ActionType.WAIT */:
313
+ template = html `<span>WAIT NOT IMPLEMENTED</span>`;
314
+ break;
315
+ case "push" /* ActionType.PUSH_NOTIFICATION */:
316
+ case "push_localized" /* ActionType.PUSH_LOCALIZED */:
317
+ case "email" /* ActionType.EMAIL */:
318
+ case "email_localized" /* ActionType.EMAIL_LOCALIZED */:
319
+ const id = type + "-notification";
320
+ template = html `<or-rule-action-notification id="${id}" .rule="${this.rule}" .action="${action}" .actionType="${type}" .config="${this.config}" .assetInfos="${this.assetInfos}" .readonly="${this.readonly}"></or-rule-action-notification>`;
321
+ break;
322
+ case "webhook" /* ActionType.WEBHOOK */:
323
+ template = html `<or-rule-action-webhook .rule="${this.rule}" .action="${action}" .actionType="${"webhook" /* ActionType.WEBHOOK */}"></or-rule-action-webhook>`;
324
+ break;
325
+ case "alarm" /* ActionType.ALARM */:
326
+ template = html `<or-rule-action-alarm .rule="${this.rule}" .action="${action}" .actionType="${"alarm" /* ActionType.ALARM */}"></or-rule-action-alarm>`;
327
+ break;
328
+ default:
329
+ template = html `<or-rule-action-attribute .action="${action}" .targetTypeMap="${this.targetTypeMap}" .config="${this.config}" .assetInfos="${this.assetInfos}" .assetProvider="${this.assetProvider}" .readonly="${this.readonly}"></or-rule-action-attribute>`;
330
+ break;
331
+ }
332
+ }
333
+ return html `
334
+ <div class="rule-action">
335
+ <div class="rule-action-wrapper">
336
+ ${typeTemplate}
337
+ ${template}
338
+ </div>
339
+ ${thenAllowRemove ? html `
340
+ <button class="button-clear" @click="${() => this.removeAction(action)}"><or-icon icon="close-circle"></or-icon></input>
341
+ ` : ``}
342
+ </div>
343
+ `;
344
+ }
345
+ render() {
346
+ const thenAllowAdd = !this.readonly && (this.thenAllowAdd || this.rule.then.length > 1);
347
+ return html `
348
+ <div>
349
+ <or-panel .heading="${i18next.t("then")}...">
350
+ ${this.ruleRecurrenceTemplate(this.rule.recurrence, this.readonly)}
351
+
352
+ ${!this.rule.then ? `` : this.rule.then.map((action) => this.ruleActionTemplate(this.rule.then, action, this.readonly))}
353
+ ${thenAllowAdd ? html `
354
+ <span class="add-button-wrapper">
355
+ ${getContentWithMenuTemplate(html `<or-mwc-input class="plus-button" type="${InputType.BUTTON}" icon="plus"
356
+ .label="${i18next.t("rulesEditorAddAction")}"></or-mwc-input>`, getActionTypesMenu(this.config, this.assetInfos), undefined, (value) => this.addAction(value))}
357
+ </span>
358
+ ` : ``}
359
+ </or-panel>
360
+ </div>
361
+ `;
362
+ }
363
+ getActionType(action) {
364
+ switch (action.action) {
365
+ case "wait":
366
+ break;
367
+ case "webhook":
368
+ return action.action;
369
+ break;
370
+ case "notification":
371
+ const type = action.notification && action.notification.message && action.notification.message.type ? action.notification.message.type : action.action;
372
+ if (type === "localized") {
373
+ const messages = Object.values(action.notification.message.languages);
374
+ if (messages && messages.length > 0) {
375
+ return messages[0].type + "_localized";
376
+ }
377
+ }
378
+ return type;
379
+ break;
380
+ case "alarm":
381
+ return action.action;
382
+ break;
383
+ case "write-attribute":
384
+ case "update-attribute":
385
+ if (!action.target) {
386
+ return;
387
+ }
388
+ if (action.target.matchedAssets) {
389
+ return getAssetTypeFromQuery(action.target.matchedAssets);
390
+ }
391
+ if (action.target.assets) {
392
+ return getAssetTypeFromQuery(action.target.assets);
393
+ }
394
+ break;
395
+ }
396
+ }
397
+ setRecurrenceOption(value) {
398
+ switch (value) {
399
+ case RecurrenceOption.ALWAYS:
400
+ this.rule.recurrence = { mins: 0 };
401
+ break;
402
+ case RecurrenceOption.ONCE_PER_HOUR:
403
+ this.rule.recurrence = { mins: 60 };
404
+ break;
405
+ case RecurrenceOption.ONCE_PER_DAY:
406
+ this.rule.recurrence = { mins: 1440 };
407
+ break;
408
+ case RecurrenceOption.ONCE_PER_WEEK:
409
+ this.rule.recurrence = { mins: 10080 };
410
+ break;
411
+ case RecurrenceOption.ONCE:
412
+ default:
413
+ delete this.rule.recurrence;
414
+ break;
415
+ }
416
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
417
+ this.requestUpdate();
418
+ }
419
+ setActionType(actions, action, value) {
420
+ var _a, _b, _c, _d, _e, _f;
421
+ action.target = undefined;
422
+ switch (action.action) {
423
+ case "wait":
424
+ action.millis = undefined;
425
+ break;
426
+ case "webhook":
427
+ break;
428
+ case "write-attribute":
429
+ action.value = undefined;
430
+ action.attributeName = undefined;
431
+ break;
432
+ case "notification":
433
+ action.notification = undefined;
434
+ break;
435
+ case "alarm":
436
+ action.alarm = undefined;
437
+ action.assigneeId = undefined;
438
+ break;
439
+ case "update-attribute":
440
+ action.value = undefined;
441
+ action.attributeName = undefined;
442
+ action.index = undefined;
443
+ action.key = undefined;
444
+ action.updateAction = undefined;
445
+ break;
446
+ }
447
+ if (value === "wait" /* ActionType.WAIT */) {
448
+ action.action = "wait";
449
+ }
450
+ else if (value == "alarm" /* ActionType.ALARM */) {
451
+ action = action;
452
+ action.action = "alarm";
453
+ action.alarm = {
454
+ title: "%RULESET_NAME%",
455
+ content: "%TRIGGER_ASSETS%",
456
+ severity: "LOW" /* AlarmSeverity.LOW */,
457
+ status: "OPEN" /* AlarmStatus.OPEN */
458
+ };
459
+ action.assigneeId = undefined;
460
+ }
461
+ else if (value == "webhook" /* ActionType.WEBHOOK */) {
462
+ action = action;
463
+ action.action = "webhook";
464
+ action.webhook = {
465
+ httpMethod: "POST" /* HTTPMethod.POST */,
466
+ payload: JSON.stringify({
467
+ rule: "%RULESET_NAME%",
468
+ assets: "%TRIGGER_ASSETS%"
469
+ }, null, 4)
470
+ };
471
+ }
472
+ else if (value === "email" /* ActionType.EMAIL */) {
473
+ action = action;
474
+ action.action = "notification";
475
+ action.notification = {
476
+ name: this.rule.name,
477
+ message: {
478
+ type: "email",
479
+ subject: "%RULESET_NAME%",
480
+ html: "%TRIGGER_ASSETS%"
481
+ }
482
+ };
483
+ }
484
+ else if (value === "push" /* ActionType.PUSH_NOTIFICATION */) {
485
+ action = action;
486
+ action.action = "notification";
487
+ action.notification = {
488
+ name: this.rule.name,
489
+ message: {
490
+ type: "push",
491
+ title: "%RULESET_NAME%",
492
+ body: "%TRIGGER_ASSETS%",
493
+ action: {
494
+ openInBrowser: false
495
+ }
496
+ }
497
+ };
498
+ }
499
+ else if (value === "email_localized" /* ActionType.EMAIL_LOCALIZED */ || value === "push_localized" /* ActionType.PUSH_LOCALIZED */) {
500
+ action = action;
501
+ action.action = "notification";
502
+ 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 || "en";
503
+ const languages = {};
504
+ if (value === "email_localized" /* ActionType.EMAIL_LOCALIZED */) {
505
+ languages[locale] = {
506
+ type: "email",
507
+ subject: "%RULESET_NAME%",
508
+ html: "%TRIGGER_ASSETS%"
509
+ };
510
+ }
511
+ else {
512
+ languages[locale] = {
513
+ type: "push",
514
+ title: "%RULESET_NAME%",
515
+ body: "%TRIGGER_ASSETS%",
516
+ action: {
517
+ openInBrowser: false
518
+ }
519
+ };
520
+ }
521
+ action.notification = {
522
+ name: this.rule.name,
523
+ message: {
524
+ type: "localized",
525
+ defaultLanguage: locale,
526
+ languages: languages
527
+ }
528
+ };
529
+ }
530
+ else {
531
+ action.action = "write-attribute";
532
+ action.target = {
533
+ matchedAssets: {
534
+ types: [
535
+ value
536
+ ]
537
+ }
538
+ };
539
+ }
540
+ const index = actions.indexOf(action);
541
+ actions[index] = Object.assign({}, action);
542
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
543
+ this.requestUpdate();
544
+ }
545
+ removeAction(action) {
546
+ if (!this.rule || !this.rule.then || !action) {
547
+ return;
548
+ }
549
+ const index = this.rule.then.indexOf(action);
550
+ if (index >= 0) {
551
+ this.rule.then.splice(index, 1);
552
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
553
+ this.requestUpdate();
554
+ }
555
+ }
556
+ addAction(type, otherwise) {
557
+ if (!this.rule) {
558
+ return;
559
+ }
560
+ let actionArray;
561
+ let newAction = {
562
+ action: "write-attribute"
563
+ };
564
+ let template;
565
+ const templateConfig = this.config && this.config.json ? this.config.json : undefined;
566
+ if (!otherwise) {
567
+ if (!this.rule.then) {
568
+ this.rule.then = [];
569
+ }
570
+ actionArray = this.rule.then;
571
+ template = templateConfig && templateConfig.then ? templateConfig.then : undefined;
572
+ }
573
+ else {
574
+ if (!this.rule.otherwise) {
575
+ this.rule.otherwise = [];
576
+ }
577
+ actionArray = this.rule.otherwise;
578
+ template = templateConfig && templateConfig.otherwise ? templateConfig.otherwise : undefined;
579
+ }
580
+ if (template) {
581
+ newAction = JSON.parse(JSON.stringify(template));
582
+ }
583
+ if (type) {
584
+ this.setActionType(actionArray, newAction, type);
585
+ }
586
+ actionArray.push(newAction);
587
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
588
+ this.requestUpdate();
589
+ }
590
+ };
591
+ __decorate([
592
+ property({ type: Array, attribute: false })
593
+ ], OrRuleThenOtherwise.prototype, "targetTypeMap", void 0);
594
+ __decorate([
595
+ property({ type: Object, attribute: false })
596
+ ], OrRuleThenOtherwise.prototype, "rule", void 0);
597
+ __decorate([
598
+ property({ type: Boolean })
599
+ ], OrRuleThenOtherwise.prototype, "readonly", void 0);
600
+ __decorate([
601
+ property({ type: Object, attribute: false })
602
+ ], OrRuleThenOtherwise.prototype, "assetInfos", void 0);
603
+ __decorate([
604
+ property({ type: Object })
605
+ ], OrRuleThenOtherwise.prototype, "assetProvider", void 0);
606
+ OrRuleThenOtherwise = __decorate([
607
+ customElement("or-rule-then-otherwise")
608
+ ], OrRuleThenOtherwise);
609
+ //# sourceMappingURL=or-rule-then-otherwise.js.map