100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Add validation to push notification
Robin Dekkersc85b36ebb087
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.jsonindex c1a27b728..318cc932d 100644--- a/deployment/manager/shared/locales/en/or.json+++ b/deployment/manager/shared/locales/en/or.json@@ -182,7 +182,7 @@"email": "Email","push-notification": "Push notification","subject": "subject",- "openWebsiteUrl": "Website to be opend",+ "openWebsiteUrl": "Website to be opened","openInBrowser": "Open in browser (for external websites)","buttonTextConfirm": "Text for action button","buttonTextDecline": "Text for decline button",diff --git a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.tsindex 3e826d4d4..45ce79b5a 100644--- a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts+++ b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts@@ -37,7 +37,7 @@ export class OrRuleFormPushNotification extends translate(i18next)(LitElement) {const buttons = message && message.buttons ? message.buttons : [];return html`- <div style="display:grid">+ <form style="display:grid"><or-input value="${title}"@or-input-changed="${(e: OrInputChangedEvent) => this.setActionNotificationName(e.detail.value, "title")}".label="${i18next.t("subject")}"@@ -58,7 +58,7 @@ export class OrRuleFormPushNotification extends translate(i18next)(LitElement) {requiredplaceholder=" "></or-input>- <or-input value="${buttons && buttons[0] && buttons[0].action && buttons[0].action.openInBrowser ? buttons[0].action.openInBrowser : ""}"+ <or-input value="${buttons && buttons[0] && buttons[0].action && buttons[0].action.openInBrowser ? buttons[0].action.openInBrowser : true}"@or-input-changed="${(e: OrInputChangedEvent) => this.setActionNotificationName(e.detail.value, "buttons.0.action.openInBrowser")}".label="${i18next.t("openInBrowser")}"type="${InputType.SWITCH}"@@ -77,7 +77,7 @@ export class OrRuleFormPushNotification extends translate(i18next)(LitElement) {type="${InputType.TEXT}"requiredplaceholder=" "></or-input>- </div>+ </form>`}diff --git a/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts b/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.tsindex 47f8b9988..9edd68a21 100644--- a/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts+++ b/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts@@ -19,7 +19,7 @@ export class OrRuleNotificationModal extends translate(i18next)(LitElement) {@property({type: String})public title = "message";-+@property({type: Object})public query?: AssetQuery;@@ -63,14 +63,46 @@ export class OrRuleNotificationModal extends translate(i18next)(LitElement) {{actionName: "cancel",content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-input>`,- action: () => {- // Nothing to do here+ action: (dialog) => {+}},{- actionName: "ok",+ actionName: "none",content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("ok")}"></or-input>`,- action: () => {+ action: (dialog) => {+ dialog.open()+ if (dialog.shadowRoot && dialog.shadowRoot.querySelector('or-rule-form-push-notification')) {+ const pushNotification = dialog.shadowRoot.querySelector('or-rule-form-push-notification');+ if(pushNotification && pushNotification.shadowRoot) {+ const form = pushNotification.shadowRoot.querySelector('form')+ if(form) {+ const inputs = form.querySelectorAll('or-input')+ const elements = Array.prototype.slice.call(inputs);++ const valid = elements.every((element) => {+ if(element.shadowRoot) {+ const input = element.shadowRoot.querySelector('input, textarea, select') as any++ if(input && input.checkValidity()) {+ return true+ } else {+ element._mdcComponent.valid = false;+ element._mdcComponent.helperTextContent = 'required';+ return false;+ }+ } else {+ return false;+ }+ })+ if(valid) {+ dialog.close()+ } else {+ }+ }++ }+ }}}];@@ -85,7 +117,7 @@ export class OrRuleNotificationModal extends translate(i18next)(LitElement) {return html`<or-input .type="${InputType.BUTTON}" .label="${i18next.t("message")}" @click="${notificationPickerModalOpen}"></or-input>- <or-mwc-dialog id="notification-modal" dialogTitle="${this.title}" .dialogActions="${notificationPickerModalActions}"></or-mwc-dialog>+ <or-mwc-dialog id="notification-modal" dialogTitle="${this.title}" .dialogActions="${notificationPickerModalActions}"></or-mwc-dialog><slot class="notification-form-slot"></slot>`}diff --git a/ui/component/or-rules/src/json-viewer/modals/or-rule-radial-modal.ts b/ui/component/or-rules/src/json-viewer/modals/or-rule-radial-modal.tsindex c0343bded..31d6a6ab1 100644--- a/ui/component/or-rules/src/json-viewer/modals/or-rule-radial-modal.ts+++ b/ui/component/or-rules/src/json-viewer/modals/or-rule-radial-modal.ts@@ -90,7 +90,7 @@ export class OrRuleRadialModal extends translate(i18next)(LitElement) {<label>Straal (minimaal 100m)</label>- <input @change="${(e:any) => this.setValuePredicateProperty("radius", parseInt(e.target.value))}" style="max-width: calc(50% - 30px);" required placeholder=" " min="50" type="number" .value="${value && value.radius ? value.radius : null}" />+ <input @change="${(e:any) => this.setValuePredicateProperty("radius", parseInt(e.target.value))}" style="max-width: calc(50% - 30px);" required placeholder=" " min="100" type="number" .value="${value && value.radius ? value.radius : null}" /></div>`;}}diff --git a/ui/component/or-survey/src/index.ts b/ui/component/or-survey/src/index.tsindex f0c47c27a..9ff0153e0 100644--- a/ui/component/or-survey/src/index.ts+++ b/ui/component/or-survey/src/index.ts@@ -438,7 +438,7 @@ class OrSurvey extends LitElement {console.error("Error: " + reason);});- if(localStorage.getItem('survey'+surveyId)){+ if(localStorage.getItem('survey'+surveyId) && this.saveanswers){this.hasSubmission = true;return;}