forked from MapComplete/MapComplete
Way to much fixes and improvements
This commit is contained in:
parent
e68d9d99a5
commit
5ed0bb431c
41 changed files with 1244 additions and 402 deletions
48
Customizations/HelpText.ts
Normal file
48
Customizations/HelpText.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import {UIElement} from "../UI/UIElement";
|
||||
import {SubtleButton} from "../UI/Base/SubtleButton";
|
||||
import {VariableUiElement} from "../UI/Base/VariableUIElement";
|
||||
import SingleSetting from "../UI/CustomGenerator/SingleSetting";
|
||||
import Combine from "../UI/Base/Combine";
|
||||
import {UIEventSource} from "../Logic/UIEventSource";
|
||||
|
||||
export default class HelpText extends UIElement {
|
||||
|
||||
private helpText: UIElement;
|
||||
private returnButton: UIElement;
|
||||
|
||||
constructor(currentSetting: UIEventSource<SingleSetting<any>>) {
|
||||
super();
|
||||
this.returnButton = new SubtleButton("./assets/close.svg",
|
||||
new VariableUiElement(
|
||||
currentSetting.map(currentSetting => {
|
||||
if (currentSetting === undefined) {
|
||||
return "";
|
||||
}
|
||||
return "Return to general help";
|
||||
}
|
||||
)
|
||||
))
|
||||
.ListenTo(currentSetting)
|
||||
.onClick(() => currentSetting.setData(undefined));
|
||||
|
||||
|
||||
this.helpText = new VariableUiElement(currentSetting.map((setting: SingleSetting<any>) => {
|
||||
if (setting === undefined) {
|
||||
return "<h1>Welcome to the Custom Theme Builder</h1>" +
|
||||
"Here, one can make their own custom mapcomplete themes.<br/>" +
|
||||
"Fill out the fields to get a working mapcomplete theme. More information on the selected field will appear here when you click it";
|
||||
}
|
||||
|
||||
return new Combine(["<h1>", setting._name, "</h1>", setting._description.Render()]).Render();
|
||||
}))
|
||||
|
||||
|
||||
}
|
||||
|
||||
InnerRender(): string {
|
||||
return new Combine([this.helpText,
|
||||
this.returnButton,
|
||||
]).Render();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import {Layout} from "../Layout";
|
||||
import {LayoutConfigJson} from "./LayoutConfigJson";
|
||||
import {AndOrTagConfigJson} from "./TagConfigJson";
|
||||
import {And, RegexTag, Tag, TagsFilter} from "../../Logic/Tags";
|
||||
import {And, Or, RegexTag, Tag, TagsFilter} from "../../Logic/Tags";
|
||||
import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
|
||||
import {TagRenderingOptions} from "../TagRenderingOptions";
|
||||
import Translation from "../../UI/i18n/Translation";
|
||||
|
@ -81,9 +81,14 @@ export class FromJSON {
|
|||
return json;
|
||||
}
|
||||
const tr = {};
|
||||
let keyCount = 0;
|
||||
for (let key in json) {
|
||||
keyCount ++;
|
||||
tr[key] = json[key]; // I'm doing this wrong, I know
|
||||
}
|
||||
if(keyCount == 0){
|
||||
return undefined;
|
||||
}
|
||||
return new Translation(tr);
|
||||
}
|
||||
|
||||
|
@ -92,14 +97,14 @@ export class FromJSON {
|
|||
}
|
||||
|
||||
public static TagRenderingWithDefault(json: TagRenderingConfigJson | string, propertyName, defaultValue: string): TagDependantUIElementConstructor {
|
||||
if (json === undefined) {
|
||||
if (json === undefined) {
|
||||
if(defaultValue !== undefined){
|
||||
console.warn(`Using default value ${defaultValue} for ${propertyName}`)
|
||||
return FromJSON.TagRendering(defaultValue);
|
||||
}
|
||||
throw `Tagrendering ${propertyName} is undefined...`
|
||||
}
|
||||
|
||||
|
||||
if (typeof json === "string") {
|
||||
|
||||
switch (json) {
|
||||
|
@ -133,26 +138,27 @@ export class FromJSON {
|
|||
let template = FromJSON.Translation(json.render);
|
||||
|
||||
let freeform = undefined;
|
||||
if (json.freeform) {
|
||||
|
||||
if(json.render === undefined){
|
||||
console.error("Freeform is defined, but render is not. This is not allowed.", json)
|
||||
if (json.freeform?.key) {
|
||||
// Setup the freeform
|
||||
if (template === undefined) {
|
||||
console.error("Freeform.key is defined, but render is not. This is not allowed.", json)
|
||||
throw "Freeform is defined, but render is not. This is not allowed."
|
||||
}
|
||||
|
||||
|
||||
freeform = {
|
||||
template: `$${json.freeform.type ?? "string"}$`,
|
||||
renderTemplate: template,
|
||||
key: json.freeform.key
|
||||
};
|
||||
if (json.freeform.addExtraTags) {
|
||||
freeform["extraTags"] = FromJSON.Tag(json.freeform.addExtraTags);
|
||||
freeform.extraTags = new And(json.freeform.addExtraTags.map(FromJSON.SimpleTag))
|
||||
}
|
||||
} else if (json.render) {
|
||||
// Template (aka rendering) is defined, but freeform.key is not. We allow an input as string
|
||||
freeform = {
|
||||
template: `$string$`,
|
||||
template: undefined, // Template to ask is undefined -> we block asking for this key
|
||||
renderTemplate: template,
|
||||
key: "id"
|
||||
key: "id" // every object always has an id
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,6 +169,10 @@ export class FromJSON {
|
|||
hideInAnswer: mapping.hideInAnswer
|
||||
})
|
||||
);
|
||||
|
||||
if(template === undefined && (mappings === undefined || mappings.length === 0)){
|
||||
throw "Empty tagrendering detected: no mappings nor template given"
|
||||
}
|
||||
|
||||
|
||||
let rendering = new TagRenderingOptions({
|
||||
|
@ -185,6 +195,9 @@ export class FromJSON {
|
|||
}
|
||||
|
||||
public static Tag(json: AndOrTagConfigJson | string): TagsFilter {
|
||||
if(json === undefined){
|
||||
throw "Error while parsing a tag: nothing defined. Make sure all the tags are defined and at least one tag is present in a complex expression"
|
||||
}
|
||||
if (typeof (json) == "string") {
|
||||
const tag = json as string;
|
||||
if (tag.indexOf("!~") >= 0) {
|
||||
|
@ -227,7 +240,7 @@ export class FromJSON {
|
|||
return new And(json.and.map(FromJSON.Tag));
|
||||
}
|
||||
if (json.or !== undefined) {
|
||||
return new And(json.or.map(FromJSON.Tag));
|
||||
return new Or(json.or.map(FromJSON.Tag));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,7 +283,8 @@ export class FromJSON {
|
|||
}) ?? [];
|
||||
|
||||
function style(tags) {
|
||||
const iconSizeStr = iconSize.GetContent(tags).txt.split(",");
|
||||
const iconSizeStr =
|
||||
iconSize.GetContent(tags).txt.split(",");
|
||||
const iconwidth = Number(iconSizeStr[0]);
|
||||
const iconheight = Number(iconSizeStr[1]);
|
||||
const iconmode = iconSizeStr[2];
|
||||
|
|
|
@ -66,7 +66,7 @@ export interface LayerConfigJson {
|
|||
* Wayhandling: should a way/area be displayed as:
|
||||
* 0) The way itself
|
||||
* 1) The centerpoint and the way
|
||||
* 2) Only the centerpoint?
|
||||
* 2) Only the centerpoint
|
||||
*/
|
||||
wayHandling?: number;
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
export interface AndOrTagConfigJson {
|
||||
|
||||
and?: (string | AndOrTagConfigJson)[]
|
||||
or?: (string | AndOrTagConfigJson)[]
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ export interface TagRenderingConfigJson {
|
|||
* If a value is added with the textfield, these extra tag is addded.
|
||||
* Usefull to add a 'fixme=freeform textfield used - to be checked'
|
||||
**/
|
||||
addExtraTags?: AndOrTagConfigJson | string;
|
||||
addExtraTags?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -127,12 +127,13 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
|
||||
// Prepare the actual input element -> pick an appropriate implementation
|
||||
|
||||
this._questionElement = this.InputElementFor(options);
|
||||
this._questionElement = this.InputElementFor(options) ??
|
||||
new FixedInputElement<TagsFilter>("<span class='alert'>No input possible</span>", new Tag("a","b"));
|
||||
const save = () => {
|
||||
const selection = self._questionElement.GetValue().data;
|
||||
console.log("Tagrendering: saving tags ", selection);
|
||||
if (selection) {
|
||||
State.state.changes.addTag(tags.data.id, selection);
|
||||
State.state?.changes?.addTag(tags.data.id, selection);
|
||||
}
|
||||
self._editMode.setData(false);
|
||||
}
|
||||
|
@ -143,7 +144,7 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
if (tags === undefined) {
|
||||
return Translations.t.general.noTagsSelected.SetClass("subtle").Render();
|
||||
}
|
||||
const csCount = State.state.osmConnection.userDetails.data.csCount;
|
||||
const csCount = State.state?.osmConnection?.userDetails?.data?.csCount ?? 1000;
|
||||
if (csCount < State.userJourney.tagsVisibleAt) {
|
||||
return "";
|
||||
}
|
||||
|
@ -154,7 +155,7 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
return tags.asHumanString(true, true);
|
||||
}
|
||||
)
|
||||
);
|
||||
).ListenTo(self._questionElement);
|
||||
|
||||
const cancel = () => {
|
||||
self._questionSkipped.setData(true);
|
||||
|
@ -246,7 +247,7 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
|
||||
|
||||
private InputForFreeForm(freeform): InputElement<TagsFilter> {
|
||||
if (freeform === undefined) {
|
||||
if (freeform?.template === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
@ -269,8 +270,14 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
if (!isValid(string, this._source.data._country)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
const tag = new Tag(freeform.key, formatter(string, this._source.data._country));
|
||||
|
||||
|
||||
if (tag.value.length > 255) {
|
||||
return undefined; // Toolong
|
||||
}
|
||||
|
||||
if (freeform.extraTags === undefined) {
|
||||
return tag;
|
||||
}
|
||||
|
@ -340,7 +347,8 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
if (this.IsKnown()) {
|
||||
return false;
|
||||
}
|
||||
if (this._question === undefined) {
|
||||
if (this._question === undefined ||
|
||||
(this._freeform?.template === undefined && (this._mapping?.length ?? 0) == 0)) {
|
||||
// We don't ask this question in the first place
|
||||
return false;
|
||||
}
|
||||
|
@ -390,15 +398,20 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
|
||||
InnerRender(): string {
|
||||
|
||||
if (this.IsQuestioning() && !State.state?.osmConnection?.userDetails?.data?.loggedIn) {
|
||||
if (this.IsQuestioning()
|
||||
&& (State.state !== undefined) // If State.state is undefined, we are testing/custom theme building -> show regular save
|
||||
&& !State.state.osmConnection.userDetails.data.loggedIn) {
|
||||
|
||||
const question =
|
||||
this.ApplyTemplate(this._question).SetClass('question-text');
|
||||
return "<div class='question'>" +
|
||||
new Combine([
|
||||
question,
|
||||
question.Render(),
|
||||
"<br/>",
|
||||
this._questionElement.Render(),
|
||||
"<span class='login-button-friendly'>" + this._friendlyLogin.Render() + "</span>",
|
||||
"<span class='login-button-friendly'>",
|
||||
this._friendlyLogin,
|
||||
"</span>",
|
||||
]).Render() + "</div>";
|
||||
}
|
||||
|
||||
|
@ -428,7 +441,8 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
|
||||
|
||||
let editButton = "";
|
||||
if (State.state?.osmConnection?.userDetails?.data?.loggedIn && this._question !== undefined) {
|
||||
if (State.state === undefined || // state undefined -> we are custom testing
|
||||
State.state?.osmConnection?.userDetails?.data?.loggedIn && this._question !== undefined) {
|
||||
editButton = this._editButton.Render();
|
||||
}
|
||||
|
||||
|
@ -438,6 +452,8 @@ TagRendering extends UIElement implements TagDependantUIElement {
|
|||
"</span>";
|
||||
}
|
||||
|
||||
console.log("No rendering for",this)
|
||||
|
||||
return "";
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue