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.Window;
|
||||||
import com.google.gwt.user.client.ui.Button;
|
import com.google.gwt.user.client.ui.Button;
|
||||||
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.HTMLPanel;
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||||
import com.google.gwt.user.client.ui.Image;
|
import com.google.gwt.user.client.ui.Image;
|
||||||
import com.google.gwt.user.client.ui.TextArea;
|
import com.google.gwt.user.client.ui.TextArea;
|
||||||
|
@ -66,7 +67,7 @@ public class AddCommentTemplate extends Composite{
|
||||||
avatarImage.setPixelSize(30, 30);
|
avatarImage.setPixelSize(30, 30);
|
||||||
avatarImage.setUrl(caller.getMyUserInfo().getAvatarId());
|
avatarImage.setUrl(caller.getMyUserInfo().getAvatarId());
|
||||||
commentTextArea.setPixelSize(450, 26);
|
commentTextArea.setPixelSize(450, 26);
|
||||||
commentTextArea.setText(toEdit.getText());
|
commentTextArea.setText(new HTML(toEdit.getText()).getText());
|
||||||
mainPanel.removeStyleName("comment-hidden");
|
mainPanel.removeStyleName("comment-hidden");
|
||||||
mainPanel.setStyleName("single-comment");
|
mainPanel.setStyleName("single-comment");
|
||||||
commentTextArea.addStyleName("dark-color");
|
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 org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEvent;
|
||||||
|
|
||||||
import com.google.gwt.core.client.GWT;
|
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.dom.client.ClickEvent;
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
import com.google.gwt.uibinder.client.UiBinder;
|
import com.google.gwt.uibinder.client.UiBinder;
|
||||||
|
@ -35,7 +36,7 @@ public class NewFeedsAvailable extends Composite {
|
||||||
initWidget(uiBinder.createAndBindUi(this));
|
initWidget(uiBinder.createAndBindUi(this));
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
if (newUpdatesNo > 0) {
|
if (newUpdatesNo > 0) {
|
||||||
caption.setHTML(newUpdatesNo > 1 ? "See " + newUpdatesNo + " new Updates" : "See 1 new Update");
|
updateNewUpdatesNo(newUpdatesNo);
|
||||||
//create the fade transition effect
|
//create the fade transition effect
|
||||||
Timer t = new Timer() {
|
Timer t = new Timer() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,7 +50,21 @@ public class NewFeedsAvailable extends Composite {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateNewUpdatesNo(int newUpdatesNo) {
|
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")
|
@UiHandler("caption")
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.gcube.portlets.user.newsfeed.server;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -338,7 +340,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
||||||
_log.trace("Trying to add this comment " + commentText);
|
_log.trace("Trying to add this comment " + commentText);
|
||||||
UserInfo user = getUserSettings().getUserInfo();
|
UserInfo user = getUserSettings().getUserInfo();
|
||||||
Comment comment = new Comment(UUID.randomUUID().toString(), user.getUsername(),
|
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 {
|
try {
|
||||||
if (store.addComment(comment))
|
if (store.addComment(comment))
|
||||||
commentCommitResult = true;
|
commentCommitResult = true;
|
||||||
|
@ -348,7 +350,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//if the comment was correctly delivered && is not an app feed notify users involved
|
//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)
|
//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());
|
NotificationsManager nm = new ApplicationNotificationsManager(getASLSession());
|
||||||
if (! user.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
|
if (! user.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
|
||||||
|
@ -362,6 +364,20 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
||||||
return comment;
|
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) {
|
private String replaceAmpersand(String toReplace) {
|
||||||
String toReturn = toReplace.replaceAll("&", "&");
|
String toReturn = toReplace.replaceAll("&", "&");
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
@ -563,19 +579,6 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
||||||
.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
|
* @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 true;
|
||||||
return false;
|
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
|
* read from the property the refreshing time
|
||||||
* @return the refreshingTime in milliseconds
|
* @return the refreshingTime in milliseconds
|
||||||
|
@ -671,6 +704,6 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 15000; //15 secs for testing
|
return 30000; //30 secs for testing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue