forked from MapComplete/MapComplete
		
	Small refactoring, fix logic which possibly caused #659 (to be confirmed)
This commit is contained in:
		
							parent
							
								
									776387a640
								
							
						
					
					
						commit
						f447854834
					
				
					 6 changed files with 16 additions and 23 deletions
				
			
		| 
						 | 
					@ -104,7 +104,7 @@ export class Changes {
 | 
				
			||||||
     * Uploads all the pending changes in one go.
 | 
					     * Uploads all the pending changes in one go.
 | 
				
			||||||
     * Triggered by the 'PendingChangeUploader'-actor in Actors
 | 
					     * Triggered by the 'PendingChangeUploader'-actor in Actors
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public async flushChanges(flushreason: string = undefined, openChangeset?: UIEventSource<number>): Promise<void> {
 | 
					    public async flushChanges(flushreason: string = undefined): Promise<void> {
 | 
				
			||||||
        if (this.pendingChanges.data.length === 0) {
 | 
					        if (this.pendingChanges.data.length === 0) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -117,7 +117,7 @@ export class Changes {
 | 
				
			||||||
        console.log("Uploading changes due to: ", flushreason)
 | 
					        console.log("Uploading changes due to: ", flushreason)
 | 
				
			||||||
        this.isUploading.setData(true)
 | 
					        this.isUploading.setData(true)
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            const csNumber = await this.flushChangesAsync(openChangeset)
 | 
					            const csNumber = await this.flushChangesAsync()
 | 
				
			||||||
            this.isUploading.setData(false)
 | 
					            this.isUploading.setData(false)
 | 
				
			||||||
            console.log("Changes flushed. Your changeset is " + csNumber);
 | 
					            console.log("Changes flushed. Your changeset is " + csNumber);
 | 
				
			||||||
        } catch (e) {
 | 
					        } catch (e) {
 | 
				
			||||||
| 
						 | 
					@ -213,7 +213,7 @@ export class Changes {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const osmObjects = Utils.NoNull(await Promise.all(neededIds.map(async id =>
 | 
					        const osmObjects = Utils.NoNull(await Promise.all(neededIds.map(async id =>
 | 
				
			||||||
            OsmObject.DownloadObjectAsync(id).catch(e => {
 | 
					            OsmObject.DownloadObjectAsync(id).catch(e => {
 | 
				
			||||||
                console.error("Could not download OSM-object", id, " dropping it from the changes")
 | 
					                console.error("Could not download OSM-object", id, " dropping it from the changes ("+e+")")
 | 
				
			||||||
                pending = pending.filter(ch => ch.type + "/" + ch.id !== id)
 | 
					                pending = pending.filter(ch => ch.type + "/" + ch.id !== id)
 | 
				
			||||||
                return undefined;
 | 
					                return undefined;
 | 
				
			||||||
            }))));
 | 
					            }))));
 | 
				
			||||||
| 
						 | 
					@ -309,7 +309,7 @@ export class Changes {
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private async flushChangesAsync(openChangeset?: UIEventSource<number>): Promise<void> {
 | 
					    private async flushChangesAsync(): Promise<void> {
 | 
				
			||||||
        const self = this;
 | 
					        const self = this;
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            // At last, we build the changeset and upload
 | 
					            // At last, we build the changeset and upload
 | 
				
			||||||
| 
						 | 
					@ -327,8 +327,7 @@ export class Changes {
 | 
				
			||||||
            const successes = await Promise.all(Array.from(pendingPerTheme,
 | 
					            const successes = await Promise.all(Array.from(pendingPerTheme,
 | 
				
			||||||
                async ([theme, pendingChanges]) => {
 | 
					                async ([theme, pendingChanges]) => {
 | 
				
			||||||
                    try {
 | 
					                    try {
 | 
				
			||||||
                        if (openChangeset === undefined) {
 | 
					                        const openChangeset = this.state.osmConnection.GetPreference("current-open-changeset-" + theme).map(
 | 
				
			||||||
                            openChangeset = this.state.osmConnection.GetPreference("current-open-changeset-" + theme).map(
 | 
					 | 
				
			||||||
                            str => {
 | 
					                            str => {
 | 
				
			||||||
                                const n = Number(str);
 | 
					                                const n = Number(str);
 | 
				
			||||||
                                if (isNaN(n)) {
 | 
					                                if (isNaN(n)) {
 | 
				
			||||||
| 
						 | 
					@ -338,7 +337,6 @@ export class Changes {
 | 
				
			||||||
                            }, [], n => "" + n
 | 
					                            }, [], n => "" + n
 | 
				
			||||||
                        );
 | 
					                        );
 | 
				
			||||||
                        console.log("Using current-open-changeset-" + theme + " from the preferences, got " + openChangeset.data)
 | 
					                        console.log("Using current-open-changeset-" + theme + " from the preferences, got " + openChangeset.data)
 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        return await self.flushSelectChanges(pendingChanges, openChangeset);
 | 
					                        return await self.flushSelectChanges(pendingChanges, openChangeset);
 | 
				
			||||||
                    } catch (e) {
 | 
					                    } catch (e) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,8 +23,7 @@ export class ChangesetHandler {
 | 
				
			||||||
    private readonly auth: any;
 | 
					    private readonly auth: any;
 | 
				
			||||||
    private readonly backend: string;
 | 
					    private readonly backend: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(layoutName: string,
 | 
					    constructor(dryRun: UIEventSource<boolean>,
 | 
				
			||||||
                dryRun: UIEventSource<boolean>,
 | 
					 | 
				
			||||||
                osmConnection: OsmConnection,
 | 
					                osmConnection: OsmConnection,
 | 
				
			||||||
                allElements: ElementStorage,
 | 
					                allElements: ElementStorage,
 | 
				
			||||||
                changes: Changes,
 | 
					                changes: Changes,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,7 +67,6 @@ export class OsmConnection {
 | 
				
			||||||
                    changes: Changes,
 | 
					                    changes: Changes,
 | 
				
			||||||
                    oauth_token?: UIEventSource<string>,
 | 
					                    oauth_token?: UIEventSource<string>,
 | 
				
			||||||
                    // Used to keep multiple changesets open and to write to the correct changeset
 | 
					                    // Used to keep multiple changesets open and to write to the correct changeset
 | 
				
			||||||
                    layoutName: string,
 | 
					 | 
				
			||||||
                    singlePage?: boolean,
 | 
					                    singlePage?: boolean,
 | 
				
			||||||
                    osmConfiguration?: "osm" | "osm-test",
 | 
					                    osmConfiguration?: "osm" | "osm-test",
 | 
				
			||||||
                    attemptLogin?: true | boolean
 | 
					                    attemptLogin?: true | boolean
 | 
				
			||||||
| 
						 | 
					@ -103,7 +102,7 @@ export class OsmConnection {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.preferencesHandler = new OsmPreferences(this.auth, this);
 | 
					        this.preferencesHandler = new OsmPreferences(this.auth, this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.changesetHandler = new ChangesetHandler(options.layoutName, this._dryRun, this, options.allElements, options.changes, this.auth);
 | 
					        this.changesetHandler = new ChangesetHandler(this._dryRun, this, options.allElements, options.changes, this.auth);
 | 
				
			||||||
        if (options.oauth_token?.data !== undefined) {
 | 
					        if (options.oauth_token?.data !== undefined) {
 | 
				
			||||||
            console.log(options.oauth_token.data)
 | 
					            console.log(options.oauth_token.data)
 | 
				
			||||||
            const self = this;
 | 
					            const self = this;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,7 +42,6 @@ export default class UserRelatedState extends ElementsState {
 | 
				
			||||||
                undefined,
 | 
					                undefined,
 | 
				
			||||||
                "Used to complete the login"
 | 
					                "Used to complete the login"
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            layoutName: layoutToUse?.id,
 | 
					 | 
				
			||||||
            osmConfiguration: <'osm' | 'osm-test'>this.featureSwitchApiURL.data,
 | 
					            osmConfiguration: <'osm' | 'osm-test'>this.featureSwitchApiURL.data,
 | 
				
			||||||
            attemptLogin: options?.attemptLogin
 | 
					            attemptLogin: options?.attemptLogin
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -226,7 +226,6 @@ class AutomatonGui {
 | 
				
			||||||
        const osmConnection = new OsmConnection({
 | 
					        const osmConnection = new OsmConnection({
 | 
				
			||||||
            allElements: undefined,
 | 
					            allElements: undefined,
 | 
				
			||||||
            changes: undefined,
 | 
					            changes: undefined,
 | 
				
			||||||
            layoutName: "automaton",
 | 
					 | 
				
			||||||
            singlePage: false,
 | 
					            singlePage: false,
 | 
				
			||||||
            oauth_token: QueryParameters.GetQueryParameter("oauth_token", "OAuth token")
 | 
					            oauth_token: QueryParameters.GetQueryParameter("oauth_token", "OAuth token")
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,6 @@ export default class OsmConnectionSpec extends T {
 | 
				
			||||||
                () => {
 | 
					                () => {
 | 
				
			||||||
                    const osmConn = new OsmConnection({
 | 
					                    const osmConn = new OsmConnection({
 | 
				
			||||||
                            osmConfiguration: "osm-test",
 | 
					                            osmConfiguration: "osm-test",
 | 
				
			||||||
                            layoutName: "Unit test",
 | 
					 | 
				
			||||||
                            allElements: new ElementStorage(),
 | 
					                            allElements: new ElementStorage(),
 | 
				
			||||||
                            changes: new Changes(),
 | 
					                            changes: new Changes(),
 | 
				
			||||||
                            oauth_token: new UIEventSource<string>(OsmConnectionSpec._osm_token)
 | 
					                            oauth_token: new UIEventSource<string>(OsmConnectionSpec._osm_token)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue