← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14531: ER, data source download.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 14531 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-03-29 10:37:37 +0100
message:
  ER, data source download.
modified:
  dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/app.js
  dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/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-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/app.js	2014-03-28 12:11:24 +0000
+++ dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/app.js	2014-03-29 09:36:06 +0000
@@ -4765,52 +4765,7 @@
 			};
 
 			web.report.getData = function(view, isUpdateGui) {
-				var paramString = '?',
-					features = [];
-
-				// stage
-				paramString += 'stage=' + view.stage.id;
-
-				// ou
-				if (Ext.isArray(view.organisationUnits)) {
-                    paramString += '&dimension=ou:';
-
-					for (var i = 0; i < view.organisationUnits.length; i++) {
-						paramString += view.organisationUnits[i].id;
-                        paramString += i < (view.organisationUnits.length - 1) ? ';' : '';
-					}
-				}
-
-				// de
-				for (var i = 0, element; i < view.dataElements.length; i++) {
-					element = view.dataElements[i];
-
-					paramString += '&dimension=' + element.id;
-
-					if (element.value) {
-						if (element.operator) {
-							paramString += ':' + element.operator;
-						}
-
-						paramString += ':' + element.value;
-					}
-				}
-
-				// pe
-				if (Ext.isArray(view.periods)) {
-					paramString += '&dimension=pe:';
-
-					for (var i = 0; i < view.periods.length; i++) {
-						paramString += view.periods[i].id + (i < view.periods.length - 1 ?  ';' : '');
-					}
-				}
-				else {
-					paramString += '&startDate=' + view.startDate;
-					paramString += '&endDate=' + view.endDate;
-				}
-
-				// hierarchy
-				paramString += view.showHierarchy ? '&hierarchyMeta=true' : '';
+				var paramString = web.analytics.getParamString(view);
 
 				// show mask
 				web.mask.show(ns.app.centerRegion);
@@ -4819,7 +4774,7 @@
                 ns.app.dateData = new Date();
 
 				Ext.Ajax.request({
-					url: ns.core.init.contextPath + '/api/analytics/events/' + view.type + '/' + view.program.id + '.json' + paramString,
+					url: ns.core.init.contextPath + paramString,
 					disableCaching: false,
 					scope: this,
 					failure: function(r) {
@@ -4948,6 +4903,11 @@
 					ns.app.centerRegion.removeAll(true);
 					ns.app.centerRegion.update(table.html);
 
+					// after render
+					ns.app.layout = layout;
+					ns.app.response = response;
+					ns.app.xResponse = xResponse;
+
 					if (NS.isSessionStorage) {
 						web.events.setColumnHeaderMouseHandlers(layout, response, xResponse);
 					}
@@ -5251,14 +5211,8 @@
 			}
 		});
 
-		getParamString = function() {
-			var paramString = ns.core.web.analytics.getParamString(ns.core.service.layout.getExtendedLayout(ns.app.layout));
-
-			if (ns.app.layout.showHierarchy) {
-				paramString += '&showHierarchy=true';
-			}
-
-			return paramString;
+		getParamString = function(format) {
+			return ns.core.init.contextPath + ns.core.web.analytics.getParamString(ns.app.layout, format);
 		};
 
 		openTableLayoutTab = function(type, isNewTab) {
@@ -5293,32 +5247,6 @@
 				items: [
 					{
 						xtype: 'label',
-						text: NS.i18n.table_layout,
-						style: 'padding:7px 5px 5px 7px; font-weight:bold; border:0 none'
-					},
-					{
-						text: 'Microsoft Excel (.xls)',
-						iconCls: 'ns-menu-item-tablelayout',
-						handler: function() {
-							openTableLayoutTab('xls');
-						}
-					},
-					{
-						text: 'CSV (.csv)',
-						iconCls: 'ns-menu-item-tablelayout',
-						handler: function() {
-							openTableLayoutTab('csv');
-						}
-					},
-					{
-						text: 'HTML (.html)',
-						iconCls: 'ns-menu-item-tablelayout',
-						handler: function() {
-							openTableLayoutTab('html', true);
-						}
-					},
-					{
-						xtype: 'label',
 						text: NS.i18n.plain_data_sources,
 						style: 'padding:7px 5px 5px 7px; font-weight:bold'
 					},
@@ -5327,7 +5255,7 @@
 						iconCls: 'ns-menu-item-datasource',
 						handler: function() {
 							if (ns.core.init.contextPath && ns.app.paramString) {
-								window.open(ns.core.init.contextPath + '/api/analytics.json' + getParamString(), '_blank');
+								window.open(getParamString('json'), '_blank');
 							}
 						}
 					},
@@ -5336,7 +5264,7 @@
 						iconCls: 'ns-menu-item-datasource',
 						handler: function() {
 							if (ns.core.init.contextPath && ns.app.paramString) {
-								window.open(ns.core.init.contextPath + '/api/analytics.xml' + getParamString(), '_blank');
+								window.open(getParamString('xml'), '_blank');
 							}
 						}
 					},
@@ -5345,7 +5273,7 @@
 						iconCls: 'ns-menu-item-datasource',
 						handler: function() {
 							if (ns.core.init.contextPath && ns.app.paramString) {
-								window.location.href = ns.core.init.contextPath + '/api/analytics.xls' + getParamString();
+								window.open(getParamString('xls'), '_blank');
 							}
 						}
 					},
@@ -5354,7 +5282,7 @@
 						iconCls: 'ns-menu-item-datasource',
 						handler: function() {
 							if (ns.core.init.contextPath && ns.app.paramString) {
-								window.location.href = ns.core.init.contextPath + '/api/analytics.csv' + getParamString();
+								window.open(getParamString('csv'), '_blank');
 							}
 						}
 					},
@@ -5363,7 +5291,7 @@
 						iconCls: 'ns-menu-item-datasource',
 						handler: function() {
 							if (ns.core.init.contextPath && ns.app.paramString) {
-								window.open(ns.core.init.contextPath + '/api/analytics.jrxml' + getParamString(), '_blank');
+								window.open(getParamString('jrxml'), '_blank');
 							}
 						}
 					}
@@ -5575,23 +5503,25 @@
 		});
 
 		setGui = function(layout, xLayout, updateGui) {
-			var dimensions = Ext.Array.clean([].concat(layout.columns || [], layout.rows || [], layout.filters || [])),
-				dimMap = ns.core.service.layout.getObjectNameDimensionMapFromDimensionArray(dimensions),
-				recMap = ns.core.service.layout.getObjectNameDimensionItemsMapFromDimensionArray(dimensions),
-				graphMap = layout.parentGraphMap,
-				objectName,
-				periodRecords,
-				fixedPeriodRecords = [],
-				dimNames = [],
-				isOu = false,
-				isOuc = false,
-				isOugc = false,
-				levels = [],
-				groups = [],
-				orgunits = [];
+			//var dimensions = Ext.Array.clean([].concat(layout.columns || [], layout.rows || [], layout.filters || [])),
+				//dimMap = ns.core.service.layout.getObjectNameDimensionMapFromDimensionArray(dimensions),
+				//recMap = ns.core.service.layout.getObjectNameDimensionItemsMapFromDimensionArray(dimensions),
+				//graphMap = layout.parentGraphMap,
+				//objectName,
+				//periodRecords,
+				//fixedPeriodRecords = [],
+				//dimNames = [],
+				//isOu = false,
+				//isOuc = false,
+				//isOugc = false,
+				//levels = [],
+				//groups = [],
+				//orgunits = [];
 
 			// State
-			//downloadButton.enable();
+			downloadButton.enable();
+
+            return;
 
 			if (layout.id) {
 				//shareButton.enable();

=== modified file 'dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/core.js	2014-03-27 14:27:41 +0000
+++ dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/core.js	2014-03-29 09:20:38 +0000
@@ -1666,71 +1666,59 @@
 			// analytics
 			web.analytics = {};
 
-			web.analytics.getParamString = function(xLayout, isSorted) {
-				var axisDimensionNames = isSorted ? xLayout.sortedAxisDimensionNames : xLayout.axisDimensionNames,
-					filterDimensions = isSorted ? xLayout.sortedFilterDimensions : xLayout.filterDimensions,
-					dimensionNameIdsMap = isSorted ? xLayout.dimensionNameSortedIdsMap : xLayout.dimensionNameIdsMap,
-					paramString = '?',
-					addCategoryDimension = false,
-					map = xLayout.dimensionNameItemsMap,
-					dx = dimConf.indicator.dimensionName,
-					co = dimConf.category.dimensionName,
-                    aggTypes = {
-                        'count': 'COUNT',
-                        'sum': 'SUM'
-                    };
-
-				for (var i = 0, dimName, items; i < axisDimensionNames.length; i++) {
-					dimName = axisDimensionNames[i];
-
-					paramString += 'dimension=' + dimName;
-
-					items = Ext.clone(dimensionNameIdsMap[dimName]);
-
-					if (dimName === dx) {
-						for (var j = 0, index; j < items.length; j++) {
-							index = items[j].indexOf('-');
-
-							if (index > 0) {
-								addCategoryDimension = true;
-								items[j] = items[j].substr(0, index);
-							}
+			web.analytics.getParamString = function(view, format) {
+                var paramString;
+
+                format = format || 'json';
+
+                paramString = '/api/analytics/events/' + view.type + '/' + view.program.id + '.' + format + '?';
+
+				// stage
+				paramString += 'stage=' + view.stage.id;
+
+				// ou
+				if (Ext.isArray(view.organisationUnits)) {
+                    paramString += '&dimension=ou:';
+
+					for (var i = 0; i < view.organisationUnits.length; i++) {
+						paramString += view.organisationUnits[i].id;
+                        paramString += i < (view.organisationUnits.length - 1) ? ';' : '';
+					}
+				}
+
+				// de
+				for (var i = 0, element; i < view.dataElements.length; i++) {
+					element = view.dataElements[i];
+
+					paramString += '&dimension=' + element.id;
+
+					if (element.value) {
+						if (element.operator) {
+							paramString += ':' + element.operator;
 						}
 
-						items = Ext.Array.unique(items);
-					}
-
-					if (dimName !== co) {
-						paramString += ':' + items.join(';');
-					}
-
-					if (i < (axisDimensionNames.length - 1)) {
-						paramString += '&';
-					}
-				}
-
-				if (addCategoryDimension) {
-					paramString += '&dimension=' + conf.finals.dimension.category.dimensionName;
-				}
-
-				if (Ext.isArray(filterDimensions) && filterDimensions.length) {
-					for (var i = 0, dim; i < filterDimensions.length; i++) {
-						dim = filterDimensions[i];
-
-						paramString += '&filter=' + dim.dimensionName + ':' + dim.ids.join(';');
-					}
-				}
-
-				if (xLayout.showHierarchy) {
-					paramString += '&hierarchyMeta=true';
-				}
-
-                if (aggTypes.hasOwnProperty(xLayout.aggregationType)) {
-                    paramString += '&aggregationType=' + aggTypes[xLayout.aggregationType];
-                }
-
-				return paramString;
-			};
+						paramString += ':' + element.value;
+					}
+				}
+
+				// pe
+				if (Ext.isArray(view.periods)) {
+					paramString += '&dimension=pe:';
+
+					for (var i = 0; i < view.periods.length; i++) {
+						paramString += view.periods[i].id + (i < view.periods.length - 1 ?  ';' : '');
+					}
+				}
+				else {
+					paramString += '&startDate=' + view.startDate;
+					paramString += '&endDate=' + view.endDate;
+				}
+
+				// hierarchy
+				paramString += view.showHierarchy ? '&hierarchyMeta=true' : '';
+
+                return paramString;
+            };
 
 			web.analytics.validateUrl = function(url) {
 				var msg;