=== 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 indicators = new ArrayList(); private List periods = new ArrayList(); @@ -60,6 +65,31 @@ } // ------------------------------------------------------------------------- + // Logic + // ------------------------------------------------------------------------- + + public Map getValueMap() + { + Map map = new HashMap(); + + 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 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 getGrids( PivotTable pivotTable ) + { + List grids = new ArrayList(); + + Map 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 grids; + + public List 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 @@ ../dhis-web-commons/oust/oust.js,javascript/pivot.js - - /dhis-web-reporting/responsePivotTable.vm + + + /dhis-web-reporting/responsePivotTable.vm plainTextError === 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 @@
- -  + + +