forked from MapComplete/MapComplete
Refactoring: use special rendering for mangrove key download in usersettings
This commit is contained in:
parent
3e46334767
commit
a3c249474d
7 changed files with 49 additions and 10 deletions
|
@ -1,18 +1,22 @@
|
|||
import Translations from "../i18n/Translations"
|
||||
import BaseUIElement from "../BaseUIElement"
|
||||
import { Store } from "../../Logic/UIEventSource"
|
||||
import { Utils } from "../../Utils"
|
||||
|
||||
export default class Link extends BaseUIElement {
|
||||
private readonly _href: string | Store<string>
|
||||
private readonly _embeddedShow: BaseUIElement
|
||||
private readonly _newTab: boolean
|
||||
private readonly _download: string
|
||||
|
||||
constructor(
|
||||
embeddedShow: BaseUIElement | string,
|
||||
href: string | Store<string>,
|
||||
newTab: boolean = false
|
||||
newTab: boolean = false,
|
||||
download: string = undefined
|
||||
) {
|
||||
super()
|
||||
this._download = download
|
||||
this._embeddedShow = Translations.W(embeddedShow)
|
||||
this._href = href
|
||||
this._newTab = newTab
|
||||
|
@ -58,6 +62,9 @@ export default class Link extends BaseUIElement {
|
|||
if (this._newTab) {
|
||||
el.target = "_blank"
|
||||
}
|
||||
if (this._download) {
|
||||
el.download = this._download
|
||||
}
|
||||
el.appendChild(embeddedShow)
|
||||
return el
|
||||
}
|
||||
|
|
|
@ -1155,19 +1155,24 @@ export default class SpecialVisualizations {
|
|||
name: "class",
|
||||
doc: "CSS-classes to add to the element",
|
||||
},
|
||||
{
|
||||
name: "download",
|
||||
doc: "If set, this link will act as a download-button. The contents of `href` will be offered for download; this parameter will act as the proposed filename",
|
||||
},
|
||||
],
|
||||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tagSource: UIEventSource<Record<string, string>>,
|
||||
args: string[]
|
||||
): BaseUIElement {
|
||||
const [text, href, classnames] = args
|
||||
const [text, href, classnames, download] = args
|
||||
return new VariableUiElement(
|
||||
tagSource.map((tags) =>
|
||||
new Link(
|
||||
Utils.SubstituteKeys(text, tags),
|
||||
Utils.SubstituteKeys(href, tags),
|
||||
true
|
||||
download === undefined,
|
||||
Utils.SubstituteKeys(download, tags)
|
||||
).SetClass(classnames)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -451,7 +451,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
*/
|
||||
public static SubstituteKeys(
|
||||
txt: string | undefined,
|
||||
tags?: Record<string, any>,
|
||||
tags: Record<string, any> | undefined,
|
||||
useLang?: string
|
||||
): string | undefined {
|
||||
if (txt === undefined) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue