forked from MapComplete/MapComplete
Refactoring: change order of parameters and remove parameter for Conversion.ts
This commit is contained in:
parent
f9ba3126a4
commit
a0b7a32223
20 changed files with 147 additions and 213 deletions
|
@ -1,18 +1,6 @@
|
|||
import {
|
||||
Concat,
|
||||
DesugaringContext,
|
||||
DesugaringStep,
|
||||
Each,
|
||||
FirstOf,
|
||||
Fuse,
|
||||
On,
|
||||
SetDefault,
|
||||
} from "./Conversion"
|
||||
import { Concat, DesugaringContext, DesugaringStep, Each, FirstOf, Fuse, On, SetDefault } from "./Conversion"
|
||||
import { LayerConfigJson } from "../Json/LayerConfigJson"
|
||||
import {
|
||||
MinimalTagRenderingConfigJson,
|
||||
TagRenderingConfigJson,
|
||||
} from "../Json/TagRenderingConfigJson"
|
||||
import { MinimalTagRenderingConfigJson, TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import RewritableConfigJson from "../Json/RewritableConfigJson"
|
||||
import SpecialVisualizations from "../../../UI/SpecialVisualizations"
|
||||
|
@ -36,9 +24,8 @@ import { ExpandTagRendering } from "./ExpandTagRendering"
|
|||
class AddFiltersFromTagRenderings extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"AddFiltersFromTagRenderings",
|
||||
'Inspects all the tagRenderings. If some tagRenderings have the `filter` attribute set, introduce those filters. This step might introduce shorthand filter names, thus \'ExpandFilter\' should be run afterwards. Can be disabled with "#filter":"no-auto"',
|
||||
["filter"],
|
||||
"AddFiltersFromTagRenderings"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -108,9 +95,8 @@ class AddFiltersFromTagRenderings extends DesugaringStep<LayerConfigJson> {
|
|||
class DetectInline extends DesugaringStep<QuestionableTagRenderingConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"DetectInline",
|
||||
"If no 'inline' is set on the freeform key, it will be automatically added. If no special renderings are used, it'll be set to true",
|
||||
["freeform.inline"],
|
||||
"DetectInline"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -173,9 +159,8 @@ class DetectInline extends DesugaringStep<QuestionableTagRenderingConfigJson> {
|
|||
export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"AddQuestionBox",
|
||||
"Adds a 'questions'-object if no question element is added yet",
|
||||
["tagRenderings"],
|
||||
"AddQuestionBox"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -284,9 +269,8 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
|
|||
|
||||
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"
|
||||
"AddEditingElements",
|
||||
"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"
|
||||
)
|
||||
this._desugaring = desugaring
|
||||
this.builtinQuestions = Array.from(this._desugaring.tagRenderings?.values() ?? [])
|
||||
|
@ -388,9 +372,8 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
|
|||
export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"RewriteSpecial",
|
||||
"Converts a 'special' translation into a regular translation which uses parameters",
|
||||
["special"],
|
||||
"RewriteSpecial"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -664,7 +647,7 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson> {
|
|||
private _expand: ExpandTagRendering
|
||||
|
||||
constructor(state: DesugaringContext, layer: LayerConfigJson) {
|
||||
super("Expands shorthand properties on iconBadges", ["iconBadges"], "ExpandIconBadges")
|
||||
super("ExpandIconBadges", "Expands shorthand properties on iconBadges")
|
||||
this._expand = new ExpandTagRendering(state, layer)
|
||||
}
|
||||
|
||||
|
@ -766,9 +749,8 @@ class PreparePointRendering extends Fuse<PointRenderingConfigJson> {
|
|||
class SetFullNodeDatabase extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"SetFullNodeDatabase",
|
||||
"sets the fullNodeDatabase-bit if needed",
|
||||
["fullNodeDatabase"],
|
||||
"SetFullNodeDatabase"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -795,9 +777,8 @@ class ExpandMarkerRenderings extends DesugaringStep<IconConfigJson> {
|
|||
|
||||
constructor(state: DesugaringContext, layer: LayerConfigJson) {
|
||||
super(
|
||||
"ExpandMarkerRenderings",
|
||||
"Expands tagRenderings in the icons, if needed",
|
||||
["icon", "color"],
|
||||
"ExpandMarkerRenderings"
|
||||
)
|
||||
this._layer = layer
|
||||
this._state = state
|
||||
|
@ -829,9 +810,8 @@ class ExpandMarkerRenderings extends DesugaringStep<IconConfigJson> {
|
|||
class AddFavouriteBadges extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"AddFavouriteBadges",
|
||||
"Adds the favourite heart to the title and the rendering badges",
|
||||
[],
|
||||
"AddFavouriteBadges"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -854,9 +834,8 @@ class AddFavouriteBadges extends DesugaringStep<LayerConfigJson> {
|
|||
export class AddRatingBadge extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"AddRatingBadge",
|
||||
"Adds the 'rating'-element if a reviews-element is used in the tagRenderings",
|
||||
["titleIcons"],
|
||||
"AddRatingBadge"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -890,9 +869,8 @@ export class AddRatingBadge extends DesugaringStep<LayerConfigJson> {
|
|||
export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"AutoTitleIcon",
|
||||
"The auto-icon creates a (non-clickable) title icon based on a tagRendering which has icons",
|
||||
["titleIcons"],
|
||||
"AutoTitleIcon"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -967,12 +945,34 @@ export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
|
|||
}
|
||||
}
|
||||
|
||||
class MoveUnitConfigs extends DesugaringStep<LayerConfigJson> {
|
||||
|
||||
constructor() {
|
||||
super("MoveUnitConfigs", "Looks into all the tagRenderings for a 'unitConfig', moves them to the layer level")
|
||||
}
|
||||
|
||||
convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson {
|
||||
json = { ...json, units: [...(json.units ?? [])] }
|
||||
for (const tr of json.tagRenderings ?? []) {
|
||||
const qtr = (<QuestionableTagRenderingConfigJson>tr)
|
||||
const unitConfig = qtr?.freeform?.unit
|
||||
if (!unitConfig) {
|
||||
continue
|
||||
}
|
||||
json.units.push({
|
||||
[qtr.freeform.key]: unitConfig
|
||||
})
|
||||
}
|
||||
return json
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DeriveSource extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"DeriveSource",
|
||||
"If no source is given, automatically derives the osmTags by 'or'-ing all the preset tags",
|
||||
["source"],
|
||||
"DeriveSource"
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue