- // Retrieve all local games (running, completed, imported...)
- // light: do not retrieve moves or clocks (TODO: this is the only usage)
- getAll: function(light, callback) {
- dbOperation((err,db) => {
- let objectStore = db.transaction("games").objectStore("games");
+ // Retrieve (all) running local games
+ getRunning: function(callback) {
+ dbOperation((err, db) => {
+ let objectStore = db
+ .transaction("games", "readonly")
+ .objectStore("games");
+ let index = objectStore.index("score");
+ const range = IDBKeyRange.only("*");
+ let games = [];
+ index.openCursor(range).onsuccess = function(event) {
+ let cursor = event.target.result;
+ if (!cursor) callback(games);
+ else {
+ // If there is still another cursor to go, keep running this code
+ let g = cursor.value;
+ // Do not retrieve moves or clocks (unused in list mode)
+ g.movesCount = g.moves.length;
+ delete g.moves;
+ delete g.clocks;
+ delete g.initime;
+ games.push(g);
+ cursor.continue();
+ }
+ };
+ });
+ },
+
+ // Retrieve completed local games
+ getNext: function(upperDt, callback) {
+ dbOperation((err, db) => {
+ let objectStore = db
+ .transaction("games", "readonly")
+ .objectStore("games");
+ let index = objectStore.index("created");
+ const range = IDBKeyRange.upperBound(upperDt);