Skip to content

armgit / core

Public Imported from GitHub
0

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

Notification manager console work

Rich Turner0ee82ba1ac65
diff --git a/client/src/main/java/org/openremote/app/client/AppSecurity.java b/client/src/main/java/org/openremote/app/client/AppSecurity.java
index fe7ca0a97..a2d2d80d2 100644
--- a/client/src/main/java/org/openremote/app/client/AppSecurity.java
+++ b/client/src/main/java/org/openremote/app/client/AppSecurity.java
@@ -4,7 +4,7 @@ import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import org.openremote.model.http.RequestParams;
-import org.openremote.model.interop.Consumer;
+import java.util.function.Consumer;
import org.openremote.model.interop.Runnable;
/**
diff --git a/client/src/main/java/org/openremote/app/client/ManagerActivityMapper.java b/client/src/main/java/org/openremote/app/client/ManagerActivityMapper.java
index 2e8669ae7..64f969289 100644
--- a/client/src/main/java/org/openremote/app/client/ManagerActivityMapper.java
+++ b/client/src/main/java/org/openremote/app/client/ManagerActivityMapper.java
@@ -33,8 +33,6 @@ import org.openremote.app.client.admin.users.AdminUsersActivity;
import org.openremote.app.client.admin.users.AdminUsersPlace;
import org.openremote.app.client.admin.users.edit.AdminUserEditActivity;
import org.openremote.app.client.admin.users.edit.AdminUserEditPlace;
-import org.openremote.app.client.admin.users.notifications.AdminUserNotificationsActivity;
-import org.openremote.app.client.admin.users.notifications.AdminUserNotificationsPlace;
import org.openremote.app.client.apps.ConsoleAppsActivity;
import org.openremote.app.client.apps.ConsoleAppsPlace;
import org.openremote.app.client.assets.AssetsDashboardActivity;
@@ -51,6 +49,8 @@ import org.openremote.app.client.map.MapPlace;
import org.openremote.app.client.mvp.AppActivity;
import org.openremote.app.client.mvp.AppActivityMapper;
import org.openremote.app.client.mvp.RoleRequiredException;
+import org.openremote.app.client.notifications.NotificationsActivity;
+import org.openremote.app.client.notifications.NotificationsPlace;
import org.openremote.app.client.rules.asset.AssetRulesEditorActivity;
import org.openremote.app.client.rules.asset.AssetRulesEditorPlace;
import org.openremote.app.client.rules.asset.AssetRulesListActivity;
@@ -89,8 +89,8 @@ public class ManagerActivityMapper implements AppActivityMapper {
protected final Provider<AdminTenantActivity> adminTenantActivityProvider;
protected final Provider<AdminUsersActivity> adminUsersActivityProvider;
protected final Provider<AdminUserEditActivity> adminUserActivityProvider;
- protected final Provider<AdminUserNotificationsActivity> adminUserNotificationsActivityProvider;
protected final Provider<UserAccountActivity> userProfileActivityProvider;
+ protected final Provider<NotificationsActivity> notificationActivityProvider;
@Inject
public ManagerActivityMapper(OpenRemoteApp app,
@@ -113,8 +113,8 @@ public class ManagerActivityMapper implements AppActivityMapper {
Provider<AdminTenantActivity> adminTenantActivityProvider,
Provider<AdminUsersActivity> adminUsersActivityProvider,
Provider<AdminUserEditActivity> adminUserActivityProvider,
- Provider<AdminUserNotificationsActivity> adminUserNotificationsActivityProvider,
- Provider<UserAccountActivity> userProfileActivityProvider) {
+ Provider<UserAccountActivity> userProfileActivityProvider,
+ Provider<NotificationsActivity> notificationActivityProvider) {
this.app = app;
this.eventBus = eventBus;
this.managerMessages = managerMessages;
@@ -135,8 +135,8 @@ public class ManagerActivityMapper implements AppActivityMapper {
this.adminTenantActivityProvider = adminTenantActivityProvider;
this.adminUsersActivityProvider = adminUsersActivityProvider;
this.adminUserActivityProvider = adminUserActivityProvider;
- this.adminUserNotificationsActivityProvider = adminUserNotificationsActivityProvider;
this.userProfileActivityProvider = userProfileActivityProvider;
+ this.notificationActivityProvider = notificationActivityProvider;
}
public AppActivity getActivity(Place place) {
@@ -174,6 +174,9 @@ public class ManagerActivityMapper implements AppActivityMapper {
if (place instanceof AssetRulesEditorPlace) {
return assetRulesEditorActivityProvider.get().init(app.getSecurity(), (AssetRulesEditorPlace) place);
}
+ if (place instanceof NotificationsPlace) {
+ return notificationActivityProvider.get().init(app.getSecurity(), (NotificationsPlace) place);
+ }
if (place instanceof ConsoleAppsPlace) {
return appsActivityProvider.get().init(app.getSecurity(), (ConsoleAppsPlace) place);
}
@@ -192,9 +195,6 @@ public class ManagerActivityMapper implements AppActivityMapper {
if (place instanceof AdminUserEditPlace) {
return adminUserActivityProvider.get().init(app.getSecurity(), (AdminUserEditPlace) place);
}
- if (place instanceof AdminUserNotificationsPlace) {
- return adminUserNotificationsActivityProvider.get().init(app.getSecurity(), (AdminUserNotificationsPlace) place);
- }
if (place instanceof UserAccountPlace) {
return userProfileActivityProvider.get().init(app.getSecurity(), (UserAccountPlace) place);
}
diff --git a/client/src/main/java/org/openremote/app/client/ManagerGinjector.java b/client/src/main/java/org/openremote/app/client/ManagerGinjector.java
index ce3c8d7b5..ca695481c 100644
--- a/client/src/main/java/org/openremote/app/client/ManagerGinjector.java
+++ b/client/src/main/java/org/openremote/app/client/ManagerGinjector.java
@@ -28,6 +28,7 @@ import org.openremote.app.client.assets.AssetsModule;
import org.openremote.app.client.apps.ConsoleAppsModule;
import org.openremote.app.client.map.MapModule;
import org.openremote.app.client.mvp.MVPModule;
+import org.openremote.app.client.notifications.NotificationsModule;
import org.openremote.app.client.rules.RulesModule;
import org.openremote.app.client.toast.ToastModule;
import org.openremote.app.client.user.UserModule;
@@ -40,6 +41,7 @@ import org.openremote.app.client.user.UserModule;
MapModule.class,
AssetsModule.class,
RulesModule.class,
+ NotificationsModule.class,
ConsoleAppsModule.class,
AdminModule.class,
UserModule.class
diff --git a/client/src/main/java/org/openremote/app/client/ManagerHistoryMapper.java b/client/src/main/java/org/openremote/app/client/ManagerHistoryMapper.java
index ce09d53a1..1f668a255 100644
--- a/client/src/main/java/org/openremote/app/client/ManagerHistoryMapper.java
+++ b/client/src/main/java/org/openremote/app/client/ManagerHistoryMapper.java
@@ -26,7 +26,6 @@ import org.openremote.app.client.admin.tenant.AdminTenantPlace;
import org.openremote.app.client.admin.tenant.AdminTenantsPlace;
import org.openremote.app.client.admin.users.AdminUsersPlace;
import org.openremote.app.client.admin.users.edit.AdminUserEditPlace;
-import org.openremote.app.client.admin.users.notifications.AdminUserNotificationsPlace;
import org.openremote.app.client.apps.ConsoleAppsPlace;
import org.openremote.app.client.assets.AssetsDashboardPlace;
import org.openremote.app.client.assets.asset.AssetEditPlace;
@@ -34,6 +33,7 @@ import org.openremote.app.client.assets.asset.AssetViewPlace;
import org.openremote.app.client.assets.tenant.AssetsTenantPlace;
import org.openremote.app.client.map.MapAssetPlace;
import org.openremote.app.client.map.MapTenantPlace;
+import org.openremote.app.client.notifications.NotificationsPlace;
import org.openremote.app.client.rules.asset.AssetRulesEditorPlace;
import org.openremote.app.client.rules.asset.AssetRulesListPlace;
import org.openremote.app.client.rules.global.GlobalRulesEditorPlace;
@@ -56,13 +56,13 @@ import org.openremote.app.client.user.UserAccountPlace;
TenantRulesEditorPlace.Tokenizer.class,
AssetRulesListPlace.Tokenizer.class,
AssetRulesEditorPlace.Tokenizer.class,
+ NotificationsPlace.Tokenizer.class,
ConsoleAppsPlace.Tokenizer.class,
AdminSyslogPlace.Tokenizer.class,
AdminTenantsPlace.Tokenizer.class,
AdminTenantPlace.Tokenizer.class,
AdminUsersPlace.Tokenizer.class,
AdminUserEditPlace.Tokenizer.class,
- AdminUserNotificationsPlace.Tokenizer.class,
UserAccountPlace.Tokenizer.class
}
)
diff --git a/client/src/main/java/org/openremote/app/client/OpenRemoteApp.java b/client/src/main/java/org/openremote/app/client/OpenRemoteApp.java
index 89250b180..6f5975540 100644
--- a/client/src/main/java/org/openremote/app/client/OpenRemoteApp.java
+++ b/client/src/main/java/org/openremote/app/client/OpenRemoteApp.java
@@ -7,9 +7,9 @@ import jsinterop.annotations.JsType;
import jsinterop.base.Any;
import org.openremote.app.client.rest.Requests;
import org.openremote.app.client.toast.Toasts;
-import org.openremote.model.interop.Consumer;
-import org.openremote.model.interop.Runnable;
+import java.util.function.Consumer;
import org.openremote.model.security.Tenant;
+import org.openremote.model.interop.Runnable;
/**
* The singleton of {@code <or-app>}.
diff --git a/client/src/main/java/org/openremote/app/client/admin/AdminModule.java b/client/src/main/java/org/openremote/app/client/admin/AdminModule.java
index 5e8b8040c..905e21dd7 100644
--- a/client/src/main/java/org/openremote/app/client/admin/AdminModule.java
+++ b/client/src/main/java/org/openremote/app/client/admin/AdminModule.java
@@ -35,7 +35,6 @@ import org.openremote.app.client.admin.users.AdminUsersImpl;
import org.openremote.app.client.admin.users.edit.AdminUserEdit;
import org.openremote.app.client.admin.users.edit.AdminUserEditActivity;
import org.openremote.app.client.admin.users.edit.AdminUserEditImpl;
-import org.openremote.app.client.admin.users.notifications.*;
import org.openremote.model.notification.NotificationResource;
import org.openremote.model.security.UserResource;
import org.openremote.model.syslog.SyslogResource;
@@ -62,10 +61,6 @@ public class AdminModule extends AbstractGinModule {
bind(AdminUserEdit.class).to(AdminUserEditImpl.class).in(Singleton.class);
bind(AdminUserEditActivity.class);
-
- bind(AdminUserNotifications.class).to(AdminUserNotificationsImpl.class).in(Singleton.class);
- bind(AdminUserNotificationsActivity.class);
- bind(AdminUserNotificationEditor.class).to(AdminUserNotificationEditorImpl.class).in(Singleton.class);
}
@Provides
@@ -79,11 +74,4 @@ public class AdminModule extends AbstractGinModule {
public native UserResource getUserResource() /*-{
return $wnd.openremote.REST.UserResource;
}-*/;
-
- @Provides
- @Singleton
- public native NotificationResource getNotificationResource() /*-{
- return $wnd.openremote.REST.NotificationResource;
- }-*/;
-
}
diff --git a/client/src/main/java/org/openremote/app/client/admin/syslog/AdminSyslogImpl.java b/client/src/main/java/org/openremote/app/client/admin/syslog/AdminSyslogImpl.java
index 17429b316..2543dbf99 100644
--- a/client/src/main/java/org/openremote/app/client/admin/syslog/AdminSyslogImpl.java
+++ b/client/src/main/java/org/openremote/app/client/admin/syslog/AdminSyslogImpl.java
@@ -63,8 +63,8 @@ public class AdminSyslogImpl extends FormViewImpl implements AdminSyslog {
int limit = SyslogConfig.DEFAULT_LIMIT;
@Inject
- public AdminSyslogImpl(Environment environment, Provider<Confirmation> confirmationDialogProvider) {
- super(confirmationDialogProvider, environment.getWidgetStyle());
+ public AdminSyslogImpl(Environment environment) {
+ super(environment.getWidgetStyle());
syslogFilter = new SyslogFilter(environment.getMessages(), environment.getWidgetStyle()) {
@Override
diff --git a/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantImpl.java b/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantImpl.java
index 9a7ea9b0c..2577decd3 100644
--- a/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantImpl.java
+++ b/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantImpl.java
@@ -71,8 +71,8 @@ public class AdminTenantImpl extends FormViewImpl implements AdminTenant {
protected Presenter presenter;
@Inject
- public AdminTenantImpl(Environment environment, Provider<Confirmation> confirmationDialogProvider) {
- super(confirmationDialogProvider, environment.getWidgetStyle());
+ public AdminTenantImpl(Environment environment) {
+ super(environment.getWidgetStyle());
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
}
diff --git a/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantPlace.java b/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantPlace.java
index f79d477f0..538b3987a 100644
--- a/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantPlace.java
+++ b/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantPlace.java
@@ -56,7 +56,7 @@ public class AdminTenantPlace extends AdminPlace {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realm='" + realm + '\'' +
+ "realmId='" + realm + '\'' +
"}";
}
}
diff --git a/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantsImpl.java b/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantsImpl.java
index 786c46540..19e601bb9 100644
--- a/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantsImpl.java
+++ b/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantsImpl.java
@@ -58,9 +58,8 @@ public class AdminTenantsImpl extends FormViewImpl implements AdminTenants {
@Inject
public AdminTenantsImpl(Environment environment,
- Provider<Confirmation> confirmationDialogProvider,
FormTableStyle formTableStyle) {
- super(confirmationDialogProvider, environment.getWidgetStyle());
+ super(environment.getWidgetStyle());
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/AbstractAdminUsersPlace.java b/client/src/main/java/org/openremote/app/client/admin/users/AbstractAdminUsersPlace.java
index 4ef9036bb..31f0f796c 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/AbstractAdminUsersPlace.java
+++ b/client/src/main/java/org/openremote/app/client/admin/users/AbstractAdminUsersPlace.java
@@ -51,7 +51,7 @@ public abstract class AbstractAdminUsersPlace extends AdminPlace {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realm='" + realm + '\'' +
+ "realmId='" + realm + '\'' +
", userId='" + userId + '\'' +
"}";
}
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/AdminUsersImpl.java b/client/src/main/java/org/openremote/app/client/admin/users/AdminUsersImpl.java
index 4af2c183c..b79e41618 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/AdminUsersImpl.java
+++ b/client/src/main/java/org/openremote/app/client/admin/users/AdminUsersImpl.java
@@ -61,11 +61,10 @@ public class AdminUsersImpl extends FormViewImpl implements AdminUsers {
Presenter presenter;
@Inject
- public AdminUsersImpl(Provider<Confirmation> confirmationDialogProvider,
- WidgetStyle widgetStyle,
+ public AdminUsersImpl(WidgetStyle widgetStyle,
FormTableStyle formTableStyle,
AdminUsersNavigation adminUsersNavigation) {
- super(confirmationDialogProvider, widgetStyle);
+ super(widgetStyle);
this.adminUsersNavigation = adminUsersNavigation;
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/AdminUsersNavigation.java b/client/src/main/java/org/openremote/app/client/admin/users/AdminUsersNavigation.java
index b4894631d..0aa3888b3 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/AdminUsersNavigation.java
+++ b/client/src/main/java/org/openremote/app/client/admin/users/AdminUsersNavigation.java
@@ -22,7 +22,6 @@ package org.openremote.app.client.admin.users;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.inject.Inject;
import org.openremote.app.client.admin.users.edit.AdminUserEditPlace;
-import org.openremote.app.client.admin.users.notifications.AdminUserNotificationsPlace;
import org.openremote.app.client.i18n.ManagerMessages;
import org.openremote.app.client.widget.Hyperlink;
import org.openremote.app.client.widget.SecondaryNavigation;
@@ -33,7 +32,6 @@ public class AdminUsersNavigation extends SecondaryNavigation {
final Hyperlink allUsersLink;
final Hyperlink editUserLink;
- final Hyperlink notificationsLink;
final Hyperlink createUserLink;
@Inject
@@ -48,16 +46,12 @@ public class AdminUsersNavigation extends SecondaryNavigation {
editUserLink = new Hyperlink("edit", managerMessages.editUser());
add(editUserLink);
-
- notificationsLink = new Hyperlink("send", managerMessages.manageNotifications());
- add(notificationsLink);
}
public void reset() {
reset(allUsersLink);
reset(createUserLink);
reset(editUserLink);
- reset(notificationsLink);
}
public void setActive(AbstractAdminUsersPlace place) {
@@ -91,18 +85,7 @@ public class AdminUsersNavigation extends SecondaryNavigation {
} else {
editUserLink.addStyleName("active");
editUserLink.setVisible(true);
-
- notificationsLink.setTargetHistoryToken(
- placeHistoryMapper.getToken(new AdminUserNotificationsPlace(place))
- );
- notificationsLink.setVisible(true);
-
}
- } else if (place instanceof AdminUserNotificationsPlace) {
- createUserLink.setVisible(true);
- editUserLink.setVisible(true);
- notificationsLink.addStyleName("active");
- notificationsLink.setVisible(true);
} else if (place instanceof AdminUsersPlace) {
allUsersLink.setVisible(false);
}
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/edit/AdminUserEditActivity.java b/client/src/main/java/org/openremote/app/client/admin/users/edit/AdminUserEditActivity.java
index 886007e2e..3d7dfe274 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/edit/AdminUserEditActivity.java
+++ b/client/src/main/java/org/openremote/app/client/admin/users/edit/AdminUserEditActivity.java
@@ -30,12 +30,12 @@ import org.openremote.model.event.bus.EventBus;
import org.openremote.model.event.bus.EventRegistration;
import org.openremote.model.http.ConstraintViolation;
import org.openremote.model.interop.Consumer;
-import org.openremote.model.interop.Runnable;
import org.openremote.model.notification.NotificationResource;
import org.openremote.model.security.Credential;
import org.openremote.model.security.Role;
import org.openremote.model.security.User;
import org.openremote.model.security.UserResource;
+import org.openremote.model.interop.Runnable;
import javax.inject.Inject;
import java.util.ArrayList;
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/edit/AdminUserEditImpl.java b/client/src/main/java/org/openremote/app/client/admin/users/edit/AdminUserEditImpl.java
index 363cc5aff..72b1d8161 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/edit/AdminUserEditImpl.java
+++ b/client/src/main/java/org/openremote/app/client/admin/users/edit/AdminUserEditImpl.java
@@ -115,9 +115,8 @@ public class AdminUserEditImpl extends FormViewImpl implements AdminUserEdit {
@Inject
public AdminUserEditImpl(Environment environment,
- Provider<Confirmation> confirmationDialogProvider,
AdminUsersNavigation adminUsersNavigation) {
- super(confirmationDialogProvider, environment.getWidgetStyle());
+ super(environment.getWidgetStyle());
this.adminUsersNavigation = adminUsersNavigation;
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationEditorImpl.java b/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationEditorImpl.java
deleted file mode 100644
index 25b719878..000000000
--- a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationEditorImpl.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * 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.admin.users.notifications;
-
-import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.InlineLabel;
-import org.openremote.app.client.style.WidgetStyle;
-import org.openremote.app.client.widget.*;
-import org.openremote.app.client.app.dialog.Dialog;
-import org.openremote.app.client.i18n.ManagerMessages;
-import org.openremote.model.interop.Consumer;
-import org.openremote.model.notification.Notification;
-import org.openremote.model.notification.PushNotificationMessage;
-import org.openremote.model.notification.SentNotification;
-
-import javax.inject.Inject;
-
-import static org.openremote.model.util.TextUtil.isNullOrEmpty;
-
-public class AdminUserNotificationEditorImpl implements AdminUserNotificationEditor {
-
- final protected Dialog dialog;
- final protected WidgetStyle widgetStyle;
- final protected ManagerMessages managerMessages;
-
- final protected FlowPanel errorPanel = new FlowPanel();
- final protected FormInputText notificationTitleInput = new FormInputText();
- final protected FormTextArea notificationMessageInput = new FormTextArea();
- final protected FormInputText notificationAppUrlInput = new FormInputText();
-
- Notification alertNotification;
-
- Consumer<Notification> onSend;
- Runnable onClose;
-
- @Inject
- public AdminUserNotificationEditorImpl(Dialog dialog,
- WidgetStyle widgetStyle,
- ManagerMessages managerMessages) {
- this.dialog = dialog;
- this.widgetStyle = widgetStyle;
- this.managerMessages = managerMessages;
-
- dialog.setHeaderLabel(managerMessages.sendNotification());
-
- dialog.setModal(true);
- dialog.setAutoHideOnHistoryEvents(true);
- dialog.addStyleName(widgetStyle.AdminNotificationEditor());
-
- PushButton sendButton = new PushButton();
- sendButton.setFocus(true);
- sendButton.setText(managerMessages.sendNotification());
- sendButton.setIcon("send");
- sendButton.addStyleName(widgetStyle.FormControl());
- sendButton.addStyleName(widgetStyle.PushButton());
- sendButton.addStyleName(widgetStyle.FormButtonPrimary());
- sendButton.addClickHandler(event -> {
- Notification notification = buildNotification();
- if (notification != null) {
- if (onSend != null)
- onSend.accept(notification);
- dialog.close();
- }
- });
- dialog.getFooterPanel().add(sendButton);
-
- PushButton cancelButton = new PushButton();
- cancelButton.setText(managerMessages.cancel());
- cancelButton.setIcon("close");
- cancelButton.addStyleName(widgetStyle.FormControl());
- cancelButton.addStyleName(widgetStyle.PushButton());
- cancelButton.addStyleName(widgetStyle.FormButton());
- cancelButton.addClickHandler(event -> {
- dialog.close();
- if (onClose != null)
- onClose.run();
- });
- dialog.getFooterPanel().add(cancelButton);
-
- errorPanel.setStyleName("flex-none layout horizontal error");
- errorPanel.addStyleName(widgetStyle.FormMessages());
- errorPanel.setVisible(false);
- dialog.getContentPanel().add(errorPanel);
-
- FormGroup titleGroup = new FormGroup();
- FormLabel titleLabel = new FormLabel(managerMessages.title());
- titleGroup.setFormLabel(titleLabel);
- FormField titleField = new FormField();
- titleGroup.setFormField(titleField);
- notificationTitleInput.addStyleName("flex");
- titleField.add(notificationTitleInput);
- dialog.getContentPanel().add(titleGroup);
-
- FormGroup messageGroup = new FormGroup();
- FormLabel messageLabel = new FormLabel(managerMessages.message());
- messageGroup.setFormLabel(messageLabel);
- FormField messageField = new FormField();
- messageGroup.setFormField(messageField);
- notificationMessageInput.setHeight("5em");
- notificationMessageInput.setResizable(false);
- notificationMessageInput.setBorder(true);
- messageField.add(notificationMessageInput);
- dialog.getContentPanel().add(messageGroup);
-
- FormGroup appUrlGroup = new FormGroup();
- FormLabel appUrlLabel = new FormLabel(managerMessages.notificationAppUrl());
- appUrlGroup.setFormLabel(appUrlLabel);
- FormField appUrlField = new FormField();
- appUrlGroup.setFormField(appUrlField);
- notificationAppUrlInput.addStyleName("flex");
- appUrlField.add(notificationAppUrlInput);
- dialog.getContentPanel().add(appUrlGroup);
- }
-
- @Override
- public void reset() {
- alertNotification = null;
- onSend = null;
- onClose = null;
- errorPanel.clear();
- notificationTitleInput.setValue(null);
- notificationMessageInput.setValue(null);
- notificationAppUrlInput.setValue(null);
- }
-
- @Override
- public void setNotification(Notification notification) {
- this.alertNotification = notification;
- errorPanel.clear();
- errorPanel.setVisible(false);
-// notificationTitleInput.setText(notification.getTitle());
-// notificationMessageInput.setText(notification.getBody());
-// notificationAppUrlInput.setText(notification.getAppUrl());
- }
-
- public void setOnSend(Consumer<Notification> onSend) {
- this.onSend = onSend;
- }
-
- public void setOnClose(Runnable onClose) {
- this.onClose = onClose;
- }
-
- public void show() {
- dialog.open();
- }
-
- protected Notification buildNotification() {
- errorPanel.clear();
- String notificationTitle = notificationTitleInput.getText();
- String notificationMessage = notificationMessageInput.getText();
- String notificationAppUrl = notificationAppUrlInput.getText();
- if (isNullOrEmpty(notificationTitle)
- || isNullOrEmpty(notificationMessage)
- || isNullOrEmpty(notificationAppUrl)) {
- errorPanel.add(new IconLabel("warning"));
- InlineLabel errorMessage = new InlineLabel(managerMessages.enterTitleMessageAppurlForNotification());
- errorPanel.add(errorMessage);
- errorPanel.setVisible(true);
- return null;
- }
- errorPanel.setVisible(false);
-// alertNotification.setTitle(notificationTitle);
-// alertNotification.setBody(notificationMessage);
-// alertNotification.setAppUrl(notificationAppUrl);
-// return alertNotification;
- return null;
- }
-}
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsActivity.java b/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsActivity.java
deleted file mode 100644
index 46246f0a7..000000000
--- a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsActivity.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright 2016, 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.admin.users.notifications;
-
-import org.openremote.app.client.Environment;
-import org.openremote.app.client.admin.*;
-import org.openremote.app.client.admin.navigation.AdminNavigation;
-import org.openremote.app.client.admin.users.edit.AdminUserEditPlace;
-import org.openremote.app.client.event.ShowSuccessEvent;
-import org.openremote.app.client.mvp.AcceptsView;
-import org.openremote.app.client.mvp.AppActivity;
-import org.openremote.model.event.bus.EventBus;
-import org.openremote.model.event.bus.EventRegistration;
-import org.openremote.model.notification.Notification;
-import org.openremote.model.notification.NotificationResource;
-import org.openremote.model.security.User;
-import org.openremote.model.security.UserResource;
-
-import javax.inject.Inject;
-import java.util.Collection;
-import java.util.Collections;
-
-public class AdminUserNotificationsActivity
- extends AbstractAdminActivity<AdminUserNotificationsPlace, AdminUserNotifications>
- implements AdminUserNotifications.Presenter {
-
- final protected Environment environment;
- final protected UserResource userResource;
- final protected UserMapper userMapper;
- final protected CredentialMapper credentialMapper;
- final protected RoleArrayMapper roleArrayMapper;
- final protected AdminUserNotificationEditor notificationEditor;
- final protected NotificationResource notificationResource;
- final protected NotificationMapper notificationMapper;
- final protected SentNotificationArrayMapper alertNotificationArrayMapper;
-
- protected AdminUserEditPlace place;
- protected String realm;
- protected String userId;
- protected User user;
- protected Notification alertNotification;
-
- @Inject
- public AdminUserNotificationsActivity(Environment environment,
- AdminView adminView,
- AdminNavigation.Presenter adminNavigationPresenter,
- AdminUserNotifications view,
- UserResource userResource,
- UserMapper userMapper,
- CredentialMapper credentialMapper,
- RoleArrayMapper roleArrayMapper,
- AdminUserNotificationEditor notificationEditor,
- NotificationResource notificationResource,
- NotificationMapper notificationMapper,
- SentNotificationArrayMapper alertNotificationArrayMapper) {
- super(adminView, adminNavigationPresenter, view);
- this.environment = environment;
- this.userResource = userResource;
- this.userMapper = userMapper;
- this.credentialMapper = credentialMapper;
- this.roleArrayMapper = roleArrayMapper;
- this.notificationEditor = notificationEditor;
- this.notificationResource = notificationResource;
- this.notificationMapper = notificationMapper;
- this.alertNotificationArrayMapper = alertNotificationArrayMapper;
- }
-
- @Override
- protected String[] getRequiredRoles() {
- return new String[]{"read:admin", "write:admin"};
- }
-
- @Override
- protected AppActivity<AdminUserNotificationsPlace> init(AdminUserNotificationsPlace place) {
- realm = place.getRealm();
- userId = place.getUserId();
- return super.init(place);
- }
-
- @Override
- public void start(AcceptsView container, EventBus eventBus, Collection<EventRegistration> registrations) {
- super.start(container, eventBus, registrations);
-
- adminContent.setPresenter(this);
-
- adminContent.clearFormMessages();
-
- if (userId != null) {
- loadUser();
- }
- }
-
- @Override
- public void onStop() {
- super.onStop();
- notificationEditor.reset();
- adminContent.setPresenter(null);
- adminContent.clearFormMessages();
- }
-
- @Override
- public void onSendNotification() {
- // Keep it so we can send it again later
- if (this.alertNotification == null)
- this.alertNotification = createDefaultNotification();
-
- notificationEditor.setNotification(this.alertNotification);
- notificationEditor.setOnSend(updatedNotification -> {
- adminContent.setFormBusy(true);
- this.alertNotification = updatedNotification;
- environment.getApp().getRequests().sendWith(
- notificationMapper,
- requestParams -> notificationResource.sendNotification(requestParams, this.alertNotification),
- 204,
- () -> {
- environment.getEventBus().dispatch(new ShowSuccessEvent(
- environment.getMessages().notificationSentToUser()
- ));
- loadNotifications(() -> adminContent.setFormBusy(false));
- }
- );
- });
- notificationEditor.show();
- }
-
- @Override
- public void onRefresh() {
- loadNotifications(() -> {
- });
- }
-
- @Override
- public void onNotificationsDelete() {
- adminContent.setFormBusy(true);
- environment.getApp().getRequests().send(
- requestParams -> notificationResource.removeNotifications(requestParams,
- null,
- null,
- null,
- Collections.singletonList(userId),
- null),
- 204,
- () -> {
- environment.getEventBus().dispatch(new ShowSuccessEvent(
- environment.getMessages().notificationsDeleted())
- );
- loadNotifications(() -> adminContent.setFormBusy(false));
- }
- );
- }
-
- @Override
- public void onNotificationDelete(Long id) {
- adminContent.setFormBusy(true);
- environment.getApp().getRequests().send(
- requestParams -> notificationResource.removeNotification(requestParams, id),
- 204,
- () -> {
- adminContent.setFormBusy(false);
- adminContent.removeNotification(id);
- environment.getEventBus().dispatch(new ShowSuccessEvent(
- environment.getMessages().notificationDeleted(id))
- );
- }
- );
- }
-
- protected Notification createDefaultNotification() {
- Notification notification = new Notification(null, null, null);
- return notification;
-//
-// PushNotificationAction alertAction = new PushNotificationAction();
-// alertAction.setTitle(environment.getMessages().notificationOpenApplicationDetails());
-// alertAction.setActionType(ActionType.LINK);
-// alertAction.setAppUrl("/#");
-// notification.addAction(alertAction);
-// return notification;
- }
-
- protected void loadUser() {
- adminContent.setFormBusy(true);
- environment.getApp().getRequests().sendAndReturn(
- userMapper,
- requestParams -> userResource.get(requestParams, realm, userId),
- 200,
- user -> {
- this.user = user;
- this.realm = user.getRealm();
- adminContent.setUsername(user.getFullName());
- loadNotifications(() -> adminContent.setFormBusy(false));
- }
- );
- }
-
- protected void loadNotifications(Runnable onComplete) {
- environment.getApp().getRequests().sendAndReturn(
- alertNotificationArrayMapper,
- requestParams -> notificationResource.getNotifications(requestParams,
- null,
- null,
- null,
- Collections.singletonList(userId),
- null),
- 200,
- notifications -> {
- adminContent.setNotifications(notifications);
- onComplete.run();
- }
- );
- }
-}
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsImpl.ui.xml b/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsImpl.ui.xml
deleted file mode 100644
index 916ffd75c..000000000
--- a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsImpl.ui.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
- xmlns:g="urn:import:com.google.gwt.user.client.ui"
- xmlns:w="urn:import:org.openremote.app.client.widget"
- xmlns:adminUsers="urn:import:org.openremote.app.client.admin.users">
-
- <ui:with field="managerMessages" type="org.openremote.app.client.i18n.ManagerMessages"/>
- <ui:with field="widgetStyle" type="org.openremote.app.client.style.WidgetStyle"/>
-
- <g:HTMLPanel styleName="flex layout vertical">
-
- <adminUsers:AdminUsersNavigation ui:field="adminUsersNavigation"/>
-
- <w:Form ui:field="form" addStyleNames="flex">
-
- <g:HTMLPanel ui:field="mainContent"
- styleName="flex-none layout vertical {widgetStyle.MainContent}">
-
- <w:Headline icon="send"
- text="{managerMessages.notifications}"/>
-
- <w:FormGroup>
- <w:label>
- <w:FormLabel text="{managerMessages.username}"/>
- </w:label>
- <w:field>
- <w:FormField>
- <w:FormOutputText ui:field="usernameOutput" addStyleNames="flex"/>
- </w:FormField>
- </w:field>
- <w:actions>
- <w:FormGroupActions>
- <w:FormButton ui:field="refreshNotificationsButton"
- text="{managerMessages.refresh}"
- icon="refresh"/>
- <w:FormButton ui:field="deleteNotificationsButton"
- danger="true"
- text="{managerMessages.deleteNotifications}"
- icon="trash"/>
- <w:FormButton ui:field="sendNotificationButton"
- primary="true"
- text="{managerMessages.sendNotification}"
- icon="send"/>
- </w:FormGroupActions>
- </w:actions>
- </w:FormGroup>
-
- </g:HTMLPanel>
-
- <g:FlowPanel ui:field="notificationsContainer"
- styleName="flex layout vertical {widgetStyle.MainContent} {widgetStyle.FormList}"/>
-
- </w:Form>
-
- </g:HTMLPanel>
-
-</ui:UiBinder>
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsPlace.java b/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsPlace.java
deleted file mode 100644
index 12546e8ad..000000000
--- a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsPlace.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2016, 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.admin.users.notifications;
-
-import com.google.gwt.place.shared.PlaceTokenizer;
-import com.google.gwt.place.shared.Prefix;
-import org.openremote.app.client.admin.users.AbstractAdminUsersPlace;
-
-public class AdminUserNotificationsPlace extends AbstractAdminUsersPlace {
-
- public AdminUserNotificationsPlace(AbstractAdminUsersPlace place) {
- super(place.getRealm(), place.getUserId());
- }
-
- public AdminUserNotificationsPlace(String realm, String userId) {
- super(realm, userId);
- }
-
- @Prefix("adminUserNotifications")
- public static class Tokenizer implements PlaceTokenizer<AdminUserNotificationsPlace> {
-
- @Override
- public AdminUserNotificationsPlace getPlace(String token) {
- if (token == null) {
- throw new IllegalArgumentException("Invalid empty token");
- }
- String[] fields = token.split(":");
- if (fields.length == 2) {
- return new AdminUserNotificationsPlace(fields[0], fields[1]);
- } else {
- throw new IllegalArgumentException("Invalid token: " + token);
- }
- }
-
- @Override
- public String getToken(AdminUserNotificationsPlace place) {
- if (place.getRealm() == null) {
- return "";
- }
- return place.getRealm() + ":" + (place.getUserId() != null ? place.getUserId() : "");
- }
- }
-
-}
diff --git a/client/src/main/java/org/openremote/app/client/app/AppModule.java b/client/src/main/java/org/openremote/app/client/app/AppModule.java
index 6dafd9181..b835749f0 100644
--- a/client/src/main/java/org/openremote/app/client/app/AppModule.java
+++ b/client/src/main/java/org/openremote/app/client/app/AppModule.java
@@ -31,8 +31,5 @@ public class AppModule extends AbstractGinModule {
bind(AppView.class).to(AppViewImpl.class).in(Singleton.class);
bind(HeaderView.class).to(HeaderViewImpl.class).in(Singleton.class);
bind(FooterView.class).to(FooterViewImpl.class).in(Singleton.class);
- bind(Dialog.class).to(DialogImpl.class);
- bind(Confirmation.class).to(ConfirmationImpl.class);
- bind(JsonEditor.class).to(JsonEditorImpl.class);
}
}
diff --git a/client/src/main/java/org/openremote/app/client/app/HeaderPresenter.java b/client/src/main/java/org/openremote/app/client/app/HeaderPresenter.java
index 7119c296f..c3d1c5140 100644
--- a/client/src/main/java/org/openremote/app/client/app/HeaderPresenter.java
+++ b/client/src/main/java/org/openremote/app/client/app/HeaderPresenter.java
@@ -34,6 +34,7 @@ import org.openremote.app.client.assets.tenant.AssetsTenantPlace;
import org.openremote.app.client.event.GoToPlaceEvent;
import org.openremote.app.client.map.MapAssetPlace;
import org.openremote.app.client.map.MapTenantPlace;
+import org.openremote.app.client.notifications.NotificationsPlace;
import org.openremote.app.client.rules.asset.AssetRulesListPlace;
import org.openremote.app.client.rules.global.GlobalRulesListPlace;
import org.openremote.app.client.rules.tenant.TenantRulesListPlace;
@@ -130,6 +131,23 @@ public class HeaderPresenter implements HeaderView.Presenter {
}
}
+ @Override
+ public void navigateNotifications() {
+ if (assetBrowserSelection == null) {
+ placeController.goTo(new NotificationsPlace());
+ return;
+ }
+ if (assetBrowserSelection.getSelectedNode() instanceof TenantTreeNode) {
+ placeController.goTo(new NotificationsPlace(((TenantTreeNode) assetBrowserSelection.getSelectedNode()).getTenant().getRealm(), null));
+ } else if (assetBrowserSelection.getSelectedNode() instanceof AssetTreeNode) {
+ placeController.goTo(
+ new NotificationsPlace(((AssetTreeNode) assetBrowserSelection.getSelectedNode()).getAsset().getTenantRealm(),
+ assetBrowserSelection.getSelectedNode().getId()));
+ } else {
+ placeController.goTo(new NotificationsPlace());
+ }
+ }
+
@Override
public void navigateApps() {
placeController.goTo(new ConsoleAppsPlace(consoleAppSelection != null ? consoleAppSelection.getRealm() : null));
@@ -138,7 +156,6 @@ public class HeaderPresenter implements HeaderView.Presenter {
@Override
public void navigateAdmin() {
placeController.goTo(new AdminSyslogPlace());
-
}
@Override
@@ -161,6 +178,11 @@ public class HeaderPresenter implements HeaderView.Presenter {
return app.getSecurity().hasResourceRoleOrIsSuperUser("read:rules", Constants.KEYCLOAK_CLIENT_ID);
}
+ @Override
+ public boolean isNotificationsEnabled() {
+ return app.getSecurity().hasResourceRoleOrIsSuperUser("read:admin", Constants.KEYCLOAK_CLIENT_ID);
+ }
+
@Override
public boolean isAppsEnabled() {
return app.getSecurity().hasResourceRoleOrIsSuperUser("read:consoles", Constants.KEYCLOAK_CLIENT_ID);
diff --git a/client/src/main/java/org/openremote/app/client/app/HeaderView.java b/client/src/main/java/org/openremote/app/client/app/HeaderView.java
index 0cb8ab4af..4a39abffb 100644
--- a/client/src/main/java/org/openremote/app/client/app/HeaderView.java
+++ b/client/src/main/java/org/openremote/app/client/app/HeaderView.java
@@ -35,6 +35,8 @@ public interface HeaderView extends IsWidget {
void navigateRules();
+ void navigateNotifications();
+
void navigateApps();
void navigateAdmin();
@@ -47,6 +49,8 @@ public interface HeaderView extends IsWidget {
boolean isRulesEnabled();
+ boolean isNotificationsEnabled();
+
boolean isAppsEnabled();
boolean isAdminEnabled();
diff --git a/client/src/main/java/org/openremote/app/client/app/HeaderViewImpl.java b/client/src/main/java/org/openremote/app/client/app/HeaderViewImpl.java
index d7a0e627d..b1e89d731 100644
--- a/client/src/main/java/org/openremote/app/client/app/HeaderViewImpl.java
+++ b/client/src/main/java/org/openremote/app/client/app/HeaderViewImpl.java
@@ -32,6 +32,7 @@ import org.openremote.app.client.assets.AssetsPlace;
import org.openremote.app.client.admin.AdminPlace;
import org.openremote.app.client.apps.ConsoleAppsPlace;
import org.openremote.app.client.map.MapPlace;
+import org.openremote.app.client.notifications.NotificationsPlace;
import org.openremote.app.client.rules.RulesPlace;
import org.openremote.app.client.user.UserAccountPlace;
import org.openremote.app.client.widget.PushButton;
@@ -53,6 +54,9 @@ public class HeaderViewImpl extends Composite implements HeaderView {
@UiField
PushButton rulesButton;
+ @UiField
+ PushButton notificationsButton;
+
@UiField
PushButton appsButton;
@@ -74,6 +78,7 @@ public class HeaderViewImpl extends Composite implements HeaderView {
mapButton.setEnabled(presenter.isMapEnabled());
assetsButton.setEnabled(presenter.isAssetsEnabled());
rulesButton.setEnabled(presenter.isRulesEnabled());
+ notificationsButton.setEnabled(presenter.isNotificationsEnabled());
appsButton.setEnabled(presenter.isAppsEnabled());
adminButton.setEnabled(presenter.isAdminEnabled());
}
@@ -83,6 +88,7 @@ public class HeaderViewImpl extends Composite implements HeaderView {
mapButton.removeStyleName("active");
assetsButton.removeStyleName("active");
rulesButton.removeStyleName("active");
+ notificationsButton.removeStyleName("active");
appsButton.removeStyleName("active");
adminButton.removeStyleName("active");
userButton.removeStyleName("active");
@@ -96,6 +102,9 @@ public class HeaderViewImpl extends Composite implements HeaderView {
if (place instanceof RulesPlace) {
rulesButton.addStyleName("active");
}
+ if (place instanceof NotificationsPlace) {
+ notificationsButton.addStyleName("active");
+ }
if (place instanceof ConsoleAppsPlace) {
appsButton.addStyleName("active");
}
@@ -135,6 +144,11 @@ public class HeaderViewImpl extends Composite implements HeaderView {
presenter.navigateRules();
}
+ @UiHandler("notificationsButton")
+ void notificationsClicked(ClickEvent e) {
+ presenter.navigateNotifications();
+ }
+
@UiHandler("appsButton")
void appsClicked(ClickEvent e) {
presenter.navigateApps();
diff --git a/client/src/main/java/org/openremote/app/client/app/HeaderViewImpl.ui.xml b/client/src/main/java/org/openremote/app/client/app/HeaderViewImpl.ui.xml
index 1dfc5d543..86d15c60a 100644
--- a/client/src/main/java/org/openremote/app/client/app/HeaderViewImpl.ui.xml
+++ b/client/src/main/java/org/openremote/app/client/app/HeaderViewImpl.ui.xml
@@ -29,6 +29,11 @@
icon="chain"
text="{managerMessages.rules}"/>
+ <w:PushButton ui:field="notificationsButton"
+ addStyleNames="{widgetStyle.NavItem}"
+ icon="chain"
+ text="{managerMessages.notifications}"/>
+
<w:PushButton ui:field="appsButton"
addStyleNames="{widgetStyle.NavItem}"
icon="connectdevelop"
diff --git a/client/src/main/java/org/openremote/app/client/app/dialog/Confirmation.java b/client/src/main/java/org/openremote/app/client/app/dialog/Confirmation.java
index a93af6b12..76974e16b 100644
--- a/client/src/main/java/org/openremote/app/client/app/dialog/Confirmation.java
+++ b/client/src/main/java/org/openremote/app/client/app/dialog/Confirmation.java
@@ -19,16 +19,72 @@
*/
package org.openremote.app.client.app.dialog;
-public interface Confirmation {
+import com.google.gwt.user.client.ui.Label;
+import org.openremote.app.client.i18n.ManagerMessages;
+import org.openremote.app.client.style.WidgetStyle;
+import org.openremote.app.client.widget.PushButton;
+import org.openremote.model.interop.Runnable;
- void setTitle(String title);
+public class Confirmation {
- void setText(String text);
+ final protected Dialog dialog;
- void setOnConfirm(Runnable onConfirm);
+ protected Runnable onConfirm;
+ protected Runnable onCancel;
- void setOnCancel(Runnable onCancel);
+ public Confirmation(WidgetStyle widgetStyle,
+ ManagerMessages managerMessages) {
+ this.dialog = new Dialog();
- void show();
+ dialog.setModal(true);
+ dialog.setAutoHideOnHistoryEvents(true);
+ dialog.addStyleName(widgetStyle.ConfirmationDialog());
-}
+ PushButton confirmButton = new PushButton();
+ confirmButton.setFocus(true);
+ confirmButton.setText(managerMessages.OK());
+ confirmButton.setIcon("check");
+ confirmButton.addStyleName(widgetStyle.FormControl());
+ confirmButton.addStyleName(widgetStyle.PushButton());
+ confirmButton.addStyleName(widgetStyle.FormButtonPrimary());
+ confirmButton.addClickHandler(event -> {
+ dialog.close();
+ if (onConfirm != null)
+ onConfirm.run();
+ });
+ dialog.getFooterPanel().add(confirmButton);
+
+ PushButton cancelButton = new PushButton();
+ cancelButton.setText(managerMessages.cancel());
+ cancelButton.setIcon("close");
+ cancelButton.addStyleName(widgetStyle.FormControl());
+ cancelButton.addStyleName(widgetStyle.PushButton());
+ cancelButton.addStyleName(widgetStyle.FormButton());
+ cancelButton.addClickHandler(event -> {
+ dialog.close();
+ if (onCancel != null)
+ onCancel.run();
+ });
+ dialog.getFooterPanel().add(cancelButton);
+ }
+
+ public void setTitle(String title) {
+ dialog.setHeaderLabel(title);
+ }
+
+ public void setText(String text) {
+ dialog.getContentPanel().add(new Label(text));
+ }
+
+ public void setOnConfirm(Runnable onConfirm) {
+ this.onConfirm = onConfirm;
+ }
+
+ public void setOnCancel(Runnable onCancel) {
+ this.onCancel = onCancel;
+ }
+
+ public void show() {
+ dialog.open();
+ }
+}
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/app/dialog/ConfirmationImpl.java b/client/src/main/java/org/openremote/app/client/app/dialog/ConfirmationImpl.java
deleted file mode 100644
index 6b7f886dc..000000000
--- a/client/src/main/java/org/openremote/app/client/app/dialog/ConfirmationImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2016, 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.app.dialog;
-
-import com.google.gwt.user.client.ui.Label;
-import org.openremote.app.client.i18n.ManagerMessages;
-import org.openremote.app.client.style.WidgetStyle;
-import org.openremote.app.client.widget.PushButton;
-
-import javax.inject.Inject;
-
-public class ConfirmationImpl implements Confirmation {
-
- final protected Dialog dialog;
-
- protected Runnable onConfirm;
- protected Runnable onCancel;
-
- @Inject
- public ConfirmationImpl(Dialog dialog,
- WidgetStyle widgetStyle,
- ManagerMessages managerMessages) {
- this.dialog = dialog;
-
- dialog.setModal(true);
- dialog.setAutoHideOnHistoryEvents(true);
- dialog.addStyleName(widgetStyle.ConfirmationDialog());
-
- PushButton confirmButton = new PushButton();
- confirmButton.setFocus(true);
- confirmButton.setText(managerMessages.OK());
- confirmButton.setIcon("check");
- confirmButton.addStyleName(widgetStyle.FormControl());
- confirmButton.addStyleName(widgetStyle.PushButton());
- confirmButton.addStyleName(widgetStyle.FormButtonPrimary());
- confirmButton.addClickHandler(event -> {
- dialog.close();
- if (onConfirm != null)
- onConfirm.run();
- });
- dialog.getFooterPanel().add(confirmButton);
-
- PushButton cancelButton = new PushButton();
- cancelButton.setText(managerMessages.cancel());
- cancelButton.setIcon("close");
- cancelButton.addStyleName(widgetStyle.FormControl());
- cancelButton.addStyleName(widgetStyle.PushButton());
- cancelButton.addStyleName(widgetStyle.FormButton());
- cancelButton.addClickHandler(event -> {
- dialog.close();
- if (onCancel != null)
- onCancel.run();
- });
- dialog.getFooterPanel().add(cancelButton);
- }
-
- @Override
- public void setTitle(String title) {
- dialog.setHeaderLabel(title);
- }
-
- @Override
- public void setText(String text) {
- dialog.getContentPanel().add(new Label(text));
- }
-
- @Override
- public void setOnConfirm(Runnable onConfirm) {
- this.onConfirm = onConfirm;
- }
-
- @Override
- public void setOnCancel(Runnable onCancel) {
- this.onCancel = onCancel;
- }
-
- @Override
- public void show() {
- dialog.open();
- }
-}
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/app/dialog/Dialog.java b/client/src/main/java/org/openremote/app/client/app/dialog/Dialog.java
index 52f52883f..bf90604b2 100644
--- a/client/src/main/java/org/openremote/app/client/app/dialog/Dialog.java
+++ b/client/src/main/java/org/openremote/app/client/app/dialog/Dialog.java
@@ -19,17 +19,56 @@
*/
package org.openremote.app.client.app.dialog;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasWidgets;
+import com.google.gwt.user.client.ui.Label;
+import org.openremote.app.client.i18n.ManagerMessages;
+import org.openremote.app.client.widget.AbstractAppPanel;
import org.openremote.app.client.widget.AppPanel;
+import org.openremote.app.client.widget.PopupPanel;
-public interface Dialog extends AppPanel {
+import javax.inject.Inject;
- void addStyleName(String name);
+public class Dialog extends AbstractAppPanel implements AppPanel {
- void setHeaderLabel(String label);
+ interface UI extends UiBinder<PopupPanel, Dialog> {
+ }
- HasWidgets getContentPanel();
+ @UiField
+ ManagerMessages managerMessages;
- HasWidgets getFooterPanel();
+ @UiField
+ FlowPanel mainPanel;
-}
+ @UiField
+ Label headerLabel;
+
+ @UiField
+ FlowPanel contentPanel;
+
+ @UiField
+ FlowPanel footerPanel;
+
+ public Dialog() {
+ super(GWT.create(UI.class));
+ }
+
+ public void addStyleName(String name) {
+ mainPanel.addStyleName(name);
+ }
+
+ public void setHeaderLabel(String label) {
+ headerLabel.setText(label);
+ }
+
+ public HasWidgets getContentPanel() {
+ return contentPanel;
+ }
+
+ public HasWidgets getFooterPanel() {
+ return footerPanel;
+ }
+}
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/app/dialog/DialogImpl.ui.xml b/client/src/main/java/org/openremote/app/client/app/dialog/Dialog.ui.xml
similarity index 100%
rename from client/src/main/java/org/openremote/app/client/app/dialog/DialogImpl.ui.xml
rename to client/src/main/java/org/openremote/app/client/app/dialog/Dialog.ui.xml
diff --git a/client/src/main/java/org/openremote/app/client/app/dialog/DialogImpl.java b/client/src/main/java/org/openremote/app/client/app/dialog/DialogImpl.java
deleted file mode 100644
index 63f2cbecd..000000000
--- a/client/src/main/java/org/openremote/app/client/app/dialog/DialogImpl.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2016, 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.app.dialog;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiField;
-import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.HasWidgets;
-import com.google.gwt.user.client.ui.Label;
-import org.openremote.app.client.i18n.ManagerMessages;
-import org.openremote.app.client.widget.AbstractAppPanel;
-import org.openremote.app.client.widget.PopupPanel;
-
-import javax.inject.Inject;
-
-public class DialogImpl extends AbstractAppPanel implements Dialog {
-
- interface UI extends UiBinder<PopupPanel, DialogImpl> {
- }
-
- @UiField
- ManagerMessages managerMessages;
-
- @UiField
- FlowPanel mainPanel;
-
- @UiField
- Label headerLabel;
-
- @UiField
- FlowPanel contentPanel;
-
- @UiField
- FlowPanel footerPanel;
-
- @Inject
- public DialogImpl() {
- super(GWT.create(UI.class));
- }
-
- @Override
- public void addStyleName(String name) {
- mainPanel.addStyleName(name);
- }
-
- @Override
- public void setHeaderLabel(String label) {
- headerLabel.setText(label);
- }
-
- @Override
- public HasWidgets getContentPanel() {
- return contentPanel;
- }
-
- @Override
- public HasWidgets getFooterPanel() {
- return footerPanel;
- }
-}
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/app/dialog/JsonEditor.java b/client/src/main/java/org/openremote/app/client/app/dialog/JsonEditor.java
index e067a5a40..8e97d1590 100644
--- a/client/src/main/java/org/openremote/app/client/app/dialog/JsonEditor.java
+++ b/client/src/main/java/org/openremote/app/client/app/dialog/JsonEditor.java
@@ -19,21 +19,148 @@
*/
package org.openremote.app.client.app.dialog;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.InlineLabel;
+import org.openremote.app.client.i18n.ManagerMessages;
+import org.openremote.app.client.style.WidgetStyle;
+import org.openremote.app.client.widget.FormTextArea;
+import org.openremote.app.client.widget.IconLabel;
+import org.openremote.app.client.widget.PushButton;
import org.openremote.model.interop.Consumer;
import org.openremote.model.value.Value;
+import org.openremote.model.value.ValueException;
+import org.openremote.model.value.Values;
+import org.openremote.model.value.impl.ValueUtil;
+import org.openremote.model.interop.Runnable;
-public interface JsonEditor {
+public class JsonEditor {
- void setTitle(String title);
+ final protected Dialog dialog;
+ final protected WidgetStyle widgetStyle;
+ final protected ManagerMessages managerMessages;
- void setValue(Value value);
+ FormTextArea editor;
+ FlowPanel errorPanel = new FlowPanel();
+ Consumer<Value> onApply;
+ Runnable onReset;
+ Runnable onCancel;
- void setOnApply(Consumer<Value> onApply);
+ public JsonEditor(String title,
+ WidgetStyle widgetStyle,
+ ManagerMessages managerMessages) {
+ this.dialog = new Dialog();
+ this.widgetStyle = widgetStyle;
+ this.managerMessages = managerMessages;
- void setOnReset(Runnable onReset);
+ dialog.setModal(true);
+ dialog.setAutoHideOnHistoryEvents(true);
+ dialog.addStyleName(widgetStyle.JsonEditor());
+ dialog.setHeaderLabel(title);
- void setOnCancel(Runnable onCancel);
+ PushButton okButton = new PushButton();
+ okButton.setFocus(true);
+ okButton.setText(managerMessages.OK());
+ okButton.setIcon("check");
+ okButton.addStyleName(widgetStyle.FormControl());
+ okButton.addStyleName(widgetStyle.PushButton());
+ okButton.addStyleName(widgetStyle.FormButtonPrimary());
+ okButton.addClickHandler(event -> {
+ Value value = parseValue();
+ if (value != null) {
+ if (onApply != null)
+ onApply.accept(value);
+ dialog.close();
+ }
+ });
+ dialog.getFooterPanel().add(okButton);
- void show();
+ PushButton resetButton = new PushButton();
+ resetButton.setText(managerMessages.reset());
+ resetButton.setIcon("refresh");
+ resetButton.addStyleName(widgetStyle.FormControl());
+ resetButton.addStyleName(widgetStyle.PushButton());
+ resetButton.addStyleName(widgetStyle.FormButton());
+ resetButton.addClickHandler(event -> {
+ if (onReset != null)
+ onReset.run();
+ });
+ dialog.getFooterPanel().add(resetButton);
-}
+ PushButton cancelButton = new PushButton();
+ cancelButton.setText(managerMessages.cancel());
+ cancelButton.setIcon("close");
+ cancelButton.addStyleName(widgetStyle.FormControl());
+ cancelButton.addStyleName(widgetStyle.PushButton());
+ cancelButton.addStyleName(widgetStyle.FormButton());
+ cancelButton.addClickHandler(event -> {
+ if (errorPanel.isVisible() && onReset != null) {
+ onReset.run();
+ }
+ dialog.close();
+ if (onCancel != null)
+ onCancel.run();
+ });
+ dialog.getFooterPanel().add(cancelButton);
+
+ errorPanel.setStyleName("flex-none layout horizontal error");
+ errorPanel.addStyleName(widgetStyle.FormMessages());
+ errorPanel.setVisible(false);
+ dialog.getContentPanel().add(errorPanel);
+
+ editor = new FormTextArea();
+ editor.setHeight("30em");
+ editor.setResizable(false);
+ editor.setBorder(true);
+ editor.setReadOnly(onApply == null);
+ dialog.getContentPanel().add(editor);
+ }
+
+ public void setTitle(String title) {
+ dialog.setHeaderLabel(title);
+ }
+
+ public void setValue(Value value) {
+ errorPanel.clear();
+ errorPanel.setVisible(false);
+ editor.setText(value != null ? ValueUtil.stringify(value, 4) : null);
+ }
+
+ public void setOnApply(Consumer<Value> onApply) {
+ this.onApply = onApply;
+ editor.setReadOnly(onApply == null);
+ }
+
+ public void setOnReset(Runnable onReset) {
+ this.onReset = onReset;
+ }
+
+ public void setOnCancel(Runnable onCancel) {
+ this.onCancel = onCancel;
+ }
+
+ public void show() {
+ dialog.open();
+ }
+
+ protected Value parseValue() {
+ errorPanel.clear();
+ Value value = null;
+ String error = null;
+ try {
+ value = Values.parse(editor.getText()).orElse(null);
+ if (value == null)
+ error = managerMessages.emptyJsonData();
+ } catch (ValueException ex) {
+ error = ex.getMessage();
+ }
+ if (error != null) {
+ errorPanel.add(new IconLabel("warning"));
+ InlineLabel errorMessage = new InlineLabel(error);
+ errorPanel.add(errorMessage);
+ errorPanel.setVisible(true);
+ return null;
+ }
+ errorPanel.setVisible(false);
+ return value;
+ }
+}
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/app/dialog/JsonEditorImpl.java b/client/src/main/java/org/openremote/app/client/app/dialog/JsonEditorImpl.java
deleted file mode 100644
index f7143b22c..000000000
--- a/client/src/main/java/org/openremote/app/client/app/dialog/JsonEditorImpl.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * 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.app.dialog;
-
-import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.InlineLabel;
-import org.openremote.app.client.i18n.ManagerMessages;
-import org.openremote.app.client.style.WidgetStyle;
-import org.openremote.app.client.widget.FormTextArea;
-import org.openremote.app.client.widget.IconLabel;
-import org.openremote.app.client.widget.PushButton;
-import org.openremote.model.interop.Consumer;
-import org.openremote.model.value.Value;
-import org.openremote.model.value.ValueException;
-import org.openremote.model.value.Values;
-import org.openremote.model.value.impl.ValueUtil;
-
-import javax.inject.Inject;
-
-public class JsonEditorImpl implements JsonEditor {
-
- final protected Dialog dialog;
- final protected WidgetStyle widgetStyle;
- final protected ManagerMessages managerMessages;
-
- FormTextArea editor;
- FlowPanel errorPanel = new FlowPanel();
- Consumer<Value> onApply;
- Runnable onReset;
- Runnable onCancel;
-
- @Inject
- public JsonEditorImpl(Dialog dialog,
- WidgetStyle widgetStyle,
- ManagerMessages managerMessages) {
- this.dialog = dialog;
- this.widgetStyle = widgetStyle;
- this.managerMessages = managerMessages;
-
- dialog.setModal(true);
- dialog.setAutoHideOnHistoryEvents(true);
- dialog.addStyleName(widgetStyle.JsonEditor());
-
- PushButton okButton = new PushButton();
- okButton.setFocus(true);
- okButton.setText(managerMessages.OK());
- okButton.setIcon("check");
- okButton.addStyleName(widgetStyle.FormControl());
- okButton.addStyleName(widgetStyle.PushButton());
- okButton.addStyleName(widgetStyle.FormButtonPrimary());
- okButton.addClickHandler(event -> {
- Value value = parseValue();
- if (value != null) {
- if (onApply != null)
- onApply.accept(value);
- dialog.close();
- }
- });
- dialog.getFooterPanel().add(okButton);
-
- PushButton resetButton = new PushButton();
- resetButton.setText(managerMessages.reset());
- resetButton.setIcon("refresh");
- resetButton.addStyleName(widgetStyle.FormControl());
- resetButton.addStyleName(widgetStyle.PushButton());
- resetButton.addStyleName(widgetStyle.FormButton());
- resetButton.addClickHandler(event -> {
- if (onReset != null)
- onReset.run();
- });
- dialog.getFooterPanel().add(resetButton);
-
- PushButton cancelButton = new PushButton();
- cancelButton.setText(managerMessages.cancel());
- cancelButton.setIcon("close");
- cancelButton.addStyleName(widgetStyle.FormControl());
- cancelButton.addStyleName(widgetStyle.PushButton());
- cancelButton.addStyleName(widgetStyle.FormButton());
- cancelButton.addClickHandler(event -> {
- if (errorPanel.isVisible() && onReset != null) {
- onReset.run();
- }
- dialog.close();
- if (onCancel != null)
- onCancel.run();
- });
- dialog.getFooterPanel().add(cancelButton);
-
- errorPanel.setStyleName("flex-none layout horizontal error");
- errorPanel.addStyleName(widgetStyle.FormMessages());
- errorPanel.setVisible(false);
- dialog.getContentPanel().add(errorPanel);
-
- editor = new FormTextArea();
- editor.setHeight("30em");
- editor.setResizable(false);
- editor.setBorder(true);
- editor.setReadOnly(onApply == null);
- dialog.getContentPanel().add(editor);
- }
-
- @Override
- public void setTitle(String title) {
- dialog.setHeaderLabel(title);
- }
-
- @Override
- public void setValue(Value value) {
- errorPanel.clear();
- errorPanel.setVisible(false);
- editor.setText(value != null ? ValueUtil.stringify(value, 4) : null);
- }
-
- @Override
- public void setOnApply(Consumer<Value> onApply) {
- this.onApply = onApply;
- editor.setReadOnly(onApply == null);
- }
-
- @Override
- public void setOnReset(Runnable onReset) {
- this.onReset = onReset;
- }
-
- @Override
- public void setOnCancel(Runnable onCancel) {
- this.onCancel = onCancel;
- }
-
- @Override
- public void show() {
- dialog.open();
- }
-
- protected Value parseValue() {
- errorPanel.clear();
- Value value = null;
- String error = null;
- try {
- value = Values.parse(editor.getText()).orElse(null);
- if (value == null)
- error = managerMessages.emptyJsonData();
- } catch (ValueException ex) {
- error = ex.getMessage();
- }
- if (error != null) {
- errorPanel.add(new IconLabel("warning"));
- InlineLabel errorMessage = new InlineLabel(error);
- errorPanel.add(errorMessage);
- errorPanel.setVisible(true);
- return null;
- }
- errorPanel.setVisible(false);
- return value;
- }
-}
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/apps/ConsoleAppSelection.java b/client/src/main/java/org/openremote/app/client/apps/ConsoleAppSelection.java
index 45e70cf94..d17ba86c7 100644
--- a/client/src/main/java/org/openremote/app/client/apps/ConsoleAppSelection.java
+++ b/client/src/main/java/org/openremote/app/client/apps/ConsoleAppSelection.java
@@ -36,7 +36,7 @@ public class ConsoleAppSelection extends Event {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realm='" + realm + '\'' +
+ "realmId='" + realm + '\'' +
'}';
}
}
diff --git a/client/src/main/java/org/openremote/app/client/apps/ConsoleAppsPlace.java b/client/src/main/java/org/openremote/app/client/apps/ConsoleAppsPlace.java
index cf3886a40..c5747f160 100644
--- a/client/src/main/java/org/openremote/app/client/apps/ConsoleAppsPlace.java
+++ b/client/src/main/java/org/openremote/app/client/apps/ConsoleAppsPlace.java
@@ -56,7 +56,7 @@ public class ConsoleAppsPlace extends Place {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realm='" + realm + '\'' +
+ "realmId='" + realm + '\'' +
'}';
}
}
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java
index fe371d91b..999bd6af5 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java
@@ -20,9 +20,7 @@
package org.openremote.app.client.assets.asset;
import com.google.gwt.user.client.ui.IsWidget;
-import com.google.inject.Provider;
import org.openremote.app.client.Environment;
-import org.openremote.app.client.app.dialog.JsonEditor;
import org.openremote.app.client.assets.AssetBrowsingActivity;
import org.openremote.app.client.assets.attributes.AbstractAttributeViewExtension;
import org.openremote.app.client.assets.attributes.AttributeView;
@@ -41,7 +39,7 @@ import org.openremote.app.client.interop.value.ObjectValueMapper;
import org.openremote.app.client.mvp.AcceptsView;
import org.openremote.app.client.mvp.AppActivity;
import org.openremote.app.client.widget.FormButton;
-import org.openremote.app.client.widget.FormOutputText;
+import org.openremote.app.client.widget.ValueEditors;
import org.openremote.model.ValidationFailure;
import org.openremote.model.ValueHolder;
import org.openremote.model.asset.Asset;
@@ -54,11 +52,11 @@ import org.openremote.model.event.bus.EventRegistration;
import org.openremote.model.interop.Consumer;
import org.openremote.model.map.MapResource;
import org.openremote.model.security.Tenant;
-import org.openremote.model.value.*;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.ValueType;
import java.util.*;
-import static org.openremote.app.client.widget.ValueEditors.*;
import static org.openremote.model.util.TextUtil.isNullOrEmpty;
public abstract class AbstractAssetActivity<V
@@ -66,7 +64,6 @@ public abstract class AbstractAssetActivity<V
implements AssetBaseView.Presenter, AssetNavigation.Presenter {
protected final List<AttributeView> attributeViews = new ArrayList<>();
- protected final Provider<JsonEditor> jsonEditorProvider;
protected final boolean editMode;
protected final ObjectValueMapper objectValueMapper;
protected final MapResource mapResource;
@@ -80,7 +77,6 @@ public abstract class AbstractAssetActivity<V
public AbstractAssetActivity(Environment environment,
AssetBrowser.Presenter assetBrowserPresenter,
- Provider<JsonEditor> jsonEditorProvider,
ObjectValueMapper objectValueMapper,
MapResource mapResource,
boolean editMode) {
@@ -88,7 +84,6 @@ public abstract class AbstractAssetActivity<V
this.objectValueMapper = objectValueMapper;
this.mapResource = mapResource;
this.editMode = editMode;
- this.jsonEditorProvider = jsonEditorProvider;
}
@Override
@@ -439,66 +434,16 @@ public abstract class AbstractAssetActivity<V
boolean isReadOnly = isValueReadOnly(valueHolder);
Optional<Long> timestamp = getTimestamp(valueHolder);
- switch(valueType) {
- case OBJECT:
- ObjectValue currentValueObj = valueHolder.getValueAsObject().orElse(null);
- String label = environment.getMessages().jsonObject();
- String title = environment.getMessages().edit() + " " + environment.getMessages().jsonObject();
- return createObjectEditor(
- currentValueObj,
- onValueModified::accept,
- timestamp,
- isReadOnly,
- label,
- title,
- jsonEditorProvider.get()
- );
- case ARRAY:
- ArrayValue currentValueArray = valueHolder.getValueAsArray().orElse(null);
- label = environment.getMessages().jsonArray();
- title = environment.getMessages().edit() + " " + environment.getMessages().jsonArray();
- return createArrayEditor(
- currentValueArray,
- onValueModified::accept,
- timestamp,
- isReadOnly,
- label,
- title,
- jsonEditorProvider.get()
- );
- case STRING:
- StringValue currentValueStr = (StringValue)valueHolder.getValue().orElse(null);
- return createStringEditor(
- currentValueStr,
- onValueModified::accept,
- timestamp,
- isReadOnly,
- style.stringEditor()
- );
- case NUMBER:
- NumberValue currentValueNumber = (NumberValue)valueHolder.getValue().orElse(null);
- return createNumberEditor(
- currentValueNumber,
- onValueModified::accept,
- timestamp,
- isReadOnly,
- style.numberEditor()
- );
- case BOOLEAN:
- BooleanValue currentValueBool = (BooleanValue)valueHolder.getValue().orElse(null);
- return createBooleanEditor(
- currentValueBool,
- onValueModified::accept,
- timestamp,
- isReadOnly,
- style.booleanEditor()
- );
- default:
- return new FormOutputText(valueHolder instanceof MetaItem ?
- environment.getMessages().unsupportedMetaItemType(valueType.name()) :
- environment.getMessages().unsupportedValueType(valueType.name())
- );
- }
+ return ValueEditors.createValueEditor(
+ valueHolder.getValue().orElse(null),
+ valueType,
+ onValueModified,
+ timestamp,
+ isReadOnly,
+ getEditorStyleName(valueType, style),
+ environment.getWidgetStyle(),
+ environment.getMessages()
+ );
}
public void showValidationError(String attributeName, String metaItemName, ValidationFailure validationFailure) {
@@ -536,4 +481,18 @@ public abstract class AbstractAssetActivity<V
public void showFailureMessage(String failureMessage) {
environment.getEventBus().dispatch(new ShowFailureEvent(failureMessage, 5000));
}
+
+ protected String getEditorStyleName(ValueType valueType, AttributeView.Style style) {
+ switch (valueType) {
+
+ case STRING:
+ return style.stringEditor();
+ case NUMBER:
+ return style.numberEditor();
+ case BOOLEAN:
+ return style.booleanEditor();
+ default:
+ return null;
+ }
+ }
}
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
index cb67f35e4..9865710fc 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
@@ -20,9 +20,7 @@
package org.openremote.app.client.assets.asset;
import com.google.gwt.user.client.ui.IsWidget;
-import com.google.inject.Provider;
import org.openremote.app.client.Environment;
-import org.openremote.app.client.app.dialog.JsonEditor;
import org.openremote.app.client.assets.*;
import org.openremote.app.client.assets.attributes.*;
import org.openremote.app.client.assets.browser.AssetBrowser;
@@ -92,7 +90,6 @@ public class AssetEditActivity
@Inject
public AssetEditActivity(Environment environment,
AssetBrowser.Presenter assetBrowserPresenter,
- Provider<JsonEditor> jsonEditorProvider,
AssetEdit view,
AssetBrowser assetBrowser,
AssetResource assetResource,
@@ -107,7 +104,7 @@ public class AssetEditActivity
FileInfoMapper fileInfoMapper,
MapResource mapResource,
ObjectValueMapper objectValueMapper) {
- super(environment, assetBrowserPresenter, jsonEditorProvider, objectValueMapper, mapResource, true);
+ super(environment, assetBrowserPresenter, objectValueMapper, mapResource, true);
this.presenter = this;
this.view = view;
this.assetBrowser = assetBrowser;
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditImpl.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditImpl.java
index 8daa7a95f..7cc71d812 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditImpl.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditImpl.java
@@ -161,7 +161,6 @@ public class AssetEditImpl extends FormViewImpl implements AssetEdit {
final AssetBrowser assetBrowser;
final AssetNavigation assetNavigation;
- final Provider<JsonEditor> jsonEditorProvider;
final Environment environment;
Presenter presenter;
Asset asset;
@@ -170,11 +169,8 @@ public class AssetEditImpl extends FormViewImpl implements AssetEdit {
@Inject
public AssetEditImpl(AssetBrowser assetBrowser,
AssetNavigation assetNavigation,
- Provider<Confirmation> confirmationDialogProvider,
- Provider<JsonEditor> jsonEditorProvider,
Environment environment) {
- super(confirmationDialogProvider, environment.getWidgetStyle());
- this.jsonEditorProvider = jsonEditorProvider;
+ super(environment.getWidgetStyle());
this.assetBrowser = assetBrowser;
this.assetNavigation = assetNavigation;
this.environment = environment;
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
index f979f7b6a..d38e558a0 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
@@ -20,9 +20,7 @@
package org.openremote.app.client.assets.asset;
import com.google.gwt.http.client.URL;
-import com.google.inject.Provider;
import org.openremote.app.client.Environment;
-import org.openremote.app.client.app.dialog.JsonEditor;
import org.openremote.app.client.assets.AgentStatusEventMapper;
import org.openremote.app.client.assets.AssetMapper;
import org.openremote.app.client.assets.attributes.AbstractAttributeViewExtension;
@@ -81,7 +79,6 @@ public class AssetViewActivity
@Inject
public AssetViewActivity(Environment environment,
AssetBrowser.Presenter assetBrowserPresenter,
- Provider<JsonEditor> jsonEditorProvider,
AssetView view,
AssetResource assetResource,
AssetMapper assetMapper,
@@ -91,7 +88,7 @@ public class AssetViewActivity
NumberDatapointArrayMapper numberDatapointArrayMapper,
MapResource mapResource,
ObjectValueMapper objectValueMapper) {
- super(environment, assetBrowserPresenter, jsonEditorProvider, objectValueMapper, mapResource, false);
+ super(environment, assetBrowserPresenter, objectValueMapper, mapResource, false);
this.agentStatusEventMapper = agentStatusEventMapper;
this.presenter = this;
this.view = view;
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewImpl.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewImpl.java
index 9122d4998..ba9a77151 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewImpl.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewImpl.java
@@ -152,7 +152,6 @@ public class AssetViewImpl extends Composite implements AssetView {
final AssetBrowser assetBrowser;
final AssetNavigation assetNavigation;
- final Provider<JsonEditor> jsonEditorProvider;
final Environment environment;
final List<AttributeView> attributeViews = new ArrayList<>();
protected Presenter presenter;
@@ -161,11 +160,9 @@ public class AssetViewImpl extends Composite implements AssetView {
@Inject
public AssetViewImpl(AssetBrowser assetBrowser,
AssetNavigation assetNavigation,
- Environment environment,
- Provider<JsonEditor> jsonEditorProvider) {
+ Environment environment) {
this.assetBrowser = assetBrowser;
this.assetNavigation = assetNavigation;
- this.jsonEditorProvider = jsonEditorProvider;
this.environment = environment;
UI ui = GWT.create(UI.class);
diff --git a/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java b/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java
index f192e228a..6f64c307a 100644
--- a/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java
+++ b/client/src/main/java/org/openremote/app/client/assets/attributes/MetaEditor.java
@@ -31,7 +31,6 @@ import org.openremote.model.asset.agent.ProtocolDescriptor;
import org.openremote.model.attribute.AttributeValidationResult;
import org.openremote.model.attribute.MetaItem;
import org.openremote.model.attribute.MetaItemDescriptor;
-import org.openremote.model.interop.Supplier;
import org.openremote.model.util.EnumUtil;
import org.openremote.model.util.Pair;
import org.openremote.model.value.Value;
@@ -39,6 +38,7 @@ import org.openremote.model.value.ValueType;
import org.openremote.model.value.Values;
import java.util.*;
+import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
diff --git a/client/src/main/java/org/openremote/app/client/assets/attributes/ProtocolDiscoveryView.java b/client/src/main/java/org/openremote/app/client/assets/attributes/ProtocolDiscoveryView.java
index 2340bdf72..92f5d640d 100644
--- a/client/src/main/java/org/openremote/app/client/assets/attributes/ProtocolDiscoveryView.java
+++ b/client/src/main/java/org/openremote/app/client/assets/attributes/ProtocolDiscoveryView.java
@@ -30,12 +30,13 @@ import org.openremote.app.client.assets.browser.AssetBrowser;
import org.openremote.app.client.assets.browser.AssetSelector;
import org.openremote.app.client.assets.browser.AssetTreeNode;
import org.openremote.app.client.assets.browser.TenantTreeNode;
-import org.openremote.model.interop.BiConsumer;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.agent.ProtocolDescriptor;
import org.openremote.model.attribute.AttributeValidationResult;
import org.openremote.model.file.FileInfo;
+import java.util.function.BiConsumer;
+
public class ProtocolDiscoveryView extends AbstractAttributeViewExtension {
public static class DiscoveryRequest {
diff --git a/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowser.java b/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowser.java
index ba9356776..75b0e525c 100644
--- a/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowser.java
+++ b/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowser.java
@@ -53,6 +53,8 @@ public interface AssetBrowser extends IsWidget {
void selectTenant(String realmId);
+ void selectRealm(String realm);
+
void clearSelection();
BrowserTreeNode getSelectedNode();
diff --git a/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowserPresenter.java b/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowserPresenter.java
index 5903b1d22..57e725c9b 100644
--- a/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowserPresenter.java
+++ b/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowserPresenter.java
@@ -26,15 +26,16 @@ import org.openremote.app.client.assets.AssetArrayMapper;
import org.openremote.app.client.assets.AssetMapper;
import org.openremote.app.client.assets.AssetQueryMapper;
import org.openremote.model.asset.Asset;
+import org.openremote.model.interop.Consumer;
import org.openremote.model.query.AssetQuery;
import org.openremote.model.asset.AssetResource;
import org.openremote.model.asset.AssetTreeModifiedEvent;
import org.openremote.model.event.shared.TenantFilter;
-import org.openremote.model.interop.Consumer;
import org.openremote.model.query.filter.ParentPredicate;
import org.openremote.model.query.filter.TenantPredicate;
import org.openremote.model.security.Tenant;
import org.openremote.model.security.TenantResource;
+import org.openremote.model.util.TextUtil;
import javax.inject.Inject;
import java.util.ArrayList;
@@ -183,12 +184,25 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
loadAsset(assetId, this::selectAsset);
}
+ @Override
+ public void selectRealm(String realm) {
+ selectTenant(realm, false);
+ }
+
@Override
public void selectTenant(String realmId) {
- BrowserTreeNode selectedTenantNode = null;
- for (BrowserTreeNode tenantNode : tenantNodes) {
- if (tenantNode.getId().equals(realmId))
- selectedTenantNode = tenantNode;
+ selectTenant(realmId, true);
+ }
+
+ protected void selectTenant(String value, boolean compareId) {
+ TenantTreeNode selectedTenantNode = null;
+ if (!TextUtil.isNullOrEmpty(value)) {
+ for (TenantTreeNode tenantNode : tenantNodes) {
+ String matchValue = compareId ? tenantNode.getId() : tenantNode.getTenant().getRealm();
+
+ if (matchValue.equals(value))
+ selectedTenantNode = tenantNode;
+ }
}
if (selectedTenantNode != null) {
onNodeSelected(selectedTenantNode);
diff --git a/client/src/main/java/org/openremote/app/client/assets/browser/AssetSelector.java b/client/src/main/java/org/openremote/app/client/assets/browser/AssetSelector.java
index 3939b9c6b..f4ecc1096 100644
--- a/client/src/main/java/org/openremote/app/client/assets/browser/AssetSelector.java
+++ b/client/src/main/java/org/openremote/app/client/assets/browser/AssetSelector.java
@@ -4,7 +4,7 @@ import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import org.openremote.app.client.widget.*;
import org.openremote.app.client.i18n.ManagerMessages;
-import org.openremote.model.interop.Consumer;
+import java.util.function.Consumer;
/**
* Shows a browser tree node in a form group and encapsulates the process of
diff --git a/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantImpl.java b/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantImpl.java
index 5f9257229..7d7974e06 100644
--- a/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantImpl.java
+++ b/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantImpl.java
@@ -73,9 +73,8 @@ public class AssetsTenantImpl extends FormViewImpl implements AssetsTenant {
@Inject
public AssetsTenantImpl(AssetBrowser assetBrowser,
- Provider<Confirmation> confirmationDialogProvider,
Environment environment) {
- super(confirmationDialogProvider, environment.getWidgetStyle());
+ super(environment.getWidgetStyle());
this.assetBrowser = assetBrowser;
assetSelector = new AssetSelector(
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 f7e3382a2..730f9621c 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
@@ -22,6 +22,8 @@ package org.openremote.app.client.i18n;
import com.google.gwt.i18n.client.LocalizableResource;
import com.google.gwt.i18n.client.Messages;
import jsinterop.annotations.JsType;
+import org.openremote.app.client.notifications.FilterOptions;
+import org.openremote.app.client.notifications.NotificationEditorImpl;
@LocalizableResource.DefaultLocale
@JsType
@@ -69,6 +71,8 @@ public interface ManagerMessages extends Messages {
String cancel();
+ String close();
+
String filter();
String search();
@@ -451,11 +455,15 @@ public interface ManagerMessages extends Messages {
String message();
- String notificationAppUrl();
+ String notificationActionUrl();
+
+ String notificationSendFailure(String errorMsg);
- String enterTitleMessageAppurlForNotification();
+ String notificationSentSuccessfully();
- String notificationSentToUser();
+ String notificationMessageMissing();
+
+ String notificationTargetMissing();
String notificationOpenApplicationDetails();
@@ -483,8 +491,6 @@ public interface ManagerMessages extends Messages {
String notifications();
- String manageNotifications();
-
String allUsers();
String noNotifications();
@@ -493,7 +499,7 @@ public interface ManagerMessages extends Messages {
String deleteNotification();
- String deliveryStatus();
+ String status();
String action();
@@ -516,4 +522,28 @@ public interface ManagerMessages extends Messages {
String language();
String confirmationRulesLangChange();
+
+ String targets();
+
+ String sentIn();
+
+ String targetType();
+
+ String notificationType(@Select String type);
+
+ String targetTypes(@Select String type);
+
+ String sentInLast(@Select FilterOptions.SentInLast sentInLast);
+
+ String body();
+
+ String data();
+
+ String notificationData();
+
+ String notificationActionType(@Select NotificationEditorImpl.ActionType type);
+
+ String none();
+
+ String notificationBuildError();
}
diff --git a/client/src/main/java/org/openremote/app/client/map/MapTenantPlace.java b/client/src/main/java/org/openremote/app/client/map/MapTenantPlace.java
index 8e8520581..e794bc47f 100644
--- a/client/src/main/java/org/openremote/app/client/map/MapTenantPlace.java
+++ b/client/src/main/java/org/openremote/app/client/map/MapTenantPlace.java
@@ -55,7 +55,7 @@ public class MapTenantPlace extends MapPlace {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realm='" + realmId + '\'' +
+ "realmId='" + realmId + '\'' +
'}';
}
}
diff --git a/client/src/main/java/org/openremote/app/client/notifications/FilterOptions.java b/client/src/main/java/org/openremote/app/client/notifications/FilterOptions.java
new file mode 100644
index 000000000..22ac4df80
--- /dev/null
+++ b/client/src/main/java/org/openremote/app/client/notifications/FilterOptions.java
@@ -0,0 +1,174 @@
+/*
+ * 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 org.openremote.model.notification.Notification;
+import org.openremote.model.notification.PushNotificationMessage;
+import org.openremote.model.util.TextUtil;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public class FilterOptions {
+
+ protected final static String[] NOTIFICATION_TYPES = new String[] {
+ PushNotificationMessage.TYPE
+ };
+
+ protected final static String[] TARGET_TYPES = new String[] {
+ Notification.TargetType.USER.name(),
+ Notification.TargetType.ASSET.name()
+ };
+
+ public enum SentInLast {
+ DAY,
+ WEEK,
+ MONTH
+ }
+
+ final protected Map<String, String> realms;
+ final protected BiConsumer<FilterOptions, Consumer<Map<String, String>>> targetsSupplier;
+ protected Map<String, String> targets = new HashMap<>();
+ protected String selectedNotificationType = NOTIFICATION_TYPES[0]; // Only one type at the moment so select it
+ protected String selectedRealm;
+ protected Notification.TargetType selectedTargetType;
+ protected String selectedTarget;
+ protected SentInLast selectedSentIn = SentInLast.DAY;
+ protected Runnable targetsChangedCallback;
+ protected Runnable changedCallback;
+
+ public FilterOptions(Map<String, String> realms, BiConsumer<FilterOptions, Consumer<Map<String, String>>> targetsSupplier) {
+ this.realms = realms;
+ this.targetsSupplier = targetsSupplier;
+ }
+
+ public String[] getNotificationTypes() {
+ return NOTIFICATION_TYPES;
+ }
+
+ public String[] getTargetTypes() {
+ return TARGET_TYPES;
+ }
+
+ public Map<String, String> getRealms() {
+ return realms;
+ }
+
+ public Map<String, String> getTargets() {
+ return targets;
+ }
+
+ protected void setTargets(Map<String, String> targets) {
+ this.targets = targets;
+
+ if (targets == null || !targets.containsKey(selectedTarget)) {
+ selectedTarget = null;
+ }
+
+ if (targetsChangedCallback != null) {
+ targetsChangedCallback.run();
+ }
+ }
+
+ public String getSelectedNotificationType() {
+ return selectedNotificationType;
+ }
+
+ public void setSelectedNotificationType(String selectedNotificationType) {
+ if (Objects.equals(selectedNotificationType, this.selectedNotificationType)) {
+ return;
+ }
+ this.selectedNotificationType = selectedNotificationType;
+ notifyChangedCallback();
+ }
+
+ public String getSelectedRealm() {
+ return selectedRealm;
+ }
+
+ public void setSelectedRealm(String selectedRealm) {
+ this.selectedRealm = selectedRealm;
+ this.selectedTarget = null;
+ notifyChangedCallback();
+ refreshTargets();
+ }
+
+ public Notification.TargetType getSelectedTargetType() {
+ return selectedTargetType;
+ }
+
+ public void setSelectedTargetType(String selectedTargetType) {
+ Notification.TargetType targetType = null;
+ if (!TextUtil.isNullOrEmpty(selectedTargetType)) {
+ try {
+ targetType = Notification.TargetType.valueOf(selectedTargetType);
+ } catch (IllegalArgumentException ignored) {
+ }
+ }
+ setSelectedTargetType(targetType);
+ }
+
+ public void setSelectedTargetType(Notification.TargetType selectedTargetType) {
+ this.selectedTargetType = selectedTargetType;
+ this.selectedTarget = null;
+ notifyChangedCallback();
+ refreshTargets();
+ }
+
+ public String getSelectedTarget() {
+ return selectedTarget;
+ }
+
+ public void setSelectedTarget(String selectedTarget) {
+ this.selectedTarget = selectedTarget;
+ notifyChangedCallback();
+ }
+
+ public SentInLast getSelectedSentIn() {
+ return selectedSentIn;
+ }
+
+ public void setSelectedSentIn(SentInLast selectedSentIn) {
+ this.selectedSentIn = selectedSentIn;
+ notifyChangedCallback();
+ }
+
+ public void setTargetsChangedCallback(Runnable targetsChangedCallback) {
+ this.targetsChangedCallback = targetsChangedCallback;
+ }
+
+ public void setChangedCallback(Runnable filterOptionsChangedCallback) {
+ this.changedCallback = filterOptionsChangedCallback;
+ }
+
+ protected void refreshTargets() {
+ setTargets(null);
+ targetsSupplier.accept(this, this::setTargets);
+ }
+
+ protected void notifyChangedCallback() {
+ if (changedCallback != null) {
+ changedCallback.run();
+ }
+ }
+}
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationEditor.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationEditor.java
similarity index 70%
rename from client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationEditor.java
rename to client/src/main/java/org/openremote/app/client/notifications/NotificationEditor.java
index b265c23f0..2e1417fed 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationEditor.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationEditor.java
@@ -17,20 +17,21 @@
* 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.admin.users.notifications;
+package org.openremote.app.client.notifications;
-import org.openremote.model.interop.Consumer;
-import org.openremote.model.notification.Notification;
+import org.openremote.model.notification.NotificationSendResult;
-public interface AdminUserNotificationEditor {
+public interface NotificationEditor {
void reset();
- void setNotification(Notification notification);
+ void setSendOptions(SendOptions options);
- void setOnSend(Consumer<Notification> onSend);
-
- void setOnClose(Runnable onClose);
+ void setOnSend(Runnable onSend);
void show();
+
+ void setResult(NotificationSendResult result);
+
+ void setBusy(boolean busy);
}
\ No newline at end of file
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
new file mode 100644
index 000000000..d866fee89
--- /dev/null
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java
@@ -0,0 +1,537 @@
+/*
+ * 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.google.gwt.user.client.ui.*;
+import org.openremote.app.client.app.dialog.Dialog;
+import org.openremote.app.client.i18n.ManagerMessages;
+import org.openremote.app.client.style.WidgetStyle;
+import org.openremote.app.client.widget.*;
+import org.openremote.app.client.widget.PushButton;
+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.Value;
+import org.openremote.model.value.ValueType;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Locale;
+import java.util.Optional;
+
+import static org.openremote.app.client.widget.ValueEditors.createValueEditor;
+import static org.openremote.model.util.TextUtil.isNullOrEmpty;
+
+public class NotificationEditorImpl implements NotificationEditor {
+
+ public enum ActionType {
+ GET,
+ DISMISS,
+ POST,
+ PUT,
+ DELETE,
+ GET_SILENT,
+ POST_SILENT,
+ PUT_SILENT,
+ DELETE_SILENT,
+ GET_INBROWSER,
+ POST_INBROWSER,
+ PUT_INBROWSER,
+ DELETE_INBROWSER
+ }
+
+ final protected Dialog dialog;
+ final protected WidgetStyle widgetStyle;
+ final protected ManagerMessages managerMessages;
+
+ final protected PushButton sendButton = new PushButton();
+ final protected FlowPanel resultPanel = new FlowPanel();
+ final protected FormListBox realmsList = new FormListBox();
+ final protected FormListBox targetTypesList = new FormListBox();
+ final protected FormGroup targetsGroup = new FormGroup();
+ final protected FormListBox targetsList = new FormListBox();
+ final protected FormListBox typesList = new FormListBox();
+ final protected Form form = new Form();
+ final protected FlowPanel messagePanel = new FlowPanel();
+
+ final protected FormInputText notificationTitleInput = new FormInputText();
+ final protected FormTextArea notificationMessageInput = new FormTextArea();
+ final protected FormInputText notificationAppUrlInput = new FormInputText();
+
+ protected SendOptions sendOptions;
+ protected Runnable onSend;
+ protected Runnable onClose;
+ protected AbstractNotificationMessage message;
+
+ @Inject
+ public NotificationEditorImpl(WidgetStyle widgetStyle,
+ ManagerMessages managerMessages) {
+ this.dialog = new Dialog();
+ this.widgetStyle = widgetStyle;
+ this.managerMessages = managerMessages;
+
+ dialog.setHeaderLabel(managerMessages.sendNotification());
+
+ dialog.setModal(true);
+ dialog.setAutoHideOnHistoryEvents(true);
+ dialog.addStyleName(widgetStyle.NotificationEditor());
+
+ sendButton.setFocus(true);
+ sendButton.setText(managerMessages.sendNotification());
+ sendButton.setIcon("send");
+ sendButton.addStyleName(widgetStyle.FormControl());
+ sendButton.addStyleName(widgetStyle.PushButton());
+ sendButton.addStyleName(widgetStyle.FormButtonPrimary());
+ sendButton.addClickHandler(event -> {
+ if (onSend != null)
+ onSend.run();
+ });
+ dialog.getFooterPanel().add(sendButton);
+
+ PushButton cancelButton = new PushButton();
+ cancelButton.setText(managerMessages.close());
+ cancelButton.setIcon("close");
+ cancelButton.addStyleName(widgetStyle.FormControl());
+ cancelButton.addStyleName(widgetStyle.PushButton());
+ cancelButton.addStyleName(widgetStyle.FormButton());
+ cancelButton.addClickHandler(event -> {
+ dialog.close();
+ if (onClose != null)
+ onClose.run();
+ });
+ dialog.getFooterPanel().add(cancelButton);
+
+ resultPanel.setStyleName("flex-none layout horizontal");
+ resultPanel.addStyleName(widgetStyle.FormMessages());
+ resultPanel.setVisible(false);
+ dialog.getContentPanel().add(resultPanel);
+
+ dialog.getContentPanel().add(form);
+
+ FormGroup realmsGroup = new FormGroup();
+ FormLabel realmsLabel = new FormLabel(managerMessages.realm());
+ realmsGroup.setFormLabel(realmsLabel);
+ FormField realmsField = new FormField();
+ realmsGroup.setFormField(realmsField);
+ realmsField.add(realmsList);
+ form.add(realmsGroup);
+
+ FormGroup targetTypeGroup = new FormGroup();
+ FormLabel targetTypeLabel = new FormLabel(managerMessages.targetType());
+ targetTypeGroup.setFormLabel(targetTypeLabel);
+ FormField targetTypeField = new FormField();
+ targetTypeGroup.setFormField(targetTypeField);
+ targetTypeField.add(targetTypesList);
+ form.add(targetTypeGroup);
+
+ FormLabel targetsLabel = new FormLabel(managerMessages.targets());
+ targetsGroup.setFormLabel(targetsLabel);
+ FormField targetsField = new FormField();
+ targetsGroup.setFormField(targetsField);
+ targetsField.add(targetsList);
+ form.add(targetsGroup);
+
+ FormGroup typeGroup = new FormGroup();
+ FormLabel typeLabel = new FormLabel(managerMessages.type());
+ typeGroup.setFormLabel(typeLabel);
+ FormField typeField = new FormField();
+ typeGroup.setFormField(typeField);
+ typeField.add(typesList);
+ form.add(typeGroup);
+
+ messagePanel.setStyleName("flex-none layout vertical");
+ messagePanel.setVisible(false);
+ form.add(messagePanel);
+
+ // Add change handlers
+ realmsList.addChangeHandler(event -> {
+ if (sendOptions != null) {
+ sendOptions.setSelectedRealm(realmsList.getSelectedValue());
+
+ if (sendOptions.getSelectedTargetType() == Notification.TargetType.TENANT) {
+ sendOptions.setSelectedTarget(realmsList.getSelectedValue());
+ }
+ }
+ });
+
+ targetTypesList.addChangeHandler(event -> {
+ if (sendOptions != null) {
+ sendOptions.setSelectedTargetType(targetTypesList.getSelectedValue());
+ targetsGroup.setVisible(sendOptions.getSelectedTargetType() != Notification.TargetType.TENANT);
+ }
+ });
+
+ targetsList.addChangeHandler(event -> {
+ if (sendOptions != null) {
+ sendOptions.setSelectedTarget(targetsList.getSelectedValue());
+ }
+ });
+
+ typesList.addChangeHandler(event -> {
+ if (sendOptions != null) {
+ sendOptions.setSelectedNotificationType(typesList.getSelectedValue());
+ }
+ updateMessagePanel();
+ });
+ }
+
+ @Override
+ public void reset() {
+ setSendOptions(null);
+ onSend = null;
+ onClose = null;
+ message = null;
+ resultPanel.clear();
+ messagePanel.clear();
+ notificationTitleInput.setValue(null);
+ notificationMessageInput.setValue(null);
+ notificationAppUrlInput.setValue(null);
+ }
+
+ @Override
+ public void setSendOptions(SendOptions sendOptions) {
+ if (this.sendOptions != null) {
+ this.sendOptions.setTargetsChangedCallback(null);
+ }
+
+ typesList.clear();
+ realmsList.clear();
+ targetTypesList.clear();
+ targetsList.clear();
+
+ this.sendOptions = sendOptions;
+
+ if (sendOptions == null) {
+ return;
+ }
+
+ sendOptions.setTargetsChangedCallback(this::onTargetsChanged);
+
+ // Type List
+ Arrays.stream(sendOptions.getNotificationTypes()).forEach(notificationType ->
+ typesList.addItem(managerMessages.notificationType(notificationType), notificationType));
+
+ if (typesList.getItemCount() > 1) {
+ typesList.insertItem("", 0);
+ }
+ typesList.selectItem(sendOptions.getSelectedNotificationType());
+
+ // Realm List
+ sendOptions.getRealms().forEach((name, value) ->
+ realmsList.addItem(value, name)
+ );
+ if (realmsList.getItemCount() > 1) {
+ realmsList.insertItem("", 0);
+ }
+ realmsList.selectItem(sendOptions.getSelectedRealm());
+
+ // Target Types
+ Arrays.stream(sendOptions.getTargetTypes()).forEach(targetType ->
+ targetTypesList.addItem(managerMessages.targetTypes(targetType), targetType));
+ if (targetTypesList.getItemCount() > 1) {
+ targetTypesList.insertItem("", 0);
+ targetTypesList.setSelectedIndex(0);
+ }
+ targetTypesList.selectItem(sendOptions.getSelectedTargetType() != null ? sendOptions.getSelectedTargetType().name() : null);
+
+ // Only show target group list when target type is not TENANT
+ targetsGroup.setVisible(sendOptions.getSelectedTargetType() != Notification.TargetType.TENANT);
+
+ // Targets
+ onTargetsChanged();
+
+ updateMessagePanel();
+ }
+
+ protected void onTargetsChanged() {
+ targetsList.clear();
+
+ if (sendOptions.getTargets() == null) {
+ return;
+ }
+
+ sendOptions.getTargets().forEach((name, value) -> targetsList.addItem(value, name));
+
+ if (targetsList.getItemCount() > 1) {
+ targetsList.insertItem("", 0);
+ targetsList.setSelectedIndex(0);
+ }
+
+ if (sendOptions.getSelectedTargetType() == Notification.TargetType.TENANT) {
+ targetsList.selectItem(sendOptions.getSelectedRealm());
+ } else {
+ targetsList.selectItem(sendOptions.getSelectedTarget());
+ }
+ }
+
+ protected void updateMessagePanel() {
+ if (sendOptions == null) {
+ messagePanel.clear();
+ return;
+ }
+
+ if (sendOptions.getMessage() != message) {
+ messagePanel.clear();
+ message = sendOptions.getMessage();
+ if (message != null) {
+ switch (message.getType()) {
+ case PushNotificationMessage.TYPE:
+ buildPushMessageEditor();
+ }
+ messagePanel.setVisible(true);
+ }
+ }
+ }
+
+ protected void buildPushMessageEditor() {
+ PushNotificationMessage message = (PushNotificationMessage)this.message;
+
+ if (message.getAction() == null) {
+ message.setAction(new PushNotificationAction("", null, false, false, "GET"));
+ }
+
+ FormGroup titleGroup = new FormGroup();
+ FormLabel titleLabel = new FormLabel(managerMessages.title());
+ titleGroup.setFormLabel(titleLabel);
+ FormField titleField = new FormField();
+ titleGroup.setFormField(titleField);
+ FormInputText titleInput = new FormInputText(message.getTitle());
+ titleInput.addStyleName("flex");
+ titleField.add(titleInput);
+ messagePanel.add(titleGroup);
+
+ FormGroup bodyGroup = new FormGroup();
+ FormLabel bodyLabel = new FormLabel(managerMessages.body());
+ bodyGroup.setFormLabel(bodyLabel);
+ FormField bodyField = new FormField();
+ bodyGroup.setFormField(bodyField);
+ FormInputText bodyInput = new FormInputText(message.getBody());
+ bodyInput.addStyleName("flex");
+ bodyField.add(bodyInput);
+ messagePanel.add(bodyGroup);
+
+ FormGroup actionGroup = new FormGroup();
+ FormLabel actionLabel = new FormLabel(managerMessages.action());
+ actionGroup.setFormLabel(actionLabel);
+ FormField actionField = new FormField();
+ actionGroup.setFormField(actionField);
+ createActionEditor(actionField, null, message.getAction(), null, this::onMessageActionChanged);
+ messagePanel.add(actionGroup);
+
+ 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 -> {
+
+ },
+ timestamp,
+ false,
+ widgetStyle,
+ managerMessages
+ ));
+
+ titleInput.addChangeHandler(event -> message.setTitle(titleInput.getValue()));
+ bodyInput.addChangeHandler(event -> message.setBody(bodyInput.getValue()));
+
+ }
+
+ protected void onMessageActionChanged(PushNotificationAction action) {
+
+ }
+
+ protected void createActionEditor(FormField parent, String title, PushNotificationAction action, Consumer<String> titleChangedCallback, Consumer<PushNotificationAction> actionChangedCallback) {
+
+ final FormInputText titleInput = new FormInputText(title);
+
+ if (title != null && titleChangedCallback != null) {
+ FormLabel titleLabel = new FormLabel(managerMessages.title());
+ parent.add(titleLabel);
+ parent.add(titleInput);
+ }
+
+ FormListBox typesList = new FormListBox();
+ parent.add(typesList);
+
+ Arrays.stream(ActionType.values()).forEach(actionType ->
+ typesList.addItem(managerMessages.notificationActionType(actionType), actionType.name())
+ );
+
+ // Initialise the type list value
+ ActionType selectedActionType = action.getHttpMethod() == null ?
+ ActionType.DISMISS : ActionType.valueOf(action.getHttpMethod().toUpperCase(Locale.ROOT));
+ if (selectedActionType != ActionType.DISMISS) {
+ if (action.isSilent()) {
+ selectedActionType = ActionType.valueOf(selectedActionType.name() + "_SILENT");
+ } else if (action.isOpenInBrowser()) {
+ selectedActionType = ActionType.valueOf(selectedActionType.name() + "_INBROWSER");
+ }
+ }
+ typesList.selectItem(selectedActionType.name());
+
+ FormLabel urlLabel = new FormLabel(managerMessages.notificationActionUrl());
+ urlLabel.addStyleName(widgetStyle.NotificationActionLabel());
+ FormInputText urlInput = new FormInputText(action.getUrl());
+ urlLabel.setVisible(!ActionType.DISMISS.name().equals(typesList.getSelectedValue()));
+ urlInput.setVisible(urlLabel.isVisible());
+ parent.add(urlLabel);
+ parent.add(urlInput);
+
+ FormLabel dataLabel = new FormLabel(managerMessages.data());
+ dataLabel.addStyleName(widgetStyle.NotificationActionLabel());
+ FlowPanel dataEditorPanel = new FlowPanel();
+ dataEditorPanel.setStyleName("flex-none layout horizontal");
+
+ FormListBox dataTypeList = new FormListBox();
+ dataTypeList.addItem(managerMessages.none(), "");
+ Arrays.stream(ValueType.values())
+ .map(Enum::name)
+ .map(valueType -> new Pair<>(managerMessages.valueTypeDisplayName(valueType), valueType))
+ .sorted(Comparator.comparing(typeEntry -> typeEntry.key))
+ .forEach(typeEntry -> dataTypeList.addItem(typeEntry.key, typeEntry.value));
+ ValueType currentValueType = Optional.ofNullable(action.getData()).map(Value::getType).orElse(null);
+ dataTypeList.selectItem(currentValueType != null ? currentValueType.name() : null);
+ dataEditorPanel.add(dataTypeList);
+ updateActionDataValueEditor(dataEditorPanel, action.getData(), currentValueType, action::setData);
+
+ dataLabel.setVisible(!ActionType.DISMISS.name().equals(typesList.getSelectedValue()));
+ dataEditorPanel.setVisible(dataLabel.isVisible());
+ parent.add(dataLabel);
+ parent.add(dataEditorPanel);
+
+ // Add change handlers
+ if (titleChangedCallback != null) {
+ titleInput.addChangeHandler(event -> titleChangedCallback.accept(titleInput.getValue()));
+ }
+
+ urlInput.addChangeHandler(event -> {
+ action.setUrl(urlInput.getValue());
+ actionChangedCallback.accept(action);
+ });
+
+ typesList.addChangeHandler(event -> {
+ ActionType actionType = ActionType.valueOf(typesList.getSelectedValue());
+ switch (actionType) {
+
+ case DISMISS:
+ action.setUrl(null);
+ action.setHttpMethod(null);
+ action.setOpenInBrowser(false);
+ action.setSilent(true);
+ action.setData(null);
+ urlLabel.setVisible(false);
+ urlInput.setVisible(false);
+ dataLabel.setVisible(false);
+ dataEditorPanel.setVisible(false);
+ break;
+
+ default:
+ String[] actionTypeArr = actionType.name().split("_");
+ action.setUrl(urlInput.getValue());
+ action.setHttpMethod(actionTypeArr[0]);
+ action.setOpenInBrowser(actionTypeArr.length == 2 && "INBROWSER".equals(actionTypeArr[1]));
+ action.setSilent(actionTypeArr.length == 2 && "SILENT".equals(actionTypeArr[1]));
+ urlLabel.setVisible(true);
+ urlInput.setVisible(true);
+ dataLabel.setVisible(true);
+ dataEditorPanel.setVisible(true);
+ break;
+ }
+ });
+
+ dataTypeList.addChangeHandler(event -> {
+ ValueType newValueType = TextUtil.isNullOrEmpty(dataTypeList.getSelectedValue()) ?
+ null : ValueType.valueOf(dataTypeList.getSelectedValue());
+ updateActionDataValueEditor(dataEditorPanel, action.getData(), newValueType, action::setData);
+ });
+ }
+
+ protected void updateActionDataValueEditor(FlowPanel editorParent,
+ Value currentValue,
+ ValueType valueType,
+ Consumer<Value> onValueModified) {
+
+ if (editorParent.getWidgetCount() > 1) {
+ editorParent.remove(1);
+ }
+
+ if (valueType != null) {
+ IsWidget editor = createValueEditor(
+ currentValue,
+ valueType,
+ onValueModified,
+ Optional.empty(),
+ false,
+ null,
+ widgetStyle,
+ managerMessages
+ );
+
+ editorParent.add(editor);
+ }
+ }
+
+ @Override
+ public void setResult(NotificationSendResult result) {
+ resultPanel.clear();
+ resultPanel.setVisible(false);
+
+ if (result != null) {
+ if (result.isSuccess()) {
+ resultPanel.add(new IconLabel("check"));
+ resultPanel.removeStyleName("error");
+ resultPanel.addStyleName("success");
+ resultPanel.add(new InlineLabel(managerMessages.notificationSentSuccessfully()));
+ } else {
+ resultPanel.add(new IconLabel("warning"));
+ resultPanel.addStyleName("error");
+ resultPanel.removeStyleName("success");
+ resultPanel.add(new InlineLabel(managerMessages.notificationSendFailure(result.getMessage())));
+ }
+ resultPanel.setVisible(true);
+ }
+ }
+
+ @Override
+ public void setBusy(boolean busy) {
+ form.setBusy(busy);
+ sendButton.setEnabled(!busy);
+ }
+
+ @Override
+ public void setOnSend(Runnable onSend) {
+ this.onSend = onSend;
+ }
+
+ public void setOnClose(Runnable onClose) {
+ this.onClose = onClose;
+ }
+
+ public void show() {
+ dialog.open();
+ }
+}
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/notifications/NotificationMapper.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationMapper.java
similarity index 95%
rename from client/src/main/java/org/openremote/app/client/admin/users/notifications/NotificationMapper.java
rename to client/src/main/java/org/openremote/app/client/notifications/NotificationMapper.java
index 7aff13cdd..87e4ba430 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/notifications/NotificationMapper.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationMapper.java
@@ -17,7 +17,7 @@
* 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.admin.users.notifications;
+package org.openremote.app.client.notifications;
import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
diff --git a/client/src/main/java/org/openremote/app/client/notifications/NotificationsActivity.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationsActivity.java
new file mode 100644
index 000000000..5590242c4
--- /dev/null
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationsActivity.java
@@ -0,0 +1,457 @@
+/*
+ * 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 org.openremote.app.client.Environment;
+import org.openremote.app.client.admin.CredentialMapper;
+import org.openremote.app.client.admin.RoleArrayMapper;
+import org.openremote.app.client.admin.TenantArrayMapper;
+import org.openremote.app.client.admin.UserArrayMapper;
+import org.openremote.app.client.assets.AssetArrayMapper;
+import org.openremote.app.client.assets.AssetBrowsingActivity;
+import org.openremote.app.client.assets.AssetMapper;
+import org.openremote.app.client.assets.AssetQueryMapper;
+import org.openremote.app.client.assets.browser.AssetBrowser;
+import org.openremote.app.client.assets.browser.AssetBrowserSelection;
+import org.openremote.app.client.assets.browser.AssetTreeNode;
+import org.openremote.app.client.assets.browser.TenantTreeNode;
+import org.openremote.app.client.event.ShowSuccessEvent;
+import org.openremote.app.client.mvp.AcceptsView;
+import org.openremote.app.client.mvp.AppActivity;
+import org.openremote.model.asset.Asset;
+import org.openremote.model.asset.AssetResource;
+import org.openremote.model.event.bus.EventBus;
+import org.openremote.model.event.bus.EventRegistration;
+import org.openremote.model.notification.*;
+import org.openremote.model.query.AssetQuery;
+import org.openremote.model.query.BaseAssetQuery;
+import org.openremote.model.query.filter.TenantPredicate;
+import org.openremote.model.security.Tenant;
+import org.openremote.model.security.TenantResource;
+import org.openremote.model.security.User;
+import org.openremote.model.security.UserResource;
+import org.openremote.model.util.TextUtil;
+
+import javax.inject.Inject;
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+public class NotificationsActivity extends AssetBrowsingActivity<NotificationsPlace> implements NotificationsView.Presenter {
+
+ final protected TenantResource tenantResource;
+ final protected TenantArrayMapper tenantArrayMapper;
+ final protected UserResource userResource;
+ final protected UserArrayMapper userArrayMapper;
+ final protected AssetResource assetResource;
+ final protected AssetMapper assetMapper;
+ final protected AssetArrayMapper assetArrayMapper;
+ final protected AssetQueryMapper assetQueryMapper;
+ final protected CredentialMapper credentialMapper;
+ final protected RoleArrayMapper roleArrayMapper;
+ final protected NotificationEditor notificationEditor;
+ final protected NotificationResource notificationResource;
+ final protected NotificationMapper notificationMapper;
+ final protected SentNotificationArrayMapper sentNotificationArrayMapper;
+ final protected NotificationsView view;
+
+ protected Tenant[] tenants;
+ protected NotificationsPlace place;
+ protected FilterOptions filterOptions;
+ protected SendOptions sendOptions;
+ protected SentNotification[] sentNotifications;
+
+ @Inject
+ public NotificationsActivity(Environment environment,
+ AssetBrowser.Presenter assetBrowserPresenter,
+ NotificationsView view,
+ TenantResource tenantResource,
+ TenantArrayMapper tenantArrayMapper,
+ AssetResource assetResource,
+ AssetMapper assetMapper,
+ AssetArrayMapper assetArrayMapper,
+ AssetQueryMapper assetQueryMapper,
+ UserResource userResource,
+ UserArrayMapper userArrayMapper,
+ CredentialMapper credentialMapper,
+ RoleArrayMapper roleArrayMapper,
+ NotificationEditor notificationEditor,
+ NotificationResource notificationResource,
+ NotificationMapper notificationMapper,
+ SentNotificationArrayMapper sentNotificationArrayMapper) {
+ super(environment, assetBrowserPresenter);
+ this.view = view;
+ this.tenantResource = tenantResource;
+ this.tenantArrayMapper = tenantArrayMapper;
+ this.assetResource = assetResource;
+ this.assetMapper = assetMapper;
+ this.assetArrayMapper = assetArrayMapper;
+ this.assetQueryMapper = assetQueryMapper;
+ this.userResource = userResource;
+ this.userArrayMapper = userArrayMapper;
+ this.credentialMapper = credentialMapper;
+ this.roleArrayMapper = roleArrayMapper;
+ this.notificationEditor = notificationEditor;
+ this.notificationResource = notificationResource;
+ this.notificationMapper = notificationMapper;
+ this.sentNotificationArrayMapper = sentNotificationArrayMapper;
+ }
+
+ @Override
+ public void start(AcceptsView container, EventBus eventBus, Collection<EventRegistration> registrations) {
+ view.setPresenter(this);
+ container.setWidget(view.asWidget());
+
+ registrations.add(eventBus.register(AssetBrowserSelection.class, event -> {
+ String realm = null;
+ String assetId = null;
+ if (event.getSelectedNode() instanceof TenantTreeNode) {
+ realm = ((TenantTreeNode) event.getSelectedNode()).getTenant().getRealm();
+ } else if (event.getSelectedNode() instanceof AssetTreeNode) {
+ realm = ((AssetTreeNode) event.getSelectedNode()).getAsset().getTenantRealm();
+ assetId = event.getSelectedNode().getId();
+ }
+
+ if (!Objects.equals(this.place.getRealm(), realm) || !Objects.equals(this.place.getAssetId(), assetId)) {
+ environment.getPlaceController().goTo(new NotificationsPlace(realm, assetId));
+ }
+ }));
+
+ view.setBusy(true);
+
+ // Build filter options
+ if (filterOptions != null) {
+ filterOptions.setChangedCallback(null);
+ filterOptions.setTargetsChangedCallback(null);
+ filterOptions = null;
+ }
+
+ loadTenants(tenants -> {
+ Map<String, String> realms = Arrays.stream(tenants)
+ .collect(Collectors.toMap(Tenant::getRealm, Tenant::getDisplayName));
+
+ filterOptions = new FilterOptions(realms, this::loadTargets);
+
+ String selectedRealm = !TextUtil.isNullOrEmpty(place.getRealm()) && realms.containsKey(place.getRealm())
+ ? place.getRealm() : null;
+
+ filterOptions.setSelectedRealm(selectedRealm);
+
+ if (selectedRealm != null && !TextUtil.isNullOrEmpty(place.getAssetId())) {
+ filterOptions.setSelectedTargetType(Notification.TargetType.ASSET);
+ filterOptions.setSelectedTarget(place.getAssetId());
+ }
+
+ filterOptions.setChangedCallback(this::onFilterOptionsChanged);
+ view.setFilterOptions(filterOptions);
+ view.setBusy(false);
+ onFilterOptionsChanged();
+ });
+ }
+
+ @Override
+ public void refreshNotifications() {
+ view.setBusy(true);
+ refreshNotifications(notifications -> {
+ sentNotifications = notifications;
+ view.setNotifications(notifications);
+ view.setDeleteAllEnabled(notifications.length > 0);
+ view.setBusy(false);
+ });
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ notificationEditor.reset();
+ view.setPresenter(null);
+ }
+
+ @Override
+ public void showNotificationEditor() {
+
+ notificationEditor.setResult(null);
+
+ loadTenants(tenants -> {
+ Map<String, String> realms = Arrays.stream(tenants)
+ .collect(Collectors.toMap(Tenant::getRealm, Tenant::getDisplayName));
+
+ if (sendOptions == null) {
+ sendOptions = new SendOptions(realms, this::loadTargets, this::createMessage);
+ }
+
+ String selectedRealm = !TextUtil.isNullOrEmpty(place.getRealm()) && realms.containsKey(place.getRealm())
+ ? place.getRealm() : null;
+
+ sendOptions.setSelectedTargetType((Notification.TargetType)null);
+ sendOptions.setSelectedRealm(selectedRealm);
+
+ if (selectedRealm != null && !TextUtil.isNullOrEmpty(place.getAssetId())) {
+ sendOptions.setSelectedTargetType(Notification.TargetType.ASSET);
+ sendOptions.setSelectedTarget(place.getAssetId());
+ }
+
+ notificationEditor.setSendOptions(sendOptions);
+ notificationEditor.setOnSend(() -> sendNotification(notificationEditor::setResult));
+ notificationEditor.show();
+ });
+ }
+
+ protected AbstractNotificationMessage createMessage() {
+ if (sendOptions == null) {
+ return null;
+ }
+
+ switch (sendOptions.getSelectedNotificationType()) {
+ case PushNotificationMessage.TYPE:
+ return new PushNotificationMessage();
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public void deleteNotifications() {
+ environment.getApp().getRequests().send(
+ requestParams -> notificationResource.removeNotifications(requestParams,
+ Arrays.stream(sentNotifications)
+ .map(SentNotification::getId)
+ .collect(Collectors.toList()),
+ null,
+ null,
+ null,
+ null,
+ null),
+ 204,
+ () -> {
+ environment.getEventBus().dispatch(new ShowSuccessEvent(
+ environment.getMessages().notificationsDeleted())
+ );
+ refreshNotifications();
+ }
+ );
+ }
+
+ @Override
+ public void deleteNotification(Long id) {
+ environment.getApp().getRequests().send(
+ requestParams -> notificationResource.removeNotification(requestParams, id),
+ 204,
+ () -> {
+ view.removeNotification(id);
+ environment.getEventBus().dispatch(new ShowSuccessEvent(
+ environment.getMessages().notificationDeleted(id))
+ );
+ }
+ );
+ }
+
+ @Override
+ protected String[] getRequiredRoles() {
+ return new String[]{"read:admin", "write:admin"};
+ }
+
+ @Override
+ protected AppActivity<NotificationsPlace> init(NotificationsPlace place) {
+ this.place = place;
+ return this;
+ }
+
+ protected void sendNotification(Consumer<NotificationSendResult> sendResultConsumer) {
+ notificationEditor.setBusy(true);
+
+ if (sendOptions.getMessage() == null) {
+ sendResultConsumer.accept(NotificationSendResult.failure(
+ environment.getMessages().notificationMessageMissing()
+ ));
+ notificationEditor.setBusy(false);
+ return;
+ }
+
+ if (sendOptions.getSelectedTargetType() == null || TextUtil.isNullOrEmpty(sendOptions.getSelectedTarget())) {
+ sendResultConsumer.accept(NotificationSendResult.failure(
+ environment.getMessages().notificationTargetMissing()
+ ));
+ notificationEditor.setBusy(false);
+ return;
+ }
+
+ Notification notification = buildNotification();
+
+ if (notification == null) {
+ sendResultConsumer.accept(NotificationSendResult.failure(environment.getMessages().notificationBuildError()));
+ notificationEditor.setBusy(false);
+ return;
+ }
+
+ environment.getApp().getRequests().sendWith(
+ notificationMapper,
+ requestParams -> notificationResource.sendNotification(requestParams, buildNotification()),
+ 204,
+ () -> {
+ sendResultConsumer.accept(NotificationSendResult.success());
+ notificationEditor.setBusy(false);
+ }
+ );
+ }
+
+ protected void onFilterOptionsChanged() {
+
+ boolean refreshEnabled = canLoadNotifications();
+ if (!TextUtil.isNullOrEmpty(filterOptions.getSelectedRealm())) {
+ if (refreshEnabled && filterOptions.getSelectedTargetType() == Notification.TargetType.ASSET) {
+ assetBrowserPresenter.selectAssetById(filterOptions.getSelectedTarget());
+ } else {
+ assetBrowserPresenter.selectRealm(filterOptions.getSelectedRealm());
+ }
+ } else {
+ assetBrowserPresenter.clearSelection();
+ }
+
+ view.setRefreshEnabled(refreshEnabled);
+ refreshNotifications();
+ }
+
+ protected boolean canLoadNotifications() {
+ return !TextUtil.isNullOrEmpty(filterOptions.getSelectedTarget());
+ }
+
+ protected void loadTargets(FilterOptions filterOptions, Consumer<Map<String, String>> targetsConsumer) {
+ view.setBusy(true);
+
+ if (filterOptions == null || filterOptions.selectedRealm == null || filterOptions.selectedTargetType == null) {
+ targetsConsumer.accept(new HashMap<>(0));
+ view.setBusy(false);
+ return;
+ }
+
+ switch (filterOptions.selectedTargetType) {
+
+ case TENANT:
+ targetsConsumer.accept(filterOptions.getRealms());
+ view.setBusy(false);
+ break;
+ case USER:
+ loadUsers(filterOptions.getSelectedRealm(), users -> {
+ targetsConsumer.accept(Arrays.stream(users)
+ .collect(Collectors.toMap(User::getId, User::getUsername)));
+ view.setBusy(false);
+ });
+ break;
+ case ASSET:
+ loadAssets(filterOptions.getSelectedRealm(), assets -> {
+ targetsConsumer.accept(Arrays.stream(assets)
+ .collect(Collectors.toMap(Asset::getId, Asset::getName)));
+ view.setBusy(false);
+ });
+ break;
+ }
+ }
+
+ protected void loadTenants(Consumer<Tenant[]> tenantConsumer) {
+
+ if (this.tenants != null) {
+ tenantConsumer.accept(this.tenants);
+ return;
+ }
+
+ environment.getApp().getRequests().sendAndReturn(
+ tenantArrayMapper,
+ tenantResource::getAll,
+ 200,
+ tenants -> {
+ this.tenants = tenants;
+ tenantConsumer.accept(tenants);
+ });
+ }
+
+ protected void loadUsers(String realm, Consumer<User[]> usersConsumer) {
+ environment.getApp().getRequests().sendAndReturn(
+ userArrayMapper,
+ requestParams -> userResource.getAll(requestParams, realm),
+ 200,
+ usersConsumer::accept);
+ }
+
+ protected void loadAssets(String realm, Consumer<Asset[]> assetConsumer) {
+ environment.getApp().getRequests().sendWithAndReturn(
+ assetArrayMapper,
+ assetQueryMapper,
+ requestParams -> assetResource.queryAssets(requestParams,
+ new AssetQuery()
+ .select(new BaseAssetQuery
+ .Select(BaseAssetQuery.Include.ONLY_ID_AND_NAME))
+ .tenant(new TenantPredicate().realm(realm))),
+ 200,
+ assetConsumer::accept);
+ }
+
+ protected void refreshNotifications(Consumer<SentNotification[]> notificationConsumer) {
+
+ SentNotification[] notifications = new SentNotification[0];
+
+ if (!canLoadNotifications()) {
+ notificationConsumer.accept(notifications);
+ return;
+ }
+
+ List<String> types = TextUtil.isNullOrEmpty(filterOptions.getSelectedNotificationType())
+ ? null : Collections.singletonList(filterOptions.getSelectedNotificationType());
+
+ List<String> users = filterOptions.getSelectedTargetType() == Notification.TargetType.USER
+ ? Collections.singletonList(filterOptions.getSelectedTarget()) : null;
+
+ List<String> assets = filterOptions.getSelectedTargetType() == Notification.TargetType.ASSET
+ ? Collections.singletonList(filterOptions.getSelectedTarget()) : null;
+
+ Long timestamp = null;
+ if (filterOptions.getSelectedSentIn() != null) {
+ switch (filterOptions.getSelectedSentIn()) {
+
+ case DAY:
+ timestamp = new Date(new Date().getTime() - (24L * 60 * 60 * 1000)).getTime();
+ break;
+ case WEEK:
+ timestamp = new Date(new Date().getTime() - (7L * 24 * 60 * 60 * 1000)).getTime();
+ break;
+ case MONTH:
+ timestamp = new Date(new Date().getTime() - (31L * 24 * 60 * 60 * 1000)).getTime();
+ break;
+ }
+ }
+
+ Long finalTimestamp = timestamp;
+ environment.getApp().getRequests().sendAndReturn(
+ sentNotificationArrayMapper,
+ requestParams -> notificationResource.getNotifications(requestParams,
+ null,
+ types,
+ finalTimestamp,
+ Collections.singletonList(filterOptions.getSelectedRealm()),
+ users,
+ assets),
+ 200,
+ notificationConsumer::accept);
+ }
+
+ protected Notification buildNotification() {
+ return new Notification("Manager Message", sendOptions.getMessage(), new Notification.Targets(sendOptions.selectedTargetType, sendOptions.selectedTarget));
+ }
+}
diff --git a/client/src/main/java/org/openremote/app/client/notifications/NotificationsModule.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationsModule.java
new file mode 100644
index 000000000..b06465c72
--- /dev/null
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationsModule.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016, 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.google.gwt.inject.client.AbstractGinModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import org.openremote.model.notification.NotificationResource;
+
+public class NotificationsModule extends AbstractGinModule {
+
+ @Override
+ protected void configure() {
+ bind(NotificationEditor.class).to(NotificationEditorImpl.class).in(Singleton.class);
+ bind(NotificationsView.class).to(NotificationsViewImpl.class).in(Singleton.class);
+ bind(NotificationsActivity.class);
+ }
+
+
+ @Provides
+ @Singleton
+ public native NotificationResource getNotificationResource() /*-{
+ return $wnd.openremote.REST.NotificationResource;
+ }-*/;
+}
diff --git a/client/src/main/java/org/openremote/app/client/notifications/NotificationsPlace.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationsPlace.java
new file mode 100644
index 000000000..c9937b92c
--- /dev/null
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationsPlace.java
@@ -0,0 +1,86 @@
+/*
+ * 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.google.gwt.place.shared.Place;
+import com.google.gwt.place.shared.PlaceTokenizer;
+import com.google.gwt.place.shared.Prefix;
+import org.openremote.model.util.TextUtil;
+
+public class NotificationsPlace extends Place {
+
+ final String realm;
+ final String assetId;
+
+ public NotificationsPlace(String realm, String assetId) {
+ this.realm = realm;
+ this.assetId = assetId;
+ }
+
+ public NotificationsPlace() {
+ this.realm = null;
+ this.assetId = null;
+ }
+
+ public String getRealm() {
+ return realm;
+ }
+
+ public String getAssetId() {
+ return assetId;
+ }
+
+ @Prefix("notifications")
+ public static class Tokenizer implements PlaceTokenizer<NotificationsPlace> {
+
+ @Override
+ public NotificationsPlace getPlace(String token) {
+ if (TextUtil.isNullOrEmpty(token)) {
+ return new NotificationsPlace();
+ }
+
+ String[] tokenArr = token.split(":");
+
+ if (tokenArr.length < 1 || tokenArr.length > 2 || TextUtil.isNullOrEmpty(tokenArr[0])) {
+ return new NotificationsPlace();
+ }
+
+ String realm = tokenArr[0];
+ String assetId = tokenArr.length == 2 ? tokenArr[1] : null;
+
+ return new NotificationsPlace(realm, assetId);
+ }
+
+ @Override
+ public String getToken(NotificationsPlace place) {
+ StringBuilder sb = new StringBuilder();
+ if (!TextUtil.isNullOrEmpty(place.realm)) {
+ sb.append(place.realm);
+ }
+
+ if (!TextUtil.isNullOrEmpty(place.assetId)) {
+ sb.append(":");
+ sb.append(place.assetId);
+ }
+
+ return sb.toString();
+ }
+ }
+}
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotifications.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationsView.java
similarity index 64%
rename from client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotifications.java
rename to client/src/main/java/org/openremote/app/client/notifications/NotificationsView.java
index e58fbaccc..ebfcbf57b 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotifications.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationsView.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016, OpenRemote Inc.
+ * Copyright 2017, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
@@ -17,35 +17,35 @@
* 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.admin.users.notifications;
+package org.openremote.app.client.notifications;
-import org.openremote.app.client.admin.AdminContent;
-import org.openremote.app.client.admin.users.AbstractAdminUsersPlace;
-import org.openremote.model.notification.PushNotificationMessage;
+import com.google.gwt.user.client.ui.IsWidget;
import org.openremote.model.notification.SentNotification;
-public interface AdminUserNotifications extends AdminContent {
+public interface NotificationsView extends IsWidget {
interface Presenter {
- AbstractAdminUsersPlace getPlace();
+ void showNotificationEditor();
- void onRefresh();
+ void deleteNotification(Long id);
- void onSendNotification();
-
- void onNotificationDelete(Long id);
-
- void onNotificationsDelete();
+ void deleteNotifications();
+ void refreshNotifications();
}
void setPresenter(Presenter presenter);
- void setUsername(String username);
+ void setBusy(boolean busy);
+
+ void setRefreshEnabled(boolean enabled);
void setNotifications(SentNotification[] notifications);
- void removeNotification(Long id);
+ void setDeleteAllEnabled(boolean enabled);
+
+ void setFilterOptions(FilterOptions filterOptions);
+ void removeNotification(Long id);
}
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsImpl.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationsViewImpl.java
similarity index 61%
rename from client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsImpl.java
rename to client/src/main/java/org/openremote/app/client/notifications/NotificationsViewImpl.java
index 03f2dfa7a..fb913071a 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/notifications/AdminUserNotificationsImpl.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationsViewImpl.java
@@ -17,37 +17,39 @@
* 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.admin.users.notifications;
+package org.openremote.app.client.notifications;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.inject.Provider;
-import org.openremote.app.client.widget.*;
import org.openremote.app.client.Environment;
-import org.openremote.app.client.admin.users.AdminUsersNavigation;
import org.openremote.app.client.app.dialog.Confirmation;
+import org.openremote.app.client.assets.browser.AssetBrowser;
+import org.openremote.app.client.i18n.ManagerMessages;
+import org.openremote.app.client.style.WidgetStyle;
+import org.openremote.app.client.widget.*;
import org.openremote.model.Constants;
-import org.openremote.model.notification.Notification;
-import org.openremote.model.notification.PushNotificationMessage;
import org.openremote.model.notification.SentNotification;
import javax.inject.Inject;
+import java.util.Arrays;
-public class AdminUserNotificationsImpl extends FormViewImpl implements AdminUserNotifications {
+public class NotificationsViewImpl extends Composite implements NotificationsView {
- interface UI extends UiBinder<HTMLPanel, AdminUserNotificationsImpl> {
+ interface UI extends UiBinder<FlexSplitPanel, NotificationsViewImpl> {
}
- @UiField(provided = true)
- AdminUsersNavigation adminUsersNavigation;
+ @UiField
+ Form form;
@UiField
- FormOutputText usernameOutput;
+ HTMLPanel sidebarContainer;
@UiField
FormButton sendNotificationButton;
@@ -61,62 +63,163 @@ public class AdminUserNotificationsImpl extends FormViewImpl implements AdminUse
@UiField
FlowPanel notificationsContainer;
+ @UiField
+ ManagerMessages managerMessages;
+
+ @UiField
+ WidgetStyle widgetStyle;
+
+ @UiField
+ FormListBox typesList;
+
+ @UiField
+ FormListBox realmsList;
+
+ @UiField
+ FormListBox targetTypesList;
+
+ @UiField
+ FormListBox targetsList;
+
+ @UiField
+ FormListBox sentInsList;
+
+ protected FilterOptions filterOptions;
protected Presenter presenter;
+ final AssetBrowser assetBrowser;
@Inject
- public AdminUserNotificationsImpl(Environment environment,
- Provider<Confirmation> confirmationDialogProvider,
- AdminUsersNavigation adminUsersNavigation) {
- super(confirmationDialogProvider, environment.getWidgetStyle());
-
- this.adminUsersNavigation = adminUsersNavigation;
+ public NotificationsViewImpl(AssetBrowser assetBrowser) {
+ this.assetBrowser = assetBrowser;
UI ui = GWT.create(UI.class);
initWidget(ui.createAndBindUi(this));
sendNotificationButton.addClickHandler(event -> {
if (presenter != null) {
- presenter.onSendNotification();
+ presenter.showNotificationEditor();
}
});
refreshNotificationsButton.addClickHandler(event -> {
if (presenter != null) {
- presenter.onRefresh();
+ presenter.refreshNotifications();
}
});
deleteNotificationsButton.addClickHandler(event -> {
if (presenter != null) {
- presenter.onNotificationsDelete();
+ presenter.deleteNotifications();
}
});
+
+ // Add change handlers
+ typesList.addChangeHandler(event -> {
+ if (filterOptions != null)
+ filterOptions.setSelectedNotificationType(typesList.getSelectedValue());
+ });
+
+ realmsList.addChangeHandler(event -> {
+ if (filterOptions != null)
+ filterOptions.setSelectedRealm(realmsList.getSelectedValue());
+ });
+
+ targetTypesList.addChangeHandler(event -> {
+ if (filterOptions != null)
+ filterOptions.setSelectedTargetType(targetTypesList.getSelectedValue());
+ });
+
+ targetsList.addChangeHandler(event -> {
+ if (filterOptions != null)
+ filterOptions.setSelectedTarget(targetsList.getSelectedValue());
+ });
}
@Override
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
- if (presenter == null) {
- deleteNotificationsButton.setEnabled(false);
- adminUsersNavigation.setVisible(false);
- adminUsersNavigation.reset();
- usernameOutput.setText(null);
- } else {
- adminUsersNavigation.setActive(presenter.getPlace());
- adminUsersNavigation.setVisible(true);
+
+ sidebarContainer.clear();
+
+ if (presenter != null) {
+ assetBrowser.asWidget().removeFromParent();
+ sidebarContainer.add(assetBrowser.asWidget());
}
}
@Override
- public void setUsername(String username) {
- usernameOutput.setText(username);
+ public void setBusy(boolean busy) {
+ form.setBusy(busy);
}
@Override
- public void setNotifications(SentNotification[] notifications) {
- clearNotifications(notifications.length == 0);
- for (SentNotification notification : notifications) {
- notificationsContainer.add(new NotificationItem(notification));
+ public void setRefreshEnabled(boolean enabled) {
+ refreshNotificationsButton.setEnabled(enabled);
+ }
+
+ @Override
+ public void setDeleteAllEnabled(boolean enabled) {
+ deleteNotificationsButton.setEnabled(enabled);
+ }
+
+ @Override
+ public void setFilterOptions(FilterOptions filterOptions) {
+ if (this.filterOptions != null) {
+ this.filterOptions.setTargetsChangedCallback(null);
+ typesList.clear();
+ realmsList.clear();
+ targetTypesList.clear();
+ targetsList.clear();
+ sentInsList.clear();
+ }
+
+ this.filterOptions = filterOptions;
+
+ if (filterOptions == null) {
+ return;
+ }
+
+ filterOptions.setTargetsChangedCallback(this::onTargetsChanged);
+
+ // Type List
+ Arrays.stream(filterOptions.getNotificationTypes()).forEach(notificationType ->
+ typesList.addItem(managerMessages.notificationType(notificationType), notificationType));
+
+ if (typesList.getItemCount() > 1) {
+ typesList.insertItem("", 0);
+ }
+ typesList.selectItem(filterOptions.getSelectedNotificationType());
+
+ // Realm List
+ filterOptions.getRealms().forEach((name, value) ->
+ realmsList.addItem(value, name)
+ );
+ if (realmsList.getItemCount() > 1) {
+ realmsList.insertItem("", 0);
+ }
+ realmsList.selectItem(filterOptions.getSelectedRealm());
+
+ // Target Types
+ Arrays.stream(filterOptions.getTargetTypes()).forEach(targetType ->
+ targetTypesList.addItem(managerMessages.targetTypes(targetType), targetType));
+ if (targetTypesList.getItemCount() > 1) {
+ targetTypesList.insertItem("", 0);
+ targetTypesList.setSelectedIndex(0);
+ }
+ targetTypesList.selectItem(filterOptions.getSelectedTargetType() != null ? filterOptions.getSelectedTargetType().name() : null);
+
+ // Targets
+ onTargetsChanged();
+
+ // Sent In
+ Arrays.stream(FilterOptions.SentInLast.values()).forEach(sentInLast ->
+ sentInsList.addItem(managerMessages.sentInLast(sentInLast), sentInLast.name()));
+ if (sentInsList.getItemCount() > 1) {
+ sentInsList.insertItem("", 0);
+ sentInsList.setSelectedIndex(0);
+ }
+ if (filterOptions.getSelectedSentIn() != null) {
+ sentInsList.selectItem(filterOptions.getSelectedSentIn().name());
}
}
@@ -134,6 +237,13 @@ public class AdminUserNotificationsImpl extends FormViewImpl implements AdminUse
}
}
+ @Override
+ public void setNotifications(SentNotification[] notifications) {
+ clearNotifications(notifications.length == 0);
+ for (SentNotification notification : notifications) {
+ notificationsContainer.add(new NotificationItem(notification));
+ }
+ }
protected void clearNotifications(boolean addEmptyMessage) {
deleteNotificationsButton.setEnabled(!addEmptyMessage);
@@ -145,6 +255,23 @@ public class AdminUserNotificationsImpl extends FormViewImpl implements AdminUse
}
}
+ protected void onTargetsChanged() {
+ targetsList.clear();
+
+ if (filterOptions.getTargets() == null) {
+ return;
+ }
+
+ filterOptions.getTargets().forEach((name, value) -> targetsList.addItem(value, name));
+
+ if (targetsList.getItemCount() > 1) {
+ targetsList.insertItem("", 0);
+ targetsList.setSelectedIndex(0);
+ }
+
+ targetsList.selectItem(filterOptions.getSelectedTarget());
+ }
+
protected class NotificationItem extends FlowPanel {
private final SentNotification notification;
@@ -156,7 +283,7 @@ public class AdminUserNotificationsImpl extends FormViewImpl implements AdminUse
FormGroup statusGroup = new FormGroup();
statusGroup.setFormGroupActions(new FormGroupActions());
FormField statusField = new FormField();
- FormLabel statusLabel = new FormLabel(managerMessages.deliveryStatus());
+ FormLabel statusLabel = new FormLabel(managerMessages.status());
statusGroup.setFormLabel(statusLabel);
statusGroup.setFormField(statusField);
FormOutputText statusTxt = new FormOutputText("");
@@ -181,7 +308,7 @@ public class AdminUserNotificationsImpl extends FormViewImpl implements AdminUse
deleteButton.setText(managerMessages.deleteNotification());
deleteButton.addClickHandler(event -> {
if (presenter != null)
- presenter.onNotificationDelete(notification.getId());
+ presenter.deleteNotification(notification.getId());
});
statusGroup.getFormGroupActions().add(deleteButton);
@@ -234,7 +361,7 @@ public class AdminUserNotificationsImpl extends FormViewImpl implements AdminUse
FormGroup appUrlGroup = new FormGroup();
FormField appUrlField = new FormField();
- FormLabel appUrlLabel = new FormLabel(managerMessages.notificationAppUrl());
+ FormLabel appUrlLabel = new FormLabel(managerMessages.notificationActionUrl());
appUrlGroup.setFormLabel(appUrlLabel);
appUrlGroup.setFormField(appUrlField);
FormOutputText appUrlTxt = new FormOutputText(/*notification.getAppUrl()*/);
diff --git a/client/src/main/java/org/openremote/app/client/notifications/NotificationsViewImpl.ui.xml b/client/src/main/java/org/openremote/app/client/notifications/NotificationsViewImpl.ui.xml
new file mode 100644
index 000000000..086e80c41
--- /dev/null
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationsViewImpl.ui.xml
@@ -0,0 +1,127 @@
+<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
+ xmlns:g="urn:import:com.google.gwt.user.client.ui"
+ xmlns:w="urn:import:org.openremote.app.client.widget">
+
+ <ui:with field="managerMessages" type="org.openremote.app.client.i18n.ManagerMessages"/>
+ <ui:with field="widgetStyle" type="org.openremote.app.client.style.WidgetStyle"/>
+
+ <ui:style>
+ .navItem {
+ margin: 0 1em;
+ }
+ </ui:style>
+
+ <w:FlexSplitPanel ui:field="splitPanel"
+ handleStyle="{widgetStyle.SplitPanelHandle}"
+ firstPanelWidth="300"
+ firstPanelMinWidth="0"
+ secondPanelMinWidth="400">
+
+ <w:first>
+ <g:HTMLPanel ui:field="sidebarContainer"
+ styleName="flex layout vertical {widgetStyle.SidebarContent}"/>
+ </w:first>
+
+ <w:second>
+ <g:HTMLPanel styleName="flex layout vertical">
+
+ <div class="layout horizontal center end-justified {widgetStyle.SecondaryNav}">
+
+ <w:FormButton ui:field="sendNotificationButton"
+ addStyleNames="{style.navItem} {widgetStyle.SecondaryNavItem}"
+ text="{managerMessages.sendNotification}"
+ icon="send"/>
+ </div>
+
+ <w:Form ui:field="form" addStyleNames="flex">
+
+ <g:HTMLPanel ui:field="mainContent"
+ styleName="flex-none layout vertical {widgetStyle.MainContent}">
+
+ <div class="layout vertical">
+
+ <w:Headline icon="filter"
+ text="{managerMessages.filter}"/>
+
+ <w:FormGroup ui:field="typeGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.type}"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <w:FormListBox ui:field="typesList" />
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+
+ <w:FormGroup ui:field="realmGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.realm}"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <w:FormListBox ui:field="realmsList" />
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+
+ <w:FormGroup ui:field="targetTypeGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.targetType}"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <w:FormListBox ui:field="targetTypesList" />
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+
+ <w:FormGroup ui:field="targetsGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.targets}"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <w:FormListBox ui:field="targetsList" />
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+
+ <w:FormGroup ui:field="sentInGroup">
+ <w:label>
+ <w:FormLabel text="{managerMessages.sentIn}"/>
+ </w:label>
+ <w:field>
+ <w:FormField>
+ <w:FormListBox ui:field="sentInsList" />
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+
+ <w:FormGroup ui:field="submitButtonGroup">
+ <w:field>
+ <w:FormField>
+ <w:FormButton ui:field="refreshNotificationsButton"
+ text="{managerMessages.refresh}"
+ icon="refresh"/>
+ <w:FormButton ui:field="deleteNotificationsButton"
+ danger="true"
+ text="{managerMessages.deleteNotifications}"
+ icon="trash"/>
+ </w:FormField>
+ </w:field>
+ </w:FormGroup>
+
+ </div>
+
+ </g:HTMLPanel>
+
+ <g:FlowPanel ui:field="notificationsContainer"
+ styleName="flex layout vertical {widgetStyle.MainContent} {widgetStyle.FormList}"/>
+
+ </w:Form>
+
+ </g:HTMLPanel>
+ </w:second>
+ </w:FlexSplitPanel>
+</ui:UiBinder>
\ No newline at end of file
diff --git a/client/src/main/java/org/openremote/app/client/notifications/SendOptions.java b/client/src/main/java/org/openremote/app/client/notifications/SendOptions.java
new file mode 100644
index 000000000..01ec31ca2
--- /dev/null
+++ b/client/src/main/java/org/openremote/app/client/notifications/SendOptions.java
@@ -0,0 +1,61 @@
+/*
+ * 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 org.openremote.model.notification.AbstractNotificationMessage;
+import org.openremote.model.notification.Notification;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+public class SendOptions extends FilterOptions {
+
+ protected final static String[] TARGET_TYPES = Arrays.stream(Notification.TargetType.values()).map(Enum::name).toArray(String[]::new);
+
+ protected Supplier<AbstractNotificationMessage> messageSupplier;
+ protected AbstractNotificationMessage message;
+
+ public SendOptions(Map<String, String> realms, BiConsumer<FilterOptions, Consumer<Map<String, String>>> targetsSupplier, Supplier<AbstractNotificationMessage> messageSupplier) {
+ super(realms, targetsSupplier);
+ this.messageSupplier = messageSupplier;
+ }
+
+ @Override
+ public String[] getTargetTypes() {
+ return TARGET_TYPES;
+ }
+
+ public AbstractNotificationMessage getMessage() {
+ if (message == null) {
+ message = messageSupplier.get();
+ } else if (!Objects.equals(message.getType(), getSelectedNotificationType())) {
+ message = null;
+
+ if (getSelectedNotificationType() != null) {
+ message = messageSupplier.get();
+ }
+ }
+ return message;
+ }
+}
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/notifications/SentNotificationArrayMapper.java b/client/src/main/java/org/openremote/app/client/notifications/SentNotificationArrayMapper.java
similarity index 96%
rename from client/src/main/java/org/openremote/app/client/admin/users/notifications/SentNotificationArrayMapper.java
rename to client/src/main/java/org/openremote/app/client/notifications/SentNotificationArrayMapper.java
index 01433259d..4bf6cae55 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/notifications/SentNotificationArrayMapper.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/SentNotificationArrayMapper.java
@@ -17,7 +17,7 @@
* 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.admin.users.notifications;
+package org.openremote.app.client.notifications;
import com.github.nmorel.gwtjackson.client.ObjectMapper;
import com.github.nmorel.gwtjackson.client.annotation.JsonMixIns;
diff --git a/client/src/main/java/org/openremote/app/client/rest/Requests.java b/client/src/main/java/org/openremote/app/client/rest/Requests.java
index 1a8086587..5695f96dc 100644
--- a/client/src/main/java/org/openremote/app/client/rest/Requests.java
+++ b/client/src/main/java/org/openremote/app/client/rest/Requests.java
@@ -20,8 +20,6 @@
package org.openremote.app.client.rest;
import com.google.gwt.core.client.GWT;
-import elemental.client.Browser;
-import elemental.html.Location;
import elemental2.core.Global;
import jsinterop.annotations.JsIgnore;
import jsinterop.annotations.JsType;
diff --git a/client/src/main/java/org/openremote/app/client/rules/AbstractRulesEditorActivity.java b/client/src/main/java/org/openremote/app/client/rules/AbstractRulesEditorActivity.java
index 02206fbe0..47888bcf9 100644
--- a/client/src/main/java/org/openremote/app/client/rules/AbstractRulesEditorActivity.java
+++ b/client/src/main/java/org/openremote/app/client/rules/AbstractRulesEditorActivity.java
@@ -33,9 +33,9 @@ import org.openremote.model.event.bus.EventRegistration;
import org.openremote.model.http.ConstraintViolation;
import org.openremote.model.http.RequestParams;
import org.openremote.model.interop.Consumer;
-import org.openremote.model.interop.Runnable;
import org.openremote.model.rules.Ruleset;
import org.openremote.model.rules.RulesResource;
+import org.openremote.model.interop.Runnable;
import javax.inject.Inject;
import java.util.Collection;
diff --git a/client/src/main/java/org/openremote/app/client/rules/RulesEditorImpl.java b/client/src/main/java/org/openremote/app/client/rules/RulesEditorImpl.java
index 6c9c76f8e..50baa9959 100644
--- a/client/src/main/java/org/openremote/app/client/rules/RulesEditorImpl.java
+++ b/client/src/main/java/org/openremote/app/client/rules/RulesEditorImpl.java
@@ -88,10 +88,9 @@ public class RulesEditorImpl extends FormViewImpl implements RulesEditor {
protected Presenter presenter;
@Inject
- public RulesEditorImpl(Provider<Confirmation> confirmationDialogProvider,
- AssetBrowser assetBrowser,
+ public RulesEditorImpl(AssetBrowser assetBrowser,
Environment environment) {
- super(confirmationDialogProvider, environment.getWidgetStyle());
+ super(environment.getWidgetStyle());
this.assetBrowser = assetBrowser;
RulesEditorImpl.UI ui = GWT.create(RulesEditorImpl.UI.class);
diff --git a/client/src/main/java/org/openremote/app/client/rules/global/GlobalRulesEditorActivity.java b/client/src/main/java/org/openremote/app/client/rules/global/GlobalRulesEditorActivity.java
index 08eaf1748..8db023a9f 100644
--- a/client/src/main/java/org/openremote/app/client/rules/global/GlobalRulesEditorActivity.java
+++ b/client/src/main/java/org/openremote/app/client/rules/global/GlobalRulesEditorActivity.java
@@ -26,11 +26,11 @@ import org.openremote.app.client.assets.browser.AssetBrowser;
import org.openremote.app.client.mvp.AcceptsView;
import org.openremote.app.client.rules.AbstractRulesEditorActivity;
import org.openremote.app.client.rules.RulesEditor;
+import org.openremote.model.interop.Consumer;
import org.openremote.model.rules.RulesResource;
import org.openremote.model.event.bus.EventBus;
import org.openremote.model.event.bus.EventRegistration;
import org.openremote.model.http.RequestParams;
-import org.openremote.model.interop.Consumer;
import org.openremote.model.rules.GlobalRuleset;
import javax.inject.Inject;
diff --git a/client/src/main/java/org/openremote/app/client/style/WidgetStyle.java b/client/src/main/java/org/openremote/app/client/style/WidgetStyle.java
index 0bdd7f4b4..9df1c323c 100644
--- a/client/src/main/java/org/openremote/app/client/style/WidgetStyle.java
+++ b/client/src/main/java/org/openremote/app/client/style/WidgetStyle.java
@@ -118,7 +118,8 @@ public class WidgetStyle {
public String TopGradient = "or-TopGradient";
public String HighlightBackground = "or-HighlightBackground";
public String JsonEditor = "or-JsonEditor";
- public String AdminNotificationEditor = "or-AdminNotificationEditor";
+ public String NotificationEditor = "or-NotificationEditor";
+ public String NotificationActionLabel = "or-NotificationActionLabel";
public String BorderRed = "or-BorderRed";
public String BorderGreen = "or-BorderGreen";
public String BorderYellow = "or-BorderYellow";
@@ -590,8 +591,13 @@ public class WidgetStyle {
}
@JsIgnore
- public String AdminNotificationEditor() {
- return AdminNotificationEditor;
+ public String NotificationEditor() {
+ return NotificationEditor;
+ }
+
+ @JsIgnore
+ public String NotificationActionLabel() {
+ return NotificationActionLabel;
}
@JsIgnore
diff --git a/client/src/main/java/org/openremote/app/client/widget/AbstractAppPanel.java b/client/src/main/java/org/openremote/app/client/widget/AbstractAppPanel.java
index 01cd154dd..5feac4fcc 100644
--- a/client/src/main/java/org/openremote/app/client/widget/AbstractAppPanel.java
+++ b/client/src/main/java/org/openremote/app/client/widget/AbstractAppPanel.java
@@ -24,7 +24,7 @@ import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.UIObject;
-import org.openremote.model.interop.Consumer;
+import java.util.function.Consumer;
public abstract class AbstractAppPanel implements AppPanel {
diff --git a/client/src/main/java/org/openremote/app/client/widget/AppPanel.java b/client/src/main/java/org/openremote/app/client/widget/AppPanel.java
index 2e101d275..5b6594895 100644
--- a/client/src/main/java/org/openremote/app/client/widget/AppPanel.java
+++ b/client/src/main/java/org/openremote/app/client/widget/AppPanel.java
@@ -20,7 +20,7 @@
package org.openremote.app.client.widget;
import com.google.gwt.user.client.ui.UIObject;
-import org.openremote.model.interop.Consumer;
+import java.util.function.Consumer;
public interface AppPanel {
diff --git a/client/src/main/java/org/openremote/app/client/widget/FormView.java b/client/src/main/java/org/openremote/app/client/widget/FormView.java
index 9b8141c4f..f17e9a0da 100644
--- a/client/src/main/java/org/openremote/app/client/widget/FormView.java
+++ b/client/src/main/java/org/openremote/app/client/widget/FormView.java
@@ -20,6 +20,7 @@
package org.openremote.app.client.widget;
import com.google.gwt.user.client.ui.IsWidget;
+import org.openremote.model.interop.Runnable;
public interface FormView extends IsWidget {
diff --git a/client/src/main/java/org/openremote/app/client/widget/FormViewImpl.java b/client/src/main/java/org/openremote/app/client/widget/FormViewImpl.java
index 87f9a202c..cf738d533 100644
--- a/client/src/main/java/org/openremote/app/client/widget/FormViewImpl.java
+++ b/client/src/main/java/org/openremote/app/client/widget/FormViewImpl.java
@@ -21,15 +21,13 @@ package org.openremote.app.client.widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
-import com.google.inject.Provider;
import org.openremote.app.client.app.dialog.Confirmation;
import org.openremote.app.client.i18n.ManagerMessages;
import org.openremote.app.client.style.WidgetStyle;
+import org.openremote.model.interop.Runnable;
public class FormViewImpl extends Composite implements FormView {
- protected final Provider<Confirmation> confirmationDialogProvider;
-
@UiField
public WidgetStyle widgetStyle;
@@ -42,9 +40,7 @@ public class FormViewImpl extends Composite implements FormView {
public FormMessages formMessagesSuccess;
public FormMessages formMessagesError;
- public FormViewImpl(Provider<Confirmation> confirmationDialogProvider, WidgetStyle widgetStyle) {
- this.confirmationDialogProvider = confirmationDialogProvider;
-
+ public FormViewImpl(WidgetStyle widgetStyle) {
this.formMessagesSuccess = new FormMessages(widgetStyle, true);
this.formMessagesError = new FormMessages(widgetStyle, false);
@@ -90,7 +86,7 @@ public class FormViewImpl extends Composite implements FormView {
@Override
public void showConfirmation(String title, String text, Runnable onConfirm, Runnable onCancel) {
- Confirmation confirmation = confirmationDialogProvider.get();
+ Confirmation confirmation = new Confirmation(widgetStyle, managerMessages);
confirmation.setTitle(title);
confirmation.setText(text);
confirmation.setOnConfirm(onConfirm);
diff --git a/client/src/main/java/org/openremote/app/client/widget/ValueEditors.java b/client/src/main/java/org/openremote/app/client/widget/ValueEditors.java
index d69173002..61f838da0 100644
--- a/client/src/main/java/org/openremote/app/client/widget/ValueEditors.java
+++ b/client/src/main/java/org/openremote/app/client/widget/ValueEditors.java
@@ -23,8 +23,11 @@ import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.IsWidget;
import org.openremote.app.client.app.dialog.JsonEditor;
+import org.openremote.app.client.i18n.ManagerMessages;
+import org.openremote.app.client.style.WidgetStyle;
import org.openremote.model.Constants;
import org.openremote.model.interop.Consumer;
+import org.openremote.model.util.TextUtil;
import org.openremote.model.value.*;
import java.util.Date;
@@ -53,6 +56,70 @@ public final class ValueEditors {
}
}
+ public static IsWidget createValueEditor(Value currentValue,
+ ValueType valueType,
+ Consumer<Value> onValueModified,
+ Optional<Long> timestamp,
+ boolean readOnly,
+ String styleName,
+ WidgetStyle widgetStyle,
+ ManagerMessages managerMessages) {
+
+ switch(valueType) {
+ case OBJECT:
+ ObjectValue currentValueObj = Values.getObject(currentValue).orElse(null);
+
+ return createObjectEditor(
+ currentValueObj,
+ onValueModified::accept,
+ timestamp,
+ readOnly,
+ widgetStyle,
+ managerMessages
+ );
+ case ARRAY:
+ ArrayValue currentValueArray = Values.getArray(currentValue).orElse(null);
+
+ return createArrayEditor(
+ currentValueArray,
+ onValueModified::accept,
+ timestamp,
+ readOnly,
+ widgetStyle,
+ managerMessages
+ );
+ case STRING:
+ StringValue currentValueStr = Values.getString(currentValue).map(Values::create).orElse(null);
+ return createStringEditor(
+ currentValueStr,
+ onValueModified::accept,
+ timestamp,
+ readOnly,
+ styleName
+ );
+ case NUMBER:
+ NumberValue currentValueNumber = Values.getNumber(currentValue).map(Values::create).orElse(null);
+ return createNumberEditor(
+ currentValueNumber,
+ onValueModified::accept,
+ timestamp,
+ readOnly,
+ styleName
+ );
+ case BOOLEAN:
+ BooleanValue currentValueBool = Values.getBoolean(currentValue).map(Values::create).orElse(null);
+ return createBooleanEditor(
+ currentValueBool,
+ onValueModified::accept,
+ timestamp,
+ readOnly,
+ styleName
+ );
+ default:
+ return new FormOutputText(managerMessages.unsupportedValueType(valueType.name()));
+ }
+ }
+
public static IsWidget createStringEditor(StringValue currentValue,
Consumer<StringValue> onValueModified,
Optional<Long> timestamp,
@@ -128,17 +195,18 @@ public final class ValueEditors {
Consumer<ObjectValue> onValueModified,
Optional<Long> timestamp,
boolean readOnly,
- String label,
- String title,
- JsonEditor jsonEditor) {
+ WidgetStyle widgetStyle,
+ ManagerMessages managerMessages) {
Consumer<Value> updateConsumer = readOnly ? null : value ->
onValueModified.accept(Values.getObject(value).orElse(null));
FlowPanel panel = new FlowPanel();
panel.setStyleName("flex layout horizontal center or-ValueEditor or-ObjectValueEditor");
+ String label = managerMessages.jsonObject();
+ String title = managerMessages.edit() + " " + managerMessages.jsonObject();
IsWidget widget = createJsonEditorWidget(
- jsonEditor, readOnly, label, title, currentValue, updateConsumer
+ new JsonEditor(title, widgetStyle, managerMessages), readOnly, label, currentValue, updateConsumer
);
FlowPanel widgetWrapper = new FlowPanel();
widgetWrapper.setStyleName("flex layout horizontal center");
@@ -152,17 +220,18 @@ public final class ValueEditors {
Consumer<ArrayValue> onValueModified,
Optional<Long> timestamp,
boolean readOnly,
- String label,
- String title,
- JsonEditor jsonEditor) {
+ WidgetStyle widgetStyle,
+ ManagerMessages managerMessages) {
Consumer<Value> updateConsumer = readOnly ? null : value ->
onValueModified.accept(Values.getArray(value).orElse(null));
FlowPanel panel = new FlowPanel();
panel.setStyleName("flex layout horizontal center or-ValueEditor or-ArrayValueEditor");
+ String label = managerMessages.jsonArray();
+ String title = managerMessages.edit() + " " + managerMessages.jsonArray();
IsWidget widget = createJsonEditorWidget(
- jsonEditor, readOnly, label, title, currentValue, updateConsumer
+ new JsonEditor(title, widgetStyle, managerMessages), readOnly, label, currentValue, updateConsumer
);
FlowPanel widgetWrapper = new FlowPanel();
widgetWrapper.setStyleName("flex layout horizontal center");
@@ -182,7 +251,9 @@ public final class ValueEditors {
String value,
Consumer<String> updateConsumer) {
FormInputText input = new FormInputText();
- input.addStyleName(styleName);
+ if (!TextUtil.isNullOrEmpty(styleName)) {
+ input.addStyleName(styleName);
+ }
if (value != null) {
input.setValue(value);
} else if (updateConsumer == null) {
@@ -205,7 +276,9 @@ public final class ValueEditors {
Boolean value,
Consumer<Boolean> updateConsumer) {
FormCheckBox input = new FormCheckBox();
- input.addStyleName(styleName);
+ if (!TextUtil.isNullOrEmpty(styleName)) {
+ input.addStyleName(styleName);
+ }
input.setEnabled(!readOnly);
if (value == null && updateConsumer == null) {
@@ -225,11 +298,8 @@ public final class ValueEditors {
private static IsWidget createJsonEditorWidget(JsonEditor jsonEditor,
boolean readOnly,
String label,
- String title,
Value currentValue,
Consumer<Value> updateConsumer) {
- jsonEditor.setTitle(title);
-
if (currentValue != null) {
jsonEditor.setValue(currentValue);
}
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 669ce43b7..b59abc29e 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
@@ -19,6 +19,7 @@ updateTenant=Save tenant
deleteTenant=Delete tenant
OK=OK
cancel=Cancel
+close=Close
filter=Filter
search=Search
newUser=New user
@@ -317,6 +318,7 @@ metaItemDisplayName[READ_ONLY]=Read only
metaItemDisplayName[ACCESS_RESTRICTED_READ]=Restricted read access
metaItemDisplayName[ACCESS_RESTRICTED_WRITE]=Restricted write access
metaItemDisplayName[ACCESS_PUBLIC_READ]=Public read access
+metaItemDisplayName[ACCESS_PUBLIC_WRITE]=Public write access
metaItemDisplayName[RANGE_MIN]=Min value
metaItemDisplayName[RANGE_MAX]=Max value
metaItemDisplayName[STEP]=Step
@@ -398,9 +400,11 @@ registeredDeviceDeleted=Device registration deleted: {0}
sendNotification=Send notification
title=Title
message=Message
-notificationAppUrl=Details URL/anchor
-enterTitleMessageAppurlForNotification=Enter title, message, and App URL of notification.
-notificationSentToUser=Alert notification sent to user.
+notificationActionUrl=URL
+notificationSendFailure=Notification send failed ''{0}''.
+notificationSentSuccessfully=Notification sent successfully.
+notificationMessageMissing=Notification type not specified and/orM notification message missing
+notificationTargetMissing=Target type and/or target missing
notificationOpenApplicationDetails=Details
linkAsset=Link asset
withUser=With user
@@ -414,12 +418,11 @@ userAssetLinkCreated=Asset/user link created.
userAssetLinkDeleted=Asset/user link deleted.
assetNotInTenant=Asset not in tenant: {0}
notifications=Notifications
-manageNotifications=Manage notifications
allUsers=All users
-noNotifications=This user has no stored notifications.
+noNotifications=This target has no stored notifications.
notificationDeleted=Notification deleted: {0}
deleteNotification=Delete notification
-deliveryStatus=Delivery status
+status=Status
action=Action
notificationsDeleted=Notifications deleted.
refresh=Refresh
@@ -431,3 +434,35 @@ shareLink=Share link
noAppsFound=No apps found
language=Language
confirmationRulesLangChange=Are you sure you want to switch rules language and replace existing rules?
+targets=Targets
+sentIn=Sent in
+targetType=Target type
+notificationType=Unknown
+notificationType[push]=Push
+targetTypes=Unknown
+targetTypes[TENANT]=Realm
+targetTypes[USER]=User
+targetTypes[ASSET]=Asset
+sentInLast=Unknown
+sentInLast[DAY]=Last day
+sentInLast[WEEK]=Last week
+sentInLast[MONTH]=Last month
+body=Body
+data=Data
+notificationData=Notification data
+notificationActionType=Unknown action type
+notificationActionType[DISMISS]=Dismiss
+notificationActionType[GET]=HTTP GET
+notificationActionType[POST]=HTTP POST
+notificationActionType[PUT]=HTTP PUT
+notificationActionType[DELETE]=HTTP DELETE
+notificationActionType[GET_SILENT]=HTTP GET (silent)
+notificationActionType[POST_SILENT]=HTTP POST (silent)
+notificationActionType[PUT_SILENT]=HTTP PUT (silent)
+notificationActionType[DELETE_SILENT]=HTTP DELETE (silent)
+notificationActionType[GET_INBROWSER]=HTTP GET (browser)
+notificationActionType[POST_INBROWSER]=HTTP POST (browser)
+notificationActionType[PUT_INBROWSER]=HTTP PUT (browser)
+notificationActionType[DELETE_INBROWSER]=HTTP DELETE (browser)
+none=None
+notificationBuildError=unable to build notification
\ No newline at end of file
diff --git a/client/src/main/webapp/src/or-app/or-style.html b/client/src/main/webapp/src/or-app/or-style.html
index 51c269ad4..4e2e1ac94 100644
--- a/client/src/main/webapp/src/or-app/or-style.html
+++ b/client/src/main/webapp/src/or-app/or-style.html
@@ -247,7 +247,7 @@
}
.or-FormBusy {
- opacity: 0;
+ opacity: 0.3;
pointer-events: none;
user-select: none;
-webkit-user-select: none; /* Chrome/Safari/Opera */
@@ -611,9 +611,14 @@
height: 40em;
}
- .or-AdminNotificationEditor {
- width: 50em;
- height: 20em;
+ .or-NotificationEditor {
+ width: 70em;
+ height: 40em;
+ }
+
+ .or-NotificationActionLabel {
+ width: auto;
+ padding: 0 0.25em 0 0.75em;
}
.or-SimulatorElement {
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
index a627c92c2..b5649ece2 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
@@ -183,8 +183,17 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
assetStorageService.deleteUserAsset(realmId, userId, assetId);
}
+ @Override
+ public Asset getPartial(RequestParams requestParams, String assetId) {
+ return get(requestParams, assetId, false);
+ }
+
@Override
public Asset get(RequestParams requestParams, String assetId) {
+ return get(requestParams, assetId, true);
+ }
+
+ public Asset get(RequestParams requestParams, String assetId, boolean loadComplete) {
try {
Asset asset;
@@ -193,9 +202,9 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
if (!assetStorageService.isUserAsset(getUserId(), assetId)) {
throw new WebApplicationException(FORBIDDEN);
}
- asset = assetStorageService.find(assetId, true, Access.RESTRICTED_READ);
+ asset = assetStorageService.find(assetId, loadComplete, Access.RESTRICTED_READ);
} else {
- asset = assetStorageService.find(assetId, true);
+ asset = assetStorageService.find(assetId, loadComplete);
}
if (asset == null)
diff --git a/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java b/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java
index 6f0ee1c68..7dc785840 100644
--- a/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java
@@ -61,18 +61,18 @@ public class NotificationResourceImpl extends WebResource implements Notificatio
}
@Override
- public SentNotification[] getNotifications(RequestParams requestParams, List<String> types, Long timestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) {
+ public SentNotification[] getNotifications(RequestParams requestParams, List<Long> ids, List<String> types, Long timestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) {
try {
- return notificationService.getNotifications(types, timestamp, tenantIds, userIds, assetIds).toArray(new SentNotification[0]);
+ return notificationService.getNotifications(ids, types, timestamp, tenantIds, userIds, assetIds).toArray(new SentNotification[0]);
} catch (IllegalArgumentException e) {
throw new WebApplicationException("Invalid criteria set", BAD_REQUEST);
}
}
@Override
- public void removeNotifications(RequestParams requestParams, List<String> types, Long timestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) {
+ public void removeNotifications(RequestParams requestParams, List<Long> ids, List<String> types, Long timestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) {
try {
- notificationService.removeNotifications(types, timestamp, tenantIds, userIds, assetIds);
+ notificationService.removeNotifications(ids, types, timestamp, tenantIds, userIds, assetIds);
} catch (IllegalArgumentException e) {
throw new WebApplicationException("Invalid criteria set", BAD_REQUEST);
}
diff --git a/manager/src/main/java/org/openremote/manager/notification/NotificationService.java b/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
index a2cd0450a..d9d8e4f71 100644
--- a/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
+++ b/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
@@ -137,7 +137,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
throw new NotificationProcessingException(MISSING_MESSAGE, "Notification message must be set");
}
- if (notification.getTargets() == null || notification.getTargets().getType() == null || notification.getTargets().getIds() == null || notification.getTargets().getIds().length == 0) {
+ if (notification.getTargets() == null || notification.getTargets().getType() == null || notification.getTargets().getIds() == null || Arrays.stream(notification.getTargets().getIds()).anyMatch(TextUtil::isNullOrEmpty)) {
throw new NotificationProcessingException(MISSING_TARGETS, "Notification targets must be set");
}
@@ -338,11 +338,11 @@ public class NotificationService extends RouteBuilder implements ContainerServic
return persistenceService.doReturningTransaction(em -> em.find(SentNotification.class, notificationId));
}
- public List<SentNotification> getNotifications(List<String> types, Long timestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) throws IllegalArgumentException {
+ public List<SentNotification> getNotifications(List<Long> ids, List<String> types, Long timestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) throws IllegalArgumentException {
StringBuilder builder = new StringBuilder();
builder.append("select n from SentNotification n where 1=1");
List<Object> parameters = new ArrayList<>();
- processCriteria(builder, parameters, types, timestamp, tenantIds, userIds, assetIds);
+ processCriteria(builder, parameters, ids, types, timestamp, tenantIds, userIds, assetIds);
return persistenceService.doReturningTransaction(entityManager -> {
TypedQuery<SentNotification> query = entityManager.createQuery(builder.toString(), SentNotification.class);
@@ -360,12 +360,12 @@ public class NotificationService extends RouteBuilder implements ContainerServic
);
}
- public void removeNotifications(List<String> types, Long timestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) throws IllegalArgumentException {
+ public void removeNotifications(List<Long> ids, List<String> types, Long timestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) throws IllegalArgumentException {
StringBuilder builder = new StringBuilder();
builder.append("delete from SentNotification n where 1=1");
List<Object> parameters = new ArrayList<>();
- processCriteria(builder, parameters, types, timestamp, tenantIds, userIds, assetIds);
+ processCriteria(builder, parameters, ids, types, timestamp, tenantIds, userIds, assetIds);
persistenceService.doTransaction(entityManager -> {
Query query = entityManager.createQuery(builder.toString());
@@ -375,13 +375,17 @@ public class NotificationService extends RouteBuilder implements ContainerServic
});
}
- protected void processCriteria(StringBuilder builder, List<Object> parameters, List<String> types, Long timestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) {
+ protected void processCriteria(StringBuilder builder, List<Object> parameters, List<Long> ids, List<String> types, Long timestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) {
+ boolean hasIds = ids != null && !ids.isEmpty();
boolean hasTypes = types != null && !types.isEmpty();
boolean hasTenants = tenantIds != null && !tenantIds.isEmpty();
boolean hasUsers = userIds != null && !userIds.isEmpty();
boolean hasAssets = assetIds != null && !assetIds.isEmpty();
int counter = 0;
+ if (hasIds) {
+ counter++;
+ }
if (hasTypes) {
counter++;
}
@@ -400,6 +404,13 @@ public class NotificationService extends RouteBuilder implements ContainerServic
throw new IllegalArgumentException("No criteria specified");
}
+ if (hasIds) {
+ builder.append(" AND n.id IN ?")
+ .append(parameters.size() + 1);
+ parameters.add(ids);
+ return;
+ }
+
if (hasTypes) {
builder.append(" AND n.type IN ?")
.append(parameters.size() + 1);
diff --git a/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java b/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java
index e91e1dc00..80ccc7165 100644
--- a/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java
+++ b/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java
@@ -44,7 +44,6 @@ import org.openremote.model.query.filter.ObjectValueKeyPredicate;
import org.openremote.model.query.filter.PathPredicate;
import org.openremote.model.query.filter.TenantPredicate;
import org.openremote.model.util.TextUtil;
-import org.openremote.model.value.StringValue;
import java.io.InputStream;
import java.nio.file.Files;
@@ -74,7 +73,6 @@ public class PushNotificationHandler extends RouteBuilder implements Notificatio
protected boolean valid;
protected Map<String, String> consoleFCMTokenMap = new HashMap<>();
protected List<String> fcmTokenBlacklist = new ArrayList<>();
- protected AbstractNotificationMessage lastSentMessage; // Bit of a hack to track topic based messages
public void init(Container container) throws Exception {
this.assetStorageService = container.getService(AssetStorageService.class);
@@ -284,23 +282,36 @@ public class PushNotificationHandler extends RouteBuilder implements Notificatio
return NotificationSendResult.failure("FCM invalid configuration so ignoring");
}
+ // Check this asset has an FCM token (i.e. it is registered for push notifications)
+ String fcmToken = consoleFCMTokenMap.get(targetId);
+
+ if (TextUtil.isNullOrEmpty(fcmToken)) {
+ LOG.warning("No FCM token found for console: " + targetId);
+ return NotificationSendResult.failure("FCM invalid configuration so ignoring");
+ }
PushNotificationMessage pushMessage = (PushNotificationMessage) message;
- if (pushMessage.getTargetType() == DEVICE) {
- String fcmToken = consoleFCMTokenMap.get(targetId);
- if (TextUtil.isNullOrEmpty(fcmToken)) {
- LOG.warning("No FCM token found for console: " + targetId);
- return NotificationSendResult.failure("FCM invalid configuration so ignoring");
- }
- pushMessage.setTarget(fcmToken);
- } else if (pushMessage.getTargetType() == TOPIC && pushMessage == lastSentMessage) {
- LOG.info("Message is for topic and already sent so skipping send");
- return NotificationSendResult.success();
- } else {
- pushMessage.setTarget(targetId);
+
+ // Assume DEVICE target if not specified
+ if (pushMessage.getTargetType() == null) {
+ pushMessage.setTargetType(DEVICE);
+ }
+
+ switch (pushMessage.getTargetType()) {
+ case DEVICE:
+ // Always use fcm token from the console asset (so users cannot target other devices)
+ pushMessage.setTarget(fcmToken);
+ break;
+ case TOPIC:
+ // TODO: Decide how to handle FCM topic support (too much power for users to put anything in target)
+ LOG.warning("Messages sent to a topic are not supported");
+ return NotificationSendResult.failure("Messages sent to a topic are not supported");
+ case CONDITION:
+ // TODO: Decide how to handle conditions support (too much power for users to put anything in target)
+ LOG.warning("Messages sent to conditional targets are not supported");
+ return NotificationSendResult.failure("Messages sent to conditional targets are not supported");
}
- lastSentMessage = pushMessage;
return sendMessage(buildFCMMessage(id, pushMessage));
}
@@ -401,10 +412,9 @@ public class PushNotificationHandler extends RouteBuilder implements Notificatio
});
if (dataOnly) {
+ apsBuilder.setContentAvailable(true);
}
}
- apsBuilder.setContentAvailable(true);
-
// Store ID so console can mark notification as delivered and/or acknowledged
builder.putData("notification-id", Long.toString(id));
diff --git a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
index d6398f0dd..122bc5418 100644
--- a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
+++ b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
@@ -242,7 +242,7 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofe
notificationService.sendNotification(
new Notification(
"GeofenceRefresh",
- new PushNotificationMessage().setData(data).setTargetType(PushNotificationMessage.TargetType.DEVICE),
+ new PushNotificationMessage().setData(data),
new Notification.Targets(Notification.TargetType.ASSET, Collections.singletonList(assetId))));
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetResource.java b/model/src/main/java/org/openremote/model/asset/AssetResource.java
index ff40bcac9..ac2ccff38 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetResource.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetResource.java
@@ -160,6 +160,17 @@ public interface AssetResource {
@SuppressWarnings("unusable-by-js")
Asset get(@BeanParam RequestParams requestParams, @PathParam("assetId") String assetId);
+ /**
+ * Same as {@link #get} but only returns a partially loaded asset (no attributes or path)
+ */
+ @GET
+ @Path("partial/{assetId}")
+ @Produces(APPLICATION_JSON)
+ @SuccessStatusCode(200)
+ @RolesAllowed({"read:assets"})
+ @SuppressWarnings("unusable-by-js")
+ Asset getPartial(@BeanParam RequestParams requestParams, @PathParam("assetId") String assetId);
+
/**
* Updates the asset. Regular users can only update assets in their authenticated realm, the superuser can update
* assets in other (all) realms. A 403 status is returned if a regular user tries to update an asset in a realm
diff --git a/model/src/main/java/org/openremote/model/notification/NotificationResource.java b/model/src/main/java/org/openremote/model/notification/NotificationResource.java
index 3ff07da67..9e57e81d5 100644
--- a/model/src/main/java/org/openremote/model/notification/NotificationResource.java
+++ b/model/src/main/java/org/openremote/model/notification/NotificationResource.java
@@ -37,7 +37,8 @@ public interface NotificationResource {
/**
* Gets all sent notifications that have been sent to the specified targets; optionally limiting the scope of the
* request by {@link AbstractNotificationMessage} type and/or sent datetime. If type(s) or timestamp are not set
- * then it is assumed no type or time constraint is required.
+ * then it is assumed no type or time constraint is required. Can also provide a list of notification IDs to get
+ * specific notifications.
* <p>
* Only the superuser can call this operation.
*/
@@ -47,6 +48,7 @@ public interface NotificationResource {
@RolesAllowed({"read:admin"})
@SuppressWarnings("unusable-by-js")
SentNotification[] getNotifications(@BeanParam RequestParams requestParams,
+ @QueryParam("ids") List<Long> ids,
@QueryParam("types") List<String> types,
@QueryParam("before") Long timestamp,
@QueryParam("tenantId") List<String> tenantIds,
@@ -56,7 +58,8 @@ public interface NotificationResource {
/**
* Removes all sent notifications that have been sent to the specified targets; optionally limiting the scope of the
* request by {@link AbstractNotificationMessage} type and/or sent datetime. If type(s) or timestamp are not set
- * then it is assumed no type or time constraint is required.
+ * then it is assumed no type or time constraint is required. Can also provide a list of notification IDs to delete
+ * specific notifications.
* <p>
* Only the superuser can call this operation.
*/
@@ -65,11 +68,12 @@ public interface NotificationResource {
@RolesAllowed({"write:admin"})
@SuppressWarnings("unusable-by-js")
void removeNotifications(@BeanParam RequestParams requestParams,
+ @QueryParam("ids") List<Long> ids,
@QueryParam("types") List<String> types,
@QueryParam("before") Long timestamp,
- @QueryParam("tenantId") List<String> tenantIds,
- @QueryParam("userId") List<String> userIds,
- @QueryParam("assetId") List<String> assetIds);
+ @QueryParam("tenantIds") List<String> tenantIds,
+ @QueryParam("userIds") List<String> userIds,
+ @QueryParam("assetIds") List<String> assetIds);
/**
* Remove a specific sent notification by ID.
diff --git a/test/src/main/groovy/org/openremote/test/TestAppSecurity.java b/test/src/main/groovy/org/openremote/test/TestAppSecurity.java
index 79e92de3a..f20ad5d89 100644
--- a/test/src/main/groovy/org/openremote/test/TestAppSecurity.java
+++ b/test/src/main/groovy/org/openremote/test/TestAppSecurity.java
@@ -26,10 +26,10 @@ import org.keycloak.representations.AccessToken;
import org.openremote.app.client.AppSecurity;
import org.openremote.model.Constants;
import org.openremote.model.http.RequestParams;
-import org.openremote.model.interop.BiConsumer;
-import org.openremote.model.interop.Consumer;
import org.openremote.model.interop.Runnable;
+import java.util.function.Consumer;
+
/**
* Does the same job as or-app-security.
*/
diff --git a/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy b/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy
index 58965b473..ff8fe0440 100644
--- a/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy
@@ -274,7 +274,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
// -----------------------------------------------
when: "the admin user requests the notifications for customer A consoles"
- def notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ def notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "all notifications sent to these consoles should be returned"
assert notifications.size() == 15
@@ -288,7 +288,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
when: "the admin user marks a customer A console notification as delivered and requests the notifications for customer A consoles"
adminNotificationResource.notificationDelivered(null, testuser2Console.id, notifications.find {n -> n.targetId == testuser2Console.id}.id)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "the notification should have been updated"
assert notifications.size() == 15
@@ -296,7 +296,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
when: "the admin user marks a customer A console notification as delivered and requests the notifications for customer A consoles"
adminNotificationResource.notificationAcknowledged(null, testuser2Console.id, notifications.find {n -> n.targetId == testuser2Console.id && n.deliveredOn != null}.id, Values.create("dismissed"))
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "the notification should have been updated"
assert notifications.size() == 15
@@ -311,7 +311,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
when: "a regular user marks a console notification for their own console as delivered"
testuser3NotificationResource.notificationDelivered(null, testuser3Console1.id, notifications.find {n -> n.targetId == testuser3Console1.id}.id)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "the notification should have been updated"
assert notifications.size() == 15
@@ -326,21 +326,21 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
when: "an anonymous user marks a console notification for their own console as delivered"
anonymousNotificationResource.notificationDelivered(null, anonymousConsole.id, notifications.find {n -> n.targetId == anonymousConsole.id}.id)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "the notification should have been updated"
assert notifications.size() == 15
assert notifications.count {n -> n.targetId == anonymousConsole.id && n.deliveredOn != null} == 1
when: "a regular user tries to remove notifications"
- testuser1NotificationResource.removeNotifications(null, [PushNotificationMessage.TYPE], null, [MASTER_REALM], null, null)
+ testuser1NotificationResource.removeNotifications(null, null, [PushNotificationMessage.TYPE], null, [MASTER_REALM], null, null)
then: "access should be forbidden"
ex = thrown()
ex.response.status == 403
when: "a restricted user tries to remove notifications"
- testuser3NotificationResource.removeNotifications(null, [PushNotificationMessage.TYPE], null, [realm], null, null)
+ testuser3NotificationResource.removeNotifications(null, null, [PushNotificationMessage.TYPE], null, [realm], null, null)
then: "access should be forbidden"
ex = thrown()
@@ -348,29 +348,29 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
when: "the admin user removes notifications by timestamp and the notifications are retrieved again"
notifications = notifications.sort {n -> n.sentOn}
- adminNotificationResource.removeNotifications(null, [PushNotificationMessage.TYPE], notifications[0].sentOn.getTime(), null, null, null)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ adminNotificationResource.removeNotifications(null, null, [PushNotificationMessage.TYPE], notifications[0].sentOn.getTime(), null, null, null)
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "notifications sent before or at that time should have been removed"
assert notifications.size() == 11
when: "the admin user removes notifications sent to specific console assets without other constraints and the notifications are retrieved again"
- adminNotificationResource.removeNotifications(null, null, null, null, null, [testuser3Console1.id, testuser3Console2.id])
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ adminNotificationResource.removeNotifications(null, null, null, null, null, null, [testuser3Console1.id, testuser3Console2.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "all notifications sent to those consoles should have been removed"
assert notifications.size() == 5
assert notifications.count {n -> n.targetId == testuser3Console1.id || n.targetId == testuser3Console2.id} == 0
when: "the admin user removes notifications by type and the notifications are retrieved again"
- adminNotificationResource.removeNotifications(null, [PushNotificationMessage.TYPE], null, null, null, null)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ adminNotificationResource.removeNotifications(null, null, [PushNotificationMessage.TYPE], null, null, null, null)
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "one notification should have been removed"
assert notifications.size() == 0
when: "the admin user removes notifications without sufficient constraints"
- adminNotificationResource.removeNotifications(null, null, null, null, null, null)
+ adminNotificationResource.removeNotifications(null, null, null, null, null, null, null)
then: "request should not be allowed"
ex = thrown()
@@ -389,21 +389,21 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
advancePseudoClock(ChronoUnit.MILLIS.between(Instant.ofEpochMilli(getClockTimeOf(container)).atZone(ZoneId.systemDefault()), advancement), TimeUnit.MILLISECONDS, container)
notification.setRepeatFrequency(RepeatFrequency.HOURLY)
testuser3NotificationResource.sendNotification(null, notification)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "the notifications should have been sent"
assert notifications.size() == 2
when: "a repeat frequency is set and a notification with the same name and scope as a previous notification is sent within the repeat window"
testuser3NotificationResource.sendNotification(null, notification)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "no new notifications should have been sent"
assert notifications.size() == 2
when: "a repeat frequency is set and a notification with the same name but different scope is sent within the repeat window"
adminNotificationResource.sendNotification(null, notification)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "new notifications should have been sent"
assert notifications.size() == 4
@@ -411,7 +411,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
when: "time advances less than the repeat frequency and the notification is sent again"
advancePseudoClock(30, TimeUnit.SECONDS, container)
adminNotificationResource.sendNotification(null, notification)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "no new notifications should have been sent"
assert notifications.size() == 4
@@ -419,7 +419,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
when: "time advances more than the repeat frequency and the notification is sent again"
advancePseudoClock(2, TimeUnit.MINUTES, container)
adminNotificationResource.sendNotification(null, notification)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "new notifications should have been sent"
assert notifications.size() == 6
@@ -428,7 +428,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
notification.setRepeatInterval("1mn")
advancePseudoClock(10, TimeUnit.DAYS, container)
adminNotificationResource.sendNotification(null, notification)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "no new notifications should have been sent"
assert notifications.size() == 6
@@ -436,7 +436,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
when: "time advances more than the repeat interval and the notification is sent again"
advancePseudoClock(30, TimeUnit.DAYS, container)
adminNotificationResource.sendNotification(null, notification)
- notifications = adminNotificationResource.getNotifications(null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
+ notifications = adminNotificationResource.getNotifications(null, null, null, null, null, null, [testuser2Console.id, testuser3Console1.id, testuser3Console2.id, anonymousConsole.id])
then: "new notifications should have been sent"
assert notifications.size() == 8