← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5299: (DV) Server response minimised + Improved code.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 5299 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-12-06 11:57:06 +0100
message:
  (DV) Server response minimised + Improved code.
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonminDataElements.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonminIndicators.vm
  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/jsonminAggregatedValues.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-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonminDataElements.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonminDataElements.vm	2011-09-22 13:17:39 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonminDataElements.vm	2011-12-06 10:53:15 +0000
@@ -1,2 +1,2 @@
 #set( $size = $dataElements.size() )
-{"dataElements":[#foreach( $dataElement in $dataElements ){"id":$!{dataElement.id},"shortName":"$!encoder.jsonEncode( ${dataElement.shortName} )"}#if( $velocityCount < $size ),#end#end]}
\ No newline at end of file
+{"dataElements":[#foreach( $dataElement in $dataElements ){"id":$!{dataElement.id},"s":"$!encoder.jsonEncode( ${dataElement.shortName} )"}#if( $velocityCount < $size ),#end#end]}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonminIndicators.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonminIndicators.vm	2011-09-22 13:17:39 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonminIndicators.vm	2011-12-06 10:53:15 +0000
@@ -1,2 +1,1 @@
-#set( $size = $indicators.size() )
-{"indicators":[#foreach( $indicator in $indicators ){"id":$!{indicator.id},"shortName":"$!encoder.jsonEncode( ${indicator.shortName} )"}#if( $velocityCount < $size ),#end#end]}
\ No newline at end of file
+#set( $size = $indicators.size() ){"indicators":[#foreach( $indicator in $indicators ){"id":$!{indicator.id},"s":"$!encoder.jsonEncode( ${indicator.shortName} )"}#if( $velocityCount < $size ),#end#end]}
\ No newline at end of file

=== 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-01 12:26:35 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js	2011-12-06 10:53:15 +0000
@@ -86,18 +86,16 @@
             
     DV.init = Ext.JSON.decode(r.responseText);
     DV.init.isInit = true;
+    
     DV.init.initialize = function() {
-        DV.util.combobox.filter.category();
-        
+        DV.util.combobox.filter.category();        
         DV.store.column = DV.store.defaultChartStore;
         DV.store.column_stacked = DV.store.defaultChartStore;
         DV.store.bar_stacked = DV.store.bar;
         DV.store.line = DV.store.defaultChartStore;
         DV.store.area = DV.store.defaultChartStore;
-        DV.store.pie = DV.store.defaultChartStore;
-        
-        DV.chart.data = DV.conf.init.data;
-        
+        DV.store.pie = DV.store.defaultChartStore;        
+        DV.chart.data = DV.conf.init.data;        
         DV.exe.execute(true, DV.init.isInit);
     };
     
@@ -109,10 +107,12 @@
         dimension: {
             indicator: {},
             dataelement: {},
-            period: []
+            period: [],
+            organisationunit: {}
         },
-        datatable: null,
-        toolbar: {}
+        toolbar: {
+            menuitem: {}
+        }
     };
     
     DV.util = {
@@ -133,7 +133,7 @@
                 if (selected.length) {
                     var array = [];
                     Ext.Array.each(selected, function(item) {
-                        array.push({id: item, shortName: a.store.getAt(a.store.find('id', item)).data.shortName});
+                        array.push({id: item, s: a.store.getAt(a.store.find('id', item)).data.s});
                     });
                     s.store.add(array);
                 }
@@ -142,7 +142,7 @@
             selectAll: function(a, s) {
                 var array = [];
                 a.store.each( function(r) {
-                    array.push({id: r.data.id, shortName: r.data.shortName});
+                    array.push({id: r.data.id, s: r.data.s});
                 });
                 s.store.add(array);
                 this.filterAvailable(a, s);
@@ -209,7 +209,7 @@
             addToStorage: function(s) {
                 s.each( function(r) {
                     if (!s.storage[r.data.id]) {
-                        s.storage[r.data.id] = {id: r.data.id, shortName: r.data.shortName, name: r.data.shortName, parent: s.parent};
+                        s.storage[r.data.id] = {id: r.data.id, s: r.data.s, name: r.data.s, parent: s.parent};
                     }
                 });
             },
@@ -223,7 +223,7 @@
                 }
                 items = Ext.Array.sort(items);
                 s.add(items);
-                s.sort('shortName', 'ASC');
+                s.sort('s', 'ASC');
             },
             containsParent: function(s) {
                 for (var obj in s.storage) {
@@ -249,11 +249,11 @@
                 getNames: function(exception) {
                     var a = [];
                     DV.cmp.dimension.indicator.selected.store.each( function(r) {
-                        a.push(DV.util.string.getEncodedString(r.data.shortName));
+                        a.push(DV.util.string.getEncodedString(r.data.s));
                     });
                     if (DV.cmp.dimension.dataelement.selected.store) {
                         DV.cmp.dimension.dataelement.selected.store.each( function(r) {
-                            a.push(DV.util.string.getEncodedString(r.data.shortName));
+                            a.push(DV.util.string.getEncodedString(r.data.s));
                         });
                     }
                     if (exception && !a.length) {
@@ -304,11 +304,11 @@
             organisationunit: {
                 getUrl: function(isFilter) {
                     var a = [],
-                        treepanel = DV.util.getCmp('treepanel'),
-                        selection = treepanel.getSelectionModel().getSelection();
+                        tp = DV.cmp.dimension.organisationunit.treepanel,
+                        selection = tp.getSelectionModel().getSelection();
                     if (!selection.length) {
-                        selection = [treepanel.getRootNode()];
-                        treepanel.selectRoot();
+                        selection = [tp.getRootNode()];
+                        tp.selectRoot();
                     }
                     Ext.Array.each(selection, function(r) {
                         a.push('organisationUnitIds=' + r.data.id);
@@ -317,11 +317,11 @@
                 },
                 getNames: function(exception) {
                     var a = [],
-                        treepanel = DV.util.getCmp('treepanel'),
-                        selection = treepanel.getSelectionModel().getSelection();
+                        tp = DV.cmp.dimension.organisationunit.treepanel,
+                        selection = tp.getSelectionModel().getSelection();
                     if (!selection.length) {
-                        selection = [treepanel.getRootNode()];
-                        treepanel.selectRoot();
+                        selection = [tp.getRootNode()];
+                        tp.selectRoot();
                     }
                     Ext.Array.each(selection, function(r) {
                         a.push(DV.util.string.getEncodedString(r.data.text));
@@ -527,6 +527,16 @@
             getEncodedString: function(text) {
                 return text.replace(/[^a-zA-Z 0-9(){}<>_!+;:?*&%#-]+/g,'');
             }
+        },
+        value: {
+            jsonfy: function(r) {
+                r = Ext.JSON.decode(r.responseText);
+                var values = [];
+                for (var i = 0; i < r.length; i++) {
+                    values.push({v: r[i][0], d: r[i][1], p: r[i][2], o: r[i][3]});
+                }
+                return values;
+            }
         }
     };
     
@@ -543,7 +553,7 @@
         },        
         indicator: {
             available: Ext.create('Ext.data.Store', {
-                fields: ['id', 'name', 'shortName'],
+                fields: ['id', 'name', 's'],
                 proxy: {
                     type: 'ajax',
                     url: DV.conf.finals.ajax.url_commons + 'getIndicatorsMinified.action',
@@ -556,19 +566,18 @@
                 listeners: {
                     load: function(s) {
                         DV.util.store.addToStorage(s);
-                        DV.util.multiselect.filterAvailable(DV.util.getCmp('multiselect[name="availableIndicators"]'),
-                            DV.util.getCmp('multiselect[name="selectedIndicators"]'));
+                        DV.util.multiselect.filterAvailable(DV.cmp.dimension.indicator.available, DV.cmp.dimension.indicator.selected);
                     }
                 }
             }),
             selected: Ext.create('Ext.data.Store', {
-                fields: ['id', 'shortName'],
+                fields: ['id', 's'],
                 data: []
             })
         },
         dataelement: {
             available: Ext.create('Ext.data.Store', {
-                fields: ['id', 'name', 'shortName'],
+                fields: ['id', 'name', 's'],
                 proxy: {
                     type: 'ajax',
                     url: DV.conf.finals.ajax.url_commons + 'getDataElementsMinified.action',
@@ -581,13 +590,12 @@
                 listeners: {
                     load: function(s) {
                         DV.util.store.addToStorage(s);
-                        DV.util.multiselect.filterAvailable(DV.util.getCmp('multiselect[name="availableDataElements"]'),
-                            DV.util.getCmp('multiselect[name="selectedDataElements"]'));
+                        DV.util.multiselect.filterAvailable(DV.cmp.dimension.dataelement.available, DV.cmp.dimension.dataelement.selected);
                     }
                 }
             }),
             selected: Ext.create('Ext.data.Store', {
-                fields: ['id', 'shortName'],
+                fields: ['id', 's'],
                 data: []
             })
         },
@@ -725,7 +733,7 @@
             Ext.Ajax.request({
                 url: baseUrl,
                 success: function(r) {
-                    DV.value.values = Ext.JSON.decode(r.responseText).values;
+                    DV.value.values = DV.util.value.jsonfy(r);
                     
                     if (!DV.value.values.length) {
                         DV.mask.hide();
@@ -733,12 +741,11 @@
                         return;
                     }
                     
-                    var storage = Ext.Object.merge(DV.store[i].available.storage, DV.store[d].available.storage);
-                    
+                    var storage = Ext.Object.merge(DV.store[i].available.storage, DV.store[d].available.storage);                    
                     Ext.Array.each(DV.value.values, function(item) {
                         item[DV.conf.finals.dimension.data.value] = DV.util.string.getEncodedString(storage[item.d].name);
                         item[DV.conf.finals.dimension.period.value] = DV.util.string.getEncodedString(DV.util.dimension.period.getNameById(item.p));
-                        item[DV.conf.finals.dimension.organisationunit.value] = DV.util.getCmp('treepanel').store.getNodeById(item.o).data.text;
+                        item[DV.conf.finals.dimension.organisationunit.value] = DV.cmp.dimension.organisationunit.treepanel.store.getNodeById(item.o).data.text;
                         item.v = parseFloat(item.v);
                     });
                     
@@ -1015,12 +1022,7 @@
                         height: DV.conf.layout.east_gridcolumn_height
                     }
                 ],
-                store: DV.store.datatable,
-                listeners: {
-                    afterrender: function() {
-                        DV.cmp.datatable = this;
-                    }
-                }
+                store: DV.store.datatable
             });
             
             if (exe) {
@@ -1304,7 +1306,7 @@
                                                 name: 'availableIndicators',
                                                 cls: 'multiselect',
                                                 width: (DV.conf.layout.west_fieldset_width - 22) / 2,
-                                                displayField: 'shortName',
+                                                displayField: 's',
                                                 valueField: 'id',
                                                 queryMode: 'remote',
                                                 store: DV.store.indicator.available,
@@ -1350,7 +1352,7 @@
                                                 name: 'selectedIndicators',
                                                 cls: 'multiselect',
                                                 width: (DV.conf.layout.west_fieldset_width - 22) / 2,
-                                                displayField: 'shortName',
+                                                displayField: 's',
                                                 valueField: 'id',
                                                 ddReorder: true,
                                                 queryMode: 'local',
@@ -1463,7 +1465,7 @@
                                                 name: 'availableDataElements',
                                                 cls: 'multiselect',
                                                 width: (DV.conf.layout.west_fieldset_width - 22) / 2,
-                                                displayField: 'shortName',
+                                                displayField: 's',
                                                 valueField: 'id',
                                                 queryMode: 'remote',
                                                 store: DV.store.dataelement.available,
@@ -1509,7 +1511,7 @@
                                                 name: 'selectedDataElements',
                                                 cls: 'multiselect',
                                                 width: (DV.conf.layout.west_fieldset_width - 22) / 2,
-                                                displayField: 'shortName',
+                                                displayField: 's',
                                                 valueField: 'id',
                                                 ddReorder: true,
                                                 queryMode: 'remote',
@@ -1734,6 +1736,9 @@
                                             }
                                         }),
                                         listeners: {
+                                            added: function() {
+                                                DV.cmp.dimension.organisationunit.treepanel = this;
+                                            },
                                             itemcontextmenu: function(v, r, h, i, e) {
                                                 if (v.menu) {
                                                     v.menu.destroy();
@@ -1769,7 +1774,7 @@
                                     },
                                     expand: function(fs) {
                                         DV.util.fieldset.collapseFieldsets([DV.cmp.fieldset.indicator, DV.cmp.fieldset.dataelement, DV.cmp.fieldset.period]);
-                                        var tp = fs.down('treepanel');
+                                        var tp = DV.cmp.dimension.organisationunit.treepanel;
                                         if (!tp.isRendered) {
                                             tp.isRendered = true;
                                             tp.getRootNode().expand();
@@ -1787,11 +1792,11 @@
                     },
                     collapse: function() {                    
                         this.collapsed = true;
-                        DV.util.getCmp('button[name="resizewest"]').setText('>>>');
+                        DV.cmp.toolbar.resizewest.setText('>>>');
                     },
                     expand: function() {
                         this.collapsed = false;
-                        DV.util.getCmp('button[name="resizewest"]').setText('<<<');
+                        DV.cmp.toolbar.resizewest.setText('<<<');
                     }
                 }
             },
@@ -1818,6 +1823,11 @@
                                 else {
                                     p.collapse();
                                 }
+                            },
+                            listeners: {
+                                added: function() {
+                                    DV.cmp.toolbar.resizewest = this;
+                                }
                             }
                         },
                         {
@@ -1851,6 +1861,11 @@
                                                         p.collapse();
                                                     }
                                                     DV.cmp.toolbar.resizeeast.show();
+                                                },
+                                                listeners: {
+                                                    added: function() {
+                                                        DV.cmp.toolbar.menuitem.datatable = this;
+                                                    }
                                                 }
                                             }
                                         ]                                            
@@ -1859,10 +1874,10 @@
                             },
                             handler: function() {
                                 if (DV.cmp.region.east.items.length) {
-                                    this.menu.down('menuitem').enable();
+                                    DV.cmp.toolbar.menuitem.datatable.enable();
                                 }
                                 else {
-                                    this.menu.down('menuitem').disable();
+                                    DV.cmp.toolbar.menuitem.datatable.disable();
                                 }
                             }
                         },
@@ -1974,8 +1989,8 @@
             resize: function(vp) {
                 DV.cmp.region.west.setWidth(DV.conf.layout.west_width);
                 
-                if (DV.cmp.datatable) {
-                    DV.cmp.datatable.setHeight(DV.util.viewport.getSize().y - DV.conf.layout.east_tbar_height);
+                if (DV.datatable.datatable) {
+                    DV.datatable.datatable.setHeight(DV.util.viewport.getSize().y - DV.conf.layout.east_tbar_height);
                 }
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonminAggregatedValues.vm'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonminAggregatedValues.vm	2011-11-26 14:08:29 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/jsonminAggregatedValues.vm	2011-12-06 10:53:15 +0000
@@ -1,1 +1,1 @@
-#set( $indicatorSize = $indicatorValues.size() )#set( $dataSize = $dataValues.size() ){"values":[#if( $indicatorSize > 0 )#foreach( $iv in $indicatorValues ){"v":"$!{iv.value}","d":"$!{iv.indicatorId}","p":"$!{iv.periodId}","o":"$!{iv.organisationUnitId}"}#if( $velocityCount < $indicatorSize ),#end#end#end#if( $dataSize > 0 )#if( $indicatorSize > 0 ),#end#foreach( $dv in $dataValues ){"v":"$!{dv.value}","d":"$!{dv.dataElementId}","p":"$!{dv.periodId}","o":"$!{dv.organisationUnitId}"}#if( $velocityCount < $dataSize ),#end#end#end]}
\ No newline at end of file
+#set( $indicatorSize = $indicatorValues.size() )#set( $dataSize = $dataValues.size() )[#if( $indicatorSize > 0 )#foreach( $iv in $indicatorValues )["$!{iv.value}","$!{iv.indicatorId}","$!{iv.periodId}","$!{iv.organisationUnitId}"]#if( $velocityCount < $indicatorSize ),#end#end#end#if( $dataSize > 0 )#if( $indicatorSize > 0 ),#end#foreach( $dv in $dataValues )["$!{dv.value}","$!{dv.dataElementId}","$!{dv.periodId}","$!{dv.organisationUnitId}"]#if( $velocityCount < $dataSize ),#end#end#end]
\ No newline at end of file