=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2011-05-30 19:10:22 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2011-05-31 11:39:19 +0000 @@ -102,7 +102,7 @@ { Document document = openDocument( out ); - toPdfInternal( grid, document ); + toPdfInternal( grid, document, 0F ); closeDocument( document ); } @@ -116,23 +116,28 @@ for ( Grid grid : grids ) { - toPdfInternal( grid, document ); + toPdfInternal( grid, document, 40F ); } closeDocument( document ); } - private static void toPdfInternal( Grid grid, Document document ) + private static void toPdfInternal( Grid grid, Document document, float spacing ) { PdfPTable table = new PdfPTable( grid.getVisibleWidth() ); table.setHeaderRows( 1 ); - table.setWidthPercentage( 100f ); + table.setWidthPercentage( 100F ); table.setKeepTogether( false ); + table.setSpacingAfter( spacing ); - table.addCell( resetPaddings( getTitleCell( grid.getTitle(), grid.getVisibleWidth() ), 0, 45, 0, 0 ) ); - table.addCell( getSubtitleCell( grid.getSubtitle(), grid.getVisibleWidth() ) ); - table.addCell( getEmptyCell( grid.getVisibleWidth(), 30 ) ); + table.addCell( resetPaddings( getTitleCell( grid.getTitle(), grid.getVisibleWidth() ), 0, 30, 0, 0 ) ); + + if ( StringUtils.isNotEmpty( grid.getSubtitle() ) ) + { + table.addCell( getSubtitleCell( grid.getSubtitle(), grid.getVisibleWidth() ) ); + table.addCell( getEmptyCell( grid.getVisibleWidth(), 30 ) ); + } for ( GridHeader header : grid.getVisibleHeaders() ) { === modified 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 2011-05-05 21:15:45 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridPdfResult.java 2011-05-31 11:18:52 +0000 @@ -27,21 +27,26 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import static org.apache.commons.lang.StringUtils.defaultIfEmpty; +import static org.hisp.dhis.system.util.CodecUtils.filenameEncode; + 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.grid.GridUtils; -import org.hisp.dhis.system.util.CodecUtils; import org.hisp.dhis.util.ContextUtils; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.Result; /** + * Creates a PDF representation of the given Grid or list of Grids and writes + * it to the servlet outputstream. One of the grid or grids arguments must be set. + * * @author Lars Helge Overland */ public class GridPdfResult @@ -52,7 +57,7 @@ */ private static final long serialVersionUID = 6613101138470779866L; - private static final String DEFAULT_FILENAME = "Grid"; + private static final String DEFAULT_NAME = "Grid"; // ------------------------------------------------------------------------- // Input @@ -65,11 +70,19 @@ this.grid = grid; } + private List grids; + + public void setGrids( List grids ) + { + this.grids = grids; + } + // ------------------------------------------------------------------------- // Result implementation // ------------------------------------------------------------------------- @Override + @SuppressWarnings( "unchecked" ) public void execute( ActionInvocation invocation ) throws Exception { @@ -81,6 +94,10 @@ grid = _grid != null ? _grid : grid; + List _grids = (List) invocation.getStack().findValue( "grids" ); + + grids = _grids != null ? _grids : grids; + // --------------------------------------------------------------------- // Configure response // --------------------------------------------------------------------- @@ -89,14 +106,21 @@ OutputStream out = response.getOutputStream(); - String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".pdf"; - + String filename = filenameEncode( defaultIfEmpty( grid != null ? grid.getTitle() : grids.iterator().next().getTitle(), DEFAULT_NAME ) ) + ".pdf";; + ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PDF, true, filename, false ); // --------------------------------------------------------------------- // Write PDF to output stream // --------------------------------------------------------------------- - GridUtils.toPdf( grid, out ); + if ( grid != null ) + { + GridUtils.toPdf( grid, out ); + } + else + { + GridUtils.toPdf( grids, out ); + } } } === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridXlsResult.java' --- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridXlsResult.java 2011-05-05 21:15:45 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridXlsResult.java 2011-05-31 11:39:19 +0000 @@ -27,21 +27,26 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import static org.apache.commons.lang.StringUtils.defaultIfEmpty; +import static org.hisp.dhis.system.util.CodecUtils.filenameEncode; + 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.grid.GridUtils; -import org.hisp.dhis.system.util.CodecUtils; import org.hisp.dhis.util.ContextUtils; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.Result; /** + * Creates an XLS representation of the given Grid or list of Grids and writes + * it to the servlet outputstream. One of the grid or grids arguments must be set. + * * @author Lars Helge Overland */ public class GridXlsResult @@ -52,7 +57,7 @@ */ private static final long serialVersionUID = 3030165635768899728L; - private static final String DEFAULT_FILENAME = "Grid.xls"; + private static final String DEFAULT_NAME = "Grid.xls"; // ------------------------------------------------------------------------- // Input @@ -65,11 +70,19 @@ this.grid = grid; } + private List grids; + + public void setGrids( List grids ) + { + this.grids = grids; + } + // ------------------------------------------------------------------------- // Result implementation // ------------------------------------------------------------------------- @Override + @SuppressWarnings( "unchecked" ) public void execute( ActionInvocation invocation ) throws Exception { @@ -81,6 +94,10 @@ grid = _grid != null ? _grid : grid; + List _grids = (List) invocation.getStack().findValue( "grids" ); + + grids = _grids != null ? _grids : grids; + // --------------------------------------------------------------------- // Configure response // --------------------------------------------------------------------- @@ -89,14 +106,21 @@ OutputStream out = response.getOutputStream(); - String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".xls"; - + String filename = filenameEncode( defaultIfEmpty( grid != null ? grid.getTitle() : grids.iterator().next().getTitle(), DEFAULT_NAME ) ) + ".xls";; + ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, true, filename, true ); // --------------------------------------------------------------------- // Create workbook and write to output stream // --------------------------------------------------------------------- - GridUtils.toXls( grid, out ); + if ( grid != null ) + { + GridUtils.toXls( grid, out ); + } + else + { + GridUtils.toXls( grids, out ); + } } } === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/SessionUtils.java' --- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/SessionUtils.java 2011-01-06 12:40:57 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/SessionUtils.java 2011-05-31 11:18:52 +0000 @@ -39,6 +39,7 @@ public static final String KEY_PREVIEW_STATUS = "previewStatus"; public static final String KEY_CURRENT_YEAR = "currentYear"; public static final String KEY_REPORT_TABLE_GRID = "lastReportTableGrid"; + public static final String KEY_DATASET_REPORT_GRID = "lastDataSetReportGrid"; public static Object getSessionVar( String name ) { === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportAction.java 2011-05-30 20:54:54 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportAction.java 2011-05-31 11:18:52 +0000 @@ -42,11 +42,13 @@ import org.hisp.dhis.oust.manager.SelectionTreeManager; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodService; +import org.hisp.dhis.util.SessionUtils; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionContext; import static org.hisp.dhis.dataset.DataSet.*; +import static org.hisp.dhis.util.SessionUtils.*; /** * @author Chau Thu Tran @@ -134,6 +136,20 @@ this.selectedUnitOnly = selectedUnitOnly; } + private boolean useLast; + + public void setUseLast( boolean useLast ) + { + this.useLast = useLast; + } + + private String type; + + public void setType( String type ) + { + this.type = type; + } + // ------------------------------------------------------------------------- // Output // ------------------------------------------------------------------------- @@ -185,37 +201,42 @@ // ------------------------------------------------------------------------- @Override + @SuppressWarnings( "unchecked" ) public String execute() throws Exception { selectedOrgunit = selectionTreeManager.getSelectedOrganisationUnit(); - if ( dataSetId == null || periodId == null || selectedOrgunit == null ) - { - return ERROR; - } - selectedDataSet = dataSetService.getDataSet( dataSetId ); - selectedPeriod = periodService.getPeriodByExternalId( periodId ); - - String type = selectedDataSet.getDataSetType(); + if ( periodId != null ) + { + selectedPeriod = periodService.getPeriodByExternalId( periodId ); + } - if ( TYPE_CUSTOM.equals( type ) ) + String dataSetType = selectedDataSet.getDataSetType(); + + if ( TYPE_CUSTOM.equals( dataSetType ) ) { customDataEntryFormCode = dataSetReportService.getCustomDataSetReport( selectedDataSet, selectedOrgunit, selectedPeriod, selectedUnitOnly, format ); } - else if ( TYPE_SECTION.equals( type ) ) + else if ( TYPE_SECTION.equals( dataSetType ) ) { - grids = dataSetReportService.getSectionDataSetReport( selectedDataSet, selectedPeriod, selectedOrgunit, selectedUnitOnly, format, i18n ); + grids = useLast ? (List) getSessionVar( KEY_DATASET_REPORT_GRID ) : + dataSetReportService.getSectionDataSetReport( selectedDataSet, selectedPeriod, selectedOrgunit, selectedUnitOnly, format, i18n ); + + SessionUtils.setSessionVar( SessionUtils.KEY_DATASET_REPORT_GRID, grids ); } else { - grid = dataSetReportService.getDefaultDataSetReport( selectedDataSet, selectedPeriod, selectedOrgunit, selectedUnitOnly, format, i18n ); + grid = useLast ? (Grid) getSessionVar( KEY_DATASET_REPORT_GRID ) : + dataSetReportService.getDefaultDataSetReport( selectedDataSet, selectedPeriod, selectedOrgunit, selectedUnitOnly, format, i18n ); + + SessionUtils.setSessionVar( SessionUtils.KEY_DATASET_REPORT_GRID, grid ); } - - ActionContext.getContext().getActionInvocation().getStack().setValue( PARAM_PAGE, VIEW_MAP.get( type ) ); - - return SUCCESS; + + ActionContext.getContext().getActionInvocation().getStack().setValue( PARAM_PAGE, VIEW_MAP.get( dataSetType ) ); + + return useLast ? type : SUCCESS; } } === 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-05-30 20:54:54 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-05-31 11:18:52 +0000 @@ -278,8 +278,11 @@ + + /main.vm - /dhis-web-reporting/menu.vm + /dhis-web-reporting/menu.vm + javascript/dataSetReport.js === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js 2011-03-20 14:21:11 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js 2011-05-31 11:18:52 +0000 @@ -10,7 +10,7 @@ selectedOrganisationUnitIds = ids; } -if ( selectionTreeSelection ) +if ( typeof( selectionTreeSelection ) != "undefined" ) { selectionTreeSelection.setListenerFunction( setSelectedOrganisationUnitIds ); } @@ -42,3 +42,9 @@ document.getElementById( "reportForm" ).submit(); } + +function exportDataSetReport( type ) +{ + var url = "generateDataSetReport.action?useLast=true&dataSetId=" + $( "#dataSetId" ).val() + "&type=" + type; + window.location.href = url; +} \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/renderDefaultDataSetReportForm.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/renderDefaultDataSetReportForm.vm 2011-05-30 20:54:54 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/renderDefaultDataSetReportForm.vm 2011-05-31 11:18:52 +0000 @@ -1,6 +1,11 @@

$i18n.getString('reporting_unit'): $encoder.htmlEncode( $selectedOrgunit.name )   $i18n.getString('reporting_period'): $format.formatPeriod( $selectedPeriod )

-

+ +
+ + + +
#parse( "dhis-web-commons/ajax/htmlGrid.vm" ) === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/renderSectionDataSetReportForm.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/renderSectionDataSetReportForm.vm 2011-05-30 20:54:54 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/renderSectionDataSetReportForm.vm 2011-05-31 11:18:52 +0000 @@ -4,8 +4,15 @@ } + +

$i18n.getString('reporting_unit'): $encoder.htmlEncode( $selectedOrgunit.name )   $i18n.getString('reporting_period'): $format.formatPeriod( $selectedPeriod )

-

+ +
+ + + +
#foreach( $grid in $grids )