Skip to content

Commit

Permalink
Implementing 'attribute anchoring' to facilitate attribute inspection…
Browse files Browse the repository at this point in the history
… by navigation across different objects.
  • Loading branch information
Macmod committed Sep 12, 2024
1 parent adf6840 commit a2f1a94
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ You can also change the address of your proxy using the `l` keybinding.
| <kbd>r</kbd> | Explorer panel | Reload the attributes and children of the selected object |
| <kbd>Ctrl</kbd> + <kbd>n</kbd> | Explorer panel | Create a new object under the selected object |
| <kbd>Ctrl</kbd> + <kbd>s</kbd> | Explorer panel | Export all loaded nodes in the selected subtree into a JSON file |
| <kbd>Ctrl</kbd> + <kbd>p</kbd> | Explorer panel | Change the password of the selected user or computer account |
| <kbd>Ctrl</kbd> + <kbd>p</kbd> | Explorer panel | Change the password of the selected user or computer account (requires TLS) |
| <kbd>Ctrl</kbd> + <kbd>a</kbd> | Explorer panel | Update the userAccountControl of the object interactively |
| <kbd>Ctrl</kbd> + <kbd>l</kbd> | Explorer panel | Move the selected object to another location |
| <kbd>Delete</kbd> | Explorer panel | Delete the selected object |
Expand Down
3 changes: 3 additions & 0 deletions tui/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func initExplorerPage() {
return attrsPanelKeyHandler(event, currentNode, &explorerCache, explorerAttrsPanel)
})

explorerAttrsPanel.SetSelectionChangedFunc(storeAnchoredAttribute(explorerAttrsPanel))

treePanel.SetInputCapture(treePanelKeyHandler)

treePanel.SetChangedFunc(treePanelChangeHandler)
Expand Down Expand Up @@ -523,6 +525,7 @@ func treePanelChangeHandler(node *tview.TreeNode) {
go app.QueueUpdateDraw(func() {
// TODO: Implement cancellation
reloadExplorerAttrsPanel(node, CacheEntries)
selectAnchoredAttribute(explorerAttrsPanel)
})
}

Expand Down
2 changes: 2 additions & 0 deletions tui/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func initSearchPage() {
searchTreePanel.SetChangedFunc(func(node *tview.TreeNode) {
searchAttrsPanel.Clear()
reloadSearchAttrsPanel(node, true)
selectAnchoredAttribute(searchAttrsPanel)
})

searchAttrsPanel = tview.NewTable().
Expand All @@ -76,6 +77,7 @@ func initSearchPage() {

return attrsPanelKeyHandler(event, currentNode, &searchCache, searchAttrsPanel)
})
searchAttrsPanel.SetSelectionChangedFunc(storeAnchoredAttribute(searchAttrsPanel))

searchLibraryPanel = tview.NewTreeView()

Expand Down
48 changes: 43 additions & 5 deletions tui/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,43 @@ import (
"github.com/rivo/tview"
)

var selectedAttrName string = "objectClass"

func storeAnchoredAttribute(attrsPanel *tview.Table) func(row, column int) {
return func(row, column int) {
selectedText := attrsPanel.GetCell(row, 0)
cellRef := selectedText.GetReference()
if cellRef != nil {
attrName, ok := cellRef.(string)
if ok {
selectedAttrName = attrName
}
}
}
}

func selectAnchoredAttribute(attrsPanel *tview.Table) {
rowCount := attrsPanel.GetRowCount()

for idx := 0; idx < rowCount; idx++ {
cell := attrsPanel.GetCell(idx, 0)
cellRef := cell.GetReference()
if cellRef == nil {
continue
}

cellAttrName, ok := cellRef.(string)
if !ok {
continue
}

if cellAttrName == selectedAttrName {
attrsPanel.Select(idx, 0)
break
}
}
}

func createTreeNodeFromEntry(entry *ldap.Entry) *tview.TreeNode {
_, ok := explorerCache.Get(entry.DN)

Expand Down Expand Up @@ -371,7 +408,7 @@ func reloadAttributesPanel(node *tview.TreeNode, attrsTable *tview.Table, useCac

var cellValues []string

attrsTable.SetCell(row, 0, tview.NewTableCell(cellName))
attrsTable.SetCell(row, 0, tview.NewTableCell(cellName).SetReference(cellName))

if FormatAttrs {
cellValues = ldaputils.FormatLDAPAttribute(attribute, TimeFormat)
Expand All @@ -380,7 +417,7 @@ func reloadAttributesPanel(node *tview.TreeNode, attrsTable *tview.Table, useCac
}

if !ExpandAttrs {
myCell := tview.NewTableCell(strings.Join(cellValues, "; "))
myCell := tview.NewTableCell(strings.Join(cellValues, "; ")).SetReference(cellName)

if Colors {
color, ok := ldaputils.GetAttrCellColor(cellName, attribute.Values[0])
Expand All @@ -395,7 +432,7 @@ func reloadAttributesPanel(node *tview.TreeNode, attrsTable *tview.Table, useCac
}

for idx, cellValue := range cellValues {
myCell := tview.NewTableCell(cellValue)
myCell := tview.NewTableCell(cellValue).SetReference(cellName)

if Colors {
var refValue string
Expand All @@ -417,10 +454,11 @@ func reloadAttributesPanel(node *tview.TreeNode, attrsTable *tview.Table, useCac
} else {
if ExpandAttrs {
if AttrLimit == -1 || idx < AttrLimit {
attrsTable.SetCell(row, 0, tview.NewTableCell(""))
attrsTable.SetCell(row, 0, tview.NewTableCell("").SetReference(cellName))
attrsTable.SetCell(row, 1, myCell)
if idx == AttrLimit-1 {
attrsTable.SetCell(row+1, 1, tview.NewTableCell("[entries hidden]"))
attrsTable.SetCell(row+1, 0, tview.NewTableCell("").SetReference(cellName))
attrsTable.SetCell(row+1, 1, tview.NewTableCell("[entries hidden]").SetReference(cellName))
row = row + 2
break
}
Expand Down

0 comments on commit a2f1a94

Please sign in to comment.