forked from MapComplete/MapComplete
Add paragraph and wikipedia options
This commit is contained in:
parent
8b06ca77f9
commit
73cec987c9
4 changed files with 72 additions and 21 deletions
33
UI/Base/Paragraph.ts
Normal file
33
UI/Base/Paragraph.ts
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import BaseUIElement from "../BaseUIElement";
|
||||||
|
|
||||||
|
export class Paragraph extends BaseUIElement {
|
||||||
|
public readonly content: (string | BaseUIElement);
|
||||||
|
|
||||||
|
constructor(html: (string | BaseUIElement)) {
|
||||||
|
super();
|
||||||
|
this.content = html ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AsMarkdown(): string {
|
||||||
|
let c:string ;
|
||||||
|
if(typeof this.content !== "string"){
|
||||||
|
c = this.content.AsMarkdown()
|
||||||
|
}else{
|
||||||
|
c = this.content
|
||||||
|
}
|
||||||
|
return "\n\n"+c+"\n\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InnerConstructElement(): HTMLElement {
|
||||||
|
const e = document.createElement("p")
|
||||||
|
if(typeof this.content !== "string"){
|
||||||
|
e.appendChild(this.content.ConstructElement())
|
||||||
|
}else{
|
||||||
|
e.innerHTML = this.content
|
||||||
|
}
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -28,12 +28,12 @@ export default class WikidataPreviewBox extends VariableUiElement {
|
||||||
requires: WikidataPreviewBox.isHuman,
|
requires: WikidataPreviewBox.isHuman,
|
||||||
property: "P21",
|
property: "P21",
|
||||||
display: new Map([
|
display: new Map([
|
||||||
['Q6581097', () => Svg.gender_male_ui().SetStyle("width: 1rem; height: auto")],
|
['Q6581097', () => Svg.gender_male_svg().SetStyle("width: 1rem; height: auto")],
|
||||||
['Q6581072', () => Svg.gender_female_ui().SetStyle("width: 1rem; height: auto")],
|
['Q6581072', () => Svg.gender_female_svg().SetStyle("width: 1rem; height: auto")],
|
||||||
['Q1097630', () => Svg.gender_inter_ui().SetStyle("width: 1rem; height: auto")],
|
['Q1097630', () => Svg.gender_inter_svg().SetStyle("width: 1rem; height: auto")],
|
||||||
['Q1052281', () => Svg.gender_trans_ui().SetStyle("width: 1rem; height: auto")/*'transwomen'*/],
|
['Q1052281', () => Svg.gender_trans_svg().SetStyle("width: 1rem; height: auto")/*'transwomen'*/],
|
||||||
['Q2449503', () => Svg.gender_trans_ui().SetStyle("width: 1rem; height: auto")/*'transmen'*/],
|
['Q2449503', () => Svg.gender_trans_svg().SetStyle("width: 1rem; height: auto")/*'transmen'*/],
|
||||||
['Q48270', () => Svg.gender_queer_ui().SetStyle("width: 1rem; height: auto")]
|
['Q48270', () => Svg.gender_queer_svg().SetStyle("width: 1rem; height: auto")]
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -84,7 +84,7 @@ export default class WikidataPreviewBox extends VariableUiElement {
|
||||||
let link = new Link(
|
let link = new Link(
|
||||||
new Combine([
|
new Combine([
|
||||||
wikidata.id,
|
wikidata.id,
|
||||||
Svg.wikidata_ui().SetStyle("width: 2.5rem").SetClass("block")
|
Svg.wikidata_svg().SetStyle("width: 2.5rem").SetClass("block")
|
||||||
]).SetClass("flex"),
|
]).SetClass("flex"),
|
||||||
Wikidata.IdToArticle(wikidata.id), true)?.SetClass("must-link")
|
Wikidata.IdToArticle(wikidata.id), true)?.SetClass("must-link")
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,14 @@ import {FixedUiElement} from "../Base/FixedUiElement";
|
||||||
import Translations from "../i18n/Translations";
|
import Translations from "../i18n/Translations";
|
||||||
import Link from "../Base/Link";
|
import Link from "../Base/Link";
|
||||||
import WikidataPreviewBox from "./WikidataPreviewBox";
|
import WikidataPreviewBox from "./WikidataPreviewBox";
|
||||||
|
import {Paragraph} from "../Base/Paragraph";
|
||||||
|
|
||||||
export default class WikipediaBox extends Combine {
|
export default class WikipediaBox extends Combine {
|
||||||
|
|
||||||
|
public static configuration = {
|
||||||
|
onlyFirstParagaph: false,
|
||||||
|
addHeader: false
|
||||||
|
}
|
||||||
|
|
||||||
constructor(wikidataIds: string[]) {
|
constructor(wikidataIds: string[]) {
|
||||||
|
|
||||||
|
@ -27,9 +32,9 @@ export default class WikipediaBox extends Combine {
|
||||||
const page = pages[0]
|
const page = pages[0]
|
||||||
mainContents.push(
|
mainContents.push(
|
||||||
new Combine([
|
new Combine([
|
||||||
new Combine([Svg.wikipedia_ui()
|
new Combine([
|
||||||
.SetStyle("width: 1.5rem").SetClass("inline-block mr-3"), page.titleElement])
|
Svg.wikipedia_svg().SetStyle("width: 1.5rem").SetClass("inline-block mr-3"),
|
||||||
.SetClass("flex"),
|
page.titleElement]).SetClass("flex"),
|
||||||
page.linkElement
|
page.linkElement
|
||||||
]).SetClass("flex justify-between align-middle"),
|
]).SetClass("flex justify-between align-middle"),
|
||||||
)
|
)
|
||||||
|
@ -52,7 +57,7 @@ export default class WikipediaBox extends Combine {
|
||||||
}),
|
}),
|
||||||
0,
|
0,
|
||||||
{
|
{
|
||||||
leftOfHeader: Svg.wikipedia_ui().SetStyle("width: 1.5rem; align-self: center;").SetClass("mr-4"),
|
leftOfHeader: Svg.wikipedia_svg().SetStyle("width: 1.5rem; align-self: center;").SetClass("mr-4"),
|
||||||
styleHeader: header => header.SetClass("subtle-background").SetStyle("height: 3.3rem")
|
styleHeader: header => header.SetClass("subtle-background").SetStyle("height: 3.3rem")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -141,7 +146,7 @@ export default class WikipediaBox extends Combine {
|
||||||
return new Title(pagetitle, 3)
|
return new Title(pagetitle, 3)
|
||||||
}
|
}
|
||||||
//return new Title(Translations.t.general.wikipedia.wikipediaboxTitle.Clone(), 2)
|
//return new Title(Translations.t.general.wikipedia.wikipediaboxTitle.Clone(), 2)
|
||||||
return new Title(wikidataId, 3)
|
return new Link(new Title(wikidataId, 3), "https://www.wikidata.org/wiki/"+wikidataId, true)
|
||||||
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -150,13 +155,13 @@ export default class WikipediaBox extends Combine {
|
||||||
const [pagetitle, language] = state
|
const [pagetitle, language] = state
|
||||||
if (pagetitle === "no page") {
|
if (pagetitle === "no page") {
|
||||||
const wd = <WikidataResponse>state[1]
|
const wd = <WikidataResponse>state[1]
|
||||||
return new Link(Svg.pop_out_ui().SetStyle("width: 1.2rem").SetClass("block "),
|
return new Link(Svg.pop_out_svg().SetStyle("width: 1.2rem").SetClass("block "),
|
||||||
"https://www.wikidata.org/wiki/" + wd.id
|
"https://www.wikidata.org/wiki/" + wd.id
|
||||||
, true)
|
, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `https://${language}.wikipedia.org/wiki/${pagetitle}`
|
const url = `https://${language}.wikipedia.org/wiki/${pagetitle}`
|
||||||
return new Link(Svg.pop_out_ui().SetStyle("width: 1.2rem").SetClass("block "), url, true)
|
return new Link(Svg.pop_out_svg().SetStyle("width: 1.2rem").SetClass("block "), url, true)
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
}))
|
}))
|
||||||
|
@ -172,15 +177,14 @@ export default class WikipediaBox extends Combine {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the actual content in a scrollable way
|
* Returns the actual content in a scrollable way
|
||||||
* @param pagename
|
|
||||||
* @param language
|
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
private static createContents(pagename: string, language: string, wikidata: WikidataResponse): BaseUIElement {
|
private static createContents(pagename: string, language: string, wikidata: WikidataResponse): BaseUIElement {
|
||||||
const htmlContent = Wikipedia.GetArticle({
|
const wpOptions = {
|
||||||
pageName: pagename,
|
pageName: pagename,
|
||||||
language: language
|
language: language,
|
||||||
})
|
firstParagraphOnly: WikipediaBox.configuration.onlyFirstParagaph
|
||||||
|
}
|
||||||
|
const htmlContent = Wikipedia.GetArticle(wpOptions)
|
||||||
const wp = Translations.t.general.wikipedia
|
const wp = Translations.t.general.wikipedia
|
||||||
const quickFacts = WikidataPreviewBox.QuickFacts(wikidata);
|
const quickFacts = WikidataPreviewBox.QuickFacts(wikidata);
|
||||||
const contents: UIEventSource<string | BaseUIElement> = htmlContent.map(htmlContent => {
|
const contents: UIEventSource<string | BaseUIElement> = htmlContent.map(htmlContent => {
|
||||||
|
@ -189,7 +193,20 @@ export default class WikipediaBox extends Combine {
|
||||||
return new Loading(wp.loading.Clone())
|
return new Loading(wp.loading.Clone())
|
||||||
}
|
}
|
||||||
if (htmlContent["success"] !== undefined) {
|
if (htmlContent["success"] !== undefined) {
|
||||||
return new FixedUiElement(htmlContent["success"]).SetClass("wikipedia-article")
|
let content: BaseUIElement = new FixedUiElement(htmlContent["success"]);
|
||||||
|
if(WikipediaBox.configuration.addHeader){
|
||||||
|
content = new Combine(
|
||||||
|
[
|
||||||
|
new Paragraph(
|
||||||
|
new Link(wp.fromWikipedia, Wikipedia.getPageUrl(wpOptions), true),
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
content
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return content.SetClass("wikipedia-article")
|
||||||
}
|
}
|
||||||
if (htmlContent["error"]) {
|
if (htmlContent["error"]) {
|
||||||
console.warn("Loading wikipage failed due to", htmlContent["error"])
|
console.warn("Loading wikipage failed due to", htmlContent["error"])
|
||||||
|
|
|
@ -247,6 +247,7 @@
|
||||||
"createNewWikidata": "Create a new Wikidata item",
|
"createNewWikidata": "Create a new Wikidata item",
|
||||||
"doSearch": "Search above to see results",
|
"doSearch": "Search above to see results",
|
||||||
"failed": "Loading the Wikipedia entry failed",
|
"failed": "Loading the Wikipedia entry failed",
|
||||||
|
"fromWikipedia": "From Wikipedia, the free encyclopedia",
|
||||||
"loading": "Loading Wikipedia...",
|
"loading": "Loading Wikipedia...",
|
||||||
"noResults": "Nothing found for <i>{search}</i>",
|
"noResults": "Nothing found for <i>{search}</i>",
|
||||||
"noWikipediaPage": "This Wikidata item has no corresponding Wikipedia page yet.",
|
"noWikipediaPage": "This Wikidata item has no corresponding Wikipedia page yet.",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue