Small refactoring: move changeset-handler creation to 'changes'

This commit is contained in:
pietervdvn 2022-02-15 23:44:16 +01:00
parent 0a43a69a0c
commit dfb16fa802
6 changed files with 16 additions and 14 deletions

View file

@ -11,7 +11,7 @@ import FeatureSource from "../FeatureSource/FeatureSource";
import {ElementStorage} from "../ElementStorage";
import {GeoLocationPointProperties} from "../Actors/GeoLocationHandler";
import {GeoOperations} from "../GeoOperations";
import {ChangesetTag} from "./ChangesetHandler";
import {ChangesetHandler, ChangesetTag} from "./ChangesetHandler";
import {OsmConnection} from "./OsmConnection";
/**
@ -33,6 +33,7 @@ export class Changes {
private readonly isUploading = new UIEventSource(false);
private readonly previouslyCreated: OsmObject[] = []
private readonly _leftRightSensitive: boolean;
private _changesetHandler: ChangesetHandler;
constructor(
state?: {
@ -47,6 +48,7 @@ export class Changes {
// If a pending change contains a negative ID, we save that
this._nextId = Math.min(-1, ...this.pendingChanges.data?.map(pch => pch.id) ?? [])
this.state = state;
this._changesetHandler = state.osmConnection.CreateChangesetHandler(state.allElements, this)
// Note: a changeset might be reused which was opened just before and might have already used some ids
// This doesn't matter however, as the '-1' is per piecewise upload, not global per changeset
@ -299,7 +301,7 @@ export class Changes {
...perBinMessage
]
await this.state.osmConnection.changesetHandler.UploadChangeset(
await this._changesetHandler.UploadChangeset(
(csId) => Changes.createChangesetFor("" + csId, changes),
metatags,
openChangeset

View file

@ -23,6 +23,14 @@ export class ChangesetHandler {
private readonly auth: any;
private readonly backend: string;
/**
* Use 'osmConnection.CreateChangesetHandler' instead
* @param dryRun
* @param osmConnection
* @param allElements
* @param changes
* @param auth
*/
constructor(dryRun: UIEventSource<boolean>,
osmConnection: OsmConnection,
allElements: ElementStorage,

View file

@ -47,7 +47,6 @@ export class OsmConnection {
public userDetails: UIEventSource<UserDetails>;
public isLoggedIn: UIEventSource<boolean>
public preferencesHandler: OsmPreferences;
public changesetHandler: ChangesetHandler;
public readonly _oauth_config: {
oauth_consumer_key: string,
oauth_secret: string,
@ -63,8 +62,6 @@ export class OsmConnection {
constructor(options: {
dryRun?: UIEventSource<boolean>,
fakeUser?: false | boolean,
allElements: ElementStorage,
changes: Changes,
oauth_token?: UIEventSource<string>,
// Used to keep multiple changesets open and to write to the correct changeset
singlePage?: boolean,
@ -102,7 +99,6 @@ export class OsmConnection {
this.preferencesHandler = new OsmPreferences(this.auth, this);
this.changesetHandler = new ChangesetHandler(this._dryRun, this, options.allElements, options.changes, this.auth);
if (options.oauth_token?.data !== undefined) {
console.log(options.oauth_token.data)
const self = this;
@ -121,6 +117,10 @@ export class OsmConnection {
console.log("Not authenticated");
}
}
public CreateChangesetHandler(allElements: ElementStorage, changes: Changes){
return new ChangesetHandler(this._dryRun, this, allElements, changes, this.auth);
}
public GetPreference(key: string, prefix: string = "mapcomplete-"): UIEventSource<string> {
return this.preferencesHandler.GetPreference(key, prefix);

View file

@ -33,10 +33,8 @@ export default class UserRelatedState extends ElementsState {
super(layoutToUse);
this.osmConnection = new OsmConnection({
changes: this.changes,
dryRun: this.featureSwitchIsTesting,
fakeUser: this.featureSwitchFakeUser.data,
allElements: this.allElements,
oauth_token: QueryParameters.GetQueryParameter(
"oauth_token",
undefined,

View file

@ -224,8 +224,6 @@ class AutomatonGui {
constructor() {
const osmConnection = new OsmConnection({
allElements: undefined,
changes: undefined,
singlePage: false,
oauth_token: QueryParameters.GetQueryParameter("oauth_token", "OAuth token")
});

View file

@ -2,8 +2,6 @@ import T from "./TestHelper";
import UserDetails, {OsmConnection} from "../Logic/Osm/OsmConnection";
import {UIEventSource} from "../Logic/UIEventSource";
import ScriptUtils from "../scripts/ScriptUtils";
import {ElementStorage} from "../Logic/ElementStorage";
import {Changes} from "../Logic/Osm/Changes";
export default class OsmConnectionSpec extends T {
@ -19,8 +17,6 @@ export default class OsmConnectionSpec extends T {
() => {
const osmConn = new OsmConnection({
osmConfiguration: "osm-test",
allElements: new ElementStorage(),
changes: new Changes(),
oauth_token: new UIEventSource<string>(OsmConnectionSpec._osm_token)
}
);