ref 12119:AccountingDashboard - Create a new Accounting Dashboard
https://support.d4science.org/issues/12119 Updated Export file support. Added CSV file export. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/accounting-dashboard@169855 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
713dc78c52
commit
842d36cc93
|
@ -28,6 +28,7 @@ public class MainAreaPresenter
|
||||||
extends Presenter<MainAreaPresenter.MainAreaView, MainAreaPresenter.MainAreaPresenterProxy>
|
extends Presenter<MainAreaPresenter.MainAreaView, MainAreaPresenter.MainAreaPresenterProxy>
|
||||||
implements MainAreaUiHandlers {
|
implements MainAreaUiHandlers {
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private static Logger logger = Logger.getLogger("");
|
private static Logger logger = Logger.getLogger("");
|
||||||
|
|
||||||
interface MainAreaView extends View, HasUiHandlers<MainAreaPresenter> {
|
interface MainAreaView extends View, HasUiHandlers<MainAreaPresenter> {
|
||||||
|
@ -43,7 +44,9 @@ public class MainAreaPresenter
|
||||||
public static final SingleSlot<FilterAreaPresenter> SLOT_FILTER = new SingleSlot<>();
|
public static final SingleSlot<FilterAreaPresenter> SLOT_FILTER = new SingleSlot<>();
|
||||||
public static final SingleSlot<ReportAreaPresenter> SLOT_REPORT = new SingleSlot<>();
|
public static final SingleSlot<ReportAreaPresenter> SLOT_REPORT = new SingleSlot<>();
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private Controller controller;
|
private Controller controller;
|
||||||
private FilterAreaPresenter filterAreaPresenter;
|
private FilterAreaPresenter filterAreaPresenter;
|
||||||
private ReportAreaPresenter reportAreaPresenter;
|
private ReportAreaPresenter reportAreaPresenter;
|
||||||
|
|
|
@ -19,6 +19,7 @@ import com.gwtplatform.mvp.client.ViewWithUiHandlers;
|
||||||
*/
|
*/
|
||||||
public class MainAreaView extends ViewWithUiHandlers<MainAreaPresenter> implements MainAreaPresenter.MainAreaView {
|
public class MainAreaView extends ViewWithUiHandlers<MainAreaPresenter> implements MainAreaPresenter.MainAreaView {
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private static Logger logger = java.util.logging.Logger.getLogger("");
|
private static Logger logger = java.util.logging.Logger.getLogger("");
|
||||||
|
|
||||||
interface Binder extends UiBinder<Widget, MainAreaView> {
|
interface Binder extends UiBinder<Widget, MainAreaView> {
|
||||||
|
@ -31,6 +32,7 @@ public class MainAreaView extends ViewWithUiHandlers<MainAreaPresenter> implemen
|
||||||
HTMLPanel reportPanel;
|
HTMLPanel reportPanel;
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private AppResources resources;
|
private AppResources resources;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.gcube.portlets.user.accountingdashboard.client.application.event.Scop
|
||||||
import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData;
|
import org.gcube.portlets.user.accountingdashboard.shared.data.RequestReportData;
|
||||||
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
|
import org.gcube.portlets.user.accountingdashboard.shared.data.ScopeData;
|
||||||
|
|
||||||
|
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.web.bindery.event.shared.EventBus;
|
import com.google.web.bindery.event.shared.EventBus;
|
||||||
import com.gwtplatform.mvp.client.HasUiHandlers;
|
import com.gwtplatform.mvp.client.HasUiHandlers;
|
||||||
|
@ -31,6 +32,7 @@ public class FilterAreaPresenter extends PresenterWidget<FilterAreaPresenter.Fil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
private Controller controller;
|
private Controller controller;
|
||||||
|
|
||||||
|
@ -77,8 +79,32 @@ public class FilterAreaPresenter extends PresenterWidget<FilterAreaPresenter.Fil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkDate(Date dateStart, Date dateEnd) {
|
private boolean checkDate(String dateStart, String dateEnd) {
|
||||||
if (dateStart.compareTo(dateEnd) > 0) {
|
DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd");
|
||||||
|
|
||||||
|
Date dateStartD = null;
|
||||||
|
try {
|
||||||
|
logger.fine("DateTemp1: " + dateStart);
|
||||||
|
dateStartD = dateTimeFormat.parse(dateStart);
|
||||||
|
logger.fine("DateStart: " + dateStartD);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(Level.SEVERE, "Error in start date: " + e.getLocalizedMessage(), e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Date dateEndD = null;
|
||||||
|
try {
|
||||||
|
logger.fine("DateTemp2: " + dateEnd);
|
||||||
|
dateEndD = dateTimeFormat.parse(dateEnd);
|
||||||
|
logger.fine("DateEnd: " + dateEndD);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(Level.SEVERE, "Error in end date: " + e.getLocalizedMessage(), e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dateStartD.compareTo(dateEndD) > 0) {
|
||||||
controller.errorShow("Attention the start date must be less than the end date!");
|
controller.errorShow("Attention the start date must be less than the end date!");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -28,9 +28,7 @@ import com.google.gwt.user.cellview.client.CellTree;
|
||||||
import com.google.gwt.user.cellview.client.TreeNode;
|
import com.google.gwt.user.cellview.client.TreeNode;
|
||||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||||
import com.google.gwt.user.client.ui.Widget;
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
import com.google.gwt.user.datepicker.client.CalendarUtil;
|
|
||||||
import com.google.gwt.view.client.ListDataProvider;
|
import com.google.gwt.view.client.ListDataProvider;
|
||||||
|
|
||||||
import com.gwtplatform.mvp.client.ViewWithUiHandlers;
|
import com.gwtplatform.mvp.client.ViewWithUiHandlers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,9 +95,6 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
|
||||||
for (int i = 2015; i <= year; i++) {
|
for (int i = 2015; i <= year; i++) {
|
||||||
yearStart.addItem(String.valueOf(i));
|
yearStart.addItem(String.valueOf(i));
|
||||||
yearEnd.addItem(String.valueOf(i));
|
yearEnd.addItem(String.valueOf(i));
|
||||||
if (i == year) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
yearStart.setSelectedValue(String.valueOf(year));
|
yearStart.setSelectedValue(String.valueOf(year));
|
||||||
yearEnd.setSelectedValue(String.valueOf(year));
|
yearEnd.setSelectedValue(String.valueOf(year));
|
||||||
|
@ -130,7 +125,7 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
|
||||||
|
|
||||||
monthEnd = new ListBox();
|
monthEnd = new ListBox();
|
||||||
monthEnd.setMultipleSelect(false);
|
monthEnd.setMultipleSelect(false);
|
||||||
|
|
||||||
for (int i = 0; i < months.length; i++) {
|
for (int i = 0; i < months.length; i++) {
|
||||||
monthStart.addItem(months[i]);
|
monthStart.addItem(months[i]);
|
||||||
monthEnd.addItem(months[i]);
|
monthEnd.addItem(months[i]);
|
||||||
|
@ -192,37 +187,44 @@ public class FilterAreaView extends ViewWithUiHandlers<FilterAreaPresenter>
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestReport() {
|
private void requestReport() {
|
||||||
DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-M-dd");
|
String[] months = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsFull();
|
||||||
|
logger.log(Level.FINE, "Months: " + months.length);
|
||||||
|
|
||||||
String yearS = yearStart.getValue();
|
String yearS = yearStart.getValue();
|
||||||
String monthS = monthStart.getValue();
|
String monthS = monthStart.getValue();
|
||||||
|
|
||||||
Date dateStart = null;
|
String monthSN=null;
|
||||||
try {
|
for(int i=0; i<months.length; i++){
|
||||||
String dStart = yearS + "-" + monthS + "-01";
|
if(months[i].compareTo(monthS)==0){
|
||||||
logger.fine("DateTemp1: " + dStart);
|
int v=i+1;
|
||||||
dateStart = dateTimeFormat.parse(dStart);
|
if(v>9){
|
||||||
logger.fine("DateStart: " + dStart);
|
monthSN=""+v;
|
||||||
} catch (Exception e) {
|
} else {
|
||||||
logger.log(Level.SEVERE, "Error in start date: " + e.getLocalizedMessage(), e);
|
monthSN="0"+v;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String dateStart = yearS + "-" + monthSN + "-01";
|
||||||
|
logger.fine("DateStart: " + dateStart);
|
||||||
|
|
||||||
String yearE = yearEnd.getValue();
|
String yearE = yearEnd.getValue();
|
||||||
String monthE = monthEnd.getValue();
|
String monthE = monthEnd.getValue();
|
||||||
|
|
||||||
Date dateEnd = null;
|
String monthEN=null;
|
||||||
try {
|
for(int i=0; i<months.length; i++){
|
||||||
String dEnd = yearE + "-" + monthE + "-01";
|
if(months[i].compareTo(monthE)==0){
|
||||||
logger.fine("DateTemp2: " + dEnd);
|
int v=i+1;
|
||||||
dateEnd = dateTimeFormat.parse(dEnd);
|
if(v>9){
|
||||||
CalendarUtil.addMonthsToDate(dateEnd, 1);
|
monthEN=""+v;
|
||||||
CalendarUtil.addDaysToDate(dateEnd, -1);
|
} else {
|
||||||
logger.fine("DateEnd: " + dateEnd);
|
monthEN="0"+v;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
}
|
||||||
logger.log(Level.SEVERE, "Error in end date: " + e.getLocalizedMessage(), e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String dateEnd = yearE + "-" + monthEN + "-01";
|
||||||
|
logger.fine("DateEnd: " + dateEnd);
|
||||||
|
|
||||||
RequestReportData requestReportData = new RequestReportData(scopeData, dateStart, dateEnd);
|
RequestReportData requestReportData = new RequestReportData(scopeData, dateStart, dateEnd);
|
||||||
getUiHandlers().getReport(requestReportData);
|
getUiHandlers().getReport(requestReportData);
|
||||||
|
|
|
@ -21,11 +21,13 @@ public class Chart extends HTMLPanel {
|
||||||
+ "type='button' style='float:right;' data-toggle='dropdown'><span class='"
|
+ "type='button' style='float:right;' data-toggle='dropdown'><span class='"
|
||||||
+ resources.uiDataCss().uiDataIconSettings() + "'></span>" + "<span class='caret'></span>" + "</button>"
|
+ resources.uiDataCss().uiDataIconSettings() + "'></span>" + "<span class='caret'></span>" + "</button>"
|
||||||
+ "<ul class='" + resources.uiDataCss().uiDataChartMenuPosition() + " dropdown-menu'>" + "<li><a id='"
|
+ "<ul class='" + resources.uiDataCss().uiDataChartMenuPosition() + " dropdown-menu'>" + "<li><a id='"
|
||||||
+ name + "_ExportPNG' href='#' download='" + reportElementData.getLabel() + ".png'>Export PNG</a>"
|
+ name + "_ExportJPEG' href='#' download='" + reportElementData.getLabel() + ".jpeg'>Export JPEG</a>"
|
||||||
+ "</li>" + "<li><a id='" + name + "_ExportJPEG' href='#' download='" + reportElementData.getLabel()
|
+ "</li>" + "<li><a id='" + name + "_ExportPNG' href='#' download='" + reportElementData.getLabel()
|
||||||
+ ".jpeg'>Export JPEG</a>" + "</li>" + "<li><a id='" + name + "_ExportPDF' href='#' download='"
|
+ ".png'>Export PNG</a>" + "</li>" + "<li><a id='" + name + "_ExportPDF' href='#' download='"
|
||||||
+ reportElementData.getLabel() + ".pdf'>Export PDF</a>" + "</li>" + "</ul>" + "</div>" + "<canvas id="
|
+ reportElementData.getLabel() + ".pdf'>Export PDF</a>" + "</li>" + "<li><a id='" + name
|
||||||
+ name + " class='" + resources.uiDataCss().uiDataChartCanvas() + "'></canvas>");
|
+ "_ExportCSV' href='#' download='" + reportElementData.getLabel() + ".csv'>Export CSV</a>" + "</li>"
|
||||||
|
+ "</ul>" + "</div>" + "<canvas id=" + name + " class='" + resources.uiDataCss().uiDataChartCanvas()
|
||||||
|
+ "'></canvas>");
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.reportElementData = reportElementData;
|
this.reportElementData = reportElementData;
|
||||||
this.addStyleName(resources.uiDataCss().uiDataChartWrapper());
|
this.addStyleName(resources.uiDataCss().uiDataChartWrapper());
|
||||||
|
@ -70,13 +72,6 @@ public class Chart extends HTMLPanel {
|
||||||
console.log('This: ' + this);
|
console.log('This: ' + this);
|
||||||
var name = this.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::name;
|
var name = this.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::name;
|
||||||
|
|
||||||
//Export PNG
|
|
||||||
var elementNamePNG = name + '_ExportPNG';
|
|
||||||
console.log('ExportPNG search: ' + elementNamePNG);
|
|
||||||
var exportPNGElement = $doc.getElementById(elementNamePNG);
|
|
||||||
console.log('ExportPNGElement: ' + exportPNGElement);
|
|
||||||
exportPNGElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveImagePNG(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this);
|
|
||||||
|
|
||||||
//Export JPEG
|
//Export JPEG
|
||||||
var elementNameJPEG = name + '_ExportJPEG';
|
var elementNameJPEG = name + '_ExportJPEG';
|
||||||
console.log('ExportJPEG search: ' + elementNameJPEG);
|
console.log('ExportJPEG search: ' + elementNameJPEG);
|
||||||
|
@ -84,6 +79,13 @@ public class Chart extends HTMLPanel {
|
||||||
console.log('ExportJPEGElement: ' + exportJPEGElement);
|
console.log('ExportJPEGElement: ' + exportJPEGElement);
|
||||||
exportJPEGElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveImageJPEG(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this);
|
exportJPEGElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveImageJPEG(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this);
|
||||||
|
|
||||||
|
//Export PNG
|
||||||
|
var elementNamePNG = name + '_ExportPNG';
|
||||||
|
console.log('ExportPNG search: ' + elementNamePNG);
|
||||||
|
var exportPNGElement = $doc.getElementById(elementNamePNG);
|
||||||
|
console.log('ExportPNGElement: ' + exportPNGElement);
|
||||||
|
exportPNGElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveImagePNG(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this);
|
||||||
|
|
||||||
//Export PDF
|
//Export PDF
|
||||||
var elementNamePDF = name + '_ExportPDF';
|
var elementNamePDF = name + '_ExportPDF';
|
||||||
console.log('ExportPDF search: ' + elementNamePDF);
|
console.log('ExportPDF search: ' + elementNamePDF);
|
||||||
|
@ -91,6 +93,38 @@ public class Chart extends HTMLPanel {
|
||||||
console.log('ExportPDFElement: ' + exportPDFElement);
|
console.log('ExportPDFElement: ' + exportPDFElement);
|
||||||
exportPDFElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveFilePDF(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;Ljava/lang/String;)(this,exportPDFElement.download);
|
exportPDFElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveFilePDF(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;Ljava/lang/String;)(this,exportPDFElement.download);
|
||||||
|
|
||||||
|
//Export CSV
|
||||||
|
var elementNameCSV = name + '_ExportCSV';
|
||||||
|
console.log('ExportCSV search: ' + elementNameCSV);
|
||||||
|
var exportCSVElement = $doc.getElementById(elementNameCSV);
|
||||||
|
console.log('ExportCSVElement: ' + exportCSVElement);
|
||||||
|
exportCSVElement.onclick = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::saveFileCSV(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(this);
|
||||||
|
|
||||||
|
}-*/;
|
||||||
|
|
||||||
|
private static native void saveImageJPEG(Chart chart)/*-{
|
||||||
|
console.log('saveImageJPEG()');
|
||||||
|
var name = chart.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::name;
|
||||||
|
console.log('Element name: ' + name);
|
||||||
|
var canvas = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::getCanvas(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(chart);
|
||||||
|
return function() {
|
||||||
|
console.log('Save file jpeg');
|
||||||
|
//Set Background White
|
||||||
|
var w = canvas.width;
|
||||||
|
var h = canvas.height;
|
||||||
|
var ctx = canvas.getContext('2d');
|
||||||
|
var data = ctx.getImageData(0, 0, w, h);
|
||||||
|
var compositeOperation = ctx.globalCompositeOperation;
|
||||||
|
ctx.globalCompositeOperation = "destination-over";
|
||||||
|
ctx.fillStyle = '#ffffff';
|
||||||
|
ctx.fillRect(0, 0, w, h);
|
||||||
|
var image = canvas.toDataURL("image/jpeg").replace("image/jpeg",
|
||||||
|
"image/octet-stream");
|
||||||
|
ctx.clearRect(0, 0, w, h);
|
||||||
|
ctx.putImageData(data, 0, 0);
|
||||||
|
ctx.globalCompositeOperation = compositeOperation;
|
||||||
|
this.href = image;
|
||||||
|
};
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
private static native void saveImagePNG(Chart chart)/*-{
|
private static native void saveImagePNG(Chart chart)/*-{
|
||||||
|
@ -102,26 +136,11 @@ public class Chart extends HTMLPanel {
|
||||||
console.log('Save file png');
|
console.log('Save file png');
|
||||||
var image = canvas.toDataURL("image/png").replace("image/png",
|
var image = canvas.toDataURL("image/png").replace("image/png",
|
||||||
"image/octet-stream");
|
"image/octet-stream");
|
||||||
console.log('Image url: ' + image);
|
|
||||||
this.href = image;
|
this.href = image;
|
||||||
//window.open(image, '_blank');
|
//window.open(image, '_blank');
|
||||||
};
|
};
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
private static native void saveImageJPEG(Chart chart)/*-{
|
|
||||||
console.log('saveImageJPEG()');
|
|
||||||
var name = chart.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::name;
|
|
||||||
console.log('Element name: ' + name);
|
|
||||||
var canvas = @org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::getCanvas(Lorg/gcube/portlets/user/accountingdashboard/client/application/mainarea/report/chartjs/Chart;)(chart);
|
|
||||||
return function() {
|
|
||||||
console.log('Save file jpeg');
|
|
||||||
var image = canvas.toDataURL("image/jpeg").replace("image/jpeg",
|
|
||||||
"image/octet-stream");
|
|
||||||
console.log('Image url: ' + image);
|
|
||||||
this.href = image;
|
|
||||||
};
|
|
||||||
}-*/;
|
|
||||||
|
|
||||||
private static native void saveFilePDF(Chart chart, String filename)/*-{
|
private static native void saveFilePDF(Chart chart, String filename)/*-{
|
||||||
console.log('saveFilePDF()');
|
console.log('saveFilePDF()');
|
||||||
var name = chart.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::name;
|
var name = chart.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::name;
|
||||||
|
@ -136,12 +155,54 @@ public class Chart extends HTMLPanel {
|
||||||
doc.addImage(image, 'JPEG', 10, 10, 280, 150);
|
doc.addImage(image, 'JPEG', 10, 10, 280, 150);
|
||||||
doc.save(filename);
|
doc.save(filename);
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//console.log('Image url: ' + image);
|
|
||||||
//this.href = image;
|
|
||||||
};
|
};
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
|
private static native void saveFileCSV(Chart chart)/*-{
|
||||||
|
console.log('saveFileCSV()');
|
||||||
|
var reportElementData = chart.@org.gcube.portlets.user.accountingdashboard.client.application.mainarea.report.chartjs.Chart::reportElementData;
|
||||||
|
console.log('ReportElementData: ' + reportElementData);
|
||||||
|
return function() {
|
||||||
|
console.log('Save file csv');
|
||||||
|
|
||||||
|
var serieses = reportElementData.getSerieses();
|
||||||
|
console.log('Serieses: ' + serieses);
|
||||||
|
var seriesesLen = serieses.length;
|
||||||
|
console.log('Serieses lenght: ' + seriesesLen);
|
||||||
|
|
||||||
|
var csvContent = "data:text/csv;charset=utf-8,";
|
||||||
|
for (var i = 0; i < seriesesLen; i++) {
|
||||||
|
var seriesData = serieses[i];
|
||||||
|
var dataRow = seriesData.getDataRow();
|
||||||
|
var dataRowLen = dataRow.length;
|
||||||
|
|
||||||
|
var dataArray = [];
|
||||||
|
if (i == 0) {
|
||||||
|
var heading = "Date";
|
||||||
|
var datasetRow = seriesData.getLabel();
|
||||||
|
for (var j = 0; j < dataRowLen; j++) {
|
||||||
|
var recordData = dataRow[j];
|
||||||
|
heading += "," + recordData.getX();
|
||||||
|
datasetRow += "," + recordData.getY();
|
||||||
|
}
|
||||||
|
csvContent += heading + "\r\n";
|
||||||
|
csvContent += datasetRow + "\r\n";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
var datasetRow = seriesData.getLabel();
|
||||||
|
for (var j = 0; j < dataRowLen; j++) {
|
||||||
|
var recordData = dataRow[j];
|
||||||
|
datasetRow += "," + recordData.getY();
|
||||||
|
}
|
||||||
|
csvContent += datasetRow + "\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.href = csvContent;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}-*/;
|
||||||
|
|
||||||
private native void redrawChart() /*-{
|
private native void redrawChart() /*-{
|
||||||
console.log('RedrawChart()');
|
console.log('RedrawChart()');
|
||||||
|
|
||||||
|
@ -190,7 +251,6 @@ public class Chart extends HTMLPanel {
|
||||||
console.log('ReportElementData: ' + reportElementData);
|
console.log('ReportElementData: ' + reportElementData);
|
||||||
|
|
||||||
var serieses = reportElementData.getSerieses();
|
var serieses = reportElementData.getSerieses();
|
||||||
console.log('Serieses: ' + serieses);
|
|
||||||
var seriesesLen = serieses.length;
|
var seriesesLen = serieses.length;
|
||||||
console.log('Serieses lenght: ' + seriesesLen);
|
console.log('Serieses lenght: ' + seriesesLen);
|
||||||
|
|
||||||
|
@ -242,8 +302,6 @@ public class Chart extends HTMLPanel {
|
||||||
var yAxisLabel = reportElementData.getyAxis();
|
var yAxisLabel = reportElementData.getyAxis();
|
||||||
|
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
ctx.fillStyle = 'white';
|
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
||||||
console.log('Create chart');
|
console.log('Create chart');
|
||||||
|
|
||||||
var chart = new Chart(ctx, {
|
var chart = new Chart(ctx, {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.gcube.portlets.user.accountingdashboard.server.accounting;
|
package org.gcube.portlets.user.accountingdashboard.server.accounting;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ import org.gcube.portlets.user.accountingdashboard.shared.exception.ServiceExcep
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Giancarlo Panichi
|
* @author Giancarlo Panichi
|
||||||
|
@ -116,12 +118,44 @@ public class AccountingService {
|
||||||
ScopeDescriptor scopeDescriptor = searchScopeDescriptor(httpServletRequest,
|
ScopeDescriptor scopeDescriptor = searchScopeDescriptor(httpServletRequest,
|
||||||
requestReportData.getScopeData());
|
requestReportData.getScopeData());
|
||||||
|
|
||||||
Date dateFrom = requestReportData.getDateFrom();
|
String dateStart = requestReportData.getDateFrom();
|
||||||
Date dateTo = requestReportData.getDateTo();
|
String dateEnd = requestReportData.getDateTo();
|
||||||
|
|
||||||
logger.debug("getReportByScope(): [ScopeDescriptor=" + scopeDescriptor + ", dateFrom=" + dateFrom
|
if (dateStart == null || dateStart.isEmpty() || dateEnd == null || dateEnd.isEmpty()) {
|
||||||
+ ", dateTo=" + dateTo + ", measureResolution=" + MeasureResolution.MONTHLY + "]");
|
logger.error("Invalid date: [dateStart=" + dateStart + ", dateEnd=" + dateEnd + "]");
|
||||||
Report report = dao.getReportByScope(scopeDescriptor, dateFrom, dateTo, MeasureResolution.MONTHLY);
|
throw new ServiceException(
|
||||||
|
"Invalid format: [dateStart=" + dateStart + ", dateEnd=" + dateEnd + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
GregorianCalendar dateFrom;
|
||||||
|
GregorianCalendar dateTo;
|
||||||
|
try {
|
||||||
|
int yearS = Integer.parseInt(dateStart.substring(0, 4));
|
||||||
|
logger.debug("yearS: " + yearS);
|
||||||
|
int monthS = Integer.parseInt(dateStart.substring(5, 7)) - 1;
|
||||||
|
logger.debug("monthS: " + monthS);
|
||||||
|
int dayS = Integer.parseInt(dateStart.substring(8, 10));
|
||||||
|
logger.debug("dayS: " + dayS);
|
||||||
|
|
||||||
|
dateFrom = new GregorianCalendar(yearS, monthS, dayS);
|
||||||
|
|
||||||
|
int yearE = Integer.parseInt(dateEnd.substring(0, 4));
|
||||||
|
int monthE = Integer.parseInt(dateEnd.substring(5, 7)) - 1;
|
||||||
|
int dayE = Integer.parseInt(dateEnd.substring(8, 10));
|
||||||
|
dateTo = new GregorianCalendar(yearE, monthE, dayE);
|
||||||
|
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.error("Invalid date format: [dateStart=" + dateStart + ", dateEnd=" + dateEnd + "]");
|
||||||
|
throw new ServiceException(
|
||||||
|
"Invalid date format: [dateStart=" + dateStart + ", dateEnd=" + dateEnd + "]");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("getReportByScope(): [ScopeDescriptor=" + scopeDescriptor + ", dateFrom="
|
||||||
|
+ dateFrom.getTime() + ", dateTo=" + dateTo.getTime() + ", measureResolution="
|
||||||
|
+ MeasureResolution.MONTHLY + "]");
|
||||||
|
Report report = dao.getReportByScope(scopeDescriptor, dateFrom.getTime(), dateTo.getTime(),
|
||||||
|
MeasureResolution.MONTHLY);
|
||||||
|
|
||||||
logger.debug("Report: " + report);
|
logger.debug("Report: " + report);
|
||||||
ReportDataBuilder reportDataBuilder = new ReportDataBuilder(report);
|
ReportDataBuilder reportDataBuilder = new ReportDataBuilder(report);
|
||||||
|
@ -180,7 +214,8 @@ public class AccountingService {
|
||||||
int i) throws ServiceException {
|
int i) throws ServiceException {
|
||||||
try {
|
try {
|
||||||
for (ScopeDescriptor child : scopeDescriptor.getChildren()) {
|
for (ScopeDescriptor child : scopeDescriptor.getChildren()) {
|
||||||
if (child.getName()!=null&&!child.getName().isEmpty()&&child.getName().compareTo(searchPath[i]) == 0) {
|
if (child.getName() != null && !child.getName().isEmpty()
|
||||||
|
&& child.getName().compareTo(searchPath[i]) == 0) {
|
||||||
i++;
|
i++;
|
||||||
if (i < searchPath.length) {
|
if (i < searchPath.length) {
|
||||||
return searchInChild(child, scopeToSearch, searchPath, i);
|
return searchInChild(child, scopeToSearch, searchPath, i);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.gcube.portlets.user.accountingdashboard.shared.data;
|
package org.gcube.portlets.user.accountingdashboard.shared.data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -12,14 +11,14 @@ public class RequestReportData implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -7428707426843173730L;
|
private static final long serialVersionUID = -7428707426843173730L;
|
||||||
private ScopeData scopeData;
|
private ScopeData scopeData;
|
||||||
private Date dateFrom;
|
private String dateFrom;
|
||||||
private Date dateTo;
|
private String dateTo;
|
||||||
|
|
||||||
public RequestReportData() {
|
public RequestReportData() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestReportData(ScopeData scopeData, Date dateFrom, Date dateTo) {
|
public RequestReportData(ScopeData scopeData, String dateFrom, String dateTo) {
|
||||||
super();
|
super();
|
||||||
this.scopeData = scopeData;
|
this.scopeData = scopeData;
|
||||||
this.dateFrom = dateFrom;
|
this.dateFrom = dateFrom;
|
||||||
|
@ -34,19 +33,19 @@ public class RequestReportData implements Serializable {
|
||||||
this.scopeData = scopeData;
|
this.scopeData = scopeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDateFrom() {
|
public String getDateFrom() {
|
||||||
return dateFrom;
|
return dateFrom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDateFrom(Date dateFrom) {
|
public void setDateFrom(String dateFrom) {
|
||||||
this.dateFrom = dateFrom;
|
this.dateFrom = dateFrom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDateTo() {
|
public String getDateTo() {
|
||||||
return dateTo;
|
return dateTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDateTo(Date dateTo) {
|
public void setDateTo(String dateTo) {
|
||||||
this.dateTo = dateTo;
|
this.dateTo = dateTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue