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 ;
2016-08-03 16:26:49 +02:00
import org.gcube.portal.databook.shared.ShowUserStatisticAction ;
import org.gcube.portlet.user.userstatisticsportlet.client.events.PageBusEvents ;
import org.gcube.portlet.user.userstatisticsportlet.client.events.ShowFeedsRelatedToUserStatisticsEvent ;
import org.gcube.portlet.user.userstatisticsportlet.client.events.ShowFeedsRelatedToUserStatisticsEventHandler ;
2015-12-09 14:34:41 +01:00
import org.gcube.portlet.user.userstatisticsportlet.client.resources.Images ;
2016-08-31 10:45:58 +02:00
import org.gcube.portlet.user.userstatisticsportlet.client.ui.ActivityWidget ;
2015-12-09 14:34:41 +01:00
import org.gcube.portlet.user.userstatisticsportlet.client.ui.StatisticWidget ;
import org.gcube.portlet.user.userstatisticsportlet.shared.PostsStatsBean ;
2017-02-12 21:14:11 +01:00
import org.gcube.portlet.user.userstatisticsportlet.shared.QuotaInfo ;
2015-12-09 14:34:41 +01:00
import org.gcube.portlet.user.userstatisticsportlet.shared.UserInformation ;
2016-07-19 15:10:45 +02:00
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 ;
2016-09-29 11:07:12 +02:00
import com.github.gwtbootstrap.client.ui.constants.IconType ;
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 ;
2016-08-03 16:26:49 +02:00
import com.google.gwt.event.shared.HandlerManager ;
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 ;
/ * *
* 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 " ;
/ * *
* tooltip for the above image
* /
2016-09-27 11:16:04 +02:00
private static final String ALERT_MESSAGE = " Information not available at the moment " ;
2015-12-09 14:34:41 +01:00
/ * *
* Title of the page
* /
public static final String DISPLAY_NAME = " Your Stats " ;
/ * *
* Labels
* /
2016-08-31 10:45:58 +02:00
private final static String ACTIVITY_LABEL = " Activity " ;
private final static String LIKES_COMMENTS_GOT_LABEL = " Got " ;
2016-05-23 17:45:17 +02:00
private final static String STORAGE_LABEL = " Space Used " ;
2015-12-09 14:34:41 +01:00
private final static String PROFILE_STRENGTH_LABEL = " Profile Strength " ;
2016-08-30 15:36:19 +02:00
private final static String SHOW_STATISTICS_OPTION_LABEL = " Show my statistics to VRE Members " ;
/ * *
* Some tooltips
* /
2017-02-24 14:14:32 +01:00
private final static String QUOTA_TOOLTIP = " Percentage of your used space in the infrastructure storage " ;
2016-08-31 10:45:58 +02:00
private final static String TOOLTIP_ACTIVITY_ROOT_PROFILE = " Posts, likes, replies done during the last year " ;
private final static String TOOLTIP_ACTIVITY_VRE = " Posts, likes, replies done in the last year in this VRE " ;
2016-08-29 18:08:08 +02:00
private final static String TOOLTIP_GOT_ROOT_PROFILE = " Likes and post replies got during the last year " ;
private final static String TOOLTIP_GOT_VRE = " Likes and post replies got during the last year in this VRE " ;
private final static String TOOLTIP_INFRASTRUCTURE_SPACE = " Total amount of space used in the infrastructure " ;
2016-08-30 15:36:19 +02:00
private final static String TOOLTIP_PROFILE_STRENGHT = " Profile strength evaluated taking into account contacts, professional summary and current position information " ;
private final static String SHOW_STATISTICS_OPTION_TOOLTIP = " Show Statistics to members viewing your profile " ;
2016-08-29 18:08:08 +02:00
/ * *
2016-08-31 10:45:58 +02:00
* Specific tooltips ( for the values )
2016-08-29 18:08:08 +02:00
* /
2016-08-31 10:45:58 +02:00
private final static String TOOLTIP_POSTS_DONE = " Posts done during the last year " ;
private final static String TOOLTIP_POSTS_DONE_VRE = " Posts done during the last year in this VRE " ;
2016-08-29 18:08:08 +02:00
private final static String TOOLTIP_LIKES_GOT = " Likes got during the last year " ;
private final static String TOOLTIP_LIKES_GOT_VRE = " Likes got during the last year in this VRE " ;
private final static String TOOLTIP_LIKES_DONE = " Likes done during the last year " ;
private final static String TOOLTIP_LIKES_DONE_VRE = " Likes done during the last year in this VRE " ;
private final static String TOOLTIP_REPLIES_DONE = " Post replies done during the last year " ;
private final static String TOOLTIP_REPLIES_DONE_VRE = " Post replies done during the last year in this VRE " ;
private final static String TOOLTIP_REPLIES_GOT = " Post replies got during the last year " ;
2016-09-29 17:30:45 +02:00
private final static String TOOLTIP_REPLIES_GOT_VRE = " Post replies got during the last year in this VRE " ;
2015-12-09 14:34:41 +01:00
/ * *
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; "
2016-08-03 16:26:49 +02:00
+ " <li> adding your contact information (facebook, linkedin, skype, google mail and so on)</ul> " ;
2016-05-20 15:12:01 +02:00
/ * *
* 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; "
2016-08-03 16:26:49 +02:00
+ " <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
/ * *
2016-08-31 10:45:58 +02: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-08-31 10:45:58 +02:00
private ActivityWidget activityGot ;
2016-01-26 10:40:46 +01:00
/ * *
2016-08-31 10:45:58 +02:00
* Posts , comments , likes done
2016-01-26 10:40:46 +01:00
* /
2016-08-31 10:45:58 +02:00
private ActivityWidget activityDone ;
2016-01-26 18:27:19 +01:00
/ * *
* 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 ( ) ;
2016-08-03 16:26:49 +02:00
/ * *
* Handler Manager for internal events
* /
private final HandlerManager eventBus = new HandlerManager ( null ) ;
2016-08-29 18:08:08 +02:00
/ * *
* Saved current user information bean
* /
UserInformation informationBeanRetrieved ;
2016-08-30 15:36:19 +02:00
2015-12-09 14:34:41 +01:00
public StatisticsPanel ( ) {
//init this object
super ( ) ;
initWidget ( mainPanel ) ;
2016-08-03 16:26:49 +02:00
// bind pagebus events/ internal 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-07-19 16:25:41 +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 ) . . if it is null or empty , the current user ' s information
/ will be retrieved .
* /
2016-05-10 18:40:55 +02:00
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 ( ) ) {
2016-08-31 10:45:58 +02:00
mainPanel . add ( new HTML ( " Sorry but the user set statistics to private " ) ) ;
2016-05-10 18:40:55 +02:00
return ;
}
2016-08-29 18:08:08 +02:00
// save it
informationBeanRetrieved = information ;
2016-08-30 15:36:19 +02:00
2016-07-19 16:25:41 +02:00
// is a user profile page? or a vre/home one (this portlet can be also deployed in a vre)
final boolean isProfilePage = isProfilePage ( ) ;
2016-05-10 18:40:55 +02:00
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-07-19 15:18:29 +02:00
// set the title
if ( userid ! = null )
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 ) ;
2016-08-31 10:45:58 +02:00
// feeds, posts, likes
final StatisticWidget activityDoneWidgetContainer = new StatisticWidget ( isRoot ) ;
activityDoneWidgetContainer . setHeader ( ACTIVITY_LABEL ) ;
2015-12-09 14:34:41 +01:00
2016-05-10 18:40:55 +02:00
if ( isRoot | | isProfilePage )
2016-08-31 10:45:58 +02:00
activityDoneWidgetContainer . setToolTip ( TOOLTIP_ACTIVITY_ROOT_PROFILE ) ;
2015-12-09 14:34:41 +01:00
else
2016-08-31 10:45:58 +02:00
activityDoneWidgetContainer . setToolTip ( TOOLTIP_ACTIVITY_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 " ) ;
2016-08-31 10:45:58 +02:00
activityDoneWidgetContainer . appendToPanel ( postsLoader ) ;
2016-08-03 16:26:49 +02:00
// append widget
2016-08-31 10:45:58 +02:00
mainPanel . add ( activityDoneWidgetContainer ) ;
2016-08-03 16:26:49 +02:00
// likes & comments got
2016-08-31 10:45:58 +02:00
final StatisticWidget activityGotWidgetContainer = new StatisticWidget ( isRoot ) ;
activityGotWidgetContainer . setHeader ( LIKES_COMMENTS_GOT_LABEL ) ;
2015-12-09 14:34:41 +01:00
2016-05-10 18:40:55 +02:00
if ( isRoot | | isProfilePage )
2016-08-31 10:45:58 +02:00
activityGotWidgetContainer . setToolTip ( TOOLTIP_GOT_ROOT_PROFILE ) ;
2015-12-09 14:34:41 +01:00
else
2016-08-31 10:45:58 +02:00
activityGotWidgetContainer . setToolTip ( TOOLTIP_GOT_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 " ) ;
2016-08-31 10:45:58 +02:00
activityGotWidgetContainer . appendToPanel ( commentsLikesLoader ) ;
2015-12-09 14:34:41 +01:00
// append widget
2016-08-31 10:45:58 +02:00
mainPanel . add ( activityGotWidgetContainer ) ;
2015-12-09 14:34:41 +01:00
2017-02-13 14:37:12 +01:00
// 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 ) ;
2016-08-29 18:08:08 +02:00
storage . setToolTip ( TOOLTIP_INFRASTRUCTURE_SPACE ) ;
2015-12-09 14:34:41 +01:00
// 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-08-29 18:08:08 +02:00
profileStrength . setToolTip ( TOOLTIP_PROFILE_STRENGHT ) ;
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 ) ;
2017-02-12 21:14:11 +01:00
// require quota information
statisticsService . getQuotaStorage ( userid , new AsyncCallback < QuotaInfo > ( ) {
2017-02-13 14:37:12 +01:00
2017-02-12 21:14:11 +01:00
@Override
public void onSuccess ( QuotaInfo quota ) {
2017-02-13 14:37:12 +01:00
2017-02-12 21:14:11 +01:00
if ( quota = = null ) {
2017-02-24 14:14:32 +01:00
2017-02-13 14:37:12 +01:00
// ask for partial value
statisticsService . getTotalSpaceInUse ( userid , new AsyncCallback < String > ( ) {
@Override
public void onFailure ( Throwable arg0 ) {
appendAlertIcon ( storage ) ;
}
@Override
public void onSuccess ( String spaceInUse ) {
if ( spaceInUse = = null ) {
appendAlertIcon ( storage ) ;
} else {
storage . clearPanelValues ( ) ;
Button storageValue = new Button ( ) ;
storageValue . setType ( ButtonType . LINK ) ;
storageValue . setText ( spaceInUse ) ;
storageValue . addStyleName ( " buttons-statistics-disabled-events " ) ;
storage . appendToPanel ( storageValue ) ;
}
}
} ) ;
2017-02-12 21:14:11 +01:00
} else {
2017-02-13 14:37:12 +01:00
Float max = quota . getMax ( ) ;
Float current = quota . getCurrent ( ) ;
float percent = ( ( float ) ( ( double ) current / ( double ) max ) ) * 100 . 0f ;
String decimalFormat = NumberFormat . getFormat ( " #.## " ) . format ( percent ) ;
storage . clearPanelValues ( ) ;
2017-02-12 21:14:11 +01:00
Button quotaStorageValue = new Button ( ) ;
quotaStorageValue . setType ( ButtonType . LINK ) ;
2017-02-13 14:37:12 +01:00
quotaStorageValue . setText ( decimalFormat + " % " ) ;
2017-02-13 14:50:12 +01:00
quotaStorageValue . setTitle ( " Currently using " + NumberFormat . getFormat ( " #.## " ) . format ( current ) + " MB of " + max + " MB assigned in the Infrastructure Storage " ) ;
2017-02-24 14:14:32 +01:00
storage . setToolTip ( QUOTA_TOOLTIP ) ;
2017-02-13 14:37:12 +01:00
storage . appendToPanel ( quotaStorageValue ) ;
2017-02-12 21:14:11 +01:00
}
2017-02-13 14:37:12 +01:00
2017-02-12 21:14:11 +01:00
}
@Override
public void onFailure ( Throwable arg0 ) {
2017-02-13 14:37:12 +01:00
// ask for partial value
statisticsService . getTotalSpaceInUse ( userid , new AsyncCallback < String > ( ) {
@Override
public void onFailure ( Throwable arg0 ) {
appendAlertIcon ( storage ) ;
}
@Override
public void onSuccess ( String spaceInUse ) {
if ( spaceInUse = = null ) {
appendAlertIcon ( storage ) ;
} else {
storage . clearPanelValues ( ) ;
Button storageValue = new Button ( ) ;
storageValue . setType ( ButtonType . LINK ) ;
storageValue . setText ( spaceInUse ) ;
storageValue . addStyleName ( " buttons-statistics-disabled-events " ) ;
storage . appendToPanel ( storageValue ) ;
}
}
} ) ;
2017-02-12 21:14:11 +01:00
}
} ) ;
2017-02-13 14:37:12 +01:00
2017-02-12 21:14:11 +01:00
// require profile strenght
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 ) ;
2016-08-31 10:45:58 +02:00
} else {
2015-12-09 14:34:41 +01:00
2016-08-31 10:45:58 +02:00
// clear panel
profileStrength . clearPanelValues ( ) ;
2016-09-27 12:05:56 +02:00
Button profileStrengthLabel = new Button ( ) ;
profileStrengthLabel . setType ( ButtonType . LINK ) ;
profileStrengthLabel . setText ( profileStrengthInt + " % " ) ;
profileStrengthLabel . addStyleName ( " buttons-statistics-disabled-events " ) ;
2016-08-31 10:45:58 +02:00
profileStrength . appendToPanel ( profileStrengthLabel ) ;
2015-12-09 14:34:41 +01:00
2016-08-31 10:45:58 +02:00
// in case too low information within the user profile
if ( profileStrengthInt < profileImproveThreshold & & information . isOwner ( ) ) {
2015-12-09 14:34:41 +01:00
2016-08-31 10:45:58 +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 " ) ;
2016-05-20 15:12:01 +02:00
2016-08-31 10:45:58 +02:00
final Button improveProfileButton = new Button ( IMPROVE_BUTTON_LABEL ) ;
improveProfileButton . setType ( ButtonType . INFO ) ;
improveProfileButton . setTitle ( " Improve your profile " ) ;
2015-12-09 14:34:41 +01:00
2016-08-31 10:45:58 +02:00
improveProfileButton . addClickHandler ( new ClickHandler ( ) {
2015-12-09 14:34:41 +01:00
2016-08-31 10:45:58 +02:00
@Override
public void onClick ( ClickEvent arg0 ) {
2015-12-09 14:34:41 +01:00
2016-08-31 10:45:58 +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
2016-08-31 10:45:58 +02:00
}
} ) ;
2015-12-09 14:34:41 +01:00
2016-08-31 10:45:58 +02:00
profileStrengthLabel . setStyleName ( " statistic-value-inline " ) ;
improveProfileButton . addStyleName ( " button-improve-profile " ) ;
profileStrength . appendToPanel ( improveProfileButton ) ;
}
2015-12-09 14:34:41 +01:00
}
}
} ) ;
}
2016-08-31 10:45:58 +02:00
// retrieve other information about number of feeds and post replies/likes done and got
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 ) {
2016-08-31 10:45:58 +02:00
appendAlertIcon ( activityDoneWidgetContainer ) ;
appendAlertIcon ( activityGotWidgetContainer ) ;
2015-12-09 14:34:41 +01:00
}
public void onSuccess ( PostsStatsBean postsBean ) {
// if there are no statistics
if ( postsBean = = null ) {
2016-08-31 10:45:58 +02:00
appendAlertIcon ( activityDoneWidgetContainer ) ;
appendAlertIcon ( activityGotWidgetContainer ) ;
2015-12-09 14:34:41 +01:00
return ;
}
2016-08-31 10:45:58 +02:00
// update feeds number, comments and likes done
activityDoneWidgetContainer . clearPanelValues ( ) ;
activityDone = new ActivityWidget ( ) ;
2016-08-29 18:08:08 +02:00
2016-08-31 10:45:58 +02:00
// set the event handler if needed
2016-09-01 17:25:40 +02:00
if ( ! isProfilePage | | getUserToShowId ( ) = = null )
2016-08-31 10:45:58 +02:00
activityDone . setEventBus ( eventBus ) ;
2016-08-03 16:26:49 +02:00
2016-08-31 10:45:58 +02:00
if ( isRoot | | isProfilePage )
activityDone . setPosts (
formattedNumbers ( postsBean . getFeedsNumber ( ) ) ,
TOOLTIP_POSTS_DONE + " ( " + postsBean . getFeedsNumber ( ) + " ) " ,
ShowUserStatisticAction . POSTS_MADE_BY_USER ,
information . getCurrentPageLanding ( ) ) ;
else
activityDone . setPosts (
formattedNumbers ( postsBean . getFeedsNumber ( ) ) ,
TOOLTIP_POSTS_DONE_VRE + " ( " + postsBean . getFeedsNumber ( ) + " ) " ,
ShowUserStatisticAction . POSTS_MADE_BY_USER ,
information . getCurrentPageLanding ( ) ) ;
2016-01-26 10:40:46 +01:00
2016-01-26 18:27:19 +01:00
numberOfWrittenFeeds = postsBean . getFeedsNumber ( ) ;
2016-08-31 10:45:58 +02:00
activityDoneWidgetContainer . appendToPanel ( activityDone ) ;
2015-12-09 14:34:41 +01:00
2016-08-03 16:26:49 +02:00
if ( isRoot | | isProfilePage )
2016-08-31 10:45:58 +02:00
activityDone . setLikes (
2016-08-03 16:26:49 +02:00
formattedNumbers ( postsBean . getLikesMade ( ) ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_LIKES_DONE + " ( " + postsBean . getLikesMade ( ) + " ) " ,
ShowUserStatisticAction . LIKES_MADE_BY_USER ,
information . getCurrentPageLanding ( ) ) ;
2016-08-03 16:26:49 +02:00
else
2016-08-31 10:45:58 +02:00
activityDone . setLikes (
2016-08-03 16:26:49 +02:00
formattedNumbers ( postsBean . getLikesMade ( ) ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_LIKES_DONE_VRE + " ( " + postsBean . getLikesMade ( ) + " ) " ,
ShowUserStatisticAction . LIKES_MADE_BY_USER ,
information . getCurrentPageLanding ( ) ) ;
2016-08-03 16:26:49 +02:00
if ( isRoot | | isProfilePage )
2016-08-31 10:45:58 +02:00
activityDone . setComments (
2016-08-03 16:26:49 +02:00
formattedNumbers ( postsBean . getCommentsMade ( ) ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_REPLIES_DONE + " ( " + postsBean . getCommentsMade ( ) + " ) " ,
ShowUserStatisticAction . COMMENTS_MADE_BY_USER ,
information . getCurrentPageLanding ( ) ) ;
2016-08-03 16:26:49 +02:00
else
2016-08-31 10:45:58 +02:00
activityDone . setComments (
2016-08-03 16:26:49 +02:00
formattedNumbers ( postsBean . getCommentsMade ( ) ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_REPLIES_DONE_VRE + " ( " + postsBean . getCommentsMade ( ) + " ) " ,
ShowUserStatisticAction . COMMENTS_MADE_BY_USER ,
information . getCurrentPageLanding ( ) ) ;
2016-08-03 16:26:49 +02:00
2016-08-31 10:45:58 +02:00
activityDoneWidgetContainer . appendToPanel ( activityDone ) ;
2016-08-03 16:26:49 +02:00
// updates comments and likes got
2016-08-31 10:45:58 +02:00
activityGotWidgetContainer . clearPanelValues ( ) ;
activityGot = new ActivityWidget ( ) ;
2016-08-03 16:26:49 +02:00
2016-09-01 17:25:40 +02:00
if ( ! isProfilePage | | getUserToShowId ( ) = = null )
2016-08-31 10:45:58 +02:00
activityGot . setEventBus ( eventBus ) ;
2016-08-03 16:26:49 +02:00
2016-05-10 18:40:55 +02:00
if ( isRoot | | isProfilePage )
2016-08-31 10:45:58 +02:00
activityGot . setLikes (
2015-12-09 14:34:41 +01:00
formattedNumbers ( postsBean . getLikesReceived ( ) ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_LIKES_GOT + " ( " + postsBean . getLikesReceived ( ) + " ) " ,
ShowUserStatisticAction . LIKES_GOT_BY_USER ,
information . getCurrentPageLanding ( ) ) ;
2015-12-09 14:34:41 +01:00
else
2016-08-31 10:45:58 +02:00
activityGot . setLikes (
2015-12-09 14:34:41 +01:00
formattedNumbers ( postsBean . getLikesReceived ( ) ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_LIKES_GOT_VRE + " ( " + postsBean . getLikesReceived ( ) + " ) " ,
ShowUserStatisticAction . LIKES_GOT_BY_USER ,
information . getCurrentPageLanding ( ) ) ;
2015-12-09 14:34:41 +01:00
2016-01-26 18:27:19 +01:00
numberOfLikesGot = postsBean . getLikesReceived ( ) ;
2016-05-10 18:40:55 +02:00
if ( isRoot | | isProfilePage )
2016-08-31 10:45:58 +02:00
activityGot . setComments (
2015-12-09 14:34:41 +01:00
formattedNumbers ( postsBean . getCommentsReceived ( ) ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_REPLIES_GOT + " ( " + postsBean . getCommentsReceived ( ) + " ) " ,
ShowUserStatisticAction . COMMENTS_GOT_BY_USER ,
information . getCurrentPageLanding ( ) ) ;
2015-12-09 14:34:41 +01:00
else
2016-08-31 10:45:58 +02:00
activityGot . setComments (
2015-12-09 14:34:41 +01:00
formattedNumbers ( postsBean . getCommentsReceived ( ) ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_REPLIES_GOT_VRE + " ( " + postsBean . getCommentsReceived ( ) + " ) " ,
ShowUserStatisticAction . COMMENTS_GOT_BY_USER ,
information . getCurrentPageLanding ( ) ) ;
2015-12-09 14:34:41 +01:00
2016-01-26 18:27:19 +01:00
numberOfCommentsGot = postsBean . getCommentsReceived ( ) ;
2016-08-31 10:45:58 +02:00
activityGotWidgetContainer . appendToPanel ( activityGot ) ;
2015-12-09 14:34:41 +01:00
}
} ) ;
2016-07-19 15:10:45 +02:00
// check if we need to show the checkbox to allow the user's profile owner to edit privacy options
// If the user is visiting his profile from within a vre, the checkbox WON'T be shown.
if ( information . isOwner ( ) & & getUserToShowId ( ) = = null & & isProfilePage ) {
2016-05-10 18:40:55 +02:00
// add a checkbox with the settable privacy option
2016-08-30 15:36:19 +02:00
CheckBox privacyOption = new CheckBox ( SHOW_STATISTICS_OPTION_LABEL ) ;
privacyOption . setTitle ( SHOW_STATISTICS_OPTION_TOOLTIP ) ;
2016-05-10 18:40:55 +02:00
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-08-29 18:08:08 +02:00
2016-08-03 16:26:49 +02:00
// on statistic value click handler
eventBus . addHandler ( ShowFeedsRelatedToUserStatisticsEvent . TYPE , new ShowFeedsRelatedToUserStatisticsEventHandler ( ) {
@Override
public void onShowRelatedFeeds (
ShowFeedsRelatedToUserStatisticsEvent event ) {
2016-08-29 18:08:08 +02:00
2016-08-03 16:26:49 +02:00
ShowUserStatisticAction actionToTake = event . getAction ( ) ;
2016-08-29 18:08:08 +02:00
2016-08-03 16:26:49 +02:00
// get current url
String currentUrl = Window . Location . getHref ( ) ;
2016-08-30 15:36:19 +02:00
2016-08-29 18:08:08 +02:00
// if it is a profile page, we have to move the user to the sitelandingpage
if ( isProfilePage ( ) ) {
currentUrl = event . getLandingPage ( ) ;
}
2016-08-30 15:36:19 +02:00
2016-08-29 18:08:08 +02:00
String [ ] splittedUrl = currentUrl . split ( " \\ ? " ) ;
Window . Location . assign ( splittedUrl [ 0 ] + " ? " + Encoder . encode ( GCubeSocialNetworking . SHOW_STATISTICS_ACTION_OID ) + " = " + Encoder . encode ( actionToTake . toString ( ) ) ) ;
2016-08-03 16:26:49 +02:00
}
} ) ;
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 + + ;
2016-08-31 10:45:58 +02:00
2016-01-26 18:27:19 +01:00
if ( isRoot )
2016-08-31 10:45:58 +02:00
activityDone . setPosts (
formattedNumbers ( numberOfWrittenFeeds ) ,
TOOLTIP_POSTS_DONE + " ( " + numberOfWrittenFeeds + " ) " ,
ShowUserStatisticAction . POSTS_MADE_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
else
2016-08-31 10:45:58 +02:00
activityDone . setPosts (
formattedNumbers ( numberOfWrittenFeeds ) ,
TOOLTIP_POSTS_DONE_VRE + " ( " + numberOfWrittenFeeds + " ) " ,
ShowUserStatisticAction . POSTS_MADE_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
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-08-31 10:45:58 +02:00
2016-01-26 18:27:19 +01:00
if ( isRoot )
2016-08-31 10:45:58 +02:00
activityDone . setPosts (
formattedNumbers ( numberOfWrittenFeeds ) ,
TOOLTIP_POSTS_DONE + " ( " + numberOfWrittenFeeds + " ) " ,
ShowUserStatisticAction . POSTS_MADE_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
else
2016-08-31 10:45:58 +02:00
activityDone . setPosts (
formattedNumbers ( numberOfWrittenFeeds ) ,
TOOLTIP_POSTS_DONE_VRE + " ( " + numberOfWrittenFeeds + " ) " ,
ShowUserStatisticAction . POSTS_MADE_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
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 + + ;
if ( isRoot )
2016-08-31 10:45:58 +02:00
activityGot . setLikes (
2016-01-26 18:27:19 +01:00
formattedNumbers ( numberOfLikesGot ) ,
2016-09-27 12:05:56 +02:00
2016-08-29 18:08:08 +02:00
TOOLTIP_LIKES_GOT + " ( " + numberOfLikesGot + " ) " ,
ShowUserStatisticAction . LIKES_GOT_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
else
2016-08-31 10:45:58 +02:00
activityGot . setLikes (
2016-01-26 18:27:19 +01:00
formattedNumbers ( numberOfLikesGot ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_LIKES_GOT_VRE + " ( " + numberOfLikesGot + " ) " ,
ShowUserStatisticAction . LIKES_GOT_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
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
if ( isRoot )
2016-08-31 10:45:58 +02:00
activityGot . setLikes (
2016-01-26 18:27:19 +01:00
formattedNumbers ( numberOfLikesGot ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_LIKES_GOT + " ( " + numberOfLikesGot + " ) " ,
ShowUserStatisticAction . LIKES_GOT_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
else
2016-08-31 10:45:58 +02:00
activityGot . setLikes (
2016-01-26 18:27:19 +01:00
formattedNumbers ( numberOfLikesGot ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_LIKES_GOT_VRE + " ( " + numberOfLikesGot + " ) " ,
ShowUserStatisticAction . LIKES_GOT_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
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
if ( isRoot )
2016-08-31 10:45:58 +02:00
activityGot . setComments (
2016-01-26 18:27:19 +01:00
formattedNumbers ( numberOfCommentsGot ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_REPLIES_GOT + " ( " + numberOfCommentsGot + " ) " ,
ShowUserStatisticAction . COMMENTS_GOT_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
else
2016-09-27 11:16:04 +02:00
activityGot . setComments (
2016-01-26 18:27:19 +01:00
formattedNumbers ( numberOfCommentsGot ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_REPLIES_GOT_VRE + " ( " + numberOfCommentsGot + " ) " ,
ShowUserStatisticAction . COMMENTS_GOT_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
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
if ( isRoot )
2016-08-31 10:45:58 +02:00
activityGot . setComments (
2016-01-26 18:27:19 +01:00
formattedNumbers ( numberOfCommentsGot ) ,
2016-08-29 18:08:08 +02:00
TOOLTIP_REPLIES_GOT + " ( " + numberOfCommentsGot + " ) " ,
ShowUserStatisticAction . COMMENTS_GOT_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
else
2016-08-31 10:45:58 +02:00
activityGot . setComments (
2016-08-29 18:08:08 +02:00
formattedNumbers ( numberOfCommentsGot ) ,
TOOLTIP_REPLIES_GOT_VRE + " ( " + numberOfCommentsGot + " ) " ,
ShowUserStatisticAction . COMMENTS_GOT_BY_USER ,
informationBeanRetrieved . getCurrentPageLanding ( ) ) ;
2016-01-26 18:27:19 +01:00
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 ( ) ;
2016-09-29 11:07:12 +02:00
Button alert = new Button ( ) ;
alert . setType ( ButtonType . LINK ) ;
alert . setIcon ( IconType . BAN_CIRCLE ) ;
2015-12-09 14:34:41 +01:00
alert . setTitle ( ALERT_MESSAGE ) ;
2016-09-29 11:07:12 +02:00
alert . addStyleName ( " alert-icon-center " ) ;
2015-12-09 14:34:41 +01:00
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 ) ;
}
2016-08-03 16:26:49 +02:00
2016-07-19 16:25:41 +02:00
/ * *
* The user - statistics can be deployed in a vre , within the home or in a profile page
* @return true if the current page is a profile page , false otherwise
* /
private boolean isProfilePage ( ) {
return Window . Location . getHref ( ) . endsWith ( " profile " )
| | Window . Location . getHref ( ) . contains ( " profile? " ) ;
}
2015-12-09 14:34:41 +01:00
}