Refactoring: add metatagging, add 'last edited by' element, add 'metacondition'

This commit is contained in:
Pieter Vander Vennet 2023-04-15 02:28:24 +02:00
parent 771783a31c
commit 105120060d
31 changed files with 217 additions and 142 deletions

View file

@ -575,12 +575,14 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
}
export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
constructor() {
private readonly _desugaring: DesugaringContext
constructor(desugaring: DesugaringContext) {
super(
"Add some editing elements, such as the delete button or the move button if they are configured. These used to be handled by the feature info box, but this has been replaced by special visualisation elements",
[],
"AddEditingElements"
)
this._desugaring = desugaring
}
convert(
@ -609,6 +611,30 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
})
}
if (json.deletion && !ValidationUtils.hasSpecialVisualisation(json, "all_tags")) {
const trc: TagRenderingConfigJson = {
id: "all-tags",
render: { "*": "{all_tags()}" },
metacondition: {
or: [
"__featureSwitchIsTesting=true",
"__featureSwitchIsDebugging=true",
"mapcomplete-show_debug=yes",
],
},
}
json.tagRenderings.push(trc)
}
if (
json.source !== "special" &&
json.source !== "special:library" &&
json.tagRenderings &&
!json.tagRenderings.some((tr) => tr["id"] === "last_edit")
) {
json.tagRenderings.push(this._desugaring.tagRenderings.get("last_edit"))
}
return { result: json }
}
}
@ -1145,7 +1171,7 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
new On("tagRenderings", new Each(new DetectInline())),
new AddQuestionBox(),
new AddMiniMap(state),
new AddEditingElements(),
new AddEditingElements(state),
new On("mapRendering", new Concat(new ExpandRewrite()).andThenF(Utils.Flatten)),
new On<(PointRenderingConfigJson | LineRenderingConfigJson)[], LayerConfigJson>(
"mapRendering",

View file

@ -47,6 +47,10 @@ export default class TagRenderingConfig {
public readonly question?: TypedTranslation<object>
public readonly questionhint?: TypedTranslation<object>
public readonly condition?: TagsFilter
/**
* Evaluated against the current 'usersettings'-state
*/
public readonly metacondition?: TagsFilter
public readonly description?: Translation
public readonly configuration_warnings: string[] = []
@ -70,14 +74,6 @@ export default class TagRenderingConfig {
if (json === undefined) {
throw "Initing a TagRenderingConfig with undefined in " + context
}
if (json === "questions") {
// Very special value
this.render = null
this.question = null
this.condition = null
this.id = "questions"
return
}
if (typeof json === "number") {
json = "" + json
@ -114,11 +110,15 @@ export default class TagRenderingConfig {
}
this.labels = json.labels ?? []
this.render = Translations.T(json.render, translationKey + ".render")
this.render = Translations.T(<any>json.render, translationKey + ".render")
this.question = Translations.T(json.question, translationKey + ".question")
this.questionhint = Translations.T(json.questionHint, translationKey + ".questionHint")
this.description = Translations.T(json.description, translationKey + ".description")
this.condition = TagUtils.Tag(json.condition ?? { and: [] }, `${context}.condition`)
this.metacondition = TagUtils.Tag(
json.metacondition ?? { and: [] },
`${context}.metacondition`
)
if (json.freeform) {
if (
json.freeform.addExtraTags !== undefined &&