forked from MapComplete/MapComplete
		
	Refactoring: split 'Utils' into multiple files; fix some stray uppercase-method names
This commit is contained in:
		
							parent
							
								
									81be4db044
								
							
						
					
					
						commit
						3ec89826e4
					
				
					 97 changed files with 884 additions and 921 deletions
				
			
		| 
						 | 
				
			
			@ -23,6 +23,7 @@ import MarkdownUtils from "../../Utils/MarkdownUtils"
 | 
			
		|||
import { And } from "../../Logic/Tags/And"
 | 
			
		||||
import OsmWiki from "../../Logic/Osm/OsmWiki"
 | 
			
		||||
import { UnitUtils } from "../UnitUtils"
 | 
			
		||||
import { Lists } from "../../Utils/Lists"
 | 
			
		||||
 | 
			
		||||
export default class LayerConfig extends WithContextLoader {
 | 
			
		||||
    public static readonly syncSelectionAllowed = ["no", "local", "theme-only", "global"] as const
 | 
			
		||||
| 
						 | 
				
			
			@ -226,7 +227,7 @@ export default class LayerConfig extends WithContextLoader {
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        if (json.lineRendering) {
 | 
			
		||||
            this.lineRendering = Utils.NoNull(json.lineRendering).map(
 | 
			
		||||
            this.lineRendering = Lists.noNull(json.lineRendering).map(
 | 
			
		||||
                (r, i) => new LineRenderingConfig(r, `${context}[${i}]`)
 | 
			
		||||
            )
 | 
			
		||||
        } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -234,7 +235,7 @@ export default class LayerConfig extends WithContextLoader {
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        if (json.pointRendering) {
 | 
			
		||||
            this.mapRendering = Utils.NoNull(json.pointRendering).map(
 | 
			
		||||
            this.mapRendering = Lists.noNull(json.pointRendering).map(
 | 
			
		||||
                (r, i) => new PointRenderingConfig(r, `${context}[${i}](${this.id})`)
 | 
			
		||||
            )
 | 
			
		||||
        } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -283,7 +284,7 @@ export default class LayerConfig extends WithContextLoader {
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        const missingIds =
 | 
			
		||||
            Utils.NoNull(json.tagRenderings)?.filter(
 | 
			
		||||
            Lists.noNull(json.tagRenderings)?.filter(
 | 
			
		||||
                (tr) =>
 | 
			
		||||
                    typeof tr !== "string" &&
 | 
			
		||||
                    tr["builtin"] === undefined &&
 | 
			
		||||
| 
						 | 
				
			
			@ -298,7 +299,7 @@ export default class LayerConfig extends WithContextLoader {
 | 
			
		|||
            throw msg
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.tagRenderings = (Utils.NoNull(json.tagRenderings) ?? []).map(
 | 
			
		||||
        this.tagRenderings = (Lists.noNull(json.tagRenderings) ?? []).map(
 | 
			
		||||
            (tr, i) =>
 | 
			
		||||
                new TagRenderingConfig(
 | 
			
		||||
                    <QuestionableTagRenderingConfigJson>tr,
 | 
			
		||||
| 
						 | 
				
			
			@ -431,7 +432,7 @@ export default class LayerConfig extends WithContextLoader {
 | 
			
		|||
 | 
			
		||||
                    return [
 | 
			
		||||
                        `[${tr.id}](#${tr.id}) ${origDef}`,
 | 
			
		||||
                        Utils.NoNull([q, r, options]).join("<br/>"),
 | 
			
		||||
                        Lists.noNull([q, r, options]).join("<br/>"),
 | 
			
		||||
                        tr.labels.join(", "),
 | 
			
		||||
                        key,
 | 
			
		||||
                    ]
 | 
			
		||||
| 
						 | 
				
			
			@ -560,7 +561,7 @@ export default class LayerConfig extends WithContextLoader {
 | 
			
		|||
            ]
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (const revDep of Utils.Dedup(layerIsNeededBy?.get(this.id) ?? [])) {
 | 
			
		||||
        for (const revDep of Lists.dedup(layerIsNeededBy?.get(this.id) ?? [])) {
 | 
			
		||||
            extraProps.push(
 | 
			
		||||
                ["This layer is needed as dependency for layer", `[${revDep}](#${revDep})`].join(
 | 
			
		||||
                    " "
 | 
			
		||||
| 
						 | 
				
			
			@ -568,32 +569,30 @@ export default class LayerConfig extends WithContextLoader {
 | 
			
		|||
            )
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const tableRows: string[][] = Utils.NoNull(
 | 
			
		||||
            this.tagRenderings
 | 
			
		||||
                .map((tr) => tr.FreeformValues())
 | 
			
		||||
                .filter((values) => values !== undefined)
 | 
			
		||||
                .filter((values) => values.key !== "id")
 | 
			
		||||
                .map((values) => {
 | 
			
		||||
                    const embedded: string[] = values.values?.map((v) =>
 | 
			
		||||
                        OsmWiki.constructLinkMd(values.key, v)
 | 
			
		||||
                    ) ?? ["_no preset options defined, or no values in them_"]
 | 
			
		||||
                    const statistics = `https://taghistory.raifer.tech/?#***/${encodeURIComponent(
 | 
			
		||||
                        values.key
 | 
			
		||||
                    )}/`
 | 
			
		||||
                    const tagInfo = `https://taginfo.openstreetmap.org/keys/${values.key}#values`
 | 
			
		||||
                    return [
 | 
			
		||||
                        [
 | 
			
		||||
                            `<a target="_blank" href='${tagInfo}'><img src='https://mapcomplete.org/assets/svg/search.svg' height='18px'></a>`,
 | 
			
		||||
                            `<a target="_blank" href='${statistics}'><img src='https://mapcomplete.org/assets/svg/statistics.svg' height='18px'></a>`,
 | 
			
		||||
                            OsmWiki.constructLinkMd(values.key),
 | 
			
		||||
                        ].join(" "),
 | 
			
		||||
                        values.type === undefined
 | 
			
		||||
                            ? "Multiple choice"
 | 
			
		||||
                            : `[${values.type}](../SpecialInputElements.md#${values.type})`,
 | 
			
		||||
                        embedded.join(" "),
 | 
			
		||||
                    ]
 | 
			
		||||
                })
 | 
			
		||||
        )
 | 
			
		||||
        const tableRows: string[][] = Lists.noNull(this.tagRenderings
 | 
			
		||||
          .map((tr) => tr.FreeformValues())
 | 
			
		||||
          .filter((values) => values !== undefined)
 | 
			
		||||
          .filter((values) => values.key !== "id")
 | 
			
		||||
          .map((values) => {
 | 
			
		||||
            const embedded: string[] = values.values?.map((v) =>
 | 
			
		||||
              OsmWiki.constructLinkMd(values.key, v)
 | 
			
		||||
            ) ?? ["_no preset options defined, or no values in them_"]
 | 
			
		||||
            const statistics = `https://taghistory.raifer.tech/?#***/${encodeURIComponent(
 | 
			
		||||
              values.key
 | 
			
		||||
            )}/`
 | 
			
		||||
            const tagInfo = `https://taginfo.openstreetmap.org/keys/${values.key}#values`
 | 
			
		||||
            return [
 | 
			
		||||
              [
 | 
			
		||||
                `<a target="_blank" href='${tagInfo}'><img src='https://mapcomplete.org/assets/svg/search.svg' height='18px'></a>`,
 | 
			
		||||
                `<a target="_blank" href='${statistics}'><img src='https://mapcomplete.org/assets/svg/statistics.svg' height='18px'></a>`,
 | 
			
		||||
                OsmWiki.constructLinkMd(values.key),
 | 
			
		||||
              ].join(" "),
 | 
			
		||||
              values.type === undefined
 | 
			
		||||
                ? "Multiple choice"
 | 
			
		||||
                : `[${values.type}](../SpecialInputElements.md#${values.type})`,
 | 
			
		||||
              embedded.join(" "),
 | 
			
		||||
            ]
 | 
			
		||||
          }))
 | 
			
		||||
 | 
			
		||||
        let quickOverview: string[] = []
 | 
			
		||||
        if (tableRows.length > 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -693,7 +692,7 @@ export default class LayerConfig extends WithContextLoader {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    AllTagRenderings(): TagRenderingConfig[] {
 | 
			
		||||
        return Utils.NoNull([...this.tagRenderings, ...this.titleIcons, this.title])
 | 
			
		||||
        return Lists.noNull([...this.tagRenderings, ...this.titleIcons, this.title])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public isLeftRightSensitive(): boolean {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue