MapComplete/src/UI/History/HistoryUtils.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-01-11 03:13:06 +01:00
import * as all_layers from "../../../public/assets/generated/themes/personal.json"
2024-11-25 23:44:26 +01:00
import ThemeConfig from "../../Models/ThemeConfig/ThemeConfig"
import { OsmObject } from "../../Logic/Osm/OsmObject"
export class HistoryUtils {
2024-12-11 02:45:44 +01:00
public static readonly personalTheme = new ThemeConfig(<any>all_layers, true)
2024-11-25 23:44:26 +01:00
private static ignoredLayers = new Set<string>(["fixme"])
2024-12-11 02:45:44 +01:00
public static determineLayer(properties: Record<string, string>) {
2024-11-25 23:44:26 +01:00
return this.personalTheme.getMatchingLayer(properties, this.ignoredLayers)
}
2024-12-11 02:45:44 +01:00
public static tagHistoryDiff(
step: OsmObject,
history: OsmObject[]
): {
key: string
value?: string
oldValue?: string
2024-12-01 01:39:13 +01:00
step: OsmObject
2024-11-25 23:44:26 +01:00
}[] {
const previous = history[step.version - 2]
if (!previous) {
2024-12-11 02:45:44 +01:00
return Object.keys(step.tags)
.filter((key) => !key.startsWith("_") && key !== "id")
.map((key) => ({
key,
value: step.tags[key],
step,
}))
2024-11-25 23:44:26 +01:00
}
const previousTags = previous.tags
2024-12-11 02:45:44 +01:00
return Object.keys(step.tags)
.filter((key) => !key.startsWith("_"))
.map((key) => {
2024-11-25 23:44:26 +01:00
const value = step.tags[key]
const oldValue = previousTags[key]
return {
2024-12-11 02:45:44 +01:00
key,
value,
oldValue,
step,
2024-11-25 23:44:26 +01:00
}
2024-12-11 02:45:44 +01:00
})
.filter((ch) => ch.oldValue !== ch.value)
2024-11-25 23:44:26 +01:00
}
2025-04-26 22:06:59 +02:00
public static fullHistoryDiff(
histories: OsmObject[][],
onlyShowUsername?: Set<string>
): {
key: string
value?: string
oldValue?: string
step: OsmObject
}[] {
const allDiffs: {
2025-04-26 22:06:59 +02:00
key: string
value?: string
oldValue?: string
step: OsmObject
}[] = []
for (const history of histories) {
const filtered = history.filter(
(step) =>
2025-04-26 22:06:59 +02:00
!onlyShowUsername || onlyShowUsername?.has(step.tags["_last_edit:contributor"])
)
for (const step of filtered) {
const diff: {
2025-04-26 22:06:59 +02:00
key: string
value?: string
oldValue?: string
step: OsmObject
}[] = HistoryUtils.tagHistoryDiff(step, history)
allDiffs.push(...diff)
}
}
2024-12-01 01:39:13 +01:00
return allDiffs
}
2024-11-25 23:44:26 +01:00
}