(notificationsPerDay.keySet());
+ Collections.sort(sortedKeys, Collections.reverseOrder());
+
+ int notCounter = 0;
+ for (Date day : sortedKeys) {
+ mainPanel.add(new DayWrapper(day));
+ for (Notification notif : notificationsPerDay.get(day)) {
+ mainPanel.add(new SingleNotificationView(notif));
+ notCounter++;
+ }
+ }
+ fromStartingPoint += notCounter;
+ GWT.log("StartingPoint incremented = " + fromStartingPoint);
+ if (notCounter >= quantity) { //there could be more notifications
+ GWT.log("Show MORE ");
+ showMoreNotificationsPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
+ showMoreWidget = new ShowMoreNotifications();
+ showMoreNotificationsPanel.add(showMoreWidget);
+ mainPanel.add(showMoreNotificationsPanel);
+ }
+ }
+ }
+ @Override
+ public void onFailure(Throwable caught) {
+ showMoreNotificationsPanel.clear();
+ mainPanel.add(new HTML("" +
+ "Ops! There were problems while retrieving your Notifications!.
" +
+ "Please try again in a short while.
"));
+ }
+ });
+ }
+
+ /**
+ * @param widget the widget to check
+ * @returnn true if the widget is in the visible part of the page
+ */
+ private boolean isScrolledIntoView(Widget widget) {
+ if (widget != null) {
+ int docViewTop = Window.getScrollTop();
+ int docViewBottom = docViewTop + Window.getClientHeight();
+ int elemTop = widget.getAbsoluteTop();
+ int elemBottom = elemTop + widget.getOffsetHeight();
+ return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
+ }
+ return false;
+ }
+
private void showLoader() {
mainPanel.clear();
mainPanel.setWidth("100%");
diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/ShowMoreNotifications.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/ShowMoreNotifications.java
new file mode 100644
index 0000000..0335678
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/ShowMoreNotifications.java
@@ -0,0 +1,42 @@
+package org.gcube.portlets.user.notifications.client.view.templates;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.dom.client.Style.Visibility;
+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.ui.Composite;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HTMLPanel;
+import com.google.gwt.user.client.ui.Widget;
+
+public class ShowMoreNotifications extends Composite {
+
+ private static ShowMoreNotificationsUiBinder uiBinder = GWT
+ .create(ShowMoreNotificationsUiBinder.class);
+
+ interface ShowMoreNotificationsUiBinder extends UiBinder {
+ }
+
+
+ @UiField HTML caption;
+ @UiField HTMLPanel panel;
+
+
+ public ShowMoreNotifications() {
+ initWidget(uiBinder.createAndBindUi(this));
+ panel.getElement().getStyle().setMarginTop(10, Unit.PX);
+ caption.addStyleName("new-notifications-show");
+ caption.getElement().getStyle().setBackgroundColor("transparent");
+ caption.getElement().getStyle().setFontSize(14, Unit.PX);
+ caption.setHTML("Show more notifications");
+ //hiding as not needed anymore (the user click)
+ panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
+ }
+
+ @UiHandler("caption")
+ void onClick(ClickEvent e) {
+ }
+}
diff --git a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/ShowMoreNotifications.ui.xml b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/ShowMoreNotifications.ui.xml
new file mode 100644
index 0000000..743c429
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/ShowMoreNotifications.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/SingleNotificationView.java b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SingleNotificationView.java
index 3961d1c..dd639c0 100644
--- a/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SingleNotificationView.java
+++ b/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SingleNotificationView.java
@@ -1,5 +1,6 @@
package org.gcube.portlets.user.notifications.client.view.templates;
+import org.apache.cassandra.cli.CliParser.attr_name_return;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.client.util.Encoder;
import org.gcube.portal.databook.shared.Notification;
@@ -60,6 +61,8 @@ public class SingleNotificationView extends Composite {
actualHTML = actualHTML.replace("link.", "link");
actualHTML += " you shared.";
}
+ //shorten the notification text if greather than 200 chars
+ actualHTML = actualHTML.length() > 200 ? actualHTML.substring(0, 200) + " ..." : actualHTML;
notificationText.setHTML(
""+
toShow.getSenderFullName()+" " + actualHTML);
+
timeArea.setHTML(DateTimeFormat.getFormat("h:mm a").format(toShow.getTime()));
notificationImage.setResource(getImageType(toShow.getType()));
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 2dcc47a..f370ae3 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
@@ -26,6 +26,7 @@ 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.client.NotificationsService;
+import org.gcube.portlets.user.notifications.shared.NotificationConstants;
import org.gcube.portlets.user.notifications.shared.NotificationPreference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -74,7 +75,7 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
user = "test.user";
-// user = "massimiliano.assante";
+ user = "massimiliano.assante";
_log.warn("USER IS NULL setting "+user+" and Running OUTSIDE PORTAL");
withinPortal = false;
@@ -115,12 +116,12 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
}
/**
- * returns the notifications separated per days
+ * returns the notifications separated per day
*/
public HashMap> getUserNotifications() {
HashMap> toReturn = new HashMap>();
try {
- for (Notification notification : store.getAllNotificationByUser(getASLSession().getUsername(), 70)) {
+ for (Notification notification : store.getAllNotificationByUser(getASLSession().getUsername(), NotificationConstants.NOTIFICATION_NUMBER)) {
Date dateWithoutTime = removeTimePart(notification.getTime());
if (! toReturn.containsKey(dateWithoutTime)) {
ArrayList nots = new ArrayList();
@@ -137,6 +138,31 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
}
return toReturn;
}
+
+ /**
+ * returns the notifications in the range separated per day
+ */
+ public HashMap> getUserNotificationsByRange(int from, int quantity) {
+ HashMap> toReturn = new HashMap>();
+ try {
+ for (Notification notification : store.getRangeNotificationsByUser(getASLSession().getUsername(), from, quantity)) {
+ Date dateWithoutTime = removeTimePart(notification.getTime());
+ if (! toReturn.containsKey(dateWithoutTime)) {
+ ArrayList nots = new ArrayList();
+ nots.add(notification);
+ toReturn.put(dateWithoutTime, nots);
+ } else {
+ toReturn.get(dateWithoutTime).add(notification);
+ }
+ }
+
+ } catch (Exception e) {
+ _log.error("While trying to get User notifications");
+ e.printStackTrace();
+ }
+ return toReturn;
+ }
+
/**
* we want notification split per day
* @param date
@@ -176,10 +202,10 @@ public class NotificationsServiceImpl extends RemoteServiceServlet implements No
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());
diff --git a/src/main/java/org/gcube/portlets/user/notifications/shared/NotificationConstants.java b/src/main/java/org/gcube/portlets/user/notifications/shared/NotificationConstants.java
new file mode 100644
index 0000000..fef904c
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/notifications/shared/NotificationConstants.java
@@ -0,0 +1,5 @@
+package org.gcube.portlets.user.notifications.shared;
+
+public class NotificationConstants {
+ public final static int NOTIFICATION_NUMBER = 70;
+}
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 c48e90f..5471073 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
@@ -2,10 +2,6 @@
-
-
-
-
diff --git a/src/main/webapp/Notifications.css b/src/main/webapp/Notifications.css
index e0072d4..d4fb6af 100644
--- a/src/main/webapp/Notifications.css
+++ b/src/main/webapp/Notifications.css
@@ -51,6 +51,13 @@ a.link:hover {
text-decoration: underline;
}
+.new-notifications-show {
+ opacity: 1;
+ background: #D6E2FC;
+ height: 18px;
+}
+
+
.day-wrapper {
width: 100%;
border-bottom-color: #DADADA;
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index d45685e..ee7748f 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -20,20 +20,6 @@
/org.gcube.portlets.user.notifications.NotificationsJUnit/notifications/notificationsServlet
-
- jUnitHostImpl
- com.google.gwt.junit.server.JUnitHostImpl
-
-
- jUnitHostImpl
- /org.gcube.portlets.user.notifications.NotificationsJUnit/junithost/*
-
-
-
- jUnitHostImpl
- /notifications/junithost/*
-
-
Notifications.html
diff --git a/src/test/java/org/gcube/portlets/user/notifications/client/GwtTestNotifications.java b/src/test/java/org/gcube/portlets/user/notifications/client/GwtTestNotifications.java
deleted file mode 100644
index b9ffc54..0000000
--- a/src/test/java/org/gcube/portlets/user/notifications/client/GwtTestNotifications.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.gcube.portlets.user.notifications.client;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.junit.client.GWTTestCase;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.rpc.ServiceDefTarget;
-
-/**
- * GWT JUnit integration tests must extend GWTTestCase.
- * Using "GwtTest*"
naming pattern exclude them from running with
- * surefire during the test phase.
- *
- * If you run the tests using the Maven command line, you will have to
- * navigate with your browser to a specific url given by Maven.
- * See http://mojo.codehaus.org/gwt-maven-plugin/user-guide/testing.html
- * for details.
- */
-public class GwtTestNotifications extends GWTTestCase {
-
- /**
- * Must refer to a valid module that sources this class.
- */
- public String getModuleName() {
- return "org.gcube.portlets.user.notifications.NotificationsJUnit";
- }
-
- /**
- * Tests the FieldVerifier.
- */
- public void testFieldVerifier() {
-// assertFalse(FieldVerifier.isValidName(null));
-// assertFalse(FieldVerifier.isValidName(""));
-// assertFalse(FieldVerifier.isValidName("a"));
-// assertFalse(FieldVerifier.isValidName("ab"));
-// assertFalse(FieldVerifier.isValidName("abc"));
-// assertTrue(FieldVerifier.isValidName("abcd"));
- }
-
- /**
- * This test will send a request to the server using the greetServer method in
- * NotificationsService and verify the response.
- */
- public void testGreetingService() {
-// // Create the service that we will test.
-// NotificationsServiceAsync greetingService = GWT.create(NotificationsService.class);
-// ServiceDefTarget target = (ServiceDefTarget) greetingService;
-// target.setServiceEntryPoint(GWT.getModuleBaseURL() + "Notifications/greet");
-
- // Since RPC calls are asynchronous, we will need to wait for a response
- // after this test method returns. This line tells the test runner to wait
- // up to 10 seconds before timing out.
- // delayTestFinish(10000);
-
-// // Send a request to the server.
-// greetingService.greetServer("GWT User", new AsyncCallback() {
-// public void onFailure(Throwable caught) {
-// // The request resulted in an unexpected error.
-// fail("Request failure: " + caught.getMessage());
-// }
-//
-// public void onSuccess(String result) {
-// // Verify that the response is correct.
-// assertTrue(result.startsWith("Hello, GWT User!"));
-//
-// // Now that we have received a response, we need to tell the test runner
-// // that the test is complete. You must call finishTest() after an
-// // asynchronous test finishes successfully, or the test will time out.
-// finishTest();
-// }
-// });
- }
-
-
-}