← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13909: GIS, infrastructural data -> web api.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 13909 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-01-31 17:34:17 +0100
message:
  GIS, infrastructural data -> web api.
modified:
  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


--
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-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	2014-01-30 16:34:39 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js	2014-01-31 16:31:07 +0000
@@ -5084,25 +5084,7 @@
 		// Stores
 
 		infrastructuralDataElementValuesStore = Ext.create('Ext.data.Store', {
-			fields: ['dataElementName', 'value'],
-			proxy: {
-				type: 'ajax',
-				url: '../getInfrastructuralDataElementMapValues.action',
-				reader: {
-					type: 'json',
-					root: 'mapValues'
-				}
-			},
-			sortInfo: {field: 'dataElementName', direction: 'ASC'},
-			autoLoad: false,
-			isLoaded: false,
-			listeners: {
-				load: function() {
-					if (!this.isLoaded) {
-						this.isLoaded = true;
-					}
-				}
-			}
+			fields: ['name', 'value']
 		});
 
 		// Components
@@ -5816,25 +5798,7 @@
 		// Stores
 
 		infrastructuralDataElementValuesStore = Ext.create('Ext.data.Store', {
-			fields: ['dataElementName', 'value'],
-			proxy: {
-				type: 'ajax',
-				url: '../getInfrastructuralDataElementMapValues.action',
-				reader: {
-					type: 'json',
-					root: 'mapValues'
-				}
-			},
-			sortInfo: {field: 'dataElementName', direction: 'ASC'},
-			autoLoad: false,
-			isLoaded: false,
-			listeners: {
-				load: function() {
-					if (!this.isLoaded) {
-						this.isLoaded = true;
-					}
-				}
-			}
+			fields: ['name', 'value']
 		});
 
 		// Components
@@ -6682,25 +6646,7 @@
 		});
 
 		infrastructuralDataElementValuesStore = Ext.create('Ext.data.Store', {
-			fields: ['dataElementName', 'value'],
-			proxy: {
-				type: 'ajax',
-				url: '../getInfrastructuralDataElementMapValues.action',
-				reader: {
-					type: 'json',
-					root: 'mapValues'
-				}
-			},
-			sortInfo: {field: 'dataElementName', direction: 'ASC'},
-			autoLoad: false,
-			isLoaded: false,
-			listeners: {
-				load: function() {
-					if (!this.isLoaded) {
-						this.isLoaded = true;
-					}
-				}
-			}
+			fields: ['name', 'value']
 		});
 
 		legendsByLegendSetStore = Ext.create('Ext.data.Store', {
@@ -8619,7 +8565,10 @@
 	initialize = function() {
 		var requests = [],
 			callbacks = 0,
-			init = {},
+			init = {
+				user: {},
+				systemSettings: {}
+			},
 			fn;
 
 		fn = function() {
@@ -8684,10 +8633,7 @@
 											var ou = organisationUnits[0];
 
 											if (ou.id) {
-												init.user = {
-													ou: ou.id
-												};
-
+												init.user.ou = ou.id;
 												init.user.ouc = ou.children ? Ext.Array.pluck(ou.children, 'id') : null;
 											};
 										}
@@ -8699,6 +8645,15 @@
 									}
 								});
 
+								// admin
+								requests.push({
+									url: init.contextPath + '/api/me/authorization/F_GIS_ADMIN',
+									success: function(r) {
+										init.user.isAdmin = Ext.decode(r.responseText);
+										fn();
+									}
+								});
+
 								// organisation unit levels
 								requests.push({
 									url: init.contextPath + '/api/organisationUnitLevels.json?paging=false&links=false',
@@ -8726,11 +8681,24 @@
 									}
 								});
 
-                                // infrastructural
-								requests.push({
-									url: init.contextPath + '/dhis-web-mapping/initialize.action',
-									success: function(r) {
-										init.systemSettings = Ext.decode(r.responseText).systemSettings || {};
+                                // infrastructural data element group
+								requests.push({
+									url: init.contextPath + '/api/configuration/infrastructuralDataElements.json',
+									success: function(r) {
+										var obj = Ext.decode(r.responseText);
+
+										init.systemSettings.infrastructuralDataElementGroup = Ext.isObject(obj) ? obj : null;
+										fn();
+									}
+								});
+
+                                // infrastructural period type
+								requests.push({
+									url: init.contextPath + '/api/configuration/infrastructuralPeriodType.json',
+									success: function(r) {
+										var obj = Ext.decode(r.responseText);
+
+										init.systemSettings.infrastructuralPeriodType = Ext.isObject(obj) ? obj : null;
 										fn();
 									}
 								});
@@ -8744,25 +8712,5 @@
                 });
             }
         });
-
-
-
-
-		//Ext.Ajax.request({
-			//url: '../initialize.action',
-			//success: function(r) {
-				//var init = Ext.decode(r.responseText);
-
-				//GIS.i18n = init.i18n;
-
-				//gis = GIS.core.getInstance(init);
-
-				//GIS.app.createExtensions();
-
-				//GIS.app.extendInstance(gis);
-
-				//gis.viewport = createViewport();
-			//}
-		//});
 	}();
 });

=== 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	2014-01-30 14:43:05 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js	2014-01-31 16:31:07 +0000
@@ -358,28 +358,78 @@
 											editable: false,
 											valueField: 'id',
 											displayField: 'name',
+											emptyText: 'Select period',
 											forceSelection: true,
 											width: 258, //todo
 											labelWidth: 70,
-											store: gis.store.infrastructuralPeriodsByType,
+											store: {
+												fields: ['id', 'name'],
+												data: function() {													
+													var pt = new PeriodType(),
+														periodType = gis.init.systemSettings.infrastructuralPeriodType.id,
+														data;
+														
+													data = pt.get(periodType).generatePeriods({
+														offset: 0,
+														filterFuturePeriods: true,
+														reversePeriods: true
+													});
+
+													if (Ext.isArray(data) && data.length) {
+														data = data.slice(0,5);
+													}
+
+													return data;
+												}()
+											},												
 											lockPosition: false,
 											listeners: {
-												select: function() {
-													infrastructuralPeriod = this.getValue();
-
-													layer.widget.infrastructuralDataElementValuesStore.load({
-														params: {
-															periodId: infrastructuralPeriod,
-															organisationUnitId: att.internalId
+												select: function(cmp) {
+													var period = cmp.getValue(),
+														url = gis.init.contextPath + '/api/analytics.json?',
+														group = gis.init.systemSettings.infrastructuralDataElementGroup;
+
+													if (group && group.dataElements) {
+														url += 'dimension=dx:';
+
+														for (var i = 0; i < group.dataElements.length; i++) {
+															url += group.dataElements[i].id;
+															url += i < group.dataElements.length - 1 ? ';' : '';
+														}
+													}
+
+													url += '&filter=pe:' + period;
+													url += '&filter=ou:' + att.id;
+
+													Ext.Ajax.request({
+														url: url,
+														success: function(r) {
+															var response = Ext.decode(r.responseText),
+																data = [];
+
+															if (Ext.isArray(response.rows)) {
+																for (var i = 0; i < response.rows.length; i++) {
+																	data.push({
+																		name: response.metaData.names[response.rows[i][0]],
+																		value: response.rows[i][1]
+																	});
+																}
+															}
+
+															layer.widget.infrastructuralDataElementValuesStore.loadData(data);
 														}
 													});
+
+													//layer.widget.infrastructuralDataElementValuesStore.load({
+														//params: {
+															//periodId: infrastructuralPeriod,
+															//organisationUnitId: att.internalId
+														//}
+													//});
 												}
 											}
 										},
 										{
-											cls: 'gis-panel-html-separator'
-										},
-										{
 											xtype: 'grid',
 											cls: 'gis-grid',
 											height: 300, //todo
@@ -387,9 +437,9 @@
 											scroll: 'vertical',
 											columns: [
 												{
-													id: 'dataElementName',
+													id: 'name',
 													text: 'Data element',
-													dataIndex: 'dataElementName',
+													dataIndex: 'name',
 													sortable: true,
 													width: 195
 												},
@@ -398,7 +448,7 @@
 													header: 'Value',
 													dataIndex: 'value',
 													sortable: true,
-													width: 60
+													width: 63
 												}
 											],
 											disableSelection: true,
@@ -479,7 +529,7 @@
 					}
 				}));
 			}
-
+			
 			if (isRelocate && isPoint) {
 
                 if (layer.id !== 'facility') {