=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java 2010-12-25 16:43:02 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java 2010-12-26 18:47:16 +0000 @@ -92,11 +92,11 @@ Grid grid = getOrganisationUnitDistribution( groupSet, organisationUnit, true ); - Assert.isTrue( grid != null && grid.getHeight() == 2 ); + Assert.isTrue( grid != null && grid.getHeight() == 1 ); for ( int i = 1; i < grid.getWidth(); i++ ) // Skip name column { - categoryValues.put( grid.getRow( 0 ).get( i ), Double.valueOf( grid.getRow( 1 ).get( i ) ) ); + categoryValues.put( grid.getHeaders().get( i ), Double.valueOf( grid.getRow( 0 ).get( i ) ) ); } String title = groupSet.getName() + TITLE_SEP + organisationUnit.getName(); === added file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java' --- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java 2010-12-26 18:47:16 +0000 @@ -0,0 +1,127 @@ +package org.hisp.dhis.result; + +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.io.OutputStream; +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.struts2.ServletActionContext; +import org.hisp.dhis.common.Grid; +import org.hisp.dhis.system.util.CodecUtils; +import org.hisp.dhis.util.ContextUtils; + +import com.lowagie.text.Document; +import com.lowagie.text.pdf.PdfPTable; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.Result; + +import static org.hisp.dhis.system.util.PDFUtils.*; + +/** + * @author Lars Helge Overland + */ +public class GridPdfResult + implements Result +{ + private static final String DEFAULT_FILENAME = "Grid.pdf"; + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private Grid grid; + + public void setGrid( Grid grid ) + { + this.grid = grid; + } + + // ------------------------------------------------------------------------- + // Result implementation + // ------------------------------------------------------------------------- + + @Override + public void execute( ActionInvocation invocation ) + throws Exception + { + // --------------------------------------------------------------------- + // Get grid + // --------------------------------------------------------------------- + + Grid _grid = (Grid) invocation.getStack().findValue( "grid" ); + + grid = _grid != null ? _grid : grid; + + // --------------------------------------------------------------------- + // Configure response + // --------------------------------------------------------------------- + + HttpServletResponse response = ServletActionContext.getResponse(); + + OutputStream out = response.getOutputStream(); + + String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".pdf"; + + ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, true, filename ); + + // --------------------------------------------------------------------- + // Write PDF to output stream + // --------------------------------------------------------------------- + + Document document = openDocument( out ); + + PdfPTable table = new PdfPTable( grid.getWidth() ); + + table.setHeaderRows( 1 ); + + table.addCell( getHeader2Cell( grid.getTitle(), grid.getWidth() ) ); + table.addCell( getCell( grid.getWidth(), 8 ) ); + + for ( String header : grid.getHeaders() ) + { + table.addCell( getItalicCell( header, 1 ) ); + } + + table.addCell( getCell( grid.getWidth(), 8 ) ); + + for ( List row : grid.getRows() ) + { + for ( String col : row ) + { + table.addCell( getTextCell( col ) ); + } + } + + addTableToDocument( document, table ); + + closeDocument( document ); + } +} === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml' --- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml 2010-12-26 15:38:45 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml 2010-12-26 18:47:16 +0000 @@ -35,6 +35,8 @@ class="org.hisp.dhis.result.GridCsvResult" /> + === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionAction.java 2010-12-25 14:36:08 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionAction.java 2010-12-26 18:47:16 +0000 @@ -27,18 +27,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hisp.dhis.common.Grid; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet; -import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupSetNameComparator; import org.hisp.dhis.orgunitdistribution.OrgUnitDistributionService; import org.hisp.dhis.oust.manager.SelectionTreeManager; @@ -50,10 +45,10 @@ public class GetOrgUnitDistributionAction implements Action { - private static final Comparator GROUPSET_COMPARATOR = new OrganisationUnitGroupSetNameComparator(); - private static final Log log = LogFactory.getLog( GetOrgUnitDistributionAction.class ); + private static final String DEFAULT_TYPE = "html"; + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -89,25 +84,18 @@ { this.groupSetId = groupSetId; } + + private String type; + + public void setType( String type ) + { + this.type = type; + } // ------------------------------------------------------------------------- // Output // ------------------------------------------------------------------------- - private List groupSets; - - public List getGroupSets() - { - return groupSets; - } - - private OrganisationUnitGroupSet selectedGroupSet; - - public OrganisationUnitGroupSet getSelectedGroupSet() - { - return selectedGroupSet; - } - private Grid grid; public Grid getGrid() @@ -121,21 +109,19 @@ public String execute() { - groupSets = new ArrayList( organisationUnitGroupService.getAllOrganisationUnitGroupSets() ); - - Collections.sort( groupSets, GROUPSET_COMPARATOR ); - - OrganisationUnit selectedOrganisationUnit = selectionTreeManager.getReloadedSelectedOrganisationUnit(); + type = StringUtils.defaultIfEmpty( type, DEFAULT_TYPE ); + + OrganisationUnit unit = selectionTreeManager.getReloadedSelectedOrganisationUnit(); if ( groupSetId != null && groupSetId > 0 ) { - selectedGroupSet = organisationUnitGroupService.getOrganisationUnitGroupSet( groupSetId ); + OrganisationUnitGroupSet groupSet = organisationUnitGroupService.getOrganisationUnitGroupSet( groupSetId ); - log.info( "Get distribution for group set: " + selectedGroupSet + " and organisation unit: " + selectedOrganisationUnit ); + log.info( "Get distribution for group set: " + groupSet + " and organisation unit: " + unit ); - grid = distributionService.getOrganisationUnitDistribution( selectedGroupSet, selectedOrganisationUnit, false ); + grid = distributionService.getOrganisationUnitDistribution( groupSet, unit, false ); } - return SUCCESS; + return type; } } === added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionOptionsAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionOptionsAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/orgunitdistribution/action/GetOrgUnitDistributionOptionsAction.java 2010-12-26 18:47:16 +0000 @@ -0,0 +1,83 @@ +package org.hisp.dhis.reporting.orgunitdistribution.action; + +/* + * Copyright (c) 2004-2009, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; +import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet; +import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupSetNameComparator; + +import com.opensymphony.xwork2.Action; + +/** + * @author Lars Helge Overland + */ +public class GetOrgUnitDistributionOptionsAction + implements Action +{ + private static final Comparator GROUPSET_COMPARATOR = new OrganisationUnitGroupSetNameComparator(); + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private OrganisationUnitGroupService organisationUnitGroupService; + + public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService ) + { + this.organisationUnitGroupService = organisationUnitGroupService; + } + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private List groupSets; + + public List getGroupSets() + { + return groupSets; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + { + groupSets = new ArrayList( organisationUnitGroupService.getAllOrganisationUnitGroupSets() ); + + Collections.sort( groupSets, GROUPSET_COMPARATOR ); + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2010-12-26 15:38:45 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2010-12-26 18:47:16 +0000 @@ -505,4 +505,12 @@ + + + + + === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties 2010-12-26 15:38:45 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties 2010-12-26 18:47:16 +0000 @@ -294,11 +294,15 @@ category_y_available_periods = Value (Y) - Available periods get_current_design = Get current design distribution_report = Distribution Report +please_select_org_unit = Please select organisation unit +please_select_group_set = Please select group set select_group_set = Select group set orgunit_distribution = Organisation unit distribution report get_report = Get report get_chart = Get chart group_set = Group set +select_org_unit = Select organisation unit get_report = Get report get_report_as_xls = Download as Excel -get_report_as_csv = Download as CSV \ No newline at end of file +get_report_as_csv = Download as CSV +get_report_as_pdf = Download as PDF \ No newline at end of file === 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 2010-12-26 15:38:45 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2010-12-26 18:47:16 +0000 @@ -390,7 +390,14 @@ - + + + + + /dhis-web-commons/ajax/htmlGrid.vm + + + /main.vm /dhis-web-reporting/viewOrgUnitDistribution.vm /dhis-web-reporting/menu.vm === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/orgUnitDistribution.js' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/orgUnitDistribution.js 2010-12-14 11:36:39 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/orgUnitDistribution.js 2010-12-26 18:47:16 +0000 @@ -1,9 +1,63 @@ +var selectedOrganisationUnit = null; + +function organisationUnitSelected( units ) { + if ( units && units[0] ) { + selectedOrganisationUnit = units[0]; + } + else { + selectedOrganisationUnit = null; + } +} + +function displayOrgUnitDistribution() { + alert(selectedOrganisationUnit); + if ( inputInvalid() ) { + return false; + } + + $( "#chartDiv" ).hide(); + $( "#tableDiv" ).show(); + var groupSetId = $( "#groupSetId" ).val(); + var url = "getOrgUnitDistribution.action?groupSetId=" + groupSetId + "&type=html"; + $( "#tableDiv" ).load( url, pageInit ); +} + +function getOrgUnitDistribution( type ) { + if ( inputInvalid() ) { + return false; + } + + var groupSetId = $( "#groupSetId" ).val(); + var url = "getOrgUnitDistribution.action?groupSetId=" + groupSetId + "&type=" + type; + window.location.href = url; +} + function displayOrgUnitDistributionChart() { + if ( inputInvalid() ) { + return false; + } + + $( "#tableDiv" ).hide(); $( "#chartDiv" ).show(); - $( "#tableDiv" ).hide(); var groupSetId = $( "#groupSetId" ).val(); var random = getRandomNumber(); var source = "getOrgUnitDistributionChart.action?groupSetId=" + groupSetId + "&r=" + random; $( "#chartImg" ).attr( "src", source ); } + +function inputInvalid() { + var groupSetId = $( "#groupSetId" ).val(); + + if ( groupSetId == null || groupSetId == 0 ) { + setHeaderDelayMessage( i18n_select_group_set ); + return true; + } + + if ( selectedOrganisationUnit == null || selectedOrganisationUnit == "" ) { + setHeaderDelayMessage( i18n_select_org_unit ); + return true; + } + + return false; +} === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewOrgUnitDistribution.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewOrgUnitDistribution.vm 2010-12-25 14:36:08 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewOrgUnitDistribution.vm 2010-12-26 18:47:16 +0000 @@ -3,74 +3,50 @@ -
- - - - - - - - - + + + + + - - - - - - - +

+ + +

+ + +
+ + + + +
$i18n.getString( "criteria" )
$i18n.getString( "select_org_unit" )
+
+
+
-
-
- -#if( $grid ) - -
- - - - - -#foreach( $header in $grid.getHeaders() ) - -#end - - - - -#foreach( $row in $grid.getRows() ) - -#foreach( $col in $row ) - -#end - -#end - - -
$!encoder.htmlEncode( $header )
$!encoder.htmlEncode( $col )
- -
- -#end +
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm 2010-12-26 15:38:45 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewTableForm.vm 2010-12-26 18:47:16 +0000 @@ -17,7 +17,7 @@ - +
$i18n.getString( "name" )