Start adding support for number of likes/posts/comments autoupdate on client side

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/user-statistics@122531 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-01-26 17:27:19 +00:00
parent bcc3ac35db
commit 96fe217a5a
3 changed files with 208 additions and 27 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/user-statistics-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/user-statistics-1.0.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -29,10 +29,10 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
<classpathentry excluding="**" kind="src" output="target/user-statistics-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/user-statistics-1.0.1-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/user-statistics-1.0.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/user-statistics-1.0.1-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>user-statistics</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
<name>User statistics portlet</name>
<description>
User statistics portlet shows main user's statistics.

View File

@ -99,9 +99,24 @@ public class StatisticsPanel extends Composite {
private Label numberOfFeedsLabel;
/**
* Number of written posts in the actual VRE
* Since the number of likes/comments got can be manipulated, we need a class reference
*/
private long numberOfWrittenPostsVRE;
private CommentsAndLikesWidget content;
/**
* Number of written posts
*/
private long numberOfWrittenFeeds;
/**
* Number of likes got
*/
private long numberOfLikesGot;
/**
* Number of likes got
*/
private long numberOfCommentsGot;
/**
* Pagebus to listen for events (coming from the news feed portlet)
@ -115,7 +130,7 @@ public class StatisticsPanel extends Composite {
initWidget(mainPanel);
// bind pagebus events
//bind();
bind();
// set style of the main panel
mainPanel.setStyleName("user-stats-frame");
@ -369,13 +384,13 @@ public class StatisticsPanel extends Composite {
else
numberOfFeedsLabel.setTitle("Your posts during the last year in this VRE (" + postsBean.getFeedsNumber() + ").");
numberOfWrittenPostsVRE = postsBean.getFeedsNumber();
numberOfWrittenFeeds = postsBean.getFeedsNumber();
numberOfFeedsLabel.setStyleName("statistic-value");
feeds.appendToPanel(numberOfFeedsLabel);
// updates comments and likes
likesAndComments.clearPanelValues();
CommentsAndLikesWidget content = new CommentsAndLikesWidget();
content = new CommentsAndLikesWidget();
String urlLikesIcon = GWT.getModuleBaseURL() + "../images/star_blue.png";
if(isRoot)
@ -391,6 +406,8 @@ public class StatisticsPanel extends Composite {
"Likes you got during the last year in this VRE",
"Likes you got during the last year in this VRE (" + postsBean.getLikesReceived() + ").");
numberOfLikesGot = postsBean.getLikesReceived();
String urlCommentsIcon = GWT.getModuleBaseURL() + "../images/comment_edit.png";
if(isRoot)
content.setComments(
@ -405,6 +422,7 @@ public class StatisticsPanel extends Composite {
"Post replies you got during the last year in this VRE.",
"Post replies you got during the last year in this VRE (" + postsBean.getCommentsReceived() + ").");
numberOfCommentsGot = postsBean.getCommentsReceived();
likesAndComments.appendToPanel(content);
}
@ -421,7 +439,7 @@ public class StatisticsPanel extends Composite {
private void bind() {
try {
// increment
// increment post number
pageBusAdapter.PageBusSubscribe("org.gcube.portal.incrementPostCount", null, null, null, null);
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
@ -434,18 +452,22 @@ public class StatisticsPanel extends Composite {
@Override
public void onPageBusSubscriptionCallback(PageBusEvent event) {
printJS("Increment number of post message received");
Window.alert("TEST");
if(event.getSubject().equals(this.getName())){
numberOfWrittenPostsVRE ++;
numberOfFeedsLabel.setText(formattedNumbers(numberOfWrittenPostsVRE));
numberOfFeedsLabel.setTitle("Your posts during the last year in this VRE (" + numberOfWrittenPostsVRE + ").");
GWT.log("Increment number of post message received");
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);
}
}
});
// decrement
// decrement post number
pageBusAdapter.PageBusSubscribe("org.gcube.portal.decrementPostCount", null, null, null, null);
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
@ -458,24 +480,183 @@ public class StatisticsPanel extends Composite {
@Override
public void onPageBusSubscriptionCallback(PageBusEvent event) {
printJS("Decrement number of post message received");
numberOfWrittenPostsVRE --;
numberOfFeedsLabel.setText(formattedNumbers(numberOfWrittenPostsVRE));
numberOfFeedsLabel.setTitle("Your posts during the last year in this VRE (" + numberOfWrittenPostsVRE + ").");
if(event.getSubject().equals(this.getName())){
GWT.log("Decrement number of post message received");
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);
}
}});
// increment likes got number
pageBusAdapter.PageBusSubscribe("org.gcube.portal.incrementLikesGot", null, null, null, null);
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
@Override
public String getName() {
return "org.gcube.portal.incrementLikesGot";
}
@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
pageBusAdapter.PageBusSubscribe("org.gcube.portal.decrementLikesGot", null, null, null, null);
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
@Override
public String getName() {
return "org.gcube.portal.decrementLikesGot";
}
@Override
public void onPageBusSubscriptionCallback(PageBusEvent event) {
if(event.getSubject().equals(this.getName())){
GWT.log("Decrement 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);
}
}
});
// increment comments got number
pageBusAdapter.PageBusSubscribe("org.gcube.portal.incrementCommentsGot", null, null, null, null);
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
@Override
public String getName() {
return "org.gcube.portal.incrementCommentsGot";
}
@Override
public void onPageBusSubscriptionCallback(PageBusEvent event) {
if(event.getSubject().equals(this.getName())){
GWT.log("Increment number of comments received");
numberOfCommentsGot ++;
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);
}
}
});
// decrement comments got
pageBusAdapter.PageBusSubscribe("org.gcube.portal.decrementCommentsGot", null, null, null, null);
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
@Override
public String getName() {
return "org.gcube.portal.decrementCommentsGot";
}
@Override
public void onPageBusSubscriptionCallback(PageBusEvent event) {
if(event.getSubject().equals(this.getName())){
GWT.log("Decrement number of comments received");
numberOfCommentsGot --;
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");
} catch (PageBusAdapterException e) {
printJS(e.toString());
GWT.log(e.toString());
}
}
public static native void printJS(String msg)/*-{
console.log(msg);
}-*/;
/**
* Show loading image
*/