forked from MapComplete/MapComplete
Chore: improve documentation and error messages
This commit is contained in:
parent
5095bffc50
commit
06a9fb3711
7 changed files with 26 additions and 19 deletions
|
@ -31,6 +31,7 @@ import MarkdownUtils from "../src/Utils/MarkdownUtils"
|
||||||
import { parse as parse_html } from "node-html-parser"
|
import { parse as parse_html } from "node-html-parser"
|
||||||
import { AvailableRasterLayers } from "../src/Models/RasterLayers"
|
import { AvailableRasterLayers } from "../src/Models/RasterLayers"
|
||||||
import { ImmutableStore } from "../src/Logic/UIEventSource"
|
import { ImmutableStore } from "../src/Logic/UIEventSource"
|
||||||
|
import * as unitUsage from "../Docs/Schemas/UnitConfigJson.schema.json"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a markdown-file into a .json file, which a walkthrough/slideshow element can use
|
* Converts a markdown-file into a .json file, which a walkthrough/slideshow element can use
|
||||||
|
@ -268,7 +269,12 @@ export class GenerateDocs extends Script {
|
||||||
|
|
||||||
private generateBuiltinUnits() {
|
private generateBuiltinUnits() {
|
||||||
const layer = new LayerConfig(<LayerConfigJson>unit, "units", true)
|
const layer = new LayerConfig(<LayerConfigJson>unit, "units", true)
|
||||||
const els: string[] = ["## " + layer.id]
|
const els: string[] = [
|
||||||
|
"# Units",
|
||||||
|
"## How to use",
|
||||||
|
unitUsage.description,
|
||||||
|
"Units ",
|
||||||
|
"## " + layer.id]
|
||||||
|
|
||||||
for (const unit of layer.units) {
|
for (const unit of layer.units) {
|
||||||
els.push("### " + unit.quantity)
|
els.push("### " + unit.quantity)
|
||||||
|
@ -295,8 +301,8 @@ export class GenerateDocs extends Script {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.WriteMarkdownFile("./Docs/builtin_units.md", ["# Units", ...els].join("\n\n"), [
|
this.WriteMarkdownFile("./Docs/builtin_units.md", els.join("\n\n"), [
|
||||||
`assets/layers/unit/unit.json`,
|
`assets/layers/unit/unit.json`, `src/Models/ThemeConfig/Json/UnitConfigJson.ts`
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ function generateLayerUsage(layer: LayerConfig): TagInfoPrototype[] {
|
||||||
const usesImageUpload = (tr.render?.txt?.indexOf("image_upload") ?? -2) > 0
|
const usesImageUpload = (tr.render?.txt?.indexOf("image_upload") ?? -2) > 0
|
||||||
|
|
||||||
if (usesImageCarousel || usesImageUpload) {
|
if (usesImageCarousel || usesImageUpload) {
|
||||||
const descrNoUpload = `Images are displayed based on the keys image, image:0, image:1,..., panoramax, panoramax:0, panoramx:1, ... , wikidata, wikipedia, wikimedia_commons and mapillary`
|
const descrNoUpload = `Images are displayed based on the keys image, image:0, image:1,..., panoramax, panoramax:0, panoramx:1, ... , wikidata, wikipedia, wikimedia_commons and mapillary`
|
||||||
const descrUpload = `${descrNoUpload} Furthermore, this layer shows images based on the keys panoramax, image, wikidata, wikipedia, wikimedia_commons and mapillary`
|
const descrUpload = `${descrNoUpload} Furthermore, this layer shows images based on the keys panoramax, image, wikidata, wikipedia, wikimedia_commons and mapillary`
|
||||||
|
|
||||||
const shownText = (usesImageUpload ? descrUpload : descrNoUpload) + condition
|
const shownText = (usesImageUpload ? descrUpload : descrNoUpload) + condition
|
||||||
|
|
|
@ -151,7 +151,11 @@ export class Each<X, Y> extends Conversion<X[], Y[]> {
|
||||||
values[i]?.["id"] !== undefined ? values[i]?.["id"] : ""
|
values[i]?.["id"] !== undefined ? values[i]?.["id"] : ""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const r = step.convert(values[i], c.enter(i))
|
let id = ""
|
||||||
|
if (values[i]?.["id"]) {
|
||||||
|
id = `(${values[i]?.["id"]})`
|
||||||
|
}
|
||||||
|
const r = step.convert(values[i], c.enter(i + id))
|
||||||
result.push(r)
|
result.push(r)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* In some cases, a value is represented in a certain unit (such as meters for heigt/distance/..., km/h for speed, ...)
|
* In some cases, a value is represented in a certain unit (such as meters for height/distance/..., km/h for speed, ...)
|
||||||
*
|
*
|
||||||
* Sometimes, multiple denominations are possible (e.g. km/h vs mile/h; megawatt vs kilowatt vs gigawatt for power generators, ...)
|
* Sometimes, multiple denominations are possible (e.g. km/h vs mile/h; megawatt vs kilowatt vs gigawatt for power generators, ...)
|
||||||
*
|
*
|
||||||
|
@ -14,9 +14,9 @@
|
||||||
*
|
*
|
||||||
* # Usage
|
* # Usage
|
||||||
*
|
*
|
||||||
* First of all, you define which keys have units applied, for example:
|
* First of all, you define which keys have units applied. This can be done centrally in the layer:
|
||||||
*
|
*
|
||||||
* ```
|
* ```json
|
||||||
* units: [
|
* units: [
|
||||||
* appliesTo: ["maxspeed", "maxspeed:hgv", "maxspeed:bus"]
|
* appliesTo: ["maxspeed", "maxspeed:hgv", "maxspeed:bus"]
|
||||||
* applicableUnits: [
|
* applicableUnits: [
|
||||||
|
|
|
@ -197,7 +197,7 @@ export default class TagRenderingConfig {
|
||||||
json.freeform.key,
|
json.freeform.key,
|
||||||
<any>Validators.availableTypes,
|
<any>Validators.availableTypes,
|
||||||
(s) => <any>s
|
(s) => <any>s
|
||||||
)}`
|
)}. See https://source.mapcomplete.org/MapComplete/MapComplete/src/branch/develop/Docs/SpecialInputElements.md for more information`
|
||||||
}
|
}
|
||||||
const type: ValidatorType = <any>json.freeform.type ?? "string"
|
const type: ValidatorType = <any>json.freeform.type ?? "string"
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default class OpeningHoursValidator extends Validator {
|
||||||
"opening_hours",
|
"opening_hours",
|
||||||
[
|
[
|
||||||
"Has extra elements to easily input when a POI is opened.",
|
"Has extra elements to easily input when a POI is opened.",
|
||||||
"### Helper arguments",
|
"#### Helper arguments",
|
||||||
"Only one helper argument named `options` can be provided. It is a JSON-object of type `{ prefix: string, postfix: string }`:",
|
"Only one helper argument named `options` can be provided. It is a JSON-object of type `{ prefix: string, postfix: string }`:",
|
||||||
MarkdownUtils.table(
|
MarkdownUtils.table(
|
||||||
["subarg", "doc"],
|
["subarg", "doc"],
|
||||||
|
@ -22,7 +22,7 @@ export default class OpeningHoursValidator extends Validator {
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
"### Example usage",
|
"#### Example usage",
|
||||||
"To add a conditional (based on time) access restriction:\n\n```\n" +
|
"To add a conditional (based on time) access restriction:\n\n```\n" +
|
||||||
`
|
`
|
||||||
"freeform": {
|
"freeform": {
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
import Combine from "../../Base/Combine"
|
|
||||||
import Wikidata, { WikidataResponse } from "../../../Logic/Web/Wikidata"
|
import Wikidata, { WikidataResponse } from "../../../Logic/Web/Wikidata"
|
||||||
import { Validator } from "../Validator"
|
import { Validator } from "../Validator"
|
||||||
import { Translation } from "../../i18n/Translation"
|
import { Translation } from "../../i18n/Translation"
|
||||||
import Translations from "../../i18n/Translations"
|
import Translations from "../../i18n/Translations"
|
||||||
import Title from "../../Base/Title"
|
|
||||||
import Table from "../../Base/Table"
|
|
||||||
import MarkdownUtils from "../../../Utils/MarkdownUtils"
|
import MarkdownUtils from "../../../Utils/MarkdownUtils"
|
||||||
|
|
||||||
export default class WikidataValidator extends Validator {
|
export default class WikidataValidator extends Validator {
|
||||||
public static readonly _searchCache = new Map<string, Promise<WikidataResponse[]>>()
|
public static readonly _searchCache = new Map<string, Promise<WikidataResponse[]>>()
|
||||||
|
|
||||||
public static docs = [
|
private static docs = [
|
||||||
"### Helper arguments",
|
"#### Helper arguments",
|
||||||
MarkdownUtils.table(
|
MarkdownUtils.table(
|
||||||
["name", "doc"],
|
["name", "doc"],
|
||||||
[
|
[
|
||||||
|
@ -25,7 +22,7 @@ export default class WikidataValidator extends Validator {
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
"#### Suboptions",
|
"##### Suboptions",
|
||||||
MarkdownUtils.table(
|
MarkdownUtils.table(
|
||||||
["subarg", "doc"],
|
["subarg", "doc"],
|
||||||
[
|
[
|
||||||
|
@ -50,7 +47,7 @@ export default class WikidataValidator extends Validator {
|
||||||
),
|
),
|
||||||
].join("\n\n")
|
].join("\n\n")
|
||||||
private static readonly docsExampleUsage: string =
|
private static readonly docsExampleUsage: string =
|
||||||
"### Example usage\n\n" +
|
"#### Example usage\n\n" +
|
||||||
`The following is the 'freeform'-part of a layer config which will trigger a search for the wikidata item corresponding with the name of the selected feature. It will also remove '-street', '-square', ... if found at the end of the name
|
`The following is the 'freeform'-part of a layer config which will trigger a search for the wikidata item corresponding with the name of the selected feature. It will also remove '-street', '-square', ... if found at the end of the name
|
||||||
|
|
||||||
\`\`\`json
|
\`\`\`json
|
||||||
|
@ -113,7 +110,7 @@ Another example is to search for species and trees:
|
||||||
return !str.split(";").some((str) => Wikidata.ExtractKey(str) === undefined)
|
return !str.split(";").some((str) => Wikidata.ExtractKey(str) === undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
getFeedback(s: string, _?: () => string): Translation | undefined {
|
getFeedback(s: string): Translation | undefined {
|
||||||
const t = Translations.t.validation.wikidata
|
const t = Translations.t.validation.wikidata
|
||||||
if (s === "") {
|
if (s === "") {
|
||||||
return t.empty
|
return t.empty
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue