From 963949f86a183840befa884fbc2f9073541bcfe9 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 6 Aug 2020 21:06:50 +0200 Subject: [PATCH] Small bugfixes on saving elements, fix #83 --- Logic/CustomLayersState.ts | 2 +- Logic/ElementStorage.ts | 2 +- Logic/LocalStorageSource.ts | 2 +- Logic/Osm/Changes.ts | 23 +++++++++++++++-------- State.ts | 3 ++- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Logic/CustomLayersState.ts b/Logic/CustomLayersState.ts index 085f119..e4cae27 100644 --- a/Logic/CustomLayersState.ts +++ b/Logic/CustomLayersState.ts @@ -64,7 +64,7 @@ export class CustomLayersState { const favs = state.favourteLayers.data; let changed = false; count.addCallback((countStr) => { - console.log("UPdating favourites") + console.log("Updating favourites") if (countStr === undefined) { return; } diff --git a/Logic/ElementStorage.ts b/Logic/ElementStorage.ts index 2d2cf8c..368179a 100644 --- a/Logic/ElementStorage.ts +++ b/Logic/ElementStorage.ts @@ -21,7 +21,7 @@ export class ElementStorage { return eventSource; } - addOrGetElement(element: any) { + addOrGetElement(element: any) : UIEventSource{ const elementId = element.properties.id; if (elementId in this._elements) { const es = this._elements[elementId]; diff --git a/Logic/LocalStorageSource.ts b/Logic/LocalStorageSource.ts index ce6a82a..1b56698 100644 --- a/Logic/LocalStorageSource.ts +++ b/Logic/LocalStorageSource.ts @@ -12,7 +12,7 @@ export class LocalStorageSource { source.addCallback((data) => { localStorage.setItem(key, data); - console.log("Wriging ", key, data) + console.log("Writing to local storage", key, data) }); return source; } catch (e) { diff --git a/Logic/Osm/Changes.ts b/Logic/Osm/Changes.ts index 85831d6..ad9ca69 100644 --- a/Logic/Osm/Changes.ts +++ b/Logic/Osm/Changes.ts @@ -79,7 +79,6 @@ export class Changes { this._pendingChanges.push({elementId: eventSource.data.id, key: key, value: value}); this.pendingChangesES.setData(this._pendingChanges.length); - } /** @@ -88,6 +87,7 @@ export class Changes { * Note that the geojson version shares the tags (properties) by pointer, but has _no_ id in properties */ createElement(basicTags:Tag[], lat: number, lon: number) { + console.log("Creating a new element with ", basicTags) const osmNode = new OsmNode(Changes._nextId); this.newElements.push(osmNode); Changes._nextId--; @@ -109,14 +109,15 @@ export class Changes { ] } } - State.state.allElements.addOrGetElement(geojson); // The basictags are COPIED, the id is included in the properties // The tags are not yet written into the OsmObject, but this is applied onto a for (const kv of basicTags) { - this.addChange(id, kv.key, kv.value); // We use the call, to trigger all the other machinery (including updating the geojson itsel properties[kv.key] = kv.value; + this._pendingChanges.push({elementId: id, key: kv.key, value: kv.value}); } + this.pendingChangesES.setData(this._pendingChanges.length); + State.state.allElements.addOrGetElement(geojson).ping(); return geojson; } @@ -281,6 +282,7 @@ export class Changes { } self.uploadAll(function () { + console.log("Uploaded changes during a last-effort save") window.close() }); var confirmationMessage = "Nog even geduld - je laatset wijzigingen worden opgeslaan!"; @@ -298,8 +300,9 @@ export class Changes { return; } - console.log("Upmoading: loss of focus") + console.log("Uploading: loss of focus") this.uploadAll(function () { + console.log("Uploaded changes during a last-effort save (loss of focus)") window.close() }); }) @@ -309,14 +312,16 @@ export class Changes { private SetupAutoSave(state: State) { const millisTillChangesAreSaved = state.secondsTillChangesAreSaved; - const saveAfterXMillis = state.secondsTillChangesAreSaved.data * 1000; - const self= this; + const saveAfterXMillis = state.saveTimeout.data; + const self = this; this.pendingChangesES.addCallback(function () { var c = self.pendingChangesES.data; if (c > 10) { millisTillChangesAreSaved.setData(0); - self.uploadAll(undefined); + self.uploadAll(() => { + console.log("Uplaoded changes: more then 10 pending changes") + }); return; } @@ -328,7 +333,9 @@ export class Changes { millisTillChangesAreSaved.addCallback((time) => { if (time <= 0 && self.pendingChangesES.data > 0) { - self.uploadAll(undefined); + self.uploadAll(() => { + console.log("Saving changes: timer elapsed") + }); } } ) diff --git a/State.ts b/State.ts index 6f6c0bb..8d8de8f 100644 --- a/State.ts +++ b/State.ts @@ -104,7 +104,8 @@ export class State { accuracy: number }> = new UIEventSource<{ latlng: number, accuracy: number }>(undefined); - // After this many milliseconds without changes, saves are sent of to OSM + /** After this many milliseconds without changes, saves are sent of to OSM + */ public readonly saveTimeout = new UIEventSource(30 * 1000); /**