dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09651
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2600: Fixed flaw with report table view, dynamic columns were not displayed
------------------------------------------------------------
revno: 2600
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-01-17 17:17:06 +0100
message:
Fixed flaw with report table view, dynamic columns were not displayed
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridCsvResult.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridXlsResult.java
dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/generateReport.js
--
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/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2011-01-14 16:14:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2011-01-17 16:17:06 +0000
@@ -875,7 +875,7 @@
}
if ( period != null )
{
- String periodName = period.getName() != null ? period.getName() : i18nFormat.formatPeriod( period );
+ String periodName = i18nFormat == null ? period.getName() : i18nFormat.formatPeriod( period );
buffer.append( periodName + SPACE );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java 2011-01-14 16:14:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java 2011-01-17 16:17:06 +0000
@@ -132,9 +132,11 @@
*
* @param id the ReportTable identifier.
* @param format the I18nFormat.
+ * @param reportingPeriod the reporting period number.
+ * @param organisationUnitId the organisation unit number.
* @return a Grid.
*/
- Grid getReportTableGrid( int id, I18nFormat format );
+ Grid getReportTableGrid( int id, I18nFormat format, Integer reportingPeriod, Integer organisationUnitId );
/**
* Tests whether the report table has been generated in the database.
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2011-01-14 16:14:22 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2011-01-17 16:17:06 +0000
@@ -155,71 +155,12 @@
{
for ( ReportTable reportTable : getReportTables( id, mode ) )
{
- // -----------------------------------------------------------------
- // Reporting period report parameter / current reporting period
- // -----------------------------------------------------------------
-
- if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamReportingMonth() )
- {
- reportTable.setRelativePeriods( periodService.reloadPeriods( reportTable.getRelatives().getRelativePeriods( reportingPeriod, format, !reportTable.isDoPeriods() ) ) );
- reportTable.setReportingMonthName( reportTable.getRelatives().getReportingMonthName( reportingPeriod, format ) );
-
- log.info( "Reporting period date from report param: " + reportTable.getReportingMonthName() );
- }
- else
- {
- reportTable.setRelativePeriods( periodService.reloadPeriods( reportTable.getRelatives().getRelativePeriods( 1, format, !reportTable.isDoPeriods() ) ) );
- reportTable.setReportingMonthName( reportTable.getRelatives().getReportingMonthName( 1, format ) );
-
- log.info( "Reporting period date default: " + reportTable.getReportingMonthName() );
- }
-
- // -----------------------------------------------------------------
- // Parent organisation unit report parameter
- // -----------------------------------------------------------------
-
- if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamParentOrganisationUnit() )
- {
- OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
- organisationUnit.setCurrentParent( true );
- reportTable.getRelativeUnits().add( organisationUnit );
- reportTable.getRelativeUnits().addAll( new ArrayList<OrganisationUnit>( organisationUnit.getChildren() ) );
- reportTable.setOrganisationUnitName( organisationUnit.getName() );
-
- log.info( "Parent organisation unit: " + organisationUnit.getName() );
- }
-
- // -----------------------------------------------------------------
- // Organisation unit report parameter
- // -----------------------------------------------------------------
-
- if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamOrganisationUnit() )
- {
- OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
-
- List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
- organisationUnits.add( organisationUnit );
- reportTable.getRelativeUnits().addAll( organisationUnits );
- reportTable.setOrganisationUnitName( organisationUnit.getName() );
-
- log.info( "Organisation unit: " + organisationUnit.getName() );
- }
-
- // -----------------------------------------------------------------
- // Set properties and initalize
- // -----------------------------------------------------------------
-
- reportTable.setI18nFormat( format );
- reportTable.init();
-
- // -----------------------------------------------------------------
- // Create report table
- // -----------------------------------------------------------------
+ reportTable = initDynamicMetaObjects( reportTable, reportingPeriod, organisationUnitId, format );
createReportTable( reportTable, doDataMart );
}
}
-
+
@Transactional
public void createReportTable( ReportTable reportTable, boolean doDataMart )
{
@@ -366,25 +307,129 @@
}
@Transactional
- public Grid getReportTableGrid( int id, I18nFormat format )
+ public Grid getReportTableGrid( int id, I18nFormat format, Integer reportingPeriod, Integer organisationUnitId )
{
ReportTable reportTable = getReportTable( id );
- reportTable.setI18nFormat( format );
- reportTable.init();
+ reportTable = initDynamicMetaObjects( reportTable, reportingPeriod, organisationUnitId, format );
return reportTableManager.getReportTableGrid( reportTable );
}
- public boolean reportTableIsGenerated( int id )
+ public boolean reportTableIsGenerated( int id ) //TODO remove
{
return reportTableManager.reportTableIsGenerated( getReportTable( id ) );
}
+
+ @Transactional
+ public Collection<ReportTable> getReportTablesBetweenByName( String name, int first, int max )
+ {
+ return reportTableStore.getBetweenByName( name, first, max );
+ }
+
+ @Transactional
+ public int getReportTableCount()
+ {
+ return reportTableStore.getCount();
+ }
+
+ @Transactional
+ public int getReportTableCountByName( String name )
+ {
+ return reportTableStore.getCountByName( name );
+ }
+
+ @Transactional
+ public Collection<ReportTable> getReportTablesBetween( int first, int max )
+ {
+ return reportTableStore.getBetween( first, max );
+ }
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
+ /**
+ * Populates the report table with dynamic meta objects originating from report
+ * table parameters.
+ *
+ * @param reportTable the report table.
+ * @param reportingPeriod the reporting period number.
+ * @param organisationUnitId the organisation unit identifier.
+ * @param format the I18n format.
+ * @return a report table.
+ */
+ private ReportTable initDynamicMetaObjects( ReportTable reportTable, Integer reportingPeriod,
+ Integer organisationUnitId, I18nFormat format )
+ {
+ // -----------------------------------------------------------------
+ // Reporting period report parameter / current reporting period
+ // -----------------------------------------------------------------
+
+ if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamReportingMonth() )
+ {
+ reportTable.setRelativePeriods( periodService.reloadPeriods( reportTable.getRelatives().getRelativePeriods( reportingPeriod, format, !reportTable.isDoPeriods() ) ) );
+ reportTable.setReportingMonthName( reportTable.getRelatives().getReportingMonthName( reportingPeriod, format ) );
+
+ log.info( "Reporting period date from report param: " + reportTable.getReportingMonthName() );
+ }
+ else
+ {
+ reportTable.setRelativePeriods( periodService.reloadPeriods( reportTable.getRelatives().getRelativePeriods( 1, format, !reportTable.isDoPeriods() ) ) );
+ reportTable.setReportingMonthName( reportTable.getRelatives().getReportingMonthName( 1, format ) );
+
+ log.info( "Reporting period date default: " + reportTable.getReportingMonthName() );
+ }
+
+ // -----------------------------------------------------------------
+ // Parent organisation unit report parameter
+ // -----------------------------------------------------------------
+
+ if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamParentOrganisationUnit() )
+ {
+ OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
+ organisationUnit.setCurrentParent( true );
+ reportTable.getRelativeUnits().add( organisationUnit );
+ reportTable.getRelativeUnits().addAll( new ArrayList<OrganisationUnit>( organisationUnit.getChildren() ) );
+ reportTable.setOrganisationUnitName( organisationUnit.getName() );
+
+ log.info( "Parent organisation unit: " + organisationUnit.getName() );
+ }
+
+ // -----------------------------------------------------------------
+ // Organisation unit report parameter
+ // -----------------------------------------------------------------
+
+ if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamOrganisationUnit() )
+ {
+ OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
+
+ List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>();
+ organisationUnits.add( organisationUnit );
+ reportTable.getRelativeUnits().addAll( organisationUnits );
+ reportTable.setOrganisationUnitName( organisationUnit.getName() );
+
+ log.info( "Organisation unit: " + organisationUnit.getName() );
+ }
+
+ // -----------------------------------------------------------------
+ // Set properties and initalize
+ // -----------------------------------------------------------------
+
+ reportTable.setI18nFormat( format );
+ reportTable.init();
+
+ return reportTable;
+ }
+
+ /**
+ * Adds columns with regression values to the given grid.
+ *
+ * @param grid the grid.
+ * @param startColumnIndex the start column index.
+ * @param numberOfColumns the number of columns.
+ * @return a grid.
+ */
private Grid addRegressionToGrid( Grid grid, int startColumnIndex, int numberOfColumns )
{
for ( int i = 0; i < numberOfColumns; i++ )
@@ -397,6 +442,12 @@
return grid;
}
+ /**
+ * Creates a grid representing the data in the report table.
+ *
+ * @param reportTable the report table.
+ * @return a grid.
+ */
private Grid getGrid( ReportTable reportTable )
{
final Grid grid = new ListGrid();
@@ -565,24 +616,4 @@
return reportTables;
}
-
- public Collection<ReportTable> getReportTablesBetweenByName( String name, int first, int max )
- {
- return reportTableStore.getBetweenByName( name, first, max );
- }
-
- public int getReportTableCount()
- {
- return reportTableStore.getCount();
- }
-
- public int getReportTableCountByName( String name )
- {
- return reportTableStore.getCountByName( name );
- }
-
- public Collection<ReportTable> getReportTablesBetween( int first, int max )
- {
- return reportTableStore.getBetween( first, max );
- }
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridCsvResult.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridCsvResult.java 2011-01-14 16:14:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridCsvResult.java 2011-01-17 16:17:06 +0000
@@ -90,7 +90,7 @@
String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".csv";
- ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, true, filename, false );
+ ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, true, filename, true );
// ---------------------------------------------------------------------
// Write CSV to output stream
=== 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-01-14 16:14:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridXlsResult.java 2011-01-17 16:17:06 +0000
@@ -107,7 +107,7 @@
String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".xls";
- ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, true, filename, false );
+ ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, true, filename, true );
// ---------------------------------------------------------------------
// Create workbook and write to output stream
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java 2011-01-14 16:14:22 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java 2011-01-17 16:17:06 +0000
@@ -59,7 +59,21 @@
{
this.format = format;
}
-
+
+ private Integer reportingPeriod;
+
+ public void setReportingPeriod( Integer reportingPeriod )
+ {
+ this.reportingPeriod = reportingPeriod;
+ }
+
+ private Integer organisationUnitId;
+
+ public void setOrganisationUnitId( Integer organisationUnitId )
+ {
+ this.organisationUnitId = organisationUnitId;
+ }
+
// -------------------------------------------------------------------------
// Input
// -------------------------------------------------------------------------
@@ -110,11 +124,11 @@
}
else
{
- grid = reportTableService.getReportTableGrid( id, format );
+ grid = reportTableService.getReportTableGrid( id, format, reportingPeriod, organisationUnitId );
}
SessionUtils.setSessionVar( SessionUtils.KEY_REPORT_TABLE_GRID, grid );
return type != null ? type : DEFAULT_TYPE;
- }
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/generateReport.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/generateReport.js 2011-01-10 17:52:52 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/generateReport.js 2011-01-17 16:17:06 +0000
@@ -89,7 +89,19 @@
}
else if ( $( "#mode" ).val() == MODE_TABLE )
{
- window.location.href = "exportTable.action?id=" + $( "#id" ).val() + "&type=html";
+ var url = "exportTable.action?id=" + $( "#id" ).val() + "&type=html";
+
+ if ( $( "#reportingPeriod" ).length )
+ {
+ url += "&reportingPeriod=" + $( "#reportingPeriod" ).val();
+ }
+
+ if ( paramOrganisationUnit != null )
+ {
+ url += "&organisationUnitId=" + paramOrganisationUnit;
+ }
+
+ window.location.href = url;
}
}
else if ( statusMessage == null )