2024-11-25 23:44:26 +01:00
|
|
|
import * as all_layers from "../../assets/generated/themes/personal.json"
|
|
|
|
import ThemeConfig from "../../Models/ThemeConfig/ThemeConfig"
|
|
|
|
import { OsmObject } from "../../Logic/Osm/OsmObject"
|
|
|
|
|
|
|
|
export class HistoryUtils {
|
|
|
|
|
2024-12-01 01:39:13 +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"])
|
|
|
|
public static determineLayer(properties: Record<string, string>){
|
|
|
|
return this.personalTheme.getMatchingLayer(properties, this.ignoredLayers)
|
|
|
|
}
|
|
|
|
|
|
|
|
public static tagHistoryDiff(step: OsmObject, history: OsmObject[]): {
|
|
|
|
key: string,
|
|
|
|
value?: string,
|
2024-12-01 01:39:13 +01:00
|
|
|
oldValue?: string,
|
|
|
|
step: OsmObject
|
2024-11-25 23:44:26 +01:00
|
|
|
}[] {
|
|
|
|
const previous = history[step.version - 2]
|
|
|
|
if (!previous) {
|
|
|
|
return Object.keys(step.tags).filter(key => !key.startsWith("_") && key !== "id").map(key => ({
|
2024-12-01 01:39:13 +01:00
|
|
|
key, value: step.tags[key], step
|
2024-11-25 23:44:26 +01:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
const previousTags = previous.tags
|
|
|
|
return Object.keys(step.tags).filter(key => !key.startsWith("_") )
|
|
|
|
.map(key => {
|
|
|
|
const value = step.tags[key]
|
|
|
|
const oldValue = previousTags[key]
|
|
|
|
return {
|
2024-12-01 01:39:13 +01:00
|
|
|
key, value, oldValue, step
|
2024-11-25 23:44:26 +01:00
|
|
|
}
|
|
|
|
}).filter(ch => ch.oldValue !== ch.value)
|
|
|
|
}
|
|
|
|
|
2024-12-04 18:48:05 +01:00
|
|
|
public static fullHistoryDiff(histories: OsmObject[][], onlyShowUsername?: Set<string>){
|
2024-12-01 01:39:13 +01:00
|
|
|
const allDiffs: {key: string, oldValue?: string, value?: string}[] = [].concat(...histories.map(
|
|
|
|
history => {
|
2024-12-04 18:48:05 +01:00
|
|
|
const filtered = history.filter(step => !onlyShowUsername || onlyShowUsername?.has(step.tags["_last_edit:contributor"] ))
|
2024-12-01 01:39:13 +01:00
|
|
|
const diffs: {
|
|
|
|
key: string;
|
|
|
|
value?: string;
|
|
|
|
oldValue?: string
|
|
|
|
}[][] = filtered.map(step => HistoryUtils.tagHistoryDiff(step, history))
|
|
|
|
return [].concat(...diffs)
|
|
|
|
}
|
|
|
|
))
|
|
|
|
return allDiffs
|
|
|
|
}
|
|
|
|
|
2024-11-25 23:44:26 +01:00
|
|
|
}
|