dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11982
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3532: Cleanup CDE
------------------------------------------------------------
revno: 3532
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-05-07 20:58:19 +0200
message:
Cleanup CDE
modified:
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java
--
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-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java 2011-05-07 14:43:19 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java 2011-05-07 18:58:19 +0000
@@ -176,7 +176,7 @@
dataElementCode = dataElementCode.replaceAll( "view=\".*?\"", "" );
// -------------------------------------------------------------
- // Insert title info - Data element id, name, type, min, max
+ // Insert title info
// -------------------------------------------------------------
StringBuilder title = new StringBuilder( "title=\"Name: " ).append( dataElement.getShortName() ).
@@ -189,7 +189,7 @@
}
else
{
- dataElementCode += title;
+ dataElementCode += " " + title;
}
// -------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java 2010-09-16 06:18:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java 2011-05-07 18:58:19 +0000
@@ -104,8 +104,7 @@
if ( dataEntryForm == null )
{
- dataEntryForm = new DataEntryForm( nameField, dataEntryFormService
- .prepareDataEntryFormCode( designTextarea ) );
+ dataEntryForm = new DataEntryForm( nameField, dataEntryFormService.prepareDataEntryFormCode( designTextarea ) );
int id = dataEntryFormService.addDataEntryForm( dataEntryForm );
message = id + "";
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java 2011-04-28 13:26:51 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java 2011-05-07 18:58:19 +0000
@@ -55,6 +55,9 @@
public class ViewDataEntryFormAction
implements Action
{
+ private static final Pattern IDENTIFIER_PATTERN = Pattern.compile( "value\\[(.*)\\].value:value\\[(.*)\\].value" );
+ private static final Pattern VIEWBY_PATTERN = Pattern.compile( "view=\"@@(.*)@@\"" );
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -173,12 +176,10 @@
*/
private String prepareDataEntryFormCode( String dataEntryFormCode )
{
- String preparedCode = dataEntryFormCode;
-
- preparedCode = prepareDataEntryFormInputs( preparedCode );
- preparedCode = prepareDataEntryFormCombos( preparedCode );
-
- return preparedCode;
+ dataEntryFormCode = prepareDataEntryFormInputs( dataEntryFormCode );
+ dataEntryFormCode = prepareDataEntryFormCombos( dataEntryFormCode );
+
+ return dataEntryFormCode;
}
private String prepareDataEntryFormInputs( String preparedCode )
@@ -200,11 +201,10 @@
// Iterate through all matching data element fields.
// ---------------------------------------------------------------------
- boolean result = matDataElement.find();
- while ( result )
+ while ( matDataElement.find() )
{
// -----------------------------------------------------------------
- // Get input HTML code (HTML input field code)
+ // Get input HTML code
// -----------------------------------------------------------------
String dataElementCode = matDataElement.group( 1 );
@@ -213,22 +213,20 @@
// Pattern to extract data element ID from data element field
// -----------------------------------------------------------------
- Pattern patDataElementId = Pattern.compile( "value\\[(.*)\\].value:value\\[(.*)\\].value" );
- Matcher matDataElementId = patDataElementId.matcher( dataElementCode );
-
- Pattern patViewBy = Pattern.compile( "view=\"@@(.*)@@\"" );
- Matcher matViewBy = patViewBy.matcher( dataElementCode );
-
- if ( matDataElementId.find() && matDataElementId.groupCount() > 0 )
+ Matcher dataElementMatcher = IDENTIFIER_PATTERN.matcher( dataElementCode );
+
+ Matcher viewByMatcher = VIEWBY_PATTERN.matcher( dataElementCode );
+
+ if ( dataElementMatcher.find() && dataElementMatcher.groupCount() > 0 )
{
// -------------------------------------------------------------
// Get data element id,name, optionCombo id,name of data element
// -------------------------------------------------------------
- int dataElementId = Integer.parseInt( matDataElementId.group( 1 ) );
+ int dataElementId = Integer.parseInt( dataElementMatcher.group( 1 ) );
DataElement dataElement = dataElementService.getDataElement( dataElementId );
- int optionComboId = Integer.parseInt( matDataElementId.group( 2 ) );
+ int optionComboId = Integer.parseInt( dataElementMatcher.group( 2 ) );
DataElementCategoryOptionCombo optionCombo = dataElementCategoryService
.getDataElementCategoryOptionCombo( optionComboId );
String optionComboName = "";
@@ -248,69 +246,71 @@
}
// -------------------------------------------------------------
- // Insert name of data element in output code.
+ // Insert name of data element in output code
// -------------------------------------------------------------
- String dispVal = "No Such DataElement Exists";
+ String displayValue = "No Such DataElement Exists";
if ( dataElement != null )
{
- dispVal = dataElement.getShortName();
+ displayValue = dataElement.getShortName();
- if ( matViewBy.find() && matViewBy.groupCount() > 0 )
+ if ( viewByMatcher.find() && viewByMatcher.groupCount() > 0 )
{
- String viewByVal = matViewBy.group( 1 );
+ String viewByVal = viewByMatcher.group( 1 );
+
if ( viewByVal.equalsIgnoreCase( "deid" ) )
{
- dispVal = String.valueOf( dataElement.getId() );
+ displayValue = String.valueOf( dataElement.getId() );
}
else if ( viewByVal.equalsIgnoreCase( "dename" ) )
{
- dispVal = dataElement.getName();
+ displayValue = dataElement.getName();
}
}
- dispVal += " - " + optionComboName;
+ displayValue += " - " + optionComboName;
if ( dataElementCode.contains( "value=\"\"" ) )
{
- dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"[ " + dispVal + " ]\"" );
+ dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"[ " + displayValue + " ]\"" );
}
else
{
- dataElementCode += " value=\"[ " + dispVal + " ]\"";
+ dataElementCode += " value=\"[ " + displayValue + " ]\"";
}
+ StringBuilder title = new StringBuilder( "title=\"" ).append( dataElement.getId() ).append( " - " ).
+ append( dataElement.getName() ).append( " - " ).append( optionCombo.getId() ).append( " - " ).
+ append( optionComboName ).append( " - " ).append( dataElement.getType() ).append( "\"" );
+
if ( dataElementCode.contains( "title=\"\"" ) )
{
- dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"-- " + dataElement.getId()
- + ". " + dataElement.getName() + " " + optionComboId + ". " + optionComboName + " ("
- + dataElement.getType() + ") --\"" );
+ dataElementCode = dataElementCode.replace( "title=\"\"", title );
}
else
{
- dataElementCode += " title=\"-- " + dataElement.getId() + ". " + dataElement.getName() + " "
- + optionComboId + ". " + optionComboName + " (" + dataElement.getType() + ") --\"";
+ dataElementCode += " " + title;
}
}
else
{
if ( dataElementCode.contains( "value=\"\"" ) )
{
- dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"[ " + dispVal + " ]\"" );
+ dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"[ " + displayValue + " ]\"" );
}
else
{
- dataElementCode += " value=\"[ " + dispVal + " ]\"";
+ dataElementCode += " value=\"[ " + displayValue + " ]\"";
}
if ( dataElementCode.contains( "title=\"\"" ) )
{
- dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"-- " + dispVal + " --\"" );
+ dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"" + displayValue + "\"" );
}
else
{
- dataElementCode += " title=\"-- " + dispVal + " --\"";
+ dataElementCode += " title=\"" + displayValue + "\"";
}
}
@@ -322,12 +322,6 @@
appendCode += "/>";
matDataElement.appendReplacement( sb, appendCode );
}
-
- // -----------------------------------------------------------------
- // Go to next data entry field
- // -----------------------------------------------------------------
-
- result = matDataElement.find();
}
// ---------------------------------------------------------------------
@@ -348,22 +342,20 @@
StringBuffer sb = new StringBuffer();
// ---------------------------------------------------------------------
- // Pattern to match data elements in the HTML code.
+ // Pattern to match data elements in the HTML code
// ---------------------------------------------------------------------
Pattern patDataElement = Pattern.compile( "(<input.*?)[/]?>" );
Matcher matDataElement = patDataElement.matcher( preparedCode );
// ---------------------------------------------------------------------
- // Iterate through all matching data element fields.
+ // Iterate through all matching data element fields
// ---------------------------------------------------------------------
- boolean result = matDataElement.find();
-
- while ( result )
+ while ( matDataElement.find() )
{
// -----------------------------------------------------------------
- // Get input HTML code (HTML input field code).
+ // Get input HTML code
// -----------------------------------------------------------------
String dataElementCode = matDataElement.group( 1 );
@@ -372,22 +364,20 @@
// Pattern to extract data element ID from data element field
// -----------------------------------------------------------------
- Pattern patDataElementId = Pattern.compile( "value\\[(.*)\\].value:value\\[(.*)\\].boolean" );
- Matcher matDataElementId = patDataElementId.matcher( dataElementCode );
-
- Pattern patViewBy = Pattern.compile( "view=\"@@(.*)@@\"" );
- Matcher matViewBy = patViewBy.matcher( dataElementCode );
-
- if ( matDataElementId.find() && matDataElementId.groupCount() > 0 )
+ Matcher dataElementMatcher = IDENTIFIER_PATTERN.matcher( dataElementCode );
+
+ Matcher viewByMatcher = VIEWBY_PATTERN.matcher( dataElementCode );
+
+ if ( dataElementMatcher.find() && dataElementMatcher.groupCount() > 0 )
{
// -------------------------------------------------------------
// Get data element id,name, optionCombo id,name of data element
// -------------------------------------------------------------
- int dataElementId = Integer.parseInt( matDataElementId.group( 1 ) );
+ int dataElementId = Integer.parseInt( dataElementMatcher.group( 1 ) );
DataElement dataElement = dataElementService.getDataElement( dataElementId );
- int optionComboId = Integer.parseInt( matDataElementId.group( 2 ) );
+ int optionComboId = Integer.parseInt( dataElementMatcher.group( 2 ) );
DataElementCategoryOptionCombo optionCombo = dataElementCategoryService
.getDataElementCategoryOptionCombo( optionComboId );
String optionComboName = "";
@@ -405,6 +395,7 @@
optionComboName += categoryOption.getName() + " ";
}
}
+
// -------------------------------------------------------------
// Insert name of data element in output code.
// -------------------------------------------------------------
@@ -415,9 +406,9 @@
{
dispVal = dataElement.getShortName();
- if ( matViewBy.find() && matViewBy.groupCount() > 0 )
+ if ( viewByMatcher.find() && viewByMatcher.groupCount() > 0 )
{
- String viewByVal = matViewBy.group( 1 );
+ String viewByVal = viewByMatcher.group( 1 );
if ( viewByVal.equalsIgnoreCase( "deid" ) )
{
@@ -440,16 +431,17 @@
dataElementCode += " value=\"[ " + dispVal + " ]\"";
}
+ StringBuilder title = new StringBuilder( "title=\"" ).append( dataElement.getId() ).append( " - " ).
+ append( dataElement.getName() ).append( " - " ).append( optionCombo.getId() ).append( " - " ).
+ append( optionComboName ).append( " - " ).append( dataElement.getType() ).append( "\"" );
+
if ( dataElementCode.contains( "title=\"\"" ) )
{
- dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"-- " + dataElement.getId()
- + ". " + dataElement.getName() + " " + optionComboId + ". " + optionComboName + " ("
- + dataElement.getType() + ") --\"" );
+ dataElementCode = dataElementCode.replace( "title=\"\"", title );
}
else
{
- dataElementCode += " title=\"-- " + dataElement.getId() + ". " + dataElement.getName() + " "
- + optionComboId + ". " + optionComboName + " (" + dataElement.getType() + ") --\"";
+ dataElementCode += " " + title;
}
}
else
@@ -465,11 +457,11 @@
if ( dataElementCode.contains( "title=\"\"" ) )
{
- dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"-- " + dispVal + " --\"" );
+ dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"" + dispVal + "\"" );
}
else
{
- dataElementCode += " title=\"-- " + dispVal + " --\"";
+ dataElementCode += " title=\"" + dispVal + "\"";
}
}
@@ -481,16 +473,10 @@
appendCode += "/>";
matDataElement.appendReplacement( sb, appendCode );
}
-
- // -----------------------------------------------------------------
- // Go to next data entry field
- // -----------------------------------------------------------------
-
- result = matDataElement.find();
}
// ---------------------------------------------------------------------
- // Add remaining code (after the last match), and return formatted code.
+ // Add remaining code (after the last match), and return formatted code
// ---------------------------------------------------------------------
matDataElement.appendTail( sb );