forked from MapComplete/MapComplete
Merge branch 'develop' into feature/maproulette
This commit is contained in:
commit
1ce88c18c5
194 changed files with 755275 additions and 38277 deletions
|
@ -95,9 +95,32 @@ export class AddContextToTranslations<T> extends DesugaringStep<T> {
|
|||
* ]
|
||||
* }
|
||||
* rewritten // => expected
|
||||
*
|
||||
*
|
||||
* // Should ignore all if '#dont-translate' is set
|
||||
* const theme = {
|
||||
* "#dont-translate": "*",
|
||||
* layers: [
|
||||
* {
|
||||
* builtin: ["abc"],
|
||||
* override: {
|
||||
* title:{
|
||||
* en: "Some title"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* const rewritten = new AddContextToTranslations<any>("prefix:").convert(theme, "context").result
|
||||
* rewritten // => theme
|
||||
*
|
||||
*/
|
||||
convert(json: T, context: string): { result: T; errors?: string[]; warnings?: string[]; information?: string[] } {
|
||||
|
||||
if(json["#dont-translate"] === "*"){
|
||||
return {result: json}
|
||||
}
|
||||
|
||||
const result = Utils.WalkJson(json, (leaf, path) => {
|
||||
if(leaf === undefined || leaf === null){
|
||||
return leaf
|
||||
|
|
|
@ -141,17 +141,21 @@ export class Each<X, Y> extends Conversion<X[], Y[]> {
|
|||
|
||||
export class On<P, T> extends DesugaringStep<T> {
|
||||
private readonly key: string;
|
||||
private readonly step: Conversion<P, P>;
|
||||
private readonly step: ((t: T) => Conversion<P, P>);
|
||||
|
||||
constructor(key: string, step: Conversion<P, P>) {
|
||||
constructor(key: string, step: Conversion<P, P> | ((t: T )=> Conversion<P, P>)) {
|
||||
super("Applies " + step.name + " onto property `"+key+"`", [key], `On(${key}, ${step.name})`);
|
||||
this.step = step;
|
||||
if(typeof step === "function"){
|
||||
this.step = step;
|
||||
}else{
|
||||
this.step = _ => step
|
||||
}
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
convert(json: T, context: string): { result: T; errors?: string[]; warnings?: string[], information?: string[] } {
|
||||
json = {...json}
|
||||
const step = this.step
|
||||
const step = this.step(json)
|
||||
const key = this.key;
|
||||
const value: P = json[key]
|
||||
if (value === undefined || value === null) {
|
||||
|
|
|
@ -16,7 +16,7 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
|
|||
super([
|
||||
"Advanced conversion which deducts a layer showing all notes that are 'importable' (i.e. a note that contains a link to some MapComplete theme, with hash '#import').",
|
||||
"The import buttons and matches will be based on the presets of the given theme",
|
||||
].join("\n\n"), [],"CreateNoteImportLayer")
|
||||
].join("\n\n"), [], "CreateNoteImportLayer")
|
||||
this._includeClosedNotesDays = includeClosedNotesDays;
|
||||
}
|
||||
|
||||
|
@ -43,18 +43,18 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
|
|||
|
||||
const pointRenderings = (layerJson.mapRendering ?? []).filter(r => r !== null && r["location"] !== undefined);
|
||||
const firstRender = <PointRenderingConfigJson>(pointRenderings [0])
|
||||
if(firstRender === undefined){
|
||||
throw `Layer ${layerJson.id} does not have a pointRendering: `+context
|
||||
if (firstRender === undefined) {
|
||||
throw `Layer ${layerJson.id} does not have a pointRendering: ` + context
|
||||
}
|
||||
const title = layer.presets[0].title
|
||||
|
||||
const importButton = {}
|
||||
{
|
||||
const translations = trs(t.importButton,{layerId: layer.id, title: layer.presets[0].title})
|
||||
const translations = trs(t.importButton, {layerId: layer.id, title: layer.presets[0].title})
|
||||
for (const key in translations) {
|
||||
if(key !== "_context"){
|
||||
if (key !== "_context") {
|
||||
importButton[key] = "{" + translations[key] + "}"
|
||||
}else{
|
||||
} else {
|
||||
importButton[key] = translations[key]
|
||||
}
|
||||
}
|
||||
|
@ -68,19 +68,19 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
|
|||
result["_context"] = translation.context
|
||||
return result
|
||||
}
|
||||
|
||||
function tr(translation: Translation){
|
||||
return{ ...translation.translations, "_context": translation.context}
|
||||
|
||||
function tr(translation: Translation) {
|
||||
return {...translation.translations, "_context": translation.context}
|
||||
}
|
||||
|
||||
function trs<T>(translation: TypedTranslation<T>, subs: T) : object{
|
||||
function trs<T>(translation: TypedTranslation<T>, subs: T): object {
|
||||
return {...translation.Subs(subs).translations, "_context": translation.context}
|
||||
}
|
||||
|
||||
const result: LayerConfigJson = {
|
||||
"id": "note_import_" + layer.id,
|
||||
// By disabling the name, the import-layers won't pollute the filter view "name": t.layerName.Subs({title: layer.title.render}).translations,
|
||||
"description": trs(t.description , {title: layer.title.render}),
|
||||
"description": trs(t.description, {title: layer.title.render}),
|
||||
"source": {
|
||||
"osmTags": {
|
||||
"and": [
|
||||
|
@ -93,7 +93,7 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
|
|||
},
|
||||
"minzoom": Math.min(12, layerJson.minzoom - 2),
|
||||
"title": {
|
||||
"render": trs( t.popupTitle, {title})
|
||||
"render": trs(t.popupTitle, {title})
|
||||
},
|
||||
"calculatedTags": [
|
||||
"_first_comment=feat.get('comments')[0].text.toLowerCase()",
|
||||
|
@ -103,22 +103,10 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
|
|||
"_tags=(() => {let lines = feat.get('comments')[0].text.split('\\n').map(l => l.trim()); lines.splice(0, feat.get('_trigger_index') + 1); lines = lines.filter(l => l != ''); return lines.join(';');})()"
|
||||
],
|
||||
"isShown": {
|
||||
"render": "no",
|
||||
"mappings": [
|
||||
{
|
||||
"if": "comments!~.*https://mapcomplete.osm.be.*",
|
||||
"then": "no"
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
and:
|
||||
["_trigger_index~*",
|
||||
{or: isShownIfAny}
|
||||
]
|
||||
},
|
||||
"then": "yes"
|
||||
}
|
||||
]
|
||||
and:
|
||||
["_trigger_index~*",
|
||||
{or: isShownIfAny}
|
||||
]
|
||||
},
|
||||
"titleIcons": [
|
||||
{
|
||||
|
@ -165,9 +153,9 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
|
|||
"render": "{add_image_to_note()}"
|
||||
},
|
||||
{
|
||||
"id":"nearby_images",
|
||||
"id": "nearby_images",
|
||||
render: tr(t.nearbyImagesIntro)
|
||||
|
||||
|
||||
}
|
||||
],
|
||||
"mapRendering": [
|
||||
|
|
|
@ -12,10 +12,12 @@ import {AddContextToTranslations} from "./AddContextToTranslations";
|
|||
|
||||
class ExpandTagRendering extends Conversion<string | TagRenderingConfigJson | { builtin: string | string[], override: any }, TagRenderingConfigJson[]> {
|
||||
private readonly _state: DesugaringContext;
|
||||
private readonly _self: LayerConfigJson;
|
||||
|
||||
constructor(state: DesugaringContext) {
|
||||
constructor(state: DesugaringContext, self: LayerConfigJson) {
|
||||
super("Converts a tagRenderingSpec into the full tagRendering, e.g. by substituting the tagRendering by the shared-question", [], "ExpandTagRendering");
|
||||
this._state = state;
|
||||
this._self = self;
|
||||
}
|
||||
|
||||
convert(json: string | TagRenderingConfigJson | { builtin: string | string[]; override: any }, context: string): { result: TagRenderingConfigJson[]; errors: string[]; warnings: string[] } {
|
||||
|
@ -33,42 +35,50 @@ class ExpandTagRendering extends Conversion<string | TagRenderingConfigJson | {
|
|||
if (state.tagRenderings.has(name)) {
|
||||
return [state.tagRenderings.get(name)]
|
||||
}
|
||||
if (name.indexOf(".") >= 0) {
|
||||
const spl = name.split(".");
|
||||
const layer = state.sharedLayers.get(spl[0])
|
||||
if (spl.length === 2 && layer !== undefined) {
|
||||
const id = spl[1];
|
||||
if (name.indexOf(".") < 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const spl = name.split(".");
|
||||
let layer = state.sharedLayers.get(spl[0])
|
||||
if (spl[0] === this._self.id) {
|
||||
layer = this._self
|
||||
}
|
||||
|
||||
const layerTrs = <TagRenderingConfigJson[]>layer.tagRenderings.filter(tr => tr["id"] !== undefined)
|
||||
let matchingTrs: TagRenderingConfigJson[]
|
||||
if (id === "*") {
|
||||
matchingTrs = layerTrs
|
||||
} else if (id.startsWith("*")) {
|
||||
const id_ = id.substring(1)
|
||||
matchingTrs = layerTrs.filter(tr => tr.group === id_ || tr.labels?.indexOf(id_) >= 0)
|
||||
} else {
|
||||
matchingTrs = layerTrs.filter(tr => tr.id === id)
|
||||
}
|
||||
if (spl.length !== 2 || layer === undefined) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const id = spl[1];
|
||||
|
||||
const layerTrs = <TagRenderingConfigJson[]>layer.tagRenderings.filter(tr => tr["id"] !== undefined)
|
||||
let matchingTrs: TagRenderingConfigJson[]
|
||||
if (id === "*") {
|
||||
matchingTrs = layerTrs
|
||||
} else if (id.startsWith("*")) {
|
||||
const id_ = id.substring(1)
|
||||
matchingTrs = layerTrs.filter(tr => tr.group === id_ || tr.labels?.indexOf(id_) >= 0)
|
||||
} else {
|
||||
matchingTrs = layerTrs.filter(tr => tr.id === id)
|
||||
}
|
||||
|
||||
|
||||
const contextWriter = new AddContextToTranslations<TagRenderingConfigJson>("layers:")
|
||||
for (let i = 0; i < matchingTrs.length; i++) {
|
||||
// The matched tagRenderings are 'stolen' from another layer. This means that they must match the layer condition before being shown
|
||||
let found : TagRenderingConfigJson = Utils.Clone(matchingTrs[i]);
|
||||
if (found.condition === undefined) {
|
||||
found.condition = layer.source.osmTags
|
||||
} else {
|
||||
found.condition = {and: [found.condition, layer.source.osmTags]}
|
||||
}
|
||||
|
||||
found = contextWriter.convertStrict(found, layer.id+ ".tagRenderings."+found["id"])
|
||||
matchingTrs[i] = found
|
||||
}
|
||||
|
||||
if (matchingTrs.length !== 0) {
|
||||
return matchingTrs
|
||||
}
|
||||
const contextWriter = new AddContextToTranslations<TagRenderingConfigJson>("layers:")
|
||||
for (let i = 0; i < matchingTrs.length; i++) {
|
||||
// The matched tagRenderings are 'stolen' from another layer. This means that they must match the layer condition before being shown
|
||||
let found: TagRenderingConfigJson = Utils.Clone(matchingTrs[i]);
|
||||
if (found.condition === undefined) {
|
||||
found.condition = layer.source.osmTags
|
||||
} else {
|
||||
found.condition = {and: [found.condition, layer.source.osmTags]}
|
||||
}
|
||||
|
||||
found = contextWriter.convertStrict(found, layer.id + ".tagRenderings." + found["id"])
|
||||
matchingTrs[i] = found
|
||||
}
|
||||
|
||||
if (matchingTrs.length !== 0) {
|
||||
return matchingTrs
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
@ -86,7 +96,7 @@ class ExpandTagRendering extends Conversion<string | TagRenderingConfigJson | {
|
|||
const lookup = this.lookup(tr);
|
||||
if (lookup === undefined) {
|
||||
const isTagRendering = ctx.indexOf("On(mapRendering") < 0
|
||||
if(isTagRendering){
|
||||
if (isTagRendering) {
|
||||
warnings.push(ctx + "A literal rendering was detected: " + tr)
|
||||
}
|
||||
return [{
|
||||
|
@ -114,13 +124,26 @@ class ExpandTagRendering extends Conversion<string | TagRenderingConfigJson | {
|
|||
for (const name of names) {
|
||||
const lookup = this.lookup(name)
|
||||
if (lookup === undefined) {
|
||||
let candidates = Array.from(state.tagRenderings.keys())
|
||||
if(name.indexOf(".") > 0){
|
||||
const [layer, search] = name.split(".")
|
||||
candidates = Utils.NoNull( state.sharedLayers.get(layer).tagRenderings.map(tr => tr["id"])).map(id => layer+"."+id)
|
||||
let candidates = Array.from(state.tagRenderings.keys())
|
||||
if (name.indexOf(".") > 0) {
|
||||
const [layerName, search] = name.split(".")
|
||||
let layer = state.sharedLayers.get(layerName)
|
||||
if (layerName === this._self.id) {
|
||||
layer = this._self;
|
||||
}
|
||||
if (layer === undefined) {
|
||||
const candidates = Utils.sortedByLevenshteinDistance(layerName, Array.from(state.sharedLayers.keys()), s => s)
|
||||
if(state.sharedLayers.size === 0){
|
||||
warnings.push(ctx + ": BOOTSTRAPPING. Rerun generate layeroverview. While reusing tagrendering: " + name + ": layer " + layerName + " not found. Maybe you meant on of " + candidates.slice(0, 3).join(", "))
|
||||
}else{
|
||||
errors.push(ctx + ": While reusing tagrendering: " + name + ": layer " + layerName + " not found. Maybe you meant on of " + candidates.slice(0, 3).join(", "))
|
||||
}
|
||||
continue
|
||||
}
|
||||
candidates = Utils.NoNull(layer.tagRenderings.map(tr => tr["id"])).map(id => layerName + "." + id)
|
||||
}
|
||||
candidates = Utils.sortedByLevenshteinDistance(name, candidates, i => i);
|
||||
errors.push(ctx + ": The tagRendering with identifier " + name + " was not found.\n\tDid you mean one of " +candidates.join(", ") + "?")
|
||||
errors.push(ctx + ": The tagRendering with identifier " + name + " was not found.\n\tDid you mean one of " + candidates.join(", ") + "?")
|
||||
continue
|
||||
}
|
||||
for (let foundTr of lookup) {
|
||||
|
@ -168,7 +191,7 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
|
|||
* "someKey": "somevalue {xyz}"
|
||||
* }
|
||||
* ExpandRewrite.RewriteParts("{xyz}", "rewritten", spec) // => {"someKey": "somevalue rewritten"}
|
||||
*
|
||||
*
|
||||
* // should substitute all occurances in strings
|
||||
* const spec = {
|
||||
* "someKey": "The left|right side has {key:left|right}"
|
||||
|
@ -187,8 +210,8 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
|
|||
|
||||
if (typeof obj === "string") {
|
||||
// This is a simple string - we do a simple replace
|
||||
while(obj.indexOf(keyToRewrite) >= 0){
|
||||
obj = obj.replace(keyToRewrite, target)
|
||||
while (obj.indexOf(keyToRewrite) >= 0) {
|
||||
obj = obj.replace(keyToRewrite, target)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
@ -199,17 +222,17 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
|
|||
|
||||
if (typeof obj === "object") {
|
||||
obj = {...obj}
|
||||
|
||||
|
||||
const isTr = targetIsTranslation && Translations.isProbablyATranslation(obj)
|
||||
|
||||
|
||||
for (const key in obj) {
|
||||
let subtarget = target
|
||||
if(isTr && target[key] !== undefined){
|
||||
if (isTr && target[key] !== undefined) {
|
||||
// The target is a translation AND the current object is a translation
|
||||
// This means we should recursively replace with the translated value
|
||||
subtarget = target[key]
|
||||
}
|
||||
|
||||
|
||||
obj[key] = replaceRecursive(obj[key], subtarget)
|
||||
}
|
||||
return obj
|
||||
|
@ -233,7 +256,7 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
|
|||
* renderings: "The value of xyz is abc"
|
||||
* }
|
||||
* new ExpandRewrite().convertStrict(spec, "test") // => ["The value of X is A", "The value of Y is B", "The value of Z is C"]
|
||||
*
|
||||
*
|
||||
* // should rewrite with translations
|
||||
* const spec = <RewritableConfigJson<any>>{
|
||||
* rewrite: {
|
||||
|
@ -287,9 +310,9 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
|
|||
{// sanity check: {rewrite: ["a", "b"] should have the right amount of 'intos' in every case
|
||||
for (let i = 0; i < rewrite.rewrite.into.length; i++) {
|
||||
const into = keysToRewrite.into[i]
|
||||
if(into.length !== rewrite.rewrite.sourceString.length){
|
||||
throw `${context}.into.${i} Error in rewrite: there are ${rewrite.rewrite.sourceString.length} keys to rewrite, but entry ${i} has only ${into.length} values`
|
||||
|
||||
if (into.length !== rewrite.rewrite.sourceString.length) {
|
||||
throw `${context}.into.${i} Error in rewrite: there are ${rewrite.rewrite.sourceString.length} keys to rewrite, but entry ${i} has only ${into.length} values`
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -315,50 +338,50 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
|
|||
*/
|
||||
export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||
constructor() {
|
||||
super("Converts a 'special' translation into a regular translation which uses parameters", ["special"],"RewriteSpecial");
|
||||
super("Converts a 'special' translation into a regular translation which uses parameters", ["special"], "RewriteSpecial");
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the heavy lifting and conversion
|
||||
*
|
||||
*
|
||||
* // should not do anything if no 'special'-key is present
|
||||
* RewriteSpecial.convertIfNeeded({"en": "xyz", "nl": "abc"}, [], "test") // => {"en": "xyz", "nl": "abc"}
|
||||
*
|
||||
*
|
||||
* // should handle a simple special case
|
||||
* RewriteSpecial.convertIfNeeded({"special": {"type":"image_carousel"}}, [], "test") // => {'*': "{image_carousel()}"}
|
||||
*
|
||||
*
|
||||
* // should handle special case with a parameter
|
||||
* RewriteSpecial.convertIfNeeded({"special": {"type":"image_carousel", "image_key": "some_image_key"}}, [], "test") // => {'*': "{image_carousel(some_image_key)}"}
|
||||
*
|
||||
*
|
||||
* // should handle special case with a translated parameter
|
||||
* const spec = {"special": {"type":"image_upload", "label": {"en": "Add a picture to this object", "nl": "Voeg een afbeelding toe"}}}
|
||||
* const r = RewriteSpecial.convertIfNeeded(spec, [], "test")
|
||||
* r // => {"en": "{image_upload(,Add a picture to this object)}", "nl": "{image_upload(,Voeg een afbeelding toe)}" }
|
||||
*
|
||||
*
|
||||
* // should handle special case with a prefix and postfix
|
||||
* const spec = {"special": {"type":"image_upload" }, before: {"en": "PREFIX "}, after: {"en": " POSTFIX", nl: " Achtervoegsel"} }
|
||||
* const r = RewriteSpecial.convertIfNeeded(spec, [], "test")
|
||||
* r // => {"en": "PREFIX {image_upload(,)} POSTFIX", "nl": "PREFIX {image_upload(,)} Achtervoegsel" }
|
||||
*
|
||||
*
|
||||
* // should warn for unexpected keys
|
||||
* const errors = []
|
||||
* RewriteSpecial.convertIfNeeded({"special": {type: "image_carousel"}, "en": "xyz"}, errors, "test") // => {'*': "{image_carousel()}"}
|
||||
* errors // => ["At test: Unexpected key in a special block: en"]
|
||||
*
|
||||
*
|
||||
* // should give an error on unknown visualisations
|
||||
* const errors = []
|
||||
* RewriteSpecial.convertIfNeeded({"special": {type: "qsdf"}}, errors, "test") // => undefined
|
||||
* errors.length // => 1
|
||||
* errors[0].indexOf("Special visualisation 'qsdf' not found") >= 0 // => true
|
||||
*
|
||||
*
|
||||
* // should give an error is 'type' is missing
|
||||
* const errors = []
|
||||
* RewriteSpecial.convertIfNeeded({"special": {}}, errors, "test") // => undefined
|
||||
* errors // => ["A 'special'-block should define 'type' to indicate which visualisation should be used"]
|
||||
*/
|
||||
private static convertIfNeeded(input: (object & {special : {type: string}}) | any, errors: string[], context: string): any {
|
||||
private static convertIfNeeded(input: (object & { special: { type: string } }) | any, errors: string[], context: string): any {
|
||||
const special = input["special"]
|
||||
if(special === undefined){
|
||||
if (special === undefined) {
|
||||
return input
|
||||
}
|
||||
|
||||
|
@ -367,17 +390,17 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
|||
}
|
||||
|
||||
const type = special["type"]
|
||||
if(type === undefined){
|
||||
if (type === undefined) {
|
||||
errors.push("A 'special'-block should define 'type' to indicate which visualisation should be used")
|
||||
return undefined
|
||||
}
|
||||
const vis = SpecialVisualizations.specialVisualizations.find(sp => sp.funcName === type)
|
||||
if(vis === undefined){
|
||||
if (vis === undefined) {
|
||||
const options = Utils.sortedByLevenshteinDistance(type, SpecialVisualizations.specialVisualizations, sp => sp.funcName)
|
||||
errors.push(`Special visualisation '${type}' not found. Did you perhaps mean ${options[0].funcName}, ${options[1].funcName} or ${options[2].funcName}?\n\tFor all known special visualisations, please see https://github.com/pietervdvn/MapComplete/blob/develop/Docs/SpecialRenderings.md`)
|
||||
return undefined
|
||||
}
|
||||
|
||||
|
||||
const argNamesList = vis.args.map(a => a.name)
|
||||
const argNames = new Set<string>(argNamesList)
|
||||
// Check for obsolete and misspelled arguments
|
||||
|
@ -385,21 +408,21 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
|||
.filter(k => !argNames.has(k))
|
||||
.filter(k => k !== "type")
|
||||
.map(wrongArg => {
|
||||
const byDistance = Utils.sortedByLevenshteinDistance(wrongArg, argNamesList, x => x)
|
||||
return `Unexpected argument with name '${wrongArg}'. Did you mean ${byDistance[0]}?\n\tAll known arguments are ${ argNamesList.join(", ")}` ;
|
||||
}))
|
||||
|
||||
const byDistance = Utils.sortedByLevenshteinDistance(wrongArg, argNamesList, x => x)
|
||||
return `Unexpected argument with name '${wrongArg}'. Did you mean ${byDistance[0]}?\n\tAll known arguments are ${argNamesList.join(", ")}`;
|
||||
}))
|
||||
|
||||
// Check that all obligated arguments are present. They are obligated if they don't have a preset value
|
||||
for (const arg of vis.args) {
|
||||
if (arg.required !== true) {
|
||||
continue;
|
||||
}
|
||||
const param = special[arg.name]
|
||||
if(param === undefined){
|
||||
if (param === undefined) {
|
||||
errors.push(`Obligated parameter '${arg.name}' not found`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const foundLanguages = new Set<string>()
|
||||
const translatedArgs = argNamesList.map(nm => special[nm])
|
||||
.filter(v => v !== undefined)
|
||||
|
@ -407,25 +430,26 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
|||
for (const translatedArg of translatedArgs) {
|
||||
for (const ln of Object.keys(translatedArg)) {
|
||||
foundLanguages.add(ln)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const before = Translations.T(input.before)
|
||||
const after = Translations.T(input.after)
|
||||
|
||||
for (const ln of Object.keys(before?.translations??{})) {
|
||||
for (const ln of Object.keys(before?.translations ?? {})) {
|
||||
foundLanguages.add(ln)
|
||||
}
|
||||
for (const ln of Object.keys(after?.translations??{})) {
|
||||
for (const ln of Object.keys(after?.translations ?? {})) {
|
||||
foundLanguages.add(ln)
|
||||
}
|
||||
|
||||
if(foundLanguages.size === 0){
|
||||
const args= argNamesList.map(nm => special[nm] ?? "").join(",")
|
||||
return {'*': `{${type}(${args})}`
|
||||
if (foundLanguages.size === 0) {
|
||||
const args = argNamesList.map(nm => special[nm] ?? "").join(",")
|
||||
return {
|
||||
'*': `{${type}(${args})}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const result = {}
|
||||
const languages = Array.from(foundLanguages)
|
||||
languages.sort()
|
||||
|
@ -433,9 +457,9 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
|||
const args = []
|
||||
for (const argName of argNamesList) {
|
||||
const v = special[argName] ?? ""
|
||||
if(Translations.isProbablyATranslation(v)){
|
||||
if (Translations.isProbablyATranslation(v)) {
|
||||
args.push(new Translation(v).textFor(ln))
|
||||
}else{
|
||||
} else {
|
||||
args.push(v)
|
||||
}
|
||||
}
|
||||
|
@ -459,7 +483,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
|||
* const result = new RewriteSpecial().convert(tr,"test").result
|
||||
* const expected = {render: {'*': "{image_carousel(image)}"}, mappings: [{if: "other_image_key", then: {'*': "{image_carousel(other_image_key)}"}} ]}
|
||||
* result // => expected
|
||||
*
|
||||
*
|
||||
* const tr = {
|
||||
* render: {special: {type: "image_carousel", image_key: "image"}, before: {en: "Some introduction"} },
|
||||
* }
|
||||
|
@ -470,20 +494,20 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
|||
convert(json: TagRenderingConfigJson, context: string): { result: TagRenderingConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } {
|
||||
const errors = []
|
||||
json = Utils.Clone(json)
|
||||
const paths : {path: string[], type?: any, typeHint?: string}[] = tagrenderingconfigmeta["default"] ?? tagrenderingconfigmeta
|
||||
const paths: { path: string[], type?: any, typeHint?: string }[] = tagrenderingconfigmeta["default"] ?? tagrenderingconfigmeta
|
||||
for (const path of paths) {
|
||||
if(path.typeHint !== "rendered"){
|
||||
if (path.typeHint !== "rendered") {
|
||||
continue
|
||||
}
|
||||
Utils.WalkPath(path.path, json, ((leaf, travelled) => RewriteSpecial.convertIfNeeded(leaf, errors, travelled.join("."))))
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
result:json,
|
||||
result: json,
|
||||
errors
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export class PrepareLayer extends Fuse<LayerConfigJson> {
|
||||
|
@ -492,11 +516,11 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
|
|||
"Fully prepares and expands a layer for the LayerConfig.",
|
||||
new On("tagRenderings", new Each(new RewriteSpecial())),
|
||||
new On("tagRenderings", new Concat(new ExpandRewrite()).andThenF(Utils.Flatten)),
|
||||
new On("tagRenderings", new Concat(new ExpandTagRendering(state))),
|
||||
new On("tagRenderings", layer => new Concat(new ExpandTagRendering(state, layer))),
|
||||
new On("mapRendering", new Concat(new ExpandRewrite()).andThenF(Utils.Flatten)),
|
||||
new On("mapRendering",new Each( new On("icon", new FirstOf(new ExpandTagRendering(state))))),
|
||||
new On("mapRendering", layer => new Each(new On("icon", new FirstOf(new ExpandTagRendering(state, layer))))),
|
||||
new SetDefault("titleIcons", ["defaults"]),
|
||||
new On("titleIcons", new Concat(new ExpandTagRendering(state)))
|
||||
new On("titleIcons", layer => new Concat(new ExpandTagRendering(state, layer)))
|
||||
);
|
||||
}
|
||||
}
|
|
@ -357,7 +357,7 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
|
|||
|
||||
for (const layerConfig of alreadyLoaded) {
|
||||
try {
|
||||
const layerDeps = DependencyCalculator.getLayerDependencies(new LayerConfig(layerConfig))
|
||||
const layerDeps = DependencyCalculator.getLayerDependencies(new LayerConfig(layerConfig, themeId+"(dependencies)"))
|
||||
dependencies.push(...layerDeps)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
|
|
|
@ -508,6 +508,7 @@ export class ValidateLayer extends DesugaringStep<LayerConfigJson> {
|
|||
const errors = []
|
||||
const warnings = []
|
||||
const information = []
|
||||
context = "While validating a layer: "+context
|
||||
if (typeof json === "string") {
|
||||
errors.push(context + ": This layer hasn't been expanded: " + json)
|
||||
return {
|
||||
|
@ -548,6 +549,10 @@ export class ValidateLayer extends DesugaringStep<LayerConfigJson> {
|
|||
if (json["hideUnderlayingFeaturesMinPercentage"] !== undefined) {
|
||||
errors.push(context + ": layer " + json.id + " contains an old 'hideUnderlayingFeaturesMinPercentage'")
|
||||
}
|
||||
|
||||
if(json.isShown !== undefined && (json.isShown["render"] !== undefined || json.isShown["mappings"] !== undefined)){
|
||||
warnings.push(context + " has a tagRendering as `isShown`")
|
||||
}
|
||||
}
|
||||
{
|
||||
// Check location of layer file
|
||||
|
|
|
@ -4,7 +4,7 @@ import FilterConfigJson from "./Json/FilterConfigJson";
|
|||
import Translations from "../../UI/i18n/Translations";
|
||||
import {TagUtils} from "../../Logic/Tags/TagUtils";
|
||||
import ValidatedTextField from "../../UI/Input/ValidatedTextField";
|
||||
import {AndOrTagConfigJson} from "./Json/TagConfigJson";
|
||||
import {TagConfigJson} from "./Json/TagConfigJson";
|
||||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import {FilterState} from "../FilteredLayer";
|
||||
import {QueryParameters} from "../../Logic/Web/QueryParameters";
|
||||
|
@ -16,7 +16,7 @@ export default class FilterConfig {
|
|||
public readonly options: {
|
||||
question: Translation;
|
||||
osmTags: TagsFilter | undefined;
|
||||
originalTagsSpec: string | AndOrTagConfigJson
|
||||
originalTagsSpec: TagConfigJson
|
||||
fields: { name: string, type: string }[]
|
||||
}[];
|
||||
public readonly defaultSelection? : number
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {AndOrTagConfigJson} from "./TagConfigJson";
|
||||
import {TagConfigJson} from "./TagConfigJson";
|
||||
|
||||
export interface DeleteConfigJson {
|
||||
|
||||
|
@ -41,7 +41,7 @@ export interface DeleteConfigJson {
|
|||
* The tags that will be given to the object.
|
||||
* This must remove tags so that the 'source/osmTags' won't match anymore
|
||||
*/
|
||||
if: string | AndOrTagConfigJson,
|
||||
if: TagConfigJson,
|
||||
/**
|
||||
* The human explanation for the options
|
||||
*/
|
||||
|
@ -67,7 +67,7 @@ export interface DeleteConfigJson {
|
|||
* }
|
||||
* ```
|
||||
*/
|
||||
softDeletionTags?: AndOrTagConfigJson | string,
|
||||
softDeletionTags?: TagConfigJson,
|
||||
/***
|
||||
* By default, the contributor needs 20 previous changesets to delete points edited by others.
|
||||
* For some small features (e.g. bicycle racks) this is too much and this requirement can be lowered or dropped, which can be done here.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {AndOrTagConfigJson} from "./TagConfigJson";
|
||||
import {TagConfigJson} from "./TagConfigJson";
|
||||
|
||||
export default interface FilterConfigJson {
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@ export default interface FilterConfigJson {
|
|||
*/
|
||||
options: {
|
||||
question: string | any;
|
||||
osmTags?: AndOrTagConfigJson | string,
|
||||
osmTags?: TagConfigJson,
|
||||
default?: boolean,
|
||||
fields?: {
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {AndOrTagConfigJson} from "./TagConfigJson";
|
||||
import {TagConfigJson} from "./TagConfigJson";
|
||||
import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
|
||||
import FilterConfigJson from "./FilterConfigJson";
|
||||
import {DeleteConfigJson} from "./DeleteConfigJson";
|
||||
|
@ -47,7 +47,7 @@ export interface LayerConfigJson {
|
|||
/**
|
||||
* Every source must set which tags have to be present in order to load the given layer.
|
||||
*/
|
||||
osmTags: AndOrTagConfigJson | string
|
||||
osmTags: TagConfigJson
|
||||
/**
|
||||
* The maximum amount of seconds that a tile is allowed to linger in the cache
|
||||
*/
|
||||
|
@ -135,7 +135,7 @@ export interface LayerConfigJson {
|
|||
doNotDownload?: boolean;
|
||||
|
||||
/**
|
||||
* This tag rendering should either be 'yes' or 'no'. If 'no' is returned, then the feature will be hidden from view.
|
||||
* If set, only features matching this extra tag will be shown.
|
||||
* This is useful to hide certain features from view.
|
||||
*
|
||||
* Important: hiding features does not work dynamically, but is only calculated when the data is first renders.
|
||||
|
@ -143,7 +143,7 @@ export interface LayerConfigJson {
|
|||
*
|
||||
* The default value is 'yes'
|
||||
*/
|
||||
isShown?: TagRenderingConfigJson;
|
||||
isShown?: TagConfigJson;
|
||||
|
||||
/**
|
||||
* Advanced option - might be set by the theme compiler
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
|
||||
import {AndOrTagConfigJson} from "./TagConfigJson";
|
||||
import {TagConfigJson} from "./TagConfigJson";
|
||||
|
||||
/**
|
||||
* The PointRenderingConfig gives all details onto how to render a single point of a feature.
|
||||
|
@ -39,7 +39,7 @@ export default interface PointRenderingConfigJson {
|
|||
* Note: strings are interpreted as icons, so layering and substituting is supported. You can use `circle:white;./my_icon.svg` to add a background circle
|
||||
*/
|
||||
iconBadges?: {
|
||||
if: string | AndOrTagConfigJson,
|
||||
if: TagConfigJson,
|
||||
/**
|
||||
* Badge to show
|
||||
* Type: icon
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {AndOrTagConfigJson} from "./TagConfigJson";
|
||||
import {TagConfigJson} from "./TagConfigJson";
|
||||
import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@ export interface MappingConfigJson {
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
if: AndOrTagConfigJson | string,
|
||||
if: TagConfigJson,
|
||||
/**
|
||||
* Shown if the 'if is fulfilled
|
||||
* Type: rendered
|
||||
|
@ -89,7 +89,7 @@ export interface MappingConfigJson {
|
|||
* hideInAnswer: "_country!=be"
|
||||
* }
|
||||
*/
|
||||
hideInAnswer?: boolean | string | AndOrTagConfigJson,
|
||||
hideInAnswer?: boolean | TagConfigJson,
|
||||
/**
|
||||
* Only applicable if 'multiAnswer' is set.
|
||||
* This is for situations such as:
|
||||
|
@ -98,7 +98,7 @@ export interface MappingConfigJson {
|
|||
* Note that we can not explicitly render this negative case to the user, we cannot show `does _not_ accept coins`.
|
||||
* If this is important to your usecase, consider using multiple radiobutton-fields without `multiAnswer`
|
||||
*/
|
||||
ifnot?: AndOrTagConfigJson | string
|
||||
ifnot?: TagConfigJson
|
||||
|
||||
/**
|
||||
* If chosen as answer, these tags will be applied as well onto the object.
|
||||
|
@ -107,10 +107,18 @@ export interface MappingConfigJson {
|
|||
addExtraTags?: string[]
|
||||
|
||||
/**
|
||||
* Searchterms (per language) to easily find an option if there are many options
|
||||
* If there are many options, the mappings-radiobuttons will be replaced by an element with a searchfunction
|
||||
*
|
||||
* Searchterms (per language) allow to easily find an option if there are many options
|
||||
*/
|
||||
searchTerms?: Record<string, string[]>
|
||||
|
||||
/**
|
||||
* If the searchable selector is picked, mappings with this item will have priority and show up even if the others are hidden
|
||||
* Use this sparingly
|
||||
*/
|
||||
priorityIf?: TagConfigJson
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,9 +1,21 @@
|
|||
/**
|
||||
* A small interface to combine tags and tagsfilters.
|
||||
*
|
||||
* The main representation of Tags.
|
||||
* See https://github.com/pietervdvn/MapComplete/blob/develop/Docs/Tags_format.md for more documentation
|
||||
*/
|
||||
export type TagConfigJson = string | AndTagConfigJson | OrTagConfigJson
|
||||
|
||||
|
||||
/**
|
||||
* Chain many tags, to match, all of these should be true
|
||||
* See https://github.com/pietervdvn/MapComplete/blob/develop/Docs/Tags_format.md for documentation
|
||||
*/
|
||||
export interface AndOrTagConfigJson {
|
||||
and?: (string | AndOrTagConfigJson)[]
|
||||
or?: (string | AndOrTagConfigJson)[]
|
||||
}
|
||||
export type OrTagConfigJson = {
|
||||
or: TagConfigJson[]
|
||||
}
|
||||
/**
|
||||
* Chain many tags, to match, a single of these should be true
|
||||
* See https://github.com/pietervdvn/MapComplete/blob/develop/Docs/Tags_format.md for documentation
|
||||
*/
|
||||
export type AndTagConfigJson = {
|
||||
and: TagConfigJson[]
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {AndOrTagConfigJson} from "./TagConfigJson";
|
||||
import {TagConfigJson} from "./TagConfigJson";
|
||||
|
||||
/**
|
||||
* A TagRenderingConfigJson is a single piece of code which converts one ore more tags into a HTML-snippet.
|
||||
|
@ -35,11 +35,45 @@ export interface TagRenderingConfigJson {
|
|||
render?: string | any,
|
||||
|
||||
/**
|
||||
* Only show this tagrendering (or question) if the object also matches the following tags.
|
||||
* Only show this tagrendering (or ask the question) if the selected object also matches the tags specified as `condition`.
|
||||
*
|
||||
* This is useful to ask a follow-up question. E.g. if there is a diaper table, then ask a follow-up question on diaper tables...
|
||||
* This is useful to ask a follow-up question.
|
||||
* For example, within toilets, asking _where_ the diaper changing table is is only useful _if_ there is one.
|
||||
* This can be done by adding `"condition": "changing_table=yes"`
|
||||
*
|
||||
* A full example would be:
|
||||
* ```json
|
||||
* {
|
||||
* "question": "Where is the changing table located?",
|
||||
* "render": "The changing table is located at {changing_table:location}",
|
||||
* "condition": "changing_table=yes",
|
||||
* "freeform": {
|
||||
* "key": "changing_table:location",
|
||||
* "inline": true
|
||||
* },
|
||||
* "mappings": [
|
||||
* {
|
||||
* "then": "The changing table is in the toilet for women.",
|
||||
* "if": "changing_table:location=female_toilet"
|
||||
* },
|
||||
* {
|
||||
* "then": "The changing table is in the toilet for men.",
|
||||
* "if": "changing_table:location=male_toilet"
|
||||
* },
|
||||
* {
|
||||
* "if": "changing_table:location=wheelchair_toilet",
|
||||
* "then": "The changing table is in the toilet for wheelchair users.",
|
||||
* },
|
||||
* {
|
||||
* "if": "changing_table:location=dedicated_room",
|
||||
* "then": "The changing table is in a dedicated room. ",
|
||||
* }
|
||||
* ],
|
||||
* "id": "toilet-changing_table:location"
|
||||
* },
|
||||
* ```
|
||||
* */
|
||||
condition?: AndOrTagConfigJson | string;
|
||||
condition?: TagConfigJson;
|
||||
|
||||
/**
|
||||
* Allow freeform text input from the user
|
||||
|
@ -66,7 +100,7 @@ export interface TagRenderingConfigJson {
|
|||
*
|
||||
* This can be an substituting-tag as well, e.g. {'if': 'addr:street:={_calculated_nearby_streetname}', 'then': '{_calculated_nearby_streetname}'}
|
||||
*/
|
||||
if: AndOrTagConfigJson | string,
|
||||
if: TagConfigJson,
|
||||
/**
|
||||
* If the condition `if` is met, the text `then` will be rendered.
|
||||
* If not known yet, the user will be presented with `then` as an option
|
||||
|
|
|
@ -39,7 +39,7 @@ export default class LayerConfig extends WithContextLoader {
|
|||
public readonly calculatedTags: [string, string, boolean][];
|
||||
public readonly doNotDownload: boolean;
|
||||
public readonly passAllFeatures: boolean;
|
||||
public readonly isShown: TagRenderingConfig;
|
||||
public readonly isShown: TagsFilter;
|
||||
public minzoom: number;
|
||||
public minzoomVisible: number;
|
||||
public readonly maxzoom: number;
|
||||
|
@ -302,7 +302,7 @@ export default class LayerConfig extends WithContextLoader {
|
|||
});
|
||||
|
||||
this.title = this.tr("title", undefined);
|
||||
this.isShown = this.tr("isShown", "yes");
|
||||
this.isShown = TagUtils.TagD(json.isShown, context+".isShown")
|
||||
|
||||
this.deletion = null;
|
||||
if (json.deletion === true) {
|
||||
|
@ -478,7 +478,7 @@ export default class LayerConfig extends WithContextLoader {
|
|||
}
|
||||
|
||||
AllTagRenderings(): TagRenderingConfig[] {
|
||||
return Utils.NoNull([...this.tagRenderings, ...this.titleIcons, this.title, this.isShown])
|
||||
return Utils.NoNull([...this.tagRenderings, ...this.titleIcons, this.title])
|
||||
}
|
||||
|
||||
public isLeftRightSensitive(): boolean {
|
||||
|
|
|
@ -71,7 +71,6 @@ export default class LineRenderingConfig extends WithContextLoader {
|
|||
}
|
||||
|
||||
const fillStr = render(this.fill, undefined)
|
||||
let fill: boolean = undefined;
|
||||
if (fillStr !== undefined && fillStr !== "") {
|
||||
style["fill"] = fillStr === "yes" || fillStr === "true"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import {TagsFilter} from "../../Logic/Tags/TagsFilter";
|
||||
import {RegexTag} from "../../Logic/Tags/RegexTag";
|
||||
import {param} from "jquery";
|
||||
|
||||
export default class SourceConfig {
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ export interface Mapping {
|
|||
readonly iconClass: string | "small" | "medium" | "large" | "small-height" | "medium-height" | "large-height",
|
||||
readonly hideInAnswer: boolean | TagsFilter
|
||||
readonly addExtraTags: Tag[],
|
||||
readonly searchTerms?: Record<string, string[]>
|
||||
readonly searchTerms?: Record<string, string[]>,
|
||||
readonly priorityIf?: TagsFilter
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -287,6 +288,11 @@ export default class TagRenderingConfig {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* const tr = TagRenderingConfig.ExtractMapping({if: "a=b", then: "x", priorityIf: "_country=be"}, 0, "test","test", false,true)
|
||||
* tr.if // => new Tag("a","b")
|
||||
* tr.priorityIf // => new Tag("_country","be")
|
||||
*/
|
||||
public static ExtractMapping(mapping: MappingConfigJson, i: number, translationKey: string,
|
||||
context: string,
|
||||
multiAnswer?: boolean, isQuestionable?: boolean, commonSize: string = "small") {
|
||||
|
@ -337,6 +343,7 @@ export default class TagRenderingConfig {
|
|||
iconClass = mapping.icon["class"] ?? iconClass
|
||||
}
|
||||
}
|
||||
const prioritySearch = mapping.priorityIf !== undefined ? TagUtils.Tag(mapping.priorityIf) : undefined;
|
||||
const mp = <Mapping>{
|
||||
if: TagUtils.Tag(mapping.if, `${ctx}.if`),
|
||||
ifnot: (mapping.ifnot !== undefined ? TagUtils.Tag(mapping.ifnot, `${ctx}.ifnot`) : undefined),
|
||||
|
@ -345,7 +352,8 @@ export default class TagRenderingConfig {
|
|||
icon,
|
||||
iconClass,
|
||||
addExtraTags,
|
||||
searchTerms: mapping.searchTerms
|
||||
searchTerms: mapping.searchTerms,
|
||||
priorityIf: prioritySearch
|
||||
};
|
||||
if (isQuestionable) {
|
||||
if (hideInAnswer !== true && mp.if !== undefined && !mp.if.isUsableAsAnswer()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue