forked from MapComplete/MapComplete
Merge branch 'develop' into feature/disable-questions
This commit is contained in:
commit
7cd886b082
1 changed files with 19 additions and 13 deletions
|
@ -62,6 +62,9 @@ export class OsmPreferences {
|
||||||
this.seenKeys = Object.keys(prefs)
|
this.seenKeys = Object.keys(prefs)
|
||||||
const legacy = OsmPreferences.getLegacyCombinedItems(prefs)
|
const legacy = OsmPreferences.getLegacyCombinedItems(prefs)
|
||||||
const merged = OsmPreferences.mergeDict(prefs)
|
const merged = OsmPreferences.mergeDict(prefs)
|
||||||
|
if(Object.keys(legacy).length > 0){
|
||||||
|
await this.removeLegacy(legacy)
|
||||||
|
}
|
||||||
for (const key in merged) {
|
for (const key in merged) {
|
||||||
this.initPreference(key, prefs[key])
|
this.initPreference(key, prefs[key])
|
||||||
}
|
}
|
||||||
|
@ -119,6 +122,15 @@ export class OsmPreferences {
|
||||||
this.removeAllWithPrefix("")
|
this.removeAllWithPrefix("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async removeLegacy(legacyDict: Record<string, string>) {
|
||||||
|
for (const k in legacyDict) {
|
||||||
|
const v = legacyDict[k]
|
||||||
|
console.log("Upgrading legacy preference",k )
|
||||||
|
await this.removeAllWithPrefix(k)
|
||||||
|
this.osmConnection.getPreference(k).set(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* OsmPreferences.mergeDict({abc: "123", def: "123", "def:0": "456", "def:1":"789"}) // => {abc: "123", def: "123456789"}
|
* OsmPreferences.mergeDict({abc: "123", def: "123", "def:0": "456", "def:1":"789"}) // => {abc: "123", def: "123456789"}
|
||||||
|
@ -140,6 +152,7 @@ export class OsmPreferences {
|
||||||
return newDict
|
return newDict
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all items which have a 'combined'-string, the legacy long preferences
|
* Gets all items which have a 'combined'-string, the legacy long preferences
|
||||||
*
|
*
|
||||||
|
@ -170,11 +183,10 @@ export class OsmPreferences {
|
||||||
} while (v !== undefined)
|
} while (v !== undefined)
|
||||||
merged[key] = str
|
merged[key] = str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return merged
|
return merged
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulk-downloads all preferences
|
* Bulk-downloads all preferences
|
||||||
* @private
|
* @private
|
||||||
|
@ -242,6 +254,7 @@ export class OsmPreferences {
|
||||||
while (v.length > 0) {
|
while (v.length > 0) {
|
||||||
await this.uploadKeyDirectly(`${k}:${i}`, v.slice(0, 255))
|
await this.uploadKeyDirectly(`${k}:${i}`, v.slice(0, 255))
|
||||||
v = v.slice(255)
|
v = v.slice(255)
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -333,12 +346,5 @@ export class OsmPreferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getExistingPreference(key: string, defaultValue: undefined, prefix: string): UIEventSource<string> {
|
|
||||||
if (prefix) {
|
|
||||||
key = prefix + key
|
|
||||||
}
|
|
||||||
key = key.replace(/[:/"' {}.%\\]/g, "")
|
|
||||||
return this.preferences[key]
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue