Use arguments

This commit is contained in:
Robin van der Linde 2024-04-25 10:52:10 +02:00
parent b8b194d04b
commit a944a26e9c
Signed by untrusted user: Robin-van-der-Linde
GPG key ID: 53956B3252478F0D
5 changed files with 27 additions and 6 deletions

View file

@ -151,6 +151,9 @@
"freeform": { "freeform": {
"key": "brand", "key": "brand",
"type": "nsi", "type": "nsi",
"helperArgs": [
"amenity=atm"
],
"placeholder": { "placeholder": {
"en": "Brand name", "en": "Brand name",
"de": "Markenname", "de": "Markenname",

View file

@ -14,12 +14,21 @@
*/ */
export let value: UIEventSource<string> = new UIEventSource<string>(undefined) export let value: UIEventSource<string> = new UIEventSource<string>(undefined)
export let feature: Feature export let feature: Feature
export let tags: UIEventSource<Record<string, string>>
export let helperArgs: (string | number | boolean)[]
export let key: string
// Currently hardcoded, should be dynamic let maintag = helperArgs[0].toString()
let maintag = "amenity=atm" let tag = key
let tag = "brand"
const path = `${tag}s/${maintag.split("=")[0]}/${maintag.split("=")[1]}` const path = `${tag}s/${maintag.split("=")[0]}/${maintag.split("=")[1]}`
// Check if the path exists in the NSI file
if (!nsiFile.nsi[path]) {
console.error(`Path ${path} does not exist in the NSI file`)
throw new Error(`Path ${path} does not exist in the NSI file`)
}
let items = nsiFile.nsi[path].items let items = nsiFile.nsi[path].items
// Get the coordinates if the feature is a point, otherwise use the center // Get the coordinates if the feature is a point, otherwise use the center
@ -34,7 +43,9 @@
lat = feature.bbox[1] + (feature.bbox[3] - feature.bbox[1]) / 2 lat = feature.bbox[1] + (feature.bbox[3] - feature.bbox[1]) / 2
} }
// Filter the items /**
* Filter the items, first by the display name, then by the location set
*/
let filter = "" let filter = ""
$: filteredItems = items $: filteredItems = items
.filter((item) => item.displayName.toLowerCase().includes(filter.toLowerCase())) .filter((item) => item.displayName.toLowerCase().includes(filter.toLowerCase()))

View file

@ -27,6 +27,9 @@
export let feature: Feature export let feature: Feature
export let args: (string | number | boolean)[] = undefined export let args: (string | number | boolean)[] = undefined
export let state: SpecialVisualizationState export let state: SpecialVisualizationState
export let tags: UIEventSource<Record<string, string>>
export let helperArgs: (string | number | boolean)[]
export let key: string
let properties = { feature, args: args ?? [] } let properties = { feature, args: args ?? [] }
</script> </script>
@ -52,5 +55,5 @@
{:else if type === "wikidata"} {:else if type === "wikidata"}
<ToSvelte construct={() => InputHelpers.constructWikidataHelper(value, properties)} /> <ToSvelte construct={() => InputHelpers.constructWikidataHelper(value, properties)} />
{:else if type === "nsi"} {:else if type === "nsi"}
<NameSuggestionIndexInput {value} {feature} /> <NameSuggestionIndexInput {value} {feature} {tags} {helperArgs} {key} />
{/if} {/if}

View file

@ -24,7 +24,6 @@ export default class NameSuggestionIndexValidator extends Validator {
"main", "main",
"The main tag to give suggestions for, e.g. `amenity=restaurant`.", "The main tag to give suggestions for, e.g. `amenity=restaurant`.",
], ],
["key", "The key to give suggestions for, e.g. `brand`."],
] ]
), ),
]), ]),

View file

@ -27,6 +27,8 @@
inline = false inline = false
inline = config.freeform?.inline inline = config.freeform?.inline
} }
let helperArgs = config.freeform?.helperArgs
let key = config.freeform?.key
const dispatch = createEventDispatcher<{ selected }>() const dispatch = createEventDispatcher<{ selected }>()
export let feedback: UIEventSource<Translation> export let feedback: UIEventSource<Translation>
@ -75,6 +77,9 @@
type={config.freeform.type} type={config.freeform.type}
{value} {value}
{state} {state}
{tags}
{helperArgs}
{key}
on:submit on:submit
/> />
</div> </div>