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:
parent
0d40b1562d
commit
225cdf91df
|
@ -8,6 +8,7 @@
|
|||
Feature #11189: Social-Networking - citing a people (with '@')
|
||||
in comments loses the focus.
|
||||
</Change>
|
||||
<Change>Feature #10192 allow to sort feeds per recent comments</Change>
|
||||
<Change>Support for ticket #11139</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.portlets-user.news-feed.2-5-0"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package org.gcube.portlets.user.newsfeed.client;
|
||||
|
||||
public enum FilterType {
|
||||
ALL_UPDATES, CONNECTIONS, LIKEDFEEDS, MINE;
|
||||
ALL_UPDATES, CONNECTIONS, RECENT_COMMENTS, MINE;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.gcube.portal.databook.shared.ClientPost;
|
|||
import org.gcube.portal.databook.shared.JSON;
|
||||
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
|
||||
|
||||
|
||||
import com.google.gwt.core.client.EntryPoint;
|
||||
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
|
||||
*/
|
||||
public static native void injectLiferayIPCEventReceiver() /*-{
|
||||
$wnd.Liferay.on('newPostCreated',function(event) {
|
||||
$wnd.handleReceiveEvent(event.payload);
|
||||
});
|
||||
try {
|
||||
$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
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package org.gcube.portlets.user.newsfeed.client.panels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.gcube.common.portal.GCubePortalConstants;
|
||||
|
@ -119,6 +121,7 @@ public class NewsFeedPanel extends Composite {
|
|||
public static final String SHARE_FWD_LABEL = "Share";
|
||||
private static final int SEARCHED_FEEDS_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;
|
||||
|
||||
|
@ -294,7 +297,7 @@ public class NewsFeedPanel extends Composite {
|
|||
GWT.log("checking params ");
|
||||
if (getFeedToShowId() != null) {
|
||||
String feedKey = getFeedToShowId();
|
||||
showSingleFeed(feedKey);
|
||||
showSinglePost(feedKey);
|
||||
filterPanel.removeFilterSelected();
|
||||
}
|
||||
else if (getHashtagParam() != null) {
|
||||
|
@ -341,6 +344,8 @@ public class NewsFeedPanel extends Composite {
|
|||
filterPanel.removeFilterSelected();
|
||||
}
|
||||
else {
|
||||
if (!result.isInfrastructure())
|
||||
filterPanelWrapper.setVisible(getFeedToShowId() == null);
|
||||
showAllUpdatesFeeds();
|
||||
}
|
||||
currentFilter = FilterType.ALL_UPDATES;
|
||||
|
@ -366,9 +371,11 @@ public class NewsFeedPanel extends Composite {
|
|||
Window.addWindowScrollHandler(new ScrollHandler() {
|
||||
@Override
|
||||
public void onWindowScroll(ScrollEvent event) {
|
||||
boolean isInView = isScrolledIntoView(showMoreWidget);
|
||||
if (isInView) {
|
||||
eventBus.fireEvent(new ShowMoreUpdatesEvent());
|
||||
if (showMoreWidget != null) {
|
||||
boolean isInView = isScrolledIntoView(showMoreWidget);
|
||||
if (isInView) {
|
||||
eventBus.fireEvent(new ShowMoreUpdatesEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -392,7 +399,7 @@ public class NewsFeedPanel extends Composite {
|
|||
showOnlyConnectionsFeeds();
|
||||
break;
|
||||
case MINE:
|
||||
showOnlyMyFeeds();
|
||||
showOnlyMyPosts();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -431,11 +438,11 @@ public class NewsFeedPanel extends Composite {
|
|||
|
||||
/**
|
||||
* used from notification referrals (see this Post)
|
||||
* @param feedKey
|
||||
* @param postKey
|
||||
*/
|
||||
private void showSingleFeed(String feedKey) {
|
||||
private void showSinglePost(String postKey) {
|
||||
newsPanel.clear();
|
||||
newsService.getSingleFeed(feedKey, new AsyncCallback<EnhancedFeed>() {
|
||||
newsService.getSingleFeed(postKey, new AsyncCallback<EnhancedFeed>() {
|
||||
@Override
|
||||
public void onSuccess(EnhancedFeed result) {
|
||||
if (result.getFeed().getType() == FeedType.DISABLED) {
|
||||
|
@ -759,35 +766,35 @@ public class NewsFeedPanel extends Composite {
|
|||
newsPanel.insert(tt, 0); //insert in the view
|
||||
allUpdates.add(0, feed); //insert in the model
|
||||
|
||||
// //timer for the transition
|
||||
// Timer t = new Timer() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// tt.setcontentAreaStyle("visible");
|
||||
//
|
||||
// // alert the user-statistics portlet to update statistics in case
|
||||
// // one or more feed belongs to user himself
|
||||
// if(tt.isUser()){
|
||||
// try{
|
||||
//
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postIncrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// int numComments = tt.numberOfComments();
|
||||
// int numLikes = tt.numberOfLikes();
|
||||
//
|
||||
// for(int i = 0; i < numComments; i++)
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// for(int i = 0; i < numLikes; i++)
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.likesIncrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// }catch (PageBusAdapterException ex) {
|
||||
// GWT.log(ex.toString());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// t.schedule(100);
|
||||
// //timer for the transition
|
||||
// Timer t = new Timer() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// tt.setcontentAreaStyle("visible");
|
||||
//
|
||||
// // alert the user-statistics portlet to update statistics in case
|
||||
// // one or more feed belongs to user himself
|
||||
// if(tt.isUser()){
|
||||
// try{
|
||||
//
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postIncrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// int numComments = tt.numberOfComments();
|
||||
// int numLikes = tt.numberOfLikes();
|
||||
//
|
||||
// for(int i = 0; i < numComments; i++)
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// for(int i = 0; i < numLikes; i++)
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.likesIncrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// }catch (PageBusAdapterException ex) {
|
||||
// GWT.log(ex.toString());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// t.schedule(100);
|
||||
}
|
||||
//after that I remove the ($updatesNo) from Window Title
|
||||
String currTitle = Document.get().getTitle();
|
||||
|
@ -1024,43 +1031,57 @@ public class NewsFeedPanel extends Composite {
|
|||
});
|
||||
}
|
||||
else{
|
||||
|
||||
int from = (fromStartingPoint == null) ? allUpdates.size()+1 : fromStartingPoint;
|
||||
|
||||
final int quantity = 10;
|
||||
GWT.log("StartingPoint = " + from);
|
||||
newsService.getMoreFeeds(from, quantity, new AsyncCallback<MoreFeedsBean>() {
|
||||
@Override
|
||||
public void onSuccess(MoreFeedsBean rangeFeeds) {
|
||||
newsPanel.remove(showMoreUpdatesPanel);
|
||||
if (rangeFeeds.getFeeds() != null) {
|
||||
fromStartingPoint = rangeFeeds.getLastReturnedFeedTimelineIndex();
|
||||
int c = 1;
|
||||
for (EnhancedFeed feed : rangeFeeds.getFeeds()) {
|
||||
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);
|
||||
loadMorePosts(quantity, false);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param quantity
|
||||
*/
|
||||
public void loadMorePosts(final int quantity, boolean isSortingByLastCommentedposts) {
|
||||
if (isSortingByLastCommentedposts)
|
||||
showLoader();
|
||||
int from = (fromStartingPoint == null) ? allUpdates.size()+1 : fromStartingPoint;
|
||||
GWT.log("StartingPoint = " + from);
|
||||
newsService.getMoreFeeds(from, quantity, new AsyncCallback<MoreFeedsBean>() {
|
||||
@Override
|
||||
public void onSuccess(MoreFeedsBean rangeFeeds) {
|
||||
newsPanel.remove(showMoreUpdatesPanel);
|
||||
if (rangeFeeds.getFeeds() != null) {
|
||||
fromStartingPoint = rangeFeeds.getLastReturnedFeedTimelineIndex();
|
||||
int c = 1;
|
||||
for (EnhancedFeed feed : rangeFeeds.getFeeds()) {
|
||||
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) {
|
||||
showMoreUpdatesPanel.clear();
|
||||
newsPanel.add(new HTML("<div class=\"nofeed-message\">" +
|
||||
"Ops! There were problems while retrieving your feeds!. <br> " +
|
||||
"Please try again in a short while.</div>"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
showMoreUpdatesPanel.clear();
|
||||
newsPanel.add(new HTML("<div class=\"nofeed-message\">" +
|
||||
"Ops! There were problems while retrieving your feeds!. <br> " +
|
||||
"Please try again in a short while.</div>"));
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param widget the widget to check
|
||||
|
@ -1127,7 +1148,7 @@ public class NewsFeedPanel extends Composite {
|
|||
/**
|
||||
* Only User Feeds
|
||||
*/
|
||||
public void showOnlyMyFeeds() {
|
||||
public void showOnlyMyPosts() {
|
||||
showLoader();
|
||||
newsService.getOnlyMyUserFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() {
|
||||
@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();
|
||||
newsService.getOnlyLikedFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() {
|
||||
@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();
|
||||
} else{
|
||||
|
||||
// // alert the User statistics portlet to increment the number of likes got
|
||||
// if(owner.isUser()){
|
||||
// try {
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(
|
||||
// PageBusEvents.likesIncrement
|
||||
// , ""
|
||||
// , Defaults.STRING_JSONIZER);
|
||||
// } catch (PageBusAdapterException ex) {
|
||||
// GWT.log(ex.toString());
|
||||
// }
|
||||
// }
|
||||
// // alert the User statistics portlet to increment the number of likes got
|
||||
// if(owner.isUser()){
|
||||
// try {
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(
|
||||
// PageBusEvents.likesIncrement
|
||||
// , ""
|
||||
// , Defaults.STRING_JSONIZER);
|
||||
// } catch (PageBusAdapterException ex) {
|
||||
// GWT.log(ex.toString());
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1259,16 +1337,16 @@ public class NewsFeedPanel extends Composite {
|
|||
}else{
|
||||
|
||||
// alert the User statistics portlet to decrement the number of likes got
|
||||
// if(owner.isUser()){
|
||||
// try {
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(
|
||||
// PageBusEvents.likesDecrement
|
||||
// , ""
|
||||
// , Defaults.STRING_JSONIZER);
|
||||
// } catch (PageBusAdapterException ex) {
|
||||
// GWT.log(ex.toString());
|
||||
// }
|
||||
// }
|
||||
// if(owner.isUser()){
|
||||
// try {
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(
|
||||
// PageBusEvents.likesDecrement
|
||||
// , ""
|
||||
// , Defaults.STRING_JSONIZER);
|
||||
// } catch (PageBusAdapterException ex) {
|
||||
// GWT.log(ex.toString());
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1277,7 +1355,7 @@ public class NewsFeedPanel extends Composite {
|
|||
}
|
||||
|
||||
private void doShowSessionExpired() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void doShowLikes(final String feedId) {
|
||||
|
@ -1324,14 +1402,14 @@ public class NewsFeedPanel extends Composite {
|
|||
owner.updateCommentsNumberCount();
|
||||
owner.showAddCommentForm(false);
|
||||
|
||||
// if(owner.isUser()){
|
||||
// // alert the User statistics portlet to increment the number of comments got
|
||||
// try {
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER);
|
||||
// } catch (PageBusAdapterException e) {
|
||||
// GWT.log(e.toString());
|
||||
// }
|
||||
// }
|
||||
// if(owner.isUser()){
|
||||
// // alert the User statistics portlet to increment the number of comments got
|
||||
// try {
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER);
|
||||
// } catch (PageBusAdapterException e) {
|
||||
// GWT.log(e.toString());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -1407,14 +1485,14 @@ public class NewsFeedPanel extends Composite {
|
|||
doShowComments(owner, false);
|
||||
owner.updateCommentsNumberCount();
|
||||
|
||||
// if(owner.isUser()){
|
||||
// // alert the User statistics portlet to decrement the number of comments got
|
||||
// try {
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER);
|
||||
// } catch (PageBusAdapterException ex) {
|
||||
// GWT.log(ex.toString());
|
||||
// }
|
||||
// }
|
||||
// if(owner.isUser()){
|
||||
// // alert the User statistics portlet to decrement the number of comments got
|
||||
// try {
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER);
|
||||
// } catch (PageBusAdapterException ex) {
|
||||
// GWT.log(ex.toString());
|
||||
// }
|
||||
// }
|
||||
} else
|
||||
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();
|
||||
|
||||
if(toDelete.isUser()){
|
||||
// try{
|
||||
// // alert the User statistics portlet to decrement the number of user's posts
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postDecrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// // alert the same portlet to decrement the number of likes/replies, if any
|
||||
// int numComments = toDelete.numberOfComments();
|
||||
// int numLikes = toDelete.numberOfLikes();
|
||||
//
|
||||
// for(int i = 0; i < numComments; i++)
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// for(int i = 0; i < numLikes; i++)
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.likesDecrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// }catch (PageBusAdapterException ex) {
|
||||
// GWT.log(ex.toString());
|
||||
// }
|
||||
// try{
|
||||
// // alert the User statistics portlet to decrement the number of user's posts
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postDecrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// // alert the same portlet to decrement the number of likes/replies, if any
|
||||
// int numComments = toDelete.numberOfComments();
|
||||
// int numLikes = toDelete.numberOfLikes();
|
||||
//
|
||||
// for(int i = 0; i < numComments; i++)
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// for(int i = 0; i < numLikes; i++)
|
||||
// NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.likesDecrement, "", Defaults.STRING_JSONIZER);
|
||||
//
|
||||
// }catch (PageBusAdapterException ex) {
|
||||
// GWT.log(ex.toString());
|
||||
// }
|
||||
}
|
||||
} else
|
||||
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));
|
||||
}
|
||||
|
||||
public int getAllUpdatesSize() {
|
||||
return allUpdates.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* set the filter type status for automatic reloading of tweets
|
||||
* @param currentFilter
|
||||
|
@ -1481,7 +1563,7 @@ public class NewsFeedPanel extends Composite {
|
|||
public static String getCurrentScope() {
|
||||
return currentScope;
|
||||
}
|
||||
|
||||
|
||||
public static String extractOrgFriendlyURL(String portalURL) {
|
||||
String groupRegEx = "/group/";
|
||||
if (portalURL.contains(groupRegEx)) {
|
||||
|
|
|
@ -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.shared.UserSettings;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.NavLink;
|
||||
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.uibinder.client.UiBinder;
|
||||
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.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
public class FilterPanel extends Composite {
|
||||
|
@ -35,85 +34,32 @@ public class FilterPanel extends Composite {
|
|||
initWidget(uiBinder.createAndBindUi(this));
|
||||
this.caller = caller;
|
||||
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
|
||||
public void onSuccess(UserSettings result) {
|
||||
if (result.getUserInfo().getUsername().equals("test.user")) {
|
||||
Window.alert(SESSION_EXPIRED);
|
||||
}
|
||||
else
|
||||
caller.showOnlyLikedFeeds();
|
||||
}
|
||||
});
|
||||
@UiField
|
||||
NavLink allUpdatesLink;
|
||||
@UiField
|
||||
NavLink recentCommentsLink;
|
||||
|
||||
public void removeFilterSelected() {
|
||||
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")
|
||||
void onAllUpdatesClick(ClickEvent e) {
|
||||
onlyme.removeStyleName("filter-selected");
|
||||
favoritesLink.removeStyleName("filter-selected");
|
||||
allUpdatesLink.setStyleName("filter-selected");
|
||||
allUpdatesLink.setActive(true);
|
||||
recentCommentsLink.setActive(false);
|
||||
caller.setCurrentFilter(FilterType.ALL_UPDATES);
|
||||
service.getUserSettings(new AsyncCallback<UserSettings>() {
|
||||
@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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,42 @@
|
|||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<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>
|
||||
.important {
|
||||
font-weight: bold;
|
||||
}
|
||||
.margin {
|
||||
margin-bottom: 0;
|
||||
margin-top: 0;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel>
|
||||
<div class="feed-filters">
|
||||
<ul>
|
||||
<li>
|
||||
<g:HTML ui:field="allUpdatesLink"></g:HTML>
|
||||
</li>
|
||||
<!-- <li> -->
|
||||
<!-- <g:HTML ui:field="connectionsLink"></g:HTML> -->
|
||||
<b:NavPills addStyleNames="{style.margin}">
|
||||
<b:NavLink disabled="true">Sort by newest:</b:NavLink>
|
||||
<b:NavLink active="true" ui:field="allUpdatesLink">Post</b:NavLink>
|
||||
<b:NavLink ui:field="recentCommentsLink">commented post</b:NavLink>
|
||||
</b:NavPills>
|
||||
<!-- <div class="feed-filters" style="display: none;"> -->
|
||||
<!-- <ul> -->
|
||||
<!-- <li class="first"> -->
|
||||
<!-- <g:HTML>Sort by newest: </g:HTML> -->
|
||||
<!-- </li> -->
|
||||
<li>
|
||||
<g:HTML ui:field="favoritesLink"></g:HTML>
|
||||
</li>
|
||||
<li class="final">
|
||||
<g:HTML ui:field="onlyme"></g:HTML>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- <li> -->
|
||||
<!-- <g:HTML ui:field="allUpdatesLink"> -->
|
||||
<!-- <a>post</a> -->
|
||||
<!-- </g:HTML> -->
|
||||
<!-- </li> -->
|
||||
<!-- <li> -->
|
||||
<!-- <g:HTML ui:field="connectionsLink"></g:HTML> -->
|
||||
<!-- </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>
|
||||
</ui:UiBinder>
|
|
@ -2,7 +2,6 @@ package org.gcube.portlets.user.newsfeed.client.ui;
|
|||
|
||||
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.shared.HandlerManager;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
|
@ -32,7 +31,7 @@ public class ShowMoreFeeds extends Composite {
|
|||
caption.getElement().getStyle().setFontSize(14, Unit.PX);
|
||||
caption.setHTML("Show more feeds");
|
||||
//done after
|
||||
panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
|
||||
//panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
*/
|
||||
private ElasticSearchClient escl;
|
||||
|
||||
private final static int MAX_FEEDS_NO = 30;
|
||||
private final static int MAX_POSTS_NO = 30;
|
||||
|
||||
public void init() {
|
||||
store = new DBCassandraAstyanaxImpl();
|
||||
|
@ -237,8 +237,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
|
||||
ArrayList<Feed> toReturn = new ArrayList<Feed>();
|
||||
//return only <MAX_FEEDS_NO> feeds
|
||||
if (toMerge.size() > MAX_FEEDS_NO)
|
||||
for (int i = 0; i < MAX_FEEDS_NO; i++)
|
||||
if (toMerge.size() > MAX_POSTS_NO)
|
||||
for (int i = 0; i < MAX_POSTS_NO; i++)
|
||||
toReturn.add(toMerge.get(i));
|
||||
else {
|
||||
return enhanceFeeds(toMerge, 2);
|
||||
|
@ -323,8 +323,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
|
||||
ArrayList<Feed> toReturn = new ArrayList<Feed>();
|
||||
//return only <MAX_FEEDS_NO> feeds
|
||||
if (toMerge.size() > MAX_FEEDS_NO)
|
||||
for (int i = 0; i < MAX_FEEDS_NO; i++)
|
||||
if (toMerge.size() > MAX_POSTS_NO)
|
||||
for (int i = 0; i < MAX_POSTS_NO; i++)
|
||||
toReturn.add(toMerge.get(i));
|
||||
else {
|
||||
return enhanceFeeds(toMerge, 2);
|
||||
|
@ -434,8 +434,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
Collections.sort(toMerge, Collections.reverseOrder());
|
||||
ArrayList<Feed> toReturn = new ArrayList<Feed>();
|
||||
//return only <MAX_FEEDS_NO> feeds
|
||||
if (toMerge.size() > MAX_FEEDS_NO)
|
||||
for (int i = 0; i < MAX_FEEDS_NO; i++)
|
||||
if (toMerge.size() > MAX_POSTS_NO)
|
||||
for (int i = 0; i < MAX_POSTS_NO; i++)
|
||||
toReturn.add(toMerge.get(i));
|
||||
else
|
||||
return enhanceFeeds(toMerge, 2);
|
||||
|
|
Loading…
Reference in New Issue