Comment editing is now properly managed

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@121784 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2015-12-11 13:16:21 +00:00
parent 1e1866c847
commit b2d0bf5cc7
6 changed files with 58 additions and 16 deletions

View File

@ -4,6 +4,7 @@ import org.gcube.portal.databook.shared.Comment;
import org.gcube.portlets.user.newsfeed.client.ui.TweetTemplate;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.user.client.ui.HTMLPanel;
@ -12,6 +13,7 @@ public class EditCommentEvent extends GwtEvent<EditCommentEventHandler> {
private TweetTemplate owner;
private Comment edited;
private HTMLPanel commentPanel;
public TweetTemplate getOwner() {
return owner;
@ -19,9 +21,14 @@ public class EditCommentEvent extends GwtEvent<EditCommentEventHandler> {
public Comment getCommentInstance() {
return edited;
}
public EditCommentEvent(TweetTemplate owner, Comment editedComment) {
public HTMLPanel getCommentPanel() {
return commentPanel;
}
public EditCommentEvent(TweetTemplate owner, Comment editedComment, HTMLPanel commentPanel) {
this.owner = owner;
this.edited = editedComment;
this.commentPanel = commentPanel;
}
@Override

View File

@ -70,6 +70,7 @@ import com.google.gwt.user.client.Window.ScrollHandler;
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.HTMLPanel;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
@ -180,7 +181,7 @@ public class NewsFeedPanel extends Composite {
eventBus.addHandler(EditCommentEvent.TYPE, new EditCommentEventHandler() {
@Override
public void onEditComment(EditCommentEvent event) {
doEditComment(event.getOwner(), event.getCommentInstance());
doEditComment(event.getOwner(), event.getCommentInstance(), event.getCommentPanel());
}
});
@ -933,7 +934,7 @@ public class NewsFeedPanel extends Composite {
}
else {
Comment comment = (Comment) result.getObject();
owner.addComment(new SingleComment(comment, owner, (comment.getUserid().equals(myUserInfo.getUsername()))), false);
owner.addComment(new SingleComment(comment, owner, (comment.getUserid().equals(myUserInfo.getUsername()))));
owner.setCommentingDisabled(false);
owner.updateCommentsNumberCount();
owner.showAddCommentForm(false);
@ -946,7 +947,7 @@ public class NewsFeedPanel extends Composite {
});
}
private void doEditComment(final TweetTemplate owner, Comment edited) {
private void doEditComment(final TweetTemplate owner, Comment edited, final HTMLPanel commentPanel) {
newsService.editComment(edited, new AsyncCallback<OperationResult>() {
@Override
public void onFailure(Throwable caught) {
@ -961,7 +962,7 @@ public class NewsFeedPanel extends Composite {
}
else {
Comment comment = (Comment) result.getObject();
owner.addComment(new SingleComment(comment, owner, (comment.getUserid().equals(myUserInfo.getUsername()))), true);
owner.updateSingleComment(comment, commentPanel);
owner.setCommentingDisabled(false);
}
}
@ -987,7 +988,7 @@ public class NewsFeedPanel extends Composite {
public void onSuccess(ArrayList<Comment> comments) {
owner.clearComments();
for (Comment comment :comments)
owner.addComment(new SingleComment(comment, owner,(comment.getUserid().equals(myUserInfo.getUsername())) ), false);
owner.addComment(new SingleComment(comment, owner,(comment.getUserid().equals(myUserInfo.getUsername()))));
owner.setCommentsFetched(true);
if (commentForm2Add)
owner.showAddCommentForm(false);

View File

@ -89,6 +89,7 @@ public class AddCommentTemplate extends Composite {
mainPanel.removeStyleName("comment-hidden");
mainPanel.setStyleName("single-comment");
commentTextArea.addStyleName("comment-dark-color");
submitButton.setText("Edit");
}
/** Used by AddCommentTemplate to instantiate SuperPosedTextArea */
@ -124,7 +125,7 @@ public class AddCommentTemplate extends Composite {
}
if (isEditing) {
toEdit.setText(escapeHtml(commentTextArea.getText()));
eventBus.fireEvent(new EditCommentEvent(owner, toEdit));
eventBus.fireEvent(new EditCommentEvent(owner, toEdit, commentPanel));
}
else { //it is ok to add this comment
eventBus.fireEvent(new AddCommentEvent(owner, escapeHtml(commentTextArea.getText()), commentTextArea.getMentionedUsers()));

View File

@ -90,6 +90,10 @@ public class SingleComment extends Composite {
Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+
Encoder.encode(toShow.getUserid())+"\">"+toShow.getFullName()+
"</a> " + commentToShow);
if(toShow.isEdit())
timeArea.setHTML(DateTimeFormat.getFormat("MMMM dd, h:mm a").format(toShow.getTime()) +
" (Last edit on " + DateTimeFormat.getFormat("MMMM dd, h:mm a").format(toShow.getLastEditTime()) + ")");
else
timeArea.setHTML(DateTimeFormat.getFormat("MMMM dd, h:mm a").format(toShow.getTime()));
if (isUsers) {
closeImage.setStyleName("closeImage");
@ -147,6 +151,10 @@ public class SingleComment extends Composite {
editImage.removeStyleName("uiEditButton");
}
}
public String getCommentKey() {
return myCommentid;
}
}

View File

@ -4,6 +4,7 @@
package org.gcube.portlets.user.newsfeed.client.ui;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
@ -242,7 +243,7 @@ public class TweetTemplate extends Composite {
commentsNo.setTitle("Show all Comments");
}
for (Comment comment : myFeed.getComments()) {
addComment(new SingleComment(comment, this, (comment.getUserid().equals(myUserInfo.getUsername()))), false);
addComment(new SingleComment(comment, this, (comment.getUserid().equals(myUserInfo.getUsername()))));
}
showAddCommentForm(false);
}
@ -449,12 +450,36 @@ public class TweetTemplate extends Composite {
mainHTML.remove(w);
}
public void addComment(SingleComment comment, boolean isEdit) {
if (isEdit)
commentsPanel.insert(comment, commentsPanel.getWidgetCount()-1);
else
commentsPanel.add(comment);
public void addComment(SingleComment comment) {
commentsPanel.add(comment);
myComments.add(comment);
}
public void updateSingleComment(Comment edited, HTMLPanel commentPanel){
commentPanel.clear();
SingleComment sc = new SingleComment(edited, this, true);
commentPanel.add(sc);
// replace the new SingleComment in the list
int index = 0;
Iterator<SingleComment> iterator = this.myComments.iterator();
for (;iterator.hasNext();) {
SingleComment singleComment = (SingleComment) iterator.next();
if(singleComment.getCommentKey().equals(edited.getKey())){
iterator.remove();
this.myComments.add(index, sc);
break;
}
index ++;
}
}
public void clearComments() {

View File

@ -82,7 +82,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
private static final String SESSION_ADMIN_ATTR = "SESSION_ADMIN_ATTR";
private static final String USER_SETTINGS_ATTR = "USER_SETTINGS_ATTR";
public static final String TEST_SCOPE = "/gcube/devsec/USTORE_VRE";
public static final String TEST_SCOPE = "/gcube/devsec/devVRE";
private String APP_ID;
@ -678,14 +678,14 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(toEdit.getText());
Comment edited = new Comment(toEdit.getKey(), toEdit.getUserid(),
new Date(), toEdit.getFeedid(), escapedCommentText, user.getFullName(), user.getAvatarId());
toEdit.getTime(), toEdit.getFeedid(), escapedCommentText, user.getFullName(), user.getAvatarId(), true, new Date());
try {
store.editComment(edited);
} catch (Exception e) {
e.printStackTrace();
return new OperationResult(false, "Exception on the server: " + e.getMessage(), null);
}
return new OperationResult(true, "OK", toEdit);
return new OperationResult(true, "OK", edited);
}
/**