Feature #10192 allow to sort feeds per recent comments

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@165130 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2018-03-15 13:45:43 +00:00
parent 0d40b1562d
commit 225cdf91df
8 changed files with 284 additions and 258 deletions

View File

@ -8,6 +8,7 @@
Feature #11189: Social-Networking - citing a people (with '@') Feature #11189: Social-Networking - citing a people (with '@')
in comments loses the focus. in comments loses the focus.
</Change> </Change>
<Change>Feature #10192 allow to sort feeds per recent comments</Change>
<Change>Support for ticket #11139</Change> <Change>Support for ticket #11139</Change>
</Changeset> </Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.2-5-0" <Changeset component="org.gcube.portlets-user.news-feed.2-5-0"

View File

@ -1,5 +1,5 @@
package org.gcube.portlets.user.newsfeed.client; package org.gcube.portlets.user.newsfeed.client;
public enum FilterType { public enum FilterType {
ALL_UPDATES, CONNECTIONS, LIKEDFEEDS, MINE; ALL_UPDATES, CONNECTIONS, RECENT_COMMENTS, MINE;
} }

View File

@ -4,6 +4,7 @@ import org.gcube.portal.databook.shared.ClientPost;
import org.gcube.portal.databook.shared.JSON; import org.gcube.portal.databook.shared.JSON;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel; import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.RootPanel;
@ -40,9 +41,13 @@ public class NewsFeed implements EntryPoint {
* this is a JSNI method that injects the Liferay Javascript function listening for events from ShareUpdates * this is a JSNI method that injects the Liferay Javascript function listening for events from ShareUpdates
*/ */
public static native void injectLiferayIPCEventReceiver() /*-{ public static native void injectLiferayIPCEventReceiver() /*-{
$wnd.Liferay.on('newPostCreated',function(event) { try {
$wnd.handleReceiveEvent(event.payload); $wnd.Liferay.on('newPostCreated',function(event) {
}); $wnd.handleReceiveEvent(event.payload);
});
} catch(err) {
$wnd.console.log('error subscribing to newPostCreated events, acceptable in dev');
}
}-*/; }-*/;
/** /**
* this is a JSNI method mapping the Javascript function handleReceiveEvent to the Java method handleReceiveEvent * this is a JSNI method mapping the Javascript function handleReceiveEvent to the Java method handleReceiveEvent

View File

@ -1,7 +1,9 @@
package org.gcube.portlets.user.newsfeed.client.panels; package org.gcube.portlets.user.newsfeed.client.panels;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import org.gcube.common.portal.GCubePortalConstants; import org.gcube.common.portal.GCubePortalConstants;
@ -119,6 +121,7 @@ public class NewsFeedPanel extends Composite {
public static final String SHARE_FWD_LABEL = "Share"; public static final String SHARE_FWD_LABEL = "Share";
private static final int SEARCHED_FEEDS_TO_SHOW = 10; private static final int SEARCHED_FEEDS_TO_SHOW = 10;
private static final int FEEDS_RELATED_TO_USER_STATISTICS_TO_SHOW = 10; private static final int FEEDS_RELATED_TO_USER_STATISTICS_TO_SHOW = 10;
private static final String LIMIT_REACHED_FOR_SORTING_COMMENTS_TEXT = "You reached the limit, sort by newest comments works up to 100 posts.";
private String vreLabel; private String vreLabel;
@ -294,7 +297,7 @@ public class NewsFeedPanel extends Composite {
GWT.log("checking params "); GWT.log("checking params ");
if (getFeedToShowId() != null) { if (getFeedToShowId() != null) {
String feedKey = getFeedToShowId(); String feedKey = getFeedToShowId();
showSingleFeed(feedKey); showSinglePost(feedKey);
filterPanel.removeFilterSelected(); filterPanel.removeFilterSelected();
} }
else if (getHashtagParam() != null) { else if (getHashtagParam() != null) {
@ -341,6 +344,8 @@ public class NewsFeedPanel extends Composite {
filterPanel.removeFilterSelected(); filterPanel.removeFilterSelected();
} }
else { else {
if (!result.isInfrastructure())
filterPanelWrapper.setVisible(getFeedToShowId() == null);
showAllUpdatesFeeds(); showAllUpdatesFeeds();
} }
currentFilter = FilterType.ALL_UPDATES; currentFilter = FilterType.ALL_UPDATES;
@ -366,9 +371,11 @@ public class NewsFeedPanel extends Composite {
Window.addWindowScrollHandler(new ScrollHandler() { Window.addWindowScrollHandler(new ScrollHandler() {
@Override @Override
public void onWindowScroll(ScrollEvent event) { public void onWindowScroll(ScrollEvent event) {
boolean isInView = isScrolledIntoView(showMoreWidget); if (showMoreWidget != null) {
if (isInView) { boolean isInView = isScrolledIntoView(showMoreWidget);
eventBus.fireEvent(new ShowMoreUpdatesEvent()); if (isInView) {
eventBus.fireEvent(new ShowMoreUpdatesEvent());
}
} }
} }
}); });
@ -392,7 +399,7 @@ public class NewsFeedPanel extends Composite {
showOnlyConnectionsFeeds(); showOnlyConnectionsFeeds();
break; break;
case MINE: case MINE:
showOnlyMyFeeds(); showOnlyMyPosts();
break; break;
default: default:
break; break;
@ -431,11 +438,11 @@ public class NewsFeedPanel extends Composite {
/** /**
* used from notification referrals (see this Post) * used from notification referrals (see this Post)
* @param feedKey * @param postKey
*/ */
private void showSingleFeed(String feedKey) { private void showSinglePost(String postKey) {
newsPanel.clear(); newsPanel.clear();
newsService.getSingleFeed(feedKey, new AsyncCallback<EnhancedFeed>() { newsService.getSingleFeed(postKey, new AsyncCallback<EnhancedFeed>() {
@Override @Override
public void onSuccess(EnhancedFeed result) { public void onSuccess(EnhancedFeed result) {
if (result.getFeed().getType() == FeedType.DISABLED) { if (result.getFeed().getType() == FeedType.DISABLED) {
@ -759,35 +766,35 @@ public class NewsFeedPanel extends Composite {
newsPanel.insert(tt, 0); //insert in the view newsPanel.insert(tt, 0); //insert in the view
allUpdates.add(0, feed); //insert in the model allUpdates.add(0, feed); //insert in the model
// //timer for the transition // //timer for the transition
// Timer t = new Timer() { // Timer t = new Timer() {
// @Override // @Override
// public void run() { // public void run() {
// tt.setcontentAreaStyle("visible"); // tt.setcontentAreaStyle("visible");
// //
// // alert the user-statistics portlet to update statistics in case // // alert the user-statistics portlet to update statistics in case
// // one or more feed belongs to user himself // // one or more feed belongs to user himself
// if(tt.isUser()){ // if(tt.isUser()){
// try{ // try{
// //
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postIncrement, "", Defaults.STRING_JSONIZER); // NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postIncrement, "", Defaults.STRING_JSONIZER);
// //
// int numComments = tt.numberOfComments(); // int numComments = tt.numberOfComments();
// int numLikes = tt.numberOfLikes(); // int numLikes = tt.numberOfLikes();
// //
// for(int i = 0; i < numComments; i++) // for(int i = 0; i < numComments; i++)
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER); // NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER);
// //
// for(int i = 0; i < numLikes; i++) // for(int i = 0; i < numLikes; i++)
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.likesIncrement, "", Defaults.STRING_JSONIZER); // NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.likesIncrement, "", Defaults.STRING_JSONIZER);
// //
// }catch (PageBusAdapterException ex) { // }catch (PageBusAdapterException ex) {
// GWT.log(ex.toString()); // GWT.log(ex.toString());
// } // }
// } // }
// } // }
// }; // };
// t.schedule(100); // t.schedule(100);
} }
//after that I remove the ($updatesNo) from Window Title //after that I remove the ($updatesNo) from Window Title
String currTitle = Document.get().getTitle(); String currTitle = Document.get().getTitle();
@ -1024,43 +1031,57 @@ public class NewsFeedPanel extends Composite {
}); });
} }
else{ else{
int from = (fromStartingPoint == null) ? allUpdates.size()+1 : fromStartingPoint;
final int quantity = 10; final int quantity = 10;
GWT.log("StartingPoint = " + from); loadMorePosts(quantity, false);
newsService.getMoreFeeds(from, quantity, new AsyncCallback<MoreFeedsBean>() { }
@Override }
public void onSuccess(MoreFeedsBean rangeFeeds) { /**
newsPanel.remove(showMoreUpdatesPanel); *
if (rangeFeeds.getFeeds() != null) { * @param quantity
fromStartingPoint = rangeFeeds.getLastReturnedFeedTimelineIndex(); */
int c = 1; public void loadMorePosts(final int quantity, boolean isSortingByLastCommentedposts) {
for (EnhancedFeed feed : rangeFeeds.getFeeds()) { if (isSortingByLastCommentedposts)
if (!isFeedPresent(feed)) { //avoid possible duplicates showLoader();
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view int from = (fromStartingPoint == null) ? allUpdates.size()+1 : fromStartingPoint;
allUpdates.add(feed); //in the model GWT.log("StartingPoint = " + from);
} newsService.getMoreFeeds(from, quantity, new AsyncCallback<MoreFeedsBean>() {
c++; @Override
} public void onSuccess(MoreFeedsBean rangeFeeds) {
if (c >= quantity) { //there could be more feeds newsPanel.remove(showMoreUpdatesPanel);
GWT.log("there could be more feeds"); if (rangeFeeds.getFeeds() != null) {
showMoreUpdatesPanel.clear(); fromStartingPoint = rangeFeeds.getLastReturnedFeedTimelineIndex();
showMoreWidget = new ShowMoreFeeds(eventBus); int c = 1;
showMoreUpdatesPanel.add(showMoreWidget); for (EnhancedFeed feed : rangeFeeds.getFeeds()) {
newsPanel.add(showMoreUpdatesPanel); if (!isFeedPresent(feed)) { //avoid possible duplicates
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
allUpdates.add(feed); //in the model
} }
c++;
}
if (c >= quantity) { //there could be more feeds
GWT.log("there could be more feeds");
showMoreUpdatesPanel.clear();
showMoreWidget = new ShowMoreFeeds(eventBus);
showMoreUpdatesPanel.add(showMoreWidget);
newsPanel.add(showMoreUpdatesPanel);
}
if (isSortingByLastCommentedposts) {
sortCurrentPostsByLatestComment();
showMoreUpdatesPanel.clear();
showMoreWidget = null;
if (getAllUpdatesSize() > 99)
newsPanel.add(new HTML(LIMIT_REACHED_FOR_SORTING_COMMENTS_TEXT));
} }
} }
@Override }
public void onFailure(Throwable caught) { @Override
showMoreUpdatesPanel.clear(); public void onFailure(Throwable caught) {
newsPanel.add(new HTML("<div class=\"nofeed-message\">" + showMoreUpdatesPanel.clear();
"Ops! There were problems while retrieving your feeds!. <br> " + newsPanel.add(new HTML("<div class=\"nofeed-message\">" +
"Please try again in a short while.</div>")); "Ops! There were problems while retrieving your feeds!. <br> " +
} "Please try again in a short while.</div>"));
}); }
} });
} }
/** /**
* @param widget the widget to check * @param widget the widget to check
@ -1127,7 +1148,7 @@ public class NewsFeedPanel extends Composite {
/** /**
* Only User Feeds * Only User Feeds
*/ */
public void showOnlyMyFeeds() { public void showOnlyMyPosts() {
showLoader(); showLoader();
newsService.getOnlyMyUserFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() { newsService.getOnlyMyUserFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() {
@Override @Override
@ -1164,9 +1185,9 @@ public class NewsFeedPanel extends Composite {
}); });
} }
/** /**
* Only User Liked Feeds * Only User Liked Posts
*/ */
public void showOnlyLikedFeeds() { public void showOnlyLikedPosts() {
showLoader(); showLoader();
newsService.getOnlyLikedFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() { newsService.getOnlyLikedFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() {
@Override @Override
@ -1202,6 +1223,63 @@ public class NewsFeedPanel extends Composite {
} }
}); });
} }
/**:
* Sort the posts per recent comment
*/
private void sortCurrentPostsByLatestComment() {
showLoader();
GWT.log(" number of posts " + allUpdates.size());
ArrayList<Comment> latestComments = new ArrayList<>();
//thePostsMap is need so that later it is faster to get the post by id
HashMap<String, EnhancedFeed> theCommentedPostsMap = new HashMap<>();
for (EnhancedFeed post : allUpdates) {
ArrayList<Comment> postComments = post.getComments();
if (postComments != null && !postComments.isEmpty()) {
theCommentedPostsMap.put(post.getFeed().getKey(), post);
Comment latest = postComments.get(postComments.size()-1);
latestComments.add(latest); //get the latest
}
}
//sort the comments
Collections.sort(latestComments, Collections.reverseOrder());
ArrayList<EnhancedFeed> sortedPostsByLatestComment = new ArrayList<>();
// evaluate unique posts' ids
HashSet<String> postIds = new HashSet<String>();
for (Comment comment : latestComments) {
String postId = comment.getFeedid();
if(!postIds.contains(postId)){
postIds.add(postId);
sortedPostsByLatestComment.add(theCommentedPostsMap.get(postId));
}
}
//at this point the sortedPostsByLatestComment list contains only the commented posts in the right order
//we need to add the remaining posts of the page in the latest post order
for (EnhancedFeed post : allUpdates) {
if (!theCommentedPostsMap.containsKey(post.getFeed().getKey()))
sortedPostsByLatestComment.add(post);
}
newsPanel.clear();
if (sortedPostsByLatestComment.size() == 0) {
newsPanel.add(new HTML("<div class=\"nofeed-message\">" +
"Looks like we've got nothing for you at the moment. <br> " +
"Set an update as your <strong>favorite</strong> to see it here</div>"));
isFirstTweet = true;
}
else {
newsPanel.setHeight("");
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
for (EnhancedFeed feed : sortedPostsByLatestComment)
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus));
if (sortedPostsByLatestComment.size() < 5) {
newsPanel.add(new Image(spacer));
}
isFirstTweet = false;
}
}
@ -1231,17 +1309,17 @@ public class NewsFeedPanel extends Composite {
doShowSessionExpired(); doShowSessionExpired();
} else{ } else{
// // alert the User statistics portlet to increment the number of likes got // // alert the User statistics portlet to increment the number of likes got
// if(owner.isUser()){ // if(owner.isUser()){
// try { // try {
// NewsFeed.pageBusAdapter.PageBusPublish( // NewsFeed.pageBusAdapter.PageBusPublish(
// PageBusEvents.likesIncrement // PageBusEvents.likesIncrement
// , "" // , ""
// , Defaults.STRING_JSONIZER); // , Defaults.STRING_JSONIZER);
// } catch (PageBusAdapterException ex) { // } catch (PageBusAdapterException ex) {
// GWT.log(ex.toString()); // GWT.log(ex.toString());
// } // }
// } // }
} }
} }
@ -1259,16 +1337,16 @@ public class NewsFeedPanel extends Composite {
}else{ }else{
// alert the User statistics portlet to decrement the number of likes got // alert the User statistics portlet to decrement the number of likes got
// if(owner.isUser()){ // if(owner.isUser()){
// try { // try {
// NewsFeed.pageBusAdapter.PageBusPublish( // NewsFeed.pageBusAdapter.PageBusPublish(
// PageBusEvents.likesDecrement // PageBusEvents.likesDecrement
// , "" // , ""
// , Defaults.STRING_JSONIZER); // , Defaults.STRING_JSONIZER);
// } catch (PageBusAdapterException ex) { // } catch (PageBusAdapterException ex) {
// GWT.log(ex.toString()); // GWT.log(ex.toString());
// } // }
// } // }
} }
} }
@ -1277,7 +1355,7 @@ public class NewsFeedPanel extends Composite {
} }
private void doShowSessionExpired() { private void doShowSessionExpired() {
} }
private void doShowLikes(final String feedId) { private void doShowLikes(final String feedId) {
@ -1324,14 +1402,14 @@ public class NewsFeedPanel extends Composite {
owner.updateCommentsNumberCount(); owner.updateCommentsNumberCount();
owner.showAddCommentForm(false); owner.showAddCommentForm(false);
// if(owner.isUser()){ // if(owner.isUser()){
// // alert the User statistics portlet to increment the number of comments got // // alert the User statistics portlet to increment the number of comments got
// try { // try {
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER); // NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER);
// } catch (PageBusAdapterException e) { // } catch (PageBusAdapterException e) {
// GWT.log(e.toString()); // GWT.log(e.toString());
// } // }
// } // }
} }
} }
else { else {
@ -1407,14 +1485,14 @@ public class NewsFeedPanel extends Composite {
doShowComments(owner, false); doShowComments(owner, false);
owner.updateCommentsNumberCount(); owner.updateCommentsNumberCount();
// if(owner.isUser()){ // if(owner.isUser()){
// // alert the User statistics portlet to decrement the number of comments got // // alert the User statistics portlet to decrement the number of comments got
// try { // try {
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER); // NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER);
// } catch (PageBusAdapterException ex) { // } catch (PageBusAdapterException ex) {
// GWT.log(ex.toString()); // GWT.log(ex.toString());
// } // }
// } // }
} else } else
Window.alert("Comment could not be deleted, please try again in a short while."); Window.alert("Comment could not be deleted, please try again in a short while.");
} }
@ -1437,23 +1515,23 @@ public class NewsFeedPanel extends Composite {
toDelete.removeFromParent(); toDelete.removeFromParent();
if(toDelete.isUser()){ if(toDelete.isUser()){
// try{ // try{
// // alert the User statistics portlet to decrement the number of user's posts // // alert the User statistics portlet to decrement the number of user's posts
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postDecrement, "", Defaults.STRING_JSONIZER); // NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postDecrement, "", Defaults.STRING_JSONIZER);
// //
// // alert the same portlet to decrement the number of likes/replies, if any // // alert the same portlet to decrement the number of likes/replies, if any
// int numComments = toDelete.numberOfComments(); // int numComments = toDelete.numberOfComments();
// int numLikes = toDelete.numberOfLikes(); // int numLikes = toDelete.numberOfLikes();
// //
// for(int i = 0; i < numComments; i++) // for(int i = 0; i < numComments; i++)
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER); // NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER);
// //
// for(int i = 0; i < numLikes; i++) // for(int i = 0; i < numLikes; i++)
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.likesDecrement, "", Defaults.STRING_JSONIZER); // NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.likesDecrement, "", Defaults.STRING_JSONIZER);
// //
// }catch (PageBusAdapterException ex) { // }catch (PageBusAdapterException ex) {
// GWT.log(ex.toString()); // GWT.log(ex.toString());
// } // }
} }
} else } else
Window.alert("Feed could not be deleted, please try again in a short while."); Window.alert("Feed could not be deleted, please try again in a short while.");
@ -1467,6 +1545,10 @@ public class NewsFeedPanel extends Composite {
Window.Location.assign(Window.Location.getHref() + ((Window.Location.getHref().contains("?")) ? "&oid="+feedKey : "?oid="+feedKey)); Window.Location.assign(Window.Location.getHref() + ((Window.Location.getHref().contains("?")) ? "&oid="+feedKey : "?oid="+feedKey));
} }
public int getAllUpdatesSize() {
return allUpdates.size();
}
/** /**
* set the filter type status for automatic reloading of tweets * set the filter type status for automatic reloading of tweets
* @param currentFilter * @param currentFilter
@ -1481,7 +1563,7 @@ public class NewsFeedPanel extends Composite {
public static String getCurrentScope() { public static String getCurrentScope() {
return currentScope; return currentScope;
} }
public static String extractOrgFriendlyURL(String portalURL) { public static String extractOrgFriendlyURL(String portalURL) {
String groupRegEx = "/group/"; String groupRegEx = "/group/";
if (portalURL.contains(groupRegEx)) { if (portalURL.contains(groupRegEx)) {

View File

@ -5,8 +5,8 @@ import org.gcube.portlets.user.newsfeed.client.NewsServiceAsync;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel; import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
import org.gcube.portlets.user.newsfeed.shared.UserSettings; import org.gcube.portlets.user.newsfeed.shared.UserSettings;
import com.github.gwtbootstrap.client.ui.NavLink;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
@ -14,7 +14,6 @@ import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
public class FilterPanel extends Composite { public class FilterPanel extends Composite {
@ -35,85 +34,32 @@ public class FilterPanel extends Composite {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
this.caller = caller; this.caller = caller;
this.service = newsService; this.service = newsService;
//connectionsLink.setHTML("<a>Connections</a>");
allUpdatesLink.setHTML("<a>All Updates</a>");
favoritesLink.setHTML("<a>Favorites</a>");
onlyme.setHTML("<a>Your Posts</a>");
//connectionsLink.getElement().getStyle().setCursor(Cursor.POINTER);
allUpdatesLink.getElement().getStyle().setCursor(Cursor.POINTER);
favoritesLink.getElement().getStyle().setCursor(Cursor.POINTER);
onlyme.getElement().getStyle().setCursor(Cursor.POINTER);
allUpdatesLink.setStyleName("filter-selected");
} }
// @UiField
// HTML connectionsLink;
@UiField
HTML allUpdatesLink;
@UiField
HTML favoritesLink;
@UiField
HTML onlyme;
// @UiHandler("connectionsLink")
// void onConnectionsClick(ClickEvent e) {
// allUpdatesLink.removeStyleName("filter-selected");
// onlyme.removeStyleName("filter-selected");
// connectionsLink.setStyleName("filter-selected");
// caller.setCurrentFilter(FilterType.CONNECTIONS);
// service.getUserInfo(new AsyncCallback<UserInfo>() {
// @Override
// public void onFailure(Throwable caught) {
// Window.alert("Ops! we encountered some problems delivering your message, server is not responding, please try again in a short while.");
// }
//
// @Override
// public void onSuccess(UserInfo result) {
// if (result.getUsername().equals("test.user")) {
// Window.alert("Your session has expired, please log out and login again");
// }
// else
// caller.showOnlyConnectionsFeeds();
// }
// });
// }
//
public void removeFilterSelected() {
allUpdatesLink.removeStyleName("filter-selected");
onlyme.removeStyleName("filter-selected");
favoritesLink.removeStyleName("filter-selected");
}
@UiHandler("favoritesLink")
void onFavoritesClick(ClickEvent e) {
allUpdatesLink.removeStyleName("filter-selected");
onlyme.removeStyleName("filter-selected");
favoritesLink.setStyleName("filter-selected");
caller.setCurrentFilter(FilterType.LIKEDFEEDS);
service.getUserSettings(new AsyncCallback<UserSettings>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(ERROR_MESSAGE);
}
@Override @UiField
public void onSuccess(UserSettings result) { NavLink allUpdatesLink;
if (result.getUserInfo().getUsername().equals("test.user")) { @UiField
Window.alert(SESSION_EXPIRED); NavLink recentCommentsLink;
}
else public void removeFilterSelected() {
caller.showOnlyLikedFeeds(); allUpdatesLink.setActive(false);
} recentCommentsLink.setActive(false);
}); }
@UiHandler("recentCommentsLink")
void onRecentCommentsLinkClick(ClickEvent e) {
allUpdatesLink.setActive(false);
recentCommentsLink.setActive(true);
caller.setCurrentFilter(FilterType.RECENT_COMMENTS);
int loadedPostsInView = caller.getAllUpdatesSize();
int quantity = loadedPostsInView < 100 ? 100 - loadedPostsInView : loadedPostsInView;
caller.loadMorePosts(quantity, true);
} }
@UiHandler("allUpdatesLink") @UiHandler("allUpdatesLink")
void onAllUpdatesClick(ClickEvent e) { void onAllUpdatesClick(ClickEvent e) {
onlyme.removeStyleName("filter-selected"); allUpdatesLink.setActive(true);
favoritesLink.removeStyleName("filter-selected"); recentCommentsLink.setActive(false);
allUpdatesLink.setStyleName("filter-selected");
caller.setCurrentFilter(FilterType.ALL_UPDATES); caller.setCurrentFilter(FilterType.ALL_UPDATES);
service.getUserSettings(new AsyncCallback<UserSettings>() { service.getUserSettings(new AsyncCallback<UserSettings>() {
@Override @Override
@ -131,27 +77,5 @@ public class FilterPanel extends Composite {
} }
}); });
} }
@UiHandler("onlyme")
void onlyme(ClickEvent e) {
allUpdatesLink.removeStyleName("filter-selected");
favoritesLink.removeStyleName("filter-selected");
onlyme.setStyleName("filter-selected");
caller.setCurrentFilter(FilterType.MINE);
service.getUserSettings(new AsyncCallback<UserSettings>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(ERROR_MESSAGE);
}
@Override
public void onSuccess(UserSettings result) {
if (result.getUserInfo().getUsername().equals("test.user")) {
Window.alert(SESSION_EXPIRED);
}
else
caller.showOnlyMyFeeds();
}
});
}
} }

View File

@ -1,27 +1,42 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"> xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style> <ui:style>
.important { .margin {
font-weight: bold; margin-bottom: 0;
} margin-top: 0;
}
</ui:style> </ui:style>
<g:HTMLPanel> <g:HTMLPanel>
<div class="feed-filters"> <b:NavPills addStyleNames="{style.margin}">
<ul> <b:NavLink disabled="true">Sort by newest:</b:NavLink>
<li> <b:NavLink active="true" ui:field="allUpdatesLink">Post</b:NavLink>
<g:HTML ui:field="allUpdatesLink"></g:HTML> <b:NavLink ui:field="recentCommentsLink">commented post</b:NavLink>
</li> </b:NavPills>
<!-- <li> --> <!-- <div class="feed-filters" style="display: none;"> -->
<!-- <g:HTML ui:field="connectionsLink"></g:HTML> --> <!-- <ul> -->
<!-- <li class="first"> -->
<!-- <g:HTML>Sort by newest: </g:HTML> -->
<!-- </li> --> <!-- </li> -->
<li> <!-- <li> -->
<g:HTML ui:field="favoritesLink"></g:HTML> <!-- <g:HTML ui:field="allUpdatesLink"> -->
</li> <!-- <a>post</a> -->
<li class="final"> <!-- </g:HTML> -->
<g:HTML ui:field="onlyme"></g:HTML> <!-- </li> -->
</li> <!-- <li> -->
</ul> <!-- <g:HTML ui:field="connectionsLink"></g:HTML> -->
</div> <!-- </li> -->
<!-- <li class="final"> -->
<!-- <g:HTML ui:field="recentCommentsLink"> -->
<!-- <a>commented post</a> -->
<!-- </g:HTML> -->
<!-- </li> -->
<!-- <li class="final" style="display: none;"> -->
<!-- <g:HTML ui:field="onlyme"> -->
<!-- <a>posted by you</a> -->
<!-- </g:HTML> -->
<!-- </li> -->
<!-- </ul> -->
<!-- </div> -->
</g:HTMLPanel> </g:HTMLPanel>
</ui:UiBinder> </ui:UiBinder>

View File

@ -2,7 +2,6 @@ package org.gcube.portlets.user.newsfeed.client.ui;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.Visibility;
import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
@ -32,7 +31,7 @@ public class ShowMoreFeeds extends Composite {
caption.getElement().getStyle().setFontSize(14, Unit.PX); caption.getElement().getStyle().setFontSize(14, Unit.PX);
caption.setHTML("Show more feeds"); caption.setHTML("Show more feeds");
//done after //done after
panel.getElement().getStyle().setVisibility(Visibility.HIDDEN); //panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
} }

View File

@ -103,7 +103,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
*/ */
private ElasticSearchClient escl; private ElasticSearchClient escl;
private final static int MAX_FEEDS_NO = 30; private final static int MAX_POSTS_NO = 30;
public void init() { public void init() {
store = new DBCassandraAstyanaxImpl(); store = new DBCassandraAstyanaxImpl();
@ -237,8 +237,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
ArrayList<Feed> toReturn = new ArrayList<Feed>(); ArrayList<Feed> toReturn = new ArrayList<Feed>();
//return only <MAX_FEEDS_NO> feeds //return only <MAX_FEEDS_NO> feeds
if (toMerge.size() > MAX_FEEDS_NO) if (toMerge.size() > MAX_POSTS_NO)
for (int i = 0; i < MAX_FEEDS_NO; i++) for (int i = 0; i < MAX_POSTS_NO; i++)
toReturn.add(toMerge.get(i)); toReturn.add(toMerge.get(i));
else { else {
return enhanceFeeds(toMerge, 2); return enhanceFeeds(toMerge, 2);
@ -323,8 +323,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
ArrayList<Feed> toReturn = new ArrayList<Feed>(); ArrayList<Feed> toReturn = new ArrayList<Feed>();
//return only <MAX_FEEDS_NO> feeds //return only <MAX_FEEDS_NO> feeds
if (toMerge.size() > MAX_FEEDS_NO) if (toMerge.size() > MAX_POSTS_NO)
for (int i = 0; i < MAX_FEEDS_NO; i++) for (int i = 0; i < MAX_POSTS_NO; i++)
toReturn.add(toMerge.get(i)); toReturn.add(toMerge.get(i));
else { else {
return enhanceFeeds(toMerge, 2); return enhanceFeeds(toMerge, 2);
@ -434,8 +434,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
Collections.sort(toMerge, Collections.reverseOrder()); Collections.sort(toMerge, Collections.reverseOrder());
ArrayList<Feed> toReturn = new ArrayList<Feed>(); ArrayList<Feed> toReturn = new ArrayList<Feed>();
//return only <MAX_FEEDS_NO> feeds //return only <MAX_FEEDS_NO> feeds
if (toMerge.size() > MAX_FEEDS_NO) if (toMerge.size() > MAX_POSTS_NO)
for (int i = 0; i < MAX_FEEDS_NO; i++) for (int i = 0; i < MAX_POSTS_NO; i++)
toReturn.add(toMerge.get(i)); toReturn.add(toMerge.get(i));
else else
return enhanceFeeds(toMerge, 2); return enhanceFeeds(toMerge, 2);