← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5527: Periods sorted correctly in visualizer plugin.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 5527 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-12-21 20:43:47 +0100
message:
  Periods sorted correctly in visualizer plugin.
modified:
  dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedValuesPluginAction.java
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.html
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.js
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonminAggregatedValuesPlugin.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-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedValuesPluginAction.java'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedValuesPluginAction.java	2011-12-07 14:23:12 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/GetAggregatedValuesPluginAction.java	2011-12-21 19:42:20 +0000
@@ -30,6 +30,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.List;
 
 import org.hisp.dhis.aggregation.AggregatedDataValue;
 import org.hisp.dhis.aggregation.AggregatedDataValueService;
@@ -128,18 +129,11 @@
         this.lastMonth = lastMonth;
     }
 
-    private boolean monthsThisYear;
-
-    public void setMonthsThisYear( boolean monthsThisYear )
-    {
-        this.monthsThisYear = monthsThisYear;
-    }
-
-    private boolean monthsLastYear;
-
-    public void setMonthsLastYear( boolean monthsLastYear )
-    {
-        this.monthsLastYear = monthsLastYear;
+    private boolean last12Months;
+
+    public void setLast12Months( boolean last12Months )
+    {
+        this.last12Months = last12Months;
     }
 
     private boolean lastQuarter;
@@ -149,18 +143,25 @@
         this.lastQuarter = lastQuarter;
     }
 
-    private boolean quartersThisYear;
-
-    public void setQuartersThisYear( boolean quartersThisYear )
-    {
-        this.quartersThisYear = quartersThisYear;
-    }
-
-    private boolean quartersLastYear;
-
-    public void setQuartersLastYear( boolean quartersLastYear )
-    {
-        this.quartersLastYear = quartersLastYear;
+    private boolean last4Quarters;
+
+    public void setLast4Quarters( boolean last4Quarters )
+    {
+        this.last4Quarters = last4Quarters;
+    }
+
+    private boolean lastSixMonth;
+
+    public void setLastSixMonth( boolean lastSixMonth )
+    {
+        this.lastSixMonth = lastSixMonth;
+    }
+
+    private boolean last2SixMonths;
+
+    public void setLast2SixMonths( boolean last2SixMonths )
+    {
+        this.last2SixMonths = last2SixMonths;
     }
 
     private boolean thisYear;
@@ -170,18 +171,11 @@
         this.thisYear = thisYear;
     }
 
-    private boolean lastYear;
-
-    public void setLastYear( boolean lastYear )
-    {
-        this.lastYear = lastYear;
-    }
-
-    private boolean lastFiveYears;
-
-    public void setLastFiveYears( boolean lastFiveYears )
-    {
-        this.lastFiveYears = lastFiveYears;
+    private boolean last5Years;
+
+    public void setLast5Years( boolean last5Years )
+    {
+        this.last5Years = last5Years;
     }
 
     // -------------------------------------------------------------------------
@@ -202,29 +196,45 @@
         return dataValues;
     }
 
+    private List<Period> periods;
+
+    public List<Period> getPeriods()
+    {
+        return periods;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
+    
+    private List<Period> setNames( List<Period> periods )
+    {
+        for ( Period period : periods )
+        {
+            period.setName( format.formatPeriod( period ) );
+        }
+        
+        return periods;
+    }
 
     public String execute()
         throws Exception
     {
         if ( organisationUnitIds != null
-            && (lastMonth || monthsThisYear || monthsLastYear || lastQuarter || quartersThisYear || quartersLastYear
-                || thisYear || lastYear || lastFiveYears) )
+            && ( lastMonth || last12Months || lastQuarter || last4Quarters || lastSixMonth ||
+                    last2SixMonths || thisYear || last5Years ) )
         {
             RelativePeriods rp = new RelativePeriods();
             rp.setReportingMonth( lastMonth );
-            rp.setMonthsThisYear( monthsThisYear );
-            rp.setMonthsLastYear( monthsLastYear );
+            rp.setLast12Months( last12Months );
             rp.setReportingQuarter( lastQuarter );
-            rp.setQuartersThisYear( quartersThisYear );
-            rp.setQuartersLastYear( quartersLastYear );
+            rp.setLast4Quarters( last4Quarters );
+            rp.setLastSixMonth( lastSixMonth );
+            rp.setLast2SixMonths( last2SixMonths );
             rp.setThisYear( thisYear );
-            rp.setLastYear( lastYear );
-            rp.setLast5Years( lastFiveYears );
+            rp.setLast5Years( last5Years );
 
-            Collection<Period> periods = periodService.reloadPeriods( rp.getRelativePeriods() );
+            periods = periodService.reloadPeriods( setNames( rp.getRelativePeriods() ) );
 
             Collection<Integer> periodIds = new ArrayList<Integer>();
 
@@ -254,7 +264,8 @@
 
                 for ( AggregatedDataValue value : dataValues )
                 {
-                    value.setDataElementName( dataElementService.getDataElement( value.getDataElementId() ).getShortName() );
+                    value.setDataElementName( dataElementService.getDataElement( value.getDataElementId() )
+                        .getShortName() );
                     value.setPeriodName( format.formatPeriod( periodService.getPeriod( value.getPeriodId() ) ) );
                     value.setOrganisationUnitName( organisationUnitService.getOrganisationUnit(
                         value.getOrganisationUnitId() ).getName() );

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js	2011-12-21 13:55:28 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js	2011-12-21 19:42:20 +0000
@@ -1144,11 +1144,13 @@
         data: [],        
         getData: function(exe) {
             this.data = [];
+console.log(DV.state.category.names);return;            
             Ext.Array.each(DV.state.category.names, function(item) {
                 var obj = {};
                 obj[DV.conf.finals.chart.x] = item;
                 DV.chart.data.push(obj);
-            });
+            });     
+console.log(this.data);return;       
             
             Ext.Array.each(DV.chart.data, function(item) {
                 for (var i = 0; i < DV.state.series.names.length; i++) {
@@ -1166,6 +1168,7 @@
                     }
                 }
             });
+console.log(this.data);return;       
             
             if (exe) {
                 DV.store.getChartStore(true);
@@ -2738,7 +2741,7 @@
                         {
                             xtype: 'button',
 							cls: 'dv-toolbar-btn-2',
-                            text: 'Show..',
+                            text: 'Data..',
                             listeners: {
                                 afterrender: function(b) {
                                     this.menu = Ext.create('Ext.menu.Menu', {

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.html'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.html	2011-12-12 10:31:20 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.html	2011-12-21 19:42:20 +0000
@@ -37,7 +37,6 @@
 			
 			DHIS.getChart({
                 indicators: [31664],
-				dataelements: [20911],
 				organisationunits: [18],
 				el: 'chart1',
 				url: url

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.js	2011-12-12 10:31:20 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/plugin/plugin.js	2011-12-21 19:42:20 +0000
@@ -248,15 +248,19 @@
         value: {
             jsonfy: function(r) {
                 r = Ext.JSON.decode(r.responseText);
-                var values = [];
-                for (var i = 0, obj = {}; i < r.length; i++) {
-                    obj.v = r[i][0];
-                    obj[DHIS.conf.finals.dimension.data.value] = r[i][1];
-                    obj[DHIS.conf.finals.dimension.period.value] = r[i][2];
-                    obj[DHIS.conf.finals.dimension.organisationunit.value] = r[i][3];
-                    values.push(obj);
+                var object = {
+                    values: [],
+                    periods: r.p
+                };
+                for (var i = 0; i < r.v.length; i++) {
+                    var obj = {};
+                    obj.v = r.v[i][0];
+                    obj[DHIS.conf.finals.dimension.data.value] = r.v[i][1];
+                    obj[DHIS.conf.finals.dimension.period.value] = r.v[i][2];
+                    obj[DHIS.conf.finals.dimension.organisationunit.value] = r.v[i][3];
+                    object.values.push(obj);
                 }
-                return values;
+                return object;
             }
         }
     };
@@ -323,7 +327,7 @@
                 type: 'column',
                 stacked: false,
                 indicators: [],
-                periods: ['monthsThisYear'],
+                periods: ['last12Months'],
                 organisationunits: [],
                 series: 'data',
                 category: 'period',
@@ -334,6 +338,10 @@
             };
             
             project.state.conf = Ext.applyIf(conf, defaultConf);
+            project.state.conf.type = project.state.conf.type.toLowerCase();
+            project.state.conf.series = project.state.conf.series.toLowerCase();
+            project.state.conf.category = project.state.conf.category.toLowerCase();
+            project.state.conf.filter = project.state.conf.filter.toLowerCase();
             
             project.state.type = project.state.conf.type;
             project.state.series.dimension = project.state.conf.series;
@@ -361,12 +369,13 @@
             Ext.Ajax.request({
                 url: baseUrl,
                 success: function(r) {
-                    project.values = DHIS.util.value.jsonfy(r);
+                    var json = DHIS.util.value.jsonfy(r);
+                    project.values = json.values;
                     
                     if (!project.values.length) {
                         alert('No data values');
                         return;
-                    }
+                    }                    
                     
                     Ext.Array.each(project.values, function(item) {
                         Ext.Array.include(project.state.series.names, DHIS.util.string.getEncodedString(item[project.state.series.dimension]));
@@ -375,6 +384,12 @@
                         item.v = parseFloat(item.v);
                     });
                     
+                    for (var k in project.state.conf) {
+                        if (project.state.conf[k] == 'period') {
+                            project.state[k].names = json.periods;
+                        }
+                    }
+                    
                     DHIS.state.state = project.state;
                     
 					DHIS.chart.getData(project);
@@ -386,12 +401,14 @@
     DHIS.chart = {
         getData: function(project) {
             project.data = [];
+//console.log(project.state.category.names);return;  
 			
             Ext.Array.each(project.state.category.names, function(item) {
                 var obj = {};
                 obj[DHIS.conf.finals.chart.x] = item;
                 project.data.push(obj);
             });
+//console.log(project.data);return;         
             
             Ext.Array.each(project.data, function(item) {
                 for (var i = 0; i < project.state.series.names.length; i++) {
@@ -403,6 +420,7 @@
                     }
                 }
             });
+//console.log(project.data);return;            
                 
 			DHIS.store.getChartStore(project);
         },

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonminAggregatedValuesPlugin.vm'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonminAggregatedValuesPlugin.vm	2011-12-07 14:23:12 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonminAggregatedValuesPlugin.vm	2011-12-21 19:42:20 +0000
@@ -1,1 +1,1 @@
-#set( $indicatorSize = $indicatorValues.size() )#set( $dataSize = $dataValues.size() )[#if( $indicatorSize > 0 )#foreach( $iv in $indicatorValues )["$!{iv.value}","$!{iv.indicatorName}","$!{iv.periodName}","$!{iv.organisationUnitName}"]#if( $velocityCount < $indicatorSize ),#end#end#end#if( $dataSize > 0 )#if( $indicatorSize > 0 ),#end#foreach( $dv in $dataValues )["$!{dv.value}","$!{dv.dataElementName}","$!{dv.periodName}","$!{dv.organisationUnitName}"]#if( $velocityCount < $dataSize ),#end#end#end]
\ No newline at end of file
+#set( $indicatorSize = $indicatorValues.size() )#set( $dataSize = $dataValues.size() )#set( $periodSize = $periods.size() ){"v":[#if( $indicatorSize > 0 )#foreach( $iv in $indicatorValues )["$!{iv.value}","$!{iv.indicatorName}","$!{iv.periodName}","$!{iv.organisationUnitName}"]#if( $velocityCount < $indicatorSize ),#end#end#end#if( $dataSize > 0 )#if( $indicatorSize > 0 ),#end#foreach( $dv in $dataValues )["$!{dv.value}","$!{dv.dataElementName}","$!{dv.periodName}","$!{dv.organisationUnitName}"]#if( $velocityCount < $dataSize ),#end#end#end],"p":[#foreach($p in $periods)"$!encoder.jsonEncode(${p.name})"#if($velocityCount<$periodSize),#end#end]}
\ No newline at end of file