← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3826: Implement Sorting of ProgramStageDataElement for default data entry form

 

------------------------------------------------------------
revno: 3826
committer: Long <thanhlongngo1988>
branch nick: dhis2
timestamp: Thu 2011-06-02 09:34:04 +0700
message:
  Implement Sorting of ProgramStageDataElement for default data entry form
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStage.hbm.xml
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageDataElement.hbm.xml
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/AddProgramStageAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/UpdateProgramStageAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.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-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElement.java	2011-06-02 02:34:04 +0000
@@ -58,6 +58,8 @@
      * programStage
      */
     private boolean compulsory = false;
+    
+    private Integer sortOrder;
 
     public ProgramStageDataElement( ProgramStage programStage, DataElement dataElement, boolean compulsory )
     {
@@ -65,6 +67,15 @@
         this.dataElement = dataElement;
         this.compulsory = compulsory;
     }
+    
+    public ProgramStageDataElement( ProgramStage programStage, DataElement dataElement, boolean compulsory,
+        Integer sortOrder )
+    {
+        this.programStage = programStage;
+        this.dataElement = dataElement;
+        this.compulsory = compulsory;
+        this.sortOrder = sortOrder;
+    }
 
     public ProgramStageDataElement()
     {
@@ -99,6 +110,16 @@
     {
         this.compulsory = compulsory;
     }
+    
+    public Integer getSortOrder()
+    {
+        return sortOrder;
+    }
+
+    public void setSortOrder( Integer sortOrder )
+    {
+        this.sortOrder = sortOrder;
+    }
 
     // -------------------------------------------------------------------------
     // hashCode, equals and toString

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2011-05-02 13:09:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2011-06-02 02:34:04 +0000
@@ -130,6 +130,9 @@
         executeSql( "ALTER TABLE indicator DROP COLUMN extendeddataelementid" );
         executeSql( "DROP TABLE extendeddataelement" );
         
+        // add sort order for programstage
+        executeSql("ALTER TABLE programstage_dataelements ADD COLUMN sort_order int");
+        
         // ---------------------------------------------------------------------
         // Update tables for dimensional model
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStage.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStage.hbm.xml	2011-05-28 21:25:46 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStage.hbm.xml	2011-06-02 02:34:04 +0000
@@ -20,7 +20,7 @@
 
     <many-to-one name="program" class="org.hisp.dhis.program.Program" column="programid" foreign-key="fk_programstage_program" />
 
-    <set name="programStageDataElements" >
+    <set name="programStageDataElements" order-by="sort_order" >
       <key column="programstageid" />
       <one-to-many class="org.hisp.dhis.program.ProgramStageDataElement" />
     </set>

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageDataElement.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageDataElement.hbm.xml	2011-05-28 21:25:46 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageDataElement.hbm.xml	2011-06-02 02:34:04 +0000
@@ -14,6 +14,8 @@
     </composite-id>
 
     <property name="compulsory" column="compulsory" not-null="true" />
+	  
+	<property name="sortOrder" column="sort_order" /> 
 
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java	2011-05-19 03:18:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java	2011-06-02 02:34:04 +0000
@@ -30,13 +30,12 @@
 import static org.hisp.dhis.i18n.I18nUtils.i18n;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
+import java.util.Set;
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.ProgramStageDataElement;
-import org.hisp.dhis.program.comparator.ProgramStageDataElementSortOrderComparator;
 import org.hisp.dhis.web.api.model.DataElement;
 import org.hisp.dhis.web.api.model.Model;
 import org.hisp.dhis.web.api.model.ModelList;
@@ -136,10 +135,7 @@
 
             List<DataElement> des = new ArrayList<DataElement>();
 
-            List<ProgramStageDataElement> programStageDataElements = new ArrayList<ProgramStageDataElement>(
-                programStage.getProgramStageDataElements() );
-
-            Collections.sort( programStageDataElements, new ProgramStageDataElementSortOrderComparator() );
+            Set<ProgramStageDataElement> programStageDataElements =  programStage.getProgramStageDataElements();
 
             for ( ProgramStageDataElement programStagedataElement : programStageDataElements )
             {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/AddProgramStageAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/AddProgramStageAction.java	2011-05-24 02:10:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/AddProgramStageAction.java	2011-06-02 02:34:04 +0000
@@ -158,7 +158,7 @@
         {
             DataElement dataElement = dataElementService.getDataElement( selectedDataElementsValidator.get( i ) );
             ProgramStageDataElement programStageDataElement = new ProgramStageDataElement( programStage, dataElement,
-                this.compulsories.get( i ) );
+                this.compulsories.get( i ), new Integer( i ) );
             programStageDataElementService.addProgramStageDataElement( programStageDataElement );
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/UpdateProgramStageAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/UpdateProgramStageAction.java	2011-05-24 02:10:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/programstage/UpdateProgramStageAction.java	2011-06-02 02:34:04 +0000
@@ -151,12 +151,14 @@
             if ( programStageDataElement == null )
             {
                 programStageDataElement = new ProgramStageDataElement( programStage, dataElement, this.compulsories
-                    .get( i ) );
+                    .get( i ), new Integer( i ) );
                 programStageDataElementService.addProgramStageDataElement( programStageDataElement );
             }
             else
             {
                 programStageDataElement.setCompulsory( this.compulsories.get( i ) );
+                
+                programStageDataElement.setSortOrder( new Integer( i ) );
 
                 programStageDataElementService.updateProgramStageDataElement( programStageDataElement );
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm	2011-05-24 02:10:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addProgramStageForm.vm	2011-06-02 02:34:04 +0000
@@ -103,6 +103,12 @@
 				</table>
 			</div>
 			</td>
+			
+		<td style="width:30px; text-align:center">
+            <a href="javascript:moveUpDataElement()"><img src="../images/move_up.png"/></a><br/><br/>
+            <a href="javascript:moveDownDataElement()"><img src="../images/move_down.png"/></a><br/><br/>
+        </td>  
+			
       </tr>
     </tbody>
 </table>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js	2011-03-30 04:59:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programStage.js	2011-06-02 02:34:04 +0000
@@ -89,6 +89,43 @@
 	});
 }
 
+//-----------------------------------------------------------------------------
+//Move Table Row Up and Down
+//-----------------------------------------------------------------------------
+
+
+function moveUpDataElement()
+{
+	var selectedList = jQuery("#selectedList");
+	jQuery("#selectedList").find("tr").each( function( i, item ){
+		item = jQuery(item);
+		if( item.hasClass("selected") )
+		{
+			var prev = item.prev('#selectedList tr');
+			if (prev.length == 1) 
+			{ 
+				prev.before(item);
+			}
+		}
+	});
+}
+
+function moveDownDataElement()
+{
+	var selectedList = jQuery("#selectedList");
+	jQuery("#selectedList").find("tr").each( function( i, item ){
+		item = jQuery(item);
+		if( item.hasClass("selected") )
+		{
+			var next = item.next('#selectedList tr');
+			if (next.length == 1) 
+			{ 
+				next.after(item);
+			}
+		}
+	});
+}
+
 function unSelectDataElement( element )
 {
 	element = jQuery(element);	

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.vm	2011-05-24 02:10:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updateProgramStageForm.vm	2011-06-02 02:34:04 +0000
@@ -114,6 +114,12 @@
 				</table>
 			</div>
         </td>
+        
+        <td style="width:30px; text-align:center">
+            <a href="javascript:moveUpDataElement()"><img src="../images/move_up.png"/></a><br/><br/>
+            <a href="javascript:moveDownDataElement()"><img src="../images/move_down.png"/></a><br/><br/>
+        </td>  
+        
     </tr>
     </tbody>
 </table>