forked from MapComplete/MapComplete
Refactoring: remove some old, UIElement based code
This commit is contained in:
parent
b84655f2cb
commit
56a55e8b54
14 changed files with 58 additions and 261 deletions
10
src/UI/InputElement/Helpers/TimeInput.svelte
Normal file
10
src/UI/InputElement/Helpers/TimeInput.svelte
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<script lang="ts">
|
||||
/**
|
||||
* Simple wrapper around the HTML-time field.
|
||||
*/
|
||||
import { UIEventSource } from "../../../Logic/UIEventSource"
|
||||
|
||||
export let value: UIEventSource<undefined | string>
|
||||
</script>
|
||||
|
||||
<input bind:value={$value} type="time" />
|
||||
57
src/UI/InputElement/Helpers/WikidataInputHelper.svelte
Normal file
57
src/UI/InputElement/Helpers/WikidataInputHelper.svelte
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<script lang="ts">
|
||||
/**
|
||||
*
|
||||
Wrapper around 'WikidataInput.svelte' which handles the arguments
|
||||
*/
|
||||
|
||||
import { UIEventSource } from "../../../Logic/UIEventSource"
|
||||
import Locale from "../../i18n/Locale"
|
||||
import { Utils } from "../../../Utils"
|
||||
import Wikidata from "../../../Logic/Web/Wikidata"
|
||||
import WikidataInput from "../Helpers/WikidataInput.svelte"
|
||||
import type { Feature } from "geojson"
|
||||
import { onDestroy } from "svelte"
|
||||
import WikidataValidator from "../Validators/WikidataValidator"
|
||||
|
||||
export let args: (string | number | boolean)[] = []
|
||||
export let feature: Feature
|
||||
|
||||
export let value: UIEventSource<string>
|
||||
|
||||
let searchKey: string = <string>args[0] ?? "name"
|
||||
|
||||
let searchFor: string =
|
||||
searchKey
|
||||
.split(";")
|
||||
.map((k) => feature?.properties[k]?.toLowerCase())
|
||||
.find((foundValue) => !!foundValue) ?? ""
|
||||
|
||||
const options: any = args[1]
|
||||
|
||||
let searchForValue: UIEventSource<string> = new UIEventSource(searchFor)
|
||||
|
||||
onDestroy(
|
||||
Locale.language.addCallbackAndRunD((lg) => {
|
||||
console.log(options)
|
||||
if (searchFor !== undefined && options !== undefined) {
|
||||
const post = options["removePostfixes"] ?? []
|
||||
const pre = options["removePrefixes"] ?? []
|
||||
const clipped = WikidataValidator.removePostAndPrefixes(searchFor, pre, post, lg)
|
||||
console.log("Got clipped value:", clipped, post, pre)
|
||||
searchForValue.setData(clipped)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
let instanceOf: number[] = Utils.NoNull(
|
||||
(options?.instanceOf ?? []).map((i) => Wikidata.QIdToNumber(i))
|
||||
)
|
||||
let notInstanceOf: number[] = Utils.NoNull(
|
||||
(options?.notInstanceOf ?? []).map((i) => Wikidata.QIdToNumber(i))
|
||||
)
|
||||
|
||||
let allowMultipleArg = options?.["multiple"] ?? "yes"
|
||||
let allowMultiple = allowMultipleArg === "yes" || "" + allowMultipleArg === "true"
|
||||
</script>
|
||||
|
||||
<WikidataInput searchValue={searchForValue} {value} {instanceOf} {notInstanceOf} {allowMultiple} />
|
||||
Loading…
Add table
Add a link
Reference in a new issue