dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33652
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17214: EV using indexeddb for option sets.
Merge authors:
Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 17214 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-10-22 17:27:48 +0200
message:
EV using indexeddb for option sets.
modified:
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/index.html
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/index.html
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.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/index.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/index.html 2014-10-21 16:30:56 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/index.html 2014-10-22 15:25:22 +0000
@@ -24,10 +24,10 @@
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.util.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/date.js"></script>
+ <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.ss.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.memory.js"></script>
- <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.js"></script>
<script src="scripts/core.js"></script>
<script src="scripts/app.js"></script>
=== 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-22 13:27:48 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js 2014-10-22 15:25:22 +0000
@@ -7238,6 +7238,15 @@
init.namePropertyUrl = namePropertyUrl;
+ // dhis2
+ dhis2.util.namespace('dhis2.er');
+
+ dhis2.er.store = dhis2.er.store || new dhis2.storage.Store({
+ name: 'dhis2',
+ adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
+ objectStores: ['optionSets']
+ });
+
// calendar
(function() {
var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js',
@@ -7377,7 +7386,7 @@
requests.push({
url: contextPath + '/api/optionSets.json?fields=id,version&paging=false',
success: function(r) {
- var optionSets = Ext.decode(r.responseText).optionSets,
+ var optionSets = Ext.decode(r.responseText).optionSets || [],
store = dhis2.er.store,
ids = [],
url = '',
@@ -7406,7 +7415,7 @@
}
};
- checkOptionSet = function(optionSet) {
+ registerOptionSet = function(optionSet) {
store.get('optionSets', optionSet.id).done( function(obj) {
if (!Ext.isObject(obj) || obj.version !== optionSet.version) {
ids.push(optionSet.id);
@@ -7418,7 +7427,7 @@
store.open().done( function() {
for (var i = 0; i < optionSets.length; i++) {
- checkOptionSet(optionSets[i]);
+ registerOptionSet(optionSets[i]);
}
});
}
=== 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 13:04:50 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/core.js 2014-10-22 15:25:22 +0000
@@ -12,15 +12,6 @@
NS.isDebug = false;
NS.isSessionStorage = ('sessionStorage' in window && window['sessionStorage'] !== null);
- // dhis2
- dhis2.util.namespace('dhis2.er');
-
- dhis2.er.store = dhis2.er.store || new dhis2.storage.Store({
- name: 'dhis2',
- adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
- objectStores: ['optionSets']
- });
-
// core
NS.getCore = function(init) {
var conf = {},
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/index.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/index.html 2014-08-31 15:21:11 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/index.html 2014-10-22 15:25:22 +0000
@@ -29,6 +29,11 @@
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.util.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/date.js"></script>
+ <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.js"></script>
+ <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js"></script>
+ <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.ss.js"></script>
+ <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.memory.js"></script>
+
<script type="text/javascript" src="../dhis-web-commons/javascripts/simpleRegression.js"></script>
<script type="text/javascript" src="scripts/core.js"></script>
<script type="text/javascript" src="scripts/app.js"></script>
=== 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-14 15:40:58 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js 2014-10-22 15:25:22 +0000
@@ -485,37 +485,17 @@
fields: [idProperty, 'name'],
data: [],
loadOptionSet: function(optionSetId, key, pageSize) {
- var store = this,
- params = {};
+ var store = this;
optionSetId = optionSetId || container.dataElement.optionSet.id;
-
- //if (key) {
- //params['key'] = key;
- //}
-
- params['max'] = pageSize || 15;
-
- Ext.Ajax.request({
- url: ns.core.init.contextPath + '/api/optionSets/' + optionSetId + '.json?fields=options[' + idProperty + ',' + nameProperty + ']',
- params: params,
- disableCaching: false,
- success: function(r) {
- var options = Ext.decode(r.responseText).options,
- data = [];
-
- for (var i = 0; i < options.length; i++) {
- if (container.valueStore.findExact(idProperty, options[i][idProperty]) === -1) {
- data.push(options[i]);
- }
- }
-
- store.removeAll();
- store.loadData(data);
-
- container.triggerCmp.storage = Ext.clone(options);
- }
- });
+ pageSize = pageSize || 100;
+
+ dhis2.ev.store.get('optionSets', optionSetId).done( function(obj) {
+ if (Ext.isObject(obj) && Ext.isArray(obj.options) && obj.options.length) {
+ store.removeAll();
+ store.loadData(obj.options.slice(0, pageSize));
+ }
+ });
},
listeners: {
datachanged: function(s) {
@@ -553,20 +533,18 @@
},
store: this.searchStore,
listeners: {
- keyup: {
- fn: function() {
- var value = this.getValue(),
- optionSetId = container.dataElement.optionSet.id;
-
- // search
- container.searchStore.loadOptionSet(optionSetId, value);
-
- // trigger
- if (!value || (Ext.isString(value) && value.length === 1)) {
- container.triggerCmp.setDisabled(!!value);
- }
- }
- },
+ keyup: function() {
+ var value = this.getValue(),
+ optionSetId = container.dataElement.optionSet.id;
+
+ // search
+ container.searchStore.loadOptionSet(optionSetId, value);
+
+ // trigger
+ if (!value || (Ext.isString(value) && value.length === 1)) {
+ container.triggerCmp.setDisabled(!!value);
+ }
+ },
select: function() {
var id = Ext.Array.from(this.getValue())[0];
@@ -595,15 +573,8 @@
disabledCls: 'ns-button-combotrigger-disabled',
width: 18,
height: 22,
- storage: [],
handler: function(b) {
- if (b.storage.length) {
- container.searchStore.removeAll();
- container.searchStore.add(Ext.clone(b.storage));
- }
- else {
- container.searchStore.loadOptionSet();
- }
+ container.searchStore.loadOptionSet();
}
});
@@ -6906,6 +6877,15 @@
init.namePropertyUrl = namePropertyUrl;
+ // dhis2
+ dhis2.util.namespace('dhis2.ev');
+
+ dhis2.ev.store = dhis2.ev.store || new dhis2.storage.Store({
+ name: 'dhis2',
+ adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
+ objectStores: ['optionSets']
+ });
+
// calendar
(function() {
var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js',
@@ -7041,6 +7021,57 @@
}
});
+ // option sets
+ requests.push({
+ url: contextPath + '/api/optionSets.json?fields=id,version&paging=false',
+ success: function(r) {
+ var optionSets = Ext.decode(r.responseText).optionSets || [],
+ store = dhis2.ev.store,
+ ids = [],
+ url = '',
+ callbacks = 0,
+ checkOptionSet,
+ updateStore;
+
+ updateStore = function() {
+ if (++callbacks === optionSets.length) {
+ if (!ids.length) {
+ fn();
+ }
+
+ for (var i = 0; i < ids.length; i++) {
+ url += '&filter=id:eq:' + ids[i];
+ }
+
+ Ext.Ajax.request({
+ url: contextPath + '/api/optionSets.json?fields=id,name,version,options[code,name]&paging=false' + url,
+ success: function(r) {
+ var sets = Ext.decode(r.responseText).optionSets;
+
+ store.setAll('optionSets', sets).done(fn);
+ }
+ });
+ }
+ };
+
+ registerOptionSet = function(optionSet) {
+ store.get('optionSets', optionSet.id).done( function(obj) {
+ if (!Ext.isObject(obj) || obj.version !== optionSet.version) {
+ ids.push(optionSet.id);
+ }
+
+ updateStore();
+ });
+ };
+
+ store.open().done( function() {
+ for (var i = 0; i < optionSets.length; i++) {
+ registerOptionSet(optionSets[i]);
+ }
+ });
+ }
+ });
+
for (var i = 0; i < requests.length; i++) {
Ext.Ajax.request(requests[i]);
}