]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/commitdiff
Fix the data log in offline server mode
authorTomas Prochazka <tomas.prochazka@cvut.cz>
Tue, 14 Aug 2018 20:11:38 +0000 (22:11 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Wed, 15 Aug 2018 05:34:37 +0000 (07:34 +0200)
Retrieve data JSON in the correct order.
JSON are sorted by the key (date), when they were stored.

templates/main.js

index f945b292cd14f4b767c725c9ae5bd4632f46ce93..561bfa769fb636617e65fd9de4427a852855dbd9 100644 (file)
@@ -17,15 +17,22 @@ function update(id, msg) {
 function loadLocalStorage() {
     if (localStorage) {
         if (localStorage.length) {
+            var entries = [];
             for (var i = 0; i < localStorage.length; i++) {
                 var value = localStorage.getItem(localStorage.key(i));
                 try {
-                    updateRemote(value);
+                    var key = localStorage.key(i);
+                    var value = localStorage.getItem(key);
+                    entries.push({ key: key, value: value });
                 } catch (err) {
                     console.log("no json: " + value)
                 }
             }
             localStorage.clear();
+            entries.sort((entry1, entry2) => { return entry1.key > entry2.key;});
+            for (var i = 0; i < entries.length; i++) {
+                updateRemote(entries[i].value);
+            }
         }
     }
 }