← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8101: WIP dynamic fields cde

 

------------------------------------------------------------
revno: 8101
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-09-16 00:53:29 +0200
message:
  WIP dynamic fields cde
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetCategoryOptionCombosAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.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-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2012-09-15 14:27:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2012-09-15 22:53:29 +0000
@@ -220,16 +220,16 @@
             }
             else if ( dynamicInputMatcher.find() && dynamicInputMatcher.groupCount() > 0 )
             {
-                String categoryOptionComboUid = dynamicInputMatcher.group( 2 );
-                DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( categoryOptionComboUid );
+                int categoryOptionComboId = Integer.parseInt( dynamicInputMatcher.group( 2 ) );
+                DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( categoryOptionComboId );
                 
                 displayValue = categoryOptionCombo != null ? "value=\"[ " + categoryOptionCombo.getDisplayName() + " ]\"" : "[ " + i18n.getString( "cat_option_combo_not_exist" ) + " ]";
                 displayTitle = categoryOptionCombo != null ? "title=\"" + categoryOptionCombo.getDisplayName() + "\"" : "[ " + i18n.getString( "cat_option_combo_not_exist" ) + " ]";
             }
             else if ( dynamicSelectMatcher.find() && dynamicSelectMatcher.groupCount() > 0 )
             {
-                String categoryComboUid = dynamicSelectMatcher.group( 2 );
-                DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryCombo( categoryComboUid );
+                int categoryComboId = Integer.parseInt( dynamicSelectMatcher.group( 2 ) );
+                DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryCombo( categoryComboId );
                 
                 displayValue = categoryCombo != null ? "value=\"[ " + categoryCombo.getDisplayName() + " ]\"" : "[ " + i18n.getString( "cat_combo_not_exist" );
                 displayTitle = categoryCombo != null ? "title=\"" + categoryCombo.getDisplayName() + "\"" : "[ " + i18n.getString( "cat_combo_not_exist" );
@@ -270,6 +270,9 @@
 
         Map<Integer, DataElement> dataElementMap = getDataElementMap( dataSet );
 
+        Set<DataElement> dataElementsNotInForm = new HashSet<DataElement>( dataSet.getDataElements() );
+        dataElementsNotInForm.removeAll( getDataElementsInDataEntryForm( dataSet ) );
+        
         while ( inputMatcher.find() )
         {
             // -----------------------------------------------------------------
@@ -279,6 +282,7 @@
             String inputHtml = inputMatcher.group();
 
             Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( inputHtml );
+            Matcher dynamicSelectMatcher = DYNAMIC_SELECT_PATTERN.matcher( inputHtml );
 
             if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
             {
@@ -325,6 +329,9 @@
 
                 inputMatcher.appendReplacement( sb, inputHtml );
             }
+            else if ( dynamicSelectMatcher.find() && dynamicSelectMatcher.groupCount() > 0 )
+            {
+            }
         }
 
         inputMatcher.appendTail( sb );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java	2012-09-15 21:52:33 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java	2012-09-15 22:53:29 +0000
@@ -99,7 +99,7 @@
             return;
         }
         
-        Period period = PeriodType.createPeriodExternalId( pe ); //TODO change to ISO
+        Period period = PeriodType.getPeriodFromIsoString( pe );
         
         if ( period == null )
         {

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetCategoryOptionCombosAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetCategoryOptionCombosAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetCategoryOptionCombosAction.java	2012-09-15 22:53:29 +0000
@@ -32,6 +32,7 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
 
 import com.opensymphony.xwork2.Action;
@@ -52,6 +53,13 @@
     {
         this.dataElementService = dataElementService;
     }
+    
+    private DataElementCategoryService categoryService;
+
+    public void setCategoryService( DataElementCategoryService categoryService )
+    {
+        this.categoryService = categoryService;
+    }
 
     // -------------------------------------------------------------------------
     // Input
@@ -64,6 +72,13 @@
         this.id = id;
     }
 
+    private Integer categoryComboId;
+
+    public void setCategoryComboId( Integer categoryComboId )
+    {
+        this.categoryComboId = categoryComboId;
+    }
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -95,6 +110,15 @@
                 }
             }
         }
+        else if ( categoryComboId != null )
+        {
+            DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryCombo( categoryComboId );
+            
+            if ( categoryCombo != null )
+            {
+                categoryOptionCombos = categoryCombo.getOptionCombos();
+            }
+        }
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2012-09-03 19:53:34 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2012-09-15 22:53:29 +0000
@@ -351,6 +351,7 @@
   <bean id="org.hisp.dhis.commons.action.GetCategoryOptionCombosAction" class="org.hisp.dhis.commons.action.GetCategoryOptionCombosAction"
     scope="prototype">
     <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+    <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
   </bean>
 
   <bean id="org.hisp.dhis.commons.action.GetDataElementAction" class="org.hisp.dhis.commons.action.GetDataElementAction"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2012-09-15 11:19:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2012-09-15 22:53:29 +0000
@@ -1,6 +1,6 @@
 
 var currentDynamicElementCode = null;
-var currentCategoryComboUid = null;
+var currentCategoryComboId = null;
 var currentCategoryComboName = null;
 
 $( document ).ready( function() {
@@ -377,8 +377,8 @@
 function insertDropDownList() {
 	var oEditor = $("#designTextarea").ckeditorGet();
 	
-	if ( currentDynamicElementCode && currentCategoryComboUid ) {
-		var id = currentDynamicElementCode + "-" + currentCategoryComboUid + "-dynselect";
+	if ( currentDynamicElementCode && currentCategoryComboId ) {
+		var id = currentDynamicElementCode + "-" + currentCategoryComboId + "-dynselect";
 		var template = '<input id="' + id + '" value="[ ' + currentCategoryComboName + ' ]" title="' + currentCategoryComboName + '" style="width:12em;" />';
 		oEditor.insertHtml( template );
 	}
@@ -388,16 +388,16 @@
  * A unique code is used to associate the data element drop down with the input
  * fields for each category option combo. The format for input field identifier is:
  * 
- * "<unique code>-<category option combo uid>-dyninput"
+ * "<unique code>-<category option combo id>-dyninput"
  */
 function insertDynamicElement() {
 	var oEditor = $("#designTextarea").ckeditorGet();
 	var $option = $("#dynamicElementSelector option:selected");
 	
 	if( $option.length !== 0 ) {
-		var categoryOptionComboUid = $option.val();
+		var categoryOptionComboId = $option.val();
 		var categoryOptionComboName = $option.text();
-		var id = currentDynamicElementCode + "-" + categoryOptionComboUid + "-dyninput";
+		var id = currentDynamicElementCode + "-" + categoryOptionComboId + "-dyninput";
 		
 		var template = '<input id="' + id + '" value="[ ' + categoryOptionComboName + ' ]" title="' + categoryOptionComboName + '" style="width:7em;text-align:center;" />';
 		oEditor.insertHtml( template );
@@ -413,16 +413,16 @@
 	$("#dynamicElementSelect").hide();
 	$("#dynamicElementInsert").show();
 	
-	var categoryComboUid = $("#categoryComboSelect option:selected").val();
+	var categoryComboId = $("#categoryComboSelect option:selected").val();
 	var categoryComboName = $("#categoryComboSelect option:selected").text();
 
 	currentDynamicElementCode = getRandomCode();
-	currentCategoryComboUid = categoryComboUid;
+	currentCategoryComboId = categoryComboId;
 	currentCategoryComboName = categoryComboName;
 	
 	clearListById( "dynamicElementSelector" );
 	
-	var optionCombos = $.getJSON( "../api/categoryCombos/" + categoryComboUid + ".json", function( json ) {
+	var optionCombos = $.getJSON( "../dhis-web-commons-ajax-json/getCategoryOptionCombos.action?categoryComboId=" + categoryComboId, function( json ) {
 		$.each( json.categoryOptionCombos, function( index, value ) {
 			addOptionById( "dynamicElementSelector", value.id, value.name );
 		} );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2012-09-13 14:34:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2012-09-15 22:53:29 +0000
@@ -134,7 +134,7 @@
 						<div style="color:#666; margin-top:5px; margin-bottom:5px;">$i18n.getString( "select_category_combo_for_which_to_insert" )</div>
 						<select id="categoryComboSelect" style="width: 100%; margin-bottom: 10px;">
 							#foreach( $categoryCombo in $categoryCombos )
-							<option value="$categoryCombo.uid">$encoder.htmlEncode( $categoryCombo.name )</option>
+							<option value="$categoryCombo.id">$encoder.htmlEncode( $categoryCombo.name )</option>
 							#end
 						</select><br>
 						<button type="button" id="startButton">$i18n.getString( "start" )</button>