forked from MapComplete/MapComplete
Refactoring: cleanup of no longer necessary code
This commit is contained in:
parent
afb94ecefb
commit
d7b83e0d88
8 changed files with 4 additions and 113 deletions
|
@ -208,10 +208,6 @@ export default class DetermineTheme {
|
|||
private static async LoadRemoteTheme(link: string): Promise<ThemeConfig | null> {
|
||||
console.log("Downloading map theme from ", link)
|
||||
|
||||
new FixedUiElement(`Downloading the theme from the <a href="${link}">link</a>...`).AttachTo(
|
||||
"maindiv"
|
||||
)
|
||||
|
||||
let parsed = <ThemeConfigJson>await Utils.downloadJson(link)
|
||||
let forcedId = parsed.id
|
||||
const url = new URL(link)
|
||||
|
|
|
@ -25,10 +25,6 @@ export default class Combine extends BaseUIElement {
|
|||
}
|
||||
}
|
||||
|
||||
public getElements(): BaseUIElement[] {
|
||||
return this.uiElements
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
const el = document.createElement("span")
|
||||
try {
|
||||
|
|
|
@ -45,11 +45,6 @@ export default class SvelteUIElement<
|
|||
this._slots = slots
|
||||
}
|
||||
|
||||
public setSpan() {
|
||||
this.tag = "span"
|
||||
return this
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
const el = document.createElement(this.tag)
|
||||
new this._svelteComponent({
|
||||
|
|
|
@ -13,33 +13,7 @@ export default abstract class BaseUIElement {
|
|||
protected readonly clss: Set<string> = new Set<string>()
|
||||
protected style: string
|
||||
private _onClick: () => void | Promise<void>
|
||||
AttachTo(divId: string) {
|
||||
const element = document.getElementById(divId)
|
||||
if (element === null) {
|
||||
if (Utils.runningFromConsole) {
|
||||
this.ConstructElement()
|
||||
return
|
||||
}
|
||||
throw "SEVERE: could not attach UIElement to " + divId
|
||||
}
|
||||
|
||||
let alreadyThere = false
|
||||
const elementToAdd = this.ConstructElement()
|
||||
const childs = Array.from(element.childNodes)
|
||||
for (const child of childs) {
|
||||
if (child === elementToAdd) {
|
||||
alreadyThere = true
|
||||
continue
|
||||
}
|
||||
element.removeChild(child)
|
||||
}
|
||||
|
||||
if (elementToAdd !== undefined && !alreadyThere) {
|
||||
element.appendChild(elementToAdd)
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
/**
|
||||
* Adds all the relevant classes, space separated
|
||||
*/
|
||||
|
|
|
@ -22,8 +22,6 @@ import { And } from "../../Logic/Tags/And"
|
|||
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"
|
||||
import TagRenderingEditable from "./TagRendering/TagRenderingEditable.svelte"
|
||||
import AllTagsPanel from "./AllTagsPanel/AllTagsPanel.svelte"
|
||||
import { FixedUiElement } from "../Base/FixedUiElement"
|
||||
import { TagUtils } from "../../Logic/Tags/TagUtils"
|
||||
import CollectionTimes from "../CollectionTimes/CollectionTimes.svelte"
|
||||
|
||||
class DirectionIndicatorVis extends SpecialVisualization {
|
||||
|
@ -293,47 +291,6 @@ class AllTagsVis extends SpecialVisualizationSvelte {
|
|||
}
|
||||
}
|
||||
|
||||
class TagsVis extends SpecialVisualization {
|
||||
funcName = "tags"
|
||||
docs = "Shows a (json of) tags in a human-readable way + links to the wiki"
|
||||
|
||||
args = [
|
||||
{
|
||||
name: "key",
|
||||
type: "key",
|
||||
defaultValue: "value",
|
||||
doc: "The key to look for the tags",
|
||||
},
|
||||
]
|
||||
|
||||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tagSource: UIEventSource<Record<string, string>>,
|
||||
argument: string[],
|
||||
): BaseUIElement {
|
||||
const key = argument[0] ?? "value"
|
||||
return new VariableUiElement(
|
||||
tagSource.map((tags) => {
|
||||
let value = tags[key]
|
||||
if (!value) {
|
||||
return new FixedUiElement("No tags found").SetClass("font-bold")
|
||||
}
|
||||
if (typeof value === "string" && value.startsWith("{")) {
|
||||
value = JSON.parse(value)
|
||||
}
|
||||
try {
|
||||
const parsed = TagUtils.Tag(value)
|
||||
return parsed.asHumanString(true, false, {})
|
||||
} catch (e) {
|
||||
return new FixedUiElement(
|
||||
"Could not parse this tag: " + JSON.stringify(value) + " due to " + e,
|
||||
).SetClass("alert")
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class PointsInTimeVis extends SpecialVisualization {
|
||||
docs = "Creates a visualisation for 'points in time', e.g. collection times of a postbox"
|
||||
group = "data"
|
||||
|
@ -372,7 +329,6 @@ export class DataVisualisations {
|
|||
new PresetDescription(),
|
||||
new PresetTypeSelect(),
|
||||
new AllTagsVis(),
|
||||
new TagsVis(),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import BaseUIElement from "../../BaseUIElement"
|
|||
import { ImportFlowUtils } from "./ImportFlow"
|
||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
|
||||
import SvelteUIElement from "../../Base/SvelteUIElement"
|
||||
import { FixedUiElement } from "../../Base/FixedUiElement"
|
||||
import WayImportFlow from "./WayImportFlow.svelte"
|
||||
import WayImportFlowState, { WayImportFlowArguments } from "./WayImportFlowState"
|
||||
import { Utils } from "../../../Utils"
|
||||
|
@ -70,8 +69,7 @@ export default class WayImportButtonViz extends SpecialVisualization implements
|
|||
): BaseUIElement {
|
||||
const geometry = feature.geometry
|
||||
if (!(geometry.type == "LineString" || geometry.type === "Polygon")) {
|
||||
console.error("Invalid type to import", geometry.type)
|
||||
return new FixedUiElement("Invalid geometry type:" + geometry.type).SetClass("alert")
|
||||
throw "Invalid type to import " + geometry.type
|
||||
}
|
||||
const args: WayImportFlowArguments = <any>Utils.ParseVisArgs(this.args, argument)
|
||||
const tagsToApply = ImportFlowUtils.getTagsToApply(tagSource, args)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import { FixedUiElement } from "../Base/FixedUiElement"
|
||||
import { Translation, TypedTranslation } from "./Translation"
|
||||
import BaseUIElement from "../BaseUIElement"
|
||||
import CompiledTranslations from "../../assets/generated/CompiledTranslations"
|
||||
import LanguageUtils from "../../Utils/LanguageUtils"
|
||||
import { Store } from "../../Logic/UIEventSource"
|
||||
|
@ -12,31 +10,7 @@ export default class Translations {
|
|||
static readonly t: Readonly<typeof CompiledTranslations.t> = CompiledTranslations.t
|
||||
private static knownLanguages = LanguageUtils.usedLanguages
|
||||
|
||||
constructor() {
|
||||
throw "Translations is static. If you want to intitialize a new translation, use the singular form"
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public static W(s: string | number | boolean | BaseUIElement): BaseUIElement {
|
||||
if (typeof s === "string") {
|
||||
return new FixedUiElement(s)
|
||||
}
|
||||
if (typeof s === "number") {
|
||||
return new FixedUiElement("" + s).SetClass("font-bold")
|
||||
}
|
||||
if (typeof s === "boolean") {
|
||||
return new FixedUiElement("" + s).SetClass("font-bold")
|
||||
}
|
||||
if (typeof s === "object") {
|
||||
if (s.ConstructElement) {
|
||||
return s
|
||||
}
|
||||
const v = JSON.stringify(s)
|
||||
return new FixedUiElement(v).SetClass("literal-code")
|
||||
}
|
||||
return s
|
||||
private constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,6 +11,8 @@ async function main() {
|
|||
console.error("Huh? Couldn't remove child!")
|
||||
}
|
||||
try {
|
||||
|
||||
document.getElementById("maindiv").innerHTML = "<div class='w-full flex justify-center my-16'>Loading map...</div>"
|
||||
const theme = await DetermineTheme.getTheme()
|
||||
new SingleThemeGui({
|
||||
target,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue