-
Notifications
You must be signed in to change notification settings - Fork 26
/
sec_grp.go
42 lines (35 loc) · 1.05 KB
/
sec_grp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package view
import (
"github.com/gdamore/tcell/v2"
"github.com/one2nc/cloudlens/internal/ui"
)
type SG struct {
ResourceViewer
}
// NewSG returns a new viewer.
func NewSG(resource string) ResourceViewer {
var sg SG
sg.ResourceViewer = NewBrowser(resource)
sg.AddBindKeysFn(sg.bindKeys)
return &sg
}
func (sg SG) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftI: ui.NewKeyAction("Sort Group-Id", sg.GetTable().SortColCmd("Group-Id", true), true),
ui.KeyShiftN: ui.NewKeyAction("Sort Group-Name", sg.GetTable().SortColCmd("Group-Name", true), true),
tcell.KeyEscape: ui.NewKeyAction("Back", sg.App().PrevCmd, false),
tcell.KeyEnter: ui.NewKeyAction("View", sg.enterCmd, false),
})
}
func (sg *SG) enterCmd(evt *tcell.EventKey) *tcell.EventKey {
groupId := sg.GetTable().GetSelectedItem()
if groupId != "" {
f := describeResource
if sg.GetTable().enterFn != nil {
f = sg.GetTable().enterFn
}
f(sg.App(), sg.GetTable().GetModel(), sg.Resource(), groupId)
sg.App().Flash().Info("groupId: " + groupId)
}
return nil
}