forked from MapComplete/MapComplete
		
	Further translations of the import helper
This commit is contained in:
		
							parent
							
								
									8e2e227563
								
							
						
					
					
						commit
						0d81decdc7
					
				
					 6 changed files with 105 additions and 22 deletions
				
			
		|  | @ -39,6 +39,39 @@ export class AddContextToTranslations<T> extends DesugaringStep<T> { | ||||||
|      * } |      * } | ||||||
|      * rewritten // => expected
 |      * rewritten // => expected
 | ||||||
|      *  |      *  | ||||||
|  |      * // should use the ID if one is present instead of the index
 | ||||||
|  |      * const theme = { | ||||||
|  |      *   layers: [ | ||||||
|  |      *       { | ||||||
|  |      *           tagRenderings:[ | ||||||
|  |      *                | ||||||
|  |      *               {id: "some-tr", | ||||||
|  |      *               question:{ | ||||||
|  |      *                   en:"Question?" | ||||||
|  |      *               } | ||||||
|  |      *               } | ||||||
|  |      *           ] | ||||||
|  |      *       } | ||||||
|  |      *   ]   | ||||||
|  |      * } | ||||||
|  |      * const rewritten = new AddContextToTranslations<any>("prefix:").convert(theme, "context").result | ||||||
|  |      * const expected = { | ||||||
|  |      *   layers: [ | ||||||
|  |      *       { | ||||||
|  |      *           tagRenderings:[ | ||||||
|  |      *                | ||||||
|  |      *               {id: "some-tr", | ||||||
|  |      *               question:{ | ||||||
|  |      *                  _context: "prefix:context.layers.0.tagRenderings.some-tr.question" | ||||||
|  |      *                   en:"Question?" | ||||||
|  |      *               } | ||||||
|  |      *               } | ||||||
|  |      *           ] | ||||||
|  |      *       } | ||||||
|  |      *   ]   | ||||||
|  |      * } | ||||||
|  |      * rewritten // => expected
 | ||||||
|  |      *  | ||||||
|      * // should preserve nulls
 |      * // should preserve nulls
 | ||||||
|      * const theme = { |      * const theme = { | ||||||
|      *   layers: [ |      *   layers: [ | ||||||
|  | @ -70,6 +103,17 @@ export class AddContextToTranslations<T> extends DesugaringStep<T> { | ||||||
|                 return leaf |                 return leaf | ||||||
|             } |             } | ||||||
|             if (typeof leaf === "object") { |             if (typeof leaf === "object") { | ||||||
|  |                  | ||||||
|  |                 // follow the path. If we encounter a number, check that there is no ID we can use instead
 | ||||||
|  |                 let breadcrumb = json; | ||||||
|  |                 for (let i = 0; i < path.length; i++) { | ||||||
|  |                     const pointer = path[i] | ||||||
|  |                     breadcrumb = breadcrumb[pointer] | ||||||
|  |                     if(pointer.match("[0-9]+") && breadcrumb["id"] !== undefined){ | ||||||
|  |                         path[i] = breadcrumb["id"] | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                  | ||||||
|                 return {...leaf, _context: this._prefix + context + "." + path.join(".")} |                 return {...leaf, _context: this._prefix + context + "." + path.join(".")} | ||||||
|             } else { |             } else { | ||||||
|                 return leaf |                 return leaf | ||||||
|  |  | ||||||
|  | @ -7,7 +7,6 @@ import {UIEventSource} from "../../Logic/UIEventSource"; | ||||||
| import Constants from "../../Models/Constants"; | import Constants from "../../Models/Constants"; | ||||||
| import RelationsTracker from "../../Logic/Osm/RelationsTracker"; | import RelationsTracker from "../../Logic/Osm/RelationsTracker"; | ||||||
| import {VariableUiElement} from "../Base/VariableUIElement"; | import {VariableUiElement} from "../Base/VariableUIElement"; | ||||||
| import {FixedUiElement} from "../Base/FixedUiElement"; |  | ||||||
| import {FlowStep} from "./FlowStep"; | import {FlowStep} from "./FlowStep"; | ||||||
| import Loading from "../Base/Loading"; | import Loading from "../Base/Loading"; | ||||||
| import {SubtleButton} from "../Base/SubtleButton"; | import {SubtleButton} from "../Base/SubtleButton"; | ||||||
|  | @ -28,6 +27,7 @@ import * as import_candidate from "../../assets/layers/import_candidate/import_c | ||||||
| import {GeoOperations} from "../../Logic/GeoOperations"; | import {GeoOperations} from "../../Logic/GeoOperations"; | ||||||
| import FeatureInfoBox from "../Popup/FeatureInfoBox"; | import FeatureInfoBox from "../Popup/FeatureInfoBox"; | ||||||
| import {ImportUtils} from "./ImportUtils"; | import {ImportUtils} from "./ImportUtils"; | ||||||
|  | import Translations from "../i18n/Translations"; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Given the data to import, the bbox and the layer, will query overpass for similar items |  * Given the data to import, the bbox and the layer, will query overpass for similar items | ||||||
|  | @ -190,6 +190,7 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea | ||||||
|             features: toImportWithNearby |             features: toImportWithNearby | ||||||
|         }) |         }) | ||||||
| 
 | 
 | ||||||
|  |         const t = Translations.t.importHelper.conflationChecker | ||||||
| 
 | 
 | ||||||
|         const conflationMaps = new Combine([ |         const conflationMaps = new Combine([ | ||||||
|             new VariableUiElement( |             new VariableUiElement( | ||||||
|  | @ -197,7 +198,7 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea | ||||||
|                     if (geojson === undefined) { |                     if (geojson === undefined) { | ||||||
|                         return undefined; |                         return undefined; | ||||||
|                     } |                     } | ||||||
|                     return new SubtleButton(Svg.download_svg(), "Download the loaded geojson from overpass").onClick(() => { |                     return new SubtleButton(Svg.download_svg(), t.downloadOverpassData).onClick(() => { | ||||||
|                         Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson, null, "  "), "mapcomplete-" + layer.id + ".geojson", { |                         Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson, null, "  "), "mapcomplete-" + layer.id + ".geojson", { | ||||||
|                             mimetype: "application/json+geo" |                             mimetype: "application/json+geo" | ||||||
|                         }) |                         }) | ||||||
|  | @ -208,43 +209,53 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea | ||||||
|                     return undefined; |                     return undefined; | ||||||
|                 } |                 } | ||||||
|                 if (age < 0) { |                 if (age < 0) { | ||||||
|                     return new FixedUiElement("Cache was expired") |                     return t.cacheExpired | ||||||
|                 } |                 } | ||||||
|                 return new FixedUiElement("Loaded data is from the cache and is " + Utils.toHumanTime(age) + " old") |                 return t.loadedDataAge.Subs({age: Utils.toHumanTime(age)}) | ||||||
|             })), |             })), | ||||||
| 
 | 
 | ||||||
|             new Title("Live data on OSM"), |             new Title(t.titleLive), | ||||||
|             "The "+toImport.features.length+" red elements on the following map are all your import candidates.", |             t.importCandidatesCount.Subs({count:toImport.features.length }), | ||||||
|              new VariableUiElement(geojson.map(geojson => new FixedUiElement((geojson?.features?.length ?? "No") + " elements are loaded from OpenStreetMap which match the layer "+layer.id+". Zooming in might be needed to show them"))), |              new VariableUiElement(geojson.map(geojson => { | ||||||
|  |                  if(geojson?.features?.length === undefined && geojson?.features?.length === 0){ | ||||||
|  |                     return t.nothingLoaded.Subs(layer).SetClass("alert") | ||||||
|  |                  } | ||||||
|  |                  return new Combine([ | ||||||
|  |                     t.osmLoaded.Subs({count: geojson.features.length, name: layer.name}), | ||||||
|  |                       | ||||||
|  |                  ])  | ||||||
|  |              })), | ||||||
|             osmLiveData, |             osmLiveData, | ||||||
|             new Combine(["The live data is shown if the zoomlevel is at least ", zoomLevel, ". The current zoom level is ", new VariableUiElement(osmLiveData.location.map(l => "" + l.zoom))]).SetClass("flex"), |             new VariableUiElement(osmLiveData.location.map(location => { | ||||||
| 
 |                 return t.zoomIn.Subs({needed:zoomLevel, current: location.zoom }) | ||||||
|             new Title("Nearby features"), |             } )), | ||||||
|             new Combine(["The following map shows features to import which have an OSM-feature within ", nearbyCutoff, "meter"]).SetClass("flex"), |             new Title(t.titleNearby), | ||||||
|  |             new Combine([t.mapShowingNearbyIntro, nearbyCutoff]).SetClass("flex"), | ||||||
|             new VariableUiElement(toImportWithNearby.features.map(feats =>  |             new VariableUiElement(toImportWithNearby.features.map(feats =>  | ||||||
|                     new FixedUiElement("The "+  feats.length +" red elements on the following map will <b>not</b> be imported!").SetClass("alert"))), |                 t.nearbyWarn.Subs({count: feats.length}).SetClass("alert"))), | ||||||
|             "Set the range to 0 or 1 if you want to import them all", |             ,t.setRangeToZero, | ||||||
|             matchedFeaturesMap]).SetClass("flex flex-col") |             matchedFeaturesMap]).SetClass("flex flex-col") | ||||||
| 
 | 
 | ||||||
|         super([ |         super([ | ||||||
|             new Title("Comparison with existing data"), |             new Title(t.title), | ||||||
|             new VariableUiElement(overpassStatus.map(d => { |             new VariableUiElement(overpassStatus.map(d => { | ||||||
|                 if (d === "idle") { |                 if (d === "idle") { | ||||||
|                     return new Loading("Checking local storage...") |                     return new Loading(t.states.idle) | ||||||
|                 } |  | ||||||
|                 if (d["error"] !== undefined) { |  | ||||||
|                     return new FixedUiElement("Could not load latest data from overpass: " + d["error"]).SetClass("alert") |  | ||||||
|                 } |                 } | ||||||
|                 if (d === "running") { |                 if (d === "running") { | ||||||
|                     return new Loading("Querying overpass...") |                     return new Loading(t.states.running) | ||||||
|                 } |                 } | ||||||
|  |                 if (d["error"] !== undefined) { | ||||||
|  |                     return t.states.error.Subs(d).SetClass("alert") | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|                 if (d === "cached") { |                 if (d === "cached") { | ||||||
|                     return conflationMaps |                     return conflationMaps | ||||||
|                 } |                 } | ||||||
|                 if (d === "success") { |                 if (d === "success") { | ||||||
|                     return conflationMaps |                     return conflationMaps | ||||||
|                 } |                 } | ||||||
|                 return new FixedUiElement("Unexpected state " + d).SetClass("alert") |                 return t.states.unexpected.Subs({state: d}).SetClass("alert") | ||||||
|             })) |             })) | ||||||
| 
 | 
 | ||||||
|         ]) |         ]) | ||||||
|  |  | ||||||
|  | @ -36,7 +36,7 @@ export default class ImportHelperGui extends LeftIndex { | ||||||
|                .then(t.mapPreview, geojson => new MapPreview(state, geojson)) |                .then(t.mapPreview, geojson => new MapPreview(state, geojson)) | ||||||
|                .then(t.selectTheme, v => new SelectTheme(v)) |                .then(t.selectTheme, v => new SelectTheme(v)) | ||||||
|                .then(t.compareToAlreadyExistingNotes, v => new CompareToAlreadyExistingNotes(state, v)) |                .then(t.compareToAlreadyExistingNotes, v => new CompareToAlreadyExistingNotes(state, v)) | ||||||
|                .then("Compare with existing data", v => new ConflationChecker(state, v)) |                .then(t.conflationChecker, v => new ConflationChecker(state, v)) | ||||||
|                .then(t.confirmProcess, v  => new ConfirmProcess(v)) |                .then(t.confirmProcess, v  => new ConfirmProcess(v)) | ||||||
|                .then(t.askMetadata, (v) => new AskMetadata(v)) |                .then(t.askMetadata, (v) => new AskMetadata(v)) | ||||||
|                .finish(t.createNotes.title, v => new CreateNotes(state, v)); |                .finish(t.createNotes.title, v => new CreateNotes(state, v)); | ||||||
|  |  | ||||||
|  | @ -9,7 +9,8 @@ export default class InputElementWrapper<T> extends InputElement<T> { | ||||||
|     private readonly _inputElement: InputElement<T>; |     private readonly _inputElement: InputElement<T>; | ||||||
|     private readonly _renderElement: BaseUIElement |     private readonly _renderElement: BaseUIElement | ||||||
| 
 | 
 | ||||||
|     constructor(inputElement: InputElement<T>, translation: Translation, key: string, tags: UIEventSource<any>, state: FeaturePipelineState) { |     constructor(inputElement: InputElement<T>, translation: Translation, key: string,  | ||||||
|  |                 tags: UIEventSource<any>, state: FeaturePipelineState) { | ||||||
|         super() |         super() | ||||||
|         this._inputElement = inputElement; |         this._inputElement = inputElement; | ||||||
|         const mapping = new Map<string, BaseUIElement>() |         const mapping = new Map<string, BaseUIElement>() | ||||||
|  |  | ||||||
|  | @ -1,4 +1,10 @@ | ||||||
| [ | [ | ||||||
|  |   { | ||||||
|  |     "start_date": "2022-05-30", | ||||||
|  |     "end_date":"2022-06-05", | ||||||
|  |     "message": "The 3rd of June is <b><a href='https://en.wikipedia.org/wiki/World_Bicycle_Day'>World Bicycle Day</a></b>. Go find a bike shop or bike pump nearby", | ||||||
|  |     "featured_theme": "cyclofix" | ||||||
|  |   }, | ||||||
|   { |   { | ||||||
|     "start_date": "2022-04-18", |     "start_date": "2022-04-18", | ||||||
|     "end_date": "2022-04-24", |     "end_date": "2022-04-24", | ||||||
|  |  | ||||||
|  | @ -310,6 +310,27 @@ | ||||||
|             "titleLong": "Did you go through the import process?", |             "titleLong": "Did you go through the import process?", | ||||||
|             "wikipageIsMade": "The process is documented on the OSM-wiki (you'll need this link later)" |             "wikipageIsMade": "The process is documented on the OSM-wiki (you'll need this link later)" | ||||||
|         }, |         }, | ||||||
|  |         "conflationChecker": { | ||||||
|  |             "cacheExpired": "Cache was expired", | ||||||
|  |             "downloadOverpassData": "Download the loaded geojson from overpass", | ||||||
|  |             "importCandidatesCount": "The {count} red elements on the following map are all your import candidates.", | ||||||
|  |             "loadedDataAge": "Loaded data is from the cache and is {age} old", | ||||||
|  |             "mapShowingNearbyIntro": "The following map shows features to import which have an OSM-feature within ", | ||||||
|  |             "nearbyWarn": "The {count} red elements on the following map will <b>not</b> be imported!", | ||||||
|  |             "nothingLoaded": "No elements are loaded from OpenStreetMap which match the current layer {name}", | ||||||
|  |             "osmLoaded": "{count} elements are loaded from OpenStreetMap which match the layer <b>{name}</b>.", | ||||||
|  |             "setRangeToZero": "Set the range to 0 or 1 if you want to import them all", | ||||||
|  |             "states": { | ||||||
|  |                 "error": "Could not load latest data from overpass due to {error}", | ||||||
|  |                 "idle": "Checking local storage...", | ||||||
|  |                 "running": "Querying overpass...", | ||||||
|  |                 "unexpected": "Unexpected state {state}" | ||||||
|  |             }, | ||||||
|  |             "title": "Compare with existing data", | ||||||
|  |             "titleLive": "Live data on OSM", | ||||||
|  |             "titleNearby": "Nearby features", | ||||||
|  |             "zoomIn": "The live data is shown if the zoomlevel is at least {needed}. The current zoom level is {current}" | ||||||
|  |         }, | ||||||
|         "createNotes": { |         "createNotes": { | ||||||
|             "creating": "Created <b>{count}</b> notes out of {total}", |             "creating": "Created <b>{count}</b> notes out of {total}", | ||||||
|             "done": "All {count} notes have been created!", |             "done": "All {count} notes have been created!", | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue