From 9077c4f17e484bfb69e5afbcad1604d559fdc7ff Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Tue, 26 Jan 2016 09:40:46 +0000 Subject: [PATCH] Bug fix git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/user-statistics@122505 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 10 +- .settings/org.eclipse.wst.common.component | 2 +- pom.xml | 11 +- .../client/StatisticsPanel.java | 95 ++++++++- .../server/UserStatisticsServiceImpl.java | 2 +- .../userstatisticsportlet/Statistics.gwt.xml | 7 +- src/main/webapp/Statistics.html | 10 +- .../webapp/WEB-INF/jsp/Statistics_view.jsp | 11 +- src/main/webapp/js/pagebus.js | 182 ++++++++++++++++++ 9 files changed, 315 insertions(+), 15 deletions(-) create mode 100644 src/main/webapp/js/pagebus.js diff --git a/.classpath b/.classpath index 3c54350..3e21853 100644 --- a/.classpath +++ b/.classpath @@ -6,11 +6,6 @@ - - - - - @@ -34,5 +29,10 @@ + + + + + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index a658bf0..41c9bcb 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -2,8 +2,8 @@ - + diff --git a/pom.xml b/pom.xml index a2d9b24..4ae4530 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.user user-statistics war - 1.0.1-SNAPSHOT + 1.0.0-SNAPSHOT User statistics portlet User statistics portlet shows main user's statistics. @@ -131,6 +131,15 @@ home-library-jcr provided + + com.google + gwt-jsonmaker + + + net.eliasbalasis + tibcopagebus4gwt + 1.2.0 + diff --git a/src/main/java/org/gcube/portlet/user/userstatisticsportlet/client/StatisticsPanel.java b/src/main/java/org/gcube/portlet/user/userstatisticsportlet/client/StatisticsPanel.java index 83612bc..d73a0e2 100644 --- a/src/main/java/org/gcube/portlet/user/userstatisticsportlet/client/StatisticsPanel.java +++ b/src/main/java/org/gcube/portlet/user/userstatisticsportlet/client/StatisticsPanel.java @@ -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 */ diff --git a/src/main/java/org/gcube/portlet/user/userstatisticsportlet/server/UserStatisticsServiceImpl.java b/src/main/java/org/gcube/portlet/user/userstatisticsportlet/server/UserStatisticsServiceImpl.java index 4b41703..d2ad9bf 100644 --- a/src/main/java/org/gcube/portlet/user/userstatisticsportlet/server/UserStatisticsServiceImpl.java +++ b/src/main/java/org/gcube/portlet/user/userstatisticsportlet/server/UserStatisticsServiceImpl.java @@ -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; } diff --git a/src/main/resources/org/gcube/portlet/user/userstatisticsportlet/Statistics.gwt.xml b/src/main/resources/org/gcube/portlet/user/userstatisticsportlet/Statistics.gwt.xml index 890d874..608aaf9 100644 --- a/src/main/resources/org/gcube/portlet/user/userstatisticsportlet/Statistics.gwt.xml +++ b/src/main/resources/org/gcube/portlet/user/userstatisticsportlet/Statistics.gwt.xml @@ -6,7 +6,12 @@ - + + + + + + diff --git a/src/main/webapp/Statistics.html b/src/main/webapp/Statistics.html index 38fa8cc..0b1f4ec 100644 --- a/src/main/webapp/Statistics.html +++ b/src/main/webapp/Statistics.html @@ -13,7 +13,8 @@ - + @@ -27,6 +28,13 @@ + + + diff --git a/src/main/webapp/WEB-INF/jsp/Statistics_view.jsp b/src/main/webapp/WEB-INF/jsp/Statistics_view.jsp index a301fa2..e907e68 100644 --- a/src/main/webapp/WEB-INF/jsp/Statistics_view.jsp +++ b/src/main/webapp/WEB-INF/jsp/Statistics_view.jsp @@ -1,6 +1,13 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - - + + +
\ No newline at end of file diff --git a/src/main/webapp/js/pagebus.js b/src/main/webapp/js/pagebus.js new file mode 100644 index 0000000..77b03e2 --- /dev/null +++ b/src/main/webapp/js/pagebus.js @@ -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"); +} + +} \ No newline at end of file