dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33774
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17298: ER option code/name support implemented.
Merge authors:
Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 17298 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-10-28 11:22:06 +0100
message:
ER option code/name support 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
--
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-23 09:11:36 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js 2014-10-27 14:40:23 +0000
@@ -6335,86 +6335,135 @@
map['aggregated_values'] = function() {
var xLayout,
+ xResponse,
xColAxis,
xRowAxis,
table,
- getHtml,
- getXLayout = service.layout.getExtendedLayout,
- getSXLayout = service.layout.getSyncronizedXLayout,
- getXResponse = service.response.aggregate.getExtendedResponse,
- getXAxis = service.layout.getExtendedAxis;
-
+ getSXLayout,
+ getXResponse,
+ getTable;
+
+ getTable = function() {
+ var getHtml = function(xLayout, xResponse) {
+ xColAxis = service.layout.getExtendedAxis(xLayout, 'col');
+ xRowAxis = service.layout.getExtendedAxis(xLayout, 'row');
+
+ return web.report.aggregate.getHtml(xLayout, xResponse, xColAxis, xRowAxis);
+ };
+
+ table = getHtml(xLayout, xResponse);
+
+ if (table.tdCount > 20000 || (layout.hideEmptyRows && table.tdCount > 10000)) {
+ alert('Table has too many cells. Please reduce the table and try again.');
+ web.mask.hide(ns.app.centerRegion);
+ return;
+ }
+
+ if (layout.sorting) {
+ xResponse = web.report.aggregate.sort(xLayout, xResponse, xColAxis);
+ xLayout = service.layout.getSyncronizedXLayout(layout, xLayout, xResponse);
+ table = getHtml(xLayout, xResponse);
+ }
+
+ web.mask.show(ns.app.centerRegion, 'Rendering table..');
+
+ // timing
+ ns.app.dateRender = new Date();
+
+ ns.app.centerRegion.removeAll(true);
+ ns.app.centerRegion.update(table.html);
+
+ // 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.xColAxis = xColAxis;
+ ns.app.xRowAxis = xRowAxis;
+ ns.app.uuidDimUuidsMap = table.uuidDimUuidsMap;
+ ns.app.uuidObjectMap = Ext.applyIf((xColAxis ? xColAxis.uuidObjectMap : {}), (xRowAxis ? xRowAxis.uuidObjectMap : {}));
+
+ if (NS.isSessionStorage) {
+ //web.events.setValueMouseHandlers(layout, response || xResponse, ns.app.uuidDimUuidsMap, ns.app.uuidObjectMap);
+ web.events.setColumnHeaderMouseHandlers(layout, response, xResponse);
+ web.storage.session.set(layout, 'eventtable');
+ }
+
+ ns.app.accordion.setGui(layout, xLayout, response, isUpdateGui, table);
+
+ web.mask.hide(ns.app.centerRegion);
+
+ if (NS.isDebug) {
+ console.log("Number of cells", table.tdCount);
+ 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);
+
+ getTable();
+ };
+
+ getXResponse = function() {
+ xLayout = service.layout.getExtendedLayout(layout);
+ xResponse = service.response.aggregate.getExtendedResponse(xLayout, response);
+
+ //get option sets
+ 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 = {},
+ fn;
+
+ fn = function() {
+ if (++callbacks === optionSetHeaders.length) {
+ //Ext.apply(xResponse.metaData.names, optionMap);
+ xResponse.metaData.optionNames = optionMap;
+ getSXLayout();
+ }
+ };
+
+ // execute
+ for (var i = 0, header; i < optionSetHeaders.length; i++) {
+ header = optionSetHeaders[i];
+ optionSetId = header.optionSet;
+ dataElementId = header.name;
+
+ dhis2.er.store.get('optionSets', optionSetId).done( function(obj) {
+ Ext.apply(optionMap, support.prototype.array.getObjectMap(obj.options, 'code', 'name', dataElementId));
+ fn();
+ });
+ }
+ }
+ else {
+ getSXLayout();
+ }
+ };
+
+ // execute
response = response || ns.app.response;
- getHtml = function(xLayout, xResponse) {
- xColAxis = getXAxis(xLayout, 'col');
- xRowAxis = getXAxis(xLayout, 'row');
-
- return web.report.aggregate.getHtml(xLayout, xResponse, xColAxis, xRowAxis);
- };
-
- xLayout = getXLayout(layout);
- xResponse = service.response.aggregate.getExtendedResponse(xLayout, response);
- xLayout = getSXLayout(layout, xLayout, xResponse);
-
- table = getHtml(xLayout, xResponse);
-
- if (table.tdCount > 20000 || (layout.hideEmptyRows && table.tdCount > 10000)) {
- alert('Table has too many cells. Please reduce the table and try again.');
- web.mask.hide(ns.app.centerRegion);
- return;
- }
-
- if (layout.sorting) {
- xResponse = web.report.aggregate.sort(xLayout, xResponse, xColAxis);
- xLayout = getSXLayout(layout, xLayout, xResponse);
- table = getHtml(xLayout, xResponse);
- }
-
- web.mask.show(ns.app.centerRegion, 'Rendering table..');
-
- // timing
- ns.app.dateRender = new Date();
-
- ns.app.centerRegion.removeAll(true);
- ns.app.centerRegion.update(table.html);
-
- // 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.xColAxis = xColAxis;
- ns.app.xRowAxis = xRowAxis;
- ns.app.uuidDimUuidsMap = table.uuidDimUuidsMap;
- ns.app.uuidObjectMap = Ext.applyIf((xColAxis ? xColAxis.uuidObjectMap : {}), (xRowAxis ? xRowAxis.uuidObjectMap : {}));
-
- if (NS.isSessionStorage) {
- //web.events.setValueMouseHandlers(layout, response || xResponse, ns.app.uuidDimUuidsMap, ns.app.uuidObjectMap);
- web.events.setColumnHeaderMouseHandlers(layout, response, xResponse);
- web.storage.session.set(layout, 'eventtable');
- }
-
- ns.app.accordion.setGui(layout, xLayout, response, isUpdateGui, table);
-
- web.mask.hide(ns.app.centerRegion);
-
- if (NS.isDebug) {
- console.log("Number of cells", table.tdCount);
- 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();
};
map['individual_cases'] = function() {
@@ -7193,6 +7242,8 @@
}
};
+ init.optionSetStorage = {};
+
// requests
Ext.Ajax.request({
url: 'manifest.webapp',
@@ -7395,12 +7446,25 @@
url = '',
callbacks = 0,
checkOptionSet,
- updateStore;
+ updateStore,
+ createStorage;
+
+ createStorage = function() {
+ store.getAll('optionSets').done( function(array) {
+ for (var i = 0, optionSet; i < array.length; i++) {
+ optionSet = array[i];
+
+ init.optionSetStorage[optionSet.id] = optionSet;
+ }
+
+ fn();
+ });
+ };
updateStore = function() {
if (++callbacks === optionSets.length) {
if (!ids.length) {
- fn();
+ createStorage();
return;
}
@@ -7413,7 +7477,7 @@
success: function(r) {
var sets = Ext.decode(r.responseText).optionSets;
- store.setAll('optionSets', sets).done(fn);
+ store.setAll('optionSets', sets).done(createStorage);
}
});
}
=== 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-22 15:25:22 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/core.js 2014-10-27 15:13:59 +0000
@@ -673,7 +673,85 @@
return uniqueItems;
};
- // object
+ support.prototype.array.getNameById = function(array, value, idProperty, nameProperty) {
+ if (!(Ext.isArray(array) && value)) {
+ return;
+ }
+
+ idProperty = idProperty || 'id';
+ nameProperty = nameProperty || 'name';
+
+ for (var i = 0; i < array.length; i++) {
+ if (array[i][idProperty] === value) {
+ return array[i][nameProperty];
+ }
+ }
+
+ return;
+ };
+
+ support.prototype.array.cleanFalsy = function(array) {
+ if (!Ext.isArray(array)) {
+ return [];
+ }
+
+ if (!array.length) {
+ return array;
+ }
+
+ for (var i = 0; i < array.length; i++) {
+ array[i] = array[i] || null;
+ }
+
+ var a = Ext.clean(array);
+ array = null;
+
+ return a;
+ };
+
+ support.prototype.array.pluckIf = function(array, pluckProperty, valueProperty, value, type) {
+ var a = [];
+
+ if (!(Ext.isArray(array) && array.length)) {
+ return a;
+ }
+
+ pluckProperty = pluckProperty || 'name';
+ valueProperty = valueProperty || pluckProperty;
+
+ for (var i = 0; i < array.length; i++) {
+ if (Ext.isDefined(type) && typeof array[i][valueProperty] === type) {
+ a.push(array[i][pluckProperty]);
+ }
+ else if (Ext.isDefined(value) && array[i][valueProperty] === value) {
+ a.push(array[i][pluckProperty]);
+ }
+ }
+
+ return a;
+ };
+
+ 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] + " WORKS";
+ }
+
+ return o;
+ };
+
+
+ // object
support.prototype.object = {};
support.prototype.object.getLength = function(object, suppressWarning) {
@@ -893,7 +971,7 @@
return name;
}
- name += metaData.names[id];
+ name += metaData.names[id] || metaData.optionNames[id];
return name;
};
@@ -1166,76 +1244,70 @@
return headerNames;
};
- return function() {
-
- // items
- for (var i = 0, dim, header; i < dimensions.length; i++) {
- dim = dimensions[i];
- dim.items = [];
- header = xResponse.nameHeaderMap[dim.dimension];
-
- if (header) {
- for (var j = 0, id; j < header.ids.length; j++) {
- id = header.ids[j];
-
- dim.items.push({
- id: id,
- name: xResponse.metaData.names[id] || id
- });
- }
- }
- }
-
- // restore order for options
- for (var i = 0, orgDim; i < originalDimensions.length; i++) {
- orgDim = originalDimensions[i];
-
- // if sorting and row dim, dont restore order
- if (layout.sorting && Ext.Array.contains(xLayout.rowDimensionNames, orgDim.dimension)) {
- continue;
+ // items
+ for (var i = 0, dim, header; i < dimensions.length; i++) {
+ dim = dimensions[i];
+ dim.items = [];
+ header = xResponse.nameHeaderMap[dim.dimension];
+ optionMap = {};
+
+ if (header) {
+ for (var j = 0, id; j < header.ids.length; j++) {
+ id = header.ids[j];
+// TODO, items used?
+ dim.items.push({
+ id: id,
+ name: xResponse.metaData.optionNames[id] || xResponse.metaData.names[id] || id
+ });
}
-
- if (Ext.isString(orgDim.filter)) {
- var a = orgDim.filter.split(':');
-
- if (a[0] === 'IN' && a.length > 1 && Ext.isString(a[1])) {
- var options = a[1].split(';'),
+ }
+ }
+
+ // restore order for options
+ for (var i = 0, orgDim; i < originalDimensions.length; i++) {
+ orgDim = originalDimensions[i];
+
+ // if sorting and row dim, dont restore order
+ if (layout.sorting && Ext.Array.contains(xLayout.rowDimensionNames, orgDim.dimension)) {
+ continue;
+ }
+
+ if (Ext.isString(orgDim.filter)) {
+ var a = orgDim.filter.split(':');
+
+ if (a[0] === 'IN' && a.length > 1 && Ext.isString(a[1])) {
+ var options = a[1].split(';');
+
+ for (var j = 0, dim, items; j < dimensions.length; j++) {
+ dim = dimensions[j];
+
+ if (dim.dimension === orgDim.dimension && dim.items && dim.items.length) {
items = [];
- for (var j = 0, dim; j < dimensions.length; j++) {
- dim = dimensions[j];
-
- if (dim.dimension === orgDim.dimension && dim.items && dim.items.length) {
- var items = [];
-
- for (var k = 0, option; k < options.length; k++) {
- option = options[k];
-
- for (var l = 0, item; l < dim.items.length; l++) {
- item = dim.items[l];
-
- if (item.name === option) {
- items.push(item);
- }
+ for (var k = 0, option; k < options.length; k++) {
+ option = options[k];
+
+ for (var l = 0, item; l < dim.items.length; l++) {
+ item = dim.items[l];
+ if (item.id === option || item.id === (dim.dimension + option)) {
+ items.push(item);
}
}
-
- dim.items = items;
}
+
+ dim.items = items;
}
}
}
}
-
- // Re-layout
- layout = api.layout.Layout(xLayout);
-
- if (layout) {
- return service.layout.getExtendedLayout(layout);
- }
-
- return null;
- }();
+ }
+
+ // Re-layout
+ layout = api.layout.Layout(xLayout);
+
+ if (layout) {
+ return service.layout.getExtendedLayout(layout);
+ }
};
service.layout.getExtendedAxis = function(xLayout, type) {