From 187cd8b799180ae1a37025617edd707ef4e1f273 Mon Sep 17 00:00:00 2001 From: "massimiliano.assante" Date: Thu, 31 Jan 2013 23:29:10 +0000 Subject: [PATCH] release ready git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/notifications@68672 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/NotificationsService.java | 2 + .../client/NotificationsServiceAsync.java | 4 + .../client/view/NotificationSettings.java | 104 +++++++++++++++++- .../client/view/NotificationsPanel.java | 5 +- .../server/NotificationsServiceImpl.java | 14 ++- src/main/webapp/images/yes.png | Bin 0 -> 2409 bytes 6 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 src/main/webapp/images/yes.png 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 c8264b1..196f349 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 @@ -22,4 +22,6 @@ public interface NotificationsService extends RemoteService { boolean setAllUserNotificationsRead(); ArrayList getNotificationChannels(); + + boolean setNotificationChannels(HashMap newSettings); } 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 bad75d7..9dfba3d 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 @@ -22,6 +22,10 @@ public interface NotificationsServiceAsync { void getNotificationChannels( AsyncCallback> callback); + void setNotificationChannels( + HashMap newSettings, + 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 index 20016b4..5575e5d 100644 --- 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 @@ -1,15 +1,24 @@ package org.gcube.portlets.user.notifications.client.view; import java.util.ArrayList; +import java.util.HashMap; import org.gcube.portal.databook.shared.NotificationChannelType; import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog; +import org.gcube.portlets.user.notifications.client.NotificationsServiceAsync; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.rpc.AsyncCallback; 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.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; @@ -19,14 +28,18 @@ public class NotificationSettings extends GCubeDialog { private HorizontalPanel buttonsContainerPanel = new HorizontalPanel(); private HorizontalPanel buttonsPanel = new HorizontalPanel(); - private CheckBox portalCB = new CheckBox("This Portal"); - private CheckBox emailCB = new CheckBox("Email"); + public static final String loading = GWT.getModuleBaseURL() + "../images/feeds-loader.gif"; + public static final String mailSentOK = GWT.getModuleBaseURL() + "../images/yes.png"; + public static final String mailSentNOK = GWT.getModuleBaseURL() + "../images/warning_blue.png"; + + private CheckBox portalCheckbox = new CheckBox("Infrastructure Gateway (this portal)"); + private CheckBox emailCheckbox = 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) { + public NotificationSettings(final ArrayList currentChannels, final NotificationsServiceAsync notificationService) { super(); buttonsPanel.setWidth("100%"); buttonsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); @@ -34,8 +47,9 @@ public class NotificationSettings extends GCubeDialog { container.setStyleName("user-notification"); container.setWidth("400px"); container.add(how); - container.add(portalCB); - container.add(emailCB); + container.add(new HTML(" ")); + container.add(portalCheckbox); + container.add(emailCheckbox); buttonsContainerPanel.add(cancel); buttonsContainerPanel.add(save); @@ -44,6 +58,86 @@ public class NotificationSettings extends GCubeDialog { setText("Notification Settings"); setWidget(container); + + if (currentChannels.contains(NotificationChannelType.EMAIL)) + emailCheckbox.setValue(true); + + if (currentChannels.contains(NotificationChannelType.PORTAL)) + portalCheckbox.setValue(true); + + save.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + boolean portalChanged = (portalCheckbox.getValue() && !currentChannels.contains(NotificationChannelType.PORTAL) || + !portalCheckbox.getValue() && currentChannels.contains(NotificationChannelType.PORTAL)); + + boolean emailChanged = (emailCheckbox.getValue() && !currentChannels.contains(NotificationChannelType.EMAIL) || + !emailCheckbox.getValue() && currentChannels.contains(NotificationChannelType.EMAIL)); + + HashMap newSettings = new HashMap(); + if (portalChanged) { + newSettings.put(NotificationChannelType.PORTAL, portalCheckbox.getValue()); + } + if (emailChanged) { + newSettings.put(NotificationChannelType.EMAIL, emailCheckbox.getValue()); + } + + if (portalChanged || emailChanged) + notificationService.setNotificationChannels(newSettings, new AsyncCallback() { + @Override + public void onSuccess(Boolean result) { + showDeliveryResult(result); + + } + @Override + public void onFailure(Throwable caught) { + showDeliveryResult(false); + } + }); + else + showDeliveryResult(true); + + } + }); + + cancel.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + hide(); + } + }); + + } + + private void showDeliveryResult(boolean success) { + container.clear(); + container.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); + container.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); + if (success) { + setText("Notifications Settings Saved"); + container.add(new Image(mailSentOK)); + } + else { + setText("Notifications Settings Saving Error"); + container.add(new Image(mailSentNOK)); + container.add(new HTML("There were problems contacting the server, please try again in a short while.")); + Button close = new Button("Close"); + close.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + hide(); + } + }); + } + Button close = new Button("Close"); + close.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + hide(); + } + }); + container.add(close); } } 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 d2f549b..c03e8bd 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 @@ -4,8 +4,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.HashMap; -import java.util.SortedSet; -import java.util.TreeSet; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.NotificationChannelType; @@ -16,7 +14,6 @@ import org.gcube.portlets.user.notifications.client.view.templates.DayWrapper; import org.gcube.portlets.user.notifications.client.view.templates.SingleNotificationView; 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; @@ -88,7 +85,7 @@ public class NotificationsPanel extends Composite { @Override public void onSuccess(ArrayList result) { - NotificationSettings dlg = new NotificationSettings(result); + NotificationSettings dlg = new NotificationSettings(result, notificationService); dlg.center(); dlg.show(); } 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 75b9cff..ccea716 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 @@ -60,9 +60,9 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No String sessionID = this.getThreadLocalRequest().getSession().getId(); String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); if (user == null) { - //user = "test.user"; + user = "test.user"; //user = "leonardo.candela"; - user = "massimiliano.assante"; +// user = "massimiliano.assante"; _log.warn("USER IS NULL setting "+user+" and Running OUTSIDE PORTAL"); withinPortal = false; } @@ -174,4 +174,14 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No } return toReturn; } + + @Override + public boolean setNotificationChannels(HashMap newSettings) { + boolean toReturn = false; + for (NotificationChannelType type : newSettings.keySet()) { + _log.error("Trying to set User notification Setting: " + type + " to: " + newSettings.get(type)); + toReturn = store.setUserNotificationChannel(getASLSession().getUsername(), type, newSettings.get(type)); + } + return toReturn; + } } diff --git a/src/main/webapp/images/yes.png b/src/main/webapp/images/yes.png new file mode 100644 index 0000000000000000000000000000000000000000..02ac8f7916222d9501d0c43e33dac37782cc1eb6 GIT binary patch literal 2409 zcmV-v36}PWP)&@0_i!F92 zu3R;4{`}?RUY~kh#VQajjMn&G+y8!N`v1bf{2z~PxO(-(_5M<$oS7+7<*TzJ#Cg4@PEDonCNdJJRC@i53o0WFHGOhF5(NY%9P65SHJ5B|6Nldp_{tM8j& z+F|22b8o5p6$EP~#u$_vbp(JI41%Db9;3WUgH6|$m>F3DqN7ud%VTUR|RIFFez#vBX32$NKUp^Mk16F9L3 zr4$H6hArX%AWqlVyxVH)CoC#|Ytb*pzh{MvKQ6qd-aa4kb8bmoa_Qpu8x=GCa{+<4 zIhHLEfaJl?DS3x;ggcy8W@g^CA^Ak6+xa!HyHqn}@AgO$EV3w0o zQ_83KHyzyC|`>1QxvQ znbwD#tatxEA35Nh(!h+HDre1JR{dHqq19_-ARtPppt2~bH>b!PT@kD@H?=nQW=AT1 z=CaCb=dP^XXqQrjK{m&&dT68*vtnj7P+}-o%Hv~B3wqs7Vwar8=Z@TK*y49@|8~C| zh<%cQIV-CdUUqBZ6{{SThOiJfYvI#^WC|ZLvX?>$z1|L5*ZAZ5>#f^*Q>PQY;NCi_ zo)!MV<*RDeYC#pYgrCaH1PB7mie$e~$qH%+m+a9o=MXYp3aUW)t$#SQ!U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