dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03004
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1002: Validated copy Report Items from the specified Report Excel to another one if exist(s).
------------------------------------------------------------
revno: 1002
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Mon 2009-11-09 13:59:22 +0700
message:
Validated copy Report Items from the specified Report Excel to another one if exist(s).
Fixed bug in Preview report excel function
modified:
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/reportItem.js
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportItems.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-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java 2009-10-21 06:52:27 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java 2009-11-09 06:59:22 +0000
@@ -40,7 +40,10 @@
import jxl.format.Colour;
import jxl.format.Pattern;
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.hisp.dhis.reportexcel.utils.ExcelUtils;
/**
* Simple demo class which uses the api to present the contents of an excel 97
@@ -89,7 +92,7 @@
private static final String MERGEDCELL_CLOSETAG = "</MergedCells>";
private static final String PRINT_END_LINE = "\n";
-
+
public static final String NUMBER_OF_ZERO = "0";
// ------------------------------------------------
@@ -214,8 +217,18 @@
{
FileInputStream fis = new FileInputStream( this.PATH_FILE_NAME );
org.apache.poi.ss.usermodel.Workbook wb = new HSSFWorkbook( fis );
- org.apache.poi.ss.usermodel.FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+ if ( sheetId > 0 ) {
+
+ this.recalculatedValueForCellFormula( wb, sheetId );
+ }
+ else {
+ for ( int sheet = 0; sheet < WORKBOOK.getNumberOfSheets(); sheet++ )
+ {
+ this.recalculatedValueForCellFormula( wb, sheetId -1);
+ }
+ }
+
if ( bWriteDescription )
{
this.writeXMLDescription( sheetId );
@@ -239,13 +252,13 @@
if ( sheetId > 0 )
{
- writeBySheetNo( wb, (sheetId - 1), evaluator, bDetailed );
+ writeBySheetNo( wb, (sheetId - 1), bDetailed );
}
else
{
for ( int sheet = 0; sheet < WORKBOOK.getNumberOfSheets(); sheet++ )
{
- writeBySheetNo( wb, sheet, evaluator, bDetailed );
+ writeBySheetNo( wb, sheet, bDetailed );
}
}
@@ -256,12 +269,10 @@
// -------------------------------------------------------------------------
// Sub-methods
// -------------------------------------------------------------------------
-
- private void writeBySheetNo( org.apache.poi.ss.usermodel.Workbook wb, int sheetNo,
- org.apache.poi.ss.usermodel.FormulaEvaluator evaluator, boolean bDetailed )
+
+ private void writeBySheetNo( org.apache.poi.ss.usermodel.Workbook wb, int sheetNo, boolean bDetailed )
{
Sheet s = WORKBOOK.getSheet( sheetNo );
- org.apache.poi.ss.usermodel.Sheet sheetPOI = wb.getSheetAt( sheetNo );
STRUCTURE_DATA_RESPONSE.append( " <sheet>" );
STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE );
@@ -271,9 +282,6 @@
Cell[] cell = null;
CellFormat format = null;
- boolean bFormula = false;
- double recalculatedValue = 0;
-
for ( int i = 0; i < s.getRows(); i++ )
{
STRUCTURE_DATA_RESPONSE.append( " <row index=\"" + i + "\">" );
@@ -287,57 +295,22 @@
// information
if ( (cell[j].getType() != CellType.EMPTY) || (cell[j].getCellFormat() != null) )
{
- bFormula = false;
-
- // check the cell formula
- if ( cell[j].getType() == CellType.NUMBER_FORMULA || cell[j].getType() == CellType.STRING_FORMULA
- || cell[j].getType() == CellType.BOOLEAN_FORMULA || cell[j].getType() == CellType.DATE_FORMULA
- || cell[j].getType() == CellType.FORMULA_ERROR )
- {
- bFormula = true;
- recalculatedValue = 0;
-
- // suppose your formula is in Cell
- org.apache.poi.ss.util.CellReference cellReference = new org.apache.poi.ss.util.CellReference(
- cell[j].getRow(), cell[j].getColumn() );
- org.apache.poi.ss.usermodel.Row rowPOI = sheetPOI.getRow( cellReference.getRow() );
- org.apache.poi.ss.usermodel.Cell cellPOI = rowPOI.getCell( cellReference.getCol() );
-
- if ( cellPOI != null )
- {
- switch ( evaluator.evaluateFormulaCell( cellPOI ) )
- {
- case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC:
- recalculatedValue = cellPOI.getNumericCellValue();
- break;
-
- // CELL_TYPE_FORMULA will never occur
- case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA:
- break;
- }
- }
- }
-
+
// end of checking the cell formula
STRUCTURE_DATA_RESPONSE.append( " <col no=\"" + j + "\">" );
STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE );
STRUCTURE_DATA_RESPONSE.append( " <data>" );
- // print data in cell
- if ( bFormula )
+ if ( cell[j].getContents().equals( NUMBER_OF_ZERO ) )
{
- STRUCTURE_DATA_RESPONSE.append( "<![CDATA[" + recalculatedValue + "]]>" );
+
+ STRUCTURE_DATA_RESPONSE.append( "<![CDATA[-]]>" );
}
else
{
- if ( cell[j].getContents().equals( NUMBER_OF_ZERO ) ) {
-
- STRUCTURE_DATA_RESPONSE.append( "<![CDATA[-]]>" );
- }
- else {
- STRUCTURE_DATA_RESPONSE.append( "<![CDATA[" + cell[j].getContents() + "]]>" );
- }
+ STRUCTURE_DATA_RESPONSE.append( "<![CDATA[" + cell[j].getContents() + "]]>" );
}
+ // }
STRUCTURE_DATA_RESPONSE.append( "</data>" );
STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE );
@@ -490,4 +463,62 @@
}
}
+ private void recalculatedValueForCellFormula( org.apache.poi.ss.usermodel.Workbook wb, int sheetNo )
+ {
+
+ Cell[] cell = null;
+ Sheet s = WORKBOOK.getSheet( sheetNo );
+
+ org.apache.poi.ss.usermodel.Sheet sheet = wb.getSheetAt( sheetNo );
+ org.apache.poi.ss.usermodel.FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+
+ String recalculatedValue = "0";
+
+ for ( int i = 0; i < s.getRows(); i++ )
+ {
+ STRUCTURE_DATA_RESPONSE.append( " <row index=\"" + i + "\">" );
+ STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE );
+
+ cell = s.getRow( i );
+
+ for ( int j = 0; j < cell.length; j++ )
+ {
+
+ if ( cell[j].getType() == CellType.NUMBER_FORMULA || cell[j].getType() == CellType.STRING_FORMULA
+ || cell[j].getType() == CellType.BOOLEAN_FORMULA || cell[j].getType() == CellType.DATE_FORMULA
+ || cell[j].getType() == CellType.FORMULA_ERROR )
+ {
+
+ // suppose your formula is in Cell
+ org.apache.poi.ss.util.CellReference cellReference = new org.apache.poi.ss.util.CellReference(
+ cell[j].getRow(), cell[j].getColumn() );
+ org.apache.poi.ss.usermodel.Row rowPOI = sheet.getRow( cellReference.getRow() );
+ org.apache.poi.ss.usermodel.Cell cellPOI = rowPOI.getCell( cellReference.getCol() );
+
+ if ( cellPOI != null )
+ {
+ switch ( evaluator.evaluateFormulaCell( cellPOI ) )
+ {
+ case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC:
+
+ recalculatedValue = String.valueOf( cellPOI.getNumericCellValue() );
+
+ if ( new Integer(recalculatedValue.split( "\\." )[1]) == 0 ) {
+
+ recalculatedValue = recalculatedValue.split( "\\." )[0];
+ }
+
+ ExcelUtils.writeValueByPOI( i, j, recalculatedValue, ExcelUtils.NUMBER, (HSSFSheet)sheet, (HSSFCellStyle)wb.createCellStyle() );
+ break;
+
+ // CELL_TYPE_FORMULA will never occur
+ case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA:
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
}
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties 2009-11-09 05:52:46 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties 2009-11-09 06:59:22 +0000
@@ -154,3 +154,5 @@
associations = Associations
sheetNo = Sheet
choose_excelItem = Please choose excel items
+copy_items_duplicated = Warning! Cannot copy the duplicated items
+copy_successful = Copy successful !
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties 2009-11-09 05:52:46 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties 2009-11-09 06:59:22 +0000
@@ -163,7 +163,11 @@
generate_advanced_report = B\u00e1o c\u00e1o theo nh\u00f3m \u0111\u01a1n v\u1ecb
report_ready_exist = B\u00e1o c\u00e1o n\u00e0y \u0111\u00e3 t\u1ed3n t\u1ea1i
upload_file_first = Upload t\u1eadp tin tr\u01b0\u1edbc !
+choose_excelItem = Xin ch\u1ecdn c\u00e1c gi\u00e1 tr\u1ecb c\u1ea7n import
please_enter_sheet_no = Vui l\u00f2ng nh\u1eadp sheet no
please_enter_group_name = Vui l\u00f2ng nh\u1eadp t\u00ean nh\u00f3m
upload_file_first = Upload t\u1eadp tin tr\u01b0\u1edbc !
choose_excelItem = Xin ch\u1ecdn c\u00e1c gi\u00e1 tr\u1ecb c\u1ea7n import
+copy_items_duplicated = ReportItem b\u1ecb tr\u00f9ng l\u1eb7p, kh\u00f4ng th\u1ec3 sao ch\u00e9p !
+copy_successful = Sao ch\u00e9p th\u00e0nh c\u00f4ng !
+
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/reportItem.js'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/reportItem.js 2009-11-09 05:52:46 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/reportItem.js 2009-11-09 06:59:22 +0000
@@ -156,7 +156,7 @@
/*
* COPY REPORT ITEM
*/
-function copySelectedItem(){
+function copySelectedItem() {
$.post("getAllReportExcels.action",{},
function (xmlObject){
xmlObject = xmlObject.getElementsByTagName('reports')[0];
@@ -173,21 +173,112 @@
},'xml');
}
-function saveCopyItems(){
- var reportItems = new Array();
- var listRadio = document.getElementsByName('reportItemCheck');
- for(var i=0;i<listRadio.length;i++){
- if(listRadio.item(i).checked){
- reportItems.push(listRadio.item(i).value);
- }
- }
- $.post("copyReportExcelItems.action",{
+
+sheetId = 0;
+reportItems = null;
+reportItemsCurTarget = null;
+reportItemsDuplicated = null;
+
+function validateCopyReportItems() {
+
+ reportItemsCurTarget = null;
+ reportItemsDuplicated = null;
+
+ reportItemsCurTarget = new Array();
+ reportItemsDuplicated = new Array();
+
+ sheetId = $("#targetSheetNo").val();
+
+ $.post("getReportExcelItems.action",
+ {
reportId:$("#targetReport").val(),
- sheetNo:$("#targetSheetNo").val(),
- reportItems:reportItems
- }, function (data) {
+ sheetNo:sheetId
+ },
+ function (data)
+ {
+ data = data.getElementsByTagName('reportItems')[0];
+ var items = data.getElementsByTagName('reportItem');
+
+ for (var i = 0 ; i < items.length ; i ++) {
+
+ reportItemsCurTarget.push(items[i].getElementsByTagName('name')[0].firstChild.nodeValue);
+ }
+
+ splitDuplicatedReportItems();
+ saveCopyItems();
+
+ }, "xml");
+}
+
+function splitDuplicatedReportItems() {
+
+ var flag = -1;
+ var reportItemsChecked = new Array();
+ var listRadio = document.getElementsByName('reportItemCheck');
+
+ reportItems = null;
+ reportItems = new Array();
+
+ for (var i = 0 ; i < listRadio.length ; i++) {
+ if ( listRadio.item(i).checked ) {
+ reportItemsChecked.push( listRadio.item(i).getAttribute("reportItemID") + "#" + listRadio.item(i).getAttribute("reportItemName"));
+ }
+ }
+
+ for (var i in reportItemsChecked)
+ {
+ flag = i;
+
+ for (var j in reportItemsCurTarget)
+ {
+ if ( reportItemsChecked[i].split("#")[1] == reportItemsCurTarget[j] )
+ {
+ flag = -1;
+ reportItemsDuplicated.push( reportItemsChecked[i].split("#")[1] );
+ break;
+ }
+ }
+ if ( flag >= 0 )
+ {
+ reportItems.push( reportItemsChecked[i].split("#")[0] );
+ }
+ }
+}
+
+function saveCopyItems() {
+
+ if (reportItemsDuplicated.length > 0) {
+
+ var reportItemsDuplicatedList = "Sheet [" + + "]" +i18n_copy_items_duplicated + "<ul>";
+
+ for (var i in reportItemsDuplicated) {
+
+ reportItemsDuplicatedList = reportItemsDuplicatedList
+ + " <li>"
+ + reportItemsDuplicated[i]
+ + "</li><br/>";
+ }
+
+ reportItemsDuplicatedList = reportItemsDuplicatedList + "</ul>"
+
+ setMessage(reportItemsDuplicatedList);
+
$("#copyTo").hide();
- },'xml');
+ }
+ else {
+ $.post("copyReportExcelItems.action",
+ {
+ reportId:$("#targetReport").val(),
+ sheetNo:sheetId,
+ reportItems:reportItems
+ },
+ function (data)
+ {
+ setMessage( i18n_copy_successful );
+ $("#copyTo").hide();
+ },'xml');
+ }
+
}
/**
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportItems.vm'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportItems.vm 2009-10-22 05:37:47 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportItems.vm 2009-11-09 06:59:22 +0000
@@ -31,7 +31,7 @@
#set( $mark = false )
#foreach($reportItem in $reportItems)
<tr #alternate( $mark )>
- <td align=center><input type="checkbox" value="$reportItem.id" name="reportItemCheck" id="reportItemCheck"/></td>
+ <td align=center><input type="checkbox" reportItemID="$reportItem.id" reportItemName="$reportItem.name" name="reportItemCheck" id="reportItemCheck"/></td>
<td>$encoder.htmlEncode( $reportItem.name )</td>
<td>$i18n.getString( $reportItem.itemType )</td>
<td>$i18n.getString( $reportItem.periodType )</td>
@@ -308,7 +308,12 @@
</tr>
</table>
<p align="center">
-<input type="button" value="$i18n.getString('ok')" onclick="saveCopyItems();"/>
+<input type="button" value="$i18n.getString('ok')" onclick="javascript: validateCopyReportItems(); "/>
<input type="button" value="$i18n.getString('cancel')" onclick="hideById('copyTo');"/>
</p>
</div>
+
+<script type="text/javascript">
+ var i18n_copy_successful = '$encoder.jsEscape( $i18n.getString( "copy_successful" ) , "'")';
+ var i18n_copy_items_duplicated = '$encoder.jsEscape( $i18n.getString( "copy_items_duplicated" ) , "'")';
+</script>