Keyboard handler, recursively open folders upwards
This commit is contained in:
parent
3763367510
commit
fc82a299f8
2 changed files with 66 additions and 7 deletions
|
|
@ -175,6 +175,13 @@ button {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
|
&.created {
|
||||||
|
* {
|
||||||
|
color: #44aa00 !important;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.subdomains {
|
.subdomains {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ export class Application {
|
||||||
window._mbus = new MessageBus()
|
window._mbus = new MessageBus()
|
||||||
this.settings = new Settings()
|
this.settings = new Settings()
|
||||||
this.records = this.parseRecords(records)
|
this.records = this.parseRecords(records)
|
||||||
this.topFolder = new Folder(this, 'root')
|
this.topFolder = new Folder(this, null, 'root')
|
||||||
this.recordsTree = null
|
this.recordsTree = null
|
||||||
this.settingsIcon = null
|
this.settingsIcon = null
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ export class Application {
|
||||||
// to be able to update them when necessary.
|
// to be able to update them when necessary.
|
||||||
let folder = currFolder.subfolders.get(label)
|
let folder = currFolder.subfolders.get(label)
|
||||||
if (folder === undefined) {
|
if (folder === undefined) {
|
||||||
folder = new Folder(this, accFolderName)
|
folder = new Folder(this, currFolder, accFolderName)
|
||||||
currFolder.subfolders.set(label, folder)
|
currFolder.subfolders.set(label, folder)
|
||||||
}
|
}
|
||||||
currFolder = folder
|
currFolder = folder
|
||||||
|
|
@ -110,6 +110,8 @@ export class Application {
|
||||||
document.body.appendChild(this.recordsTree)
|
document.body.appendChild(this.recordsTree)
|
||||||
document.body.appendChild(this.settingsIcon)
|
document.body.appendChild(this.settingsIcon)
|
||||||
document.body.appendChild(this.createIcon)
|
document.body.appendChild(this.createIcon)
|
||||||
|
|
||||||
|
document.body.addEventListener('keydown', event => this.handlerKeys(event))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Top root folder doesn't have to be shown.
|
// Top root folder doesn't have to be shown.
|
||||||
|
|
@ -125,6 +127,29 @@ export class Application {
|
||||||
this.setBoxedFolders(this.settings.get('boxed_folders'))
|
this.setBoxedFolders(this.settings.get('boxed_folders'))
|
||||||
|
|
||||||
}// }}}
|
}// }}}
|
||||||
|
handlerKeys(event) {// {{{
|
||||||
|
let handled = true
|
||||||
|
|
||||||
|
// Every keyboard shortcut for the application wide handler is using Alt+Shift
|
||||||
|
// for consistency and that it works with a lot of browsers.
|
||||||
|
if (!event.altKey || !event.shiftKey || event.ctrlKey) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.key.toLowerCase()) {
|
||||||
|
case 'n':
|
||||||
|
new RecordDialog(new Record()).show()
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
handled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handled) {
|
||||||
|
event.stopPropagation()
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
|
}// }}}
|
||||||
handlerTop(event) {// {{{
|
handlerTop(event) {// {{{
|
||||||
const topEl = event.target.closest('.top')
|
const topEl = event.target.closest('.top')
|
||||||
|
|
||||||
|
|
@ -154,7 +179,6 @@ export class Application {
|
||||||
records = document.querySelectorAll(`[data-top="${topEl.dataset.self}"]`)
|
records = document.querySelectorAll(`[data-top="${topEl.dataset.self}"]`)
|
||||||
types = document.querySelectorAll(`[data-top="${topEl.dataset.self}"] + .type`)
|
types = document.querySelectorAll(`[data-top="${topEl.dataset.self}"] + .type`)
|
||||||
values = document.querySelectorAll(`[data-top="${topEl.dataset.self}"] + .type + .value`)
|
values = document.querySelectorAll(`[data-top="${topEl.dataset.self}"] + .type + .value`)
|
||||||
console.log(records)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const r of records) {
|
for (const r of records) {
|
||||||
|
|
@ -186,9 +210,10 @@ export class Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Folder {
|
class Folder {
|
||||||
constructor(app, name) {// {{{
|
constructor(app, parentFolder, name) {// {{{
|
||||||
this.application = app
|
this.application = app
|
||||||
this.open = false
|
this.open = false
|
||||||
|
this.parentFolder = parentFolder
|
||||||
this.folderName = name
|
this.folderName = name
|
||||||
this.subfolders = new Map()
|
this.subfolders = new Map()
|
||||||
this.records = []
|
this.records = []
|
||||||
|
|
@ -205,11 +230,12 @@ class Folder {
|
||||||
}// }}}
|
}// }}}
|
||||||
addRecord(rec) {// {{{
|
addRecord(rec) {// {{{
|
||||||
this.records.push(rec)
|
this.records.push(rec)
|
||||||
|
rec.setFolder(this)
|
||||||
}// }}}
|
}// }}}
|
||||||
openFolder(recursive) {// {{{
|
openFolder(recursive) {// {{{
|
||||||
this.open = true
|
this.open = true
|
||||||
this.div.classList.add('open')
|
this.div?.classList.add('open')
|
||||||
this.div.classList.remove('closed')
|
this.div?.classList.remove('closed')
|
||||||
|
|
||||||
if (recursive)
|
if (recursive)
|
||||||
this.subfolders.forEach(folder => folder.openFolder(recursive))
|
this.subfolders.forEach(folder => folder.openFolder(recursive))
|
||||||
|
|
@ -280,6 +306,7 @@ class Record {
|
||||||
constructor(data) {// {{{
|
constructor(data) {// {{{
|
||||||
this.data = data || {}
|
this.data = data || {}
|
||||||
|
|
||||||
|
this.folder = null
|
||||||
this.imgIcon = null
|
this.imgIcon = null
|
||||||
this.divFQDN = null
|
this.divFQDN = null
|
||||||
this.divType = null
|
this.divType = null
|
||||||
|
|
@ -337,6 +364,9 @@ class Record {
|
||||||
|
|
||||||
this.data[key] = value
|
this.data[key] = value
|
||||||
}// }}}
|
}// }}}
|
||||||
|
setFolder(folder) {// {{{
|
||||||
|
this.folder = folder
|
||||||
|
}// }}}
|
||||||
render() {// {{{
|
render() {// {{{
|
||||||
if (this.divFQDN === null) {
|
if (this.divFQDN === null) {
|
||||||
this.imgIcon = document.createElement('img')
|
this.imgIcon = document.createElement('img')
|
||||||
|
|
@ -405,14 +435,36 @@ class Record {
|
||||||
// The data is read from the server/routeros device
|
// The data is read from the server/routeros device
|
||||||
// since it could have manipulated the data.
|
// since it could have manipulated the data.
|
||||||
this.data = json.Record
|
this.data = json.Record
|
||||||
if (created)
|
if (created) {
|
||||||
_app.records.push(this)
|
_app.records.push(this)
|
||||||
|
}
|
||||||
|
|
||||||
_app.cleanFolders()
|
_app.cleanFolders()
|
||||||
_app.renderFolders()
|
_app.renderFolders()
|
||||||
_app.render()
|
_app.render()
|
||||||
|
|
||||||
|
// renderFolders is setting the folder the record resides in.
|
||||||
|
// It can now be expanded to the parent folder.
|
||||||
|
if (created) {
|
||||||
|
this.openParentFolders()
|
||||||
|
this.divFQDN.classList.add('created')
|
||||||
|
setTimeout(
|
||||||
|
() => this.divFQDN.classList.remove('created'),
|
||||||
|
1000,
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}// }}}
|
}// }}}
|
||||||
|
|
||||||
|
openParentFolders(folder) {// {{{
|
||||||
|
if (folder === undefined)
|
||||||
|
folder = this.folder
|
||||||
|
|
||||||
|
folder?.openFolder(false)
|
||||||
|
|
||||||
|
if (folder?.parentFolder)
|
||||||
|
this.openParentFolders(folder.parentFolder)
|
||||||
|
}// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RecordDialog {
|
class RecordDialog {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue