ref 12119:AccountingDashboard - Create a new Accounting Dashboard

https://support.d4science.org/issues/12119

Updated Report support

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/accounting-dashboard@169800 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-07-16 16:56:04 +00:00
parent 4f5504bfc3
commit 845f76b807
14 changed files with 246 additions and 74 deletions

View File

@ -93,7 +93,13 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
for (int i = 2015; i <= year; i++) {
yearStart.addItem(String.valueOf(i));
yearEnd.addItem(String.valueOf(i));
if(i==year){
}
}
yearStart.setSelectedValue(String.valueOf(year));
yearEnd.setSelectedValue(String.valueOf(year));
// returns a String array with localized names of the months
String[] months = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsFull();
@ -109,6 +115,11 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
monthEnd.addItem(months[i]);
}
String currentMonth = DateTimeFormat.getFormat(PredefinedFormat.MONTH).format(now);
monthStart.setSelectedValue(currentMonth);
monthEnd.setSelectedValue(currentMonth);
dataProvider = new ListDataProvider<ScopeData>();
RequestReportEventHandler handler = new RequestReportEventHandler() {
@ -140,7 +151,7 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
dataProvider.flush();
TreeNode root = scopeTree.getRootTreeNode();
root.setChildOpen(root.getIndex(), true);
requestReport();
}
private void requestReport() {

View File

@ -1,17 +1,18 @@
package org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart;
import org.gcube.portlets.user.accountingdashboard.client.resources.AppResources;
import org.gcube.portlets.user.accountingdashboard.shared.data.RecordData;
import org.gcube.portlets.user.accountingdashboard.shared.data.ReportData;
import org.gcube.portlets.user.accountingdashboard.shared.data.ReportElementData;
import org.gcube.portlets.user.accountingdashboard.shared.data.SeriesData;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTMLPanel;
@ -42,7 +43,7 @@ public class ReportAreaView extends ViewWithUiHandlers<ReportAreaPresenter>
init();
initWidget(uiBinder.createAndBindUi(this));
//
/*
RecordData recordData1 = new RecordData();
recordData1.setX("Gennaio");
recordData1.setY(3d);
@ -51,21 +52,31 @@ public class ReportAreaView extends ViewWithUiHandlers<ReportAreaPresenter>
recordData2.setX("Febbraio");
recordData2.setY(2d);
RecordData recordData3 = new RecordData();
recordData3.setX("Marzo");
recordData3.setY(4d);
RecordData[] dataRow1 = new RecordData[2];
dataRow1[0] = recordData1;
dataRow1[1] = recordData2;
RecordData recordData3 = new RecordData();
recordData3.setX("Gennaio");
recordData3.setY(1d);
dataRow1[2] = recordData3;
RecordData recordData4 = new RecordData();
recordData4.setX("Febbraio");
recordData4.setY(5d);
recordData4.setX("Gennaio");
recordData4.setY(1d);
RecordData recordData5 = new RecordData();
recordData5.setX("Febbraio");
recordData5.setY(5d);
RecordData recordData6 = new RecordData();
recordData6.setX("Marzo");
recordData6.setY(2d);
RecordData[] dataRow2 = new RecordData[2];
dataRow2[0] = recordData3;
dataRow2[1] = recordData4;
dataRow2[0] = recordData4;
dataRow2[1] = recordData5;
dataRow2[2] = recordData6;
SeriesData seriesData1 = new SeriesData();
seriesData1.setLabel("Series1");
@ -100,7 +111,7 @@ public class ReportAreaView extends ViewWithUiHandlers<ReportAreaPresenter>
rData.setElements(elements);
displayReportData(rData);
displayReportData(rData);*/
}
private void init() {
@ -124,10 +135,31 @@ public class ReportAreaView extends ViewWithUiHandlers<ReportAreaPresenter>
reportPanel.clear();
} else {
reportPanel.clear();
HashMap<String, ArrayList<Chart>> categories=new HashMap<>();
for (int i = 0; i < reportData.getElements().size(); i++) {
Chart chart = new Chart(resources, "report_" + i, reportData.getElements().get(i));
reportPanel.add(chart);
ReportElementData reportElementData=reportData.getElements().get(i);
ArrayList<Chart> category;
if(categories.containsKey(reportElementData.getCategory())){
category=categories.get(reportElementData.getCategory());
} else {
category=new ArrayList<>();
}
Chart chart = new Chart(resources, "report_" + i, reportElementData);
category.add(chart);
}
TabPanel tabPanel=new TabPanel();
for(String category:categories.keySet()){
Tab tab=new Tab();
HTMLPanel tabContent=new HTMLPanel("");
for(Chart chart:categories.get(category)){
tabContent.add(chart);
}
tab.add(tabContent);
tabPanel.add(tab);
}
reportPanel.add(tabPanel);
}
}

View File

@ -57,18 +57,37 @@ public class Chart extends HTMLPanel {
private native void drawChart() /*-{
var seedPalette = 0;
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
var palette = [ '#FF0000', '#00FFFF', '#483D8B', '#FFFF00',
'#4B0082', '#FFF8DC', '#ADFF2F', '#FF6347', '#E0FFFF',
'#6A5ACD', '#FFFFE0', '#663399', '#FFEBCD', '#7FFF00',
'#FF7F50', '#AFEEEE', '#7B68EE', '#FFFACD', '#00008B',
'#FFE4C4', '#7CFC00', '#FF8C00', '#7FFFD4', '#9370DB',
'#FAFAD2', '#0000CD', '#FFDEAD', '#00FF00', '#FFA500',
'#40E0D0', '#800080', '#FFEFD5', '#0000FF', '#F5DEB3',
'#32CD32', '#8B0000', '#48D1CC', '#8A2BE2', '#FFE4B5',
'#4169E1', '#DEB887', '#98FB98', '#B22222', '#00CED1',
'#9400D3', '#FFDAB9', '#1E90FF', '#D2B48C', '#90EE90',
'#800000', '#556B2F', '#9932CC', '#EEE8AA', '#00BFFF',
'#BC8F8F', '#00FA9A', '#FFD700', '#66CDAA', '#BA55D3',
'#F0E68C', '#6495ED', '#F4A460', '#00FF7F', '#FF4500',
'#8FBC8F', '#FF00FF', '#BDB76B', '#87CEEB', '#DAA520',
'#3CB371', '#DC143C', '#20B2AA', '#FF00FF', '#FFC0CB',
'#87CEFA', '#B8860B', '#2E8B57', '#CD5C5C', '#008B8B',
'#EE82EE', '#FFB6C1', '#B0E0E6', '#CD853F', '#228B22',
'#F08080', '#008080', '#DA70D6', '#FF69B4', '#ADD8E6',
'#D2691E', '#008000', '#E9967A', '#F0FFF0', '#DDA0DD',
'#FF1493', '#B0C4DE', '#808000', '#006400', '#FA8072',
'#F5FFFA', '#D8BFD8', '#DB7093', '#4682B4', '#8B4513',
'#9ACD32', '#FFA07A', '#778899', '#E6E6FA', '#C71585',
'#5F9EA0', '#A0522D', '#6B8E23' ];
seedPalette = (seedPalette) % 112;
var color = palette[seedPalette];
seedPalette += 1;
return color;
}
var name = this.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::name;
console.log('Element name: ' + name);
var element = this;
@ -85,11 +104,12 @@ public class Chart extends HTMLPanel {
console.log('ReportElementData: ' + reportElementData);
var serieses = reportElementData.getSerieses();
console.log('Serieses: '+serieses);
console.log('Serieses: ' + serieses);
var seriesesLen = serieses.length;
console.log('Serieses lenght: ' + seriesesLen);
var datasetsArray = [];
var labelsArray = []
for (var i = 0; i < seriesesLen; i++) {
console.log("for");
var seriesData = serieses[i];
@ -98,14 +118,23 @@ public class Chart extends HTMLPanel {
var dataRowLen = dataRow.length;
var dataArray = [];
if (i == 0) {
for (var j = 0; j < dataRowLen; j++) {
var recordData = dataRow[j];
var recordData = dataArray.push(recordData.getY());
dataArray.push(recordData.getY());
labelsArray.push(recordData.getX());
}
var colorChart=getRandomColor();
console.log('Color: '+colorChart);
} else {
for (var j = 0; j < dataRowLen; j++) {
var recordData = dataRow[j];
dataArray.push(recordData.getY());
}
}
var colorChart = getRandomColor();
console.log('Color: ' + colorChart);
// backgroundColor : 'rgba(255,0,0,0.9)',
// borderColor : 'rgba(255,0,0,1)',
@ -122,11 +151,12 @@ public class Chart extends HTMLPanel {
//console.log('Color: ' + color);
var barChartData = {
labels : [ 'January', 'February' ],
labels : labelsArray,
datasets : datasetsArray
};
var label = reportElementData.getLabel();
var label = [ reportElementData.getLabel(), ' [',
reportElementData.getCategory(), ']' ].filter(Boolean).join("");
var xAxisLabel = reportElementData.getxAxis();
var yAxisLabel = reportElementData.getyAxis();
@ -136,6 +166,7 @@ public class Chart extends HTMLPanel {
type : 'bar',
data : barChartData,
options : {
animation : false,
responsive : true,
legend : {
position : 'top',

View File

@ -17,6 +17,7 @@
border-style: solid !important;
border-width: 1px !important;
padding: 3px !important;
margin-bottom: 5px;
}
.uiDataFiltersExplorePanel {
@ -24,6 +25,7 @@
border-style: solid !important;
border-width: 1px !important;
padding: 3px !important;
margin-bottom: 5px;
}
.uiDataFiltersTitle {
@ -50,22 +52,21 @@
/* Report*/
.uiDataReportPanel {
/*float: left;*/ /*display: block;*/
float: left;
}
/* Chart */
.uiDataChartWrapper {
/*max-width:100%;*/
}
.uiDataChartCanvas {
/*width: 100%;*/ /*min-width: 250px;*/ /*height: 100%;*/
/*min-height: 300px;*/
min-height: 500px;
height: 100%;
max-height: 800px;
}
/* Monitor Dialog */
.uiDataMonitorPopup {
background-color: white;

View File

@ -73,7 +73,7 @@ public class AccountingDashboardServiceImpl extends RemoteServiceServlet impleme
if (Constants.DEBUG_MODE) {
as = new AccountingService(AccountingServiceType.CurrentScope);
} else {
as = new AccountingService(AccountingServiceType.CurrentScope);
as = new AccountingService(AccountingServiceType.PortalContex);
}
ScopeData scopeData = as.getTree(this.getThreadLocalRequest());

View File

@ -99,6 +99,8 @@ public class AccountingService {
Date dateFrom = requestReportData.getDateFrom();
Date dateTo = requestReportData.getDateTo();
logger.debug("getReportByScope(): [ScopeDescriptor=" + scopeDescriptor + ", dateFrom=" + dateFrom
+ ", dateTo=" + dateTo + ", measureResolution=" + MeasureResolution.MONTHLY + "]");
Report report = dao.getReportByScope(scopeDescriptor, dateFrom, dateTo, MeasureResolution.MONTHLY);
logger.debug("Report: " + report);

View File

@ -8,7 +8,7 @@ package org.gcube.portlets.user.accountingdashboard.shared;
*/
public class Constants {
public static final boolean DEBUG_MODE = true;
public static final boolean DEBUG_MODE = false;
public static final boolean TEST_ENABLE = false;
public static final String APPLICATION_ID = "org.gcube.portlets.user.accountingdashboard.server.portlet.AccountingDashboardPortlet";
@ -18,7 +18,7 @@ public class Constants {
public static final String DEFAULT_USER = "giancarlo.panichi";
public static final String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
public static final String DEFAULT_TOKEN = "ae1208f0-210d-47c9-9b24-d3f2dfcce05f-98187548";
public static final String DEFAULT_TOKEN = "";
public static final String DEFAULT_ROLE = "OrganizationMember";
//

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.accountingdashboard.shared.data;
import java.io.Serializable;
import java.util.Arrays;
import jsinterop.annotations.JsType;
@ -67,7 +68,7 @@ public class ReportElementData implements Serializable {
@Override
public String toString() {
return "ReportElementData [label=" + label + ", category=" + category + ", xAxis=" + xAxis + ", yAxis=" + yAxis
+ ", serieses=" + serieses + "]";
+ ", serieses=" + Arrays.toString(serieses) + "]";
}
}

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.user.accountingdashboard.shared.data;
import java.io.Serializable;
import java.util.Arrays;
import jsinterop.annotations.JsType;
@ -38,7 +39,7 @@ public class SeriesData implements Serializable {
@Override
public String toString() {
return "SeriesData [label=" + label + ", dataRow=" + dataRow + "]";
return "SeriesData [label=" + label + ", dataRow=" + Arrays.toString(dataRow) + "]";
}
}

View File

@ -3,7 +3,7 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- -->
<!-- Consider inlining CSS to reduce the number of requested files -->
<!-- -->

View File

@ -1,6 +1,6 @@
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- -->
<!-- The module reference below is the link -->
<!-- between html and your Web Toolkit module -->

View File

@ -22,13 +22,13 @@ public class AccountingServiceTest extends TestCase {
private static Logger logger = LoggerFactory.getLogger(AccountingServiceTest.class);
@Test
public void testCMESService() {
public void testService() {
if (Constants.TEST_ENABLE) {
try {
AuthTest.setToken();
AccountingService accountingService = new AccountingService(AccountingServiceType.CurrentScope);
//accountingService.getTree();
// accountingService.getTree();
assertTrue("Success", true);
} catch (Throwable e) {
@ -47,28 +47,8 @@ public class AccountingServiceTest extends TestCase {
if (Constants.TEST_ENABLE) {
try {
ScopeData children1 = new ScopeData("1", "children1", null);
ScopeData children3 = new ScopeData("3", "children3", null);
ScopeData children4 = new ScopeData("4", "children4", null);
ArrayList<ScopeData> children2List = new ArrayList<>();
children2List.add(children3);
children2List.add(children4);
ScopeData children2 = new ScopeData("2", "children2", children2List);
ArrayList<ScopeData> rootList = new ArrayList<>();
rootList.add(children1);
rootList.add(children2);
ScopeData root = new ScopeData("0", "root", rootList);
ArrayList<ScopeData> scopeDataList = new ArrayList<>();
scopeDataList.add(root);
logger.debug("Data example: "+scopeDataList);
assertTrue("Success", true);
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
fail("Error:" + e.getLocalizedMessage());

View File

@ -0,0 +1,113 @@
package org.gcube.portlets.user.accountingdashboard;
import org.gcube.portlets.user.accountingdashboard.shared.Constants;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cern.colt.Arrays;
import junit.framework.TestCase;
/**
*
* @author Giancarlo Panichi
*
*
*/
public class ColorTest extends TestCase {
private static Logger logger = LoggerFactory.getLogger(ColorTest.class);
@Test
public void testService() {
if (Constants.TEST_ENABLE) {
try {
String[] red = new String[] { "#FF0000", "#FF6347", "#FF7F50", "#FF8C00", "#FFA500", "#8B0000",
"#B22222", "#800000", "#FFD700", "#FF4500", "#DC143C", "#CD5C5C", "#F08080", "#E9967A",
"#FA8072", "#FFA07A" };
String[] cyan = new String[] { "#00FFFF", "#E0FFFF", "#AFEEEE", "#7FFFD4", "#40E0D0", "#48D1CC",
"#00CED1", "#556B2F", "#66CDAA", "#8FBC8F", "#20B2AA", "#008B8B", "#008080", "#F0FFF0",
"#F5FFFA", "#778899" };
String[] purple = new String[] { "#483D8B", "#6A5ACD", "#7B68EE", "#9370DB", "#800080", "#8A2BE2",
"#9400D3", "#9932CC", "#BA55D3", "#FF00FF", "#FF00FF", "#EE82EE", "#DA70D6", "#DDA0DD",
"#D8BFD8", "#E6E6FA" };
String[] yellow = new String[] { "#FFFF00", "#FFFFE0", "#FFFACD", "#FAFAD2", "#FFEFD5", "#FFE4B5",
"#FFDAB9", "#EEE8AA", "#F0E68C", "#BDB76B", "#FFC0CB", "#FFB6C1", "#FF69B4", "#FF1493",
"#DB7093", "#C71585" };
String[] blue = new String[] { "#4B0082", "#663399", "#00008B", "#0000CD", "#0000FF", "#4169E1",
"#1E90FF", "#00BFFF", "#6495ED", "#87CEEB", "#87CEFA", "#B0E0E6", "#ADD8E6", "#B0C4DE",
"#4682B4", "#5F9EA0" };
String[] brown = new String[] { "#FFF8DC", "#FFEBCD", "#FFE4C4", "#FFDEAD", "#F5DEB3", "#DEB887",
"#D2B48C", "#BC8F8F", "#F4A460", "#DAA520", "#B8860B", "#CD853F", "#D2691E", "#808000",
"#8B4513", "#A0522D" };
String[] green = new String[] { "#ADFF2F", "#7FFF00", "#7CFC00", "#00FF00", "#32CD32", "#98FB98",
"#90EE90", "#00FA9A", "#00FF7F", "#3CB371", "#2E8B57", "#228B22", "#008000", "#006400",
"#9ACD32", "#6B8E23" };
logger.debug("Dimension: red=" + red.length + ", cyan=" + cyan.length + ", purple=" + purple.length
+ ", yellow=" + yellow.length + ", blue=" + blue.length + ", brown=" + brown.length + ", green="
+ green.length);
int average = (red.length + cyan.length + purple.length + yellow.length + blue.length + brown.length
+ green.length) / 7;
logger.debug("Average: " + average);
/*
System.out.print("purple=[");
for (int i = purple.length - 1; i > -1; i--) {
if (i == purple.length - 1) {
System.out.print("\"" + purple[i] + "\"");
} else {
System.out.print(",\"" + purple[i] + "\"");
}
}
System.out.print("]");
System.out.println("");
*/
String[] palette = new String[112];
int j = 0;
for (int i = 0; i < 16; i++) {
j = i * 7;
palette[j] = red[i];
palette[j + 1] = cyan[i];
palette[j + 2] = purple[i];
palette[j + 3] = yellow[i];
palette[j + 4] = blue[i];
palette[j + 5] = brown[i];
palette[j + 6] = green[i];
}
logger.debug("Palette: " + Arrays.toString(palette));
StringBuilder paletteBuilder = new StringBuilder();
paletteBuilder.append("[");
for (int i = 0; i < palette.length; i++) {
if (i == 0) {
paletteBuilder.append("'" + palette[i] + "'");
} else {
paletteBuilder.append(",'" + palette[i] + "'");
}
}
paletteBuilder.append("]");
logger.debug("Palette array: " + paletteBuilder.toString());
assertTrue("Success", true);
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
fail("Error:" + e.getLocalizedMessage());
}
} else {
assertTrue("Success", true);
}
}
}

View File

@ -18,7 +18,7 @@ public class ServiceTest extends TestCase {
private static Logger logger = LoggerFactory.getLogger(ServiceTest.class);
@Test
public void testCMESService() {
public void testService() {
if (Constants.TEST_ENABLE) {
try {