From 6656bde6e9d6aeb83ac850bf82a5567dec85797b Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 13 Mar 2024 00:01:03 +0100 Subject: [PATCH] Add changesetMeta documentation --- scripts/generateDocs.ts | 7 +- src/Logic/Osm/Actions/ChangeLocationAction.ts | 14 +++ src/Logic/Osm/Actions/ChangeTagAction.ts | 21 ++++ src/Logic/Osm/Changes.ts | 97 +++++++++++++++++++ src/Logic/Osm/ChangesetHandler.ts | 8 ++ 5 files changed, 146 insertions(+), 1 deletion(-) diff --git a/scripts/generateDocs.ts b/scripts/generateDocs.ts index 331ef6f526..c6a968c3a7 100644 --- a/scripts/generateDocs.ts +++ b/scripts/generateDocs.ts @@ -30,6 +30,7 @@ import { LayerConfigJson } from "../src/Models/ThemeConfig/Json/LayerConfigJson" import { Utils } from "../src/Utils" import { TagUtils } from "../src/Logic/Tags/TagUtils" import Script from "./Script" +import { Changes } from "../src/Logic/Osm/Changes" /** * Converts a markdown-file into a .json file, which a walkthrough/slideshow element can use @@ -180,6 +181,10 @@ export class GenerateDocs extends Script { "src/UI/InputElement/Validators.ts", ]) + this.WriteFile("./Docs/ChangesetMeta.md", Changes.getDocs(), [ + "src/Logic/Osm/Changes.ts", + "src/Logic/Osm/ChangesetHandler.ts", + ]) new WikiPageGenerator().generate() console.log("Generated docs") @@ -239,7 +244,7 @@ export class GenerateDocs extends Script { } private generateHotkeyDocs() { - new ThemeViewState(new LayoutConfig(bookcases)) + new ThemeViewState(new LayoutConfig(bookcases), new Set()) this.WriteFile("./Docs/Hotkeys.md", Hotkeys.generateDocumentation(), []) } diff --git a/src/Logic/Osm/Actions/ChangeLocationAction.ts b/src/Logic/Osm/Actions/ChangeLocationAction.ts index e5d2b8486d..be84fed486 100644 --- a/src/Logic/Osm/Actions/ChangeLocationAction.ts +++ b/src/Logic/Osm/Actions/ChangeLocationAction.ts @@ -5,6 +5,20 @@ export default class ChangeLocationAction extends OsmChangeAction { private readonly _id: number private readonly _newLonLat: [number, number] private readonly _meta: { theme: string; reason: string } + static metatags: { + readonly key?: string + readonly value?: string + readonly docs: string + readonly changeType: string[] + readonly specialMotivation?: boolean + }[] = [ + { + value: "relocated|improve_accuraccy|...", + docs: "Will appear if the ", + changeType: ["move"], + specialMotivation: true, + }, + ] constructor( id: string, diff --git a/src/Logic/Osm/Actions/ChangeTagAction.ts b/src/Logic/Osm/Actions/ChangeTagAction.ts index 72fbffab4d..f86e6c938a 100644 --- a/src/Logic/Osm/Actions/ChangeTagAction.ts +++ b/src/Logic/Osm/Actions/ChangeTagAction.ts @@ -4,6 +4,27 @@ import { TagsFilter } from "../../Tags/TagsFilter" import { OsmTags } from "../../../Models/OsmFeature" export default class ChangeTagAction extends OsmChangeAction { + static metatags: { + readonly key?: string + readonly value?: string + readonly docs: string + readonly changeType: string[] + readonly specialMotivation?: boolean + }[] = [ + { + changeType: ["answer"], + docs: "Indicates the number of questions that have been answered", + }, + { changeType: ["soft-delete"], docs: "Indicates the number of soft-deleted items" }, + { + changeType: ["add-image"], + docs: "Indicates the number of images that have been added in this changeset", + }, + { + changeType: ["link-image"], + docs: "Indicates the number of images that have been linked in this changeset", + }, + ] private readonly _elementId: string /** * The tags to apply onto the object diff --git a/src/Logic/Osm/Changes.ts b/src/Logic/Osm/Changes.ts index 3f2611edb6..2ec95db6f2 100644 --- a/src/Logic/Osm/Changes.ts +++ b/src/Logic/Osm/Changes.ts @@ -13,6 +13,12 @@ import { ChangesetHandler, ChangesetTag } from "./ChangesetHandler" import { OsmConnection } from "./OsmConnection" import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore" import OsmObjectDownloader from "./OsmObjectDownloader" +import Combine from "../../UI/Base/Combine" +import BaseUIElement from "../../UI/BaseUIElement" +import Title from "../../UI/Base/Title" +import Table from "../../UI/Base/Table" +import ChangeLocationAction from "./Actions/ChangeLocationAction" +import ChangeTagAction from "./Actions/ChangeTagAction" /** * Handles all changes made to OSM. @@ -99,6 +105,97 @@ export class Changes { return changes } + public static getDocs(): BaseUIElement { + function addSource(items: any[], src: string) { + items.forEach((i) => { + i["source"] = src + }) + return items + } + const metatagsDocs: { + key?: string + value?: string + docs: string + changeType?: string[] + specialMotivation?: boolean + source?: string + }[] = [ + ...addSource( + [ + { + key: "comment", + docs: "The changeset comment. Will be a fixed string, mentioning the theme", + }, + { + key: "theme", + docs: "The name of the theme that was used to create this change. ", + }, + { + key: "source", + value: "survey", + docs: "The contributor had their geolocation enabled while making changes", + }, + { + key: "change_within_{distance}", + docs: "If the contributor enabled their geolocation, this will hint how far away they were from the objects they edited. This gives an indication of proximity and if they truly surveyed or were armchair-mapping", + }, + { + key: "change_over_{distance}", + docs: "If the contributor enabled their geolocation, this will hint how far away they were from the objects they edited. If they were over 5000m away, the might have been armchair-mapping", + }, + { + key: "created_by", + value: "MapComplete ", + docs: "The piece of software used to create this changeset; will always start with MapComplete, followed by the version number", + }, + { + key: "locale", + value: "en|nl|de|...", + docs: "The code of the language that the contributor used MapComplete in. Hints what language the user speaks.", + }, + { + key: "host", + value: "https://mapcomplete.org/", + docs: "The URL that the contributor used to make changes. One can see the used instance with this", + }, + { + key: "imagery", + docs: "The identifier of the used background layer, this will probably be an identifier from the [editor layer index](https://github.com/osmlab/editor-layer-index)", + }, + ], + "default" + ), + ...addSource(ChangeTagAction.metatags, "ChangeTag"), + ...addSource(ChangeLocationAction.metatags, "ChangeLocation"), + // TODO + /* + ...DeleteAction.metatags, + ...LinkImageAction.metatags, + ...OsmChangeAction.metatags, + ...RelationSplitHandler.metatags, + ...ReplaceGeometryAction.metatags, + ...SplitAction.metatags,*/ + ] + return new Combine([ + new Title("Metatags on a changeset", 1), + "You might encounter the following metatags on a changeset:", + new Table( + ["key", "value", "explanation", "source"], + metatagsDocs.map(({ key, value, docs, source, changeType, specialMotivation }) => [ + key ?? changeType?.join(", ") ?? "", + value, + new Combine([ + docs, + specialMotivation + ? "This might give a reason per modified node or way" + : "", + ]), + source, + ]) + ), + ]) + } + private static GetNeededIds(changes: ChangeDescription[]) { return Utils.Dedup(changes.filter((c) => c.id >= 0).map((c) => c.type + "/" + c.id)) } diff --git a/src/Logic/Osm/ChangesetHandler.ts b/src/Logic/Osm/ChangesetHandler.ts index dca2b0a676..71c0e299fc 100644 --- a/src/Logic/Osm/ChangesetHandler.ts +++ b/src/Logic/Osm/ChangesetHandler.ts @@ -6,6 +6,14 @@ import Constants from "../../Models/Constants" import { Changes } from "./Changes" import { Utils } from "../../Utils" import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore" +import ChangeLocationAction from "./Actions/ChangeLocationAction" +import ChangeTagAction from "./Actions/ChangeTagAction" +import DeleteAction from "./Actions/DeleteAction" +import LinkImageAction from "./Actions/LinkImageAction" +import OsmChangeAction from "./Actions/OsmChangeAction" +import RelationSplitHandler from "./Actions/RelationSplitHandler" +import ReplaceGeometryAction from "./Actions/ReplaceGeometryAction" +import SplitAction from "./Actions/SplitAction" export interface ChangesetTag { key: string