Start adding support for number of likes/posts/comments autoupdate on client side

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@122532 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-01-26 17:28:08 +00:00
parent 886b8fc239
commit 81656dcd66
6 changed files with 100 additions and 18 deletions

View File

@ -10,6 +10,7 @@ import org.gcube.portal.databook.shared.ClientFeed.ClientFeedJsonizer;
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
import org.jsonmaker.gwt.client.Jsonizer;
import org.jsonmaker.gwt.client.base.Defaults;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
@ -62,8 +63,8 @@ public class NewsFeed implements EntryPoint {
ClientFeed feed = (ClientFeed)event.getMessage((Jsonizer)GWT.create(ClientFeedJsonizer.class));
mainPanel.addJustAddedFeed(feed);
// alert the User statistics widget to increment the number of user's posts (no need to pass info)
pageBusAdapter.PageBusPublish("org.gcube.portal.incrementPostCount", null, null);
// alert the User statistics portlet to increment the number of user's posts
pageBusAdapter.PageBusPublish("org.gcube.portal.incrementPostCount", "", Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException e) {
e.printStackTrace();

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapterException;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.client.util.Encoder;
import org.gcube.portal.databook.shared.Attachment;
@ -15,6 +17,7 @@ import org.gcube.portal.databook.shared.Like;
import org.gcube.portal.databook.shared.PrivacyLevel;
import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.portlets.user.newsfeed.client.FilterType;
import org.gcube.portlets.user.newsfeed.client.NewsFeed;
import org.gcube.portlets.user.newsfeed.client.NewsService;
import org.gcube.portlets.user.newsfeed.client.NewsServiceAsync;
import org.gcube.portlets.user.newsfeed.client.event.AddCommentEvent;
@ -57,6 +60,7 @@ import org.gcube.portlets.widgets.userselection.client.events.SelectedUserEvent;
import org.gcube.portlets.widgets.userselection.client.events.SelectedUserEventHandler;
import org.gcube.portlets.widgets.userselection.client.events.UsersFetchedEvent;
import org.gcube.portlets.widgets.userselection.shared.ItemSelectableBean;
import org.jsonmaker.gwt.client.base.Defaults;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
@ -968,6 +972,15 @@ public class NewsFeedPanel extends Composite {
owner.setCommentingDisabled(false);
owner.updateCommentsNumberCount();
owner.showAddCommentForm(false);
if(owner.isUser()){
// alert the User statistics portlet to increment the number of comments got
try {
NewsFeed.pageBusAdapter.PageBusPublish("org.gcube.portal.incrementCommentsGot", "", Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException e) {
GWT.log(e.toString());
}
}
}
}
else {
@ -1042,6 +1055,15 @@ public class NewsFeedPanel extends Composite {
if (result) {
doShowComments(owner, false);
owner.updateCommentsNumberCount();
if(owner.isUser()){
// alert the User statistics portlet to decrement the number of comments got
try {
NewsFeed.pageBusAdapter.PageBusPublish("org.gcube.portal.decrementCommentsGot", "", 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.");
}

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.newsfeed.client.ui;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.portlets.user.gcubewidgets.client.elements.Div;
@ -76,12 +77,12 @@ public class AddCommentTemplate extends Composite {
this.commentPanel = commentPanel;
isEditing = true;
this.toEdit = toEdit;
String commentText = new HTML(toEdit.getText()).getText();
//replace the < & and >
commentText = commentText.replaceAll("&lt;","<").replaceAll("&gt;",">");
commentText = commentText.replaceAll("&amp;","&");
owner = caller;
avatarImage.setPixelSize(30, 30);
avatarImage.setUrl(caller.getMyUserInfo().getAvatarId());
@ -107,7 +108,7 @@ public class AddCommentTemplate extends Composite {
}
};
t.schedule(200);
}

View File

@ -22,7 +22,7 @@ public class LinkPreviewer extends Composite {
// is the preview image still there ?
private boolean imageRemoved = false;
@UiField
HTML titleArea;
@UiField
@ -32,6 +32,9 @@ public class LinkPreviewer extends Composite {
@UiField
Image image;
// saved file name
private final String fileName;
private static LinkPreviewUiBinder uiBinder = GWT
.create(LinkPreviewUiBinder.class);
@ -41,17 +44,20 @@ public class LinkPreviewer extends Composite {
public LinkPreviewer(String title, String titleDesc, String host, String linkThumbUrl, String url) {
initWidget(uiBinder.createAndBindUi(this));
if (linkThumbUrl == null || linkThumbUrl.equals("null")){
image.removeFromParent();
imageRemoved = true;
}
else {
image.setUrl(linkThumbUrl);
image.setWidth("80px");
}
// save the filename info
fileName = title;
titleArea.setHTML("<a class=\"link\" target=\"_blank\" href=\"" + url + "\">"+title+"</a> <span style=\"color: #333;\"> - " + host+ "</span>");
urlText.setHTML((url.length() > 70) ? url.substring(0, 70)+"..." : url);
String desc = titleDesc;
@ -82,4 +88,26 @@ public class LinkPreviewer extends Composite {
}
});
}
/**
* Open the carousel when the user clicks on the previews' file name.
* @param carousel
*/
public void onFileNameClickOpenCarousel(final Carousel carousel) {
String nameToShow = fileName.length() > 40 ? fileName.substring(0, 40) + "..." : fileName;
titleArea.setHTML("<a class=\"link\" >"+ nameToShow +"</a>");
titleArea.setTitle(fileName);
titleArea.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
carousel.show();
}
});
}
}

View File

@ -26,6 +26,7 @@ import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
import org.gcube.portlets.widgets.imagepreviewerwidget.client.EnhancedImage;
import org.gcube.portlets.widgets.imagepreviewerwidget.client.ui.Carousel;
import org.jsonmaker.gwt.client.base.Defaults;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
@ -167,7 +168,7 @@ public class TweetTemplate extends Composite {
EnhancedImage enhancedImage = new EnhancedImage(
new com.github.gwtbootstrap.client.ui.Image(
feed.getUri()),
feed.getLinkTitle(),
feed.getLinkTitle() + " (" + feed.getLinkDescription() + ")",
feed.getLinkTitle(),
feed.getUri()
);
@ -176,8 +177,9 @@ public class TweetTemplate extends Composite {
listOfEnhancedImages.add(enhancedImage);
carousel.updateImages(listOfEnhancedImages);
// set handler on the linkpreviewer image to show this carousel
// set handler on the linkpreviewer image to show this carousel and on the image title too
linkPreviewer.onImageClickOpenCarousel(carousel);
linkPreviewer.onFileNameClickOpenCarousel(carousel);
// remove next and prev buttons of the carousel since we have only an image
carousel.hideArrows();
@ -218,7 +220,7 @@ public class TweetTemplate extends Composite {
EnhancedImage enhancedImage = new EnhancedImage(
new com.github.gwtbootstrap.client.ui.Image(
feed.getUri()),
feed.getLinkTitle(),
feed.getLinkTitle() + " (" + feed.getLinkDescription() + ")",
feed.getLinkTitle(),
feed.getUri()
);
@ -241,7 +243,7 @@ public class TweetTemplate extends Composite {
EnhancedImage enhancedImage = new EnhancedImage(
new com.github.gwtbootstrap.client.ui.Image(
otherAttachment.getUri()),
otherAttachment.getName(),
otherAttachment.getName() + " (" + otherAttachment.getDescription() + ")",
otherAttachment.getName(),
otherAttachment.getUri()
);
@ -410,10 +412,10 @@ public class TweetTemplate extends Composite {
if(isUsers){
try {
// alert the User statistics widget to decrement the number of user's posts (no need to pass info)
NewsFeed.pageBusAdapter.PageBusPublish("org.gcube.portal.decrementPostCount", null, null);
// alert the User statistics portlet to decrement the number of user's posts
NewsFeed.pageBusAdapter.PageBusPublish("org.gcube.portal.decrementPostCount", "", Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException e1) {
GWT.log("Unable to send this notification " + e1.toString());
}
@ -477,6 +479,18 @@ public class TweetTemplate extends Composite {
}
eventBus.fireEvent(new AddLikeEvent(this, myFeed.getFeed().getKey()));
setFavoritedUI(true);
// alert the User statistics portlet to increment the number of likes got
if(isUsers){
try {
NewsFeed.pageBusAdapter.PageBusPublish(
"org.gcube.portal.incrementLikesGot"
, ""
, Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException ex) {
GWT.log(e.toString());
}
}
}
catch (NumberFormatException ex) {
likeArea.setHTML("Error on the server");
@ -496,6 +510,18 @@ public class TweetTemplate extends Composite {
}
eventBus.fireEvent(new UnLikeEvent(this, myFeed.getFeed().getKey()));
setFavoritedUI(false);
// alert the User statistics portlet to decrement the number of likes got
if(isUsers){
try {
NewsFeed.pageBusAdapter.PageBusPublish(
"org.gcube.portal.decrementLikesGot"
, ""
, Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException ex) {
GWT.log(e.toString());
}
}
}
}
@ -663,4 +689,8 @@ public class TweetTemplate extends Composite {
public boolean isAppFeed() {
return isAppFeed;
}
public boolean isUser() {
return isUsers;
}
}

View File

@ -124,7 +124,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
*/
public String getDevelopmentUser() {
String user = NewsConstants.TEST_USER;
// user = "costantino.perciante";
//user = "costantino.perciante";
return user;
}
/**