Add small overview document for every layer

This commit is contained in:
Pieter Vander Vennet 2022-01-14 19:34:00 +01:00
parent eba52836b2
commit 77e9151095
41 changed files with 1325 additions and 2040 deletions

View file

@ -7,6 +7,11 @@ import {And} from "../../Logic/Tags/And";
import ValidatedTextField from "../../UI/Input/ValidatedTextField";
import {Utils} from "../../Utils";
import {Tag} from "../../Logic/Tags/Tag";
import BaseUIElement from "../../UI/BaseUIElement";
import Combine from "../../UI/Base/Combine";
import Title from "../../UI/Base/Title";
import Link from "../../UI/Base/Link";
import List from "../../UI/Base/List";
/***
* The parsed version of TagRenderingConfigJSON
@ -397,7 +402,7 @@ export default class TagRenderingConfig {
EnumerateTranslations(): Translation[] {
const translations: Translation[] = []
for (const key in this) {
if(!this.hasOwnProperty(key)){
if (!this.hasOwnProperty(key)) {
continue;
}
const o = this[key]
@ -420,5 +425,74 @@ export default class TagRenderingConfig {
return usedIcons;
}
FreeformValues(): { key: string, type?: string, values?: string [] } {
try {
const key = this.freeform?.key
if (key === undefined) {
let values: { k: string, v: string }[][] = Utils.NoNull(this.mappings?.map(m => m.if.asChange({})) ?? [])
if (values.length === 0) {
return;
}
const allKeys = values.map(arr => arr.map(o => o.k))
let common = allKeys[0];
for (const keyset of allKeys) {
common = common.filter(item => keyset.indexOf(item) >= 0)
}
const commonKey = common[0]
if (commonKey === undefined) {
return undefined;
}
return {
key: commonKey,
values: Utils.NoNull(values.map(arr => arr.filter(item => item.k === commonKey)[0]?.v))
}
}
let values = Utils.NoNull(this.mappings?.map(m => m.if.asChange({}).filter(item => item.k === key)[0]?.v) ?? [])
if (values.length === undefined) {
values = undefined
}
return {
key,
type: this.freeform.type,
values
}
} catch (e) {
console.error("Could not create FreeformValues for tagrendering", this.id)
return undefined
}
}
GenerateDocumentation(): BaseUIElement {
let withRender: (BaseUIElement | string)[] = [];
if (this.freeform?.key !== undefined) {
withRender = [
`This rendering asks information about the property `,
Link.OsmWiki(this.freeform.key),
`\nThis is rendered with \`${this.render.txt}\``
]
}
let mappings: BaseUIElement = undefined;
if (this.mappings !== undefined) {
mappings = new List(
this.mappings.map(m =>
"**" + m.then.txt + "** corresponds with " + m.if.asHumanString(true, false, {})
)
)
}
return new Combine([
new Title(this.id, 3),
this.question !== undefined ? "The question is **" + this.question.txt + "**" : "_This tagrendering has no question and is thus read-only_",
new Combine(withRender),
mappings
]).SetClass("flex-col");
}
}