dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22467
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10795: proper greyfield fix for formutils. also does not add group if there are no available input fields.
------------------------------------------------------------
revno: 10795
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-05-10 20:11:16 +0700
message:
proper greyfield fix for formutils. also does not add group if there are no available input fields.
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.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-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java 2013-05-10 10:39:37 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/FormUtils.java 2013-05-10 13:11:16 +0000
@@ -37,8 +37,6 @@
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.Section;
import org.hisp.dhis.datavalue.DataValue;
-import org.hisp.dhis.system.util.CollectionUtils;
-import org.hisp.dhis.system.util.functional.Predicate;
import java.util.ArrayList;
import java.util.Collection;
@@ -62,20 +60,29 @@
{
for ( Section section : dataSet.getSections() )
{
+ List<Field> fields = inputsFromDataElements( new ArrayList<DataElement>( section.getDataElements() ), new ArrayList<DataElementOperand>( section.getGreyedFields() ) );
+
+ if ( !fields.isEmpty() )
+ {
+ Group s = new Group();
+ s.setLabel( section.getDisplayName() );
+ s.setFields( fields );
+ form.getGroups().add( s );
+ }
+ }
+ }
+ else
+ {
+ List<Field> fields = inputsFromDataElements( new ArrayList<DataElement>( dataSet.getDataElements() ) );
+
+ if ( !fields.isEmpty() )
+ {
Group s = new Group();
- s.setLabel( section.getDisplayName() );
- s.setFields( inputsFromDataElements( new ArrayList<DataElement>( section.getDataElements() ), new ArrayList<DataElementOperand>( section.getGreyedFields() ) ) );
+ s.setLabel( "default" );
+ s.setFields( fields );
form.getGroups().add( s );
}
}
- else
- {
- Group s = new Group();
- s.setLabel( "default" );
- s.setFields( inputsFromDataElements( new ArrayList<DataElement>( dataSet.getDataElements() ) ) );
-
- form.getGroups().add( s );
- }
return form;
}
@@ -90,39 +97,11 @@
{
List<Field> fields = new ArrayList<Field>();
- CollectionUtils.filter( dataElements, new Predicate<DataElement>()
- {
- @Override
- public boolean evaluate( DataElement dataElement )
- {
- for ( DataElementOperand operand : greyedFields )
- {
- if ( dataElement.equals( operand.getDataElement() ) && dataElement.getCategoryCombo().equals( operand.getCategoryOptionCombo().getCategoryCombo() ) )
- {
- return false;
- }
- }
-
- return true;
- }
- } );
-
for ( DataElement dataElement : dataElements )
{
- if ( dataElement.getCategoryCombo().isDefault() )
- {
- Field field = new Field();
-
- field.setLabel( dataElement.getDisplayName() );
- field.setDataElement( dataElement.getUid() );
- field.setCategoryOptionCombo( dataElement.getCategoryCombo().getSortedOptionCombos().get( 0 ).getUid() );
- field.setType( inputTypeFromDataElement( dataElement ) );
-
- fields.add( field );
- }
- else
- {
- for ( DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getCategoryCombo().getSortedOptionCombos() )
+ for ( DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getCategoryCombo().getSortedOptionCombos() )
+ {
+ if ( !isDisabled( dataElement, categoryOptionCombo, greyedFields ) )
{
Field field = new Field();
@@ -139,6 +118,20 @@
return fields;
}
+ private static boolean isDisabled( DataElement dataElement, DataElementCategoryOptionCombo dataElementCategoryOptionCombo, List<DataElementOperand> greyedFields )
+ {
+ for ( DataElementOperand operand : greyedFields )
+ {
+ if ( dataElement.getUid().equals( operand.getDataElement().getUid() )
+ && dataElementCategoryOptionCombo.getUid().equals( operand.getCategoryOptionCombo().getUid() ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private static InputType inputTypeFromDataElement( DataElement dataElement )
{
if ( DataElement.VALUE_TYPE_STRING.equals( dataElement.getType() ) )