|
|
|
|
@ -122,18 +122,36 @@ export class PageActions extends HTMLElement {
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
|
newPath,
|
|
|
|
|
localStorage.getItem(this.path)
|
|
|
|
|
)
|
|
|
|
|
localStorage.setItem(
|
|
|
|
|
'settings/page:' + newPath,
|
|
|
|
|
localStorage.getItem(this.path)
|
|
|
|
|
)
|
|
|
|
|
localStorage.removeItem(this.path)
|
|
|
|
|
localStorage.removeItem(
|
|
|
|
|
'settings/page:' + newPath,
|
|
|
|
|
)
|
|
|
|
|
dialog.close()
|
|
|
|
|
location.hash = newPath
|
|
|
|
|
})
|
|
|
|
|
@ -227,6 +245,7 @@ export class PageActions extends HTMLElement {
|
|
|
|
|
'm-settings-page-settings'
|
|
|
|
|
)
|
|
|
|
|
settingsEl.cspProfiles = this.cspProfiles
|
|
|
|
|
settingsEl.path = this.path
|
|
|
|
|
settingsEl.data = this.page.settings
|
|
|
|
|
const h = document.createElement('h2')
|
|
|
|
|
h.innerText = this.text.settings
|
|
|
|
|
@ -236,7 +255,16 @@ export class PageActions extends HTMLElement {
|
|
|
|
|
'm-forms-button-group'
|
|
|
|
|
)
|
|
|
|
|
bGroup.addPrimary(this.text.save, () => {
|
|
|
|
|
this.page.settings = settingsEl.data
|
|
|
|
|
const settingsData = settingsEl.data
|
|
|
|
|
this.page.settings = settingsData
|
|
|
|
|
for (const dir of ['outbound', 'inbound']) {
|
|
|
|
|
const otherDir = (
|
|
|
|
|
dir === 'outbound' ? 'inbound' : 'outbound'
|
|
|
|
|
)
|
|
|
|
|
this.applyInverseSettings(
|
|
|
|
|
settingsData, dir, otherDir
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
dialog.close()
|
|
|
|
|
this.dispatchEvent(new CustomEvent(
|
|
|
|
|
'settings-change', {bubbles: true, composed: true}
|
|
|
|
|
@ -249,6 +277,62 @@ export class PageActions extends HTMLElement {
|
|
|
|
|
dialog.open()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applyInverseSettings(settingsData, dir, otherDir) {
|
|
|
|
|
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] ?? {}
|
|
|
|
|
)
|
|
|
|
|
data.connections[otherDir][this.path] = access
|
|
|
|
|
localStorage.setItem(
|
|
|
|
|
key, JSON.stringify(data)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|