← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20250: PT download data option implemented.

 

------------------------------------------------------------
revno: 20250
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-09-21 12:53:31 +0300
message:
  PT download data option implemented.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/i18n/i18n_app.properties
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.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-apps/src/main/webapp/dhis-web-pivot/i18n/i18n_app.properties'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/i18n/i18n_app.properties	2015-09-15 19:42:00 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/i18n/i18n_app.properties	2015-09-21 09:53:31 +0000
@@ -204,3 +204,4 @@
 include_only_completed_events_only=Include only completed events
 comma=Comma
 space=Space
+download_data=Download data

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js	2015-09-15 22:59:55 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js	2015-09-21 09:53:31 +0000
@@ -2812,8 +2812,9 @@
             dimensionPanelMap = {},
 			getDimensionPanel,
 			getDimensionPanels,
+
+            getLayout,
 			update,
-
 			accordionBody,
             accordion,
             westRegion,
@@ -2823,6 +2824,7 @@
             getParamString,
             openTableLayoutTab,
             openPlainDataSource,
+            openDataDump,
             downloadButton,
             interpretationItem,
             pluginItem,
@@ -6410,15 +6412,16 @@
 
 		// viewport
 
+        getLayout = function() {
+            return ns.core.api.layout.Layout(ns.core.web.pivot.getLayoutConfig());
+        };
+
 		update = function() {
-			var config = ns.core.web.pivot.getLayoutConfig(),
-                layout = ns.core.api.layout.Layout(config);
-
-			if (!layout) {
-				return;
-			}
-
-			ns.core.web.pivot.getData(layout, false);
+			var layout;
+
+			if (layout = getLayout()) {
+                ns.core.web.pivot.getData(layout, false);
+            }
 		};
 
 		accordionBody = Ext.create('Ext.panel.Panel', {
@@ -6516,6 +6519,78 @@
 			}
 		});
 
+        updateButton = Ext.create('Ext.button.Split', {
+            text: '<b>' + NS.i18n.update + '</b>&nbsp;',
+            handler: function() {
+                update();
+            },
+            arrowHandler: function(b) {
+                b.menu = Ext.create('Ext.menu.Menu', {
+                    closeAction: 'destroy',
+                    shadow: false,
+                    showSeparator: false,
+                    items: [
+                        {
+                            xtype: 'label',
+                            text: NS.i18n.download_data,
+                            style: 'padding:7px 40px 5px 7px; font-weight:bold; color:#111; border:0 none'
+                        },
+                        {
+                            text: 'CSV',
+                            iconCls: 'ns-menu-item-datasource',
+                            handler: function() {
+                                openDataDump('csv', 'ID');
+                            },
+                            menu: [
+                                {
+                                    xtype: 'label',
+                                    text: NS.i18n.metadata_id_scheme,
+                                    style: 'padding:7px 18px 5px 7px; font-weight:bold; color:#333'
+                                },
+                                {
+                                    text: 'ID',
+                                    iconCls: 'ns-menu-item-scheme',
+                                    handler: function() {
+                                        openDataDump('csv', 'ID');
+                                    }
+                                },
+                                {
+                                    text: 'Code',
+                                    iconCls: 'ns-menu-item-scheme',
+                                    handler: function() {
+                                        openDataDump('csv', 'CODE');
+                                    }
+                                },
+                                {
+                                    text: 'Name',
+                                    iconCls: 'ns-menu-item-scheme',
+                                    handler: function() {
+                                        openDataDump('csv', 'NAME');
+                                    }
+                                }
+                            ]
+                        }
+                    ],
+                    listeners: {
+                        added: function() {
+                            ns.app.updateButton = this;
+                        },
+                        show: function() {
+                            ns.core.web.window.setAnchorPosition(b.menu, b);
+                        },
+                        hide: function() {
+                            b.menu.destroy();
+                        },
+                        destroy: function(m) {
+                            b.menu = null;
+                        }
+                    }
+                });
+
+                this.menu.show();
+            }
+        });
+
 		layoutButton = Ext.create('Ext.button.Button', {
 			text: 'Layout',
 			menu: {},
@@ -6569,10 +6644,12 @@
 			}
 		});
 
-		getParamString = function() {
-			var paramString = ns.core.web.analytics.getParamString(ns.core.service.layout.getExtendedLayout(ns.app.layout));
-
-			if (ns.app.layout.showHierarchy) {
+		getParamString = function(layout) {
+            layout = layout || ns.app.layout;
+
+			var paramString = ns.core.web.analytics.getParamString(ns.core.service.layout.getExtendedLayout(layout));
+
+			if (layout.showHierarchy) {
 				paramString += '&showHierarchy=true';
 			}
 
@@ -6609,6 +6686,17 @@
             }
         };
 
+        openDataDump = function(format, scheme, isNewTab) {
+            var layout;
+
+            format = format || 'csv';
+            scheme = scheme || 'ID';
+
+            if (layout = getLayout()) {
+                window.open(ns.core.init.contextPath + '/api/analytics.' + format + getParamString(layout) + (scheme ? '&outputIdScheme=' + scheme : ''), isNewTab ? '_blank' : '_top');
+            }
+        };
+
 		downloadButton = Ext.create('Ext.button.Button', {
             text: NS.i18n.download,
 			disabled: true,
@@ -7173,12 +7261,7 @@
 							westRegion.toggleCollapse();
 						}
 					},
-					{
-						text: '<b>' + NS.i18n.update + '</b>',
-						handler: function() {
-							update();
-						}
-					},
+                    updateButton,
 					layoutButton,
 					optionsButton,
 					{