diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsService.java b/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsService.java index bd9726a..c8264b1 100644 --- a/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsService.java +++ b/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsService.java @@ -4,9 +4,9 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; -import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portal.databook.shared.Notification; - +import org.gcube.portal.databook.shared.NotificationChannelType; +import org.gcube.portal.databook.shared.UserInfo; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -20,4 +20,6 @@ public interface NotificationsService extends RemoteService { HashMap> getUserNotifications(); boolean setAllUserNotificationsRead(); + + ArrayList getNotificationChannels(); } diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsServiceAsync.java b/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsServiceAsync.java index 2d9a351..bad75d7 100644 --- a/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/notifications/client/NotificationsServiceAsync.java @@ -5,6 +5,7 @@ import java.util.Date; import java.util.HashMap; import org.gcube.portal.databook.shared.Notification; +import org.gcube.portal.databook.shared.NotificationChannelType; import org.gcube.portal.databook.shared.UserInfo; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -18,6 +19,9 @@ public interface NotificationsServiceAsync { void setAllUserNotificationsRead(AsyncCallback callback); + void getNotificationChannels( + AsyncCallback> callback); + } diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationSettings.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationSettings.java new file mode 100644 index 0000000..20016b4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationSettings.java @@ -0,0 +1,49 @@ +package org.gcube.portlets.user.notifications.client.view; + +import java.util.ArrayList; + +import org.gcube.portal.databook.shared.NotificationChannelType; +import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog; + +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.CheckBox; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.VerticalPanel; + + +public class NotificationSettings extends GCubeDialog { + + private VerticalPanel container = new VerticalPanel(); + private HorizontalPanel buttonsContainerPanel = new HorizontalPanel(); + private HorizontalPanel buttonsPanel = new HorizontalPanel(); + + private CheckBox portalCB = new CheckBox("This Portal"); + private CheckBox emailCB = new CheckBox("Email"); + private HTML how = new HTML("How You Get Notifications:"); + + private Button cancel = new Button("Cancel"); + private Button save = new Button("Save"); + + public NotificationSettings(ArrayList currentChannels) { + super(); + buttonsPanel.setWidth("100%"); + buttonsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); + + container.setStyleName("user-notification"); + container.setWidth("400px"); + container.add(how); + container.add(portalCB); + container.add(emailCB); + + buttonsContainerPanel.add(cancel); + buttonsContainerPanel.add(save); + buttonsPanel.add(buttonsContainerPanel); + container.add(buttonsPanel); + + setText("Notification Settings"); + setWidget(container); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationsPanel.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationsPanel.java index 296284d..d2f549b 100644 --- a/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationsPanel.java +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/NotificationsPanel.java @@ -8,6 +8,7 @@ import java.util.SortedSet; import java.util.TreeSet; import org.gcube.portal.databook.shared.Notification; +import org.gcube.portal.databook.shared.NotificationChannelType; import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portlets.user.notifications.client.NotificationsService; import org.gcube.portlets.user.notifications.client.NotificationsServiceAsync; @@ -16,13 +17,17 @@ import org.gcube.portlets.user.notifications.client.view.templates.SingleNotific import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HasAlignment; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HasVerticalAlignment; +import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.VerticalPanel; @@ -37,11 +42,24 @@ public class NotificationsPanel extends Composite { private static final String warning = GWT.getModuleBaseURL() + "../images/warning_blue.png"; private UserInfo myUserInfo; private Image loadingImage; + + private VerticalPanel container = new VerticalPanel(); + private HorizontalPanel settingsPanel = new HorizontalPanel(); + private VerticalPanel mainPanel; + + private HTML notificationSettings = new HTML("Notification Settings"); public NotificationsPanel() { + notificationSettings.setVisible(false); mainPanel = new VerticalPanel(); mainPanel.setWidth("100%"); + container.setWidth("100%"); + settingsPanel.setWidth("100%"); + settingsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); + settingsPanel.add(notificationSettings); + container.add(settingsPanel); + container.add(mainPanel); loadingImage = new Image(loading); showLoader(); @@ -59,10 +77,28 @@ public class NotificationsPanel extends Composite { } } }); + initWidget(container); + + notificationSettings.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + notificationService.getNotificationChannels(new AsyncCallback>() { + @Override + public void onFailure(Throwable caught) { } - initWidget(mainPanel); + @Override + public void onSuccess(ArrayList result) { + NotificationSettings dlg = new NotificationSettings(result); + dlg.center(); + dlg.show(); + } + }); + } + }); } + + private void showUserNotifications() { showLoader(); notificationService.getUserNotifications(new AsyncCallback>>() { @@ -72,6 +108,7 @@ public class NotificationsPanel extends Composite { } public void onSuccess(HashMap> notificationsPerDay) { + notificationSettings.setVisible(true); if (notificationsPerDay != null) { mainPanel.clear(); if (notificationsPerDay.size() == 0) { diff --git a/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java b/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java index 586334e..75b9cff 100644 --- a/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/notifications/server/NotificationsServiceImpl.java @@ -13,7 +13,9 @@ import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DatabookStore; import org.gcube.portal.databook.shared.Notification; +import org.gcube.portal.databook.shared.NotificationChannelType; import org.gcube.portal.databook.shared.UserInfo; +import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException; import org.gcube.portlets.user.notifications.client.NotificationsService; import com.google.gwt.user.server.rpc.RemoteServiceServlet; @@ -59,8 +61,8 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); if (user == null) { //user = "test.user"; - user = "leonardo.candela"; - //user = "massimiliano.assante"; + //user = "leonardo.candela"; + user = "massimiliano.assante"; _log.warn("USER IS NULL setting "+user+" and Running OUTSIDE PORTAL"); withinPortal = false; } @@ -159,4 +161,17 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No } return false; } + + @Override + public ArrayList getNotificationChannels() { + ArrayList toReturn = new ArrayList(); + try { + for (NotificationChannelType channel : store.getUserNotificationChannels(getASLSession().getUsername())) + toReturn.add(channel); + + } catch (NotificationChannelTypeNotFoundException e) { + e.printStackTrace(); + } + return toReturn; + } } diff --git a/src/main/webapp/Notifications.css b/src/main/webapp/Notifications.css index 4489a39..4314282 100644 --- a/src/main/webapp/Notifications.css +++ b/src/main/webapp/Notifications.css @@ -23,7 +23,7 @@ a.link:hover { border-bottom-color: #DADADA; border-bottom-style: solid; border-bottom-width: 1px; - padding: 12px 7px 3px; + padding: 5px 7px 3px; } .day-label { @@ -70,6 +70,14 @@ a.link:hover { white-space: nowrap; } +.gwt-CheckBox { + margin: 5px; + padding: 5px; +} + +.gwt-CheckBox label { + padding: 5px; +} .user-notification { width: 99%; color: #333;