← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10990: (GIS) Detailed data elements supported WIP.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 10990 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-05-24 18:04:36 +0200
message:
  (GIS) Detailed data elements supported WIP.
added:
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetInfrastructuralDataElementMapValuesAction.java
modified:
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/org/hisp/dhis/mapping/i18n_module.properties
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/i18n.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
=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetInfrastructuralDataElementMapValuesAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetInfrastructuralDataElementMapValuesAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetInfrastructuralDataElementMapValuesAction.java	2013-05-24 15:50:45 +0000
@@ -0,0 +1,95 @@
+package org.hisp.dhis.mapping.action;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+import org.hisp.dhis.aggregation.AggregatedMapValue;
+import org.hisp.dhis.mapping.MappingService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Jan Henrik Overland
+ * @version $Id$
+ */
+public class GetInfrastructuralDataElementMapValuesAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private MappingService mappingService;
+
+    public void setMappingService( MappingService mappingService )
+    {
+        this.mappingService = mappingService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer periodId;
+
+    public void setPeriodId( Integer periodId )
+    {
+        this.periodId = periodId;
+    }
+
+    private Integer organisationUnitId;
+
+    public void setOrganisationUnitId( Integer organisationUnitId )
+    {
+        this.organisationUnitId = organisationUnitId;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private Collection<AggregatedMapValue> object;
+
+    public Collection<AggregatedMapValue> getObject()
+    {
+        return object;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        object = mappingService.getInfrastructuralDataElementMapValues( periodId, organisationUnitId );
+
+        return SUCCESS;
+    }
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/org/hisp/dhis/mapping/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/org/hisp/dhis/mapping/i18n_module.properties	2013-04-17 10:38:34 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/org/hisp/dhis/mapping/i18n_module.properties	2013-05-24 15:50:45 +0000
@@ -365,4 +365,6 @@
 home=Home
 google_streets=Google Streets
 google_hybrid=Google Hybrid
-openstreetmap=OpenStreetMap
\ No newline at end of file
+openstreetmap=OpenStreetMap
+totals=Totals
+details=Details
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js	2013-05-21 11:02:09 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js	2013-05-24 16:03:12 +0000
@@ -277,7 +277,7 @@
 		};
 
 		util.gui.window.setPositionTopLeft = function(window) {
-			window.setPosition(4,35);
+			window.setPosition(2,33);
 		};
 
 		util.gui.window.addHideOnBlurHandler = function(w) {
@@ -3477,6 +3477,8 @@
 			indicator,
 			dataElementGroup,
 			dataElement,
+			dataElementDetailLevel,
+			dataElementPanel,
 			periodType,
 			period,
 			periodPrev,
@@ -3538,7 +3540,7 @@
 		});
 
 		dataElementsByGroupStore = Ext.create('Ext.data.Store', {
-			fields: ['id', 'name'],
+			fields: ['id', 'name', 'dataElementId', 'optionComboId', 'operandName'],
 			proxy: {
 				type: 'ajax',
 				url: '',
@@ -3556,6 +3558,67 @@
 					this.load(fn);
 				}
 			},
+			sortStore: function() {
+				this.sort('name', 'ASC');
+			},
+			setTotalsProxy: function(uid) {
+				var path;
+
+				if (Ext.isString(uid)) {
+					path = 'dataElementGroups/' + uid + '.json?links=false&paging=false';
+				}
+				else if (uid === 0) {
+					path = 'dataElements.json?paging=false&links=false';
+				}
+
+				if (!path) {
+					alert('Invalid parameter');
+					return;
+				}
+
+				this.setProxy({
+					type: 'ajax',
+					url: gis.conf.url.path_api + path,
+					reader: {
+						type: 'json',
+						root: 'dataElements'
+					}
+				});
+
+				this.load({
+					scope: this,
+					callback: function() {
+						this.sortStore();
+					}
+				});
+			},
+			setDetailsProxy: function(uid) {
+				if (Ext.isString(uid)) {
+					this.setProxy({
+						type: 'ajax',
+						url: gis.conf.url.path_commons + 'getOperands.action?uid=' + uid,
+						reader: {
+							type: 'json',
+							root: 'operands'
+						}
+					});
+
+					this.load({
+						scope: this,
+						callback: function() {
+							this.each(function(r) {
+								r.set('id', r.data.dataElementId + '-' + r.data.optionComboId);
+								r.set('name', r.data.operandName);
+							});
+
+							this.sortStore();
+						}
+					});
+				}
+				else {
+					alert('Invalid parameter');
+				}
+			},
 			listeners: {
 				load: function() {
 					if (!this.isLoaded) {
@@ -3637,13 +3700,13 @@
 				indicatorGroup.show();
 				indicator.show();
 				dataElementGroup.hide();
-				dataElement.hide();
+				dataElementPanel.hide();
 			}
 			else if (valueType === 'dataElement') {
 				indicatorGroup.hide();
 				indicator.hide();
 				dataElementGroup.show();
-				dataElement.show();
+				dataElementPanel.show();
 			}
 		};
 
@@ -3761,16 +3824,27 @@
 			labelWidth: gis.conf.layout.widget.itemlabel_width,
 			hidden: true,
 			store: gis.store.dataElementGroups,
+			loadAvailable: function() {
+				var store = dataElementsByGroupStore,
+					detailLevel = dataElementDetailLevel.getValue(),
+					value = this.getValue();
+
+				if (value !== null) {
+					if (detailLevel === gis.conf.finals.dimension.dataElement.objectName) {
+						store.setTotalsProxy(value);
+					}
+					else {
+						store.setDetailsProxy(value);
+					}
+				}
+			},
 			listeners: {
 				added: function() {
 					this.store.cmp.push(this);
 				},
-				select: function() {
+				select: function(cb) {
 					dataElement.clearValue();
-
-					var store = dataElement.store;
-					store.proxy.url = gis.baseUrl + gis.conf.url.path_api +  'dataElementGroups/' + this.getValue() + '.json?links=false&paging=false';
-					store.load();
+					cb.loadAvailable();
 				}
 			}
 		});
@@ -3782,15 +3856,21 @@
 			displayField: 'name',
 			queryMode: 'local',
 			forceSelection: true,
-			width: gis.conf.layout.widget.item_width,
+			width: gis.conf.layout.widget.item_width - 65,
 			labelWidth: gis.conf.layout.widget.itemlabel_width,
 			listConfig: {loadMask: false},
-			hidden: true,
 			store: dataElementsByGroupStore,
 			listeners: {
 				select: function() {
+					var id = this.getValue(),
+						index = id.indexOf('-');
+
+					if (index !== -1) {
+						id = id.substr(0, index);
+					}
+
 					Ext.Ajax.request({
-						url: gis.baseUrl + gis.conf.url.path_api + 'dataElements/' + this.getValue() + '.json?links=false',
+						url: gis.baseUrl + gis.conf.url.path_api + 'dataElements/' + id + '.json?links=false',
 						success: function(r) {
 							r = Ext.decode(r.responseText);
 
@@ -3817,13 +3897,46 @@
 			}
 		});
 
+		dataElementDetailLevel = Ext.create('Ext.form.field.ComboBox', {
+			style: 'margin-left:2px',
+			queryMode: 'local',
+			editable: false,
+			valueField: 'id',
+			displayField: 'text',
+			width: 65 - 2,
+			value: gis.conf.finals.dimension.dataElement.objectName,
+			store: {
+				fields: ['id', 'text'],
+				data: [
+					{id: gis.conf.finals.dimension.dataElement.objectName, text: GIS.i18n.totals},
+					{id: gis.conf.finals.dimension.operand.objectName, text: GIS.i18n.details}
+				]
+			},
+			listeners: {
+				select: function(cb) {
+					dataElementGroup.loadAvailable();
+					dataElement.clearValue();
+				}
+			}
+		});
+
+		dataElementPanel = Ext.create('Ext.container.Container', {
+			layout: 'column',
+			bodyStyle: 'border:0 none',
+			hidden: true,
+			items: [
+				dataElement,
+				dataElementDetailLevel
+			]
+		});
+
 		periodType = Ext.create('Ext.form.field.ComboBox', {
 			editable: false,
 			valueField: 'id',
 			displayField: 'name',
 			forceSelection: true,
 			queryMode: 'local',
-			width: 116,
+			width: 142,
 			store: gis.store.periodTypes,
 			periodOffset: 0,
 			listeners: {
@@ -3944,7 +4057,7 @@
 			displayField: 'name',
 			queryMode: 'local',
 			value: 2,
-			width: 109,
+			width: 135,
 			store: Ext.create('Ext.data.ArrayStore', {
 				fields: ['id', 'name'],
 				data: [
@@ -3956,12 +4069,14 @@
 
 		colorLow = Ext.create('Ext.ux.button.ColorButton', {
 			style: 'margin-right: 3px',
+			width: 135,
 			value: 'ff0000',
 			scope: this
 		});
 
 		colorHigh = Ext.create('Ext.ux.button.ColorButton', {
 			style: 'margin-right: 3px',
+			width: 135,
 			value: '00ff00',
 			scope: this
 		});
@@ -4405,7 +4520,7 @@
 				{
 					xtype: 'form',
 					cls: 'el-border-0',
-					width: 270,
+					//width: 270,
 					items: [
 						{
 							html: GIS.i18n.data_options,
@@ -4415,7 +4530,7 @@
 						indicatorGroup,
 						indicator,
 						dataElementGroup,
-						dataElement,
+						dataElementPanel,
 						periodTypePanel,
 						period,
 						{

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js	2013-05-24 12:34:17 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js	2013-05-24 15:50:45 +0000
@@ -35,6 +35,13 @@
 					dimensionName: 'dx',
 					objectName: 'de'
 				},
+				operand: {
+					id: 'operand',
+					value: 'operand',
+					param: 'dc',
+					dimensionName: 'dx',
+					objectName: 'dc'
+				},
 				period: {
 					id: 'period',
 					value: 'period',
@@ -78,13 +85,14 @@
 		},
 		url: {
 			path_api: '/api/',
-			path_gis: '/dhis-web-mapping/'
+			path_gis: '/dhis-web-mapping/',
+			path_commons: '../../dhis-web-commons-ajax-json/'
 		},
 		layout: {
 			widget: {
-				item_width: 262,
+				item_width: 288,
 				itemlabel_width: 95,
-				window_width: 284
+				window_width: 310
 			},
 			tool: {
 				item_width: 222,
@@ -1326,10 +1334,20 @@
 			indicator = gis.conf.finals.dimension.indicator,
 			dataElement = gis.conf.finals.dimension.dataElement,
 			period = gis.conf.finals.dimension.period,
-			organisationUnit = gis.conf.finals.dimension.organisationUnit;
+			organisationUnit = gis.conf.finals.dimension.organisationUnit,
+			dx;
 
+		// ou
 		paramString += 'dimension=ou:LEVEL-' + view.organisationUnitLevel.level + '-' + view.parentOrganisationUnit.id;
-		paramString += '&dimension=dx:' + view[type].id;
+
+		// dx
+		if (Ext.isString(view[type].id) && view[type].id.indexOf('-') !== -1) {
+			paramString += '&dimension=co&dimension=dx:' + view[type].id.substr(0, view[type].id.indexOf('-'));
+		}
+		else {
+			paramString += '&dimension=dx:' + view[type].id;
+		}
+
 		paramString += '&filter=pe:' + view.period.id;
 
 		Ext.Ajax.request({

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/i18n.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/i18n.vm	2013-04-17 10:38:34 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/i18n.vm	2013-05-24 15:50:45 +0000
@@ -389,5 +389,7 @@
     home: '$encoder.jsEscape($i18n.getString( 'home' ) , "'")',
     google_streets: '$encoder.jsEscape($i18n.getString( 'google_streets' ) , "'")',
     google_hybrid: '$encoder.jsEscape($i18n.getString( 'google_hybrid' ) , "'")',
-    openstreetmap: '$encoder.jsEscape($i18n.getString( 'openstreetmap' ) , "'")'
+    openstreetmap: '$encoder.jsEscape($i18n.getString( 'openstreetmap' ) , "'")',
+    totals: '$encoder.jsEscape($i18n.getString( 'totals' ) , "'")',
+    details: '$encoder.jsEscape($i18n.getString( 'details' ) , "'")'
 };
\ No newline at end of file