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": {
"key": "brand",
"type": "nsi",
"helperArgs": [
"amenity=atm"
],
"placeholder": {
"en": "Brand name",
"de": "Markenname",

View file

@ -14,12 +14,21 @@
*/
export let value: UIEventSource<string> = new UIEventSource<string>(undefined)
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 = "amenity=atm"
let tag = "brand"
let maintag = helperArgs[0].toString()
let tag = key
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
// 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
}
// Filter the items
/**
* Filter the items, first by the display name, then by the location set
*/
let filter = ""
$: filteredItems = items
.filter((item) => item.displayName.toLowerCase().includes(filter.toLowerCase()))

View file

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

View file

@ -24,7 +24,6 @@ export default class NameSuggestionIndexValidator extends Validator {
"main",
"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 = config.freeform?.inline
}
let helperArgs = config.freeform?.helperArgs
let key = config.freeform?.key
const dispatch = createEventDispatcher<{ selected }>()
export let feedback: UIEventSource<Translation>
@ -75,6 +77,9 @@
type={config.freeform.type}
{value}
{state}
{tags}
{helperArgs}
{key}
on:submit
/>
</div>