← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14939: ER, analytics synchronization.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 14939 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-04-22 16:49:09 +0200
message:
  ER, analytics synchronization.
modified:
  dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/app.js
  dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/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-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/app.js	2014-04-21 18:18:01 +0000
+++ dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/app.js	2014-04-22 14:48:02 +0000
@@ -54,17 +54,25 @@
             bodyStyle: 'border:0 none',
             style: 'margin: ' + margin,
             getRecord: function() {
-                return {
-                    dimension: this.dataElement.id,
-                    name: this.dataElement.name,
-                    operator: this.operatorCmp.getValue(),
-                    filter: this.valueCmp.getValue()
-                };
+                var record = {};
+
+                record.dimension = this.dataElement.id;
+                record.name = this.dataElement.name;
+
+                if (this.valueCmp.getValue()) {
+					record.filter = this.operatorCmp.getValue() + ':' + this.valueCmp.getValue();
+				}
+
+				return record;
             },
             setRecord: function(record) {
-                this.operatorCmp.setValue(record.operator);
-                this.valueCmp.setValue(record.filter);
-            },
+				if (record.filter) {
+					var a = record.filter.split(':');
+
+					this.operatorCmp.setValue(a[0]);
+					this.valueCmp.setValue(a[1]);
+				}
+			},
             initComponent: function() {
                 var container = this;
 
@@ -135,12 +143,16 @@
             bodyStyle: 'border:0 none',
             style: 'margin: ' + margin,
             getRecord: function() {
-                return {
-                    dimension: this.dataElement.id,
-                    name: this.dataElement.name,
-                    operator: this.operatorCmp.getValue(),
-                    value: this.valueCmp.getValue()
-                };
+                var record = {};
+
+                record.dimension = this.dataElement.id;
+                record.name = this.dataElement.name;
+
+                if (this.valueCmp.getValue()) {
+					record.filter = this.operatorCmp.getValue() + ':' + this.valueCmp.getValue();
+				}
+
+				return record;
             },
             setRecord: function(record) {
                 this.operatorCmp.setValue(record.operator);
@@ -212,16 +224,24 @@
             bodyStyle: 'border:0 none',
             style: 'margin: ' + margin,
             getRecord: function() {
-                return {
-                    dimension: this.dataElement.id,
-                    name: this.dataElement.name,
-                    operator: this.operatorCmp.getValue(),
-                    filter: this.valueCmp.getSubmitValue()
-                };
+                var record = {};
+
+                record.dimension = this.dataElement.id;
+                record.name = this.dataElement.name;
+
+                if (this.valueCmp.getValue()) {
+					record.filter = this.operatorCmp.getValue() + ':' + this.valueCmp.getSubmitValue();
+				}
+
+				return record;
             },
             setRecord: function(record) {
-                this.operatorCmp.setValue(record.operator);
-                this.valueCmp.setValue(record.filter);
+				if (record.filter && Ext.isString(record.filter)) {
+					var a = record.filter.split(':');
+
+					this.operatorCmp.setValue(a[0]);
+					this.valueCmp.setValue(a[1]);
+				}
             },
             initComponent: function() {
                 var container = this;
@@ -294,12 +314,16 @@
             bodyStyle: 'border:0 none',
             style: 'margin: ' + margin,
             getRecord: function() {
-                return {
-                    dimension: this.dataElement.id,
-                    name: this.dataElement.name,
-                    operator: 'EQ',
-                    filter: this.valueCmp.getValue()
-                };
+                var record = {};
+
+                record.dimension = this.dataElement.id;
+                record.name = this.dataElement.name;
+
+                if (this.valueCmp.getValue()) {
+					record.filter = 'EQ:' + this.valueCmp.getValue();
+				}
+
+				return record;
             },
             setRecord: function(record) {
                 this.valueCmp.setValue(record.filter);
@@ -364,22 +388,27 @@
             bodyStyle: 'border:0 none',
             style: 'margin: ' + margin,
             getRecord: function() {
-				var valueArray = this.valueCmp.getValue().split(';');
+				var valueArray = this.valueCmp.getValue().split(';'),
+					record = {};
 
 				for (var i = 0; i < valueArray.length; i++) {
 					valueArray[i] = Ext.String.trim(valueArray[i]);
 				}
 
-                return {
-                    dimension: this.dataElement.id,
-                    name: this.dataElement.name,
-                    operator: this.operatorCmp.getValue(),
-                    filter: valueArray.join(';')
-                };
+				record.dimension = this.dataElement.id;
+				record.name = this.dataElement.name;
+
+				if (Ext.Array.clean(valueArray).length) {
+					record.filter = this.operatorCmp.getValue() + ':' + valueArray.join(';');
+				}
+
+				return record;
             },
             setRecord: function(record) {
-                this.operatorCmp.setValue(record.operator);
-                this.valueCmp.setOptionValues(record.filter.split(';'));
+				if (Ext.isString(record.filter) && record.filter) {
+					var a = record.filter.split(':');
+					this.valueCmp.setOptionValues(a[1].split(';'));
+				}
             },
             initComponent: function() {
                 var container = this;
@@ -529,7 +558,7 @@
                 });
 
                 this.valueCmp = Ext.create('Ext.form.field.Text', {
-					width: 224,
+					width: 226,
                     style: 'margin-bottom:0',
 					addOptionValue: function(option) {
 						var value = this.getValue();
@@ -3595,6 +3624,7 @@
 
         selectDataElements = function(items, layout) {
             var dataElements = [],
+				allElements = [],
                 aggWindow = ns.app.aggregateLayoutWindow,
                 queryWindow = ns.app.queryLayoutWindow,
                 includeKeys = ['int', 'number', 'boolean', 'bool'],
@@ -3623,9 +3653,33 @@
                 }
             }
 
+            // expand if multiple filter
+            for (var i = 0, element, a, numberOfElements; i < dataElements.length; i++) {
+				element = dataElements[i];
+				allElements.push(element);
+
+				if (element.type === 'int' && element.filter) {
+					a = element.filter.split(':');
+					numberOfElements = a.length / 2;
+
+					if (numberOfElements > 1) {
+						a.shift();
+						a.shift();
+
+						for (var j = 1, newElement; j < numberOfElements; j++) {
+							newElement = Ext.clone(element);
+							newElement.filter = a.shift();
+							newElement.filter += ':' + a.shift();
+
+							allElements.push(newElement);
+						}
+					}
+				}
+			}
+
 			// panel, store
-            for (var i = 0, element, ux, store; i < dataElements.length; i++) {
-				element = dataElements[i];
+            for (var i = 0, element, ux, store; i < allElements.length; i++) {
+				element = allElements[i];
                 element.type = element.type || element.valueType;
                 element.name = element.name || element.displayName;
                 recordMap[element.id] = element;
@@ -4951,8 +5005,24 @@
 				layoutWindow.colStore.each(function(item) {
 					a = map[item.data.id] || [];
 
-					for (var i = 0; i < a.length; i++) {
-						columns.push(a[i]);
+					if (a.length) {
+						if (a.length === 1) {
+							columns.push(a[0]);
+						}
+						else {
+							var dim;
+
+							for (var i = 0; i < a.length; i++) {
+								if (!dim) {
+									dim = a[i];
+								}
+								else {
+									dim.filter += ':' + a[i].filter;
+								}
+							}
+
+							columns.push(dim);
+						}
 					}
 				});
 			}
@@ -4961,8 +5031,24 @@
 				layoutWindow.rowStore.each(function(item) {
 					a = map[item.data.id] || [];
 
-					for (var i = 0; i < a.length; i++) {
-						rows.push(a[i]);
+					if (a.length) {
+						if (a.length === 1) {
+							rows.push(a[0]);
+						}
+						else {
+							var dim;
+
+							for (var i = 0; i < a.length; i++) {
+								if (!dim) {
+									dim = a[i];
+								}
+								else {
+									dim.filter += ':' + a[i].filter;
+								}
+							}
+
+							rows.push(dim);
+						}
 					}
 				});
 			}
@@ -4971,8 +5057,24 @@
 				layoutWindow.filterStore.each(function(item) {
 					a = map[item.data.id] || [];
 
-					for (var i = 0; i < a.length; i++) {
-						filters.push(a[i]);
+					if (a.length) {
+						if (a.length === 1) {
+							filters.push(a[0]);
+						}
+						else {
+							var dim;
+
+							for (var i = 0; i < a.length; i++) {
+								if (!dim) {
+									dim = a[i];
+								}
+								else {
+									dim.filter += ':' + a[i].filter;
+								}
+							}
+
+							filters.push(dim);
+						}
 					}
 				});
 			}
@@ -4981,8 +5083,24 @@
 				layoutWindow.fixedFilterStore.each(function(item) {
 					a = map[item.data.id] || [];
 
-					for (var i = 0; i < a.length; i++) {
-						filters.push(a[i]);
+					if (a.length) {
+						if (a.length === 1) {
+							filters.push(a[0]);
+						}
+						else {
+							var dim;
+
+							for (var i = 0; i < a.length; i++) {
+								if (!dim) {
+									dim = a[i];
+								}
+								else {
+									dim.filter += ':' + a[i].filter;
+								}
+							}
+
+							filters.push(dim);
+						}
 					}
 				});
 			}

=== modified file 'dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/core.js	2014-04-21 18:18:01 +0000
+++ dhis-2/dhis-web/dhis-web-event-reports/src/main/webapp/dhis-web-event-reports/app/scripts/core.js	2014-04-22 14:48:02 +0000
@@ -894,7 +894,7 @@
 
 				// columns, rows, filters
 				if (layout.columns) {
-                    layout.columns = support.prototype.array.uniqueByProperty(layout.columns, 'dimension');
+                    //layout.columns = support.prototype.array.uniqueByProperty(layout.columns, 'dimension');
 
 					for (var i = 0, dim, items, xDim; i < layout.columns.length; i++) {
 						dim = layout.columns[i];
@@ -932,7 +932,7 @@
 				}
 
 				if (layout.rows) {
-                    layout.rows = support.prototype.array.uniqueByProperty(layout.rows, 'dimension');
+                    //layout.rows = support.prototype.array.uniqueByProperty(layout.rows, 'dimension');
 
 					for (var i = 0, dim, items, xDim; i < layout.rows.length; i++) {
 						dim = Ext.clone(layout.rows[i]);
@@ -970,7 +970,7 @@
 				}
 
 				if (layout.filters) {
-                    layout.filters = support.prototype.array.uniqueByProperty(layout.filters, 'dimension');
+                    //layout.filters = support.prototype.array.uniqueByProperty(layout.filters, 'dimension');
 
 					for (var i = 0, dim, items, xDim; i < layout.filters.length; i++) {
 						dim = layout.filters[i];
@@ -1809,8 +1809,6 @@
 
                 // dimensions
                 if (dimensions) {
-                    nameItemsMap = {};
-
 					for (var i = 0, dim; i < dimensions.length; i++) {
 						dim = dimensions[i];
 
@@ -1818,38 +1816,20 @@
 							continue;
 						}
 
-                        if (!nameItemsMap[dim.dimension]) {
-                            nameItemsMap[dim.dimension] = [];
-                        }
-
-                        nameItemsMap[dim.dimension].push(dim);
-                    }
-
-                    for (var key in nameItemsMap) {
-                        var dimArray;
-
-                        if (nameItemsMap.hasOwnProperty(key)) {
-                            dimArray = nameItemsMap[key];
-
-                            paramString += '&dimension=' + key;
-
-                            for (var i = 0, dim; i < dimArray.length; i++) {
-                                dim = dimArray[i];
-
-                                if (dim.items && dim.items.length) {
-                                    paramString += ':';
-
-                                    for (var j = 0, item; j < dim.items.length; j++) {
-                                        item = dim.items[j];
-
-                                        paramString += encodeURIComponent(item.id) + ((j < (dim.items.length - 1)) ? ';' : '');
-                                    }
-                                }
-                                else if (dim.operator && !Ext.isEmpty(dim.filter)) {
-                                    paramString += ':' + dim.operator + ':' + encodeURIComponent(dim.filter);
-                                }
-                            }
-                        }
+						paramString += '&dimension=' + dim.dimension;
+
+						if (dim.items && dim.items.length) {
+							paramString += ':';
+
+							for (var j = 0, item; j < dim.items.length; j++) {
+								item = dim.items[j];
+
+								paramString += encodeURIComponent(item.id) + ((j < (dim.items.length - 1)) ? ';' : '');
+							}
+						}
+						else {
+							paramString += dim.filter ? ':' + encodeURIComponent(dim.filter) : '';
+						}
 					}
 				}
 
@@ -1858,24 +1838,8 @@
 					for (var i = 0, dim; i < view.filters.length; i++) {
 						dim = view.filters[i];
 
-						if (Ext.Array.contains(ignoreKeys, dim.dimension)) {
-							continue;
-						}
-
 						paramString += '&filter=' + dim.dimension;
-
-						if (dim.items && dim.items.length) {
-							paramString += ':';
-
-							for (var j = 0, item; j < dim.items.length; j++) {
-								item = dim.items[j];
-
-								paramString += encodeURIComponent(item.id) + ((j < (dim.items.length - 1)) ? ';' : '');
-							}
-						}
-						else if (dim.operator && !Ext.isEmpty(dim.filter)) {
-							paramString += ':' + dim.operator + ':' + encodeURIComponent(dim.filter);
-						}
+						paramString += dim.filter ? ':' + encodeURIComponent(dim.filter) : '';
 					}
 				}