git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/user-statistics@122505 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-01-26 09:40:46 +00:00
parent 08081a895e
commit 9077c4f17e
9 changed files with 315 additions and 15 deletions

View File

@ -6,11 +6,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/user-statistics-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
@ -34,5 +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">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/user-statistics-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -2,8 +2,8 @@
<wb-module deploy-name="user-statistics">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="java-output-path" value="/user-statistics/target/user-statistics-portlet-0.0.1-SNAPSHOT/WEB-INF/classes"/>
<property name="context-root" value="user-statistics"/>
</wb-module>

11
pom.xml
View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>user-statistics</artifactId>
<packaging>war</packaging>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<name>User statistics portlet</name>
<description>
User statistics portlet shows main user's statistics.
@ -131,6 +131,15 @@
<artifactId>home-library-jcr</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google</groupId>
<artifactId>gwt-jsonmaker</artifactId>
</dependency>
<dependency>
<groupId>net.eliasbalasis</groupId>
<artifactId>tibcopagebus4gwt</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<build>

View File

@ -1,5 +1,10 @@
package org.gcube.portlet.user.userstatisticsportlet.client;
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapter;
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapterException;
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusEvent;
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusListener;
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;
@ -61,7 +66,7 @@ public class StatisticsPanel extends Composite {
/**
* profile url
*/
private final static String profileAccount = "https://dev.d4science.org/group/data-e-infrastructure-gateway/profile";
private final static String profileAccount = "https://i-marine.d4science.org/group/data-e-infrastructure-gateway/profile";
/**
* profile button label
@ -88,12 +93,30 @@ public class StatisticsPanel extends Composite {
*/
private FlowPanel mainPanel = new FlowPanel();
/**
* Since the number of feeds(posts) can be manipulated when the user posts, we need a class reference
*/
private Label numberOfFeedsLabel;
/**
* Number of written posts in the actual VRE
*/
private long numberOfWrittenPostsVRE;
/**
* Pagebus to listen for events (coming from the news feed portlet)
*/
final public static PageBusAdapter pageBusAdapter = new PageBusAdapter();
public StatisticsPanel() {
//init this object
super();
initWidget(mainPanel);
// bind pagebus events
//bind();
// set style of the main panel
mainPanel.setStyleName("user-stats-frame");
@ -128,8 +151,10 @@ public class StatisticsPanel extends Composite {
// add the border to the panel and the VRE name (check for VRE name lenght)
mainPanel.addStyleName("user-stats-frame-border");
String nameToShow = DISPLAY_NAME + " in " + information.getActualVre();
// cut it if it's too long
nameToShow = nameToShow.length() > 30 ?
nameToShow.substring(0, 27) + "..." : information.getActualVre();
nameToShow.substring(0, 27) + "..." : nameToShow;
final HTML name = new HTML(nameToShow);
name.setTitle(DISPLAY_NAME + " in " + information.getActualVre());
name.setStyleName("user-stats-title");
@ -338,11 +363,13 @@ public class StatisticsPanel extends Composite {
// update feeds number
feeds.clearPanelValues();
Label numberOfFeedsLabel = new Label(formattedNumbers(postsBean.getFeedsNumber()));
numberOfFeedsLabel = new Label(formattedNumbers(postsBean.getFeedsNumber()));
if(isRoot)
numberOfFeedsLabel.setTitle("Your posts during the last year (" + postsBean.getFeedsNumber() + ").");
else
numberOfFeedsLabel.setTitle("Your posts during the last year in this VRE (" + postsBean.getFeedsNumber() + ").");
numberOfWrittenPostsVRE = postsBean.getFeedsNumber();
numberOfFeedsLabel.setStyleName("statistic-value");
feeds.appendToPanel(numberOfFeedsLabel);
@ -387,6 +414,68 @@ public class StatisticsPanel extends Composite {
});
}
/**
* Bind for events of increment/decrement of user's posts coming from the news-feed portlet
*/
private void bind() {
try {
// increment
pageBusAdapter.PageBusSubscribe("org.gcube.portal.incrementPostCount", null, null, null, null);
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
@Override
public String getName() {
return "org.gcube.portal.incrementPostCount";
}
@Override
public void onPageBusSubscriptionCallback(PageBusEvent event) {
printJS("Increment number of post message received");
Window.alert("TEST");
numberOfWrittenPostsVRE ++;
numberOfFeedsLabel.setText(formattedNumbers(numberOfWrittenPostsVRE));
numberOfFeedsLabel.setTitle("Your posts during the last year in this VRE (" + numberOfWrittenPostsVRE + ").");
}
});
// decrement
pageBusAdapter.PageBusSubscribe("org.gcube.portal.decrementPostCount", null, null, null, null);
pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener(){
@Override
public String getName() {
return "org.gcube.portal.decrementPostCount";
}
@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 + ").");
}});
} catch (PageBusAdapterException e) {
printJS(e.toString());
}
}
public static native void printJS(String msg)/*-{
console.log(msg);
}-*/;
/**
* Show loading image
*/

View File

@ -120,7 +120,7 @@ public class UserStatisticsServiceImpl extends RemoteServiceServlet implements U
*/
public String getDevelopmentUser() {
String user = userid;
user = "massimiliano.assante";
// user = "massimiliano.assante";
return user;
}

View File

@ -6,7 +6,12 @@
<!-- Other module inherits -->
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
<inherits name='org.gcube.portal.databook.GCubeSocialNetworking' />
<!-- Other module inherits -->
<inherits name="net.eliasbalasis.tibcopagebus4gwt.tibcopagebus4gwt" />
<inherits name="org.jsonmaker.gwt.Gwt_jsonmaker" />
<inherits name="net.eliasbalasis.tibcopagebus4gwt.testsubscriber.TestSubscriber" />
<!-- Specify the app entry point class. -->
<entry-point
class='org.gcube.portlet.user.userstatisticsportlet.client.Statistics' />

View File

@ -13,7 +13,8 @@
<!-- Consider inlining CSS to reduce the number of requested files -->
<!-- -->
<link type="text/css" rel="stylesheet" href="Statistics.css">
<link href='https://fonts.googleapis.com/css?family=Architects+Daughter' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Architects+Daughter'
rel='stylesheet' type='text/css'>
<!-- -->
<!-- Any title is fine -->
@ -27,6 +28,13 @@
<!-- -->
<script type="text/javascript" language="javascript"
src="statistics/statistics.nocache.js"></script>
<script type="text/javascript" language="javascript" src="js/pagebus.js"></script>
<script type="text/javascript">
if(window.parent.PageBus) {
window.PageBus = window.parent.PageBus;
}
</script>
</head>
<!-- -->

View File

@ -1,6 +1,13 @@
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<link href='https://fonts.googleapis.com/css?family=Architects+Daughter' rel='stylesheet' type='text/css'>
<script type="text/javascript" language="javascript" src="<%=request.getContextPath()%>/statistics/statistics.nocache.js"></script>
<link href='https://fonts.googleapis.com/css?family=Architects+Daughter'
rel='stylesheet' type='text/css'>
<script type="text/javascript" language="javascript"
src="<%=request.getContextPath()%>/statistics/statistics.nocache.js"></script>
<script type="text/javascript">
if (window.parent.PageBus) {
window.PageBus = window.parent.PageBus;
}
</script>
<div id="statistics-container"></div>

View File

@ -0,0 +1,182 @@
/**
* Copyright (c) 2006-2007, TIBCO Software Inc.
* Use, modification, and distribution subject to terms of license.
*
* TIBCO(R) PageBus 1.1.0
*/
if(typeof window.PageBus == 'undefined') {
PageBus = {
version: "1.1.0",
S: {c:{},s:[]},
X: 0,
P: 0,
U: [],
H: "undefined"
};
PageBus.subscribe = function(name, scope, callback, subscriberData)
{
if(name == null)
this._badName();
if(scope == null)
scope = window;
var path = name.split(".");
var sub = { f: callback, d: subscriberData, i: this.X++, p: path, w: scope };
for(var i = 0; i < path.length; i++) {
if((path[i].indexOf("*") != -1) && (path[i] != "*") && (path[i] != "**"))
this._badName();
}
this._subscribe(this.S, path, 0, sub);
return sub;
}
PageBus.publish = function (name, message)
{
if((name == null) || (name.indexOf("*") != -1))
this._badName();
var path = name.split(".");
if(this.P > 100)
this._throw("StackOverflow");
try {
this.P++;
this._publish(this.S, path, 0, name, message);
}
catch(err) {
this.P--;
throw err;
}
try {
this.P--;
if((this.U.length > 0) && (this.P == 0)) {
for(var i = 0; i < this.U.length; i++)
this.unsubscribe(this.U[i]);
this.U = [];
}
}
catch(err) {
// All unsubscribe exceptions should already have
// been handled when unsubscribe was called in the
// publish callback. This is a repeat appearance
// of this exception. Discard it.
}
}
PageBus.unsubscribe = function(sub)
{
this._unsubscribe(this.S, sub.p, 0, sub.i);
}
/*
* @private @jsxobf-clobber
*/
PageBus._throw = function(n)
{
throw new Error("PageBus." + n);
}
/*
* @private @jsxobf-clobber
*/
PageBus._badName = function(n)
{
this._throw("BadName");
}
/*
* @private @jsxobf-clobber
*/
PageBus._subscribe = function(tree, path, index, sub)
{
var tok = path[index];
if(tok == "")
this._badName();
if(index == path.length)
tree.s.push(sub);
else {
if(typeof tree.c == this.H)
tree.c = {};
if(typeof tree.c[tok] == this.H) {
try {
tree.c[tok] = { c: {}, s: [] };
this._subscribe(tree.c[tok], path, index + 1, sub);
}
catch(err) {
delete tree.c[tok];
throw err;
}
}
else
this._subscribe( tree.c[tok], path, index + 1, sub );
}
}
/*
* @private @jsxobf-clobber
*/
PageBus._publish = function(tree, path, index, name, msg) {
if(path[index] == "")
this._badName();
if(typeof tree != this.H) {
if(index < path.length) {
this._publish(tree.c[path[index]], path, index + 1, name, msg);
this._publish(tree.c["*"], path, index + 1, name, msg);
this._call(tree.c["**"], name, msg);
}
else
this._call(tree, name, msg);
}
}
/*
* @private @jsxobf-clobber
*/
PageBus._call = function(node, name, msg) {
if(typeof node != this.H) {
var callbacks = node.s;
var max = callbacks.length;
for(var i = 0; i < max; i++)
if(callbacks[i].f != null)
callbacks[i].f.apply(callbacks[i].w, [name, msg, callbacks[i].d]);
}
}
/*
* @jsxobf-clobber
*/
PageBus._unsubscribe = function(tree, path, index, sid) {
if(typeof tree != this.H) {
if(index < path.length) {
var childNode = tree.c[path[index]];
this._unsubscribe(childNode, path, index + 1, sid);
if(childNode.s.length == 0) {
for(var x in childNode.c) // not empty. We're done.
return;
delete tree.c[path[index]]; // if we got here, c is empty
}
return;
}
else {
var callbacks = tree.s;
var max = callbacks.length;
for(var i = 0; i < max; i++) {
if(sid == callbacks[i].i) {
if(this.P > 0) {
if(callbacks[i].f == null)
this._throw("BadParameter");
callbacks[i].f = null;
this.U.push(callbacks[i]);
}
else
callbacks.splice(i, 1);
return;
}
}
// Not found. Fall through
}
}
this._throw("BadParameter");
}
}