← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6913: Added option for considering org unit as parent in chart plugin

 

------------------------------------------------------------
revno: 6913
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-05-11 11:57:03 +0200
message:
  Added option for considering org unit as parent in chart plugin
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/chart.js
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html


--
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/controller/ChartPluginController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java	2012-05-10 19:02:58 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java	2012-05-11 09:57:03 +0000
@@ -31,6 +31,7 @@
 import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
 import static org.hisp.dhis.system.util.DateUtils.setNames;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
@@ -92,6 +93,7 @@
     public String getChartValues( @RequestParam(required=false) Set<String> indicatorIds,
                                 @RequestParam(required=false) Set<String> dataElementIds,
                                 @RequestParam Set<String> organisationUnitIds,
+                                @RequestParam(required=false) boolean orgUnitIsParent, 
                                 RelativePeriods relativePeriods,
                                 Model model, 
                                 HttpServletResponse response )
@@ -100,7 +102,11 @@
         ChartPluginValue chartValue = new ChartPluginValue();
         
         I18nFormat format = i18nManager.getI18nFormat();
-                
+
+        // ---------------------------------------------------------------------
+        // Periods
+        // ---------------------------------------------------------------------
+
         List<Period> periods = periodService.reloadPeriods( setNames( relativePeriods.getRelativePeriods(), format ) );
 
         if ( periods.isEmpty() )
@@ -113,7 +119,11 @@
         {
             chartValue.getPeriods().add( period.getName() );
         }
-        
+
+        // ---------------------------------------------------------------------
+        // Organisation units
+        // ---------------------------------------------------------------------
+
         List<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsByUid( organisationUnitIds );
         
         if ( organisationUnits.isEmpty() )
@@ -122,11 +132,27 @@
             return null;
         }
         
+        if ( orgUnitIsParent )
+        {
+            List<OrganisationUnit> childOrganisationUnits = new ArrayList<OrganisationUnit>();
+            
+            for ( OrganisationUnit unit : organisationUnits )
+            {
+                childOrganisationUnits.addAll( unit.getChildren() );
+            }
+            
+            organisationUnits = childOrganisationUnits;
+        }
+        
         for ( OrganisationUnit unit : organisationUnits )
         {
             chartValue.getOrgUnits().add( unit.getName() );
         }
-        
+
+        // ---------------------------------------------------------------------
+        // Indicators
+        // ---------------------------------------------------------------------
+
         if ( indicatorIds != null )
         {
             List<Indicator> indicators = indicatorService.getIndicatorsByUid( indicatorIds );
@@ -160,6 +186,10 @@
             }
         }
 
+        // ---------------------------------------------------------------------
+        // Data elements
+        // ---------------------------------------------------------------------
+
         if ( dataElementIds != null )
         {
             List<DataElement> dataElements = dataElementService.getDataElementsByUid( dataElementIds );

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/chart.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/chart.js	2012-05-06 19:28:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/chart.js	2012-05-11 09:57:03 +0000
@@ -38,7 +38,8 @@
             stackedbar: 'stackedbar',
             line: 'line',
             area: 'area',
-            pie: 'pie'
+            pie: 'pie',
+            orgUnitIsParent: 'orgUnitIsParent'
         }
     }
 };
@@ -281,6 +282,12 @@
                     url += '/';
                 }
                 return url;
+            },
+            appendUrlIfTrue: function(url, param, expression) {
+            	if (expression && expression == true) {
+            		url = Ext.String.urlAppend(url, param + '=true');
+            	}
+            	return url;            	
             }
         },
         value: {
@@ -381,6 +388,7 @@
                 filter: 'organisationunit',
                 el: '',
                 legendPosition: false,
+                orgUnitIsParent: false,
                 url: ''
             };
             
@@ -398,6 +406,7 @@
             project.state.series.dimension = project.state.conf.series;
             project.state.category.dimension = project.state.conf.category;
             project.state.filter.dimension = project.state.conf.filter;
+            project.state.orgUnitIsParent = project.state.conf.orgUnitIsParent;
             
             DHIS.state.state = project.state;
             
@@ -445,6 +454,8 @@
             params = params.concat(DHIS.util.dimension[project.state.filter.dimension].getUrl(true));
                         
             var baseUrl = DHIS.util.string.extendUrl(project.state.conf.url) + DHIS.conf.finals.ajax.data_get;
+            baseUrl = DHIS.util.string.appendUrlIfTrue(baseUrl, DHIS.conf.finals.chart.orgUnitIsParent, project.state.orgUnitIsParent);
+            
             Ext.Array.each(params, function(item) {
                 baseUrl = Ext.String.urlAppend(baseUrl, item);
             });

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html	2012-05-09 13:28:07 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/index.html	2012-05-11 09:57:03 +0000
@@ -27,8 +27,11 @@
 			DHIS.getChart({
 				type: 'stackedcolumn',
 				indicators: ['Uvn6LCg7dVU', 'OdiHJayrsKo'],
-				periods: 'last12Months',
+				periods: 'thisYear',
+				category: 'organisationunit',
+				filter: 'period',
 				organisationunits: ['ImspTQPwCqd'],
+				orgUnitIsParent: true,
 				el: 'chart2',
 				url: url
 			});