fix renaming settings & update inverse settings on rename

main
bat 3 years ago
parent 03885398c5
commit c0113e8c71

@ -122,18 +122,36 @@ export class PageActions extends HTMLElement {
}
return
}
localStorage.setItem(
newPath,
localStorage.getItem(this.path)
const sKeyOld = 'settings/page:' + this.path
const sKeyNew = 'settings/page:' + newPath
const settingsJson = localStorage.getItem(sKeyOld)
if (settingsJson ?? true === true) {
localStorage.setItem(sKeyNew, settingsJson)
localStorage.removeItem(sKeyOld)
let settingsData
try {
settingsData = JSON.parse(settingsJson)
} catch (err) {
settingsData = {}
}
if (settingsData?.connections) {
for (const dir of ['outbound', 'inbound']) {
const otherDir = (
dir === 'outbound' ? 'inbound' : 'outbound'
)
this.applyInverseRename(
settingsData, dir, otherDir, this.path, newPath
)
}
}
} else {
localStorage.removeItem(sKeyNew)
}
localStorage.setItem(
'settings/page:' + newPath,
newPath,
localStorage.getItem(this.path)
)
localStorage.removeItem(this.path)
localStorage.removeItem(
'settings/page:' + newPath,
)
dialog.close()
location.hash = newPath
})
@ -285,6 +303,36 @@ export class PageActions extends HTMLElement {
}
}
applyInverseRename(
settingsData, dir, otherDir, oldPath, newPath
) {
const selfEntries = Object.entries(
settingsData.connections[dir] ?? {}
)
for (const [path, access] of selfEntries) {
const key = 'settings/page:' + path
let val = localStorage.getItem(key)
try {
if (val !== null) {
val = JSON.parse(val)
}
} catch (err) {
// ignore
}
const data = val ?? {}
data.connections = data.connections ?? {}
data.connections[otherDir] = (
data.connections[otherDir] ?? {}
)
const accessValue = data.connections[otherDir][oldPath]
data.connections[otherDir][newPath] = accessValue
data.connections[otherDir][oldPath] = undefined
localStorage.setItem(
key, JSON.stringify(data)
)
}
}
get language() {
return this._language
}

Loading…
Cancel
Save