dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13818
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4536: Impl export to XLS for web pivot table
------------------------------------------------------------
revno: 4536
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-09-07 13:00:47 +0200
message:
Impl export to XLS for web pivot table
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTable.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTableService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java
dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableAction.java
dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTable.java 2011-04-01 09:57:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTable.java 2011-09-07 11:00:47 +0000
@@ -29,11 +29,14 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.hisp.dhis.aggregation.AggregatedIndicatorValue;
+import org.hisp.dhis.common.AbstractIdentifiableObject;
import org.hisp.dhis.common.AggregatedValue;
-import org.hisp.dhis.common.AbstractIdentifiableObject;
+import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
@@ -43,6 +46,8 @@
*/
public class PivotTable
{
+ public static final String SEPARATOR = "-";
+
private List<? extends AbstractIdentifiableObject> indicators = new ArrayList<AbstractIdentifiableObject>();
private List<Period> periods = new ArrayList<Period>();
@@ -60,6 +65,31 @@
}
// -------------------------------------------------------------------------
+ // Logic
+ // -------------------------------------------------------------------------
+
+ public Map<String, Double> getValueMap()
+ {
+ Map<String, Double> map = new HashMap<String, Double>();
+
+ for ( AggregatedValue value : indicatorValues )
+ {
+ String key = value.getElementId() + SEPARATOR + value.getPeriodId() + SEPARATOR + value.getOrganisationUnitId();
+
+ map.put( key, value.getValue() );
+ }
+
+ return map;
+ }
+
+ public static String getKey( IdentifiableObject element, Period period, OrganisationUnit unit )
+ {
+ String key = element.getId() + SEPARATOR + period.getId() + SEPARATOR + unit.getId();
+
+ return key;
+ }
+
+ // -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTableService.java 2011-03-15 23:26:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/pivottable/PivotTableService.java 2011-09-07 11:00:47 +0000
@@ -1,5 +1,9 @@
package org.hisp.dhis.pivottable;
+import java.util.List;
+
+import org.hisp.dhis.common.Grid;
+
/*
* Copyright (c) 2004-2010, University of Oslo
@@ -49,4 +53,6 @@
* @return a PivotTable object.
*/
PivotTable getPivotTable( int dataType, int groupId, String periodTypeName, String startDate, String endDate, int level );
+
+ List<Grid> getGrids( PivotTable pivotTable );
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java 2011-08-24 20:25:14 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/pivottable/impl/DefaultPivotTableService.java 2011-09-07 11:00:47 +0000
@@ -34,10 +34,14 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.Map;
import org.hisp.dhis.aggregation.AggregatedDataValueService;
import org.hisp.dhis.common.AggregatedValue;
import org.hisp.dhis.common.AbstractIdentifiableObject;
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.GridHeader;
+import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
@@ -52,6 +56,7 @@
import org.hisp.dhis.period.comparator.AscendingPeriodComparator;
import org.hisp.dhis.pivottable.PivotTable;
import org.hisp.dhis.pivottable.PivotTableService;
+import org.hisp.dhis.system.grid.ListGrid;
import org.hisp.dhis.system.util.ConversionUtils;
/**
@@ -179,4 +184,40 @@
return pivotTable;
}
+
+
+ public List<Grid> getGrids( PivotTable pivotTable )
+ {
+ List<Grid> grids = new ArrayList<Grid>();
+
+ Map<String, Double> valueMap = pivotTable.getValueMap();
+
+ for ( Period period : pivotTable.getPeriods() )
+ {
+ Grid grid = new ListGrid().setTitle( period.getName() );
+
+ grid.addHeader( new GridHeader( "Organisation unit", false, true ) );
+
+ for ( IdentifiableObject element : pivotTable.getIndicators() )
+ {
+ grid.addHeader( new GridHeader( element.getName(), false, false ) );
+ }
+
+ for ( OrganisationUnit unit : pivotTable.getOrganisationUnits() )
+ {
+ grid.addRow();
+
+ grid.addValue( unit.getName() );
+
+ for ( IdentifiableObject element : pivotTable.getIndicators() )
+ {
+ grid.addValue( valueMap.get( PivotTable.getKey( element, period, unit ) ) );
+ }
+ }
+
+ grids.add( grid );
+ }
+
+ return grids;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableAction.java 2011-03-15 23:26:14 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableAction.java 2011-09-07 11:00:47 +0000
@@ -27,6 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.List;
+
+import org.hisp.dhis.common.Grid;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.pivottable.PivotTable;
@@ -41,6 +44,8 @@
public class GetPivotTableAction
implements Action
{
+ private static final String DEFAULT_TYPE = "json";
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -105,6 +110,13 @@
this.organisationUnitId = organisationUnitId;
}
+ private String type;
+
+ public void setType( String type )
+ {
+ this.type = type;
+ }
+
// -------------------------------------------------------------------------
// Output
// -------------------------------------------------------------------------
@@ -115,6 +127,13 @@
{
return pivotTable;
}
+
+ private List<Grid> grids;
+
+ public List<Grid> getGrids()
+ {
+ return grids;
+ }
// -------------------------------------------------------------------------
// Action implementation
@@ -128,7 +147,12 @@
{
period.setName( format.formatPeriod( period ) );
}
-
- return SUCCESS;
+
+ if ( type != null )
+ {
+ grids = pivotTableService.getGrids( pivotTable );
+ }
+
+ return type != null ? type : DEFAULT_TYPE;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-08-19 12:08:26 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-09-07 11:00:47 +0000
@@ -430,8 +430,9 @@
<param name="javascripts">../dhis-web-commons/oust/oust.js,javascript/pivot.js</param>
</action>
- <action name="getPivotTable" class="org.hisp.dhis.reporting.pivottable.action.GetPivotTableAction">
- <result name="success" type="velocity-json">/dhis-web-reporting/responsePivotTable.vm</result>
+ <action name="getPivotTable" class="org.hisp.dhis.reporting.pivottable.action.GetPivotTableAction">
+ <result name="xls" type="gridXlsResult"/>
+ <result name="json" type="velocity-json">/dhis-web-reporting/responsePivotTable.vm</result>
<param name="onExceptionReturn">plainTextError</param>
</action>
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js 2011-09-03 18:23:12 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js 2011-09-07 11:00:47 +0000
@@ -20,6 +20,8 @@
var organisationUnitId = -1;
+var currentParams = null;
+
var DATA_TYPE_INDICATOR = 0;
var DATA_TYPE_DATA_ELEMENT = 1;
var currentDataType = DATA_TYPE_INDICATOR;
@@ -69,14 +71,16 @@
showLoader();
- $.getJSON( url, {
+ currentParams = {
"dataType" : dataType,
"groupId" : groupId,
"periodTypeName" : periodTypeName,
"startDate" : startDate,
"endDate" : endDate,
"organisationUnitId" : organisationUnitId
- }, function( json )
+ };
+
+ $.getJSON( url, currentParams, function( json )
{
var pivot = json.pivotTable;
@@ -97,6 +101,22 @@
}
}
+function exportXls()
+{
+ if ( currentParams != null )
+ {
+ var url = "getPivotTable.action?dataType=" + currentParams.dataType +
+ "&groupId=" + currentParams.groupId +
+ "&periodTypeName=" + currentParams.periodTypeName +
+ "&startDate=" + currentParams.startDate +
+ "&endDate=" + currentParams.endDate +
+ "&organisationUnitId=" + currentParams.organisationUnitId +
+ "&type=xls";
+
+ window.location.href = url;
+ }
+}
+
/**
* This method is called from the UI and is responsible for pivoting the table.
*/
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm 2011-09-03 18:23:12 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm 2011-09-07 11:00:47 +0000
@@ -86,8 +86,9 @@
<!-- Control panel -->
<div id="control">
-<input type="button" value='$i18n.getString( "data" )' style="width:120px" onclick="showCriteria()" />
-<input type="button" value='$i18n.getString( "pivot" )' style="width:120px" onclick="showPivot()" />
+<input type="button" value='$i18n.getString( "data" )' style="width:110px" onclick="showCriteria()" />
+<input type="button" value='$i18n.getString( "pivot" )' style="width:110px" onclick="showPivot()" />
+<input type="button" value="$i18n.getString( 'get_report_as_xls' )" onclick="exportXls()" style="width:130px">
<label id="dataLabel" style="color:#606060"></label>
</div>