← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17317: EV optionset idb + code/name implemented.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 17317 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-10-30 17:30:32 +0100
message:
  EV optionset idb + code/name implemented.
modified:
  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-visualizer/scripts/app.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/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-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	2014-10-29 00:52:49 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js	2014-10-30 16:12:52 +0000
@@ -6408,9 +6408,9 @@
 						table,
 						getSXLayout,
 						getXResponse,
-                        getTable;
+                        getReport;
 
-                    getTable = function() {
+                    getReport = function() {
                         var getHtml = function(xLayout, xResponse) {
                             xColAxis = service.layout.getExtendedAxis(xLayout, 'col');
                             xRowAxis = service.layout.getExtendedAxis(xLayout, 'row');
@@ -6481,7 +6481,7 @@
                     getSXLayout = function() {
                         xLayout = service.layout.getSyncronizedXLayout(layout, xLayout, xResponse);
 
-                        getTable();
+                        getReport();
                     };
 
                     getXResponse = function() {
@@ -6499,9 +6499,9 @@
 
 				map['individual_cases'] = function() {
 					var xResponse,
-                        getTable;
+                        getReport;
 
-                    getTable = function() {
+                    getReport = function() {
                         table = web.report.query.getHtml(layout, xResponse);
 
                         //if (layout.sorting) {
@@ -6529,7 +6529,7 @@
                     // execute
                     xResponse = service.response.query.getExtendedResponse(layout, response);
 
-                    getOptionSets(xResponse, getTable);
+                    getOptionSets(xResponse, getReport);
 				};
 
 				map[layout.dataType]();

=== 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	2014-10-29 00:56:31 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/core.js	2014-10-30 16:12:52 +0000
@@ -754,7 +754,6 @@
                 return o;
             };
 
-
                 // object
 			support.prototype.object = {};
 

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js	2014-10-29 00:52:49 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js	2014-10-30 16:12:52 +0000
@@ -443,7 +443,7 @@
                 if (items.length) {
                     record.filter = 'IN:' + items.join(';');
                 }
-                
+
                 return record;
             },
             setRecord: function(record) {
@@ -482,7 +482,7 @@
                 });
 
                 this.searchStore = Ext.create('Ext.data.Store', {
-					fields: [idProperty, 'name'],
+					fields: [idProperty, nameProperty],
 					data: [],
 					loadOptionSet: function(optionSetId, key, pageSize) {
 						var store = this;
@@ -492,8 +492,31 @@
 
                         dhis2.ev.store.get('optionSets', optionSetId).done( function(obj) {
                             if (Ext.isObject(obj) && Ext.isArray(obj.options) && obj.options.length) {
+                                var data = [];
+
+                                if (key) {
+                                    var re = new RegExp(key, 'gi');
+
+                                    for (var i = 0, name, match; i < obj.options.length; i++) {
+                                        name = obj.options[i].name;
+                                        match = name.match(re);
+
+                                        if (Ext.isArray(match) && match.length) {
+                                            data.push(obj.options[i]);
+
+                                            if (data.length === pageSize) {
+                                                break;
+                                            }
+                                        }
+                                    }
+                                }
+                                else {
+                                    data = obj.options;
+                                }
+
                                 store.removeAll();
-                                store.loadData(obj.options.slice(0, pageSize));
+                                store.loadData(data.slice(0, pageSize));
+
                             }
                         });
 					},
@@ -525,11 +548,10 @@
                     valueField: idProperty,
                     displayField: nameProperty,
                     hideTrigger: true,
-                    delimiter: '; ',
                     enableKeyEvents: true,
                     queryMode: 'local',
                     listConfig: {
-                        minWidth: 304
+                        minWidth: 346
                     },
                     store: this.searchStore,
                     listeners: {
@@ -602,11 +624,12 @@
                     store: container.valueStore,
                     queryMode: 'local',
                     listConfig: {
+                        minWidth: 266,
                         cls: 'optionselector'
                     },
                     setOptionValues: function(optionArray) {
                         var options = [];
-                        
+
                         for (var i = 0; i < optionArray.length; i++) {
                             options.push({
                                 code: optionArray[i],
@@ -618,7 +641,7 @@
                         container.valueStore.loadData(options);
 
                         this.setValue(options);
-                    },                            
+                    },
 					listeners: {
                         change: function(cmp, newVal, oldVal) {
                             newVal = Ext.Array.from(newVal);
@@ -662,6 +685,7 @@
                 this.callParent();
             }
         });
+
     }());
 
 		// toolbar
@@ -1026,7 +1050,7 @@
 
 					ms.store.on('add', function(store, addedRecords) {
                         var range = store.getRange();
-                        
+
                         if (range.length > 1) {
                             var addedIds = Ext.Array.pluck(addedRecords, 'internalId'),
                                 records = Ext.clone(range);
@@ -1042,10 +1066,10 @@
                                 }
                             }
                         }
-                        
+
 						Ext.defer( function() {
 							ms.boundList.getSelectionModel().deselectAll();
-						}, 10);                        
+						}, 10);
 					});
 				}
 			}
@@ -1078,7 +1102,7 @@
 
 					ms.store.on('add', function(store, addedRecords) {
                         var range = store.getRange();
-                        
+
                         if (range.length > 1) {
                             var addedIds = Ext.Array.pluck(addedRecords, 'internalId'),
                                 records = Ext.clone(range);
@@ -1094,10 +1118,10 @@
                                 }
                             }
                         }
-                        
+
 						Ext.defer( function() {
 							ms.boundList.getSelectionModel().deselectAll();
-						}, 10);                        
+						}, 10);
 					});
 				}
 			}
@@ -1294,7 +1318,7 @@
 				{
 					text: '<b>' + NS.i18n.update + '</b>',
                     handler: function() {
-                        ns.app.viewport.update();                        
+                        ns.app.viewport.update();
 
                         window.hide();
                     }
@@ -1342,7 +1366,7 @@
             rangeAxisDecimals,
 			rangeAxisTitle,
 			domainAxisTitle,
-            
+
 			hideLegend,
 			hideTitle,
 			title,
@@ -1514,7 +1538,7 @@
 			enforceMaxLength: true,
 			style: 'margin-bottom:1px'
 		});
-		
+
 		domainAxisTitle = Ext.create('Ext.form.field.Text', {
 			width: cmpWidth,
 			fieldLabel: NS.i18n.domain_axis_label,
@@ -1588,7 +1612,7 @@
 				rangeAxisTitle,
 				domainAxisTitle
 			]
-		};			
+		};
 
 		general = {
 			bodyStyle: 'border:0 none',
@@ -1713,7 +1737,7 @@
 				else {
 					domainAxisTitle.reset();
 				}
-				
+
 				hideLegend.setValue(Ext.isBoolean(layout.hideLegend) ? layout.hideLegend : false);
 				hideTitle.setValue(Ext.isBoolean(layout.hideTitle) ? layout.hideTitle : false);
 
@@ -1794,7 +1818,7 @@
 					w.rangeAxisDecimals = rangeAxisDecimals;
 					w.rangeAxisTitle = rangeAxisTitle;
 					w.domainAxisTitle = domainAxisTitle;
-					
+
 					w.hideLegend = hideLegend;
 					w.hideTitle = hideTitle;
 					w.title = title;
@@ -1862,7 +1886,7 @@
 
 			if (ns.app.layout) {
 				favorite = Ext.clone(ns.app.layout);
-                
+
 				// server sync
 				favorite.showData = favorite.showValues;
 				delete favorite.showValues;
@@ -2951,7 +2975,7 @@
 				isOugc = false,
 				levels = [],
 				groups = [],
-                
+
 				optionsWindow = ns.app.aggregateOptionsWindow;
 
             reset();
@@ -3500,7 +3524,7 @@
 					for (var i = 0, record, dim; i < layout.columns.length; i++) {
                         dim = layout.columns[i];
                         record = recordMap[dim.dimension];
-                        
+
 						aggWindow.colStore.add(record || extendDim(Ext.clone(dim)));
 					}
 				}
@@ -3509,7 +3533,7 @@
 					for (var i = 0, record, dim; i < layout.rows.length; i++) {
                         dim = layout.rows[i];
                         record = recordMap[dim.dimension];
-                        
+
 						aggWindow.rowStore.add(record || extendDim(Ext.clone(dim)));
 					}
 				}
@@ -3628,14 +3652,14 @@
                 }
             });
         };
-        
+
         onDateFieldRender = function(c) {
             $('#' + c.inputEl.id).calendarsPicker({
                 calendar: ns.core.init.calendar,
                 dateFormat: ns.core.init.systemInfo.dateFormat
             });
         };
-        
+
         startDate = Ext.create('Ext.form.field.Text', {
 			fieldLabel: 'Start date',
 			labelAlign: 'top',
@@ -4507,7 +4531,7 @@
 				},
 				afterrender: function() {
 					this.getSelectionModel().select(0);
-                    
+
                     Ext.defer(function() {
                         data.expand();
                     }, 20);
@@ -5119,7 +5143,7 @@
                 return;
             }
 
-			// pe            
+			// pe
             if (periodMode.getValue() === 'dates') {
                 view.startDate = startDate.getSubmitValue();
                 view.endDate = endDate.getSubmitValue();
@@ -5862,7 +5886,7 @@
                         direction: view.sortOrder == 1 ? 'DESC' : 'ASC'
                     };
                 }
-                
+
                 return view;
             };
 
@@ -5933,73 +5957,124 @@
 
 			web.report.createReport = function(layout, response, isUpdateGui) {
                 var xLayout,
+                    xResponse,
                     xColAxis,
                     xRowAxis,
                     chart,
-                    getXLayout = service.layout.getExtendedLayout,
-                    getSXLayout = service.layout.getSyncronizedXLayout,
-                    getXResponse = service.response.aggregate.getExtendedResponse;
-
+                    getOptionSets,
+                    getReport,
+                    getSXLayout,
+                    getXResponse;
+
+                getOptionSets = function(xResponse, callbackFn) {
+                    var optionSetHeaders = [];
+
+                    for (var i = 0; i < xResponse.headers.length; i++) {
+                        if (Ext.isString(xResponse.headers[i].optionSet)) {
+                            optionSetHeaders.push(xResponse.headers[i]);
+                        }
+                    }
+
+                    if (optionSetHeaders.length) {
+                        var callbacks = 0,
+                            optionMap = {},
+                            getOptions,
+                            fn;
+
+                        fn = function() {
+                            if (++callbacks === optionSetHeaders.length) {
+                                xResponse.metaData.optionNames = optionMap;
+                                callbackFn();
+                            }
+                        };
+
+                        getOptions = function(optionSetId, dataElementId) {
+                            dhis2.ev.store.get('optionSets', optionSetId).done( function(obj) {
+                                Ext.apply(optionMap, support.prototype.array.getObjectMap(obj.options, 'code', 'name', dataElementId));
+                                fn();
+                            });
+                        };
+
+                        // execute
+                        for (var i = 0, header, optionSetId, dataElementId; i < optionSetHeaders.length; i++) {
+                            header = optionSetHeaders[i];
+                            optionSetId = header.optionSet;
+                            dataElementId = header.name;
+
+                            getOptions(optionSetId, dataElementId);
+                        }
+                    }
+                    else {
+                        callbackFn();
+                    }
+                };
+
+                getReport = function() {
+                    if (!xLayout) {
+                        web.mask.hide(ns.app.centerRegion);
+                        return;
+                    }
+
+                    web.mask.show(ns.app.centerRegion, 'Error while rendering chart..');
+
+                    chart = web.report.aggregate.createChart(layout, xLayout, xResponse, ns.app.centerRegion);
+
+                    // timing
+                    ns.app.dateRender = new Date();
+
+                    ns.app.centerRegion.update();
+                    ns.app.centerRegion.removeAll(true);
+                    ns.app.centerRegion.add(chart);
+
+                    // timing
+                    ns.app.dateTotal = new Date();
+
+                    // after render
+                    ns.app.layout = layout;
+                    ns.app.xLayout = xLayout;
+                    ns.app.response = response;
+                    ns.app.xResponse = xResponse;
+                    ns.app.chart = chart;
+
+                    if (NS.isSessionStorage) {
+                        web.storage.session.set(layout, 'eventchart');
+                    }
+
+                    ns.app.accordion.setGui(layout, xLayout, response, isUpdateGui); //table);
+
+                    web.mask.hide(ns.app.centerRegion);
+
+                    if (NS.isDebug) {
+                        console.log("DATA", (ns.app.dateCreate - ns.app.dateData) / 1000);
+                        console.log("CREATE", (ns.app.dateRender - ns.app.dateCreate) / 1000);
+                        console.log("RENDER", (ns.app.dateTotal - ns.app.dateRender) / 1000);
+                        console.log("TOTAL", (ns.app.dateTotal - ns.app.dateData) / 1000);
+                        console.log("layout", layout);
+                        console.log("response", response);
+                        console.log("xResponse", xResponse);
+                        console.log("xLayout", xLayout);
+                        console.log("core", ns.core);
+                        console.log("app", ns.app);
+                    }
+                };
+
+                getSXLayout = function() {
+                    xLayout = service.layout.getSyncronizedXLayout(layout, xLayout, xResponse);
+
+                    getReport();
+                };
+
+                getXResponse = function() {
+                    xLayout = service.layout.getExtendedLayout(layout);
+                    xResponse = service.response.aggregate.getExtendedResponse(xLayout, response);
+
+                    getOptionSets(xResponse, getSXLayout);
+                };
+
+                // execute
                 response = response || ns.app.response;
 
-                xLayout = getXLayout(layout);
-                xResponse = service.response.aggregate.getExtendedResponse(xLayout, response);
-                xLayout = getSXLayout(layout, xLayout, xResponse);
-
-                if (!xLayout) {
-                    web.mask.hide(ns.app.centerRegion);
-                    return;
-                }
-
-                web.mask.show(ns.app.centerRegion, 'Error while rendering chart..');
-                
-                chart = web.report.aggregate.createChart(layout, xLayout, xResponse, ns.app.centerRegion);
-
-                //if (layout.sorting) {
-                    //xResponse = web.report.aggregate.sort(xLayout, xResponse, xColAxis);
-                    //xLayout = getSXLayout(xLayout, xResponse);
-                    //table = getHtml(xLayout, xResponse);
-                //}
-
-                // timing
-                ns.app.dateRender = new Date();
-
-                ns.app.centerRegion.update();
-                ns.app.centerRegion.removeAll(true);
-				ns.app.centerRegion.add(chart);
-
-                // timing
-                ns.app.dateTotal = new Date();
-
-                // after render
-                ns.app.layout = layout;
-                ns.app.xLayout = xLayout;
-                ns.app.response = response;
-                ns.app.xResponse = xResponse;
-                ns.app.chart = chart;
-                
-                if (NS.isSessionStorage) {
-                    web.storage.session.set(layout, 'eventchart');
-                }
-
-                ns.app.accordion.setGui(layout, xLayout, response, isUpdateGui); //table);
-
-                web.mask.hide(ns.app.centerRegion);
-                
-                if (NS.isDebug) {
-                    console.log("DATA", (ns.app.dateCreate - ns.app.dateData) / 1000);
-                    console.log("CREATE", (ns.app.dateRender - ns.app.dateCreate) / 1000);
-                    console.log("RENDER", (ns.app.dateTotal - ns.app.dateRender) / 1000);
-                    console.log("TOTAL", (ns.app.dateTotal - ns.app.dateData) / 1000);
-                    console.log("layout", layout);
-                    console.log("response", response);
-                    console.log("xResponse", xResponse);
-                    console.log("xLayout", xLayout);
-                    console.log("core", ns.core);
-                    console.log("app", ns.app);
-                }
-				//};
-
+                getXResponse();
 			};
 		}());
 	};
@@ -6027,7 +6102,7 @@
             category,
             filter,
             layout,
-            
+
 			accordion,
 			westRegion,
             layoutButton,
@@ -6573,7 +6648,7 @@
 				}
 			}
 		});
-        
+
 		defaultButton = Ext.create('Ext.button.Button', {
 			text: NS.i18n.chart,
 			iconCls: 'ns-button-icon-chart',
@@ -6743,7 +6818,7 @@
 			listeners: {
 				render: function() {
 					ns.app.viewport = this;
-                    
+
                     var initEl = document.getElementById('init');
                     initEl.parentNode.removeChild(initEl);
 

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/core.js	2014-10-29 10:41:44 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/core.js	2014-10-30 16:29:02 +0000
@@ -755,6 +755,25 @@
                 return uniqueItems;
             };
 
+            support.prototype.array.getObjectMap = function(array, idProperty, nameProperty, namePrefix) {
+                if (!(Ext.isArray(array) && array.length)) {
+                    return {};
+                }
+
+                var o = {};
+                idProperty = idProperty || 'id';
+                nameProperty = nameProperty || 'name';
+                namePrefix = namePrefix || '';
+
+                for (var i = 0, obj; i < array.length; i++) {
+                    obj = array[i];
+
+                    o[namePrefix + obj[idProperty]] = obj[nameProperty];
+                }
+
+                return o;
+            };
+
 				// object
 			support.prototype.object = {};
 
@@ -1773,6 +1792,7 @@
                 names = response.metaData.names;
                 names[emptyId] = emptyId;
 
+                response.metaData.optionNames = {};
 				response.nameHeaderMap = {};
 				response.idValueMap = {};
 
@@ -2452,7 +2472,7 @@
                     else {
                         for (var i = 0, id, name, mxl, ids; i < store.rangeFields.length; i++) {
                             id = failSafeColumnIdMap[store.rangeFields[i]];
-                            name = xResponse.metaData.names[id];
+                            name = xResponse.metaData.optionNames[id] || xResponse.metaData.names[id];
 
                             if (Ext.isObject(xLayout.legend) && xLayout.legend.maxLength) {
                                 var mxl = parseInt(xLayout.legend.maxLength);
@@ -2787,7 +2807,7 @@
                                 legend = this.legend,
                                 legendCenterX,
                                 titleX;
-                                
+
                             if (this.legend.position === 'top') {
                                 legendCenterX = legend.x + (legend.width / 2);
                                 titleX = titleWidth ? legendCenterX - (titleWidth / 2) : titleXFallback;