← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18297: ER aggregation types, work in progress.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 18297 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-02-17 20:18:25 +0100
message:
  ER aggregation types, work in progress.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/i18n/i18n_app.properties
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/core.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/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
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/i18n/i18n_app.properties'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/i18n/i18n_app.properties	2015-02-16 14:25:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/i18n/i18n_app.properties	2015-02-17 18:12:44 +0000
@@ -1,7 +1,4 @@
 dimensions=Dimensions
-row=Row
-column=Column
-filter=Filter
 table_layout=Table layout
 show_totals=Show totals
 show_subtotals=Show sub-totals
@@ -177,3 +174,14 @@
 event=Event
 tracked_entity_instance=Tracked entity instance
 enrollment=Enrollment
+column_dimensions=Column dimensions
+row_dimensions=Row dimensions
+report_filter=Report filter
+average=Average
+count=Count
+sum=Sum
+by_data_element=By data element
+stddev=Std Dev
+variance=Variance
+min=Min
+max=Max

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js	2015-02-16 14:25:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js	2015-02-17 19:16:48 +0000
@@ -1006,7 +1006,9 @@
             fixedFilterStore,
 			filter,
 			filterStore,
+            onValueSelect,
 			value,
+            aggregationType,
 
 			getStore,
 			getStoreKeys,
@@ -1023,7 +1025,7 @@
 			window,
 
 			margin = 1,
-			defaultWidth = 160,
+			defaultWidth = 200,
 			defaultHeight = 220,
 			maxHeight = (ns.app.viewport.getHeight() - 100) / 2,
 
@@ -1068,6 +1070,27 @@
 		rowStore = getStore();
         fixedFilterStore = getStore();
         filterStore = getStore();
+        valueStore = getStore();
+
+        // store listeners
+        valueStore.on('add', function(store, records) {
+            if (!value.getValue()) {
+                value.setValue(records[0].data.id);
+            }
+        });
+
+        valueStore.on('remove', function(store, record) {
+            if (value.getValue() === record.data.id) {
+                value.clearValue();
+            }
+
+            if (store.getRange().length) {
+                var id = store.getRange()[0].data.id;
+
+                value.setValue(id);
+                onValueSelect(id);
+            }
+        });
 
         fixedFilterStore.setListHeight = function() {
             var fixedFilterHeight = 26 + (this.getRange().length * 21) + 1;
@@ -1089,7 +1112,7 @@
 				height: 25,
 				items: {
 					xtype: 'label',
-					text: NS.i18n.column,
+					text: NS.i18n.column_dimensions,
 					cls: 'ns-toolbar-multiselect-leftright-label'
 				}
 			},
@@ -1113,7 +1136,7 @@
 			cls: 'ns-toolbar-multiselect-leftright',
 			width: defaultWidth,
 			height: defaultHeight,
-			style: 'margin-bottom:0px',
+			style: 'margin-right:' + margin + 'px; margin-bottom:0px',
 			valueField: 'id',
 			displayField: 'name',
 			dragGroup: 'layoutDD',
@@ -1123,7 +1146,7 @@
 				height: 25,
 				items: {
 					xtype: 'label',
-					text: NS.i18n.row,
+					text: NS.i18n.row_dimensions,
 					cls: 'ns-toolbar-multiselect-leftright-label'
 				}
 			},
@@ -1155,7 +1178,7 @@
 				height: 25,
 				items: {
 					xtype: 'label',
-					text: NS.i18n.filter,
+					text: NS.i18n.report_filter,
 					cls: 'ns-toolbar-multiselect-leftright-label'
 				}
 			},
@@ -1181,7 +1204,6 @@
 			store: filterStore,
 			listeners: {
 				afterrender: function(ms) {
-
 					ms.store.on('add', function() {
 						Ext.defer( function() {
 							ms.boundList.getSelectionModel().deselectAll();
@@ -1191,6 +1213,60 @@
 			}
 		});
 
+        aggregationType = Ext.create('Ext.form.field.ComboBox', {
+			cls: 'ns-combo h22',
+			width: 80,
+			height: 22,
+			style: 'margin: 0',
+            fieldStyle: 'height: 22px',
+			queryMode: 'local',
+			valueField: 'id',
+			editable: false,
+            value: 'AVERAGE',
+			store: Ext.create('Ext.data.Store', {
+				fields: ['id', 'text'],
+				data: [
+					{id: 'AVERAGE', text: NS.i18n.average},
+					{id: 'SUM', text: NS.i18n.sum},
+					{id: 'COUNT', text: NS.i18n.count},
+					{id: 'STDDEV', text: NS.i18n.stddev},
+					{id: 'VARIANCE', text: NS.i18n.variance},
+					{id: 'MIN', text: NS.i18n.min},
+					{id: 'MAX', text: NS.i18n.max}
+				]
+			})
+		});
+
+        onValueSelect = function(id) {
+
+            // remove selected
+            removeDimension(id, valueStore);
+
+            // add unselected
+            valueStore.each( function(record) {
+                if (record.data.id !== id) {
+                    addDimension(record.data, null, valueStore);
+                }
+            });
+        };
+
+		value = Ext.create('Ext.form.field.ComboBox', {
+			cls: 'ns-combo h24',
+			width: defaultWidth - 4,
+			height: 24,
+            fieldStyle: 'height: 24px',
+			queryMode: 'local',
+			valueField: 'id',
+            displayField: 'name',
+			editable: false,
+			store: valueStore,
+            listeners: {
+                select: function(cb, r) {
+                    onValueSelect(r[0].data.id);
+                }
+            }
+		});
+
 		selectPanel = Ext.create('Ext.panel.Panel', {
 			bodyStyle: 'border:0 none',
 			items: [
@@ -1211,39 +1287,72 @@
 					]
 				},
 				{
-					layout: 'column',
+					xtype: 'container',
+                    layout: 'column',
 					bodyStyle: 'border:0 none',
 					items: [
-						row
+						row,
+                        {
+                            xtype: 'panel',
+                            bodyStyle: 'padding: 1px',
+                            width: defaultWidth,
+                            height: 220,
+                            items: value,
+                            tbar: {
+                                height: 25,
+                                style: 'padding: 1px',
+                                items: [
+                                    {
+                                        xtype: 'label',
+                                        height: 22,
+                                        style: 'padding-left: 6px; line-height: 22px',
+                                        text: 'Value'
+                                    },
+                                    '->',
+                                    aggregationType
+                                ]
+                            }
+                        }
 					]
 				}
 			]
 		});
 
-        addDimension = function(record, store) {
+        addDimension = function(record, store, excludedStores) {
             var store = dimensionStoreMap[record.id] || store || filterStore;
 
-            if (!hasDimension(record.id)) {
+            if (!hasDimension(record.id, excludedStores)) {
+
+                // if not applicable for value store
+                if (store === valueStore && !Ext.Array.contains(['int', 'number'], record.type)) {
+                    store = rowStore;
+                }
+
+                // if already value
+                if (store === valueStore && valueStore.getRange().length) {
+                    rowStore.add(record);
+                }
+
                 store.add(record);
             }
         };
 
-        removeDimension = function(dataElementId) {
-            var stores = [colStore, rowStore, filterStore, fixedFilterStore];
+        removeDimension = function(id, excludedStores) {
+            var stores = Ext.Array.difference([colStore, rowStore, filterStore, fixedFilterStore, valueStore], Ext.Array.from(excludedStores));
 
             for (var i = 0, store, index; i < stores.length; i++) {
                 store = stores[i];
-                index = store.findExact('id', dataElementId);
+                index = store.findExact('id', id);
 
                 if (index != -1) {
                     store.remove(store.getAt(index));
-                    dimensionStoreMap[dataElementId] = store;
+                    dimensionStoreMap[id] = store;
                 }
             }
         };
 
-        hasDimension = function(id) {
-            var stores = [colStore, rowStore, filterStore, fixedFilterStore];
+        hasDimension = function(id, excludedStores) {
+            var stores = Ext.Array.difference([colStore, rowStore, filterStore, fixedFilterStore, valueStore], Ext.Array.from(excludedStores));
 
             for (var i = 0, store, index; i < stores.length; i++) {
                 store = stores[i];
@@ -1276,6 +1385,10 @@
                 map[record.data.id] = fixedFilterStore;
             });
 
+            valueStore.each(function(record) {
+                map[record.data.id] = valueStore;
+            });
+
             return map;
         };
 
@@ -1295,6 +1408,8 @@
 			rowStore.removeAll();
 			fixedFilterStore.removeAll();
 			filterStore.removeAll();
+            valueStore.removeAll();
+            value.clearValue();
 
 			if (!isAll) {
 				colStore.add({id: dimConf.organisationUnit.dimensionName, name: dimConf.organisationUnit.name});
@@ -1316,12 +1431,19 @@
 			rowStore: rowStore,
             fixedFilterStore: fixedFilterStore,
 			filterStore: filterStore,
+            valueStore: valueStore,
             addDimension: addDimension,
             removeDimension: removeDimension,
             hasDimension: hasDimension,
             saveState: saveState,
             resetData: resetData,
             reset: reset,
+            getValueId: function() {
+                return value.getValue();
+            },
+            getAggregationType: function() {
+                return aggregationType.getValue();
+            },
 			hideOnBlur: true,
 			items: selectPanel,
 			bbar: [
@@ -3875,7 +3997,6 @@
         selectDataElements = function(items, layout) {
             var dataElements = [],
 				allElements = [],
-                fixedFilterElementIds = [],
                 aggWindow = ns.app.aggregateLayoutWindow,
                 queryWindow = ns.app.queryLayoutWindow,
                 includeKeys = ['int', 'number', 'bool', 'boolean', 'trueOnly'],
@@ -3945,11 +4066,7 @@
                     ux.setRecord(element);
                 }
 
-                store = Ext.Array.contains(includeKeys, element.type) || element.optionSet ? aggWindow.rowStore : aggWindow.fixedFilterStore;
-
-                if (store === aggWindow.fixedFilterStore) {
-					fixedFilterElementIds.push(element.id);
-				}
+                store = Ext.Array.contains(includeKeys, element.type) || element.optionSet ? aggWindow.valueStore : aggWindow.fixedFilterStore;
 
                 aggWindow.addDimension(element, store);
                 queryWindow.colStore.add(element);
@@ -5575,6 +5692,7 @@
 				columns = [],
 				rows = [],
 				filters = [],
+                values = [],
 				a;
 
 			view.dataType = dataType;
@@ -5734,8 +5852,6 @@
 				});
 			}
 
-            // view
-
 			if (columns.length) {
 				view.columns = columns;
 			}
@@ -5746,6 +5862,12 @@
 				view.filters = filters;
 			}
 
+            // value
+            view.valueId = layoutWindow.getValueId();
+
+            // aggregation type
+            view.aggregationType = layoutWindow.getAggregationType();
+
 			return view;
 		};
 

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/core.js	2015-02-16 16:00:31 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/core.js	2015-02-17 18:40:51 +0000
@@ -2064,6 +2064,16 @@
 					}
 				}
 
+                // values
+                if (view.valueId) {
+                    paramString += '&value=' + view.valueId;
+				}
+
+                // aggregation type
+                if (view.aggregationType) {
+                    paramString += '&aggregationType=' + view.aggregationType;
+                }
+
                 // dates
                 if (view.startDate && view.endDate) {
                     paramString += '&startDate=' + view.startDate + '&endDate=' + view.endDate;

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/styles/style.css'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/styles/style.css	2014-11-19 16:30:33 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/styles/style.css	2015-02-17 14:52:40 +0000
@@ -433,6 +433,17 @@
     border-radius: 1px 0px 0px 0px;
 }
 
+	/* Custom */
+.ns-combo.h21 .x-form-trigger {
+    height: 21px;
+}
+.ns-combo.h22 .x-form-trigger {
+    height: 22px;
+}
+.ns-combo.h24 .x-form-trigger {
+    height: 24px;
+}
+
 
 /*----------------------------------------------------------------------------
  * PT Trigger