From 27802448c52da0bbafd6e02e349538fe45a6ef04 Mon Sep 17 00:00:00 2001 From: "massimiliano.assante" Date: Wed, 5 Jun 2013 16:45:10 +0000 Subject: [PATCH] integrated GQuery (GWT jQuery) git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/notifications@76802 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 6 + .../client/NotificationsService.java | 5 +- .../client/NotificationsServiceAsync.java | 5 +- .../client/view/NotificationSettings.java | 89 +++++++++---- .../client/view/NotificationsPanel.java | 19 +-- .../view/templates/CategoryWrapper.java | 29 +++++ .../view/templates/CategoryWrapper.ui.xml | 7 ++ .../client/view/templates/Div.java | 23 ++++ .../templates/NotificationPreference.java | 29 ----- .../templates/NotificationPreference.ui.xml | 13 -- .../templates/NotificationPreferenceView.java | 36 ++++++ .../NotificationPreferenceView.ui.xml | 22 ++++ .../client/view/templates/SlidingButton.java | 43 +++++++ .../view/templates/SlidingButton.ui.xml | 8 ++ .../client/view/templates/SwitchButton.java | 43 +++++++ .../client/view/templates/SwitchButton.ui.xml | 15 +++ .../server/NotificationsServiceImpl.java | 118 ++++++++++++++++-- .../shared/NotificationPreference.java | 78 ++++++++++++ .../user/notifications/Notifications.gwt.xml | 2 + src/main/webapp/Notifications.css | 112 +++++++++-------- .../NotificationTypeCategories.properties | 3 - .../webapp/conf/categorybytype.properties | 20 +++ ...tions.properties => descbytype.properties} | 0 ...mans.properties => labelbytype.properties} | 0 24 files changed, 589 insertions(+), 136 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/CategoryWrapper.java create mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/CategoryWrapper.ui.xml create mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/Div.java delete mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreference.java delete mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreference.ui.xml create mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreferenceView.java create mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreferenceView.ui.xml create mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SlidingButton.java create mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SlidingButton.ui.xml create mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SwitchButton.java create mode 100644 src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SwitchButton.ui.xml create mode 100644 src/main/java/org/gcube/portlets/user/notifications/shared/NotificationPreference.java delete mode 100644 src/main/webapp/conf/NotificationTypeCategories.properties create mode 100644 src/main/webapp/conf/categorybytype.properties rename src/main/webapp/conf/{NotificationTypeDescriptions.properties => descbytype.properties} (100%) rename src/main/webapp/conf/{NotificationTypeHumans.properties => labelbytype.properties} (100%) diff --git a/pom.xml b/pom.xml index b15e172..ca87e9b 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,12 @@ ${gwtVersion} provided + + com.googlecode.gwtquery + gwtquery + 1.3.3 + provided + org.gcube.core gcf 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 d8a592a..2db7a34 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 @@ -3,12 +3,15 @@ package org.gcube.portlets.user.notifications.client; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.TreeMap; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.NotificationChannelType; import org.gcube.portal.databook.shared.NotificationType; import org.gcube.portal.databook.shared.UserInfo; +import org.gcube.portlets.user.notifications.shared.NotificationPreference; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -23,7 +26,7 @@ public interface NotificationsService extends RemoteService { boolean setAllUserNotificationsRead(); - HashMap getUserNotificationPreferences(); + LinkedHashMap> getUserNotificationPreferences(); boolean setUserNotificationPreferences(Map enabledChannels); } 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 27099c6..75a811a 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 @@ -3,12 +3,14 @@ package org.gcube.portlets.user.notifications.client; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.NotificationChannelType; import org.gcube.portal.databook.shared.NotificationType; import org.gcube.portal.databook.shared.UserInfo; +import org.gcube.portlets.user.notifications.shared.NotificationPreference; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -21,7 +23,8 @@ public interface NotificationsServiceAsync { void setAllUserNotificationsRead(AsyncCallback callback); - void getUserNotificationPreferences(AsyncCallback> callback); + void getUserNotificationPreferences( + AsyncCallback>> callback); void setUserNotificationPreferences( Map enabledChannels, 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 c9d319c..61687ad 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 @@ -2,17 +2,23 @@ package org.gcube.portlets.user.notifications.client.view; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.TreeMap; -import org.gcube.portal.databook.shared.NotificationChannelType; -import org.gcube.portal.databook.shared.NotificationType; import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog; import org.gcube.portlets.user.notifications.client.NotificationsServiceAsync; -import org.gcube.portlets.user.notifications.client.view.templates.NotificationPreference; +import org.gcube.portlets.user.notifications.client.view.templates.CategoryWrapper; +import org.gcube.portlets.user.notifications.client.view.templates.NotificationPreferenceView; +import org.gcube.portlets.user.notifications.shared.NotificationPreference; + 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.DOM; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.CheckBox; import com.google.gwt.user.client.ui.HTML; @@ -21,8 +27,23 @@ 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.Label; +import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; +import com.google.gwt.query.client.GQuery; +import com.google.gwt.query.client.Function; +import com.google.gwt.query.client.Selector; +import com.google.gwt.query.client.Selectors; +import com.google.gwt.query.client.css.CSS; +import com.google.gwt.query.client.css.RGBColor; + +import static com.google.gwt.query.client.GQuery.*; +import static com.google.gwt.query.client.css.CSS.*; + +import static com.google.gwt.query.client.plugins.Effects.Effects; +import static com.google.gwt.query.client.GQuery.$; /** * @author Massimiliano Assante ISTI-CNR @@ -38,47 +59,71 @@ public class NotificationSettings extends GCubeDialog { 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"); - private HashMap preferences; + private LinkedHashMap> preferences; - public NotificationSettings(final HashMap preferences, final NotificationsServiceAsync notificationService) { + public NotificationSettings(LinkedHashMap> preferences, final NotificationsServiceAsync notificationService) { super(); + ScrollPanel scroller = new ScrollPanel(); + scroller.setWidth("1000px"); + scroller.setHeight("500px"); this.preferences = preferences; buttonsPanel.setWidth("100%"); buttonsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); container.setStyleName("user-notification"); - container.setWidth("800px"); - container.add(how); - container.add(new HTML(" ")); - container.add(new NotificationPreference()); + container.setWidth("950px"); + for (String category : preferences.keySet()) { + container.add(new CategoryWrapper(category)); + for (NotificationPreference pref : preferences.get(category)) { + container.add(new NotificationPreferenceView(pref)); + } + } - - container.add(portalCheckbox); - container.add(emailCheckbox); + buttonsContainerPanel.add(cancel); buttonsContainerPanel.add(save); buttonsPanel.add(buttonsContainerPanel); container.add(buttonsPanel); + setText("Notification Settings"); - setWidget(container); + scroller.add(container); + setWidget(scroller); - - save.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { + Label label = new Label("test"); + DOM.setElementProperty(label.getElement(), "id", "myId"); + buttonsContainerPanel.add(label); + Timer t = new Timer() { + @Override + public void run() { + $("#myId").css(CSS.BACKGROUND_COLOR.with(RGBColor.RED)); + + $("#myId").click(new Function() { + @Override + public void f(Widget w) { + Window.alert("Ciao"); + //fade out the button + $(w).fadeOut(1000); + } + }); } - }); + }; + t.schedule(1000); + + +// save.addClickHandler(new ClickHandler() { +// @Override +// public void onClick(ClickEvent event) { +// +// } +// }); cancel.addClickHandler(new ClickHandler() { 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 c3d2462..6dd3ed8 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,6 +4,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.TreeMap; + import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.NotificationChannelType; @@ -13,6 +16,7 @@ import org.gcube.portlets.user.notifications.client.NotificationsService; import org.gcube.portlets.user.notifications.client.NotificationsServiceAsync; import org.gcube.portlets.user.notifications.client.view.templates.DayWrapper; import org.gcube.portlets.user.notifications.client.view.templates.SingleNotificationView; +import org.gcube.portlets.user.notifications.shared.NotificationPreference; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; @@ -85,20 +89,19 @@ public class NotificationsPanel extends Composite { @Override public void onClick(ClickEvent event) { - notificationService.getUserNotificationPreferences(new AsyncCallback>() { + notificationService.getUserNotificationPreferences(new AsyncCallback>>() { @Override - public void onFailure(Throwable caught) { - } + public void onFailure(Throwable caught) { } @Override - public void onSuccess(HashMap result) { + public void onSuccess(LinkedHashMap> result) { + NotificationSettings dlg = new NotificationSettings(result, notificationService); dlg.center(); - dlg.show(); + dlg.show(); + } - }); - - + }); } }); } diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/CategoryWrapper.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/CategoryWrapper.java new file mode 100644 index 0000000..dbba308 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/CategoryWrapper.java @@ -0,0 +1,29 @@ +package org.gcube.portlets.user.notifications.client.view.templates; + +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.Composite; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.Widget; + +/** + * @author Massimiliano Assante ISTI-CNR + * + */ +public class CategoryWrapper extends Composite { + + private static CategoryWrapperUiBinder uiBinder = GWT + .create(CategoryWrapperUiBinder.class); + + interface CategoryWrapperUiBinder extends UiBinder { + } + + @UiField HTML categoryLabel; + + public CategoryWrapper(String catName) { + initWidget(uiBinder.createAndBindUi(this)); + categoryLabel.setHTML(catName); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/CategoryWrapper.ui.xml b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/CategoryWrapper.ui.xml new file mode 100644 index 0000000..a7599ff --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/CategoryWrapper.ui.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/Div.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/Div.java new file mode 100644 index 0000000..f8fa60b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/Div.java @@ -0,0 +1,23 @@ +package org.gcube.portlets.user.notifications.client.view.templates; + +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasText; + +/** + * + * @author Massimiliano Assante, ISTI-CNR + * @version 0.1 Sep 2012 + * + */ +public class Div extends HTML implements HasText { + + public Div() { + super(DOM.createElement("div")); + } + + public Div(String text) { + this(); + setText(text); + } +} diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreference.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreference.java deleted file mode 100644 index c2513ea..0000000 --- a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreference.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.gcube.portlets.user.notifications.client.view.templates; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.uibinder.client.UiBinder; -import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.uibinder.client.UiHandler; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.HasText; -import com.google.gwt.user.client.ui.Widget; - -public class NotificationPreference extends Composite { - - private static NotificationPreferenceUiBinder uiBinder = GWT - .create(NotificationPreferenceUiBinder.class); - - interface NotificationPreferenceUiBinder extends - UiBinder { - } - - public NotificationPreference() { - initWidget(uiBinder.createAndBindUi(this)); - } - - - -} diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreference.ui.xml b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreference.ui.xml deleted file mode 100644 index f2a27e2..0000000 --- a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreference.ui.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - -
-
WP_FOLDER_SHARE
-
use to notify a user he got a workspace folder shared
-
-
-
-
-
-
\ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreferenceView.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreferenceView.java new file mode 100644 index 0000000..a950859 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreferenceView.java @@ -0,0 +1,36 @@ +package org.gcube.portlets.user.notifications.client.view.templates; + +import org.gcube.portlets.user.notifications.shared.NotificationPreference; + +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.CheckBox; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; + +public class NotificationPreferenceView extends Composite { + + private static NotificationPreferenceUiBinder uiBinder = GWT + .create(NotificationPreferenceUiBinder.class); + + interface NotificationPreferenceUiBinder extends + UiBinder { + } + + @UiField Span prefType; + @UiField Span prefDesc; + + @UiField CheckBox portalCheckbox; + @UiField CheckBox emailCheckbox; + //@UiField CheckBox noneCheckbox; + + public NotificationPreferenceView(NotificationPreference toDisplay) { + initWidget(uiBinder.createAndBindUi(this)); + prefType.setHTML(toDisplay.getTypeLabel()); + prefDesc.setHTML(toDisplay.getTypeDesc()); + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreferenceView.ui.xml b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreferenceView.ui.xml new file mode 100644 index 0000000..8cf46ce --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/NotificationPreferenceView.ui.xml @@ -0,0 +1,22 @@ + + + + + + + + + +
+ + + + Portal + Email + + +
+
+
\ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SlidingButton.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SlidingButton.java new file mode 100644 index 0000000..6dc992e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SlidingButton.java @@ -0,0 +1,43 @@ +package org.gcube.portlets.user.notifications.client.view.templates; + +import static com.google.gwt.query.client.GQuery.$; + +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.query.client.Function; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FocusPanel; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Widget; + +public class SlidingButton extends Composite { + + private static SlidingButtonUiBinder uiBinder = GWT + .create(SlidingButtonUiBinder.class); + + interface SlidingButtonUiBinder extends UiBinder { + } + + @UiField FocusPanel switchContainer; + @UiField Div switcherButton; + + public SlidingButton() { + initWidget(uiBinder.createAndBindUi(this)); + switchContainer.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + //switcherButton.getElement().getStyle().setLeft(-1, Unit.PX); + //// Animate the switch + // this.button.animate({ left: newLeft }, 250, "easeInOutCubic"); + $(switcherButton).animate("left: -1", 250); + } + }); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SlidingButton.ui.xml b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SlidingButton.ui.xml new file mode 100644 index 0000000..2f79083 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SlidingButton.ui.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SwitchButton.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SwitchButton.java new file mode 100644 index 0000000..30c5d95 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SwitchButton.java @@ -0,0 +1,43 @@ +package org.gcube.portlets.user.notifications.client.view.templates; + +import static com.google.gwt.query.client.GQuery.$; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.query.client.Function; +import com.google.gwt.query.client.css.CSS; +import com.google.gwt.query.client.css.RGBColor; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; + +public class SwitchButton extends Composite { + + private static SwitchButtonUiBinder uiBinder = GWT + .create(SwitchButtonUiBinder.class); + + interface SwitchButtonUiBinder extends UiBinder { + } + + public SwitchButton() { + initWidget(uiBinder.createAndBindUi(this)); + Timer t = new Timer() { + @Override + public void run() { + $("#switchButton").click(new Function() { + @Override + public void f() { + Window.alert("Ciao"); + //fade out the button + // $(w).fadeOut(1000); + } + }); + } + }; + t.schedule(1000); + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SwitchButton.ui.xml b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SwitchButton.ui.xml new file mode 100644 index 0000000..446958a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SwitchButton.ui.xml @@ -0,0 +1,15 @@ + + + + OFF + + ON +
+
+
+ + + + \ No newline at end of file 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 a2bb3a8..d0c24eb 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 @@ -1,10 +1,18 @@ package org.gcube.portlets.user.notifications.server; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; + +import javax.servlet.ServletContext; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; @@ -17,9 +25,8 @@ import org.gcube.portal.databook.shared.Notification; import org.gcube.portal.databook.shared.NotificationChannelType; import org.gcube.portal.databook.shared.NotificationType; import org.gcube.portal.databook.shared.UserInfo; -import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException; -import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException; import org.gcube.portlets.user.notifications.client.NotificationsService; +import org.gcube.portlets.user.notifications.shared.NotificationPreference; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.liferay.portal.kernel.util.WebKeys; @@ -36,6 +43,9 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No * */ private static GCUBEClientLog _log = new GCUBEClientLog(NotificationsServiceImpl.class); + private final static String TYPE_CATEGORIES_FILENAME = "categorybytype.properties"; + private final static String TYPE_LABELS_FILENAME = "labelbytype.properties"; + private final static String TYPE_DESCRIPTIONS_FILENAME = "descbytype.properties"; /** * The store interface */ @@ -103,7 +113,7 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No } return new UserInfo(); } - + /** * returns the notifications separated per days */ @@ -155,17 +165,45 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No } return false; } - + @Override - public HashMap getUserNotificationPreferences() { + public LinkedHashMap> getUserNotificationPreferences() { String userid = getASLSession().getUsername(); - HashMap toReturn = new HashMap(); - try { - toReturn.putAll(store.getUserNotificationPreferences(userid)); + //load the 3 prop files + Properties categories = getCategoriesByType(); + Properties labels = getLabelsByType(); + Properties descriptions = getDescriptionsByType(); + + TreeMap> treeMap = new TreeMap>(); + try { + Map storePreferences = store.getUserNotificationPreferences(userid); + for (NotificationType type : storePreferences.keySet()) { + String category = categories.getProperty(type.toString()); + String typeLabel = labels.getProperty(type.toString()); + String typeDesc = descriptions.getProperty(type.toString()); + if (category != null) { + if (treeMap.containsKey(category)) { + treeMap.get(category).add(new NotificationPreference(type, typeLabel, typeDesc, storePreferences.get(type.toString()))); + } else { + ArrayList toAdd = new ArrayList(); + toAdd.add(new NotificationPreference(type, typeLabel, typeDesc, storePreferences.get(type.toString()))); + treeMap.put(category, toAdd); + } + } + } } catch (Exception e) { _log.error("While trying to get getUser Notification Preferences"); e.printStackTrace(); } + //need the key in revers order so that workspace appears first + LinkedHashMap> toReturn = new LinkedHashMap>(); + for (String category : treeMap.descendingKeySet()) { + ArrayList toAdd = new ArrayList(); + for (NotificationPreference pref : treeMap.get(category)) { + toAdd.add(pref); + } + toReturn.put(category, toAdd); + } return toReturn; } @@ -173,5 +211,69 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No public boolean setUserNotificationPreferences(Map enabledChannels) { return store.setUserNotificationPreferences(getASLSession().getUsername(), enabledChannels); } + /** + * + * @param type the type to look for + * @return the Category if there is correspodance, null otherwise + */ + private Properties getCategoriesByType() { + Properties props = new Properties(); + try { + ServletContext servletContext = getServletContext(); + String contextPath = servletContext.getRealPath(File.separator); + String propertyfile = contextPath + "conf" + File.separator + TYPE_CATEGORIES_FILENAME; + File propsFile = new File(propertyfile); + FileInputStream fis = new FileInputStream(propsFile); + props.load( fis); + return props; + } + //catch exception in case properties file does not exist + catch(IOException e) { + _log.error(TYPE_CATEGORIES_FILENAME + "file not found under conf dir, returning null"); + return null; + } + } + /** + * + * @return the properties for labels + */ + private Properties getLabelsByType() { + Properties props = new Properties(); + try { + ServletContext servletContext = getServletContext(); + String contextPath = servletContext.getRealPath(File.separator); + String propertyfile = contextPath + "conf" + File.separator + TYPE_LABELS_FILENAME; + File propsFile = new File(propertyfile); + FileInputStream fis = new FileInputStream(propsFile); + props.load( fis); + return props; + } + //catch exception in case properties file does not exist + catch(IOException e) { + _log.error(TYPE_LABELS_FILENAME + "file not found under conf dir, returning null"); + return null; + } + } + /** + * + * @return the properties for descriptions + */ + private Properties getDescriptionsByType() { + Properties props = new Properties(); + try { + ServletContext servletContext = getServletContext(); + String contextPath = servletContext.getRealPath(File.separator); + String propertyfile = contextPath + "conf" + File.separator + TYPE_DESCRIPTIONS_FILENAME; + File propsFile = new File(propertyfile); + FileInputStream fis = new FileInputStream(propsFile); + props.load( fis); + return props; + } + //catch exception in case properties file does not exist + catch(IOException e) { + _log.error(TYPE_DESCRIPTIONS_FILENAME + "file not found under conf dir, returning null"); + return null; + } + } } diff --git a/src/main/java/org/gcube/portlets/user/notifications/shared/NotificationPreference.java b/src/main/java/org/gcube/portlets/user/notifications/shared/NotificationPreference.java new file mode 100644 index 0000000..5981bd8 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/notifications/shared/NotificationPreference.java @@ -0,0 +1,78 @@ +package org.gcube.portlets.user.notifications.shared; + +import java.io.Serializable; +import java.util.Arrays; + +import org.gcube.portal.databook.shared.NotificationChannelType; +import org.gcube.portal.databook.shared.NotificationType; +/** + * @author Massimiliano Assante, CNR-ISTI + * This class represent a notification preference with its type (allowing associating a label and a description) + * and the channels selected by the user for this type + */ +@SuppressWarnings("serial") +public class NotificationPreference implements Serializable { + NotificationType type; + String typeLabel; + String typeDesc; + NotificationChannelType[] selectedChannels; + public NotificationPreference() { + super(); + } + + + public NotificationPreference(NotificationType type, String typeLabel, + String typeDesc, NotificationChannelType[] selectedChannels) { + super(); + this.type = type; + this.typeLabel = typeLabel; + this.typeDesc = typeDesc; + this.selectedChannels = selectedChannels; + } + + + public NotificationChannelType[] getSelectedChannels() { + return selectedChannels; + } + + + public void setSelectedChannels(NotificationChannelType[] selectedChannels) { + this.selectedChannels = selectedChannels; + } + + + public NotificationType getType() { + return type; + } + + public void setType(NotificationType type) { + this.type = type; + } + + public String getTypeLabel() { + return typeLabel; + } + + public void setTypeLabel(String typeLabel) { + this.typeLabel = typeLabel; + } + + public String getTypeDesc() { + return typeDesc; + } + + public void setTypeDesc(String typeDesc) { + this.typeDesc = typeDesc; + } + + + @Override + public String toString() { + return "NotificationPreference [type=" + type + ", typeLabel=" + + typeLabel + ", typeDesc=" + typeDesc + ", selectedChannels=" + + Arrays.toString(selectedChannels) + "]"; + } + + + +} diff --git a/src/main/resources/org/gcube/portlets/user/notifications/Notifications.gwt.xml b/src/main/resources/org/gcube/portlets/user/notifications/Notifications.gwt.xml index 60c930d..a3c6cbe 100644 --- a/src/main/resources/org/gcube/portlets/user/notifications/Notifications.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/notifications/Notifications.gwt.xml @@ -13,6 +13,8 @@ + + diff --git a/src/main/webapp/Notifications.css b/src/main/webapp/Notifications.css index d25d26f..8e78130 100644 --- a/src/main/webapp/Notifications.css +++ b/src/main/webapp/Notifications.css @@ -3,57 +3,6 @@ table { border-spacing: 0; } -#preferenceContainer { - border: 1px solid black; - position: relative; - height: 50px; -} - -#preferenceType { - border: 1px solid black; - position: absolute; - top: 0; - left: 0; - height: 50px; - width: 150px; -} - -#preferenceDesc { - border: 1px solid black; - position: absolute; - top: 0; - left: 150px; - height: 50px; - width: 500px; -} - -#preferenceSettingOff { - border: 1px solid black; - position: absolute; - top: 0; - left: 650px; - height: 50px; - width: 50px; -} - -#preferenceSettingPortal { - border: 1px solid black; - position: absolute; - top: 0; - left: 700px; - height: 50px; - width: 50px; -} - -#preferenceSettingEmail { - border: 1px solid black; - position: absolute; - top: 0; - left: 750px; - height: 50px; - width: 50px; -} - a.link,a.link:active,a.link:visited { font-family: 'Lucida Grande', Verdana, 'Bitstream Vera Sans', Arial, sans-serif; @@ -138,4 +87,65 @@ a.link:hover { border-color: #999; border-width: 1px; letter-spacing: normal; +} +.gwt-CheckBox { + margin-right: 0; + padding-right: 0; +} +.floatingLeft { + float:left; +} +/* Switch Button */ + +.switch-button-label { + float: left; + + font-size: 10pt; + cursor: pointer; +} + +.switch-button-label.off { + color: #adadad; +} + +.switch-button-label.on { + color: #0088CC; +} + +.switch-button-background { + float: left; + position: relative; + + background: #ccc; + border: 1px solid #aaa; + + margin: 1px 10px; + + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; + + cursor: pointer; + + width: 25px; + height: 11px; + + outline-style: none; /* this avoid the tabindex property to sorround this element with a (maybe dotted) rectangle*/ +} + +.switch-button-button { + position: absolute; + + width: 12px; + height: 11px; + + left: 12px; + top : -1px; + + background: #FAFAFA; + border: 1px solid #aaa; + + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; } \ No newline at end of file diff --git a/src/main/webapp/conf/NotificationTypeCategories.properties b/src/main/webapp/conf/NotificationTypeCategories.properties deleted file mode 100644 index 4736f82..0000000 --- a/src/main/webapp/conf/NotificationTypeCategories.properties +++ /dev/null @@ -1,3 +0,0 @@ -Sharing=WP_FOLDER_SHARE,WP_FOLDER_ADDEDUSER,WP_FOLDER_REMOVEDUSER,WP_FOLDER_RENAMED,WP_ITEM_DELETE,WP_ITEM_UPDATED,WP_ITEM_RENAMED,WP_ITEM_NEW -Social=OWN_COMMENT,COMMENT,MENTION,LIKE,MESSAGE -DocumentWorkflows=DOCUMENT_WORKFLOW_EDIT,DOCUMENT_WORKFLOW_VIEW,DOCUMENT_WORKFLOW_STEP_REQUEST_TASK,DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT,DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER,DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER,DOCUMENT_WORKFLOW_STEP_FORWARD_PEER diff --git a/src/main/webapp/conf/categorybytype.properties b/src/main/webapp/conf/categorybytype.properties new file mode 100644 index 0000000..4785e40 --- /dev/null +++ b/src/main/webapp/conf/categorybytype.properties @@ -0,0 +1,20 @@ +DOCUMENT_WORKFLOW_EDIT=Document Workflow +DOCUMENT_WORKFLOW_VIEW=Document Workflow +DOCUMENT_WORKFLOW_STEP_REQUEST_TASK=Document Workflow +DOCUMENT_WORKFLOW_FIRST_STEP_REQUEST_INVOLVMENT=Document Workflow +DOCUMENT_WORKFLOW_USER_FORWARD_TO_OWNER=Document Workflow +DOCUMENT_WORKFLOW_FORWARD_STEP_COMPLETED_OWNER=Document Workflow +DOCUMENT_WORKFLOW_STEP_FORWARD_PEER=Document Workflow +WP_FOLDER_SHARE=Workspace Sharing +WP_FOLDER_ADDEDUSER=Workspace Sharing +WP_FOLDER_REMOVEDUSER=Workspace Sharing +WP_FOLDER_RENAMED=Workspace Sharing +WP_ITEM_DELETE=Workspace Sharing +WP_ITEM_UPDATED=Workspace Sharing +WP_ITEM_RENAMED=Workspace Sharing +WP_ITEM_NEW=Workspace Sharing +OWN_COMMENT=Social Networking +COMMENT=Social Networking +MENTION=Social Networking +LIKE=Social Networking +MESSAGE=Social Networking diff --git a/src/main/webapp/conf/NotificationTypeDescriptions.properties b/src/main/webapp/conf/descbytype.properties similarity index 100% rename from src/main/webapp/conf/NotificationTypeDescriptions.properties rename to src/main/webapp/conf/descbytype.properties diff --git a/src/main/webapp/conf/NotificationTypeHumans.properties b/src/main/webapp/conf/labelbytype.properties similarity index 100% rename from src/main/webapp/conf/NotificationTypeHumans.properties rename to src/main/webapp/conf/labelbytype.properties