Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Added buttons part to push notification composer. Fixed data part.

Michael Rademaker416a21c7ec08
diff --git a/client/src/main/java/org/openremote/app/client/assets/attributes/ValueFilterArrayMapper.java b/client/src/main/java/org/openremote/app/client/assets/attributes/ValueFilterArrayMapper.java
index f1f384b8c..f8a9479b0 100644
--- a/client/src/main/java/org/openremote/app/client/assets/attributes/ValueFilterArrayMapper.java
+++ b/client/src/main/java/org/openremote/app/client/assets/attributes/ValueFilterArrayMapper.java
@@ -22,9 +22,6 @@ package org.openremote.app.client.assets.attributes;
import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
import org.openremote.app.client.interop.jackson.DefaultJsonMixin;
-import org.openremote.app.client.rest.EntityReader;
-import org.openremote.app.client.rest.EntityWriter;
-import org.openremote.model.attribute.AttributeLink;
import org.openremote.model.value.ValueFilter;
@JsonMixIns({@JsonMixIns.JsonMixIn(target = ValueFilter.class, mixIn = DefaultJsonMixin.class)})
diff --git a/client/src/main/java/org/openremote/app/client/i18n/ManagerMessages.java b/client/src/main/java/org/openremote/app/client/i18n/ManagerMessages.java
index f849c23ea..03588f3d8 100644
--- a/client/src/main/java/org/openremote/app/client/i18n/ManagerMessages.java
+++ b/client/src/main/java/org/openremote/app/client/i18n/ManagerMessages.java
@@ -524,6 +524,8 @@ public interface ManagerMessages extends Messages {
String action();
+ String buttons();
+
String notificationsDeleted();
String refresh();
diff --git a/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java
index 4ebabdced..07e7dacb4 100644
--- a/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java
@@ -19,6 +19,7 @@
*/
package org.openremote.app.client.notifications;
+import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.IsWidget;
@@ -30,14 +31,13 @@ import org.openremote.model.interop.Consumer;
import org.openremote.model.notification.*;
import org.openremote.model.util.Pair;
import org.openremote.model.util.TextUtil;
+import org.openremote.model.value.ArrayValue;
import org.openremote.model.value.Value;
import org.openremote.model.value.ValueType;
+import org.openremote.model.value.Values;
import javax.inject.Inject;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Locale;
-import java.util.Optional;
+import java.util.*;
import static org.openremote.app.client.widget.ValueEditors.createValueEditor;
@@ -81,6 +81,8 @@ public class NotificationEditorImpl implements NotificationEditor {
protected Runnable onSend;
protected Runnable onClose;
protected AbstractNotificationMessage message;
+ PushNotificationButtonArrayMapper pushNotificationButtonArrayMapper = GWT.create(PushNotificationButtonArrayMapper.class);
+
@Inject
public NotificationEditorImpl(WidgetStyle widgetStyle,
@@ -343,18 +345,40 @@ public class NotificationEditorImpl implements NotificationEditor {
createActionEditor(actionField, null, message.getAction(), null, this::onMessageActionChanged);
messagePanel.add(actionGroup);
+ FormGroup buttonsGroup = new FormGroup();
+ FormLabel buttonsLabel = new FormLabel(managerMessages.buttons());
+ buttonsGroup.setFormLabel(buttonsLabel);
+ FormField buttonsField = new FormField();
+ buttonsGroup.setFormField(buttonsField);
+ Optional<Long> timestamp = Optional.empty();
+ ArrayValue buttonsArray = null;
+
+ if (message.getButtons() != null && message.getButtons().size() > 0) {
+ List<PushNotificationButton> buttonList = message.getButtons();
+ buttonsArray = Values.parse(pushNotificationButtonArrayMapper.write(buttonList)).flatMap(Values::getArray).orElse(null);
+ }
+
+ buttonsField.add(ValueEditors.createArrayEditor(
+ buttonsArray,
+ arrayValue -> {
+ message.setButtons(pushNotificationButtonArrayMapper.read(arrayValue.toJson()));
+ },
+ timestamp,
+ false,
+ widgetStyle,
+ managerMessages
+ ));
+ messagePanel.add(buttonsGroup);
+
FormGroup dataGroup = new FormGroup();
FormLabel dataLabel = new FormLabel(managerMessages.notificationData());
dataGroup.setFormLabel(dataLabel);
FormField dataField = new FormField();
dataGroup.setFormField(dataField);
messagePanel.add(dataGroup);
- Optional<Long> timestamp = Optional.empty();
dataField.add(ValueEditors.createObjectEditor(
message.getData(),
- objectValue -> {
-
- },
+ message::setData,
timestamp,
false,
widgetStyle,
diff --git a/client/src/main/java/org/openremote/app/client/notifications/NotificationMapper.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationMapper.java
index 87e4ba430..e60cfe5a8 100644
--- a/client/src/main/java/org/openremote/app/client/notifications/NotificationMapper.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationMapper.java
@@ -24,7 +24,6 @@ import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
import org.openremote.app.client.interop.jackson.DefaultJsonMixin;
import org.openremote.app.client.rest.EntityWriter;
import org.openremote.model.notification.Notification;
-import org.openremote.model.notification.PushNotificationMessage;
@JsonMixIns({@JsonMixIns.JsonMixIn(target = Notification.class, mixIn = DefaultJsonMixin.class)})
public interface NotificationMapper
diff --git a/client/src/main/java/org/openremote/app/client/notifications/PushNotificationButtonArrayMapper.java b/client/src/main/java/org/openremote/app/client/notifications/PushNotificationButtonArrayMapper.java
new file mode 100644
index 000000000..c05f65521
--- /dev/null
+++ b/client/src/main/java/org/openremote/app/client/notifications/PushNotificationButtonArrayMapper.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.app.client.notifications;
+
+import com.github.nmorel.gwtjackson.client.ObjectMapper;
+import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
+import org.openremote.app.client.interop.jackson.DefaultJsonMixin;
+import org.openremote.app.client.rest.EntityWriter;
+import org.openremote.model.notification.PushNotificationButton;
+
+import java.util.List;
+
+@JsonMixIns({@JsonMixIns.JsonMixIn(target = PushNotificationButton.class, mixIn = DefaultJsonMixin.class)})
+public interface PushNotificationButtonArrayMapper
+ extends ObjectMapper<List<PushNotificationButton>>,
+ EntityWriter<List<PushNotificationButton>> {
+}
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/notifications/SentNotificationArrayMapper.java b/client/src/main/java/org/openremote/app/client/notifications/SentNotificationArrayMapper.java
index 4bf6cae55..a56006fcc 100644
--- a/client/src/main/java/org/openremote/app/client/notifications/SentNotificationArrayMapper.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/SentNotificationArrayMapper.java
@@ -23,8 +23,6 @@ import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
import org.openremote.app.client.interop.jackson.DefaultJsonMixin;
import org.openremote.app.client.rest.EntityReader;
-import org.openremote.model.notification.Notification;
-import org.openremote.model.notification.PushNotificationMessage;
import org.openremote.model.notification.SentNotification;
@JsonMixIns({@JsonMixIns.JsonMixIn(target = SentNotification.class, mixIn = DefaultJsonMixin.class)})
diff --git a/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java b/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java
index be2dc51e8..b38017faa 100644
--- a/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java
+++ b/client/src/main/java/org/openremote/app/client/widget/AttributeLinkEditor.java
@@ -29,7 +29,6 @@ import org.openremote.app.client.assets.attributes.MetaEditor;
import org.openremote.app.client.assets.attributes.ValueFilterArrayMapper;
import org.openremote.model.ValidationFailure;
import org.openremote.model.asset.AssetAttribute;
-import org.openremote.model.attribute.MetaItemType;
import org.openremote.model.attribute.*;
import org.openremote.model.interop.Consumer;
import org.openremote.model.util.EnumUtil;
@@ -41,7 +40,6 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static org.openremote.app.client.widget.ValueEditors.createArrayEditor;
-import static org.openremote.app.client.widget.ValueEditors.createObjectEditor;
public class AttributeLinkEditor extends FlowPanel {
diff --git a/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties b/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
index 860c83b54..e7eb9dea8 100644
--- a/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
+++ b/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
@@ -463,6 +463,7 @@ notificationDeleted=Notification deleted: {0}
deleteNotification=Delete notification
status=Status
action=Action
+buttons=Buttons
notificationsDeleted=Notifications deleted.
refresh=Refresh
deleteNotifications=Delete all notifications
diff --git a/model/src/main/java/org/openremote/model/notification/PushNotificationMessage.java b/model/src/main/java/org/openremote/model/notification/PushNotificationMessage.java
index 848c098fe..ddd94cbd7 100644
--- a/model/src/main/java/org/openremote/model/notification/PushNotificationMessage.java
+++ b/model/src/main/java/org/openremote/model/notification/PushNotificationMessage.java
@@ -21,13 +21,11 @@ package org.openremote.model.notification;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
-import org.openremote.model.util.TextUtil;
import org.openremote.model.value.ArrayValue;
import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Values;
import java.util.List;
-import java.util.Map;
import static org.openremote.model.util.TextUtil.isNullOrEmpty;