2015-12-09 14:34:41 +01:00
|
|
|
package org.gcube.portlet.user.userstatisticsportlet.client;
|
|
|
|
|
2016-01-26 10:40:46 +01:00
|
|
|
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapter;
|
|
|
|
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapterException;
|
|
|
|
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusEvent;
|
|
|
|
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusListener;
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
import org.gcube.portal.databook.client.GCubeSocialNetworking;
|
|
|
|
import org.gcube.portal.databook.client.util.Encoder;
|
2015-12-09 14:34:41 +01:00
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.client.resources.Images;
|
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.client.ui.CommentsAndLikesWidget;
|
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.client.ui.StatisticWidget;
|
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.shared.PostsStatsBean;
|
|
|
|
import org.gcube.portlet.user.userstatisticsportlet.shared.UserInformation;
|
2016-05-20 15:12:01 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
2016-04-11 11:41:33 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
2016-05-10 18:40:55 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.CheckBox;
|
2016-05-20 15:12:01 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
2016-04-11 11:41:33 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
2015-12-09 14:34:41 +01:00
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2016-05-10 18:40:55 +02:00
|
|
|
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
|
|
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
2015-12-09 14:34:41 +01:00
|
|
|
import com.google.gwt.i18n.client.NumberFormat;
|
|
|
|
import com.google.gwt.user.client.Window;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
import com.google.gwt.user.client.ui.FlowPanel;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
|
|
import com.google.gwt.user.client.ui.Image;
|
|
|
|
import com.google.gwt.user.client.ui.Label;
|
|
|
|
/**
|
|
|
|
* Panel to show received user's statistics
|
|
|
|
*
|
|
|
|
* @author Costantino Perciante at ISTI-CNR
|
|
|
|
*/
|
|
|
|
public class StatisticsPanel extends Composite {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a remote service proxy to talk to the server-side statistics service.
|
|
|
|
*/
|
|
|
|
private final UserStatisticsServiceAsync statisticsService = GWT.create(UserStatisticsService.class);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Path of the image to be shown during loading
|
|
|
|
*/
|
|
|
|
public static final String imagePath = GWT.getModuleBaseURL() + "../images/statistics-loader.gif";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* alert icon to be show if some statistic is not available
|
|
|
|
*/
|
|
|
|
public static final String alertIconPath = GWT.getModuleBaseURL() + "../images/icon-alert.png";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tooltip for the above image
|
|
|
|
*/
|
|
|
|
private static final String ALERT_MESSAGE = "Information not available at the moment.";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*/
|
|
|
|
public static final String DISPLAY_NAME = "Your Stats ";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Labels
|
|
|
|
*/
|
|
|
|
private final static String POSTS_LABEL = "Posts";
|
2016-05-23 17:45:17 +02:00
|
|
|
private final static String STORAGE_LABEL = "Space Used";
|
2016-05-10 18:40:55 +02:00
|
|
|
private final static String LIKES_COMMENTS_LABEL = "Got";
|
2015-12-09 14:34:41 +01:00
|
|
|
private final static String PROFILE_STRENGTH_LABEL = "Profile Strength";
|
|
|
|
|
|
|
|
/**
|
2016-05-20 15:12:01 +02:00
|
|
|
* improve profile hints
|
2015-12-09 14:34:41 +01:00
|
|
|
*/
|
2016-05-20 15:12:01 +02:00
|
|
|
public static String IMPROVE_PROFILE_HINT_MESSAGE_ROOT = "You can improve your profile strength by: <ul>"
|
|
|
|
+ "<li> adding a job title, your current position or your professional summary;"
|
|
|
|
+ "<li> adding your contact information (facebook, linkedin, skype, google mail and so on).</ul>";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* improve profile hints
|
|
|
|
*/
|
|
|
|
public static final String IMPROVE_PROFILE_HINT_MESSAGE_PROFILE = "You can improve your profile strength by: <ul>"
|
|
|
|
+ "<li> adding a job title, your current position or your professional summary;"
|
|
|
|
+ "<li> adding your contact information (facebook, linkedin, skype, google mail and so on).</ul>";
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* profile button label
|
|
|
|
*/
|
|
|
|
private final static String IMPROVE_BUTTON_LABEL = "Improve";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* threshold for improving profile button
|
|
|
|
*/
|
|
|
|
private final static int profileImproveThreshold = 50;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Information about the context of the running portlet
|
|
|
|
*/
|
|
|
|
private boolean isRoot;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Image to be shown during loading
|
|
|
|
*/
|
|
|
|
private Image loadingImage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FlowPanel to contain the statistics
|
|
|
|
*/
|
|
|
|
private FlowPanel mainPanel = new FlowPanel();
|
|
|
|
|
2016-01-26 10:40:46 +01:00
|
|
|
/**
|
|
|
|
* Since the number of feeds(posts) can be manipulated when the user posts, we need a class reference
|
|
|
|
*/
|
|
|
|
private Label numberOfFeedsLabel;
|
|
|
|
|
|
|
|
/**
|
2016-01-26 18:27:19 +01:00
|
|
|
* Since the number of likes/comments got can be manipulated, we need a class reference
|
2016-01-26 10:40:46 +01:00
|
|
|
*/
|
2016-01-26 18:27:19 +01:00
|
|
|
private CommentsAndLikesWidget content;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of written posts
|
|
|
|
*/
|
|
|
|
private long numberOfWrittenFeeds;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of likes got
|
|
|
|
*/
|
|
|
|
private long numberOfLikesGot;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of likes got
|
|
|
|
*/
|
|
|
|
private long numberOfCommentsGot;
|
2016-01-26 10:40:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pagebus to listen for events (coming from the news feed portlet)
|
|
|
|
*/
|
|
|
|
final public static PageBusAdapter pageBusAdapter = new PageBusAdapter();
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
public StatisticsPanel() {
|
|
|
|
|
|
|
|
//init this object
|
|
|
|
super();
|
|
|
|
initWidget(mainPanel);
|
|
|
|
|
2016-01-26 10:40:46 +01:00
|
|
|
// bind pagebus events
|
2016-01-26 18:27:19 +01:00
|
|
|
bind();
|
2016-01-26 10:40:46 +01:00
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
// set style of the main panel
|
|
|
|
mainPanel.setStyleName("user-stats-frame");
|
|
|
|
|
|
|
|
//init image loader
|
|
|
|
loadingImage = new Image(imagePath);
|
|
|
|
loadingImage.setStyleName("loading-image-center");
|
|
|
|
|
|
|
|
//show loader, waiting for the answer coming by the server
|
|
|
|
showLoader();
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
// does the profile belong to someone? (when we are on a profile page of someone other, we need
|
|
|
|
// to retrieve the statistics of that person)
|
|
|
|
final String userid = getUserToShowId();
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
// request user's information
|
2016-05-10 18:40:55 +02:00
|
|
|
statisticsService.getUserSettings(userid, new AsyncCallback<UserInformation>() {
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable arg0) {
|
|
|
|
|
|
|
|
showError();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-10 18:40:55 +02:00
|
|
|
public void onSuccess(final UserInformation information) {
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
// remove loading image
|
|
|
|
mainPanel.remove(loadingImage);
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
// first of all check if the statistics can be shown to other people
|
|
|
|
if(userid != null && !userid.equals(information.getAslSessionUsername()) && !information.isProfileShowable()){
|
|
|
|
|
|
|
|
mainPanel.add(new HTML("Sorry but the user set his Statistics to private."));
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// is a user profile page?
|
|
|
|
final boolean isProfilePage =
|
|
|
|
Window.Location.getHref().endsWith("profile")
|
|
|
|
|| Window.Location.getHref().contains("profile?");
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
// check which kind of information we have to show
|
|
|
|
isRoot = information.isRoot();
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
if(!isRoot && !isProfilePage){
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2016-01-22 10:56:03 +01:00
|
|
|
// add the border to the panel and the VRE name (check for VRE name lenght)
|
2015-12-09 14:34:41 +01:00
|
|
|
mainPanel.addStyleName("user-stats-frame-border");
|
2016-01-22 10:56:03 +01:00
|
|
|
String nameToShow = DISPLAY_NAME + " in " + information.getActualVre();
|
2016-01-26 10:40:46 +01:00
|
|
|
|
2016-01-22 10:56:03 +01:00
|
|
|
final HTML name = new HTML(nameToShow);
|
|
|
|
name.setTitle(DISPLAY_NAME + " in " + information.getActualVre());
|
2015-12-09 14:34:41 +01:00
|
|
|
name.setStyleName("user-stats-title");
|
2016-04-04 10:17:42 +02:00
|
|
|
mainPanel.add(name);
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-20 15:12:01 +02:00
|
|
|
// save page landing
|
|
|
|
if(information.getCurrentPageLanding() != null)
|
|
|
|
IMPROVE_PROFILE_HINT_MESSAGE_ROOT += "<a href='" + information.getCurrentPageLanding() + "/profile" + "'><b>Go to your profile</b></a>";
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
// user image
|
|
|
|
Images image = GWT.create(Images.class);
|
|
|
|
Image userImage = new Image(image.avatarLoader());
|
|
|
|
|
|
|
|
// check if the user has an avatar
|
|
|
|
if(information.getUrlAvatar() == null)
|
|
|
|
userImage.setResource(image.avatarDefaultImage());
|
2016-05-10 18:40:55 +02:00
|
|
|
else{
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
userImage.setUrl(information.getUrlAvatar());
|
2016-05-11 19:58:47 +02:00
|
|
|
if(userid != null && !userid.equals(information.getAslSessionUsername()))
|
2016-05-10 18:40:55 +02:00
|
|
|
userImage.setTitle("User's avatar");
|
|
|
|
else
|
|
|
|
userImage.setTitle("Your current avatar");
|
|
|
|
}
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
// set the style for the user image
|
|
|
|
userImage.setStyleName("user-image");
|
2016-01-22 10:56:03 +01:00
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
// add image to mainPanel
|
|
|
|
mainPanel.add(userImage);
|
|
|
|
|
|
|
|
// feeds
|
2016-01-07 16:48:36 +01:00
|
|
|
final StatisticWidget feeds = new StatisticWidget(isRoot);
|
2015-12-09 14:34:41 +01:00
|
|
|
feeds.setHeader(POSTS_LABEL);
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
if(isRoot || isProfilePage)
|
|
|
|
feeds.setToolTip("Posts during the last year.");
|
2015-12-09 14:34:41 +01:00
|
|
|
else
|
2016-05-10 18:40:55 +02:00
|
|
|
feeds.setToolTip("Posts during the last year in this VRE.");
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
// add loading image that will be replaced by the incoming values
|
|
|
|
Image postsLoader = new Image(imagePath);
|
|
|
|
postsLoader.setStyleName("loading-image-center-small");
|
|
|
|
feeds.appendToPanel(postsLoader);
|
|
|
|
|
|
|
|
// append widget
|
|
|
|
mainPanel.add(feeds);
|
|
|
|
|
|
|
|
// likes & comments
|
2016-01-07 16:48:36 +01:00
|
|
|
final StatisticWidget likesAndComments = new StatisticWidget(isRoot);
|
2015-12-09 14:34:41 +01:00
|
|
|
likesAndComments.setHeader(LIKES_COMMENTS_LABEL);
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
if(isRoot || isProfilePage)
|
|
|
|
likesAndComments.setToolTip("Likes and post replies got during the last year.");
|
2015-12-09 14:34:41 +01:00
|
|
|
else
|
2016-05-10 18:40:55 +02:00
|
|
|
likesAndComments.setToolTip("Likes and post replies got during the last year in this VRE.");
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
// add loading image that will be replaced by the incoming values
|
|
|
|
Image commentsLikesLoader = new Image(imagePath);
|
|
|
|
commentsLikesLoader.setStyleName("loading-image-center-small");
|
|
|
|
likesAndComments.appendToPanel(commentsLikesLoader);
|
|
|
|
|
|
|
|
// append widget
|
|
|
|
mainPanel.add(likesAndComments);
|
|
|
|
|
|
|
|
// the storage and the profile strength(only in root)
|
2016-01-07 16:48:36 +01:00
|
|
|
final StatisticWidget storage = new StatisticWidget(isRoot);
|
|
|
|
final StatisticWidget profileStrength = new StatisticWidget(isRoot);
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
if(isRoot || isProfilePage){
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
storage.setHeader(STORAGE_LABEL);
|
|
|
|
storage.setToolTip("Total amount of space used in the infrastructure.");
|
|
|
|
|
|
|
|
// add loading image that will be replaced by the incoming values
|
|
|
|
Image totalSpaceLoader = new Image(imagePath);
|
|
|
|
totalSpaceLoader.setStyleName("loading-image-center-small");
|
|
|
|
storage.appendToPanel(totalSpaceLoader);
|
|
|
|
|
|
|
|
mainPanel.add(storage);
|
|
|
|
|
|
|
|
profileStrength.setHeader(PROFILE_STRENGTH_LABEL);
|
2016-05-10 18:40:55 +02:00
|
|
|
profileStrength.setToolTip("Profile strength.");
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
// add loading image that will be replaced by the incoming values
|
|
|
|
Image profileStrengthLoader = new Image(imagePath);
|
|
|
|
profileStrengthLoader.setStyleName("loading-image-center-small");
|
|
|
|
profileStrength.appendToPanel(profileStrengthLoader);
|
|
|
|
|
|
|
|
// add to the panel
|
|
|
|
mainPanel.add(profileStrength);
|
|
|
|
|
|
|
|
// async requests that must be performed in root context
|
2016-05-10 18:40:55 +02:00
|
|
|
statisticsService.getTotalSpaceInUse(userid, new AsyncCallback<String>() {
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable arg0) {
|
|
|
|
|
|
|
|
appendAlertIcon(storage);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String spaceInUse) {
|
|
|
|
|
|
|
|
if(spaceInUse == null){
|
|
|
|
appendAlertIcon(storage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
storage.clearPanelValues();
|
|
|
|
Label storageValue = new Label(spaceInUse);
|
|
|
|
storageValue.setStyleName("statistic-value");
|
|
|
|
storage.appendToPanel(storageValue);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
statisticsService.getProfileStrength(userid, new AsyncCallback<Integer>() {
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable arg0) {
|
|
|
|
|
|
|
|
appendAlertIcon(profileStrength);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Integer profileStrengthInt) {
|
|
|
|
|
|
|
|
if(profileStrengthInt < 0){
|
|
|
|
|
|
|
|
appendAlertIcon(profileStrength);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear panel
|
|
|
|
profileStrength.clearPanelValues();
|
|
|
|
final Label profileStrengthLabel = new Label(profileStrengthInt + "%");
|
|
|
|
profileStrengthLabel.setStyleName("statistic-value");
|
|
|
|
|
|
|
|
profileStrength.appendToPanel(profileStrengthLabel);
|
|
|
|
|
|
|
|
// in case too low information within the user profile
|
2016-05-10 18:40:55 +02:00
|
|
|
if(profileStrengthInt < profileImproveThreshold && information.isOwner()){
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2016-05-20 15:12:01 +02:00
|
|
|
// Show an alert block in which underline how he can improve the profile
|
|
|
|
final AlertBlock improveProfileHint = new AlertBlock();
|
|
|
|
improveProfileHint.setType(AlertType.INFO);
|
|
|
|
improveProfileHint.addStyleName("improve-profile-hint-message");
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
final Button improveProfileButton = new Button(IMPROVE_BUTTON_LABEL);
|
2016-05-20 15:12:01 +02:00
|
|
|
improveProfileButton.setType(ButtonType.INFO);
|
2015-12-09 14:34:41 +01:00
|
|
|
improveProfileButton.setTitle("Improve your profile.");
|
|
|
|
|
|
|
|
improveProfileButton.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent arg0) {
|
|
|
|
|
2016-05-20 15:12:01 +02:00
|
|
|
// set text according current url
|
|
|
|
if(isProfilePage)
|
|
|
|
improveProfileHint.setHTML(IMPROVE_PROFILE_HINT_MESSAGE_PROFILE);
|
|
|
|
else
|
|
|
|
improveProfileHint.setHTML(IMPROVE_PROFILE_HINT_MESSAGE_ROOT);
|
|
|
|
mainPanel.add(improveProfileHint);
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
profileStrengthLabel.setStyleName("statistic-value-inline");
|
2016-04-11 11:41:33 +02:00
|
|
|
improveProfileButton.addStyleName("button-improve-profile");
|
2015-12-09 14:34:41 +01:00
|
|
|
profileStrength.appendToPanel(improveProfileButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// retrieve othe information about number of feeds and post replies/likes
|
2016-05-10 18:40:55 +02:00
|
|
|
statisticsService.getPostsStats(userid, new AsyncCallback<PostsStatsBean>(){
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
public void onFailure(Throwable arg0) {
|
|
|
|
|
|
|
|
appendAlertIcon(feeds);
|
|
|
|
appendAlertIcon(likesAndComments);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onSuccess(PostsStatsBean postsBean) {
|
|
|
|
|
|
|
|
// if there are no statistics
|
|
|
|
if(postsBean == null){
|
|
|
|
|
|
|
|
appendAlertIcon(feeds);
|
|
|
|
appendAlertIcon(likesAndComments);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// update feeds number
|
|
|
|
feeds.clearPanelValues();
|
2016-01-26 10:40:46 +01:00
|
|
|
numberOfFeedsLabel = new Label(formattedNumbers(postsBean.getFeedsNumber()));
|
2016-05-10 18:40:55 +02:00
|
|
|
if(isRoot || isProfilePage)
|
|
|
|
numberOfFeedsLabel.setTitle("Posts during the last year (" + postsBean.getFeedsNumber() + ").");
|
2015-12-09 14:34:41 +01:00
|
|
|
else
|
2016-05-10 18:40:55 +02:00
|
|
|
numberOfFeedsLabel.setTitle("Posts during the last year in this VRE (" + postsBean.getFeedsNumber() + ").");
|
2016-01-26 10:40:46 +01:00
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
numberOfWrittenFeeds = postsBean.getFeedsNumber();
|
2015-12-09 14:34:41 +01:00
|
|
|
numberOfFeedsLabel.setStyleName("statistic-value");
|
|
|
|
feeds.appendToPanel(numberOfFeedsLabel);
|
|
|
|
|
|
|
|
// updates comments and likes
|
|
|
|
likesAndComments.clearPanelValues();
|
2016-01-26 18:27:19 +01:00
|
|
|
content = new CommentsAndLikesWidget();
|
2015-12-09 14:34:41 +01:00
|
|
|
|
|
|
|
String urlLikesIcon = GWT.getModuleBaseURL() + "../images/star_blue.png";
|
2016-05-10 18:40:55 +02:00
|
|
|
if(isRoot || isProfilePage)
|
2015-12-09 14:34:41 +01:00
|
|
|
content.setLikes(
|
|
|
|
urlLikesIcon,
|
|
|
|
formattedNumbers(postsBean.getLikesReceived()),
|
2016-05-10 18:40:55 +02:00
|
|
|
"Likes got during the last year.",
|
|
|
|
"Likes got during the last year (" + postsBean.getLikesReceived() + ").");
|
2015-12-09 14:34:41 +01:00
|
|
|
else
|
|
|
|
content.setLikes(
|
|
|
|
urlLikesIcon,
|
|
|
|
formattedNumbers(postsBean.getLikesReceived()),
|
2016-05-10 18:40:55 +02:00
|
|
|
"Likes got during the last year in this VRE",
|
|
|
|
"Likes got during the last year in this VRE (" + postsBean.getLikesReceived() + ").");
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
numberOfLikesGot = postsBean.getLikesReceived();
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
String urlCommentsIcon = GWT.getModuleBaseURL() + "../images/comment_edit.png";
|
2016-05-10 18:40:55 +02:00
|
|
|
if(isRoot || isProfilePage)
|
2015-12-09 14:34:41 +01:00
|
|
|
content.setComments(
|
|
|
|
urlCommentsIcon,
|
|
|
|
formattedNumbers(postsBean.getCommentsReceived()),
|
2016-05-10 18:40:55 +02:00
|
|
|
"Post replies got during the last year.",
|
|
|
|
"Post replies got during the last year (" + postsBean.getCommentsReceived() + ").");
|
2015-12-09 14:34:41 +01:00
|
|
|
else
|
|
|
|
content.setComments(
|
|
|
|
urlCommentsIcon,
|
|
|
|
formattedNumbers(postsBean.getCommentsReceived()),
|
2016-05-10 18:40:55 +02:00
|
|
|
"Post replies got during the last year in this VRE.",
|
|
|
|
"Post replies got during the last year in this VRE (" + postsBean.getCommentsReceived() + ").");
|
2015-12-09 14:34:41 +01:00
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
numberOfCommentsGot = postsBean.getCommentsReceived();
|
2015-12-09 14:34:41 +01:00
|
|
|
likesAndComments.appendToPanel(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-05-10 18:40:55 +02:00
|
|
|
|
|
|
|
// check if we need to show the checkbox to allow the user's profile owner to edit privacy options
|
|
|
|
if(information.isOwner() && (isProfilePage)){
|
|
|
|
|
|
|
|
// add a checkbox with the settable privacy option
|
|
|
|
CheckBox privacyOption = new CheckBox("Show my statistics to VRE Members");
|
|
|
|
privacyOption.setTitle("Show Statistics to members viewing your profile");
|
|
|
|
privacyOption.setValue(information.isProfileShowable());
|
|
|
|
privacyOption.addStyleName("privacy-checkbox-statistics-style");
|
|
|
|
|
|
|
|
privacyOption.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onValueChange(ValueChangeEvent<Boolean> event) {
|
|
|
|
|
|
|
|
// set this privacy option
|
|
|
|
statisticsService.setShowMyOwnStatisticsToOtherPeople(event.getValue(), new AsyncCallback<Void>(){
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Void result) {
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mainPanel.add(privacyOption);
|
|
|
|
}
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-05-10 18:40:55 +02:00
|
|
|
|
2016-01-26 10:40:46 +01:00
|
|
|
/**
|
|
|
|
* Bind for events of increment/decrement of user's posts coming from the news-feed portlet
|
|
|
|
*/
|
|
|
|
private void bind() {
|
|
|
|
|
|
|
|
try {
|
2016-01-26 18:27:19 +01:00
|
|
|
// increment post number
|
2016-01-27 09:18:48 +01:00
|
|
|
pageBusAdapter.PageBusSubscribe(PageBusEvents.postIncrement, null, null, null, null);
|
2016-01-26 10:40:46 +01:00
|
|
|
|
|
|
|
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
2016-01-27 09:18:48 +01:00
|
|
|
return PageBusEvents.postIncrement;
|
2016-01-26 10:40:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageBusSubscriptionCallback(PageBusEvent event) {
|
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
if(event.getSubject().equals(this.getName())){
|
2016-01-26 10:40:46 +01:00
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
GWT.log("Increment number of post message received");
|
2016-01-26 10:40:46 +01:00
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
numberOfWrittenFeeds ++;
|
|
|
|
numberOfFeedsLabel.setText(formattedNumbers(numberOfWrittenFeeds));
|
|
|
|
if(isRoot)
|
|
|
|
numberOfFeedsLabel.setTitle("Your posts during the last year (" + numberOfWrittenFeeds + ").");
|
|
|
|
else
|
|
|
|
numberOfFeedsLabel.setTitle("Your posts during the last year in this VRE (" + numberOfWrittenFeeds + ").");
|
|
|
|
GWT.log("Number of written posts changed to " + numberOfWrittenFeeds);
|
|
|
|
}
|
2016-01-26 10:40:46 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
// decrement post number
|
2016-01-27 09:18:48 +01:00
|
|
|
pageBusAdapter.PageBusSubscribe(PageBusEvents.postDecrement, null, null, null, null);
|
2016-01-26 10:40:46 +01:00
|
|
|
|
|
|
|
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
2016-01-27 09:18:48 +01:00
|
|
|
return PageBusEvents.postDecrement;
|
2016-01-26 10:40:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageBusSubscriptionCallback(PageBusEvent event) {
|
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
if(event.getSubject().equals(this.getName())){
|
|
|
|
GWT.log("Decrement number of post message received");
|
2016-01-26 10:40:46 +01:00
|
|
|
|
2016-01-28 16:52:50 +01:00
|
|
|
// they can't be less than zero...
|
2016-01-26 18:27:19 +01:00
|
|
|
numberOfWrittenFeeds --;
|
2016-01-28 16:52:50 +01:00
|
|
|
numberOfWrittenFeeds = numberOfWrittenFeeds < 0 ? 0: numberOfWrittenFeeds;
|
2016-01-26 18:27:19 +01:00
|
|
|
numberOfFeedsLabel.setText(formattedNumbers(numberOfWrittenFeeds));
|
|
|
|
if(isRoot)
|
|
|
|
numberOfFeedsLabel.setTitle("Your posts during the last year (" + numberOfWrittenFeeds + ").");
|
|
|
|
else
|
|
|
|
numberOfFeedsLabel.setTitle("Your posts during the last year in this VRE (" + numberOfWrittenFeeds + ").");
|
|
|
|
GWT.log("Number of written posts changed to " + numberOfWrittenFeeds);
|
|
|
|
}
|
2016-01-26 10:40:46 +01:00
|
|
|
}});
|
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
// increment likes got number
|
2016-01-27 09:18:48 +01:00
|
|
|
pageBusAdapter.PageBusSubscribe(PageBusEvents.likesIncrement, null, null, null, null);
|
2016-01-26 18:27:19 +01:00
|
|
|
|
|
|
|
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
2016-01-27 09:18:48 +01:00
|
|
|
return PageBusEvents.likesIncrement;
|
2016-01-26 18:27:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageBusSubscriptionCallback(PageBusEvent event) {
|
|
|
|
|
|
|
|
if(event.getSubject().equals(this.getName())){
|
|
|
|
|
|
|
|
GWT.log("Increment number of likes received");
|
|
|
|
|
|
|
|
numberOfLikesGot ++;
|
|
|
|
String urlLikesIcon = GWT.getModuleBaseURL() + "../images/star_blue.png";
|
|
|
|
|
|
|
|
if(isRoot)
|
|
|
|
content.setLikes(
|
|
|
|
urlLikesIcon,
|
|
|
|
formattedNumbers(numberOfLikesGot),
|
|
|
|
"Likes you got during the last year.",
|
|
|
|
"Likes you got during the last year (" + numberOfLikesGot + ").");
|
|
|
|
else
|
|
|
|
content.setLikes(
|
|
|
|
urlLikesIcon,
|
|
|
|
formattedNumbers(numberOfLikesGot),
|
|
|
|
"Likes you got during the last year in this VRE",
|
|
|
|
"Likes you got during the last year in this VRE (" + numberOfLikesGot + ").");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GWT.log("Number of likes got changed to " + numberOfLikesGot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// decrement likes got
|
2016-01-27 09:18:48 +01:00
|
|
|
pageBusAdapter.PageBusSubscribe(PageBusEvents.likesDecrement, null, null, null, null);
|
2016-01-26 18:27:19 +01:00
|
|
|
|
|
|
|
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
2016-01-27 09:18:48 +01:00
|
|
|
return PageBusEvents.likesDecrement;
|
2016-01-26 18:27:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageBusSubscriptionCallback(PageBusEvent event) {
|
|
|
|
|
|
|
|
if(event.getSubject().equals(this.getName())){
|
|
|
|
|
|
|
|
GWT.log("Decrement number of likes received");
|
|
|
|
|
2016-01-28 16:52:50 +01:00
|
|
|
// they can't be less than zero...
|
2016-01-26 18:27:19 +01:00
|
|
|
numberOfLikesGot --;
|
2016-01-28 16:52:50 +01:00
|
|
|
numberOfLikesGot = numberOfLikesGot < 0 ? 0: numberOfLikesGot;
|
2016-01-26 18:27:19 +01:00
|
|
|
String urlLikesIcon = GWT.getModuleBaseURL() + "../images/star_blue.png";
|
|
|
|
|
|
|
|
if(isRoot)
|
|
|
|
content.setLikes(
|
|
|
|
urlLikesIcon,
|
|
|
|
formattedNumbers(numberOfLikesGot),
|
|
|
|
"Likes you got during the last year.",
|
|
|
|
"Likes you got during the last year (" + numberOfLikesGot + ").");
|
|
|
|
else
|
|
|
|
content.setLikes(
|
|
|
|
urlLikesIcon,
|
|
|
|
formattedNumbers(numberOfLikesGot),
|
|
|
|
"Likes you got during the last year in this VRE",
|
|
|
|
"Likes you got during the last year in this VRE (" + numberOfLikesGot + ").");
|
|
|
|
|
|
|
|
GWT.log("Number of likes got changed to " + numberOfLikesGot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// increment comments got number
|
2016-01-27 09:18:48 +01:00
|
|
|
pageBusAdapter.PageBusSubscribe(PageBusEvents.commentsIncrement, null, null, null, null);
|
2016-01-26 18:27:19 +01:00
|
|
|
|
|
|
|
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
2016-01-27 09:18:48 +01:00
|
|
|
return PageBusEvents.commentsIncrement;
|
2016-01-26 18:27:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageBusSubscriptionCallback(PageBusEvent event) {
|
|
|
|
|
|
|
|
if(event.getSubject().equals(this.getName())){
|
|
|
|
|
|
|
|
GWT.log("Increment number of comments received");
|
|
|
|
|
|
|
|
numberOfCommentsGot ++;
|
2016-01-27 09:00:37 +01:00
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
String urlCommentsIcon = GWT.getModuleBaseURL() + "../images/comment_edit.png";
|
2016-01-27 09:00:37 +01:00
|
|
|
|
2016-01-26 18:27:19 +01:00
|
|
|
if(isRoot)
|
|
|
|
content.setComments(
|
|
|
|
urlCommentsIcon,
|
|
|
|
formattedNumbers(numberOfCommentsGot),
|
|
|
|
"Post replies you got during the last year.",
|
|
|
|
"Post replies you got during the last year (" + numberOfCommentsGot + ").");
|
|
|
|
else
|
|
|
|
content.setComments(
|
|
|
|
urlCommentsIcon,
|
|
|
|
formattedNumbers(numberOfCommentsGot),
|
|
|
|
"Post replies you got during the last year in this VRE.",
|
|
|
|
"Post replies you got during the last year in this VRE (" + numberOfCommentsGot + ").");
|
|
|
|
|
|
|
|
GWT.log("Number of comments got changed to " + numberOfCommentsGot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// decrement comments got
|
2016-01-27 09:18:48 +01:00
|
|
|
pageBusAdapter.PageBusSubscribe(PageBusEvents.commentsDecrement, null, null, null, null);
|
2016-01-26 18:27:19 +01:00
|
|
|
|
|
|
|
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
2016-01-27 09:18:48 +01:00
|
|
|
return PageBusEvents.commentsDecrement;
|
2016-01-26 18:27:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageBusSubscriptionCallback(PageBusEvent event) {
|
|
|
|
|
|
|
|
if(event.getSubject().equals(this.getName())){
|
|
|
|
|
|
|
|
GWT.log("Decrement number of comments received");
|
|
|
|
|
2016-01-28 16:52:50 +01:00
|
|
|
// they can't be less than zero...
|
2016-01-26 18:27:19 +01:00
|
|
|
numberOfCommentsGot --;
|
2016-01-28 16:52:50 +01:00
|
|
|
numberOfCommentsGot = numberOfCommentsGot < 0 ? 0: numberOfCommentsGot;
|
2016-01-26 18:27:19 +01:00
|
|
|
String urlCommentsIcon = GWT.getModuleBaseURL() + "../images/comment_edit.png";
|
|
|
|
if(isRoot)
|
|
|
|
content.setComments(
|
|
|
|
urlCommentsIcon,
|
|
|
|
formattedNumbers(numberOfCommentsGot),
|
|
|
|
"Post replies you got during the last year.",
|
|
|
|
"Post replies you got during the last year (" + numberOfCommentsGot + ").");
|
|
|
|
else
|
|
|
|
content.setComments(
|
|
|
|
urlCommentsIcon,
|
|
|
|
formattedNumbers(numberOfCommentsGot),
|
|
|
|
"Post replies you got during the last year in this VRE.",
|
|
|
|
"Post replies you got during the last year in this VRE (" + numberOfCommentsGot + ").");
|
|
|
|
|
|
|
|
GWT.log("Number of comments got changed to " + numberOfCommentsGot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
GWT.log("Subscriptions ok");
|
|
|
|
|
2016-01-26 10:40:46 +01:00
|
|
|
} catch (PageBusAdapterException e) {
|
2016-01-26 18:27:19 +01:00
|
|
|
GWT.log(e.toString());
|
2016-01-26 10:40:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-09 14:34:41 +01:00
|
|
|
/**
|
|
|
|
* Show loading image
|
|
|
|
*/
|
|
|
|
private void showLoader() {
|
|
|
|
mainPanel.clear();
|
|
|
|
mainPanel.add(loadingImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Error when is not possible to receive data or the received data is null
|
|
|
|
*/
|
|
|
|
private void showError() {
|
|
|
|
mainPanel.clear();
|
|
|
|
HTML messageError = new HTML(
|
|
|
|
"Sorry but it is not possible to retrieve your statistics at the moment. Retry later."
|
|
|
|
);
|
|
|
|
messageError.setStyleName("error-msg");
|
|
|
|
mainPanel.add(messageError);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add alert icon/message for this statistic
|
|
|
|
* @param w
|
|
|
|
*/
|
|
|
|
private void appendAlertIcon(StatisticWidget w) {
|
|
|
|
|
|
|
|
w.clearPanelValues();
|
|
|
|
Image alert = new Image(alertIconPath);
|
|
|
|
alert.setTitle(ALERT_MESSAGE);
|
|
|
|
alert.setStyleName("alert-icon-center");
|
|
|
|
w.appendToPanel(alert);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format a given value and append k, M, G
|
|
|
|
* @param value
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private String formattedNumbers(long value){
|
|
|
|
|
|
|
|
String formattedString = null;
|
|
|
|
|
|
|
|
double v = value;
|
|
|
|
double k = (double)value/1000.0;
|
|
|
|
double m = (double)value/1_000_000.0;
|
|
|
|
double g = (double)value/1_000_000_000.0;
|
|
|
|
|
|
|
|
NumberFormat dec = NumberFormat.getFormat("###.###");
|
|
|
|
|
|
|
|
if ( g >= 1.0 ) {
|
|
|
|
formattedString = dec.format(g).concat("G");
|
|
|
|
} else if ( m >= 1.0 ) {
|
|
|
|
formattedString = dec.format(m).concat("M");
|
|
|
|
} else if ( k >= 1.0 ) {
|
|
|
|
formattedString = dec.format(k).concat("K");
|
|
|
|
} else {
|
|
|
|
formattedString = dec.format(v).concat("");
|
|
|
|
}
|
|
|
|
|
|
|
|
return formattedString;
|
|
|
|
}
|
2016-05-10 18:40:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* decode the userid from the location param
|
|
|
|
* @return the decoded (base64) userid
|
|
|
|
*/
|
|
|
|
public static String getUserToShowId() {
|
|
|
|
String encodedOid = Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID);
|
|
|
|
if (Window.Location.getParameter(encodedOid) == null)
|
|
|
|
return null;
|
|
|
|
String encodedUserId = Window.Location.getParameter(encodedOid);
|
|
|
|
return Encoder.decode(encodedUserId);
|
|
|
|
}
|
2015-12-09 14:34:41 +01:00
|
|
|
}
|