frame the mainpanel if in VRE

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@73154 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-04-11 10:58:50 +00:00
parent e1d2c1e23f
commit 64de50b635
5 changed files with 148 additions and 114 deletions

View File

@ -29,8 +29,6 @@ import org.gcube.portlets.user.newsfeed.client.event.SeeLikesEvent;
import org.gcube.portlets.user.newsfeed.client.event.SeeLikesEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEvent;
import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.StopTimerEvent;
import org.gcube.portlets.user.newsfeed.client.event.StopTimerEventHandler;
import org.gcube.portlets.user.newsfeed.client.panels.dialog.LikesDialog;
import org.gcube.portlets.user.newsfeed.client.templates.FilterPanel;
import org.gcube.portlets.user.newsfeed.client.templates.NewFeedsAvailable;
@ -54,8 +52,6 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import edu.emory.mathcs.backport.java.util.Collections;
/**
*
* @author Massimiliano Assante, ISTI-CNR
@ -73,7 +69,7 @@ public class NewsFeedPanel extends Composite {
private HorizontalPanel filterPanel = new HorizontalPanel();
private SimplePanel newUpdatesPanel = new SimplePanel();
private VerticalPanel newsPanel = new VerticalPanel();
private NewFeedsAvailable newsFeedAlert;
private static final String warning = GWT.getModuleBaseURL() + "../images/warning_blue.png";
@ -86,7 +82,7 @@ public class NewsFeedPanel extends Composite {
public static final String MESSAGE_LABEL = "Message";
private int delayMillis = 300000; //5 minutes by default (is read from a configuration file in the first async callback)
private int currNewUpdatesNo = 0;
private boolean isFirstTweet = false;
@ -104,7 +100,7 @@ public class NewsFeedPanel extends Composite {
* events binder
*/
private void bind() {
eventBus.addHandler(ShowNewUpdatesEvent.TYPE, new ShowNewUpdatesEventHandler() {
@Override
public void onShowNewUpdatesClick(ShowNewUpdatesEvent event) {
@ -113,21 +109,9 @@ public class NewsFeedPanel extends Composite {
});
eventBus.addHandler(StopTimerEvent.TYPE, new StopTimerEventHandler() {
@Override
public void onStopTimer(StopTimerEvent event) {
GWT.log("Stop timer");
if (event.isRestart())
resetTimer();
else
stopTimer();
}
});
eventBus.addHandler(AddLikeEvent.TYPE, new AddLikeEventHandler() {
@Override
public void onAddLike(AddLikeEvent event) {
resetTimer();
doAddLike( event.getOwner(), event.getFeedId());
}
});
@ -135,7 +119,6 @@ public class NewsFeedPanel extends Composite {
eventBus.addHandler(AddCommentEvent.TYPE, new AddCommentEventHandler() {
@Override
public void onAddComment(AddCommentEvent event) {
resetTimer();
doAddComment(event.getOwner(), event.getText());
}
});
@ -143,7 +126,6 @@ public class NewsFeedPanel extends Composite {
eventBus.addHandler(EditCommentEvent.TYPE, new EditCommentEventHandler() {
@Override
public void onEditComment(EditCommentEvent event) {
resetTimer();
doEditComment(event.getOwner(), event.getCommentInstance());
}
});
@ -152,7 +134,6 @@ public class NewsFeedPanel extends Composite {
eventBus.addHandler(SeeLikesEvent.TYPE, new SeeLikesEventHandler() {
@Override
public void onSeeLikes(SeeLikesEvent event) {
resetTimer();
doShowLikes(event.getFeedId());
}
});
@ -160,7 +141,6 @@ public class NewsFeedPanel extends Composite {
eventBus.addHandler(SeeCommentsEvent.TYPE, new SeeCommentsEventHandler() {
@Override
public void onSeeComments(SeeCommentsEvent event) {
resetTimer();
doShowComments(event.getOwner(), event.isCommentForm2Add());
}
});
@ -168,7 +148,6 @@ public class NewsFeedPanel extends Composite {
eventBus.addHandler(DeleteCommentEvent.TYPE, new DeleteCommentEventHandler() {
@Override
public void onDeleteComment(DeleteCommentEvent event) {
resetTimer();
doDeleteComment(event.getOwner(), event.getCommentId());
}
});
@ -176,7 +155,6 @@ public class NewsFeedPanel extends Composite {
eventBus.addHandler(DeleteFeedEvent.TYPE, new DeleteFeedEventHandler() {
@Override
public void onDeleteFeed(DeleteFeedEvent event) {
resetTimer();
doDeleteFeed(event.getToDelete());
}
});
@ -189,7 +167,9 @@ public class NewsFeedPanel extends Composite {
*/
public NewsFeedPanel() {
bind();
mainPanel.setWidth("600px");
mainPanel.add(filterPanel);
filterPanel.setVisible(false);
mainPanel.add(newUpdatesPanel);
mainPanel.add(newsPanel);
@ -211,7 +191,7 @@ public class NewsFeedPanel extends Composite {
@Override
public void onSuccess(UserSettings result) {
myUserInfo = result.getUserInfo();
delayMillis = result.getRefreshingTimeInMillis();
delayMillis = result.getRefreshingTimeInMillis();
if (result.getUserInfo().getUsername().equals("test.user")) {
Window.alert("Your session has expired, please log out and login again");
}
@ -219,6 +199,12 @@ public class NewsFeedPanel extends Composite {
showAllUpdatesFeeds();
currentFilter = FilterType.ALL_UPDATES;
}
//adjustments in the UI Depending on the scope
if (result.isInfrastructure())
filterPanel.setVisible(true);
else
mainPanel.addStyleName("framed");
}
});
@ -231,13 +217,6 @@ public class NewsFeedPanel extends Composite {
feedsTimer.scheduleRepeating(delayMillis);
}
private void resetTimer() {
feedsTimer.cancel();
feedsTimer.scheduleRepeating(delayMillis);
}
private void stopTimer() {
feedsTimer.cancel();
}
/**
*
*/
@ -265,20 +244,20 @@ public class NewsFeedPanel extends Composite {
Date myLastUpdateTime = allUpdates.get(0).getFeed().getTime(); //this is the last update in the View
GWT.log("Last Mine: "+allUpdates.get(0).getFeed().getDescription());
GWT.log("Last Retr.: "+feeds.get(0).getFeed().getDescription());
tempCacheNewUpdates = new ArrayList<EnhancedFeed>(); //need to clear it everytime i check (in case someone deleted the updated in the meanwhile)
//check if there are new updates (enter the while) and put them in a temporary cache for displaying on user click
int i = 0;
while (i < feeds.size() && feeds.get(i).getFeed().getTime().after(myLastUpdateTime)) {
tempCacheNewUpdates.add(feeds.get(i));
i++;
}
/* currNewUpdatesNo keeps the number of updates to be added on user clicks,
* i keeps the total number as it arrives,
* if they differ you got to refresh the updates to show the new number
@ -308,7 +287,7 @@ public class NewsFeedPanel extends Composite {
newUpdatesPanel.clear(); //remove the alert panel
newsFeedAlert = null; //reset the alert panel and other needed vars
currNewUpdatesNo = 0;
//need to put them in reverse order;
for (int i = tempCacheNewUpdates.size(); i > 0; i--) {
EnhancedFeed feed = tempCacheNewUpdates.get(i-1);
@ -328,7 +307,7 @@ public class NewsFeedPanel extends Composite {
String currTitle = Document.get().getTitle();
Document.get().setTitle(currTitle.startsWith("(") ? currTitle.substring(4) : currTitle);
}
/**
* used when addin directly a feed from the UI (IPC)
* @param userid
@ -359,7 +338,7 @@ public class NewsFeedPanel extends Composite {
};
t.schedule(500);
//insert it also in the model so that the user who created it do not get notified about this new update
allUpdates.add(0, toAdd); //insert in the model
}
@ -369,7 +348,6 @@ public class NewsFeedPanel extends Composite {
*/
public void showAllUpdatesFeeds() {
showLoader();
resetTimer();
newsService.getAllUpdateUserFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
@ -416,7 +394,6 @@ public class NewsFeedPanel extends Composite {
*/
public void showOnlyConnectionsFeeds() {
showLoader();
resetTimer();
newsService.getOnlyConnectionsUserFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
@ -457,7 +434,6 @@ public class NewsFeedPanel extends Composite {
*/
public void showOnlyMyFeeds() {
showLoader();
resetTimer();
newsService.getOnlyMyUserFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
@ -497,7 +473,6 @@ public class NewsFeedPanel extends Composite {
*/
public void showOnlyLikedFeeds() {
showLoader();
resetTimer();
newsService.getOnlyLikedFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
@ -549,7 +524,6 @@ public class NewsFeedPanel extends Composite {
newsPanel.add(new HTML("<div class=\"nofeed-message\">" +
"Ops! There were problems while retrieving your feeds!. <br> " +
"Looks like we are not able to communicate with the infrastructure,<br> (or your session expired)<br> please try again in a short while or refresh the page.</div>"));
stopTimer();
}
private void doAddLike(final TweetTemplate owner, final String feedId) {

View File

@ -94,14 +94,61 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
_log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL");
user = "test.user";
//user = "massimiliano.assante";
//user = "test.user";
user = "massimiliano.assante";
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
}
else {
withinPortal = true;
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
/**
* this is the first method called by the web app
*/
@Override
public UserSettings getUserSettings() {
if (getUserSettingsFromSession() != null)
return getUserSettingsFromSession();
try {
ASLSession session = getASLSession();
String username = session.getUsername();
String email = username+"@isti.cnr.it";
String fullName = username+" FULL";
String thumbnailURL = "images/Avatar_default.png";
if (withinPortal) {
UserModel user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
fullName = user.getFirstName() + " " + user.getLastName();
email = user.getEmailAddress();
ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
String accountURL = themeDisplay.getURLMyAccount().toString();
UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, false, null);
UserSettings toReturn = new UserSettings(userInfo, getFeedsRefreshTimeInMillis(), session.getScopeName(), isInfrastructureScope());
setUserSettingsInSession(toReturn);
return toReturn;
}
else {
_log.info("Returning test USER");
UserInfo user = new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, null);
return new UserSettings(user, getFeedsRefreshTimeInMillis(), session.getScopeName(), isInfrastructureScope());
}
} catch (Exception e) {
e.printStackTrace();
}
return new UserSettings();
}
/**
* Indicates whether the scope is the whole infrastructure.
* @return <code>true</code> if it is, <code>false</code> otherwise.
*/
private boolean isInfrastructureScope() {
return getASLSession().getScope().isInfrastructure();
}
@Override
public ArrayList<EnhancedFeed> getAllUpdateUserFeeds() {
@ -122,37 +169,50 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
_log.info("****** retrieving feeds for user: " + userName);
User currUser = OrganizationsUtil.validateUser(userName);
//VRE Feeds
for (Organization org : currUser.getOrganizations()) {
GroupManager gm = new LiferayGroupManager();
if (gm.isVRE(org.getOrganizationId()+"")) {
String vreid = gm.getScope(""+org.getOrganizationId()); //get the scope
_log.trace("Reading feeds for VRE: " + vreid);
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, 10);
for (Feed feed : OrganizationFeeds) {
feedsMap.put(feed.getKey(), feed);
/**
* this handles the case where the portlet is deployed outside of VREs (regular)
*/
if (isInfrastructureScope()) {
//VRE Feeds
for (Organization org : currUser.getOrganizations()) {
GroupManager gm = new LiferayGroupManager();
if (gm.isVRE(org.getOrganizationId()+"")) {
String vreid = gm.getScope(""+org.getOrganizationId()); //get the scope
_log.trace("Reading feeds for VRE: " + vreid);
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, 10);
for (Feed feed : OrganizationFeeds) {
feedsMap.put(feed.getKey(), feed);
}
}
}
}
//User Own Feeds
ArrayList<Feed> userFeeds = (ArrayList<Feed>) store.getRecentFeedsByUser(userName, 10);
for (Feed feed : userFeeds) {
feedsMap.put(feed.getKey(), feed);
}
//User Own Feeds
ArrayList<Feed> userFeeds = (ArrayList<Feed>) store.getRecentFeedsByUser(userName, 10);
for (Feed feed : userFeeds) {
feedsMap.put(feed.getKey(), feed);
}
//UserFriends Feeds
ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName);
for (String userid : userFriendsIds) {
for (Feed feed : store.getRecentFeedsByUser(userid, 10)) {
//UserFriends Feeds
ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName);
for (String userid : userFriendsIds) {
for (Feed feed : store.getRecentFeedsByUser(userid, 10)) {
feedsMap.put(feed.getKey(), feed);
}
}
//Portal Feeds
ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds();
for (Feed feed : portalFeeds) {
feedsMap.put(feed.getKey(), feed);
}
}
//Portal Feeds
ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds();
for (Feed feed : portalFeeds) {
feedsMap.put(feed.getKey(), feed);
//else must be in a VRE scope
else {
String vreid = getASLSession().getScopeName();
_log.trace("News Feed in VRE, Reading feeds for VRE: " + vreid);
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, 30);
for (Feed feed : OrganizationFeeds) {
feedsMap.put(feed.getKey(), feed);
}
}
for (String key: feedsMap.keySet()) {
@ -377,7 +437,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
return edited;
}
private String replaceAmpersand(String toReplace) {
String toReturn = toReplace.replaceAll("&amp;", "&");
return toReturn;
@ -472,40 +532,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
@Override
public UserSettings getUserSettings() {
if (getUserSettingsFromSession() != null)
return getUserSettingsFromSession();
try {
String username = getASLSession().getUsername();
String email = username+"@isti.cnr.it";
String fullName = username+" FULL";
String thumbnailURL = "images/Avatar_default.png";
if (withinPortal) {
UserModel user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
fullName = user.getFirstName() + " " + user.getLastName();
email = user.getEmailAddress();
ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
String accountURL = themeDisplay.getURLMyAccount().toString();
UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, false, null);
UserSettings toReturn = new UserSettings(userInfo, getFeedsRefreshTimeInMillis());
setUserSettingsInSession(toReturn);
return toReturn;
}
else {
_log.info("Returning test USER");
UserInfo user = new UserInfo(getASLSession().getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, null);
return new UserSettings(user, getFeedsRefreshTimeInMillis());
}
} catch (Exception e) {
e.printStackTrace();
}
return new UserSettings();
}
@Override
public ArrayList<Like> getAllLikesByFeed(String feedid) {
@ -578,7 +605,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;")
.replaceAll(">", "&gt;");
}
/**
*
* @return true if the user is a portal administrator or not
@ -704,6 +731,6 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return toReturn;
}
else
return 30000; //30 secs for testing
return 60000; //60 secs for testing
}
}

View File

@ -8,14 +8,18 @@ import org.gcube.portal.databook.shared.UserInfo;
public class UserSettings implements Serializable {
private UserInfo userInfo;
private int refreshingTimeInMillis;
public UserSettings() {
private String currentScope;
boolean isInfrastructure;
public UserSettings() {
super();
// TODO Auto-generated constructor stub
}
public UserSettings(UserInfo userInfo, int refreshingTimeInMillis) {
public UserSettings(UserInfo userInfo, int refreshingTimeInMillis,
String currentScope, boolean isInfrastructure) {
super();
this.userInfo = userInfo;
this.refreshingTimeInMillis = refreshingTimeInMillis;
this.currentScope = currentScope;
this.isInfrastructure = isInfrastructure;
}
public UserInfo getUserInfo() {
return userInfo;
@ -29,9 +33,24 @@ public class UserSettings implements Serializable {
public void setRefreshingTimeInMillis(int refreshingTimeInMillis) {
this.refreshingTimeInMillis = refreshingTimeInMillis;
}
public String getCurrentScope() {
return currentScope;
}
public void setCurrentScope(String currentScope) {
this.currentScope = currentScope;
}
public boolean isInfrastructure() {
return isInfrastructure;
}
public void setInfrastructure(boolean isInfrastructure) {
this.isInfrastructure = isInfrastructure;
}
@Override
public String toString() {
return "UserSettings [userInfo=" + userInfo
+ ", refreshingTimeInMillis=" + refreshingTimeInMillis + "]";
+ ", refreshingTimeInMillis=" + refreshingTimeInMillis
+ ", currentScope=" + currentScope + ", isInfrastructure="
+ isInfrastructure + "]";
}
}

View File

@ -5,6 +5,20 @@ table {
border-spacing: 0;
}
.framed {
margin: 0 0 10px;
padding: 10px;
margin: 0px 5px;
background: #FFF url(images/vre_bg_gray.png) repeat-x left bottom;
border-radius: 6px !important;
-moz-border-radius: 6px !important;
-webkit-border-radius: 6px !important;
border: 1px solid #DBDBDB;
}
.new-feeds-container {
position: relative;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB