← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4837: (DV) Clientside indicator/data element storage. Number of server requests reduced.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 4837 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-10-05 13:47:48 +0200
message:
  (DV) Clientside indicator/data element storage. Number of server requests reduced.
modified:
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.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-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-10-04 16:34:11 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/app.js	2011-10-05 11:45:45 +0000
@@ -153,6 +153,34 @@
                 }
             }
         },
+        store: {
+            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};
+                    }
+                });
+            },
+            loadFromStorage: function(s) {
+                var items = [];
+                s.removeAll();
+                for (var obj in s.storage) {
+                    if (s.storage[obj].parent === s.parent) {
+                        items.push(s.storage[obj]);
+                    }
+                }
+                items = Ext.Array.sort(items);
+                s.add(items);
+            },
+            containsParent: function(s) {
+                for (var obj in s.storage) {
+                    if (s.storage[obj].parent === s.parent) {
+                        return true;
+                    }
+                }
+                return false;
+            }
+        },
         dimension: {
             indicator: {
                 getUrl: function(isFilter) {
@@ -275,27 +303,19 @@
                     }
                 },
                 storage: {},
-                addToStorage: function() {
-                    st = this.storage;
-                    this.each( function(r) {
-                        if (!st[r.data.id]) {
-                            st[r.data.id] = {name: r.data.shortName, parent: this.param};
-                        }
-                    });
-                },
                 listeners: {
                     load: function(s) {
-                        s.addToStorage(s);
+                        DV.util.store.addToStorage(s);
                         DV.util.multiselect.filterAvailable(DV.util.getCmp('multiselect[name="availableIndicators"]'),
                             DV.util.getCmp('multiselect[name="selectedIndicators"]'));
                     }
                 }
-            }),            
+            }),
             selected: Ext.create('Ext.data.Store', {
                 fields: ['id', 'shortName'],
                 data: []
             })
-        },        
+        },
         dataelement: {
             available: Ext.create('Ext.data.Store', {
                 fields: ['id', 'name', 'shortName'],
@@ -308,28 +328,20 @@
                     }
                 },
                 storage: {},
-                addToStorage: function() {
-                    st = this.storage;
-                    this.each( function(r) {
-                        if (!st[r.data.id]) {
-                            st[r.data.id] = {name: r.data.shortName, parent: this.param};
-                        }
-                    });
-                },
                 listeners: {
                     load: function(s) {
-                        s.addToStorage(s);
+                        DV.util.store.addToStorage(s);
                         DV.util.multiselect.filterAvailable(DV.util.getCmp('multiselect[name="availableDataElements"]'),
                             DV.util.getCmp('multiselect[name="selectedDataElements"]'));
                     }
                 }
-            }),            
+            }),
             selected: Ext.create('Ext.data.Store', {
                 fields: ['id', 'shortName'],
                 data: []
             })
-        },        
-        chart: null,        
+        },
+        chart: null,
         getChartStore: function(exe) {
             this[DV.state.type](exe);
         },
@@ -338,7 +350,7 @@
             this.chart = Ext.create('Ext.data.Store', {
                 fields: properties,
                 data: DV.data.data
-            });            
+            });
             this.chart.bottom = properties.slice(0, 1);
             this.chart.left = properties.slice(1, properties.length);
             
@@ -347,14 +359,14 @@
             }
             else {
                 return DV.store.chart;
-            }            
+            }
         },
         bar: function(exe) {
             var properties = Ext.Object.getKeys(DV.data.data[0]);
             this.chart = Ext.create('Ext.data.Store', {
                 fields: properties,
                 data: DV.data.data
-            });            
+            });
             this.chart.left = properties.slice(0, 1);
             this.chart.bottom = properties.slice(1, properties.length);
             
@@ -363,30 +375,30 @@
             }
             else {
                 return DV.store.chart;
-            }            
+            }
         }
     };
     
     DV.state = {
         type: DV.conf.finals.chart.column,
-        indiment: [],        
-        period: [],        
-        organisationunit: [],        
+        indiment: [],
+        period: [],
+        organisationunit: [],
         series: {
             cmp: null,
             dimension: DV.conf.finals.dimension.indicator.value,
             data: []
-        },        
+        },
         category: {
             cmp: null,
             dimension: DV.conf.finals.dimension.period.value,
             data: []
-        },        
+        },
         filter: {
             cmp: null,
             dimension: DV.conf.finals.dimension.organisationunit.value,
             data: []
-        },        
+        },
         getState: function(exe) {
             this.resetState();
             
@@ -880,8 +892,14 @@
                                         listeners: {
                                             select: function(cb) {
                                                 var store = DV.store.indicator.available;
-                                                store.param = cb.getValue();
-                                                store.load({params: {id: cb.getValue()}});
+                                                store.parent = cb.getValue();
+                                                
+                                                if (DV.util.store.containsParent(store)) {
+                                                    DV.util.store.loadFromStorage(store);
+                                                }
+                                                else {
+                                                    store.load({params: {id: cb.getValue()}});
+                                                }
                                             }
                                         }
                                     },                                    
@@ -1022,8 +1040,14 @@
                                         listeners: {
                                             select: function(cb) {
                                                 var store = DV.store.dataelement.available;
-                                                store.param = cb.getValue();
-                                                store.load({params: {id: cb.getValue()}});
+                                                store.parent = cb.getValue();
+                                                
+                                                if (DV.util.store.containsParent(store)) {
+                                                    DV.util.store.loadFromStorage(store);
+                                                }
+                                                else {
+                                                    store.load({params: {id: cb.getValue()}});
+                                                }
                                             }
                                         }
                                     },