diff --git a/Models/Constants.ts b/Models/Constants.ts index e7ec48ba9..71625ac88 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -2,7 +2,7 @@ import { Utils } from "../Utils"; export default class Constants { - public static vNumber = "0.7.5b"; + public static vNumber = "0.8.0"; // The user journey states thresholds when a new feature gets unlocked public static userJourney = { diff --git a/State.ts b/State.ts index 18fc3f972..8e4322d65 100644 --- a/State.ts +++ b/State.ts @@ -221,7 +221,7 @@ export default class State { this.backgroundLayerId = QueryParameters.GetQueryParameter("background", - layoutToUse.defaultBackgroundId ?? "osm", + layoutToUse?.defaultBackgroundId ?? "osm", "The id of the background layer to start with") } diff --git a/UI/Base/Button.ts b/UI/Base/Button.ts index 89364807b..e671e0979 100644 --- a/UI/Base/Button.ts +++ b/UI/Base/Button.ts @@ -1,39 +1,29 @@ import {UIElement} from "../UIElement"; -import Locale from "../i18n/Locale"; import Translations from "../i18n/Translations"; import BaseUIElement from "../BaseUIElement"; -export class Button extends UIElement { +export class Button extends BaseUIElement { private _text: BaseUIElement; private _onclick: () => void; - private _clss: string; - constructor(text: string | UIElement, onclick: (() => void), clss: string = "") { - super(Locale.language); + constructor(text: string | UIElement, onclick: (() => void)) { + super(); this._text = Translations.W(text); this._onclick = onclick; - if (clss !== "") { - - this._clss = "class='" + clss + "'"; - }else{ - this._clss = ""; - } } - - InnerRender(): string { - - return "
"; - } - - InnerUpdate(htmlElement: HTMLElement) { - super.InnerUpdate(htmlElement); - const self = this; - document.getElementById("button-"+this.id).onclick = function(){ - self._onclick(); + protected InnerConstructElement(): HTMLElement { + const el = this._text.ConstructElement(); + if(el === undefined){ + return undefined; } + const form = document.createElement("form") + const button = document.createElement("button") + button.type = "button" + button.appendChild(el) + button.onclick = this._onclick + form.appendChild(button) + return form; } } \ No newline at end of file diff --git a/UI/Base/Table.ts b/UI/Base/Table.ts new file mode 100644 index 000000000..f02f8c49d --- /dev/null +++ b/UI/Base/Table.ts @@ -0,0 +1,59 @@ +import BaseUIElement from "../BaseUIElement"; +import {Utils} from "../../Utils"; +import Translations from "../i18n/Translations"; + +export default class Table extends BaseUIElement { + + private readonly _header: BaseUIElement[]; + private readonly _contents: BaseUIElement[][]; + + constructor(header: (BaseUIElement | string)[], contents: (BaseUIElement | string)[][]) { + super(); + this._header = header.map(Translations.W); + this._contents = contents.map(row => row.map(Translations.W)); + } + + protected InnerConstructElement(): HTMLElement { + const table = document.createElement("table") + + const headerElems = Utils.NoNull((this._header ?? []).map(elems => elems.ConstructElement())) + if (headerElems.length > 0) { + + const tr = document.createElement("tr"); + headerElems.forEach(headerElem => { + const td = document.createElement("th") + td.appendChild(headerElem) + tr.appendChild(td) + }) + table.appendChild(tr) + } + + for (const row of this._contents) { + const tr = document.createElement("tr") + for (const elem of row) { + const htmlElem = elem.ConstructElement() + if (htmlElem === undefined) { + continue; + } + + const td = document.createElement("td") + td.appendChild(htmlElem) + tr.appendChild(td) + } + table.appendChild(tr) + } + + return table; + } + + AsMarkdown(): string { + + const headerMarkdownParts = this._header.map(hel => hel?.AsMarkdown() ?? " ") + const header =headerMarkdownParts.join(" | "); + const headerSep = headerMarkdownParts.map(part => '-'.repeat(part.length + 2)).join("|") + const table = this._contents.map(row => row.map(el => el.AsMarkdown()?? " ").join("|")).join("\n") + + return [header, headerSep, table, ""].join("\n") + } + +} \ No newline at end of file diff --git a/UI/BigComponents/LicensePicker.ts b/UI/BigComponents/LicensePicker.ts index f87d8c775..efdd6aafd 100644 --- a/UI/BigComponents/LicensePicker.ts +++ b/UI/BigComponents/LicensePicker.ts @@ -6,11 +6,11 @@ import {UIEventSource} from "../../Logic/UIEventSource"; export default class LicensePicker extends DropDown