forked from MapComplete/MapComplete
		
	Attempting to add in backend to the element
This commit is contained in:
		
							parent
							
								
									ba5cbe9b5c
								
							
						
					
					
						commit
						e11a5ca17b
					
				
					 2 changed files with 29 additions and 25 deletions
				
			
		| 
						 | 
					@ -6,6 +6,7 @@ import Constants from "../../Models/Constants";
 | 
				
			||||||
import FeatureSource from "../FeatureSource/FeatureSource";
 | 
					import FeatureSource from "../FeatureSource/FeatureSource";
 | 
				
			||||||
import {TagsFilter} from "../Tags/TagsFilter";
 | 
					import {TagsFilter} from "../Tags/TagsFilter";
 | 
				
			||||||
import {Tag} from "../Tags/Tag";
 | 
					import {Tag} from "../Tags/Tag";
 | 
				
			||||||
 | 
					import {OsmConnection} from "./OsmConnection";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Handles all changes made to OSM.
 | 
					 * Handles all changes made to OSM.
 | 
				
			||||||
| 
						 | 
					@ -14,13 +15,12 @@ import {Tag} from "../Tags/Tag";
 | 
				
			||||||
export class Changes implements FeatureSource {
 | 
					export class Changes implements FeatureSource {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static _nextId = -1; // Newly assigned ID's are negative
 | 
				
			||||||
    public readonly name = "Newly added features"
 | 
					    public readonly name = "Newly added features"
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The newly created points, as a FeatureSource
 | 
					     * The newly created points, as a FeatureSource
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public features = new UIEventSource<{ feature: any, freshness: Date }[]>([]);
 | 
					    public features = new UIEventSource<{ feature: any, freshness: Date }[]>([]);
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    private static _nextId = -1; // Newly assigned ID's are negative
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * All the pending changes
 | 
					     * All the pending changes
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
| 
						 | 
					@ -50,7 +50,6 @@ export class Changes implements FeatureSource{
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    addTag(elementId: string, tagsFilter: TagsFilter,
 | 
					    addTag(elementId: string, tagsFilter: TagsFilter,
 | 
				
			||||||
           tags?: UIEventSource<any>) {
 | 
					           tags?: UIEventSource<any>) {
 | 
				
			||||||
        const eventSource = tags ?? State.state?.allElements.getEventSourceById(elementId);
 | 
					        const eventSource = tags ?? State.state?.allElements.getEventSourceById(elementId);
 | 
				
			||||||
| 
						 | 
					@ -86,6 +85,7 @@ export class Changes implements FeatureSource{
 | 
				
			||||||
        this.uploadAll([], this.pending.data);
 | 
					        this.uploadAll([], this.pending.data);
 | 
				
			||||||
        this.pending.setData([]);
 | 
					        this.pending.setData([]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Create a new node element at the given lat/long.
 | 
					     * Create a new node element at the given lat/long.
 | 
				
			||||||
     * An internal OsmObject is created to upload later on, a geojson represention is returned.
 | 
					     * An internal OsmObject is created to upload later on, a geojson represention is returned.
 | 
				
			||||||
| 
						 | 
					@ -118,10 +118,10 @@ export class Changes implements FeatureSource{
 | 
				
			||||||
        // 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 
 | 
				
			||||||
        const changes = [];
 | 
					        const changes = [];
 | 
				
			||||||
        for (const kv of basicTags) {
 | 
					        for (const kv of basicTags) {
 | 
				
			||||||
            properties[kv.key] = kv.value;
 | 
					 | 
				
			||||||
            if (typeof kv.value !== "string") {
 | 
					            if (typeof kv.value !== "string") {
 | 
				
			||||||
                throw "Invalid value: don't use a regex in a preset"
 | 
					                throw "Invalid value: don't use a regex in a preset"
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            properties[kv.key] = kv.value;
 | 
				
			||||||
            changes.push({elementId: id, key: kv.key, value: kv.value})
 | 
					            changes.push({elementId: id, key: kv.key, value: kv.value})
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -131,7 +131,11 @@ export class Changes implements FeatureSource{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        State.state.allElements.addOrGetElement(geojson).ping();
 | 
					        State.state.allElements.addOrGetElement(geojson).ping();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.uploadAll([osmNode], changes);
 | 
					        if (State.state.osmConnection.userDetails.data.backend !== OsmConnection.oauth_configs.osm.url) {
 | 
				
			||||||
 | 
					            properties["_backend"] = State.state.osmConnection.userDetails.data.backend
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // this.uploadAll([osmNode], changes);
 | 
				
			||||||
        return geojson;
 | 
					        return geojson;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@ export default class UserDetails {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class OsmConnection {
 | 
					export class OsmConnection {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static readonly _oauth_configs = {
 | 
					    public static readonly oauth_configs = {
 | 
				
			||||||
        "osm": {
 | 
					        "osm": {
 | 
				
			||||||
            oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem',
 | 
					            oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem',
 | 
				
			||||||
            oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI',
 | 
					            oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI',
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ export class OsmConnection {
 | 
				
			||||||
                osmConfiguration: "osm" | "osm-test" = 'osm'
 | 
					                osmConfiguration: "osm" | "osm-test" = 'osm'
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
        this._singlePage = singlePage;
 | 
					        this._singlePage = singlePage;
 | 
				
			||||||
        this._oauth_config = OsmConnection._oauth_configs[osmConfiguration] ?? OsmConnection._oauth_configs.osm;
 | 
					        this._oauth_config = OsmConnection.oauth_configs[osmConfiguration] ?? OsmConnection.oauth_configs.osm;
 | 
				
			||||||
        console.debug("Using backend", this._oauth_config.url)
 | 
					        console.debug("Using backend", this._oauth_config.url)
 | 
				
			||||||
        OsmObject.SetBackendUrl(this._oauth_config.url + "/")
 | 
					        OsmObject.SetBackendUrl(this._oauth_config.url + "/")
 | 
				
			||||||
        this._iframeMode = Utils.runningFromConsole ? false : window !== window.top;
 | 
					        this._iframeMode = Utils.runningFromConsole ? false : window !== window.top;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue