← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17426: GIS event layer option sets.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 17426 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-11-11 12:05:27 +0100
message:
  GIS event layer option sets.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/plugin.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-apps/src/main/webapp/dhis-web-mapping/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.js	2014-11-10 13:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.js	2014-11-11 11:03:28 +0000
@@ -1055,11 +1055,11 @@
                     lonIndex,
                     latIndex,
                     optionSetIndex,
-                    optionSet,
+                    optionSetHeader,
                     map = Ext.clone(r.metaData.names),
                     updateFeatures;
 
-                updateFeatures = function(map) {
+                updateFeatures = function() {
                     for (var i = 0, header; i < r.headers.length; i++) {
                         header = r.headers[i];
                         map[header.name] = header.column;
@@ -1071,7 +1071,7 @@
                         obj = {};
 
                         for (var j = 0; j < row.length; j++) {
-                            obj[r.headers[j].name] = j === optionSetIndex ? map[row[j]] : row[j];
+                            obj[r.headers[j].name] = j === optionSetIndex ? r.metaData.optionNames[row[j]] || map[row[j]] : row[j];
                         }
 
                         obj[gis.conf.finals.widget.value] = 0;
@@ -1097,6 +1097,19 @@
                     loadLegend(view);
                 };
 
+                getOptionSets = function() {
+                    if (!optionSetHeader) {
+                        updateFeatures();
+                    }
+
+                    dhis2.gis.store.get('optionSets', optionSetHeader.optionSet).done( function(obj) {
+                        Ext.apply(r.metaData.optionNames, gis.util.array.getObjectMap(obj.options, 'code', 'name'));
+                        updateFeatures();
+                    });
+                };
+
+                r.metaData.optionNames = {};
+
                 // name-column map, lonIndex, latIndex, optionSet
                 for (var i = 0, header; i < r.headers.length; i++) {
                     header = r.headers[i];
@@ -1113,7 +1126,7 @@
 
                     if (Ext.isString(header.optionSet) && header.optionSet.length) {
                         optionSetIndex = i;
-                        optionSet = header.optionSet;
+                        optionSetHeader = header;
                     }
                 }
 
@@ -1135,13 +1148,7 @@
                 }
 
                 // option set
-                if (optionSet) {
-                    updateFeatures(r.metaData.names);
-                }
-                else {
-                    updateFeatures(r.metaData.names);
-                }
-
+                getOptionSets();
             };
 
 			if (Ext.isObject(GIS.app)) {
@@ -2740,6 +2747,25 @@
 				return array;
 			};
 
+            util.array.getObjectMap = function(array, idProperty, nameProperty, namePrefix) {
+                if (!(Ext.isArray(array) && array.length)) {
+                    return {};
+                }
+
+                var o = {};
+                idProperty = idProperty || 'id';
+                nameProperty = nameProperty || 'name';
+                namePrefix = namePrefix || '';
+
+                for (var i = 0, obj; i < array.length; i++) {
+                    obj = array[i];
+
+                    o[namePrefix + obj[idProperty]] = obj[nameProperty];
+                }
+
+                return o;
+            };
+
             util.layout = {};
 
 			util.layout.getAnalytical = function(map) {

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/plugin.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/plugin.js	2014-11-04 13:10:27 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/plugin.js	2014-11-11 11:03:28 +0000
@@ -5228,9 +5228,9 @@
                                                 init.namePropertyUrl = namePropertyUrl;
 
                                                 // dhis2
-                                                dhis2.util.namespace('dhis2.er');
+                                                dhis2.util.namespace('dhis2.gis');
 
-                                                dhis2.er.store = dhis2.er.store || new dhis2.storage.Store({
+                                                dhis2.gis.store = dhis2.gis.store || new dhis2.storage.Store({
                                                     name: 'dhis2',
                                                     adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
                                                     objectStores: ['optionSets']
@@ -5241,7 +5241,7 @@
                                                     url: contextPath + '/api/optionSets.jsonp?fields=id,version&paging=false',
                                                     success: function(r) {
                                                         var optionSets = r.optionSets || [],
-                                                            store = dhis2.er.store,
+                                                            store = dhis2.gis.store,
                                                             ids = [],
                                                             url = '',
                                                             callbacks = 0,