← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19277: Program indicator, cleaned up logic

 

------------------------------------------------------------
revno: 19277
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-06-03 16:47:49 +0200
message:
  Program indicator, cleaned up logic
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/GetProgramAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicator.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramIndicator.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-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/GetProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/GetProgramAction.java	2015-03-29 20:22:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/program/GetProgramAction.java	2015-06-03 14:47:49 +0000
@@ -33,8 +33,6 @@
 import java.util.List;
 
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
-import org.hisp.dhis.constant.Constant;
-import org.hisp.dhis.constant.ConstantService;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
@@ -45,7 +43,6 @@
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.user.UserGroup;
 import org.hisp.dhis.user.UserGroupService;
-import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -88,9 +85,6 @@
         this.periodService = periodService;
     }
 
-    @Autowired
-    private ConstantService constantService;
-
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -154,13 +148,6 @@
         return programIndicators;
     }
 
-    private List<Constant> constants;
-
-    public List<Constant> getConstants()
-    {
-        return constants;
-    }
-
     private List<PeriodType> periodTypes = new ArrayList<>();
 
     public List<PeriodType> getPeriodTypes()
@@ -188,10 +175,6 @@
 
         Collections.sort( programIndicators, IdentifiableObjectNameComparator.INSTANCE );
 
-        constants = new ArrayList<>( constantService.getAllConstants() );
-
-        Collections.sort( constants, IdentifiableObjectNameComparator.INSTANCE );
-
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorAction.java	2015-06-03 14:01:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/java/org/hisp/dhis/trackedentity/action/programindicator/GetProgramIndicatorAction.java	2015-06-03 14:47:49 +0000
@@ -35,8 +35,10 @@
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.constant.Constant;
 import org.hisp.dhis.constant.ConstantService;
+import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramIndicator;
 import org.hisp.dhis.program.ProgramIndicatorService;
+import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.system.filter.AggregatableTrackedEntityAttributeValueFilter;
 import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
 import org.hisp.dhis.util.FilterUtils;
@@ -46,7 +48,6 @@
 
 /**
  * @author Chau Thu Tran
- * @version $ DeleteProgramIndicatorAction Apr 16, 2013 3:24:51 PM $
  */
 public class GetProgramIndicatorAction
     implements Action
@@ -64,6 +65,9 @@
 
     @Autowired
     private ConstantService constantService;
+    
+    @Autowired
+    private ProgramService programService;
 
     // -------------------------------------------------------------------------
     // Setters
@@ -75,6 +79,13 @@
     {
         this.id = id;
     }
+    
+    private Integer programId;
+
+    public void setProgramId( Integer programId )
+    {
+        this.programId = programId;
+    }
 
     private ProgramIndicator programIndicator;
 
@@ -83,6 +94,13 @@
         return programIndicator;
     }
 
+    private Program program;
+    
+    public Program getProgram()
+    {
+        return program;
+    }
+
     private String description;
 
     public String getDescription()
@@ -119,21 +137,24 @@
     public String execute()
         throws Exception
     {
-        programIndicator = programIndicatorService.getProgramIndicator( id );
-
-        description = programIndicatorService.getExpressionDescription( programIndicator.getExpression() );
-        
-        filter = programIndicatorService.getExpressionDescription( programIndicator.getFilter() );
-
-        attributes = new ArrayList<>( programIndicator.getProgram().getTrackedEntityAttributes() );
-        
-        FilterUtils.filter( attributes, AggregatableTrackedEntityAttributeValueFilter.INSTANCE );
-        
-        constants = new ArrayList<>( constantService.getAllConstants() );
-        
-        Collections.sort( constants, IdentifiableObjectNameComparator.INSTANCE );
+        if ( id != null )
+        {
+            programIndicator = programIndicatorService.getProgramIndicator( id );
+            description = programIndicatorService.getExpressionDescription( programIndicator.getExpression() );        
+            filter = programIndicatorService.getExpressionDescription( programIndicator.getFilter() );
+        }
+        
+        if ( programId != null )
+        {            
+            program = programService.getProgram( programId );
+            attributes = new ArrayList<>( program.getTrackedEntityAttributes() );
+            constants = new ArrayList<>( constantService.getAllConstants() );
+
+            FilterUtils.filter( attributes, AggregatableTrackedEntityAttributeValueFilter.INSTANCE );
+            Collections.sort( attributes, IdentifiableObjectNameComparator.INSTANCE );
+            Collections.sort( constants, IdentifiableObjectNameComparator.INSTANCE );
+        }
         
         return SUCCESS;
     }
-
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml	2015-06-02 15:46:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/resources/struts.xml	2015-06-03 14:47:49 +0000
@@ -1024,7 +1024,7 @@
     </action>
 
     <action name="showAddProgramIndicator"
-      class="org.hisp.dhis.trackedentity.action.program.GetProgramAction">
+      class="org.hisp.dhis.trackedentity.action.programindicator.GetProgramIndicatorAction">
       <result name="success" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-maintenance-program/addProgramIndicator.vm</param>
       <param name="javascripts">javascript/programIndicator.js</param>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js	2015-06-02 22:11:37 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/javascript/programIndicator.js	2015-06-03 14:47:49 +0000
@@ -10,7 +10,7 @@
 // -----------------------------------------------------------------------------
 
 function showUpdateProgramIndicator( context ) {
-  location.href = 'showUpdateProgramIndicator.action?id=' + context.id;
+  location.href = 'showUpdateProgramIndicator.action?id=' + context.id + '&programId=' + context.program;
 }
 
 function removeIndicator( context ) {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicator.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicator.vm	2015-02-11 16:59:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicator.vm	2015-06-03 14:47:49 +0000
@@ -16,7 +16,7 @@
 <table class="mainPageTable">
 	<tr>
 		<td style="text-align:right">
-			<input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddProgramIndicator.action?id=$program.id'" style="width:100px"><br>
+			<input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddProgramIndicator.action?programId=$program.id'" style="width:100px"><br>
 			<input type="button" value="$i18n.getString( 'back' )" onclick="window.location.href='program.action'" style="width:100px">
 		</td>
 	</tr>
@@ -35,7 +35,8 @@
 				<tbody id="list">
 					#set( $mark = false )
 					#foreach( $programIndicator in $programIndicators )
-						<tr id="tr${programIndicator.id}" data-id="$!programIndicator.id" data-uid="$!programIndicator.uid" data-type="ProgramIndicator" data-name="$encoder.htmlEncode( $!programIndicator.displayName )"
+						<tr id="tr${programIndicator.id}" data-id="$!programIndicator.id" data-uid="$!programIndicator.uid" 
+							data-type="ProgramIndicator" data-name="$encoder.htmlEncode( $!programIndicator.displayName )" data-program="$program.id"
 						    data-can-manage="$security.canManage( $programIndicator )"
 						    data-can-update="$security.canUpdate( $programIndicator )"
 						    data-can-delete="$security.canDelete( $programIndicator )">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm	2015-06-03 13:37:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/programIndicatorForm.vm	2015-06-03 14:47:49 +0000
@@ -25,7 +25,7 @@
 		        <tr>
 					<td>
 						<select id="expression-program-stage" onChange="getTrackedEntityDataElements('expression');" style="width:35%;margin-right:20px;">
-							<option value=''>[ $i18n.getString('select_program_stage') ]</option>
+							<option>[ $i18n.getString('select_program_stage') ]</option>
 							#foreach( $programStage in $program.programStages )
 								<option value='$programStage.uid'>$programStage.displayName</option>
 							#end
@@ -55,9 +55,9 @@
 		        </tr>
 		        <tr>
 					<td>
-						<select multiple id="expression-attributes" name="expression-attributes" size="7" style="width:100%" ondblclick="insertAttribute(this,'A');">
+						<select multiple id="expression-attributes" name="expression-attributes" size="7" style="width:100%" ondblclick="insertAttribute('expression');">
 							#foreach( $programAttribute in $attributes )
-								<option value='$programAttribute.attribute.uid'>$encoder.htmlEncode($programAttribute.attribute.displayName)</option>
+								<option value='$programAttribute.uid'>$encoder.htmlEncode($programAttribute.displayName)</option>
 							#end
 						</select>
 					</td>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramIndicator.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramIndicator.vm	2015-06-02 22:11:37 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-program/src/main/webapp/dhis-web-maintenance-program/updateProgramIndicator.vm	2015-06-03 14:47:49 +0000
@@ -20,8 +20,6 @@
 });
 </script>
 
-#set($program = $programIndicator.program)
-
 <h3>$i18n.getString( "update_program_indicator" ) #openHelp( "program_indicator" )</h3>
 		
 <h4>$encoder.htmlEncode($program.displayName)</h4>