← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14644: Apprival UI, loading of data report

 

------------------------------------------------------------
revno: 14644
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-04-03 19:51:13 +0200
message:
  Apprival UI, loading of data report
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroup.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroupSet.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroups.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataapproval/action/GetCategoryOptionGroupsAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataApprovalForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataApproval.js


--
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-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroup.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroup.vm	2014-02-13 09:51:36 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroup.vm	2014-04-03 17:51:13 +0000
@@ -1,6 +1,7 @@
 { "categoryOptionGroup": 
   {
     "id": $!{categoryOptionGroup.id},
+    "uid": "$!{categoryOptionGroup.uid}",
     "name": "$!encoder.jsonEncode( ${categoryOptionGroup.displayName} )",
 	"shortName": "$!encoder.jsonEncode( ${categoryOptionGroup.displayShortName} )",
 	"code": "$!encoder.jsonEncode( ${categoryOptionGroup.code} )",

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroupSet.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroupSet.vm	2014-02-13 12:09:31 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroupSet.vm	2014-04-03 17:51:13 +0000
@@ -1,6 +1,7 @@
 { "categoryOptionGroupSet": 
   {
     "id": $!{categoryOptionGroupSet.id},
+    "uid": "$!{categoryOptionGroupSet.uid}",
     "name": "$!encoder.jsonEncode( ${categoryOptionGroupSet.displayName} )",
     "description": "$!encoder.jsonEncode( ${categoryOptionGroupSet.description} )",
     "memberCount": "$categoryOptionGroupSet.members.size()"

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroups.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroups.vm	2014-02-17 14:36:01 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionGroups.vm	2014-04-03 17:51:13 +0000
@@ -3,10 +3,12 @@
 #foreach( $categoryOptionGroup in $categoryOptionGroups )
   {
     "id": $!{categoryOptionGroup.id},
+    "uid": "$!{categoryOptionGroup.uid}",
     "name": "$!encoder.jsonEncode( ${categoryOptionGroup.displayName} )",
 	"shortName": "$!encoder.jsonEncode( ${categoryOptionGroup.displayShortName} )",
 	"code": "$!encoder.jsonEncode( ${categoryOptionGroup.code} )",
-    "memberCount": "$categoryOptionGroup.members.size()"
+    "memberCount": "$categoryOptionGroup.members.size()",
+    "groupSet": "$!categoryOptionGroup.groupSet.uid"
   }#if( $velocityCount < $size ),#end 
 #end
 ]

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataapproval/action/GetCategoryOptionGroupsAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataapproval/action/GetCategoryOptionGroupsAction.java	2014-04-03 13:57:45 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataapproval/action/GetCategoryOptionGroupsAction.java	2014-04-03 17:51:13 +0000
@@ -73,11 +73,11 @@
     // Output
     // -------------------------------------------------------------------------
 
-    private List<CategoryOptionGroup> objects;
+    private List<CategoryOptionGroup> categoryOptionGroups;
 
-    public List<CategoryOptionGroup> getObjects()
+    public List<CategoryOptionGroup> getCategoryOptionGroups()
     {
-        return objects;
+        return categoryOptionGroups;
     }
 
     // -------------------------------------------------------------------------
@@ -95,15 +95,17 @@
     {
         if ( ou != null )
         {
-            int ouLevel = organisationUnitService.getLevelOfOrganisationUnit( ou );
-            
-            List<DataApprovalLevel> approvalLevels = approvalLevelService.getUserDataApprovalLevels(); // TODO filter by org unit level
-    
+            int orgUnitLevel = organisationUnitService.getLevelOfOrganisationUnit( ou );
+            
+            List<DataApprovalLevel> approvalLevels = approvalLevelService.getUserDataApprovalLevels();
+
+            FilterUtils.filter( approvalLevels, new DataApprovalLevelOrgUnitLevelFilter( orgUnitLevel ) );
+            
             Set<CategoryOptionGroupSet> groupSets = getCategoryOptionGroupSets( approvalLevels );
             
-            objects = new ArrayList<CategoryOptionGroup>( categoryService.getAllCategoryOptionGroups() );
+            categoryOptionGroups = new ArrayList<CategoryOptionGroup>( categoryService.getAllCategoryOptionGroups() );
             
-            FilterUtils.filter( objects, new CategoryOptionGroupGroupSetFilter( groupSets ) );        
+            FilterUtils.filter( categoryOptionGroups, new CategoryOptionGroupGroupSetFilter( groupSets ) );        
         }
         
         return SUCCESS;    
@@ -135,6 +137,23 @@
         return groupSets;
     }
     
+    class DataApprovalLevelOrgUnitLevelFilter
+        implements Filter<DataApprovalLevel>
+    {
+        private int orgUnitLevel;
+        
+        public DataApprovalLevelOrgUnitLevelFilter( int orgUnitLevel )
+        {
+            this.orgUnitLevel = orgUnitLevel;
+        }
+        
+        @Override
+        public boolean retain( DataApprovalLevel level )
+        {
+            return level != null && level.getOrgUnitLevel() == orgUnitLevel;
+        }
+    }
+    
     class CategoryOptionGroupGroupSetFilter
         implements Filter<CategoryOptionGroup>
     {

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml	2014-04-03 13:57:45 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml	2014-04-03 17:51:13 +0000
@@ -199,7 +199,7 @@
     </action>
     
     <action name="getCategoryOptionGroups" class="org.hisp.dhis.reporting.dataapproval.action.GetCategoryOptionGroupsAction">    
-      <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonIdentifiableObjects.vm</result>
+      <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonCategoryOptionGroups.vm</result>
       <param name="onExceptionReturn">plainTextError</param>
     </action>
 

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataApprovalForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataApprovalForm.vm	2014-04-03 17:22:46 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataApprovalForm.vm	2014-04-03 17:51:13 +0000
@@ -92,7 +92,7 @@
 </div>
 
 <div class="inputSection">
-<input type="button" value='$i18n.getString( "get_data" )' style="width:120px" onclick="dhis2.dsr.generateDataSetReport()">
+<input type="button" value='$i18n.getString( "get_data" )' style="width:120px" onclick="dhis2.appr.generateDataReport()">
 <input type="button" value='$i18n.getString( "cancel" )' style="width:120px" onclick="dhis2.dsr.hideCriteria()">
 </div>
 

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataApproval.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataApproval.js	2014-04-03 17:22:46 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataApproval.js	2014-04-03 17:51:13 +0000
@@ -55,8 +55,8 @@
 	
 	$.getJSON( url, {ou:ou}, function( json ) {
 		var html = "";
-		$.each( json.objects, function( index, group ) {
-			html += "<option value=\"" + group.uid + "\">" + group.name + "</option>";
+		$.each( json.categoryOptionGroups, function( index, group ) {
+			html += "<option value=\"" + group.uid + "\" data-dimension=\"" + group.groupSet + "\">" + group.name + "</option>";
 		} );
 		
 		$( "#categoryOptionGroupSection" ).show();
@@ -64,6 +64,60 @@
 	} );
 }
 
+dhis2.appr.getDataReport = function()
+{
+	var ds = $( "#dataSetId" ).val();
+	
+    var dataReport = {
+        ds: ds,
+        pe: $( "#periodId" ).val(),
+        ou: selectionTreeSelection.getSelectedUid()[0]
+    };
+    
+    var cog = $( "#categoryOptionGroupId" ).val();
+    var cogs = $( "#categoryOptionGroupId :selected" ).data( "dimension" );
+    
+    if ( cog && cogs ) {
+    	var item = cogs + ":" + cog;
+    	dataReport.dimension = item;
+    }
+    
+    return dataReport;
+}
+
+dhis2.appr.generateDataReport = function()
+{
+	var dataReport = dhis2.appr.getDataReport();
+	
+	if ( !dataReport.ds )
+    {
+        setHeaderMessage( i18n_select_data_set );
+        return false;
+    }
+    if ( !dataReport.pe )
+    {
+        setHeaderMessage( i18n_select_period );
+        return false;
+    }
+    if ( !selectionTreeSelection.isSelected() )
+    {
+        setHeaderMessage( i18n_select_organisation_unit );
+        return false;
+    }
+
+    hideHeaderMessage();
+	$( "#criteria" ).hide( "fast" );
+	$( "#content" ).hide( "fast" );
+    showLoader();
+    
+    $.get( "generateDataSetReport.action", dataReport, function( data ) {
+    	$( '#content' ).html( data );
+    	hideLoader();
+    	$( "#content" ).show( "fast" );
+    	setTableStyles();
+    } );
+}
+
 //------------------------------------------------------------------------------
 // Approval
 //------------------------------------------------------------------------------