← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13834: PT, sorting improved, makes it possible to sort directly from favorite, embed bug fixed.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 13834 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-01-23 20:59:34 +0100
message:
  PT, sorting improved, makes it possible to sort directly from favorite, embed bug fixed.
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementGroupController.java
  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


--
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-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementGroupController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementGroupController.java	2014-01-21 11:14:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementGroupController.java	2014-01-23 19:55:42 +0000
@@ -169,6 +169,8 @@
 
         WebMetaData metaData = new WebMetaData();
         List<DataElementOperand> dataElementOperands = Lists.newArrayList( dataElementCategoryService.getOperands( dataElementGroup.getMembers() ) );
+        
+        Collections.sort( dataElementOperands, IdentifiableObjectNameComparator.INSTANCE );
 
 		Collections.sort( dataElementOperands, IdentifiableObjectNameComparator.INSTANCE );
 

=== 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	2014-01-21 15:29:35 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js	2014-01-23 19:56:40 +0000
@@ -1430,6 +1430,11 @@
 		};
 
 		getBody = function() {
+			if (!ns.core.init.user) {
+				alert('User is not assigned to any organisation units');
+				return;
+			}
+
 			var body = {
 				object: {
 					id: sharing.object.id,
@@ -2111,38 +2116,43 @@
 				}
 			};
 
-			web.events.setColumnHeaderMouseHandlers = function(xLayout, response) {
+			//web.events.setColumnHeaderMouseHandlers = function(xLayout, response) {
+			web.events.setColumnHeaderMouseHandlers = function(layout, xLayout, xResponse) {
 				if (Ext.isArray(xLayout.sortableIdObjects)) {
 					for (var i = 0, obj, el; i < xLayout.sortableIdObjects.length; i++) {
 						obj = xLayout.sortableIdObjects[i];
 						el = Ext.get(obj.uuid);
 
-						el.dom.xLayout = xLayout;
-						el.dom.response = response;
+						el.dom.layout = layout;
+						el.dom.xResponse = xResponse;
 						el.dom.metaDataId = obj.id;
 						el.dom.onColumnHeaderMouseClick = web.events.onColumnHeaderMouseClick;
 						el.dom.onColumnHeaderMouseOver = web.events.onColumnHeaderMouseOver;
 						el.dom.onColumnHeaderMouseOut = web.events.onColumnHeaderMouseOut;
 
-						el.dom.setAttribute('onclick', 'this.onColumnHeaderMouseClick(this.xLayout, this.response, this.metaDataId)');
+						//el.dom.setAttribute('onclick', 'this.onColumnHeaderMouseClick(this.xLayout, this.response, this.metaDataId)');
+						el.dom.setAttribute('onclick', 'this.onColumnHeaderMouseClick(this.layout, this.xResponse, this.metaDataId)');
 						el.dom.setAttribute('onmouseover', 'this.onColumnHeaderMouseOver(this)');
 						el.dom.setAttribute('onmouseout', 'this.onColumnHeaderMouseOut(this)');
 					}
 				}
 			};
 
-			web.events.onColumnHeaderMouseClick = function(xLayout, response, id) {
-				if (xLayout.sorting && xLayout.sorting.id === id) {
-					xLayout.sorting.direction = support.prototype.str.toggleDirection(xLayout.sorting.direction);
+			//web.events.onColumnHeaderMouseClick = function(xLayout, response, id) {
+			web.events.onColumnHeaderMouseClick = function(layout, xResponse, id) {
+				if (layout.sorting && layout.sorting.id === id) {
+					layout.sorting.direction = support.prototype.str.toggleDirection(layout.sorting.direction);
 				}
 				else {
-					xLayout.sorting = {
+					layout.sorting = {
 						id: id,
 						direction: 'DESC'
 					};
 				}
 
-				ns.core.web.pivot.sort(xLayout, response, id);
+				web.pivot.createTable(layout, null, xResponse, false);
+
+				//ns.core.web.pivot.sort(xLayout, response, id);
 			};
 
 			web.events.onColumnHeaderMouseOver = function(el) {
@@ -2278,54 +2288,62 @@
 							return;
 						}
 
-						// sync xLayout with response
-						xLayout = service.layout.getSyncronizedXLayout(xLayout, response);
-
-						if (!xLayout) {
-							web.mask.hide(ns.app.centerRegion);
-							return;
-						}
-
 						ns.app.paramString = paramString;
 
-						web.pivot.createTable(layout, xLayout, response, isUpdateGui);
+						web.pivot.createTable(layout, response, null, isUpdateGui);
 					}
 				});
 			};
 
-			web.pivot.createTable = function(layout, xLayout, response, isUpdateGui) {
-				var xResponse,
+			web.pivot.createTable = function(layout, response, xResponse, isUpdateGui) {
+				var xLayout,
 					xColAxis,
 					xRowAxis,
-					config;
-
-				if (!xLayout) {
-					xLayout = service.layout.getExtendedLayout(layout);
-				}
-
-				// extend response
-				xResponse = service.response.getExtendedResponse(xLayout, response);
-
-				// extended axes
-				xColAxis = service.layout.getExtendedAxis(xLayout, xResponse, 'col');
-				xRowAxis = service.layout.getExtendedAxis(xLayout, xResponse, 'row');
-
-				// update viewport
-				config = web.pivot.getHtml(xLayout, xResponse, xColAxis, xRowAxis);
+					table,
+					getHtml,
+					getXLayout = service.layout.getExtendedLayout,
+					getSXLayout = service.layout.getSyncronizedXLayout,
+					getXResponse = service.response.getExtendedResponse,
+					getXAxis = service.layout.getExtendedAxis;
+
+				getHtml = function(xLayout, xResponse) {
+					xColAxis = getXAxis(xLayout, 'col');
+					xRowAxis = getXAxis(xLayout, 'row');
+
+					return web.pivot.getHtml(xLayout, xResponse, xColAxis, xRowAxis);
+				};
+
+				xLayout = getSXLayout(getXLayout(layout), xResponse || response);
+
+				if (layout.sorting) {
+					if (!xResponse) {
+						xResponse = getXResponse(xLayout, response);
+						getHtml(xLayout, xResponse);
+					}
+
+					web.pivot.sort(xLayout, xResponse);
+					xLayout = getXLayout(api.layout.Layout(xLayout));
+				}
+				else {
+					xResponse = service.response.getExtendedResponse(xLayout, response);
+				}
+
+				table = getHtml(xLayout, xResponse);
+
 				ns.app.centerRegion.removeAll(true);
-				ns.app.centerRegion.update(config.html);
+				ns.app.centerRegion.update(table.html);
 
 				// after render
 				ns.app.layout = layout;
 				ns.app.xLayout = xLayout;
 				ns.app.response = response;
 				ns.app.xResponse = xResponse;
-				ns.app.uuidDimUuidsMap = config.uuidDimUuidsMap;
+				ns.app.uuidDimUuidsMap = table.uuidDimUuidsMap;
 				ns.app.uuidObjectMap = Ext.applyIf((xColAxis ? xColAxis.uuidObjectMap : {}), (xRowAxis ? xRowAxis.uuidObjectMap : {}));
 
 				if (NS.isSessionStorage) {
 					web.events.setValueMouseHandlers(layout, response, ns.app.uuidDimUuidsMap, ns.app.uuidObjectMap);
-					web.events.setColumnHeaderMouseHandlers(xLayout, response);
+					web.events.setColumnHeaderMouseHandlers(layout, xLayout, xResponse);
 					web.storage.session.set(layout, 'table');
 				}
 
@@ -2339,11 +2357,11 @@
 				}
 			};
 
-			web.pivot.sort = function(xLayout, response, id) {
-				var xLayout = Ext.clone(xLayout),
-					response = Ext.clone(response),
+			web.pivot.sort = function(xLayout, xResponse) {
+				var xResponse = Ext.clone(xResponse),
+					id = xLayout.sorting.id,
 					dim = xLayout.rows[0],
-					valueMap = response.idValueMap,
+					valueMap = xResponse.idValueMap,
 					direction = xLayout.sorting ? xLayout.sorting.direction : 'DESC',
 					layout;
 
@@ -2366,11 +2384,7 @@
 					dim.ids.push(dim.items[i].id);
 				}
 
-				// re-layout
-				layout = api.layout.Layout(xLayout);
-
-				// re-create table
-				web.pivot.createTable(layout, null, response, false);
+				return xLayout;
 			};
 		}());
 	};

=== 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	2014-01-21 15:29:35 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js	2014-01-23 19:55:42 +0000
@@ -1184,6 +1184,23 @@
 						}
 					}
 
+					// Add missing names
+					dimensions = Ext.Array.clean([].concat(xLayout.columns || [], xLayout.rows || [], xLayout.filters || []));
+
+					for (var i = 0, idNameMap = response.metaData.names, dimItems; i < dimensions.length; i++) {
+						dimItems = dimensions[i].items;
+
+						if (Ext.isArray(dimItems) && dimItems.length) {
+							for (var j = 0, item; j < dimItems.length; j++) {
+								item = dimItems[j];
+
+								if (Ext.isObject(item) && Ext.isString(idNameMap[item.id]) && !Ext.isString(item.name)) {
+									item.name = idNameMap[item.id] || '';
+								}
+							}
+						}
+					}
+
 					// Remove dimensions from layout that do not exist in response
 					for (var i = 0, dimensionName; i < xLayout.axisDimensionNames.length; i++) {
 						dimensionName = xLayout.axisDimensionNames[i];
@@ -1196,22 +1213,6 @@
 					layout = api.layout.Layout(xLayout);
 
 					if (layout) {
-						dimensions = Ext.Array.clean([].concat(layout.columns || [], layout.rows || [], layout.filters || []));
-
-						for (var i = 0, idNameMap = response.metaData.names, dimItems; i < dimensions.length; i++) {
-							dimItems = dimensions[i].items;
-
-							if (Ext.isArray(dimItems) && dimItems.length) {
-								for (var j = 0, item; j < dimItems.length; j++) {
-									item = dimItems[j];
-
-									if (Ext.isObject(item) && Ext.isString(idNameMap[item.id]) && !Ext.isString(item.name)) {
-										item.name = idNameMap[item.id] || '';
-									}
-								}
-							}
-						}
-
 						return service.layout.getExtendedLayout(layout);
 					}
 
@@ -1219,7 +1220,7 @@
 				}();
 			};
 
-			service.layout.getExtendedAxis = function(xLayout, xResponse, type) {
+			service.layout.getExtendedAxis = function(xLayout, type) {
 				var dimensionNames,
 					spanType,
 					aDimensions = [],
@@ -1264,7 +1265,7 @@
 					var a = [];
 
 					for (var i = 0; i < aDimensions.length; i++) {
-						a.push(xResponse.nameHeaderMap[aDimensions[i].dimensionName].ids);
+						a.push(xLayout.dimensionNameIdsMap[aDimensions[i].dimensionName]);
 					}
 
 					return a;
@@ -1605,6 +1606,8 @@
 			service.response.getExtendedResponse = function(xLayout, response) {
 				var ids = [];
 
+				response = Ext.clone(response);
+
 				response.nameHeaderMap = {};
 				response.idValueMap = {};