update to pc
This commit is contained in:
File diff suppressed because one or more lines are too long
670
public/js/app.js
670
public/js/app.js
@@ -2386,6 +2386,244 @@ InitPromise.mainPromise = new Promise(function(resolver){
|
||||
InitPromise.mainResolver = resolver;
|
||||
});
|
||||
|
||||
class MyDb {
|
||||
constructor(dbName, version) {
|
||||
let indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
|
||||
this._conn = indexedDB.open(dbName, version);
|
||||
|
||||
let myDB = this;
|
||||
this._conn.onupgradeneeded = function (upgradeEvent) {
|
||||
myDB.upgrade(myDB._conn.result, upgradeEvent.oldVersion, upgradeEvent.newVersion, upgradeEvent);
|
||||
};
|
||||
this.queryPromise = new Promise(function (resolve) {
|
||||
myDB._conn.onsuccess = function (e) {
|
||||
myDB._db = myDB._conn.result;
|
||||
resolve(e);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
openTransaction(name, transactionMode, callback) {
|
||||
let myDb = this;
|
||||
if (typeof transactionMode === 'function' && Helper.isNull(callback)) {
|
||||
callback = transactionMode;
|
||||
transactionMode = "read";
|
||||
}
|
||||
|
||||
this.queryPromise.then(function () {
|
||||
let res = null;
|
||||
try {
|
||||
res = myDb._conn.result.transaction(name, transactionMode);
|
||||
}
|
||||
catch (e) {
|
||||
console.warn(e);
|
||||
res = myDb._conn.result.transaction(name);
|
||||
}
|
||||
callback(res);
|
||||
});
|
||||
}
|
||||
|
||||
openStore(name, transactionMode, callback) {
|
||||
if (typeof transactionMode === 'function' && Helper.isNull(callback)) {
|
||||
callback = transactionMode;
|
||||
transactionMode = "readonly";
|
||||
}
|
||||
this.openTransaction(name, transactionMode, function (t) {
|
||||
callback(t.objectStore(name));
|
||||
});
|
||||
}
|
||||
|
||||
saveObj(obj, objectStore) {
|
||||
let self = this;
|
||||
return new Promise(function (resolve) {
|
||||
self.openStore(objectStore, "readwrite", function (store) {
|
||||
let request = store.put(obj);
|
||||
request.onsuccess = resolve;
|
||||
request.onerror = function (e) {
|
||||
throw {
|
||||
"type": "indexed-db-error",
|
||||
"event": e
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
saveMany(manyObj, objectStore) {
|
||||
let self = this;
|
||||
return new Promise(function (resolve) {
|
||||
self.openStore(objectStore, "readwrite", function (store) {
|
||||
let promises = [];
|
||||
for (let i = 0, n = manyObj.length; i < n; i++) {
|
||||
promises.push(new Promise(function (resolveInner) {
|
||||
let request = store.put(manyObj[i]);
|
||||
request.onsuccess = resolveInner;
|
||||
request.onerror = function (e) {
|
||||
throw {
|
||||
"type": "indexed-db-error",
|
||||
"event": e
|
||||
}
|
||||
};
|
||||
}));
|
||||
}
|
||||
resolve(Promise.all(promises));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
load(key, objectStore) {
|
||||
let self = this;
|
||||
return new Promise(function (resolve) {
|
||||
self.openStore(objectStore, function (store) {
|
||||
let request = store.get(key);
|
||||
request.onsuccess = function (e) {
|
||||
resolve(e.currentTarget.result);
|
||||
};
|
||||
request.onerror = function (e) {
|
||||
console.warn(e);
|
||||
throw {
|
||||
"type": "indexed-db-load-error",
|
||||
"event": e
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
loadAll(objectStore, query, count)
|
||||
{
|
||||
let self = this;
|
||||
return new Promise(function (resolve) {
|
||||
self.openStore(objectStore, function (store) {
|
||||
let request = store.getAll(query, count);
|
||||
request.onsuccess = function (e) {
|
||||
resolve(e.currentTarget.result);
|
||||
};
|
||||
request.onerror = function (e) {
|
||||
console.warn(e);
|
||||
throw {
|
||||
"type": "indexed-db-load-error",
|
||||
"event": e
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
loadMany(index, value, objectStore, limit, direction) {
|
||||
let self = this;
|
||||
return new Promise(function (resolve) {
|
||||
self.openStore(objectStore, function (store) {
|
||||
let indexRequest = store.index(index);
|
||||
indexRequest.onerror = function (e) {
|
||||
throw {
|
||||
"type": "indexed-db-index-error",
|
||||
"event": e
|
||||
}
|
||||
};
|
||||
let request = indexRequest.openCursor(value, direction);
|
||||
request.onerror = function (e) {
|
||||
throw {
|
||||
"type": "indexed-db-index-error",
|
||||
"event": e
|
||||
}
|
||||
};
|
||||
let objects = [];
|
||||
let numberResults = 0;
|
||||
request.onsuccess = function (e) {
|
||||
let cursor = e.target.result;
|
||||
if (cursor) {
|
||||
objects.push(cursor.value);
|
||||
numberResults++;
|
||||
if (Helper.isNull(limit) || numberResults < limit) {
|
||||
cursor.continue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
resolve(objects);
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
remove(id, objectStore) {
|
||||
let self = this;
|
||||
return new Promise(function (resolve) {
|
||||
self.openStore(objectStore, "readwrite", function (store) {
|
||||
let deleteRequest = store.delete(id);
|
||||
deleteRequest.onerror = function (e) {
|
||||
throw {
|
||||
"type": "indexed-db-delete-error",
|
||||
"event": e
|
||||
}
|
||||
};
|
||||
deleteRequest.onsuccess = function (e) {
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
removeMany(ids, objectStore) {
|
||||
let self = this;
|
||||
return new Promise(function (resolve) {
|
||||
self.openStore(objectStore, "readwrite", function (store) {
|
||||
let promises = [];
|
||||
for (let i = 0, n = ids.length; i < n; i++) {
|
||||
let deleteRequest = store.delete(ids[i]);
|
||||
deleteRequest.onerror = function (e) {
|
||||
throw {
|
||||
"type": "indexed-db-delete-error",
|
||||
"event": e
|
||||
}
|
||||
};
|
||||
promises.push(new Promise(function (resolve) {
|
||||
deleteRequest.onsuccess = function () {
|
||||
resolve();
|
||||
};
|
||||
}));
|
||||
}
|
||||
resolve(Promise.all(promises));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
removeWithIndex(index, value, objectStore) {
|
||||
let self = this;
|
||||
return new Promise(function (resolve) {
|
||||
self.openStore(objectStore, "readwrite", function (store) {
|
||||
let indexRequest = store.index(index);
|
||||
indexRequest.onerror = function (e) {
|
||||
throw {
|
||||
"type": "indexed-db-index-error",
|
||||
"event": e
|
||||
}
|
||||
};
|
||||
let request = indexRequest.openCursor(value);
|
||||
request.onerror = function (e) {
|
||||
throw {
|
||||
"type": "indexed-db-index-error",
|
||||
"event": e
|
||||
}
|
||||
};
|
||||
request.onsuccess = function (e) {
|
||||
let cursor = e.target.result;
|
||||
if (cursor) {
|
||||
cursor.delete();
|
||||
cursor.continue();
|
||||
}
|
||||
else {
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
upgrade(db) {
|
||||
};
|
||||
}
|
||||
|
||||
class ShareButton {
|
||||
constructor(deviceType, icon, callback)
|
||||
{
|
||||
@@ -2759,291 +2997,233 @@ SystemSettings.setBasePath("/pwa/wordRotator/public/");
|
||||
Translator.supportedLanguages = ["de", "en"];
|
||||
Translator.markTranslations = false;
|
||||
|
||||
class Segment{
|
||||
constructor(element){
|
||||
this.rotation = 0;
|
||||
this.element = element;
|
||||
class DataManager {
|
||||
static load(url, isCachable, raw) {
|
||||
isCachable = Helper.nonNull(isCachable, false);
|
||||
raw = Helper.nonNull(raw, false);
|
||||
let fullUrl = (isCachable) ? Helper.basePath(DataManager.cachePath + url) : Helper.basePath(DataManager.dataPath + url);
|
||||
return fetch(fullUrl, {"credentials": "same-origin"}).then(function (res) {
|
||||
if (raw) {
|
||||
return res.text();
|
||||
}
|
||||
return res.json();
|
||||
}).catch(function (e) {
|
||||
console.error("error", e);
|
||||
if (!raw) {
|
||||
return {
|
||||
"success": false,
|
||||
"errors": [
|
||||
"not-online"
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
isSolved(){
|
||||
return (this.rotation === 0);
|
||||
}
|
||||
|
||||
rotate(){};
|
||||
static send(url, params) {
|
||||
let fullUrl = Helper.basePath(DataManager.dataPath + url);
|
||||
|
||||
_updateElement(){};
|
||||
if (!(params instanceof FormData)) {
|
||||
let newParams = new FormData();
|
||||
for (let k in params) {
|
||||
newParams.append(k, params[k]);
|
||||
}
|
||||
params = newParams;
|
||||
}
|
||||
|
||||
applyRotations(rotations){
|
||||
return rotations;
|
||||
return fetch(fullUrl, {
|
||||
"credentials": "same-origin",
|
||||
"method": "POST",
|
||||
"body": params
|
||||
}).then(function (res) {
|
||||
return res.json();
|
||||
}).catch(function (e) {
|
||||
console.error("error", e);
|
||||
return {
|
||||
"success": false,
|
||||
"errors": [
|
||||
"not-online"
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getElement()
|
||||
{
|
||||
return this.element;
|
||||
static buildQuery(values) {
|
||||
return Helper.buildQuery(values);
|
||||
}
|
||||
}
|
||||
|
||||
class ParentSegment extends Segment {
|
||||
constructor(element) {
|
||||
super(element);
|
||||
this.children = [];
|
||||
this.class = "rotate-0";
|
||||
}
|
||||
DataManager.dataPath = "data/";
|
||||
DataManager.cachePath = "cached/";
|
||||
|
||||
rotate() {
|
||||
this.rotation += 90;
|
||||
this.rotation %= 360;
|
||||
|
||||
this._updateRotationClass();
|
||||
}
|
||||
|
||||
applyRotations(rotations) {
|
||||
// debugger;
|
||||
this.rotation = rotations[0];
|
||||
rotations.splice(0, 1);
|
||||
for (let i = 0, n = this.children.length; i < n; i++) {
|
||||
rotations = this.children[i].applyRotations(rotations);
|
||||
class SettingsSite extends AbstractSite$1 {
|
||||
constructor(siteManager) {
|
||||
super(siteManager, 'public/html/settings.html', "settings");
|
||||
for (let k in SettingsSite.settingsFragments) {
|
||||
this.addSettingsFragment(k, new SettingsSite.settingsFragments[k](this));
|
||||
}
|
||||
return rotations;
|
||||
this.active = null;
|
||||
}
|
||||
|
||||
isSolved() {
|
||||
for (let i = 0, n = this.children.length; i < n; i++) {
|
||||
if (!this.children[i].isSolved()) {
|
||||
return false;
|
||||
addSettingsFragment(name, settingsFragment) {
|
||||
this.addFragment("#settings-fragments", settingsFragment);
|
||||
delete this.fragments["#settings-fragments"];
|
||||
this.fragments[name] = settingsFragment;
|
||||
}
|
||||
|
||||
onStart() {
|
||||
let res = super.onStart();
|
||||
if (Helper.isNotNull(this.active) && !this.fragments[this.active].isActive()) {
|
||||
this.setActive(null);
|
||||
}
|
||||
|
||||
this.buildList();
|
||||
return res;
|
||||
}
|
||||
|
||||
setActive(name) {
|
||||
if (Helper.isNotNull(this.active)) {
|
||||
this.fragments[this.active].inflatePromise.then(function (view) {
|
||||
view.classList.remove("active");
|
||||
});
|
||||
this.findBy("#show-fragment-" + this.active).classList.remove("active");
|
||||
}
|
||||
this.active = name;
|
||||
if (Helper.isNotNull(this.active)) {
|
||||
this.fragments[this.active].inflatePromise.then(function (view) {
|
||||
view.classList.add("active");
|
||||
});
|
||||
this.findBy("#show-fragment-" + this.active).classList.add("active");
|
||||
}
|
||||
}
|
||||
|
||||
buildList() {
|
||||
let listNameElem = this.findBy("#settings-fragment-list");
|
||||
listNameElem.removeAllChildren();
|
||||
|
||||
let self = this;
|
||||
for (let k in this.fragments) {
|
||||
if (this.fragments[k].isActive()) {
|
||||
|
||||
let liElement = document.createElement("li");
|
||||
liElement.id = "show-fragment-" + k;
|
||||
liElement.appendChild(Translator.makePersistentTranslation(k, null, "a"));
|
||||
liElement.addEventListener("click", function () {
|
||||
self.setActive(k);
|
||||
});
|
||||
listNameElem.appendChild(liElement);
|
||||
|
||||
if (Helper.isNull(this.active)) {
|
||||
this.setActive(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.isSolved();
|
||||
}
|
||||
|
||||
setChildren(children) {
|
||||
this.children = [];
|
||||
for (let i = 0, n = children.length; i < n; i++) {
|
||||
this.addChild(children[i]);
|
||||
}
|
||||
static addSettingsFragment(name, settingsFragment) {
|
||||
SettingsSite.settingsFragments[name] = settingsFragment;
|
||||
}
|
||||
|
||||
addChild(child) {
|
||||
this.children.push(child);
|
||||
this._updateElement();
|
||||
}
|
||||
|
||||
_updateRotationClass() {
|
||||
// this.style.transform = "rotate("+this.rotation+"deg)";
|
||||
this.element.classList.remove(this.class);
|
||||
this.class = "rotate-" + this.rotation;
|
||||
if (this.class === "rotate-0")
|
||||
{
|
||||
this.class = "rotate-360";
|
||||
}
|
||||
this.element.classList.add(this.class);
|
||||
|
||||
// if (this.rotation === 0) {
|
||||
// const self = this;
|
||||
// self.element.classList.add("no-transition");
|
||||
//
|
||||
// setTimeout(() => {
|
||||
// if (self.class === "rotate-0") {
|
||||
// requestAnimationFrame(()=>{
|
||||
//
|
||||
// self.element.classList.remove("rotate-0");
|
||||
// self.element.classList.remove("no-transition");
|
||||
// });
|
||||
// }
|
||||
// }, 250);
|
||||
// }
|
||||
}
|
||||
|
||||
_updateElement() {
|
||||
const childContainer = this.element.querySelector(".child-container");
|
||||
childContainer.removeAllChildren();
|
||||
|
||||
this._updateRotationClass();
|
||||
|
||||
const self = this;
|
||||
this.element.onclick = function () {
|
||||
self.rotate();
|
||||
};
|
||||
|
||||
for (let i = 0, n = this.children.length; i < n; i++) {
|
||||
this.children[i]._updateElement();
|
||||
childContainer.appendChild(this.children[i].getElement());
|
||||
}
|
||||
static setAddSettingsSite(addLink) {
|
||||
SettingsSite.shouldAddSettingsSite = addLink;
|
||||
}
|
||||
}
|
||||
|
||||
class LeafSegment extends Segment{
|
||||
SettingsSite.settingsFragments = {};
|
||||
SettingsSite.shouldAddSettingsSite = true;
|
||||
|
||||
constructor(element, leaf) {
|
||||
super(element);
|
||||
this.leaf = 'A';
|
||||
if (Helper.isNotNull(leaf))
|
||||
{
|
||||
this.setLeaf(leaf);
|
||||
InitPromise.addPromise(function (app) {
|
||||
if (SettingsSite.shouldAddSettingsSite) {
|
||||
app.addDeepLink("settings", SettingsSite.name);
|
||||
|
||||
let settingsAction = new MenuAction("settings", function () {
|
||||
app.startSite(SettingsSite.name);
|
||||
}, MenuAction.SHOW_FOR_LARGE, 10000);
|
||||
settingsAction.setIcon("img/settings.png");
|
||||
app.addDefaultAction(settingsAction);
|
||||
}
|
||||
});
|
||||
|
||||
class WordRotatorDb extends MyDb {
|
||||
|
||||
static getInstance() {
|
||||
if (Helper.isNull(WordRotatorDb.instance)) {
|
||||
WordRotatorDb.instance = new WordRotatorDb();
|
||||
}
|
||||
}
|
||||
|
||||
setLeaf(leaf)
|
||||
{
|
||||
this.leaf = leaf;
|
||||
return WordRotatorDb.instance;
|
||||
}
|
||||
|
||||
_updateElement() {
|
||||
this.element.querySelector(".leaf-element").removeAllChildren().appendChild(document.createTextNode(this.leaf));
|
||||
constructor() {
|
||||
super("wordRotator", 1);
|
||||
}
|
||||
|
||||
upgrade(db, oldVersion, newVersion, e) {
|
||||
if (Helper.isNull(oldVersion) || oldVersion < 1 && newVersion >= 1) {
|
||||
let levelObjectStore = db.createObjectStore(WordRotatorDb.OBJECT_STORE.LEVEL, {"keyPath": "id"});
|
||||
}
|
||||
};
|
||||
|
||||
async saveManyLevels(levels) {
|
||||
return this.saveMany(levels, WordRotatorDb.OBJECT_STORE.LEVEL);
|
||||
}
|
||||
|
||||
async loadLevel(levelId)
|
||||
{
|
||||
return this.load(levelId, WordRotatorDb.OBJECT_STORE.LEVEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TemplateContainer{
|
||||
constructor(leafTemplate, parentTemplate, rowTemplate){
|
||||
this.leafTemplate = leafTemplate;
|
||||
this.parentTemplate = parentTemplate;
|
||||
this.rowTemplate = rowTemplate;
|
||||
}
|
||||
WordRotatorDb.OBJECT_STORE = {
|
||||
LEVEL: "level",
|
||||
};
|
||||
WordRotatorDb.instance = null;
|
||||
|
||||
copyLeafTemplate()
|
||||
{
|
||||
return Helper.cloneNode(this.leafTemplate);
|
||||
}
|
||||
class SynchronizeSite extends AbstractSite$1 {
|
||||
|
||||
copyParentTemplate()
|
||||
{
|
||||
return Helper.cloneNode(this.parentTemplate);
|
||||
}
|
||||
|
||||
copyRowTemplate()
|
||||
{
|
||||
return Helper.cloneNode(this.rowTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
class Level {
|
||||
constructor(templateContainer) {
|
||||
this.rootSegment = null;
|
||||
this.words = [];
|
||||
this.startRotations = [];
|
||||
this.templateContainer = templateContainer;
|
||||
}
|
||||
|
||||
setWords(words)
|
||||
{
|
||||
this.words = [];
|
||||
for (let i = 0, n = words.length; i < n; i++) {
|
||||
this.words.push(words[i].toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
setStartRotations(rotations)
|
||||
{
|
||||
this.startRotations = rotations;
|
||||
}
|
||||
|
||||
hasWon() {
|
||||
return this.rootSegment.isSolved();
|
||||
}
|
||||
|
||||
getRootSegment(){
|
||||
return this.rootSegment;
|
||||
}
|
||||
|
||||
createSegments() {};
|
||||
|
||||
static _createLeafsForWord(word, leafSegmentTemplate)
|
||||
{
|
||||
let leafSegments = [];
|
||||
for (let i = 0, n = word.length; i < n; i++) {
|
||||
leafSegments.push(new LeafSegment(Helper.cloneNode(leafSegmentTemplate), word.charAt(i)));
|
||||
}
|
||||
return leafSegments;
|
||||
}
|
||||
}
|
||||
|
||||
class RowSegment extends ParentSegment{
|
||||
rotate() {}
|
||||
|
||||
applyRotations(rotations)
|
||||
{
|
||||
for (let i = 0, n = this.children.length; i < n; i++) {
|
||||
rotations = this.children[i].applyRotations(rotations);
|
||||
}
|
||||
return rotations;
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleLevel extends Level{
|
||||
|
||||
createSegments() {
|
||||
if (this.words.length >= 2 && this.words[0].length >= 6 &&this.words[1].length >= 6){
|
||||
|
||||
let leafsWordOne = Level._createLeafsForWord(this.words[0], this.templateContainer.copyLeafTemplate());
|
||||
let leafsWordTwo = Level._createLeafsForWord(this.words[1], this.templateContainer.copyLeafTemplate());
|
||||
|
||||
let segmentOne = new ParentSegment(this.templateContainer.copyParentTemplate());
|
||||
let segmentTwo = new ParentSegment(this.templateContainer.copyParentTemplate());
|
||||
let segmentThree = new ParentSegment(this.templateContainer.copyParentTemplate());
|
||||
|
||||
segmentOne.addChild(leafsWordOne[0]);
|
||||
segmentOne.addChild(leafsWordOne[1]);
|
||||
segmentOne.addChild(leafsWordTwo[0]);
|
||||
segmentOne.addChild(leafsWordTwo[1]);
|
||||
|
||||
segmentTwo.addChild(leafsWordOne[2]);
|
||||
segmentTwo.addChild(leafsWordOne[3]);
|
||||
segmentTwo.addChild(leafsWordTwo[2]);
|
||||
segmentTwo.addChild(leafsWordTwo[3]);
|
||||
|
||||
segmentThree.addChild(leafsWordOne[4]);
|
||||
segmentThree.addChild(leafsWordOne[5]);
|
||||
segmentThree.addChild(leafsWordTwo[4]);
|
||||
segmentThree.addChild(leafsWordTwo[5]);
|
||||
|
||||
this.rootSegment = new RowSegment(this.templateContainer.copyRowTemplate());
|
||||
this.rootSegment.addChild(segmentOne);
|
||||
this.rootSegment.addChild(segmentTwo);
|
||||
this.rootSegment.addChild(segmentThree);
|
||||
|
||||
this.rootSegment.applyRotations(this.startRotations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LevelSite extends AbstractSite$1{
|
||||
constructor(siteManager) {
|
||||
super(siteManager, "html/application/level.html", "level");
|
||||
}
|
||||
|
||||
onConstruct(args) {
|
||||
this.setTitle("Level");
|
||||
return super.onConstruct(args);
|
||||
super(siteManager, "html/application/sync.html");
|
||||
}
|
||||
|
||||
onFirstStart() {
|
||||
super.onFirstStart();
|
||||
this.loadLevels();
|
||||
}
|
||||
|
||||
let leafSegmentTemplate = this.findBy("#segment-leaf-template");
|
||||
let parentSegmentTemplate = this.findBy("#segment-parent-template");
|
||||
let rowSegmentTemplate = this.findBy("#segment-row-template");
|
||||
async loadLevels() {
|
||||
|
||||
leafSegmentTemplate.id = null;
|
||||
parentSegmentTemplate.id = null;
|
||||
rowSegmentTemplate.id = null;
|
||||
const dateLastSync = Helper.nonNull(localStorage.getItem("date-last-sync"), 0);
|
||||
const db = WordRotatorDb.getInstance();
|
||||
|
||||
leafSegmentTemplate.remove();
|
||||
parentSegmentTemplate.remove();
|
||||
rowSegmentTemplate.remove();
|
||||
let newLastSync = null;
|
||||
let maxRuns = 1;
|
||||
let levelPromises = [];
|
||||
for (let run = 0; run < maxRuns; run++) {
|
||||
let res = await DataManager.load("wordRotator/levels" + DataManager.buildQuery({
|
||||
"currentRun": run,
|
||||
"dateLastSync": dateLastSync
|
||||
}));
|
||||
if (!res["success"]) {
|
||||
break;
|
||||
}
|
||||
res = res["result"];
|
||||
newLastSync = Helper.nonNull(newLastSync, res["currentSyncDate"]);
|
||||
maxRuns = res["maxRuns"];
|
||||
|
||||
let templateContainer = new TemplateContainer(leafSegmentTemplate, parentSegmentTemplate, rowSegmentTemplate);
|
||||
let levels = res["levels"];
|
||||
for (let i = 0, n = levels.length; i < n; i++) {
|
||||
let currentLevel = levels[i];
|
||||
levelPromises.push(db.loadLevel(levels[i]["id"]).then(level => {
|
||||
currentLevel["played"] = (Helper.nonNull(Helper.nonNull(level, {}).played, false));
|
||||
return currentLevel;
|
||||
}));
|
||||
}
|
||||
}
|
||||
let levels = await Promise.all(levelPromises);
|
||||
console.log(levels);
|
||||
await db.saveManyLevels(levels);
|
||||
|
||||
|
||||
let level = new SimpleLevel(templateContainer);
|
||||
level.setWords([
|
||||
"Dynamo",
|
||||
"Abhang"
|
||||
]);
|
||||
level.setStartRotations([0,90,180]);
|
||||
|
||||
level.createSegments();
|
||||
level.getRootSegment()._updateElement();
|
||||
this.findBy("#level").appendChild(level.getRootSegment().getElement());
|
||||
// localStorage.setItem("date-last-sync", newLastSync);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3074,6 +3254,6 @@ app.addDefaultAction(Translator.generateChangeLanguageMenuAction());
|
||||
// window["Translator"]["setLanguage"] = Translator.setLanguage;
|
||||
|
||||
InitPromise.resolve(app).then(function(){
|
||||
app.start(LevelSite);
|
||||
app.start(SynchronizeSite);
|
||||
Translator.setLanguage("de");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user