More work on inspector

This commit is contained in:
Pieter Vander Vennet 2024-12-01 01:39:13 +01:00
parent 552ea22275
commit 951bd3c0ae
9 changed files with 257 additions and 108 deletions

View file

@ -4,7 +4,7 @@ import { OsmObject } from "../../Logic/Osm/OsmObject"
export class HistoryUtils {
private static personalTheme = new ThemeConfig(<any> all_layers, true)
public static readonly personalTheme = new ThemeConfig(<any> all_layers, true)
private static ignoredLayers = new Set<string>(["fixme"])
public static determineLayer(properties: Record<string, string>){
return this.personalTheme.getMatchingLayer(properties, this.ignoredLayers)
@ -13,12 +13,13 @@ export class HistoryUtils {
public static tagHistoryDiff(step: OsmObject, history: OsmObject[]): {
key: string,
value?: string,
oldValue?: string
oldValue?: string,
step: OsmObject
}[] {
const previous = history[step.version - 2]
if (!previous) {
return Object.keys(step.tags).filter(key => !key.startsWith("_") && key !== "id").map(key => ({
key, value: step.tags[key]
key, value: step.tags[key], step
}))
}
const previousTags = previous.tags
@ -27,9 +28,24 @@ export class HistoryUtils {
const value = step.tags[key]
const oldValue = previousTags[key]
return {
key, value, oldValue
key, value, oldValue, step
}
}).filter(ch => ch.oldValue !== ch.value)
}
public static fullHistoryDiff(histories: OsmObject[][], onlyShowUsername?: string){
const allDiffs: {key: string, oldValue?: string, value?: string}[] = [].concat(...histories.map(
history => {
const filtered = history.filter(step => !onlyShowUsername || step.tags["_last_edit:contributor"] === onlyShowUsername)
const diffs: {
key: string;
value?: string;
oldValue?: string
}[][] = filtered.map(step => HistoryUtils.tagHistoryDiff(step, history))
return [].concat(...diffs)
}
))
return allDiffs
}
}