Refactoring: use theme instead of layout in a lot of places

This commit is contained in:
Pieter Vander Vennet 2024-10-17 04:06:03 +02:00
parent 9427083939
commit bdc9ba52a6
104 changed files with 445 additions and 449 deletions

View file

@ -114,7 +114,7 @@
}
const newElementAction = new CreateNewNodeAction(tags, location.lat, location.lon, {
theme: state.layout?.id ?? "unkown",
theme: state.theme?.id ?? "unkown",
changeType: "create",
snapOnto: snapToWay,
reusePointWithinMeters: 1,

View file

@ -1,5 +1,5 @@
<script lang="ts">
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"
import ThemeConfig from "../../../Models/ThemeConfig/ThemeConfig"
import { createEventDispatcher } from "svelte"
import type PresetConfig from "../../../Models/ThemeConfig/PresetConfig"
import Tr from "../../Base/Tr.svelte"
@ -19,7 +19,7 @@
* This component lists all the presets and allows the user to select one
*/
export let state: SpecialVisualizationState
let layout: LayoutConfig = state.layout
let layout: ThemeConfig = state.theme
let presets: {
preset: PresetConfig
layer: LayerConfig

View file

@ -10,7 +10,7 @@ import StaticFeatureSource from "../../Logic/FeatureSource/Sources/StaticFeature
import { VariableUiElement } from "../Base/VariableUIElement"
import Loading from "../Base/Loading"
import Translations from "../i18n/Translations"
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
import ThemeConfig from "../../Models/ThemeConfig/ThemeConfig"
import { Changes } from "../../Logic/Osm/Changes"
import { UIElement } from "../UIElement"
import FilteredLayer from "../../Models/FilteredLayer"
@ -32,7 +32,7 @@ export interface AutoAction extends SpecialVisualization {
applyActionOn(
feature: Feature,
state: {
layout: LayoutConfig
theme: ThemeConfig
changes: Changes
indexedFeatures: IndexedFeatureSource
},
@ -282,7 +282,7 @@ export default class AutoApplyButton implements SpecialVisualization {
argument: string[]
): BaseUIElement {
try {
if (!state.layout.official && !state.featureSwitchIsTesting.data) {
if (!state.theme.official && !state.featureSwitchIsTesting.data) {
const t = Translations.t.general.add.import
return new Combine([
new FixedUiElement(

View file

@ -65,7 +65,7 @@
featureId,
deleteConfig.softDeletionTags,
{
theme: state?.layout?.id ?? "unknown",
theme: state?.theme?.id ?? "unknown",
specialMotivation: deleteReason,
},
canBeDeleted.data
@ -73,7 +73,7 @@
} else {
// no _delete_reason is given, which implies that this is _not_ a deletion but merely a retagging via a nonDeleteMapping
actionToTake = new ChangeTagAction(featureId, selectedTags, tags.data, {
theme: state?.layout?.id ?? "unkown",
theme: state?.theme?.id ?? "unkown",
changeType: "special-delete",
})
}

View file

@ -1,7 +1,6 @@
import { SpecialVisualization, SpecialVisualizationState } from "../../SpecialVisualization"
import { UIEventSource } from "../../../Logic/UIEventSource"
import { Feature, Geometry, LineString, Polygon } from "geojson"
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
import BaseUIElement from "../../BaseUIElement"
import { ImportFlowArguments, ImportFlowUtils } from "./ImportFlow"
import Translations from "../../i18n/Translations"
@ -12,7 +11,7 @@ import ConflateImportFlowState from "./ConflateImportFlowState"
import { AutoAction } from "../AutoApplyButton"
import { IndexedFeatureSource } from "../../../Logic/FeatureSource/FeatureSource"
import { Changes } from "../../../Logic/Osm/Changes"
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"
import ThemeConfig from "../../../Models/ThemeConfig/ThemeConfig"
import { OsmConnection } from "../../../Logic/Osm/OsmConnection"
export interface ConflateFlowArguments extends ImportFlowArguments {
@ -47,7 +46,7 @@ export default class ConflateImportButtonViz implements SpecialVisualization, Au
feature: Feature<Geometry, { [name: string]: any }>,
state: {
osmConnection: OsmConnection
layout: LayoutConfig
theme: ThemeConfig
changes: Changes
indexedFeatures: IndexedFeatureSource
},

View file

@ -10,7 +10,7 @@ import { GeoOperations } from "../../../Logic/GeoOperations"
import { TagUtils } from "../../../Logic/Tags/TagUtils"
import { MergePointConfig } from "../../../Logic/Osm/Actions/CreateWayWithPointReuseAction"
import { And } from "../../../Logic/Tags/And"
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"
import ThemeConfig from "../../../Models/ThemeConfig/ThemeConfig"
import { Changes } from "../../../Logic/Osm/Changes"
import { FeatureSource, IndexedFeatureSource } from "../../../Logic/FeatureSource/FeatureSource"
import FullNodeDatabaseSource from "../../../Logic/FeatureSource/TiledFeatureSource/FullNodeDatabaseSource"
@ -61,7 +61,7 @@ export default class ConflateImportFlowState extends ImportFlow<ConflateFlowArgu
args: ConflateFlowArguments,
state: {
osmConnection: OsmConnection
layout: LayoutConfig
theme: ThemeConfig
changes: Changes
indexedFeatures: IndexedFeatureSource
fullNodeDatabase?: FullNodeDatabaseSource
@ -88,7 +88,7 @@ export default class ConflateImportFlowState extends ImportFlow<ConflateFlowArgu
GeoOperations.removeOvernoding(feature),
idOfFeatureToReplaceGeometry,
{
theme: state.layout.id,
theme: state.theme.id,
newTags: tagsToApply.data,
}
)

View file

@ -174,7 +174,7 @@ export default abstract class ImportFlow<ArgT extends ImportFlowArguments> {
return { error: t.hasBeenImported }
}
if (!state.layout.official && !isTesting) {
if (!state.theme.official && !isTesting) {
// Unofficial theme - imports not allowed
return {
error: t.officialThemesOnly,
@ -183,7 +183,7 @@ export default abstract class ImportFlow<ArgT extends ImportFlowArguments> {
}
if (this.targetLayer === undefined) {
const e = `Target layer not defined: error in import button for theme: ${this.state.layout.id}: layer ${this.args.targetLayer} not found`
const e = `Target layer not defined: error in import button for theme: ${this.state.theme.id}: layer ${this.args.targetLayer} not found`
console.error(e)
return { error: new Translation({ "*": e }) }
}

View file

@ -15,7 +15,7 @@
// The following variables are used for the map
const targetLayers: LayerConfig[] = args.targetLayer
.split(" ")
.map((tl) => state.layout.layers.find((l) => l.id === tl))
.map((tl) => state.theme.layers.find((l) => l.id === tl))
const snapToLayers: string[] | undefined =
args.snap_onto_layers?.split(",")?.map((l) => l.trim()) ?? []
const maxSnapDistance: number = Number(args.max_snap_distance ?? 25) ?? 25

View file

@ -63,7 +63,7 @@ export class PointImportFlowState extends ImportFlow<PointImportFlowArguments> {
}
const newElementAction = new CreateNewNodeAction(tags, location.lat, location.lon, {
theme: this.state.layout.id,
theme: this.state.theme.id,
changeType: "import",
snapOnto: <OsmWay>snapOnto,
specialMotivation: specialMotivation,

View file

@ -10,7 +10,7 @@ import { FixedUiElement } from "../../Base/FixedUiElement"
import WayImportFlow from "./WayImportFlow.svelte"
import WayImportFlowState, { WayImportFlowArguments } from "./WayImportFlowState"
import { Utils } from "../../../Utils"
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"
import ThemeConfig from "../../../Models/ThemeConfig/ThemeConfig"
import { Changes } from "../../../Logic/Osm/Changes"
import { IndexedFeatureSource } from "../../../Logic/FeatureSource/FeatureSource"
import FullNodeDatabaseSource from "../../../Logic/FeatureSource/TiledFeatureSource/FullNodeDatabaseSource"
@ -87,7 +87,7 @@ export default class WayImportButtonViz implements AutoAction, SpecialVisualizat
public async applyActionOn(
feature: Feature,
state: {
layout: LayoutConfig
theme: ThemeConfig
changes: Changes
indexedFeatures: IndexedFeatureSource
fullNodeDatabase: FullNodeDatabaseSource

View file

@ -32,7 +32,7 @@
ShowDataLayer.showMultipleLayers(
map,
new StaticFeatureSource([importFlow.originalFeature]),
state.layout.layers,
state.theme.layers,
{ zoomToFeatures: false }
)

View file

@ -11,7 +11,7 @@ import { TagUtils } from "../../../Logic/Tags/TagUtils"
import { OsmCreateAction, PreviewableAction } from "../../../Logic/Osm/Actions/OsmChangeAction"
import { FeatureSource, IndexedFeatureSource } from "../../../Logic/FeatureSource/FeatureSource"
import CreateMultiPolygonWithPointReuseAction from "../../../Logic/Osm/Actions/CreateMultiPolygonWithPointReuseAction"
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"
import ThemeConfig from "../../../Models/ThemeConfig/ThemeConfig"
import { Changes } from "../../../Logic/Osm/Changes"
import FullNodeDatabaseSource from "../../../Logic/FeatureSource/TiledFeatureSource/FullNodeDatabaseSource"
@ -52,7 +52,7 @@ export default class WayImportFlowState extends ImportFlow<WayImportFlowArgument
feature: Feature<LineString | Polygon>,
args: WayImportFlowArguments,
state: {
layout: LayoutConfig
theme: ThemeConfig
changes: Changes
indexedFeatures: IndexedFeatureSource
fullNodeDatabase?: FullNodeDatabaseSource

View file

@ -60,7 +60,7 @@
} else if (state.changes) {
await state.changes.applyAction(
new ChangeTagAction(tags.data.id, new And(selection), tags.data, {
theme: state?.layout?.id ?? "unkown",
theme: state?.theme?.id ?? "unkown",
changeType: "answer",
})
)

View file

@ -19,7 +19,7 @@
const t = Translations.t.favouritePoi
function markFavourite(isFavourite: boolean) {
state.favourites.markAsFavourite(feature, layer.id, state.layout.id, tags, isFavourite)
state.favourites.markAsFavourite(feature, layer.id, state.theme.id, tags, isFavourite)
}
</script>

View file

@ -20,7 +20,7 @@
const t = Translations.t.favouritePoi
function markFavourite(isFavourite: boolean) {
state.favourites.markAsFavourite(feature, layer.id, state.layout.id, tags, isFavourite)
state.favourites.markAsFavourite(feature, layer.id, state.theme.id, tags, isFavourite)
}
</script>

View file

@ -72,7 +72,7 @@
ShowDataLayer.showMultipleLayers(
mlmap,
new StaticFeatureSource(featuresToShow),
state.layout.layers,
state.theme.layers,
{ zoomToFeatures: true }
)
</script>

View file

@ -94,7 +94,7 @@ export class MoveWizardState {
const matchingPresets = this.layer.presets.filter(preset => preset.preciseInput.snapToLayers && new And(preset.tags).matchesProperties(tags))
const matchingPreset = matchingPresets.flatMap(pr => pr.preciseInput?.snapToLayers)
for (const layerId of matchingPreset) {
const snapOntoLayer = this._state.layout.getLayer(layerId)
const snapOntoLayer = this._state.theme.getLayer(layerId)
const text = <Translation> t.reasons.reasonSnapTo.PartialSubsTr("name", snapOntoLayer.snapName)
reasons.push({
text,
@ -133,7 +133,7 @@ export class MoveWizardState {
snappedTo,
{
reason: reason.changesetCommentValue,
theme: state.layout.id,
theme: state.theme.id,
}),
)
featureToMove.properties._lat = loc.lat
@ -152,7 +152,7 @@ export class MoveWizardState {
featureToMove.properties,
{
changeType: "relocated",
theme: state.layout.id,
theme: state.theme.id,
},
),
)

View file

@ -64,7 +64,7 @@ class MultiApplyExecutor {
const keysToChange = this.params.keysToApply
const overwrite = this.params.overwrite
const selfTags = this.params.tagsSource.data
const theme = this.params.state.layout.id
const theme = this.params.state.theme.id
for (const id of featuresToChange) {
const tagsToApply: Tag[] = []
const otherFeatureTags = allElements.getStore(id).data

View file

@ -47,7 +47,7 @@
return
}
const loc = coordinate.data
txt += "\n\n #MapComplete #" + state?.layout?.id
txt += "\n\n #MapComplete #" + state?.theme?.id
const id = await state?.osmConnection?.openNote(loc.lat, loc.lon, txt)
console.log("Created a note, got id", id)
const feature = <Feature<Point, OsmTags>>{

View file

@ -49,7 +49,7 @@ export class PlantNetDetectionViz implements SpecialVisualization {
]),
tags.data,
{
theme: state.layout.id,
theme: state.theme.id,
changeType: "plantnet-ai-detection",
}
)

View file

@ -17,7 +17,7 @@
let [lon, lat] = GeoOperations.centerpointCoordinates(feature)
const includeLayout = window.location.pathname.split("/").at(-1).startsWith("theme")
const layout = includeLayout ? "layout=" + state.layout.id + "&" : ""
const layout = includeLayout ? "layout=" + state.theme.id + "&" : ""
let id: Store<string> = tags.mapD((tags) => tags.id)
let url = id.mapD(
(id) =>

View file

@ -30,9 +30,9 @@ export class ShareLinkViz implements SpecialVisualization {
const text = args[1]
const generateShareData = () => {
const title = state?.layout?.title?.txt ?? "MapComplete"
const title = state?.theme?.title?.txt ?? "MapComplete"
let matchingLayer: LayerConfig = state?.layout?.getMatchingLayer(tagSource?.data)
let matchingLayer: LayerConfig = state?.theme?.getMatchingLayer(tagSource?.data)
let name =
matchingLayer?.title?.GetRenderValue(tagSource.data)?.Subs(tagSource.data)?.txt ??
tagSource.data?.name ??
@ -49,7 +49,7 @@ export class ShareLinkViz implements SpecialVisualization {
return {
title: name,
url: url,
text: state?.layout?.shortDescription?.txt ?? "MapComplete",
text: state?.theme?.shortDescription?.txt ?? "MapComplete",
}
}

View file

@ -58,7 +58,7 @@
id,
splitPoints.data.map((ff) => <[number, number]>(<Point>ff.geometry).coordinates),
{
theme: state?.layout?.id,
theme: state?.theme?.id,
},
5
)

View file

@ -144,7 +144,7 @@ export default class TagApplyButton implements AutoAction, SpecialVisualization
new And(tagsToApply.data),
tags.data, // We pass in the tags of the selected element, not the tags of the target element!
{
theme: state.layout.id,
theme: state.theme.id,
changeType: "answer",
}
)

View file

@ -283,7 +283,7 @@
}
dispatch("saved", { config, applied: selectedTags })
const change = new ChangeTagAction(tags.data.id, selectedTags, tags.data, {
theme: tags.data["_orig_theme"] ?? state.layout.id,
theme: tags.data["_orig_theme"] ?? state.theme.id,
changeType: "answer",
})
freeformInput.set(undefined)
@ -327,7 +327,7 @@
function clearAnswer() {
const tagsToSet = settableKeys.data.map(k => new Tag(k, ""))
const change = new ChangeTagAction(tags.data.id, new And(tagsToSet), tags.data, {
theme: tags.data["_orig_theme"] ?? state.layout.id,
theme: tags.data["_orig_theme"] ?? state.theme.id,
changeType: "answer",
})
freeformInput.set(undefined)