Attempt to fix #422

This commit is contained in:
pietervdvn 2021-07-13 00:40:27 +02:00
parent b9e15697f4
commit c26783187b
4 changed files with 55 additions and 29 deletions

View file

@ -29,10 +29,11 @@ export class Changes implements FeatureSource {
/** /**
* All the pending new objects to upload * All the pending new objects to upload
* @private
*/ */
private readonly newObjects = LocalStorageSource.GetParsed<{ id: number, lat: number, lon: number }[]>("newObjects", []) private readonly newObjects = LocalStorageSource.GetParsed<{ id: number, lat: number, lon: number }[]>("newObjects", [])
private readonly isUploading = new UIEventSource(false);
/** /**
* Adds a change to the pending changes * Adds a change to the pending changes
*/ */
@ -190,6 +191,12 @@ export class Changes implements FeatureSource {
console.log("No changes in any object"); console.log("No changes in any object");
return; return;
} }
const self = this;
if (this.isUploading.data) {
return;
}
this.isUploading.setData(true)
console.log("Beginning upload..."); console.log("Beginning upload...");
// At last, we build the changeset and upload // At last, we build the changeset and upload
@ -235,9 +242,12 @@ export class Changes implements FeatureSource {
}, },
() => { () => {
console.log("Upload successfull!") console.log("Upload successfull!")
this.newObjects.setData([]) self.newObjects.setData([])
this.pending.setData([]); self.pending.setData([]);
}); self.isUploading.setData(false)
},
() => self.isUploading.setData(false)
);
}; };

View file

@ -27,7 +27,7 @@ export class ChangesetHandler {
} }
} }
private static parseUploadChangesetResponse(response: XMLDocument, allElements: ElementStorage) : void{ private static parseUploadChangesetResponse(response: XMLDocument, allElements: ElementStorage): void {
const nodes = response.getElementsByTagName("node"); const nodes = response.getElementsByTagName("node");
// @ts-ignore // @ts-ignore
for (const node of nodes) { for (const node of nodes) {
@ -70,7 +70,8 @@ export class ChangesetHandler {
layout: LayoutConfig, layout: LayoutConfig,
allElements: ElementStorage, allElements: ElementStorage,
generateChangeXML: (csid: string) => string, generateChangeXML: (csid: string) => string,
whenDone : (csId: string) => void) { whenDone: (csId: string) => void,
onFail: () => void) {
if (this.userDetails.data.csCount == 0) { if (this.userDetails.data.csCount == 0) {
// The user became a contributor! // The user became a contributor!
@ -98,8 +99,11 @@ export class ChangesetHandler {
whenDone, whenDone,
(e) => { (e) => {
console.error("UPLOADING FAILED!", e) console.error("UPLOADING FAILED!", e)
onFail()
} }
) )
}, {
onFail: onFail
}) })
} else { } else {
// There still exists an open changeset (or at least we hope so) // There still exists an open changeset (or at least we hope so)
@ -114,8 +118,7 @@ export class ChangesetHandler {
// Mark the CS as closed... // Mark the CS as closed...
this.currentChangeset.setData(""); this.currentChangeset.setData("");
// ... and try again. As the cs is closed, no recursive loop can exist // ... and try again. As the cs is closed, no recursive loop can exist
self.UploadChangeset(layout, allElements, generateChangeXML, whenDone); self.UploadChangeset(layout, allElements, generateChangeXML, whenDone, onFail);
} }
) )
@ -161,18 +164,22 @@ export class ChangesetHandler {
const self = this; const self = this;
this.OpenChangeset(layout, (csId: string) => { this.OpenChangeset(layout, (csId: string) => {
// The cs is open - let us actually upload! // The cs is open - let us actually upload!
const changes = generateChangeXML(csId) const changes = generateChangeXML(csId)
self.AddChange(csId, changes, allElements, (csId) => { self.AddChange(csId, changes, allElements, (csId) => {
console.log("Successfully deleted ", object.id) console.log("Successfully deleted ", object.id)
self.CloseChangeset(csId, continuation) self.CloseChangeset(csId, continuation)
}, (csId) => { }, (csId) => {
alert("Deletion failed... Should not happend") alert("Deletion failed... Should not happend")
// FAILED // FAILED
self.CloseChangeset(csId, continuation) self.CloseChangeset(csId, continuation)
}) })
}, true, reason) }, {
isDeletionCS: true,
deletionReason: reason
}
)
} }
private CloseChangeset(changesetId: string = undefined, continuation: (() => void) = () => { private CloseChangeset(changesetId: string = undefined, continuation: (() => void) = () => {
@ -204,15 +211,20 @@ export class ChangesetHandler {
private OpenChangeset( private OpenChangeset(
layout: LayoutConfig, layout: LayoutConfig,
continuation: (changesetId: string) => void, continuation: (changesetId: string) => void,
isDeletionCS: boolean = false, options?: {
deletionReason: string = undefined) { isDeletionCS?: boolean,
deletionReason?: string,
onFail?: () => void
}
) {
options = options ?? {}
options.isDeletionCS = options.isDeletionCS ?? false
const commentExtra = layout.changesetmessage !== undefined ? " - " + layout.changesetmessage : ""; const commentExtra = layout.changesetmessage !== undefined ? " - " + layout.changesetmessage : "";
let comment = `Adding data with #MapComplete for theme #${layout.id}${commentExtra}` let comment = `Adding data with #MapComplete for theme #${layout.id}${commentExtra}`
if (isDeletionCS) { if (options.isDeletionCS) {
comment = `Deleting a point with #MapComplete for theme #${layout.id}${commentExtra}` comment = `Deleting a point with #MapComplete for theme #${layout.id}${commentExtra}`
if (deletionReason) { if (options.deletionReason) {
comment += ": " + deletionReason; comment += ": " + options.deletionReason;
} }
} }
@ -221,7 +233,7 @@ export class ChangesetHandler {
const metadata = [ const metadata = [
["created_by", `MapComplete ${Constants.vNumber}`], ["created_by", `MapComplete ${Constants.vNumber}`],
["comment", comment], ["comment", comment],
["deletion", isDeletionCS ? "yes" : undefined], ["deletion", options.isDeletionCS ? "yes" : undefined],
["theme", layout.id], ["theme", layout.id],
["language", Locale.language.data], ["language", Locale.language.data],
["host", window.location.host], ["host", window.location.host],
@ -244,6 +256,9 @@ export class ChangesetHandler {
}, function (err, response) { }, function (err, response) {
if (response === undefined) { if (response === undefined) {
console.log("err", err); console.log("err", err);
if(options.onFail){
options.onFail()
}
return; return;
} else { } else {
continuation(response); continuation(response);

View file

@ -111,8 +111,9 @@ export class OsmConnection {
layout: LayoutConfig, layout: LayoutConfig,
allElements: ElementStorage, allElements: ElementStorage,
generateChangeXML: (csid: string) => string, generateChangeXML: (csid: string) => string,
whenDone: (csId: string) => void) { whenDone: (csId: string) => void,
this.changesetHandler.UploadChangeset(layout, allElements, generateChangeXML, whenDone); onFail: () => {}) {
this.changesetHandler.UploadChangeset(layout, allElements, generateChangeXML, whenDone, onFail);
} }
public GetPreference(key: string, prefix: string = "mapcomplete-"): UIEventSource<string> { public GetPreference(key: string, prefix: string = "mapcomplete-"): UIEventSource<string> {

View file

@ -2,7 +2,7 @@ import { Utils } from "../Utils";
export default class Constants { export default class Constants {
public static vNumber = "0.8.4-rc1"; public static vNumber = "0.8.4-rc2";
// The user journey states thresholds when a new feature gets unlocked // The user journey states thresholds when a new feature gets unlocked
public static userJourney = { public static userJourney = {