Small bugfixes on saving elements, fix #83
This commit is contained in:
parent
072e466607
commit
963949f86a
5 changed files with 20 additions and 12 deletions
|
@ -64,7 +64,7 @@ export class CustomLayersState {
|
||||||
const favs = state.favourteLayers.data;
|
const favs = state.favourteLayers.data;
|
||||||
let changed = false;
|
let changed = false;
|
||||||
count.addCallback((countStr) => {
|
count.addCallback((countStr) => {
|
||||||
console.log("UPdating favourites")
|
console.log("Updating favourites")
|
||||||
if (countStr === undefined) {
|
if (countStr === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ export class ElementStorage {
|
||||||
return eventSource;
|
return eventSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
addOrGetElement(element: any) {
|
addOrGetElement(element: any) : UIEventSource<any>{
|
||||||
const elementId = element.properties.id;
|
const elementId = element.properties.id;
|
||||||
if (elementId in this._elements) {
|
if (elementId in this._elements) {
|
||||||
const es = this._elements[elementId];
|
const es = this._elements[elementId];
|
||||||
|
|
|
@ -12,7 +12,7 @@ export class LocalStorageSource {
|
||||||
|
|
||||||
source.addCallback((data) => {
|
source.addCallback((data) => {
|
||||||
localStorage.setItem(key, data);
|
localStorage.setItem(key, data);
|
||||||
console.log("Wriging ", key, data)
|
console.log("Writing to local storage", key, data)
|
||||||
});
|
});
|
||||||
return source;
|
return source;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -79,7 +79,6 @@ export class Changes {
|
||||||
this._pendingChanges.push({elementId: eventSource.data.id, key: key, value: value});
|
this._pendingChanges.push({elementId: eventSource.data.id, key: key, value: value});
|
||||||
this.pendingChangesES.setData(this._pendingChanges.length);
|
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
|
* Note that the geojson version shares the tags (properties) by pointer, but has _no_ id in properties
|
||||||
*/
|
*/
|
||||||
createElement(basicTags:Tag[], lat: number, lon: number) {
|
createElement(basicTags:Tag[], lat: number, lon: number) {
|
||||||
|
console.log("Creating a new element with ", basicTags)
|
||||||
const osmNode = new OsmNode(Changes._nextId);
|
const osmNode = new OsmNode(Changes._nextId);
|
||||||
this.newElements.push(osmNode);
|
this.newElements.push(osmNode);
|
||||||
Changes._nextId--;
|
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 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
|
// The tags are not yet written into the OsmObject, but this is applied onto a
|
||||||
for (const kv of basicTags) {
|
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;
|
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;
|
return geojson;
|
||||||
}
|
}
|
||||||
|
@ -281,6 +282,7 @@ export class Changes {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.uploadAll(function () {
|
self.uploadAll(function () {
|
||||||
|
console.log("Uploaded changes during a last-effort save")
|
||||||
window.close()
|
window.close()
|
||||||
});
|
});
|
||||||
var confirmationMessage = "Nog even geduld - je laatset wijzigingen worden opgeslaan!";
|
var confirmationMessage = "Nog even geduld - je laatset wijzigingen worden opgeslaan!";
|
||||||
|
@ -298,8 +300,9 @@ export class Changes {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Upmoading: loss of focus")
|
console.log("Uploading: loss of focus")
|
||||||
this.uploadAll(function () {
|
this.uploadAll(function () {
|
||||||
|
console.log("Uploaded changes during a last-effort save (loss of focus)")
|
||||||
window.close()
|
window.close()
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -309,14 +312,16 @@ export class Changes {
|
||||||
private SetupAutoSave(state: State) {
|
private SetupAutoSave(state: State) {
|
||||||
|
|
||||||
const millisTillChangesAreSaved = state.secondsTillChangesAreSaved;
|
const millisTillChangesAreSaved = state.secondsTillChangesAreSaved;
|
||||||
const saveAfterXMillis = state.secondsTillChangesAreSaved.data * 1000;
|
const saveAfterXMillis = state.saveTimeout.data;
|
||||||
const self = this;
|
const self = this;
|
||||||
this.pendingChangesES.addCallback(function () {
|
this.pendingChangesES.addCallback(function () {
|
||||||
|
|
||||||
var c = self.pendingChangesES.data;
|
var c = self.pendingChangesES.data;
|
||||||
if (c > 10) {
|
if (c > 10) {
|
||||||
millisTillChangesAreSaved.setData(0);
|
millisTillChangesAreSaved.setData(0);
|
||||||
self.uploadAll(undefined);
|
self.uploadAll(() => {
|
||||||
|
console.log("Uplaoded changes: more then 10 pending changes")
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +333,9 @@ export class Changes {
|
||||||
|
|
||||||
millisTillChangesAreSaved.addCallback((time) => {
|
millisTillChangesAreSaved.addCallback((time) => {
|
||||||
if (time <= 0 && self.pendingChangesES.data > 0) {
|
if (time <= 0 && self.pendingChangesES.data > 0) {
|
||||||
self.uploadAll(undefined);
|
self.uploadAll(() => {
|
||||||
|
console.log("Saving changes: timer elapsed")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
3
State.ts
3
State.ts
|
@ -104,7 +104,8 @@ export class State {
|
||||||
accuracy: number
|
accuracy: number
|
||||||
}> = new UIEventSource<{ latlng: number, accuracy: number }>(undefined);
|
}> = 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<number>(30 * 1000);
|
public readonly saveTimeout = new UIEventSource<number>(30 * 1000);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue