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:
parent
1e1866c847
commit
b2d0bf5cc7
|
@ -4,6 +4,7 @@ import org.gcube.portal.databook.shared.Comment;
|
||||||
import org.gcube.portlets.user.newsfeed.client.ui.TweetTemplate;
|
import org.gcube.portlets.user.newsfeed.client.ui.TweetTemplate;
|
||||||
|
|
||||||
import com.google.gwt.event.shared.GwtEvent;
|
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 TweetTemplate owner;
|
||||||
private Comment edited;
|
private Comment edited;
|
||||||
|
private HTMLPanel commentPanel;
|
||||||
|
|
||||||
public TweetTemplate getOwner() {
|
public TweetTemplate getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
|
@ -19,9 +21,14 @@ public class EditCommentEvent extends GwtEvent<EditCommentEventHandler> {
|
||||||
public Comment getCommentInstance() {
|
public Comment getCommentInstance() {
|
||||||
return edited;
|
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.owner = owner;
|
||||||
this.edited = editedComment;
|
this.edited = editedComment;
|
||||||
|
this.commentPanel = commentPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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.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.HTML;
|
||||||
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||||
import com.google.gwt.user.client.ui.HasAlignment;
|
import com.google.gwt.user.client.ui.HasAlignment;
|
||||||
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
||||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||||
|
@ -180,7 +181,7 @@ public class NewsFeedPanel extends Composite {
|
||||||
eventBus.addHandler(EditCommentEvent.TYPE, new EditCommentEventHandler() {
|
eventBus.addHandler(EditCommentEvent.TYPE, new EditCommentEventHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onEditComment(EditCommentEvent event) {
|
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 {
|
else {
|
||||||
Comment comment = (Comment) result.getObject();
|
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.setCommentingDisabled(false);
|
||||||
owner.updateCommentsNumberCount();
|
owner.updateCommentsNumberCount();
|
||||||
owner.showAddCommentForm(false);
|
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>() {
|
newsService.editComment(edited, new AsyncCallback<OperationResult>() {
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
|
@ -961,7 +962,7 @@ public class NewsFeedPanel extends Composite {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Comment comment = (Comment) result.getObject();
|
Comment comment = (Comment) result.getObject();
|
||||||
owner.addComment(new SingleComment(comment, owner, (comment.getUserid().equals(myUserInfo.getUsername()))), true);
|
owner.updateSingleComment(comment, commentPanel);
|
||||||
owner.setCommentingDisabled(false);
|
owner.setCommentingDisabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -987,7 +988,7 @@ public class NewsFeedPanel extends Composite {
|
||||||
public void onSuccess(ArrayList<Comment> comments) {
|
public void onSuccess(ArrayList<Comment> comments) {
|
||||||
owner.clearComments();
|
owner.clearComments();
|
||||||
for (Comment comment :comments)
|
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);
|
owner.setCommentsFetched(true);
|
||||||
if (commentForm2Add)
|
if (commentForm2Add)
|
||||||
owner.showAddCommentForm(false);
|
owner.showAddCommentForm(false);
|
||||||
|
|
|
@ -89,6 +89,7 @@ public class AddCommentTemplate extends Composite {
|
||||||
mainPanel.removeStyleName("comment-hidden");
|
mainPanel.removeStyleName("comment-hidden");
|
||||||
mainPanel.setStyleName("single-comment");
|
mainPanel.setStyleName("single-comment");
|
||||||
commentTextArea.addStyleName("comment-dark-color");
|
commentTextArea.addStyleName("comment-dark-color");
|
||||||
|
submitButton.setText("Edit");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used by AddCommentTemplate to instantiate SuperPosedTextArea */
|
/** Used by AddCommentTemplate to instantiate SuperPosedTextArea */
|
||||||
|
@ -124,7 +125,7 @@ public class AddCommentTemplate extends Composite {
|
||||||
}
|
}
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
toEdit.setText(escapeHtml(commentTextArea.getText()));
|
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
|
else { //it is ok to add this comment
|
||||||
eventBus.fireEvent(new AddCommentEvent(owner, escapeHtml(commentTextArea.getText()), commentTextArea.getMentionedUsers()));
|
eventBus.fireEvent(new AddCommentEvent(owner, escapeHtml(commentTextArea.getText()), commentTextArea.getMentionedUsers()));
|
||||||
|
|
|
@ -90,6 +90,10 @@ public class SingleComment extends Composite {
|
||||||
Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+
|
Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+
|
||||||
Encoder.encode(toShow.getUserid())+"\">"+toShow.getFullName()+
|
Encoder.encode(toShow.getUserid())+"\">"+toShow.getFullName()+
|
||||||
"</a> " + commentToShow);
|
"</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()));
|
timeArea.setHTML(DateTimeFormat.getFormat("MMMM dd, h:mm a").format(toShow.getTime()));
|
||||||
if (isUsers) {
|
if (isUsers) {
|
||||||
closeImage.setStyleName("closeImage");
|
closeImage.setStyleName("closeImage");
|
||||||
|
@ -147,6 +151,10 @@ public class SingleComment extends Composite {
|
||||||
editImage.removeStyleName("uiEditButton");
|
editImage.removeStyleName("uiEditButton");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCommentKey() {
|
||||||
|
return myCommentid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package org.gcube.portlets.user.newsfeed.client.ui;
|
package org.gcube.portlets.user.newsfeed.client.ui;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.portal.databook.client.GCubeSocialNetworking;
|
import org.gcube.portal.databook.client.GCubeSocialNetworking;
|
||||||
|
@ -242,7 +243,7 @@ public class TweetTemplate extends Composite {
|
||||||
commentsNo.setTitle("Show all Comments");
|
commentsNo.setTitle("Show all Comments");
|
||||||
}
|
}
|
||||||
for (Comment comment : myFeed.getComments()) {
|
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);
|
showAddCommentForm(false);
|
||||||
}
|
}
|
||||||
|
@ -449,12 +450,36 @@ public class TweetTemplate extends Composite {
|
||||||
mainHTML.remove(w);
|
mainHTML.remove(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addComment(SingleComment comment, boolean isEdit) {
|
public void addComment(SingleComment comment) {
|
||||||
if (isEdit)
|
|
||||||
commentsPanel.insert(comment, commentsPanel.getWidgetCount()-1);
|
commentsPanel.add(comment);
|
||||||
else
|
|
||||||
commentsPanel.add(comment);
|
|
||||||
myComments.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() {
|
public void clearComments() {
|
||||||
|
|
|
@ -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 SESSION_ADMIN_ATTR = "SESSION_ADMIN_ATTR";
|
||||||
private static final String USER_SETTINGS_ATTR = "USER_SETTINGS_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;
|
private String APP_ID;
|
||||||
|
|
||||||
|
@ -678,14 +678,14 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
||||||
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(toEdit.getText());
|
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(toEdit.getText());
|
||||||
|
|
||||||
Comment edited = new Comment(toEdit.getKey(), toEdit.getUserid(),
|
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 {
|
try {
|
||||||
store.editComment(edited);
|
store.editComment(edited);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return new OperationResult(false, "Exception on the server: " + e.getMessage(), null);
|
return new OperationResult(false, "Exception on the server: " + e.getMessage(), null);
|
||||||
}
|
}
|
||||||
return new OperationResult(true, "OK", toEdit);
|
return new OperationResult(true, "OK", edited);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue