forked from MapComplete/MapComplete
Full code cleanup
This commit is contained in:
parent
8e6ee8c87f
commit
bd21212eba
246 changed files with 19418 additions and 11729 deletions
|
@ -3,26 +3,25 @@ import {VariableUiElement} from "./VariableUIElement";
|
|||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import Loading from "./Loading";
|
||||
|
||||
export default class AsyncLazy extends BaseUIElement{
|
||||
export default class AsyncLazy extends BaseUIElement {
|
||||
private readonly _f: () => Promise<BaseUIElement>;
|
||||
|
||||
|
||||
constructor(f: () => Promise<BaseUIElement>) {
|
||||
super();
|
||||
this._f = f;
|
||||
}
|
||||
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
// The caching of the BaseUIElement will guarantee that _f will only be called once
|
||||
|
||||
|
||||
return new VariableUiElement(
|
||||
UIEventSource.FromPromise(this._f()).map(el => {
|
||||
if(el === undefined){
|
||||
if (el === undefined) {
|
||||
return new Loading()
|
||||
}
|
||||
return el
|
||||
})
|
||||
|
||||
).ConstructElement()
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -30,13 +30,13 @@ export default class Combine extends BaseUIElement {
|
|||
if (subEl === undefined || subEl === null) {
|
||||
continue;
|
||||
}
|
||||
try{
|
||||
|
||||
const subHtml = subEl.ConstructElement()
|
||||
if (subHtml !== undefined) {
|
||||
el.appendChild(subHtml)
|
||||
}
|
||||
}catch(e){
|
||||
try {
|
||||
|
||||
const subHtml = subEl.ConstructElement()
|
||||
if (subHtml !== undefined) {
|
||||
el.appendChild(subHtml)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Could not generate subelement in combine due to ", e)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ export default class Img extends BaseUIElement {
|
|||
fallbackImage?: string
|
||||
}) {
|
||||
super();
|
||||
if(src === undefined || src === "undefined"){
|
||||
if (src === undefined || src === "undefined") {
|
||||
throw "Undefined src for image"
|
||||
}
|
||||
this._src = src;
|
||||
|
@ -44,7 +44,7 @@ export default class Img extends BaseUIElement {
|
|||
}
|
||||
el.onerror = () => {
|
||||
if (self._options?.fallbackImage) {
|
||||
if(el.src === self._options.fallbackImage){
|
||||
if (el.src === self._options.fallbackImage) {
|
||||
// Sigh... nothing to be done anymore
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import BaseUIElement from "../BaseUIElement";
|
||||
|
||||
export default class Lazy extends BaseUIElement{
|
||||
export default class Lazy extends BaseUIElement {
|
||||
private readonly _f: () => BaseUIElement;
|
||||
|
||||
|
||||
constructor(f: () => BaseUIElement) {
|
||||
super();
|
||||
this._f = f;
|
||||
}
|
||||
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
// The caching of the BaseUIElement will guarantee that _f will only be called once
|
||||
return this._f().ConstructElement();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
import {FixedUiElement} from "./FixedUiElement";
|
||||
import {Translation} from "../i18n/Translation";
|
||||
import Combine from "./Combine";
|
||||
import Svg from "../../Svg";
|
||||
|
@ -6,11 +5,11 @@ import Translations from "../i18n/Translations";
|
|||
|
||||
export default class Loading extends Combine {
|
||||
constructor(msg?: Translation | string) {
|
||||
const t = Translations.T(msg ) ?? Translations.t.general.loading.Clone();
|
||||
const t = Translations.T(msg) ?? Translations.t.general.loading.Clone();
|
||||
t.SetClass("pl-2")
|
||||
super([
|
||||
Svg.loading_svg().SetClass("animate-spin").SetStyle("width: 1.5rem; height: 1.5rem;"),
|
||||
t
|
||||
t
|
||||
])
|
||||
this.SetClass("flex p-1")
|
||||
}
|
||||
|
|
|
@ -17,8 +17,10 @@ export interface MinimapOptions {
|
|||
}
|
||||
|
||||
export interface MinimapObj {
|
||||
readonly leafletMap: UIEventSource<any>,
|
||||
installBounds(factor: number | BBox, showRange?: boolean) : void
|
||||
readonly leafletMap: UIEventSource<any>,
|
||||
|
||||
installBounds(factor: number | BBox, showRange?: boolean): void
|
||||
|
||||
TakeScreenshot(): Promise<any>;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,12 @@ export default class MinimapImplementation extends BaseUIElement implements Mini
|
|||
})
|
||||
}
|
||||
|
||||
public async TakeScreenshot() {
|
||||
const screenshotter = new SimpleMapScreenshoter();
|
||||
screenshotter.addTo(this.leafletMap.data);
|
||||
return await screenshotter.takeScreen('image')
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
const div = document.createElement("div")
|
||||
div.id = this._id;
|
||||
|
@ -148,8 +154,8 @@ export default class MinimapImplementation extends BaseUIElement implements Mini
|
|||
const self = this;
|
||||
let currentLayer = this._background.data.layer()
|
||||
let latLon = <[number, number]>[location.data?.lat ?? 0, location.data?.lon ?? 0]
|
||||
if(isNaN(latLon[0]) || isNaN(latLon[1])){
|
||||
latLon = [0,0]
|
||||
if (isNaN(latLon[0]) || isNaN(latLon[1])) {
|
||||
latLon = [0, 0]
|
||||
}
|
||||
const options = {
|
||||
center: latLon,
|
||||
|
@ -279,10 +285,4 @@ export default class MinimapImplementation extends BaseUIElement implements Mini
|
|||
|
||||
this.leafletMap.setData(map)
|
||||
}
|
||||
|
||||
public async TakeScreenshot(){
|
||||
const screenshotter = new SimpleMapScreenshoter();
|
||||
screenshotter.addTo(this.leafletMap.data);
|
||||
return await screenshotter.takeScreen('image')
|
||||
}
|
||||
}
|
|
@ -19,8 +19,8 @@ import Img from "./Img";
|
|||
export default class ScrollableFullScreen extends UIElement {
|
||||
private static readonly empty = new FixedUiElement("");
|
||||
private static _currentlyOpen: ScrollableFullScreen;
|
||||
private hashToShow: string;
|
||||
public isShown: UIEventSource<boolean>;
|
||||
private hashToShow: string;
|
||||
private _component: BaseUIElement;
|
||||
private _fullscreencomponent: BaseUIElement;
|
||||
|
||||
|
@ -61,13 +61,6 @@ export default class ScrollableFullScreen extends UIElement {
|
|||
})
|
||||
}
|
||||
|
||||
private clear() {
|
||||
ScrollableFullScreen.empty.AttachTo("fullscreen")
|
||||
const fs = document.getElementById("fullscreen");
|
||||
ScrollableFullScreen._currentlyOpen?.isShown?.setData(false);
|
||||
fs.classList.add("hidden")
|
||||
}
|
||||
|
||||
InnerRender(): BaseUIElement {
|
||||
return this._component;
|
||||
}
|
||||
|
@ -80,6 +73,13 @@ export default class ScrollableFullScreen extends UIElement {
|
|||
fs.classList.remove("hidden")
|
||||
}
|
||||
|
||||
private clear() {
|
||||
ScrollableFullScreen.empty.AttachTo("fullscreen")
|
||||
const fs = document.getElementById("fullscreen");
|
||||
ScrollableFullScreen._currentlyOpen?.isShown?.setData(false);
|
||||
fs.classList.add("hidden")
|
||||
}
|
||||
|
||||
private BuildComponent(title: BaseUIElement, content: BaseUIElement, isShown: UIEventSource<boolean>) {
|
||||
const returnToTheMap =
|
||||
new Combine([
|
||||
|
|
|
@ -6,7 +6,7 @@ import {VariableUiElement} from "./VariableUIElement";
|
|||
|
||||
export class TabbedComponent extends Combine {
|
||||
|
||||
constructor(elements: { header: BaseUIElement | string, content: BaseUIElement | string }[],
|
||||
constructor(elements: { header: BaseUIElement | string, content: BaseUIElement | string }[],
|
||||
openedTab: (UIEventSource<number> | number) = 0,
|
||||
options?: {
|
||||
leftOfHeader?: BaseUIElement
|
||||
|
@ -15,13 +15,13 @@ export class TabbedComponent extends Combine {
|
|||
|
||||
const openedTabSrc = typeof (openedTab) === "number" ? new UIEventSource(openedTab) : (openedTab ?? new UIEventSource<number>(0))
|
||||
|
||||
const tabs: BaseUIElement[] = [options?.leftOfHeader ]
|
||||
const tabs: BaseUIElement[] = [options?.leftOfHeader]
|
||||
const contentElements: BaseUIElement[] = [];
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
let element = elements[i];
|
||||
const header = Translations.W(element.header).onClick(() => openedTabSrc.setData(i))
|
||||
openedTabSrc.addCallbackAndRun(selected => {
|
||||
if(selected >= elements.length){
|
||||
if (selected >= elements.length) {
|
||||
selected = 0
|
||||
}
|
||||
if (selected === i) {
|
||||
|
@ -40,7 +40,7 @@ export class TabbedComponent extends Combine {
|
|||
}
|
||||
|
||||
const header = new Combine(tabs).SetClass("tabs-header-bar")
|
||||
if(options?.styleHeader){
|
||||
if (options?.styleHeader) {
|
||||
options.styleHeader(header)
|
||||
}
|
||||
const actualContent = new VariableUiElement(
|
||||
|
|
|
@ -7,9 +7,9 @@ export default class Title extends BaseUIElement {
|
|||
|
||||
constructor(embedded: string | BaseUIElement, level: number = 3) {
|
||||
super()
|
||||
if(typeof embedded === "string"){
|
||||
this._embedded = new FixedUiElement(embedded)
|
||||
}else{
|
||||
if (typeof embedded === "string") {
|
||||
this._embedded = new FixedUiElement(embedded)
|
||||
} else {
|
||||
this._embedded = embedded
|
||||
}
|
||||
this._level = level;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue