← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17210: ER using indexeddb for option sets.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 17210 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-10-22 15:31:52 +0200
message:
  ER 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-mapping/scripts/core.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/styles/style.css
  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
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/styles/style.css


--
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-08-31 15:21:11 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/index.html	2014-10-21 16:30:56 +0000
@@ -23,7 +23,12 @@
     <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/calendars/jquery.calendars.picker.min.js"></script>
     <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.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>
 </body>

=== 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-14 15:40:58 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js	2014-10-22 13:27:48 +0000
@@ -486,37 +486,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.er.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) {
@@ -554,20 +534,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];
 
@@ -596,15 +574,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();
                     }
                 });
 
@@ -7402,6 +7373,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.er.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);
+                                                            }
+                                                        });
+                                                    }
+                                                };
+
+                                                checkOptionSet = 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++) {
+                                                        checkOptionSet(optionSets[i]);
+                                                    }
+                                                });
+                                            }
+                                        });
+
                                         for (var i = 0; i < requests.length; i++) {
                                             Ext.Ajax.request(requests[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-16 13:53:02 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/core.js	2014-10-22 13:04:50 +0000
@@ -12,6 +12,16 @@
 	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 = {},
             api = {},

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.js	2014-10-15 11:27:39 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/core.js	2014-10-21 16:30:56 +0000
@@ -705,7 +705,7 @@
                 pointRadius: 8,
                 labelAlign: 'cr',
                 labelYOffset: 13,
-                fontFamily: 'arial,sans-serif,roboto,helvetica neue,helvetica,consolas'
+                fontFamily: '"Arial","Sans-serif","Roboto","Helvetica","Consolas"'
 			},
 			select = {
 				fillOpacity: 0.9,

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/styles/style.css'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/styles/style.css	2014-10-17 11:15:46 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/styles/style.css	2014-10-21 16:30:56 +0000
@@ -53,7 +53,7 @@
 .x-form-item-label,
 .x-window-header-text-default {
     font-size: 11px;
-	font-family: arial,sans-serif,ubuntu,consolas;
+	font-family: 'Arial','Sans-serif','Roboto','Helvetica','Consolas';
 }
 
 body {

=== 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	2014-10-20 13:12:14 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js	2014-10-21 16:30:56 +0000
@@ -1949,7 +1949,7 @@
 
 				svg = Ext.get(svg[0]);
 				svg = svg.parent().dom.innerHTML;
-console.log(svg);
+
 				Ext.query('#svgField')[0].value = svg;
 				Ext.query('#filenameField')[0].value = 'test';
 

=== 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	2014-10-20 14:33:20 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/core.js	2014-10-21 16:30:56 +0000
@@ -212,7 +212,7 @@
             conf.chart = {
                 style: {
                     inset: 30,
-                    fontFamily: 'Arial,Sans-serif,Helvetica,Helvetica Neue,Lucida Grande,Ubuntu'
+                    fontFamily: 'Arial,Sans-serif,Roboto,Helvetica,Consolas'
                 },
                 theme: {
                     dv1: ['#94ae0a', '#1d5991', '#a61120', '#ff8809', '#7c7474', '#a61187', '#ffd13e', '#24ad9a', '#a66111', '#414141', '#4500c4', '#1d5700']

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/styles/style.css'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/styles/style.css	2014-10-16 13:55:24 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/styles/style.css	2014-10-21 16:30:56 +0000
@@ -49,7 +49,7 @@
 .x-form-item-label,
 .x-window-header-text-default {
     font-size: 11px;
-	font-family: arial,sans-serif,ubuntu,consolas;
+	font-family: 'Arial','Sans-serif','Roboto','Helvetica','Consolas';
 }
 
 body {