added avatar replacement image if user has no avatar
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@94797 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d3e31ce7e9
commit
1ebc89d0b4
|
@ -6,6 +6,7 @@
|
||||||
<Change>Added possibility to unlike alread liked posts</Change>
|
<Change>Added possibility to unlike alread liked posts</Change>
|
||||||
<Change>Added possibility to mention users in comments</Change>
|
<Change>Added possibility to mention users in comments</Change>
|
||||||
<Change>Added default comment inputbox at the bottom of feed comments, if any</Change>
|
<Change>Added default comment inputbox at the bottom of feed comments, if any</Change>
|
||||||
|
<Change>Added avatar replacement if user has no avatar</Change>
|
||||||
<Change>Fixed double notifications for post owner who commented his
|
<Change>Fixed double notifications for post owner who commented his
|
||||||
post</Change>
|
post</Change>
|
||||||
<Change>Fixed double notifications for post owner who liked his post
|
<Change>Fixed double notifications for post owner who liked his post
|
||||||
|
|
|
@ -55,6 +55,7 @@ import org.gcube.portlets.widgets.userselection.shared.ItemSelectableBean;
|
||||||
|
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
import com.google.gwt.core.client.RunAsyncCallback;
|
import com.google.gwt.core.client.RunAsyncCallback;
|
||||||
|
import java.util.HashMap;
|
||||||
import com.google.gwt.dom.client.Document;
|
import com.google.gwt.dom.client.Document;
|
||||||
import com.google.gwt.dom.client.Style.Unit;
|
import com.google.gwt.dom.client.Style.Unit;
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
|
@ -101,6 +102,11 @@ public class NewsFeedPanel extends Composite {
|
||||||
private static final String warning = GWT.getModuleBaseURL() + "../images/warning_blue.png";
|
private static final String warning = GWT.getModuleBaseURL() + "../images/warning_blue.png";
|
||||||
private static final String spacer = GWT.getModuleBaseURL() + "../images/feeds-spacer.gif";
|
private static final String spacer = GWT.getModuleBaseURL() + "../images/feeds-spacer.gif";
|
||||||
public static final String loading = GWT.getModuleBaseURL() + "../images/feeds-loader.gif";
|
public static final String loading = GWT.getModuleBaseURL() + "../images/feeds-loader.gif";
|
||||||
|
/**
|
||||||
|
* since we want to maintain the color assigned to an avatar replacement through all the session
|
||||||
|
* this hashmap maintain the assigned users color, chosen reandomly at the beginning
|
||||||
|
*/
|
||||||
|
public static final HashMap<String, String> avatarReplacementAssignedColors = new HashMap<String, String>();
|
||||||
|
|
||||||
public static final String GET_OID_PARAMETER = "oid";
|
public static final String GET_OID_PARAMETER = "oid";
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
package org.gcube.portlets.user.newsfeed.client.ui;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
|
||||||
|
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.uibinder.client.UiBinder;
|
||||||
|
import com.google.gwt.uibinder.client.UiField;
|
||||||
|
import com.google.gwt.user.client.Random;
|
||||||
|
import com.google.gwt.user.client.ui.Composite;
|
||||||
|
import com.google.gwt.user.client.ui.HTML;
|
||||||
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
|
|
||||||
|
public class AvatarReplacement extends Composite {
|
||||||
|
|
||||||
|
private static NoAvatarUiBinder uiBinder = GWT
|
||||||
|
.create(NoAvatarUiBinder.class);
|
||||||
|
|
||||||
|
interface NoAvatarUiBinder extends UiBinder<Widget, AvatarReplacement> {
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiField HTML avatarBox;
|
||||||
|
/**
|
||||||
|
* the random colors
|
||||||
|
*/
|
||||||
|
private String[] randomColors = {
|
||||||
|
"#8e8e93",
|
||||||
|
"#ff2d55",
|
||||||
|
"#ff3b30",
|
||||||
|
"#ff9500",
|
||||||
|
"#ffcc00",
|
||||||
|
"#4cd964",
|
||||||
|
"#5ac8fa",
|
||||||
|
"#34aadc",
|
||||||
|
"#007aff",
|
||||||
|
"#5856d6"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public AvatarReplacement() {
|
||||||
|
initWidget(uiBinder.createAndBindUi(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInitials(String username, String firstName, String lastName) {
|
||||||
|
pickRandomColor(username);
|
||||||
|
String first = "A";
|
||||||
|
if (firstName != null && firstName.trim().length() > 0)
|
||||||
|
first = firstName.trim().substring(0, 1);
|
||||||
|
String second = "Z";
|
||||||
|
if (lastName != null && lastName.trim().length() > 0)
|
||||||
|
second = lastName.trim().substring(0, 1);
|
||||||
|
avatarBox.setText(first+second);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* randomize of does not find it, else color is maintained through all the session
|
||||||
|
* @param username
|
||||||
|
*/
|
||||||
|
private void pickRandomColor(String username) {
|
||||||
|
if (! NewsFeedPanel.avatarReplacementAssignedColors.containsKey(username)) {
|
||||||
|
String randomColor = randomColors[Random.nextInt(randomColors.length)];
|
||||||
|
avatarBox.getElement().getStyle().setBackgroundColor(randomColor);
|
||||||
|
NewsFeedPanel.avatarReplacementAssignedColors.put(username, randomColor);
|
||||||
|
} else
|
||||||
|
avatarBox.getElement().getStyle().setBackgroundColor(NewsFeedPanel.avatarReplacementAssignedColors.get(username));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||||
|
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||||
|
xmlns:g="urn:import:com.google.gwt.user.client.ui">
|
||||||
|
<ui:style>
|
||||||
|
.avatar-frame {
|
||||||
|
border: 1px solid #E6E6E6;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
|
.avatar-replacement {
|
||||||
|
display: table-cell;
|
||||||
|
text-align: center;
|
||||||
|
vertical-align: middle;
|
||||||
|
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
|
||||||
|
font-weight: 300;
|
||||||
|
font-size: 22px;
|
||||||
|
padding: 0;
|
||||||
|
color: #FFF;
|
||||||
|
}
|
||||||
|
</ui:style>
|
||||||
|
<g:HTMLPanel width="50px" height="50px" styleName="{style.avatar-frame}">
|
||||||
|
<g:HTML width="50px" height="50px" styleName="{style.avatar-replacement}" ui:field="avatarBox"></g:HTML>
|
||||||
|
</g:HTMLPanel>
|
||||||
|
</ui:UiBinder>
|
|
@ -90,6 +90,8 @@ public class TweetTemplate extends Composite {
|
||||||
@UiField
|
@UiField
|
||||||
Image avatarImage;
|
Image avatarImage;
|
||||||
@UiField
|
@UiField
|
||||||
|
AvatarReplacement avatarReplacement;
|
||||||
|
@UiField
|
||||||
HTMLPanel mainHTML;
|
HTMLPanel mainHTML;
|
||||||
@UiField
|
@UiField
|
||||||
HTML likesNo;
|
HTML likesNo;
|
||||||
|
@ -150,6 +152,9 @@ public class TweetTemplate extends Composite {
|
||||||
seeMore.setHTML("<a class=\"seemore\"> See More </a>");
|
seeMore.setHTML("<a class=\"seemore\"> See More </a>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avatarImage.setUrl(feed.getThumbnailURL());
|
||||||
|
avatarImage.setPixelSize(50, 50);
|
||||||
|
|
||||||
//replace the < & and >
|
//replace the < & and >
|
||||||
feedText = feedText.replaceAll("<","<").replaceAll(">",">");
|
feedText = feedText.replaceAll("<","<").replaceAll(">",">");
|
||||||
feedText = feedText.replaceAll("&","&");
|
feedText = feedText.replaceAll("&","&");
|
||||||
|
@ -167,6 +172,24 @@ public class TweetTemplate extends Composite {
|
||||||
String vreName = feed.getVreid().substring(feed.getVreid().lastIndexOf("/")+1);
|
String vreName = feed.getVreid().substring(feed.getVreid().lastIndexOf("/")+1);
|
||||||
vreSource.setHTML("<a class=\"link\" style=\"font-size: 10px; white-space: nowrap;\" href=\"/group/"+vreName.toLowerCase()+"\">[" +vreName + "]</a>");
|
vreSource.setHTML("<a class=\"link\" style=\"font-size: 10px; white-space: nowrap;\" href=\"/group/"+vreName.toLowerCase()+"\">[" +vreName + "]</a>");
|
||||||
}
|
}
|
||||||
|
//check if the user has his own avatar
|
||||||
|
if (feed.getThumbnailURL().endsWith("img_id=0") || !feed.getThumbnailURL().contains("?")) { //it means no avatar is set
|
||||||
|
avatarImage.setVisible(false);
|
||||||
|
String f = "A";
|
||||||
|
String s = "Z";
|
||||||
|
if (feed.getFullName() != null) {
|
||||||
|
String[] parts = feed.getFullName().split("\\s");
|
||||||
|
if (parts.length > 0) {
|
||||||
|
f = parts[0].toUpperCase();
|
||||||
|
s = parts[parts.length-1].toUpperCase();
|
||||||
|
} else {
|
||||||
|
f = feed.getFullName().substring(0,1);
|
||||||
|
s = feed.getFullName().substring(1,2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
avatarReplacement.setInitials(feed.getEntityId(), f, s);
|
||||||
|
avatarReplacement.setVisible(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// messageSeparator.setVisible(false);
|
// messageSeparator.setVisible(false);
|
||||||
|
@ -184,8 +207,7 @@ public class TweetTemplate extends Composite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
avatarImage.setUrl(feed.getThumbnailURL());
|
|
||||||
avatarImage.setPixelSize(50, 50);
|
|
||||||
try {
|
try {
|
||||||
String formattedTime = DateTimeFormat.getFormat("MMMM dd, h:mm a").format(feed.getTime());
|
String formattedTime = DateTimeFormat.getFormat("MMMM dd, h:mm a").format(feed.getTime());
|
||||||
timeArea.setHTML(formattedTime);
|
timeArea.setHTML(formattedTime);
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||||
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:m="org.gcube.portlets.user.newsfeed.client.ui">
|
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:m="urn:import:org.gcube.portlets.user.newsfeed.client.ui">
|
||||||
<g:HTMLPanel ui:field="mainHTML">
|
<g:HTMLPanel ui:field="mainHTML">
|
||||||
<div class="div-table">
|
<div class="div-table">
|
||||||
<div class="div-table-row">
|
<div class="div-table-row">
|
||||||
<div class="div-table-col photo">
|
<div class="div-table-col photo">
|
||||||
<g:Image title="" styleName="member-photo" url=""
|
<g:Image title="" styleName="member-photo" url=""
|
||||||
ui:field="avatarImage" width="60" height="60" />
|
ui:field="avatarImage" width="60" height="60"/>
|
||||||
|
<m:AvatarReplacement visible="false" ui:field="avatarReplacement"></m:AvatarReplacement>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="div-table-col content">
|
<div class="div-table-col content">
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
_log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL");
|
_log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL");
|
||||||
user = getDevelopmentUser();
|
user = getDevelopmentUser();
|
||||||
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
|
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devNext/NextNext");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
withinPortal = true;
|
withinPortal = true;
|
||||||
|
@ -116,7 +116,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
||||||
*/
|
*/
|
||||||
public String getDevelopmentUser() {
|
public String getDevelopmentUser() {
|
||||||
String user = "test.user";
|
String user = "test.user";
|
||||||
//user = "massimiliano.assante";
|
// user = "massimiliano.assante";
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue