← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13525: GIS, app/plugin json/jsonp + PT DV, 414 error handler

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 13525 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-12-31 17:51:51 +0100
message:
  GIS, app/plugin json/jsonp + PT DV, 414 error handler
modified:
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js
  dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js
  dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/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/core.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js	2013-12-31 00:23:25 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js	2013-12-31 16:46:50 +0000
@@ -1757,6 +1757,8 @@
 		};
 
 		loadData = function(view, features) {
+			var success;
+			
 			view = view || layer.core.view;
 			features = features || layer.core.featureStore.features;
 
@@ -1793,70 +1795,88 @@
 				paramString += i < peItems.length - 1 ? ';' : '';
 			}
 
-			Ext.data.JsonP.request({
-				url: gis.init.contextPath + '/api/analytics.jsonp' + paramString,
-				disableCaching: false,
-				scope: this,
-				success: function(r) {
-					var response = gis.api.response.Response(r),
-						featureMap = {},
-						valueMap = {},
-						ouIndex,
-						dxIndex,
-						valueIndex,
-						newFeatures = [],
-						dimensions,
-						items = [];
-
-					if (!response) {
-						olmap.mask.hide();
-						return;
-					}
-
-					// ou index, value index
-					for (var i = 0; i < response.headers.length; i++) {
-						if (response.headers[i].name === dimConf.organisationUnit.dimensionName) {
-							ouIndex = i;
-						}
-						else if (response.headers[i].name === dimConf.value.dimensionName) {
-							valueIndex = i;
-						}
-					}
-
-					// Feature map
-					for (var i = 0, id; i < features.length; i++) {
-						var id = features[i].attributes.id;
-
-						featureMap[id] = true;
-					}
-
-					// Value map
-					for (var i = 0; i < response.rows.length; i++) {
-						var id = response.rows[i][ouIndex],
-							value = parseFloat(response.rows[i][valueIndex]);
-
-						valueMap[id] = value;
-					}
-
-					for (var i = 0; i < features.length; i++) {
-						var feature = features[i],
-							id = feature.attributes.id;
-
-						if (featureMap.hasOwnProperty(id) && valueMap.hasOwnProperty(id)) {
-							feature.attributes.value = valueMap[id];
-							feature.attributes.label = feature.attributes.name + ' (' + feature.attributes.value + ')';
-							newFeatures.push(feature);
-						}
-					}
-
-					layer.removeFeatures(layer.features);
-					layer.addFeatures(newFeatures);
-
-					gis.response = response;
-
-					loadLegend(view);
-				}
-			});
+			success = function(json) {
+				var response = gis.api.response.Response(json),
+					featureMap = {},
+					valueMap = {},
+					ouIndex,
+					dxIndex,
+					valueIndex,
+					newFeatures = [],
+					dimensions,
+					items = [];
+
+				if (!response) {
+					olmap.mask.hide();
+					return;
+				}
+
+				// ou index, value index
+				for (var i = 0; i < response.headers.length; i++) {
+					if (response.headers[i].name === dimConf.organisationUnit.dimensionName) {
+						ouIndex = i;
+					}
+					else if (response.headers[i].name === dimConf.value.dimensionName) {
+						valueIndex = i;
+					}
+				}
+
+				// Feature map
+				for (var i = 0, id; i < features.length; i++) {
+					var id = features[i].attributes.id;
+
+					featureMap[id] = true;
+				}
+
+				// Value map
+				for (var i = 0; i < response.rows.length; i++) {
+					var id = response.rows[i][ouIndex],
+						value = parseFloat(response.rows[i][valueIndex]);
+
+					valueMap[id] = value;
+				}
+
+				for (var i = 0; i < features.length; i++) {
+					var feature = features[i],
+						id = feature.attributes.id;
+
+					if (featureMap.hasOwnProperty(id) && valueMap.hasOwnProperty(id)) {
+						feature.attributes.value = valueMap[id];
+						feature.attributes.label = feature.attributes.name + ' (' + feature.attributes.value + ')';
+						newFeatures.push(feature);
+					}
+				}
+
+				layer.removeFeatures(layer.features);
+				layer.addFeatures(newFeatures);
+
+				gis.response = response;
+
+				loadLegend(view);
+			};
+
+			if (Ext.isObject(GIS.app)) {
+				Ext.Ajax.request({
+					url: gis.init.contextPath + '/api/analytics.json' + paramString,
+					disableCaching: false,
+					failure: function(r) {
+						alert(r.responseText);
+					},
+					success: function(r) {
+						success(Ext.decode(r.responseText));
+					}
+				});
+			}
+			else if (Ext.isObject(GIS.plugin)) {
+				Ext.data.JsonP.request({
+					url: gis.init.contextPath + '/api/analytics.jsonp' + paramString,
+					disableCaching: false,
+					scope: this,
+					success: function(r) {
+						success(r);
+					}
+				});
+			}
 		};
 
 		loadLegend = function(view) {

=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js	2013-12-31 13:38:19 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js	2013-12-31 16:01:52 +0000
@@ -2237,10 +2237,6 @@
 				xLayout = service.layout.getExtendedLayout(layout);
 				paramString = web.analytics.getParamString(xLayout, true);
 
-				if (!web.analytics.validateUrl(init.contextPath + '/api/analytics.json' + paramString)) {
-					return;
-				}
-
 				// show mask
 				web.mask.show(ns.app.centerRegion);
 
@@ -2254,7 +2250,13 @@
 					disableCaching: false,
 					failure: function(r) {
 						web.mask.hide(ns.app.centerRegion);
-						alert(r.responseText);
+
+						if (r.status === 414) {
+							web.analytics.validateUrl(init.contextPath + '/api/analytics.json' + paramString);
+						}
+						else {
+							alert(r.responseText);
+						}
 					},
 					success: function(r) {
 						var response = api.response.Response(Ext.decode(r.responseText));

=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js	2013-12-05 10:23:38 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js	2013-12-31 16:01:52 +0000
@@ -1790,13 +1790,19 @@
 			};
 
 			web.analytics.validateUrl = function(url) {
-				if (!Ext.isString(url) || url.length > 2000) {
-					var percent = ((url.length - 2000) / url.length) * 100;
-					alert('Too many parameters selected. Please reduce the number of parameters by at least ' + Ext.Number.toFixed(percent, 0) + '%.');
-					return;
-				}
-
-				return true;
+				var msg;
+
+                if (Ext.isIE) {
+                    msg = 'Too many items selected (url has ' + url.length + ' characters). Internet Explorer accepts maximum 2048 characters.';
+                }
+                else {
+					var len = url.length > 8000 ? '8000' : (url.length > 4000 ? '4000' : '2000');
+					msg = 'Too many items selected (url has ' + url.length + ' characters). Please reduce to less than ' + len + ' characters.';
+                }
+
+                msg += '\n\n' + 'Hint: A good way to reduce the number of items is to use relative periods and level/group organisation unit selection modes.';
+
+                alert(msg);
 			};
 
 			// pivot

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js	2013-12-25 22:51:31 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js	2013-12-31 16:01:52 +0000
@@ -1676,10 +1676,6 @@
 				xLayout = service.layout.getExtendedLayout(layout);
 				paramString = web.analytics.getParamString(xLayout, true);
 
-				if (!web.analytics.validateUrl(init.contextPath + '/api/analytics.json' + paramString)) {
-					return;
-				}
-
 				// show mask
 				web.mask.show(ns.app.centerRegion);
 
@@ -1693,7 +1689,13 @@
 					disableCaching: false,
 					failure: function(r) {
 						web.mask.hide(ns.app.centerRegion);
-						alert(r.responseText);
+
+						if (r.status === 414) {
+							web.analytics.validateUrl(init.contextPath + '/api/analytics.json' + paramString);
+						}
+						else {
+							alert(r.responseText);
+						}
 					},
 					success: function(r) {
 						var xResponse,

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.js	2013-12-30 20:44:50 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.js	2013-12-31 16:01:52 +0000
@@ -1559,13 +1559,19 @@
             };
 
 			web.analytics.validateUrl = function(url) {
-				if (!Ext.isString(url) || url.length > 2000) {
-					var percent = ((url.length - 2000) / url.length) * 100;
-					alert('Too many parameters selected. Please reduce the number of parameters by at least ' + percent.toFixed(0) + '%.');
-					return;
-				}
-
-				return true;
+				var msg;
+
+                if (Ext.isIE) {
+                    msg = 'Too many items selected (url has ' + url.length + ' characters). Internet Explorer accepts maximum 2048 characters.';
+                }
+                else {
+					var len = url.length > 8000 ? '8000' : (url.length > 4000 ? '4000' : '2000');
+					msg = 'Too many items selected (url has ' + url.length + ' characters). Please reduce to less than ' + len + ' characters.';
+                }
+
+                msg += '\n\n' + 'Hint: A good way to reduce the number of items is to use relative periods and level/group organisation unit selection modes.';
+
+                alert(msg);
 			};
 
 			// chart