forked from MapComplete/MapComplete
Scripts: reorder tagRenderings, fix tests
This commit is contained in:
parent
bba8546a55
commit
2e66278291
5 changed files with 50 additions and 9 deletions
|
@ -216,7 +216,6 @@
|
||||||
"panoramaxHelp": "<b>Panoramax</b> is an online service which gathers street-level pictures and offers them under a free license. Contributors are allowed to use these pictures to improve OpenStreetMap",
|
"panoramaxHelp": "<b>Panoramax</b> is an online service which gathers street-level pictures and offers them under a free license. Contributors are allowed to use these pictures to improve OpenStreetMap",
|
||||||
"panoramaxLicenseCCBYSA": "Your pictures are published under CC-BY-SA - everyone can reuse your image if they mention your name",
|
"panoramaxLicenseCCBYSA": "Your pictures are published under CC-BY-SA - everyone can reuse your image if they mention your name",
|
||||||
"seeOnMapillary": "See this image on Mapillary",
|
"seeOnMapillary": "See this image on Mapillary",
|
||||||
|
|
||||||
"themeBy": "Theme maintained by {author}",
|
"themeBy": "Theme maintained by {author}",
|
||||||
"title": "Copyright and attribution",
|
"title": "Copyright and attribution",
|
||||||
"translatedBy": "MapComplete has been translated by {contributors} and <a href='https://source.mapcomplete.org/MapComplete/MapComplete/activity/contributors' target='_blank'>{hiddenCount} more contributors</a>"
|
"translatedBy": "MapComplete has been translated by {contributors} and <a href='https://source.mapcomplete.org/MapComplete/MapComplete/activity/contributors' target='_blank'>{hiddenCount} more contributors</a>"
|
||||||
|
|
|
@ -1092,15 +1092,47 @@ class DeriveSource extends DesugaringStep<LayerConfigJson> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OrderLayer extends DesugaringStep<LayerConfigJson> {
|
export class OrderTagRendering extends DesugaringStep<TagRenderingConfigJson | string> {
|
||||||
|
constructor() {
|
||||||
|
super("OrderTagRendering", "Places all components of a tagRendering in a fixed order")
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly tagRenderingAttributesOrder: ReadonlyArray<string> = [
|
||||||
|
"id", "labels", "description", "question", "questionHint", "render", "icon", "freeform", "mappings",
|
||||||
|
"condition", "metacondition", "filter",
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
convert(json: TagRenderingConfigJson, context: ConversionContext): TagRenderingConfigJson {
|
||||||
|
if (typeof json !== "object") {
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
console.log("Ordering", json.id, OrderTagRendering.tagRenderingAttributesOrder)
|
||||||
|
return Utils.reorder(json, OrderTagRendering.tagRenderingAttributesOrder)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OrderLayer extends DesugaringStep<string | LayerConfigJson> {
|
||||||
private static readonly layerAttributesOrder: ReadonlyArray<string> = Utils.Dedup(
|
private static readonly layerAttributesOrder: ReadonlyArray<string> = Utils.Dedup(
|
||||||
(<ConfigMeta[]>layerconfig).filter((c) => c.path.length === 1).map((c) => c.path[0])
|
(<ConfigMeta[]>layerconfig).filter((c) => c.path.length === 1).map((c) => c.path[0])
|
||||||
)
|
)
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("OrderLayer", "Reorders the layer to the default order")
|
super("OrderLayer", "Reorders a tagRendering to the default order")
|
||||||
}
|
}
|
||||||
|
|
||||||
public convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson {
|
public convert(json: LayerConfigJson | string, context: ConversionContext): LayerConfigJson | string {
|
||||||
|
if (typeof json !== "object") {
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
if (typeof json === "string") {
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
json = new On<"tagRenderings", TagRenderingConfigJson[], LayerConfigJson>("tagRenderings", new Each(
|
||||||
|
new OrderTagRendering(),
|
||||||
|
)).convert(<LayerConfigJson>json, context)
|
||||||
return Utils.reorder(json, OrderLayer.layerAttributesOrder)
|
return Utils.reorder(json, OrderLayer.layerAttributesOrder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
SetDefault,
|
SetDefault,
|
||||||
} from "./Conversion"
|
} from "./Conversion"
|
||||||
import { ThemeConfigJson } from "../Json/ThemeConfigJson"
|
import { ThemeConfigJson } from "../Json/ThemeConfigJson"
|
||||||
import { PrepareLayer, RewriteSpecial } from "./PrepareLayer"
|
import { OrderLayer, PrepareLayer, RewriteSpecial } from "./PrepareLayer"
|
||||||
import { LayerConfigJson } from "../Json/LayerConfigJson"
|
import { LayerConfigJson } from "../Json/LayerConfigJson"
|
||||||
import { Utils } from "../../../Utils"
|
import { Utils } from "../../../Utils"
|
||||||
import Constants from "../../Constants"
|
import Constants from "../../Constants"
|
||||||
|
@ -611,13 +611,15 @@ class PostvalidateTheme extends DesugaringStep<ThemeConfigJson> {
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class OrderTheme extends DesugaringStep<ThemeConfigJson> {
|
export class OrderTheme extends Fuse<ThemeConfigJson> {
|
||||||
private static readonly themeAttributesOrder: ReadonlyArray<string> = Utils.Dedup(
|
private static readonly themeAttributesOrder: ReadonlyArray<string> = Utils.Dedup(
|
||||||
(<ConfigMeta[]>themeconfig).filter((c) => c.path.length === 1).map((c) => c.path[0])
|
(<ConfigMeta[]>themeconfig).filter((c) => c.path.length === 1).map((c) => c.path[0])
|
||||||
)
|
)
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("OrderLayer", "Reorders the layer to the default order")
|
super("Reorders the layer to the default order",
|
||||||
|
new On("layers", new Each(new OrderLayer()))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public convert(json: ThemeConfigJson, context: ConversionContext): ThemeConfigJson {
|
public convert(json: ThemeConfigJson, context: ConversionContext): ThemeConfigJson {
|
||||||
|
|
|
@ -174,7 +174,7 @@ export default class Translations {
|
||||||
/**
|
/**
|
||||||
* Creates the url to Hosted weblate
|
* Creates the url to Hosted weblate
|
||||||
*
|
*
|
||||||
* LinkToWeblate.hrefToWeblate("nl", "category:some.context") // => "https://translate.mapcomplete.org/translate/mapcomplete/category/nl/?offset=1&q=context%3A%3D%22some.context%22"
|
* Translations.hrefToWeblate("nl", "category:some.context") // => "https://translate.mapcomplete.org/translate/mapcomplete/category/nl/?offset=1&q=context%3A%3D%22some.context%22"
|
||||||
*/
|
*/
|
||||||
public static hrefToWeblate(language: string, contextKey: string): string {
|
public static hrefToWeblate(language: string, contextKey: string): string {
|
||||||
if (contextKey === undefined || contextKey.indexOf(":") < 0) {
|
if (contextKey === undefined || contextKey.indexOf(":") < 0) {
|
||||||
|
|
|
@ -1882,7 +1882,15 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
||||||
return [].concat(...param)
|
return [].concat(...param)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* JSON.stringify(Utils.reorder({b: "0", a: "1"}, ["a", "b"])) // => '{"a":"1","b":"0"}'
|
||||||
|
* Utils.reorder("test", []) // => "test"
|
||||||
|
*/
|
||||||
public static reorder<T extends object>(object: T, order: ReadonlyArray<string>): T {
|
public static reorder<T extends object>(object: T, order: ReadonlyArray<string>): T {
|
||||||
|
if(typeof object !== "object"){
|
||||||
|
return object
|
||||||
|
}
|
||||||
const allKeys = new Set<string>(Object.keys(object))
|
const allKeys = new Set<string>(Object.keys(object))
|
||||||
const copy = {}
|
const copy = {}
|
||||||
for (const key of order) {
|
for (const key of order) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue