dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37114
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18981: PT DV filter dynamic dimension items.
Merge authors:
Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 18981 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-04-22 14:20:29 +0200
message:
PT DV filter dynamic dimension items.
modified:
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-visualizer/scripts/app.js
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-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-pivot/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js 2015-04-16 08:51:08 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js 2015-04-22 12:10:13 +0000
@@ -4984,50 +4984,89 @@
this.isPending = false;
dataSearch.hideFilter();
},
+ storage: {},
+ addToStorage: function(dimensionId, filter, data) {
+ filter = 'cache_' + (Ext.isString(filter) || Ext.isNumber(filter) ? filter : '');
+
+ if (!dimensionId) {
+ return;
+ }
+
+ if (!this.storage.hasOwnProperty(dimensionId)) {
+ this.storage[dimensionId] = {};
+ }
+
+ if (!this.storage[dimensionId][filter]) {
+ this.storage[dimensionId][filter] = data;
+ }
+ },
+ getFromStorage: function(dimensionId, filter) {
+ filter = 'cache_' + (Ext.isString(filter) || Ext.isNumber(filter) ? filter : '');
+
+ if (this.storage.hasOwnProperty(dimensionId)) {
+ if (this.storage[dimensionId].hasOwnProperty(filter)) {
+ return this.storage[dimensionId][filter];
+ }
+ }
+
+ return;
+ },
loadPage: function(filter, append, noPaging, fn) {
var store = this,
params = {},
- path;
+ path,
+ cacheData;
filter = filter || indicatorFilter.getValue() || null;
- if (!append) {
- this.lastPage = null;
- this.nextPage = 1;
- }
-
- if (store.nextPage === store.lastPage) {
- return;
- }
-
- path = '/dimensions/' + dimension.id + '/items.json' + (filter ? '?filter=name:like:' + filter : '');
-
- if (noPaging) {
- params.paging = false;
- }
- else {
- params.page = store.nextPage;
- params.pageSize = 50;
- }
-
- store.isPending = true;
- ns.core.web.mask.show(available.boundList);
-
- Ext.Ajax.request({
- url: ns.core.init.contextPath + '/api' + path,
- params: params,
- success: function(r) {
- var response = Ext.decode(r.responseText),
- data = response.items || [],
- pager = response.pager;
-
- store.loadStore(data, pager, append, fn);
- },
- callback: function() {
- store.isPending = false;
- ns.core.web.mask.hide(available.boundList);
- }
- });
+ // check session cache
+ cacheData = store.getFromStorage(dimension.id, filter);
+
+ if (!append && cacheData) {
+ store.loadStore(cacheData, {}, append, fn);
+ }
+ else {
+ if (!append) {
+ this.lastPage = null;
+ this.nextPage = 1;
+ }
+
+ if (store.nextPage === store.lastPage) {
+ return;
+ }
+
+ path = '/dimensions/' + dimension.id + '/items.json' + (filter ? '?filter=name:like:' + filter : '');
+
+ if (noPaging) {
+ params.paging = false;
+ }
+ else {
+ params.page = store.nextPage;
+ params.pageSize = 50;
+ }
+
+ store.isPending = true;
+ ns.core.web.mask.show(available.boundList);
+
+ Ext.Ajax.request({
+ url: ns.core.init.contextPath + '/api' + path,
+ params: params,
+ success: function(r) {
+ var response = Ext.decode(r.responseText),
+ data = response.items || [],
+ pager = response.pager;
+
+ // add to session cache
+ store.addToStorage(dimension.id, filter, data);
+
+ store.loadStore(data, pager, append, fn);
+ },
+ callback: function() {
+ store.isPending = false;
+ ns.core.web.mask.hide(available.boundList);
+ }
+ });
+ }
},
loadStore: function(data, pager, append, fn) {
pager = pager || {};
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js 2015-04-12 20:00:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js 2015-04-22 12:10:13 +0000
@@ -5162,52 +5162,91 @@
this.lastPage = null;
this.nextPage = 1;
this.isPending = false;
- //indicatorSearch.hideFilter();
+ dataSearch.hideFilter();
},
+ storage: {},
+ addToStorage: function(dimensionId, filter, data) {
+ filter = 'cache_' + (Ext.isString(filter) || Ext.isNumber(filter) ? filter : '');
+
+ if (!dimensionId) {
+ return;
+ }
+
+ if (!this.storage.hasOwnProperty(dimensionId)) {
+ this.storage[dimensionId] = {};
+ }
+
+ if (!this.storage[dimensionId][filter]) {
+ this.storage[dimensionId][filter] = data;
+ }
+ },
+ getFromStorage: function(dimensionId, filter) {
+ filter = 'cache_' + (Ext.isString(filter) || Ext.isNumber(filter) ? filter : '');
+
+ if (this.storage.hasOwnProperty(dimensionId)) {
+ if (this.storage[dimensionId].hasOwnProperty(filter)) {
+ return this.storage[dimensionId][filter];
+ }
+ }
+
+ return;
+ },
loadPage: function(filter, append, noPaging, fn) {
var store = this,
params = {},
- path;
+ path,
+ cacheData;
filter = filter || indicatorFilter.getValue() || null;
- if (!append) {
- this.lastPage = null;
- this.nextPage = 1;
- }
-
- if (store.nextPage === store.lastPage) {
- return;
- }
-
- path = '/dimensions/' + dimension.id + '/items.json' + (filter ? '?filter=name:like:' + filter : '');
-
- if (noPaging) {
- params.paging = false;
- }
- else {
- params.page = store.nextPage;
- params.pageSize = 50;
- }
-
- store.isPending = true;
- ns.core.web.mask.show(available.boundList);
-
- Ext.Ajax.request({
- url: ns.core.init.contextPath + '/api' + path,
- params: params,
- success: function(r) {
- var response = Ext.decode(r.responseText),
- data = response.items || [],
- pager = response.pager;
-
- store.loadStore(data, pager, append, fn);
- },
- callback: function() {
- store.isPending = false;
- ns.core.web.mask.hide(available.boundList);
- }
- });
+ // check session cache
+ cacheData = store.getFromStorage(dimension.id, filter);
+
+ if (!append && cacheData) {
+ store.loadStore(cacheData, {}, append, fn);
+ }
+ else {
+ if (!append) {
+ this.lastPage = null;
+ this.nextPage = 1;
+ }
+
+ if (store.nextPage === store.lastPage) {
+ return;
+ }
+
+ path = '/dimensions/' + dimension.id + '/items.json' + (filter ? '?filter=name:like:' + filter : '');
+
+ if (noPaging) {
+ params.paging = false;
+ }
+ else {
+ params.page = store.nextPage;
+ params.pageSize = 50;
+ }
+
+ store.isPending = true;
+ ns.core.web.mask.show(available.boundList);
+
+ Ext.Ajax.request({
+ url: ns.core.init.contextPath + '/api' + path,
+ params: params,
+ success: function(r) {
+ var response = Ext.decode(r.responseText),
+ data = response.items || [],
+ pager = response.pager;
+
+ // add to session cache
+ store.addToStorage(dimension.id, filter, data);
+
+ store.loadStore(data, pager, append, fn);
+ },
+ callback: function() {
+ store.isPending = false;
+ ns.core.web.mask.hide(available.boundList);
+ }
+ });
+ }
},
loadStore: function(data, pager, append, fn) {
pager = pager || {};
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/core.js 2015-04-22 09:10:45 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/core.js 2015-04-22 12:10:13 +0000
@@ -1370,7 +1370,7 @@
support.prototype.number.prettyPrint = function(number, separator) {
separator = separator || 'space';
- if (!number) {
+ if (!(Ext.isNumber(number) || Ext.isString(number))) {
return;
}
@@ -1540,18 +1540,18 @@
dimensionNameIdsMap: {},
// for param string
- dimensionNameSortedIdsMap: {}
+ dimensionNameSortedIdsMap: {},
// sort table by column
//sortableIdObjects: []
+
+ dimensionNameAxisMap: {}
};
Ext.applyIf(xLayout, layout);
// columns, rows, filters
if (layout.columns) {
- //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];
items = dim.items;
@@ -1559,13 +1559,11 @@
xDim.dimension = dim.dimension;
xDim.objectName = dim.dimension;
- xDim.dimensionName = dimConf.objectNameMap.hasOwnProperty(dim.dimension) ? dimConf.objectNameMap[dim.dimension].dimensionName || dim.dimension : dim.dimension;
-
- xDim.items = [];
- xDim.ids = [];
+ xDim.dimensionName = dimConf.objectNameMap[dim.dimension].dimensionName;
if (items) {
xDim.items = items;
+ xDim.ids = [];
for (var j = 0; j < items.length; j++) {
xDim.ids.push(items[j].id);
@@ -1579,17 +1577,17 @@
xLayout.axisDimensions.push(xDim);
xLayout.axisObjectNames.push(xDim.objectName);
- xLayout.axisDimensionNames.push(dimConf.objectNameMap.hasOwnProperty(xDim.objectName) ? dimConf.objectNameMap[xDim.objectName].dimensionName || xDim.objectName : xDim.objectName);
+ xLayout.axisDimensionNames.push(dimConf.objectNameMap[xDim.objectName].dimensionName);
xLayout.objectNameDimensionsMap[xDim.objectName] = xDim;
xLayout.objectNameItemsMap[xDim.objectName] = xDim.items;
xLayout.objectNameIdsMap[xDim.objectName] = xDim.ids;
+
+ xLayout.dimensionNameAxisMap[xDim.dimensionName] = xLayout.columns;
}
}
if (layout.rows) {
- //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]);
items = dim.items;
@@ -1597,13 +1595,11 @@
xDim.dimension = dim.dimension;
xDim.objectName = dim.dimension;
- xDim.dimensionName = dimConf.objectNameMap.hasOwnProperty(dim.dimension) ? dimConf.objectNameMap[dim.dimension].dimensionName || dim.dimension : dim.dimension;
-
- xDim.items = [];
- xDim.ids = [];
+ xDim.dimensionName = dimConf.objectNameMap[dim.dimension].dimensionName;
if (items) {
xDim.items = items;
+ xDim.ids = [];
for (var j = 0; j < items.length; j++) {
xDim.ids.push(items[j].id);
@@ -1617,17 +1613,17 @@
xLayout.axisDimensions.push(xDim);
xLayout.axisObjectNames.push(xDim.objectName);
- xLayout.axisDimensionNames.push(dimConf.objectNameMap.hasOwnProperty(xDim.objectName) ? dimConf.objectNameMap[xDim.objectName].dimensionName || xDim.objectName : xDim.objectName);
+ xLayout.axisDimensionNames.push(dimConf.objectNameMap[xDim.objectName].dimensionName);
xLayout.objectNameDimensionsMap[xDim.objectName] = xDim;
xLayout.objectNameItemsMap[xDim.objectName] = xDim.items;
xLayout.objectNameIdsMap[xDim.objectName] = xDim.ids;
+
+ xLayout.dimensionNameAxisMap[xDim.dimensionName] = xLayout.rows;
}
}
if (layout.filters) {
- //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];
items = dim.items;
@@ -1635,13 +1631,11 @@
xDim.dimension = dim.dimension;
xDim.objectName = dim.dimension;
- xDim.dimensionName = dimConf.objectNameMap.hasOwnProperty(dim.dimension) ? dimConf.objectNameMap[dim.dimension].dimensionName || dim.dimension : dim.dimension;
-
- xDim.items = [];
- xDim.ids = [];
+ xDim.dimensionName = dimConf.objectNameMap[dim.dimension].dimensionName;
if (items) {
xDim.items = items;
+ xDim.ids = [];
for (var j = 0; j < items.length; j++) {
xDim.ids.push(items[j].id);
@@ -1652,11 +1646,13 @@
xLayout.filterDimensions.push(xDim);
xLayout.filterObjectNames.push(xDim.objectName);
- xLayout.filterDimensionNames.push(dimConf.objectNameMap.hasOwnProperty(xDim.objectName) ? dimConf.objectNameMap[xDim.objectName].dimensionName || xDim.objectName : xDim.objectName);
+ xLayout.filterDimensionNames.push(dimConf.objectNameMap[xDim.objectName].dimensionName);
xLayout.objectNameDimensionsMap[xDim.objectName] = xDim;
xLayout.objectNameItemsMap[xDim.objectName] = xDim.items;
xLayout.objectNameIdsMap[xDim.objectName] = xDim.ids;
+
+ xLayout.dimensionNameAxisMap[xDim.dimensionName] = xLayout.filters;
}
}
@@ -2117,7 +2113,9 @@
idIndexOrder = [];
// idIndexOrder
- for (var i = 0; i < axisDimensionNames.length; i++) {
+ for (var i = 0, dimName, index; i < axisDimensionNames.length; i++) {
+ dimName = axisDimensionNames[i];
+ //index = response.nameHeaderMap.hasOwnProperty(
idIndexOrder.push(response.nameHeaderMap[axisDimensionNames[i]].index);
// If co exists in response and is not added in layout, add co after dx