← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10015: (PT) Download as XLS and CSV + Data element group sets supported.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 10015 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-03-06 18:28:36 +0100
message:
  (PT) Download as XLS and CSV + Data element group sets supported.
added:
  dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/images/dataelementgroupset.png
  dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/images/organisationunitgroupset.png
modified:
  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-pivot/src/main/webapp/dhis-web-pivot/app/styles/style.css


--
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-pivot/src/main/webapp/dhis-web-pivot/app/images/dataelementgroupset.png'
Binary files dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/images/dataelementgroupset.png	1970-01-01 00:00:00 +0000 and dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/images/dataelementgroupset.png	2013-03-06 13:39:47 +0000 differ
=== added file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/images/organisationunitgroupset.png'
Binary files dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/images/organisationunitgroupset.png	1970-01-01 00:00:00 +0000 and dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/images/organisationunitgroupset.png	2013-03-06 13:39:47 +0000 differ
=== 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-03-05 22:56:38 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js	2013-03-06 17:24:40 +0000
@@ -586,9 +586,20 @@
 					}
 				}
 			],
+			hasBlurHandler: false,
 			listeners: {
 				show: function(w) {
 					pt.util.window.setAnchorPosition(w, pt.viewport.layoutButton);
+
+					if (!w.hasBlurHandler) {
+						var el = Ext.get(document.getElementsByClassName('x-mask')[0]);
+
+						el.on('click', function() {
+							w.hide();
+						});
+
+						w.hasBlurHandler = true;
+					}
 				}
 			}
 		});
@@ -719,9 +730,20 @@
 					}
 				}
 			],
+			hasBlurHandler: false,
 			listeners: {
 				show: function(w) {
 					pt.util.window.setAnchorPosition(w, pt.viewport.optionsButton);
+
+					if (!w.hasBlurHandler) {
+						var el = Ext.get(document.getElementsByClassName('x-mask')[0]);
+
+						el.on('click', function() {
+							w.hide();
+						});
+
+						w.hasBlurHandler = true;
+					}
 				}
 			}
 		});
@@ -733,12 +755,7 @@
 		var createViewport;
 
 		createViewport = function() {
-			var viewport,
-				westRegion,
-				centerRegion,
-				accordion,
-
-				indicatorAvailable,
+			var indicatorAvailable,
 				indicatorSelected,
 				indicator,
 				dataElementAvailable,
@@ -751,11 +768,21 @@
 				relativePeriod,
 				fixedPeriodAvailable,
 				fixedPeriodSelected,
-				fixedPeriod,
+				period,
 				organisationUnit,
-				getOrganisationUnitGroupSetPanels,
+				getGroupSetPanels,
+				validateSpecialCases,
 				update,
 
+				layoutButton,
+				optionsButton,
+				downloadButton,
+
+				accordion,
+				westRegion,
+				centerRegion,
+				viewport,
+
 				addListeners;
 
 			indicatorAvailable = Ext.create('Ext.ux.form.MultiSelect', {
@@ -1972,7 +1999,7 @@
 				}
 			};
 
-			getGroupSetPanels = function(groupSets, url) {
+			getGroupSetPanels = function(groupSets, iconCls) {
 				var	getAvailableStore,
 					getSelectedStore,
 
@@ -2113,7 +2140,7 @@
 
 					panel = {
 						xtype: 'panel',
-						title: '<div class="pt-panel-title-organisationunit">' + groupSet.name + '</div>', //i18n
+						title: '<div class="' + iconCls + '">' + groupSet.name + '</div>', //i18n
 						hideCollapseTool: true,
 						getData: function() {
 							var data = {
@@ -2239,11 +2266,15 @@
 								dataSet,
 								period,
 								organisationUnit
-							];
-
-							panels = panels.concat(getGroupSetPanels(pt.init.ougs, 'organisationUnitGroupSets'));
-
-							panels = panels.concat(getGroupSetPanels(pt.init.degs, 'dataElementGroupSets'));
+							],
+							ougs = Ext.clone(pt.init.ougs),
+							degs = Ext.clone(pt.init.degs);
+
+							pt.util.array.sortObjectsByString(ougs);
+							pt.util.array.sortObjectsByString(degs);
+
+							panels = panels.concat(getGroupSetPanels(ougs, 'pt-panel-title-organisationunitgroupset'));
+							panels = panels.concat(getGroupSetPanels(degs, 'pt-panel-title-dataelementgroupset'));
 
 							last = panels[panels.length - 1];
 							last.cls = 'pt-accordion-last';
@@ -2275,6 +2306,7 @@
 
 			layoutButton = Ext.create('Ext.button.Button', {
 				text: 'Layout',
+				menu: {},
 				handler: function() {
 					if (!pt.viewport.settingsWindow) {
 						pt.viewport.settingsWindow = PT.app.SettingsWindow(pt);
@@ -2286,6 +2318,7 @@
 
 			optionsButton = Ext.create('Ext.button.Button', {
 				text: 'Options',
+				menu: {},
 				handler: function() {
 					if (!pt.viewport.optionsWindow) {
 						pt.viewport.optionsWindow = PT.app.OptionsWindow();
@@ -2295,6 +2328,42 @@
 				}
 			});
 
+			downloadButton = Ext.create('Ext.button.Button', {
+				text: 'Download',
+				disabled: true,
+				menu: {
+					cls: 'pt-menu',
+					width: 105,
+					shadow: false,
+					showSeparator: false,
+					items: [
+						{
+							text: 'Excel (XLS)',
+							iconCls: 'pt-menu-item-xls',
+							handler: function() {
+								if (pt.baseUrl && pt.paramString) {
+									window.location.href = pt.baseUrl + '/api/analytics.xls' + pt.paramString;
+								}
+							}
+						},
+						{
+							text: 'CSV',
+							iconCls: 'pt-menu-item-csv',
+							handler: function() {
+								if (pt.baseUrl && pt.paramString) {
+									window.location.href = pt.baseUrl + '/api/analytics.csv' + pt.paramString;
+								}
+							}
+						}
+					],
+					listeners: {
+						afterrender: function() {
+							this.getEl().addCls('pt-toolbar-btn-menu');
+						}
+					}
+				}
+			});
+
 			centerRegion = Ext.create('Ext.panel.Panel', {
 				region: 'center',
 				bodyStyle: 'padding:1px',
@@ -2332,7 +2401,7 @@
 							handler: function() {
 							}
 						},
-
+						downloadButton,
                         '->',
                         {
                             xtype: 'button',
@@ -2409,6 +2478,7 @@
 				updateViewport: update,
 				layoutButton: layoutButton,
 				optionsButton: optionsButton,
+				downloadButton: downloadButton,
 				items: [
 					westRegion,
 					centerRegion
@@ -2444,9 +2514,14 @@
 		};
 
 		pt.init = PT.app.getInits(r);
+		pt.baseUrl = pt.init.contextPath;
+
 		pt.util = PT.app.getUtils();
+
 		pt.store = PT.app.getStores();
+
 		pt.cmp = PT.app.getCmp();
+
 		pt.viewport = createViewport();
 
 		pt.viewport.settingsWindow = PT.app.SettingsWindow();

=== 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-03-05 22:56:38 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js	2013-03-06 17:24:40 +0000
@@ -130,7 +130,7 @@
         west_fill_accordion_indicator: 63,
         west_fill_accordion_dataelement: 63,
         west_fill_accordion_dataset: 33,
-        west_fill_accordion_period: 240,
+        west_fill_accordion_period: 256,
         west_fill_accordion_organisationunit: 62,
         west_maxheight_accordion_indicator: 400,
         west_maxheight_accordion_dataelement: 400,
@@ -406,6 +406,23 @@
 			}
 
 			return dimensions;
+		},
+
+		sortObjectsByString: function(array, key) {
+			key = key || 'name';
+			array.sort( function(a, b) {
+				var nameA = a[key].toLowerCase(),
+					nameB = b[key].toLowerCase();
+
+				if (nameA < nameB) {
+					return -1;
+				}
+				if (nameA > nameB) {
+					return 1;
+				}
+				return 0;
+			});
+			return array;
 		}
 	};
 
@@ -461,7 +478,7 @@
 				extendRowAxis,
 				getTableHtmlArrays,
 				initialize,
-									
+
 				dimConf = pt.conf.finals.dimension;
 
 			extendSettings = function(settings) {
@@ -903,15 +920,12 @@
 			};
 
 			getTableHtml = function(xColAxis, xRowAxis, xResponse) {
-				var getEmptyHtmlArray,
+				var doSubTotals,
 					getColAxisHtmlArray,
-					getRowAxisHtmlArray,
+					getRowHtmlArray,
 					rowAxisHtmlArray,
-					getRowHtmlArray,
-					getRowTotalHtmlArray,
 					getColTotalHtmlArray,
 					getGrandTotalHtmlArray,
-					getRowHtmlArray,
 					getTotalHtmlArray,
 					getHtml,
 
@@ -1091,16 +1105,22 @@
 
 					// Value total objects
 					if (xColAxis) {
-						valueItemsCopy = Ext.clone(valueItems);
-
-						for (var i = 0, rowSum; i < valueItemsCopy.length; i++) {
-							rowSum = Ext.Array.sum(valueItemsCopy[i]);
-							rowSum = pt.util.number.roundIf(rowSum, 1);
+						for (var i = 0, empty, total; i < valueObjects.length; i++) {
+							empty = [];
+							total = 0;
+
+							for (j = 0, obj; j < valueObjects[i].length; j++) {
+								obj = valueObjects[i][j];
+
+								empty.push(obj.empty);
+								total += obj.value;
+							}
+
 							totalValueObjects.push({
 								type: 'valueTotal',
-								value: rowSum,
-								htmlValue: rowSum,
-								cls: 'pivot-value-total'
+								cls: 'pivot-value-total',
+								value: total,
+								htmlValue: pt.util.number.roundIf(total, 1) || '-'
 							});
 						}
 					}
@@ -1152,7 +1172,7 @@
 
 								if (colCount === colUniqueFactor) {
 									rowSubTotal = pt.util.number.roundIf(rowSubTotal, 1);
-									
+
 									row.push({
 										type: 'valueSubtotal',
 										value: rowSubTotal,
@@ -1233,7 +1253,7 @@
 
 								if (rowCount === rowUniqueFactor) {
 									subTotal = pt.util.number.roundIf(subTotal, 1);
-									
+
 									tmpValueObjects[tmpCount++].push({
 										type: item.cls === 'pivot-value-subtotal' ? 'valueSubtotal' : 'valueSubtotalTotal',
 										value: subTotal,
@@ -1258,7 +1278,7 @@
 
 							if (count === xRowAxis.span[0]) {
 								subTotal = pt.util.number.roundIf(subTotal, 1);
-								
+
 								tmpTotalValueObjects.push({
 									type: 'valueTotalSubgrandtotal',
 									cls: 'pivot-value-total-subgrandtotal',
@@ -1281,7 +1301,7 @@
 					// Merge dim, value, total
 					for (var i = 0, row; i < valueObjects.length; i++) {
 						row = [];
-						
+
 						if (xRowAxis) {
 							row = row.concat(axisObjects[i]);
 						}
@@ -1339,14 +1359,14 @@
 								subTotal += item.value;
 								colCount++;
 
-								if (colCount === colUniqueFactor) {									
+								if (colCount === colUniqueFactor) {
 									tmp.push({
 										type: 'valueTotalSubgrandtotal',
 										value: subTotal,
 										htmlValue: subTotal,
 										cls: 'pivot-value-total-subgrandtotal'
 									});
-									
+
 									subTotal = 0;
 									colCount = 0;
 								}
@@ -1431,19 +1451,31 @@
 			};
 
 			initialize = function() {
-				var xSettings,
+				var url,
+					xSettings,
 					xResponse,
 					xColAxis,
 					xRowAxis;
 
+				xSettings = extendSettings(settings);
+
+				pt.paramString = getParamString(xSettings);
+				url = pt.init.contextPath + '/api/analytics.jsonp' + pt.paramString;
+
+				if (url.length > 2000) {
+					var percent = ((url.length - 2000) / url.length) * 100;
+
+					alert('Too many parameters selected. Please reduce the number of parameters by minimum ' + percent.toFixed(0) + '%');
+					return;
+				}
+
 				pt.util.mask.showMask(pt.viewport);
 
-				xSettings = extendSettings(settings);
-
 				Ext.data.JsonP.request({
 					method: 'GET',
-					url: pt.init.contextPath + '/api/analytics.jsonp' + getParamString(xSettings),
+					url: url,
 					callbackName: 'analytics',
+					timeout: 60000,
 					headers: {
 						'Content-Type': 'application/json',
 						'Accept': 'application/json'
@@ -1470,19 +1502,21 @@
 						}
 
 						xResponse = extendResponse(response, xSettings);
-console.log("xResponse", xResponse);
 
 						xColAxis = extendAxis('col', xSettings.col, xResponse);
 						xRowAxis = extendAxis('row', xSettings.row, xResponse);
-console.log("xColAxis", xColAxis);
-console.log("xRowAxis", xRowAxis);
 
 						html = getTableHtml(xColAxis, xRowAxis, xResponse);
 
 						pt.container.removeAll(true);
 						pt.container.update(html);
 
+						// After table success
 						pt.util.mask.hideMask();
+
+						if (pt.viewport.downloadButton) {
+							pt.viewport.downloadButton.enable();
+						}
 					}
 				});
 

=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/styles/style.css'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/styles/style.css	2013-03-01 10:57:44 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/styles/style.css	2013-03-06 17:24:40 +0000
@@ -115,45 +115,54 @@
 .pivot td {
 	padding: 5px;
 	border: 1px solid #b2b2b2;
-	text-align: center;
 }
 
 .pivot-dim {
 	background-color: #dae6f8;
+	text-align: center;
 }
 .pivot-dim-subtotal {
 	background-color: #cad6e8;
+	text-align: center;
 }
 .pivot-dim-total {
 	background-color: #bac6d8;
+	text-align: center;
 }
 .pivot-dim-empty {
 	background-color: #dae6f8;
+	text-align: center;
 }
 
 .pivot-value {
 	background-color: #fff;
 	white-space: nowrap;
+	text-align: right;
 }
 .pivot-value-subtotal {
 	background-color: #f5f5f5;
 	white-space: nowrap;
+	text-align: right;
 }
 .pivot-value-subtotal-total {
 	background-color: #e8e8e8;
 	white-space: nowrap;
+	text-align: right;
 }
 .pivot-value-total {
 	background-color: #e4e4e4;
 	white-space: nowrap;
+	text-align: right;
 }
 .pivot-value-total-subgrandtotal {
 	background-color: #d9d9d9;
 	white-space: nowrap;
+	text-align: right;
 }
 .pivot-value-grandtotal {
 	background-color: #c8c8c8;
 	white-space: nowrap;
+	text-align: right;
 }
 
 td .good div {
@@ -189,7 +198,7 @@
 .pt-panel-title-period,
 .pt-panel-title-organisationunit,
 .pt-panel-title-organisationunitgroupset,
-.pt-panel-title-options {
+.pt-panel-title-dataelementgroupset {
 	height: 17px;
 	background-repeat: no-repeat;
 	padding-left: 20px
@@ -207,8 +216,8 @@
 .pt-panel-title-organisationunitgroupset {
 	background-image: url(../images/organisationunitgroupset.png);
 }
-.pt-panel-title-options {
-	background-image: url(../images/options.png);
+.pt-panel-title-dataelementgroupset {
+	background-image: url(../images/dataelementgroupset.png);
 }
 
 
@@ -396,7 +405,7 @@
 
 	/* Align menu */
 .pt-toolbar-btn-menu {
-	margin-top: 5px;
+	margin-top: 4px;
 }
 
 /*----------------------------------------------------------------------------
@@ -432,16 +441,12 @@
  *--------------------------------------------------------------------------*/
 
 	/* Menu item icon */
-.pt-menu-item-png {
-    background-image:url('../images/png.png');
-    padding-left: 18px;
-}
-.pt-menu-item-pdf {
-    background-image:url('../images/pdf.png');
-    padding-left: 18px;
-}
-.pt-menu-item-edit {
-    background-image:url('../images/edit.png');
+.pt-menu-item-xls {
+    background-image:url('../images/pdf.png');
+    padding-left: 18px;
+}
+.pt-menu-item-csv {
+    background-image:url('../images/pdf.png');
     padding-left: 18px;
 }