More work on the custom theme generator, kindof works now
This commit is contained in:
parent
1fa6a8edfb
commit
ee9c9e201f
24 changed files with 1192 additions and 2265 deletions
|
@ -23,6 +23,7 @@ export default class HelpText extends UIElement {
|
|||
)
|
||||
))
|
||||
.ListenTo(currentSetting)
|
||||
.SetClass("small-button")
|
||||
.onClick(() => currentSetting.setData(undefined));
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ export class FromJSON {
|
|||
FromJSON.Layer(drinkingWater),
|
||||
FromJSON.Layer(ghostbikes),
|
||||
FromJSON.Layer(viewpoint),
|
||||
|
||||
];
|
||||
|
||||
for (const layer of sharedLayersList) {
|
||||
|
@ -44,7 +43,6 @@ export class FromJSON {
|
|||
}
|
||||
|
||||
public static LayoutFromJSON(json: LayoutConfigJson): Layout {
|
||||
console.log("Parsing ", json.id)
|
||||
const tr = FromJSON.Translation;
|
||||
|
||||
const layers = json.layers.map(FromJSON.Layer);
|
||||
|
@ -99,7 +97,7 @@ export class FromJSON {
|
|||
public static TagRenderingWithDefault(json: TagRenderingConfigJson | string, propertyName, defaultValue: string): TagDependantUIElementConstructor {
|
||||
if (json === undefined) {
|
||||
if(defaultValue !== undefined){
|
||||
console.warn(`Using default value ${defaultValue} for ${propertyName}`)
|
||||
console.log(`Using default value ${defaultValue} for ${propertyName}`)
|
||||
return FromJSON.TagRendering(defaultValue);
|
||||
}
|
||||
throw `Tagrendering ${propertyName} is undefined...`
|
||||
|
@ -138,7 +136,7 @@ export class FromJSON {
|
|||
let template = FromJSON.Translation(json.render);
|
||||
|
||||
let freeform = undefined;
|
||||
if (json.freeform?.key) {
|
||||
if (json.freeform?.key && json.freeform.key !== "") {
|
||||
// Setup the freeform
|
||||
if (template === undefined) {
|
||||
console.error("Freeform.key is defined, but render is not. This is not allowed.", json)
|
||||
|
@ -171,6 +169,7 @@ export class FromJSON {
|
|||
);
|
||||
|
||||
if(template === undefined && (mappings === undefined || mappings.length === 0)){
|
||||
console.error("Empty tagrendering detected: no mappings nor template given", json)
|
||||
throw "Empty tagrendering detected: no mappings nor template given"
|
||||
}
|
||||
|
||||
|
@ -182,7 +181,6 @@ export class FromJSON {
|
|||
});
|
||||
|
||||
if (json.condition) {
|
||||
console.log("Applying confition ", json.condition)
|
||||
return rendering.OnlyShowIf(FromJSON.Tag(json.condition));
|
||||
}
|
||||
|
||||
|
@ -205,7 +203,6 @@ export class FromJSON {
|
|||
if (split[1] === "*") {
|
||||
split[1] = ".*"
|
||||
}
|
||||
console.log(split)
|
||||
return new RegexTag(
|
||||
split[0],
|
||||
new RegExp("^" + split[1] + "$"),
|
||||
|
@ -244,16 +241,6 @@ export class FromJSON {
|
|||
}
|
||||
}
|
||||
|
||||
private static Title(json: string | Map<string, string> | TagRenderingConfigJson): TagDependantUIElementConstructor {
|
||||
if ((json as TagRenderingConfigJson).render !== undefined) {
|
||||
return FromJSON.TagRendering((json as TagRenderingConfigJson));
|
||||
} else if (typeof (json) === "string") {
|
||||
return new FixedText(Translations.WT(json));
|
||||
} else {
|
||||
return new FixedText(FromJSON.Translation(json as Map<string, string>));
|
||||
}
|
||||
}
|
||||
|
||||
public static Layer(json: LayerConfigJson | string): LayerDefinition {
|
||||
|
||||
if (typeof (json) === "string") {
|
||||
|
@ -265,8 +252,7 @@ export class FromJSON {
|
|||
throw "Layer not yet loaded..."
|
||||
}
|
||||
|
||||
|
||||
console.log("Parsing ", json.name);
|
||||
console.log("Parsing layer", json)
|
||||
const tr = FromJSON.Translation;
|
||||
const overpassTags = FromJSON.Tag(json.overpassTags);
|
||||
const icon = FromJSON.TagRenderingWithDefault(json.icon, "layericon", "./assets/bug.svg");
|
||||
|
@ -328,7 +314,7 @@ export class FromJSON {
|
|||
icon: icon.GetContent(renderTags).txt,
|
||||
overpassFilter: overpassTags,
|
||||
|
||||
title: FromJSON.Title(json.title),
|
||||
title: FromJSON.TagRendering(json.title),
|
||||
minzoom: json.minzoom,
|
||||
presets: presets,
|
||||
elementsToShow: json.tagRenderings?.map(FromJSON.TagRendering) ?? [],
|
||||
|
|
|
@ -39,7 +39,7 @@ export interface LayerConfigJson {
|
|||
/**
|
||||
* The title shown in a popup for elements of this layer
|
||||
*/
|
||||
title: string | any | TagRenderingConfigJson;
|
||||
title: string | TagRenderingConfigJson;
|
||||
|
||||
/**
|
||||
* The icon for an element.
|
||||
|
|
|
@ -348,6 +348,7 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
return false;
|
||||
}
|
||||
if (this._question === undefined ||
|
||||
this._question === "" ||
|
||||
(this._freeform?.template === undefined && (this._mapping?.length ?? 0) == 0)) {
|
||||
// We don't ask this question in the first place
|
||||
return false;
|
||||
|
@ -395,7 +396,6 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
InnerRender(): string {
|
||||
|
||||
if (this.IsQuestioning()
|
||||
|
@ -408,7 +408,7 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
new Combine([
|
||||
question.Render(),
|
||||
"<br/>",
|
||||
this._questionElement.Render(),
|
||||
this._questionElement,
|
||||
"<span class='login-button-friendly'>",
|
||||
this._friendlyLogin,
|
||||
"</span>",
|
||||
|
@ -434,28 +434,29 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
}
|
||||
|
||||
if (this.IsKnown()) {
|
||||
const html = this.RenderAnswer().Render();
|
||||
if (html === "") {
|
||||
|
||||
const answer = this.RenderAnswer();
|
||||
if(answer.IsEmpty()){
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
let editButton = "";
|
||||
let editButton;
|
||||
if (State.state === undefined || // state undefined -> we are custom testing
|
||||
State.state?.osmConnection?.userDetails?.data?.loggedIn && this._question !== undefined) {
|
||||
editButton = this._editButton.Render();
|
||||
editButton = this._editButton;
|
||||
}
|
||||
|
||||
return "<span class='answer'>" +
|
||||
"<span class='answer-text'>" + html + "</span>" +
|
||||
editButton +
|
||||
"</span>";
|
||||
return new Combine([
|
||||
"<span class='answer'>",
|
||||
"<span class='answer-text'>",
|
||||
answer,
|
||||
"</span>",
|
||||
editButton ?? "",
|
||||
"</span>"]).Render();
|
||||
}
|
||||
|
||||
console.log("No rendering for",this)
|
||||
|
||||
return "";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue