← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20387: GIS program data in favorites.

 

------------------------------------------------------------
revno: 20387
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-09-28 14:25:26 +0300
message:
  GIS program data in favorites.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.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/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js	2015-09-27 12:09:57 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js	2015-09-28 11:25:26 +0000
@@ -8727,7 +8727,8 @@
 				ouDim = view.rows[0],
 				vType = dxDim.dimension === dimConf.operand.objectName ? dimConf.dataElement.objectName : dxDim.dimension,
 				lType = Ext.isObject(view.legendSet) && Ext.isString(view.legendSet.id) ? gis.conf.finals.widget.legendtype_predefined : gis.conf.finals.widget.legendtype_automatic,
-				objectNameCmpMap = {},
+				itemTypeCmpMap = {},
+                objectNameProgramCmpMap = {},
 				isOu = false,
 				isOuc = false,
 				isOugc = false,
@@ -8735,14 +8736,19 @@
 				groups = [],
 				setLayerGui,
 				setWidgetGui,
-                dataDim;
-
-			objectNameCmpMap[dimConf.indicator.objectName] = indicator;
-			objectNameCmpMap[dimConf.dataElement.objectName] = dataElement;
-			objectNameCmpMap[dimConf.operand.objectName] = dataElement;
-			objectNameCmpMap[dimConf.dataSet.objectName] = dataSet;
-			objectNameCmpMap[dimConf.eventDataItem.objectName] = eventDataItem;
-			objectNameCmpMap[dimConf.programIndicator.objectName] = programIndicator;
+                dxItemType,
+                dxObjectName;
+
+			itemTypeCmpMap[dimConf.indicator.itemType] = indicator;
+			itemTypeCmpMap[dimConf.dataElement.itemType] = dataElement;
+			itemTypeCmpMap[dimConf.operand.itemType] = dataElement;
+			itemTypeCmpMap[dimConf.dataSet.itemType] = dataSet;
+			itemTypeCmpMap[dimConf.programDataElement.itemType] = eventDataItem;
+			itemTypeCmpMap[dimConf.programAttribute.itemType] = eventDataItem;
+			itemTypeCmpMap[dimConf.programIndicator.itemType] = programIndicator;
+
+            objectNameProgramCmpMap[dimConf.eventDataItem.objectName] = eventDataItemProgram;
+            objectNameProgramCmpMap[dimConf.programIndicator.objectName] = programIndicatorProgram;
 
 			setWidgetGui = function() {
 
@@ -8754,17 +8760,31 @@
 				// Reset
 				reset(true);
 
+                // dx type
+                dxItemType = gis.util.dhis.getDataDimensionItemTypes(view.dataDimensionItems)[0];
+                dxObjectName = dimConf.itemTypeMap[dxItemType].objectName;
+
 				// Value type
-				valueType.setValue(dxDim.objectName);
-				valueTypeToggler(dxDim.objectName);
+				valueType.setValue(dxObjectName);
+				valueTypeToggler(dxObjectName);
 
-                if (dxDim.objectName === dimConf.dataElement.objectName) {
-                    dataElementDetailLevel.setValue(dxDim.dimension);
+                if (dxObjectName === dimConf.dataElement.objectName) {
+                    dataElementDetailLevel.setValue(dxObjectName);
                 }
 
 				// Data
-				objectNameCmpMap[dxDim.objectName].store.add(dxDim.items[0]);
-				objectNameCmpMap[dxDim.objectName].setValue(dxDim.items[0].id);
+				itemTypeCmpMap[dxItemType].store.add(dxDim.items[0]);
+				itemTypeCmpMap[dxItemType].setValue(dxDim.items[0].id);
+
+                // program
+                if (dxObjectName === dimConf.eventDataItem.objectName && view.program) {
+                    objectNameProgramCmpMap[dimConf.eventDataItem.objectName].store.add(view.program);
+                    objectNameProgramCmpMap[dimConf.eventDataItem.objectName].setValue(view.program.id);
+                }
+                else if (dxObjectName === dimConf.programIndicator.objectName && view.program) {
+                    objectNameProgramCmpMap[dimConf.programIndicator.objectName].store.add(view.program);
+                    objectNameProgramCmpMap[dimConf.programIndicator.objectName].setValue(view.program.id);
+                }
 
 				// Period
 				period.store.add(gis.conf.period.relativePeriodRecordsMap[peDim.items[0].id] ? gis.conf.period.relativePeriodRecordsMap[peDim.items[0].id] : peDim.items[0]);
@@ -8851,7 +8871,7 @@
                 ds = dimConf.dataSet.objectName,
                 di = dimConf.eventDataItem.objectName;
                 pi = dimConf.programIndicator.objectName,
-                vtype = valueType.getValue() === de ? dataElementDetailLevel.getValue() : valueType.getValue(),
+                vType = valueType.getValue() === de ? dataElementDetailLevel.getValue() : valueType.getValue(),
 				objectNameCmpMap = {},
 				view = {};
 
@@ -8866,21 +8886,21 @@
             view.layer = layer.id;
 
             // dx
-            if (objectNameCmpMap[vtype].getValue()) {
+            if (objectNameCmpMap[vType].getValue()) {
                 view.columns = [{
                     dimension: 'dx',
-                    objectName: vtype,
+                    objectName: vType,
                     items: [{
-                        id: objectNameCmpMap[vtype].getValue()
+                        id: objectNameCmpMap[vType].getValue()
                     }]
                 }];
             }
 
             // program
-            if (vtype === di && eventDataItemProgram.getValue()) {
+            if (vType === di && eventDataItemProgram.getValue()) {
                 view.program = {id: eventDataItemProgram.getValue()};
             }
-            else if (vtype === pi && programIndicatorProgram.getValue()) {
+            else if (vType === pi && programIndicatorProgram.getValue()) {
                 view.program = {id: programIndicatorProgram.getValue()};
             }
 

=== 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	2015-09-27 12:09:57 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.js	2015-09-28 11:25:26 +0000
@@ -1105,7 +1105,7 @@
 
                 gis.alert(r);
             };
-console.log(gis.util.connection);
+            
             if (isPlugin) {
                 Ext.data.JsonP.request({
                     url: url,
@@ -2752,36 +2752,53 @@
 						value: 'indicators',
 						param: 'in',
 						dimensionName: 'dx',
-						objectName: 'in'
+						objectName: 'in',
+                        itemType: 'INDICATOR'
 					},
 					dataElement: {
 						id: 'dataElement',
 						value: 'dataElement',
 						param: 'de',
 						dimensionName: 'dx',
-						objectName: 'de'
+						objectName: 'de',
+                        itemType: 'AGGREGATE_DATA_ELEMENT'
 					},
 					operand: {
 						id: 'operand',
 						value: 'operand',
 						param: 'dc',
 						dimensionName: 'dx',
-						objectName: 'dc'
+						objectName: 'dc',
+                        itemType: 'DATA_ELEMENT_OPERAND'
 					},
 					dataSet: {
 						value: 'dataSets',
 						dimensionName: 'dx',
-						objectName: 'ds'
+						objectName: 'ds',
+                        itemType: 'DATA_SET'
 					},
 					eventDataItem: {
 						value: 'eventDataItem',
 						dimensionName: 'dx',
 						objectName: 'di'
 					},
+                    programDataElement: {
+						value: 'programDataElement',
+						dimensionName: 'dx',
+						objectName: 'di',
+                        itemType: 'PROGRAM_DATA_ELEMENT'
+					},
+                    programAttribute: {
+						value: 'programAttribute',
+						dimensionName: 'dx',
+						objectName: 'di',
+                        itemType: 'PROGRAM_ATTRIBUTE'
+					},
 					programIndicator: {
 						value: 'programIndicator',
 						dimensionName: 'dx',
-						objectName: 'pi'
+						objectName: 'pi',
+                        itemType: 'PROGRAM_INDICATOR'
 					},
 					period: {
 						id: 'period',
@@ -2828,6 +2845,34 @@
 				}
 			};
 
+            // dimension objectNameMap
+            (function() {
+                dimConf = conf.finals.dimension;
+
+                dimConf.objectNameMap = {};
+                dimConf.objectNameMap[dimConf.indicator.objectName] = dimConf.indicator;
+                dimConf.objectNameMap[dimConf.dataElement.objectName] = dimConf.dataElement;
+                dimConf.objectNameMap[dimConf.operand.objectName] = dimConf.operand;
+                dimConf.objectNameMap[dimConf.dataSet.objectName] = dimConf.dataSet;
+                dimConf.objectNameMap[dimConf.programDataElement.objectName] = dimConf.programDataElement;
+                dimConf.objectNameMap[dimConf.programAttribute.objectName] = dimConf.programAttribute;
+                dimConf.objectNameMap[dimConf.programIndicator.objectName] = dimConf.programIndicator;
+            })();
+
+            // dimension itemTypeMap
+            (function() {
+                dimConf = conf.finals.dimension;
+
+                dimConf.itemTypeMap = {};
+                dimConf.itemTypeMap[dimConf.indicator.itemType] = dimConf.indicator;
+                dimConf.itemTypeMap[dimConf.dataElement.itemType] = dimConf.dataElement;
+                dimConf.itemTypeMap[dimConf.operand.itemType] = dimConf.operand;
+                dimConf.itemTypeMap[dimConf.dataSet.itemType] = dimConf.dataSet;
+                dimConf.itemTypeMap[dimConf.programDataElement.itemType] = dimConf.programDataElement;
+                dimConf.itemTypeMap[dimConf.programAttribute.itemType] = dimConf.programAttribute;
+                dimConf.itemTypeMap[dimConf.programIndicator.itemType] = dimConf.programIndicator;
+            })();
+
 			conf.layout = {
 				widget: {
 					item_width: 288,
@@ -3400,6 +3445,22 @@
                 window.show();
             };
 
+            util.dhis = {};
+
+            util.dhis.getDataDimensionItemTypes = function(dataDimensionItems) {
+                var types = [];
+
+                if (Ext.isArray(dataDimensionItems) && dataDimensionItems.length) {
+                    for (var i = 0, obj; i < dataDimensionItems.length; i++) {
+                        if (Ext.isObject(dataDimensionItems[i])) {
+                            types.push(dataDimensionItems[i].dataDimensionItemType);
+                        }
+                    }
+                }
+
+                return types;
+            };
+        
             util.connection = {};
 
             util.connection.ajax = function(requestConfig, authConfig) {
@@ -3535,6 +3596,8 @@
 
                 // hidden: boolean (false)
 
+                // dataDimensionItems: array
+
                 getValidatedDimensionArray = function(dimensionArray) {
                     var dimensions = [];
 
@@ -3707,6 +3770,8 @@
                     layout.legendSet = config.legendSet;
 
                     layout.organisationUnitGroupSet = config.organisationUnitGroupSet;
+                    
+                    layout.dataDimensionItems = config.dataDimensionItems;                    
 
                     if (Ext.Array.from(config.userOrgUnit).length) {
                         layout.userOrgUnit = Ext.Array.from(config.userOrgUnit);