added window title updates no prefix for smart refresh, added anchor url for http links in comments
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@73081 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
80bc8b119a
commit
49fd6ab9f9
|
@ -15,6 +15,7 @@ import com.google.gwt.uibinder.client.UiHandler;
|
|||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
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.Image;
|
||||
import com.google.gwt.user.client.ui.TextArea;
|
||||
|
@ -66,7 +67,7 @@ public class AddCommentTemplate extends Composite{
|
|||
avatarImage.setPixelSize(30, 30);
|
||||
avatarImage.setUrl(caller.getMyUserInfo().getAvatarId());
|
||||
commentTextArea.setPixelSize(450, 26);
|
||||
commentTextArea.setText(toEdit.getText());
|
||||
commentTextArea.setText(new HTML(toEdit.getText()).getText());
|
||||
mainPanel.removeStyleName("comment-hidden");
|
||||
mainPanel.setStyleName("single-comment");
|
||||
commentTextArea.addStyleName("dark-color");
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.portlets.user.newsfeed.client.templates;
|
|||
import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEvent;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
|
@ -35,7 +36,7 @@ public class NewFeedsAvailable extends Composite {
|
|||
initWidget(uiBinder.createAndBindUi(this));
|
||||
this.eventBus = eventBus;
|
||||
if (newUpdatesNo > 0) {
|
||||
caption.setHTML(newUpdatesNo > 1 ? "See " + newUpdatesNo + " new Updates" : "See 1 new Update");
|
||||
updateNewUpdatesNo(newUpdatesNo);
|
||||
//create the fade transition effect
|
||||
Timer t = new Timer() {
|
||||
@Override
|
||||
|
@ -49,7 +50,21 @@ public class NewFeedsAvailable extends Composite {
|
|||
}
|
||||
|
||||
public void updateNewUpdatesNo(int newUpdatesNo) {
|
||||
caption.setHTML(newUpdatesNo > 1 ? "See " + newUpdatesNo + " new Updates" : "See 1 new Update");
|
||||
String messageToShow = newUpdatesNo > 1 ? "See " + newUpdatesNo + " new Updates" : "See 1 new Update";
|
||||
caption.setHTML(messageToShow);
|
||||
setBrowserWindowTitle(newUpdatesNo);
|
||||
}
|
||||
|
||||
public static void setBrowserWindowTitle (int newUpdatesNo) {
|
||||
if (Document.get() != null) {
|
||||
String currTitle = Document.get().getTitle();
|
||||
if (currTitle.startsWith("(")) {
|
||||
String newTitle = "(" + newUpdatesNo + currTitle.substring(2);
|
||||
Document.get().setTitle(newTitle);
|
||||
}
|
||||
else
|
||||
Document.get().setTitle ("("+newUpdatesNo+") " + currTitle);
|
||||
}
|
||||
}
|
||||
|
||||
@UiHandler("caption")
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.gcube.portlets.user.newsfeed.server;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
@ -338,7 +340,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
_log.trace("Trying to add this comment " + commentText);
|
||||
UserInfo user = getUserSettings().getUserInfo();
|
||||
Comment comment = new Comment(UUID.randomUUID().toString(), user.getUsername(),
|
||||
new Date(), feedid, escapeHtml(commentText), user.getFullName(), user.getAvatarId());
|
||||
new Date(), feedid, transformUrls(escapeHtml(commentText)), user.getFullName(), user.getAvatarId());
|
||||
try {
|
||||
if (store.addComment(comment))
|
||||
commentCommitResult = true;
|
||||
|
@ -348,7 +350,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
return null;
|
||||
}
|
||||
//if the comment was correctly delivered && is not an app feed notify users involved
|
||||
if (commentCommitResult) {
|
||||
if (commentCommitResult && withinPortal) {
|
||||
//if the user who commented this post is not the user who posted it notify the poster user (Feed owner)
|
||||
NotificationsManager nm = new ApplicationNotificationsManager(getASLSession());
|
||||
if (! user.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
|
||||
|
@ -362,6 +364,20 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
return comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comment editComment(Comment toEdit) {
|
||||
UserInfo user = getUserSettings().getUserInfo();
|
||||
Comment edited = new Comment(toEdit.getKey(), toEdit.getUserid(),
|
||||
new Date(), toEdit.getFeedid(), transformUrls(escapeHtml(toEdit.getText())), user.getFullName(), user.getAvatarId());
|
||||
try {
|
||||
store.editComment(edited);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return edited;
|
||||
}
|
||||
|
||||
private String replaceAmpersand(String toReplace) {
|
||||
String toReturn = toReplace.replaceAll("&", "&");
|
||||
return toReturn;
|
||||
|
@ -562,20 +578,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
return html.replaceAll("&", "&").replaceAll("<", "<")
|
||||
.replaceAll(">", ">");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comment editComment(Comment toEdit) {
|
||||
UserInfo user = getUserSettings().getUserInfo();
|
||||
Comment edited = new Comment(toEdit.getKey(), toEdit.getUserid(),
|
||||
new Date(), toEdit.getFeedid(), escapeHtml(toEdit.getText()), user.getFullName(), user.getAvatarId());
|
||||
try {
|
||||
store.editComment(edited);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return edited;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the user is a portal administrator or not
|
||||
|
@ -633,6 +636,36 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* utilty method that convert a URL in a text into a clickable link into the browser
|
||||
*
|
||||
* @param text
|
||||
* @return the text with the clickable url in it
|
||||
*/
|
||||
public String transformUrls(String textToCheck) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// separate input by spaces ( URLs have no spaces )
|
||||
String [] parts = textToCheck.split("\\s");
|
||||
// Attempt to convert each item into an URL.
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
if (parts[i].startsWith("http")) {
|
||||
try {
|
||||
URL url = new URL(parts[i]);
|
||||
// If possible then replace with anchor...
|
||||
sb.append("<a class=\"link\" style=\"font-size:11px;\" href=\"").append(url).append("\" target=\"_blank\">").append(url).append("</a> ");
|
||||
} catch (MalformedURLException e) {
|
||||
// If there was an URL then it's not valid
|
||||
_log.error("MalformedURLException returning... ");
|
||||
return textToCheck;
|
||||
}
|
||||
} else {
|
||||
sb.append(parts[i]);
|
||||
sb.append(" ");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
/**
|
||||
* read from the property the refreshing time
|
||||
* @return the refreshingTime in milliseconds
|
||||
|
@ -671,6 +704,6 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
return toReturn;
|
||||
}
|
||||
else
|
||||
return 15000; //15 secs for testing
|
||||
return 30000; //30 secs for testing
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue