dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20385
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9278: local vn - Auto generate form (DONE)
------------------------------------------------------------
revno: 9278
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-12-12 16:34:51 +0700
message:
local vn - Auto generate form (DONE)
modified:
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/utils/ExcelUtils.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/utils/NumberUtils.java
local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties
local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties
local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml
local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.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 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java 2012-12-12 05:14:59 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java 2012-12-12 09:34:51 +0000
@@ -84,6 +84,7 @@
* choice
*
* @author Dang Duy Hieu
+ * @author Chau Thu Tran
* @version $Id$
*/
@@ -160,9 +161,29 @@
try
{
- autoGenerateFormByTemplate( selectionManager.getUploadFilePath(), collectSheets );
+ this.cleanUp();
+
+ String pathFileName = selectionManager.getUploadFilePath();
+
+ InputStream inputSteam = new FileInputStream( pathFileName );
+ excelFileName = getName( pathFileName );
+ commonName = getBaseName( pathFileName );
+
+ if ( getExtension( pathFileName ).equals( "xls" ) )
+ {
+ this.WORKBOOK = new HSSFWorkbook( inputSteam );
+ }
+ else
+ {
+ this.WORKBOOK = new XSSFWorkbook( inputSteam );
+ }
+
+ this.evaluatorFormula = WORKBOOK.getCreationHelper().createFormulaEvaluator();
+
+ writeFormattedXML( collectSheets );
xmlStructureResponse = xml.toString();
+
xml = null;
}
catch ( Exception e )
@@ -183,38 +204,6 @@
}
/**
- * Constructor
- *
- * @param w The workbook to interrogate
- * @param enc The encoding used by the output stream. Null or unrecognized
- * values cause the encoding to default to UTF8
- * @param f Indicates whether the generated XML document should contain the
- * cell format information
- * @exception java.io.IOException
- */
-
- private void autoGenerateFormByTemplate( String pathFileName, Set<Integer> collectSheets )
- throws Exception
- {
- this.cleanUp();
-
- InputStream inputSteam = new FileInputStream( pathFileName );
- excelFileName = getName( pathFileName );
- commonName = getBaseName( pathFileName );
-
- if ( getExtension( pathFileName ).equals( "xls" ) )
- {
- this.WORKBOOK = new HSSFWorkbook( inputSteam );
- }
- else
- {
- this.WORKBOOK = new XSSFWorkbook( inputSteam );
- }
-
- writeFormattedXML( collectSheets );
- }
-
- /**
* Writes out the WORKBOOK data as XML, with formatting information
*
* @param bDetailed
@@ -224,7 +213,7 @@
private void writeFormattedXML( Collection<Integer> collectSheets )
throws Exception
- {
+ {
this.writeXMLMergedDescription( collectSheets );
xml.append( WORKBOOK_OPENTAG );
@@ -237,7 +226,7 @@
private void createFormByComment( int sheetNo, DataElementCategoryOptionCombo optionCombo )
{
PeriodType periodType = PeriodType.getPeriodTypeByName( MonthlyPeriodType.NAME );
-
+
// Create new DataSet
DataSet dataSet = new DataSet( commonName, commonName, periodType );
@@ -261,13 +250,15 @@
for ( Cell cell : row )
{
Comment cmt = cell.getCellComment();
+ int rowIndex = cell.getRowIndex();
+ int colIndex = cell.getColumnIndex();
if ( cmt != null )
{
+ idxMap.clear();
String deName = cell.getStringCellValue();
- String[] indexes = cmt.getString().getString().split( "," );
- int rowIndex = cell.getRowIndex();
+ String[] indexes = cmt.getString().toString().split( "," );
for ( String index : indexes )
{
@@ -308,32 +299,34 @@
}
}
- xml.append( "<col no='" + cell.getColumnIndex() + "'>" );
-
- if ( idxMap.containsKey( cell.getColumnIndex() ) )
+ if ( idxMap.containsKey( colIndex ) )
{
- xml.append( "<data><![CDATA[" + "<input id=\"" + idxMap.get( cell.getColumnIndex() ) + "-"
- + optionCombo.getId()
- + "-val\" style=\"width:7em;text-align:right\" title=\"\" value=\"\">" + "]]></data>" );
+ xml.append( "<col no='" + colIndex + "'>" );
+
+ xml.append( "<data><![CDATA[" + "<input name='entryfield' id='" + idxMap.get( colIndex ) + "-"
+ + optionCombo.getId() + "-val']]></data>" );
+
+ xml.append( "</col>" );
}
else if ( (cell.getCellStyle() != null || cell.getCellType() != Cell.CELL_TYPE_BLANK)
- && !s.isColumnHidden( cell.getColumnIndex() ) )
+ && !s.isColumnHidden( colIndex ) )
{
+ xml.append( "<col no='" + colIndex + "'>" );
+
xml.append( "<data><![CDATA["
- + readValueByPOI( row.getRowNum() + 1, cell.getColumnIndex() + 1, s, evaluatorFormula )
- + "]]></data>" );
+ + readValueByPOI( row.getRowNum() + 1, colIndex + 1, s, evaluatorFormula ) + "]]></data>" );
this.readingDetailsFormattedCell( s, cell );
+ xml.append( "</col>" );
}
- xml.append( "</col>" );
}
xml.append( "</row>" );
}
xml.append( "</sheet>" );
-
+
// Update DataSet
- DataEntryForm dataEntryForm = new DataEntryForm( commonName );
+ DataEntryForm dataEntryForm = new DataEntryForm( commonName, "<p></p>" );
dataEntryFormService.addDataEntryForm( dataEntryForm );
dataSet.setDataEntryForm( dataEntryForm );
@@ -345,14 +338,16 @@
exportReport.setDataSets( dataSets );
exportReportService.updateExportReport( exportReport );
-
+
xml.append( "<ds id='" + dataSetId + "' n='" + commonName + "'/>" );
}
catch ( Exception e )
{
+ cleanUp();
+
// Catch exception if any
- System.err.println( "Error: " + e.getMessage() );
+ e.printStackTrace();
}
}
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/utils/ExcelUtils.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/utils/ExcelUtils.java 2012-12-04 02:28:27 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/utils/ExcelUtils.java 2012-12-12 09:34:51 +0000
@@ -344,7 +344,7 @@
else
{
cellPOI.setCellValue( Double.parseDouble( value ) );
- //cellPOI.setCellValue( getFormattedNumber( value ) );
+ // cellPOI.setCellValue( getFormattedNumber( value ) );
}
}
}
@@ -388,7 +388,7 @@
else
{
cellPOI.setCellValue( Double.parseDouble( value ) );
- //cellPOI.setCellValue( getFormattedNumber( value ) );
+ // cellPOI.setCellValue( getFormattedNumber( value ) );
}
}
}
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/utils/NumberUtils.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/utils/NumberUtils.java 2012-12-01 11:00:04 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/utils/NumberUtils.java 2012-12-12 09:34:51 +0000
@@ -62,6 +62,11 @@
public static String getFormattedNumber( String input )
{
+ if ( df == null )
+ {
+ return input;
+ }
+
try
{
return df.format( Double.parseDouble( input ) );
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties 2012-11-28 07:33:12 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties 2012-12-12 09:34:51 +0000
@@ -386,4 +386,8 @@
new_value = The new value
reverted = reverted
deleted = deleted
-no_value_rollbacked = There is no value rollbacked
\ No newline at end of file
+no_value_rollbacked = There is no value rollbacked
+automate = Automate
+auto_generate_form = Automatic generating form
+generate_form = Generate form
+auto_generate_form_completed= Form generated
\ No newline at end of file
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties 2012-11-28 07:33:12 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties 2012-12-12 09:34:51 +0000
@@ -417,4 +417,8 @@
new_value = D\u1eef li\u1ec7u m\u1edbi
reverted = ph\u1ee5c h\u1ed3i
deleted = b\u1ecb x\u00f3a
-no_value_rollbacked = Kh\u00f4ng c\u00f3 d\u1eef li\u1ec7u n\u00e0o \u0111\u01b0\u1ee3c ph\u1ee5c h\u1ed3i
\ No newline at end of file
+no_value_rollbacked = Kh\u00f4ng c\u00f3 d\u1eef li\u1ec7u n\u00e0o \u0111\u01b0\u1ee3c ph\u1ee5c h\u1ed3i
+automate = T\u1ef1 \u0111\u1ed9ng h\u00f3a
+auto_generate_form = T\u1ef1 \u0111\u1ed9ng t\u1ea1o bi\u1ec3u m\u1eabu
+generate_form = T\u1ea1o bi\u1ec3u m\u1eabu
+auto_generate_form_completed = Bi\u1ec3u m\u1eabu \u0111\u01b0\u1ee3c ho\u00e0n th\u00e0nh
\ No newline at end of file
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml 2012-12-12 05:14:59 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml 2012-12-12 09:34:51 +0000
@@ -1865,9 +1865,10 @@
<action name="autoGenerateFormByTemplate"
class="org.hisp.dhis.reportsheet.preview.action.AutoGenerateFormByTemplate">
- <result name="success" type="velocity-json">../dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
- <result name="error" type="velocity-json">../dhis-web-commons/ajax/jsonResponseError.vm</result>
- <param name="onExceptionReturn">plainTextError</param>
+ <result name="success" type="velocity-xml">
+ /dhis-web-spreadsheet-reporting/responseExportReportPreview.vm</result>
+ <result name="error" type="velocity-xml">
+ /dhis-web-commons/ajax/xmlResponseError.vm</result>
</action>
</package>
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js 2012-12-12 05:14:59 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js 2012-12-12 09:34:51 +0000
@@ -19,7 +19,7 @@
{
data = data.getElementsByTagName('message')[0];
var type = data.getAttribute("type");
- alert(type);
+
if ( type == 'error' ) {
setMessage( data.firstChild.nodeValue );
} else {
@@ -46,6 +46,8 @@
function autoGenerateFormByTemplate()
{
+ lockScreen();
+
$.ajax({
cache: false,
url: spreadsheetTreePath + "autoGenerateFormByTemplate.action",
@@ -56,108 +58,117 @@
function autoGenerateFormByTemplateReceived( parentElement )
{
- var aKey = new Array();
- var aMerged = new Array();
- var cells = parentElement.getElementsByTagName( 'cell' );
-
- for (var i = 0 ; i < cells.length ; i ++)
+ var type = getElementAttribute( parentElement, 'message', 'type' );
+
+ if ( type && type == 'error' )
+ {
+ showErrorMessage( parentElement.firstChild.nodeValue );
+ }
+ else
{
- aKey[i] = cells[i].getAttribute( 'iKey' );
- aMerged[i] = cells[i].firstChild.nodeValue;
- }
-
- var _index = 0;
- var _orderSheet = 0;
- var _sPattern = "";
- var _rows = "";
- var _cols = "";
- var _sHTML = [];
- var _sheets = parentElement.getElementsByTagName( 'sheet' );
-
- var dataSetId = getElementAttribute( parentElement, 'ds', 'id' );
- var dataSetName = getElementAttribute( parentElement, 'ds', 'n' );
-
- for (var s = 0 ; s < _sheets.length ; s ++)
- {
- _rows = _sheets[s].getElementsByTagName( 'row' );
- _orderSheet = getRootElementAttribute( _sheets[s], "id" );
-
- _sHTML.push( "<table>" );
-
- for (var i = 0 ; i < _rows.length ; i ++)
- {
- _index = 0;
- _sHTML.push( "<tr>" );
-
- _cols = _rows[i].getElementsByTagName( 'col' );
-
- for (var j = 0 ; j < _cols.length ; )
- {
- var _number = getRootElementAttribute( _cols[j], 'no' );
- var keyId = getRootElementAttribute( _cols[j], 'id' );
-
- // Printing out the unformatted cells
- for (; _index < _number ; _index ++)
- {
- _sHTML.push( "<td/>" );
- }
-
- if ( _index == _number )
- {
- var _sData = getElementValue( _cols[j], 'data' );
- var _align = getElementAttribute( _cols[j], 'format', 'a' );
- var _border = getElementAttribute( _cols[j], 'format', 'b' );
- var _size = getElementAttribute( _cols[j], 'font', 's' );
- var _bold = getElementAttribute( _cols[j], 'font', 'b' );
- var _italic = getElementAttribute( _cols[j], 'font', 'i' );
- var _color = getElementAttribute( _cols[j], 'font', 'c' );
-
- // If this cell is merged - Key's form: Sheet#Row#Col
- _sPattern = _orderSheet + "#" + i + "#" + _number;
- var _colspan = getMergedNumberForEachCell( aKey, _sPattern, aMerged );
-
- // Jumping for <For Loop> AND <Empty Cells>
- j = Number(j) + Number(_colspan);
- _index = Number(_index) + Number(_colspan);
- _size = Number(_size) + 2;
-
- _sHTML.push( "<td align='", _align, "' colspan='", _colspan, "'" );
- _sHTML.push( " style='font-size:", _size, "px" );
- _sHTML.push( _color == "" ? "'" : ";color:" + _color + "'" );
- _sHTML.push( _border > 0 ? " ui-widget-content" : "" );
-
- if ( _bold == "1" )
- {
- _sData = "<b>" + _sData + "</b>";
- }
- if ( _italic == "true" )
- {
- _sData = "<i>" + _sData + "</i>";
- }
-
- _sHTML.push( "'>", _sData, "</td>" );
- }
- }
- _sHTML.push( "</tr>" );
+ var aKey = new Array();
+ var aMerged = new Array();
+ var cells = parentElement.getElementsByTagName( 'cell' );
+
+ for (var i = 0 ; i < cells.length ; i ++)
+ {
+ aKey[i] = cells[i].getAttribute( 'iKey' );
+ aMerged[i] = cells[i].firstChild.nodeValue;
}
- _sHTML.push( "</table>" );
- }
- jQuery( '#previewDiv' ).html( _sHTML.join('') );
- showById( "previewDiv" );
+ var _index = 0;
+ var _orderSheet = 0;
+ var _sPattern = "";
+ var _rows = "";
+ var _cols = "";
+ var _sHTML = [];
+ var _sheets = parentElement.getElementsByTagName( 'sheet' );
- unLockScreen();
- showSuccessMessage( "auto_generate_form_completed" );
-
- if ( _sHTML.length > 0 )
- {
- jQuery.postUTF8( '../dhis-web-maintenance-dataset/saveDataEntryForm.action',
- {
- dataSetIdField: dataSetId,
- nameField: dataSetName,
- style: 'regular',
- designTextarea: _sHTML.join('')
- } );
+ var dataSetId = getElementAttribute( parentElement, 'ds', 'id' );
+ var dataSetName = getElementAttribute( parentElement, 'ds', 'n' );
+
+ for (var s = 0 ; s < _sheets.length ; s ++)
+ {
+ _rows = _sheets[s].getElementsByTagName( 'row' );
+ _orderSheet = getRootElementAttribute( _sheets[s], "id" );
+
+ _sHTML.push( "<table>" );
+
+ for (var i = 0 ; i < _rows.length ; i ++)
+ {
+ _index = 0;
+ _sHTML.push( "<tr>" );
+
+ _cols = _rows[i].getElementsByTagName( 'col' );
+
+ for (var j = 0 ; j < _cols.length ; )
+ {
+ var _number = getRootElementAttribute( _cols[j], 'no' );
+ var keyId = getRootElementAttribute( _cols[j], 'id' );
+
+ // Printing out the unformatted cells
+ for (; _index < _number ; _index ++)
+ {
+ _sHTML.push( "<td/>" );
+ }
+
+ if ( _index == _number )
+ {
+ var _sData = getElementValue( _cols[j], 'data' );
+ var _align = getElementAttribute( _cols[j], 'format', 'a' );
+ var _border = getElementAttribute( _cols[j], 'format', 'b' );
+ var _size = getElementAttribute( _cols[j], 'font', 's' );
+ var _bold = getElementAttribute( _cols[j], 'font', 'b' );
+ var _italic = getElementAttribute( _cols[j], 'font', 'i' );
+ var _color = getElementAttribute( _cols[j], 'font', 'c' );
+
+ // If this cell is merged - Key's form: Sheet#Row#Col
+ _sPattern = _orderSheet + "#" + i + "#" + _number;
+ var _colspan = getMergedNumberForEachCell( aKey, _sPattern, aMerged );
+
+ // Jumping for <For Loop> AND <Empty Cells>
+ j = Number(j) + Number(_colspan);
+ _index = Number(_index) + Number(_colspan);
+ _size = Number(_size) + 2;
+
+ _sHTML.push( "<td align='", _align, "' colspan='", _colspan, "'" );
+ _sHTML.push( " style='font-size:", _size, "px" );
+ _sHTML.push( _color == "" ? "'" : ";color:" + _color + "'" );
+ _sHTML.push( _border > 0 ? " ui-widget-content" : "" );
+
+ if ( _bold == "1" )
+ {
+ _sData = "<b>" + _sData + "</b>";
+ }
+ if ( _italic == "true" )
+ {
+ _sData = "<i>" + _sData + "</i>";
+ }
+
+ _sHTML.push( "'>", _sData, "</td>" );
+ }
+ }
+ _sHTML.push( "</tr>" );
+ }
+ _sHTML.push( "</table>" );
+ }
+
+ //jQuery( '#previewDiv' ).html( _sHTML.join('') );
+ //showById( "previewDiv" );
+
+ unLockScreen();
+ showSuccessMessage( i18n_auto_generate_form_completed );
+
+ if ( _sHTML.length > 0 )
+ {
+ jQuery.postUTF8( '../dhis-web-maintenance-dataset/saveDataEntryForm.action',
+ {
+ dataSetIdField: dataSetId,
+ nameField: dataSetName,
+ style: 'regular',
+ designTextarea: _sHTML.join('')
+ } );
+ }
}
}