forked from MapComplete/MapComplete
Support for lexemes, decent etymology layer and theme with rudimentary icon
This commit is contained in:
parent
9726d85ad7
commit
9faac532b5
18 changed files with 611 additions and 270 deletions
|
@ -17,6 +17,7 @@ import {GeoOperations} from "../../Logic/GeoOperations";
|
|||
import {Unit} from "../../Models/Unit";
|
||||
import {FixedInputElement} from "./FixedInputElement";
|
||||
import WikidataSearchBox from "../Wikipedia/WikidataSearchBox";
|
||||
import Wikidata from "../../Logic/Web/Wikidata";
|
||||
|
||||
interface TextFieldDef {
|
||||
name: string,
|
||||
|
@ -153,20 +154,23 @@ export default class ValidatedTextField {
|
|||
if (str === undefined) {
|
||||
return false;
|
||||
}
|
||||
return (str.length > 1 && (str.startsWith("q") || str.startsWith("Q")) || str.startsWith("https://www.wikidata.org/wiki/Q"))
|
||||
if(str.length <= 2){
|
||||
return false;
|
||||
}
|
||||
return !str.split(";").some(str => Wikidata.ExtractKey(str) === undefined)
|
||||
},
|
||||
(str) => {
|
||||
if (str === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const wd = "https://www.wikidata.org/wiki/";
|
||||
if (str.startsWith(wd)) {
|
||||
str = str.substr(wd.length)
|
||||
let out = str.split(";").map(str => Wikidata.ExtractKey(str)).join("; ")
|
||||
if(str.endsWith(";")){
|
||||
out = out + ";"
|
||||
}
|
||||
return str.toUpperCase();
|
||||
return out;
|
||||
},
|
||||
(currentValue, inputHelperOptions) => {
|
||||
const args = inputHelperOptions.args
|
||||
const args = inputHelperOptions.args ?? []
|
||||
const searchKey = args[0] ?? "name"
|
||||
|
||||
let searchFor = <string>inputHelperOptions.feature?.properties[searchKey]?.toLowerCase()
|
||||
|
@ -175,7 +179,6 @@ export default class ValidatedTextField {
|
|||
if (searchFor !== undefined && options !== undefined) {
|
||||
const prefixes = <string[]>options["removePrefixes"]
|
||||
const postfixes = <string[]>options["removePostfixes"]
|
||||
|
||||
for (const postfix of postfixes ?? []) {
|
||||
if (searchFor.endsWith(postfix)) {
|
||||
searchFor = searchFor.substring(0, searchFor.length - postfix.length)
|
||||
|
|
|
@ -136,7 +136,7 @@ export default class TagRenderingQuestion extends Combine {
|
|||
options.cancelButton,
|
||||
saveButton,
|
||||
bottomTags])
|
||||
this.SetClass("question")
|
||||
this.SetClass("question disable-links")
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,8 +51,9 @@ export default class WikidataPreviewBox extends VariableUiElement {
|
|||
wikidata.id,
|
||||
Svg.wikidata_ui().SetStyle("width: 2.5rem").SetClass("block")
|
||||
]).SetClass("flex"),
|
||||
"https://wikidata.org/wiki/"+wikidata.id ,true)
|
||||
"https://wikidata.org/wiki/"+wikidata.id ,true).SetClass("must-link")
|
||||
|
||||
console.log(wikidata)
|
||||
let info = new Combine( [
|
||||
new Combine([Translation.fromMap(wikidata.labels).SetClass("font-bold"),
|
||||
link]).SetClass("flex justify-between"),
|
||||
|
|
|
@ -6,12 +6,10 @@ import {UIEventSource} from "../../Logic/UIEventSource";
|
|||
import Wikidata, {WikidataResponse} from "../../Logic/Web/Wikidata";
|
||||
import Locale from "../i18n/Locale";
|
||||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
import {FixedUiElement} from "../Base/FixedUiElement";
|
||||
import WikidataPreviewBox from "./WikidataPreviewBox";
|
||||
import Title from "../Base/Title";
|
||||
import WikipediaBox from "./WikipediaBox";
|
||||
import Svg from "../../Svg";
|
||||
import Link from "../Base/Link";
|
||||
|
||||
export default class WikidataSearchBox extends InputElement<string> {
|
||||
|
||||
|
@ -104,7 +102,7 @@ export default class WikidataSearchBox extends InputElement<string> {
|
|||
if (wid === undefined) {
|
||||
return undefined
|
||||
}
|
||||
return new WikipediaBox([wid]);
|
||||
return new WikipediaBox(wid.split(";"));
|
||||
})).SetStyle("max-height:12.5rem"),
|
||||
full
|
||||
]).ConstructElement();
|
||||
|
|
|
@ -22,7 +22,7 @@ export default class WikipediaBox extends Combine {
|
|||
|
||||
const mainContents = []
|
||||
|
||||
const pages = wikidataIds.map(wdId => WikipediaBox.createLinkedContent(wdId))
|
||||
const pages = wikidataIds.map(wdId => WikipediaBox.createLinkedContent(wdId.trim()))
|
||||
if (wikidataIds.length == 1) {
|
||||
const page = pages[0]
|
||||
mainContents.push(
|
||||
|
@ -88,6 +88,9 @@ export default class WikipediaBox extends Combine {
|
|||
|
||||
}
|
||||
const wikidata = <WikidataResponse>maybewikidata["success"]
|
||||
if(wikidata === undefined){
|
||||
return "failed"
|
||||
}
|
||||
if (wikidata.wikisites.size === 0) {
|
||||
return ["no page", wikidata]
|
||||
}
|
||||
|
@ -157,7 +160,7 @@ export default class WikipediaBox extends Combine {
|
|||
}
|
||||
return undefined
|
||||
}))
|
||||
.SetClass("flex items-center")
|
||||
.SetClass("flex items-center enable-links")
|
||||
|
||||
return {
|
||||
contents: contents,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue