Move mark logic to Table
parent
9307f42842
commit
b73bd7cecf
|
|
@ -66,7 +66,6 @@ type (
|
||||||
Rows RowEvents
|
Rows RowEvents
|
||||||
NumCols map[string]bool
|
NumCols map[string]bool
|
||||||
Namespace string
|
Namespace string
|
||||||
Marks map[string]bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// List protocol to display and update a collection of resources
|
// List protocol to display and update a collection of resources
|
||||||
|
|
@ -85,7 +84,6 @@ type (
|
||||||
SetFieldSelector(string)
|
SetFieldSelector(string)
|
||||||
SetLabelSelector(string)
|
SetLabelSelector(string)
|
||||||
HasSelectors() bool
|
HasSelectors() bool
|
||||||
ToggleMark(sk string)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Columnar tracks resources that can be diplayed in a tabular fashion.
|
// Columnar tracks resources that can be diplayed in a tabular fashion.
|
||||||
|
|
@ -129,15 +127,9 @@ type (
|
||||||
verbs int
|
verbs int
|
||||||
resource Resource
|
resource Resource
|
||||||
cache RowEvents
|
cache RowEvents
|
||||||
marks map[string]bool
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsMarked checks if key is marked.
|
|
||||||
func (t *TableData) IsMarked(sk string) bool {
|
|
||||||
return t.Marks[sk]
|
|
||||||
}
|
|
||||||
|
|
||||||
func newRowEvent(a watch.EventType, f, d Row) *RowEvent {
|
func newRowEvent(a watch.EventType, f, d Row) *RowEvent {
|
||||||
return &RowEvent{Action: a, Fields: f, Deltas: d}
|
return &RowEvent{Action: a, Fields: f, Deltas: d}
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +142,6 @@ func NewList(ns, name string, res Resource, verbs int) *list {
|
||||||
verbs: verbs,
|
verbs: verbs,
|
||||||
resource: res,
|
resource: res,
|
||||||
cache: RowEvents{},
|
cache: RowEvents{},
|
||||||
marks: make(map[string]bool),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,7 +232,6 @@ func (l *list) Data() TableData {
|
||||||
Rows: l.cache,
|
Rows: l.cache,
|
||||||
NumCols: l.resource.NumCols(l.namespace),
|
NumCols: l.resource.NumCols(l.namespace),
|
||||||
Namespace: l.namespace,
|
Namespace: l.namespace,
|
||||||
Marks: l.marks,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,19 +343,10 @@ func (l *list) ensureDeletes(kk []string) {
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
delete(l.cache, k)
|
delete(l.cache, k)
|
||||||
l.removeMark(k)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *list) removeMark(sk string) {
|
|
||||||
delete(l.marks, sk)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *list) ToggleMark(sk string) {
|
|
||||||
l.marks[sk] = !l.marks[sk]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helpers...
|
// Helpers...
|
||||||
|
|
||||||
func computeDeltas(evt *RowEvent, newRow, deltas Row) watch.EventType {
|
func computeDeltas(evt *RowEvent, newRow, deltas Row) watch.EventType {
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ type Table struct {
|
||||||
selectedRow int
|
selectedRow int
|
||||||
selectedFn func(string) string
|
selectedFn func(string) string
|
||||||
selListeners []SelectedRowFunc
|
selListeners []SelectedRowFunc
|
||||||
|
marks map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTable returns a new table view.
|
// NewTable returns a new table view.
|
||||||
|
|
@ -53,6 +54,7 @@ func NewTable(title string, styles *config.Styles) *Table {
|
||||||
cmdBuff: NewCmdBuff('/', FilterBuff),
|
cmdBuff: NewCmdBuff('/', FilterBuff),
|
||||||
baseTitle: title,
|
baseTitle: title,
|
||||||
sortCol: SortColumn{0, 0, true},
|
sortCol: SortColumn{0, 0, true},
|
||||||
|
marks: make(map[string]bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
v.SetFixed(1, 0)
|
v.SetFixed(1, 0)
|
||||||
|
|
@ -171,9 +173,9 @@ func (v *Table) GetSelectedItem() string {
|
||||||
|
|
||||||
// GetSelectedItems return currently marked or selected items names.
|
// GetSelectedItems return currently marked or selected items names.
|
||||||
func (v *Table) GetSelectedItems() []string {
|
func (v *Table) GetSelectedItems() []string {
|
||||||
if len(v.data.Marks) > 0 {
|
if len(v.marks) > 0 {
|
||||||
var items []string
|
var items []string
|
||||||
for item, marked := range v.data.Marks {
|
for item, marked := range v.marks {
|
||||||
if marked {
|
if marked {
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
|
|
@ -332,7 +334,7 @@ func (v *Table) buildRow(row int, data resource.TableData, sk string, pads MaxyP
|
||||||
if v.colorerFn != nil {
|
if v.colorerFn != nil {
|
||||||
f = v.colorerFn
|
f = v.colorerFn
|
||||||
}
|
}
|
||||||
m := data.IsMarked(sk)
|
m := v.isMarked(sk)
|
||||||
for col, field := range data.Rows[sk].Fields {
|
for col, field := range data.Rows[sk].Fields {
|
||||||
header := data.Header[col]
|
header := data.Header[col]
|
||||||
field, align := v.formatCell(data.NumCols[header], header, field+Deltas(data.Rows[sk].Deltas[col], field), pads[col])
|
field, align := v.formatCell(data.NumCols[header], header, field+Deltas(data.Rows[sk].Deltas[col], field), pads[col])
|
||||||
|
|
@ -540,3 +542,12 @@ func (v *Table) SortInvertCmd(evt *tcell.EventKey) *tcell.EventKey {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToggleMark toggles marked row
|
||||||
|
func (v *Table) ToggleMark() {
|
||||||
|
v.marks[v.GetSelectedItem()] = !v.marks[v.GetSelectedItem()]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Table) isMarked(item string) bool {
|
||||||
|
return v.marks[item]
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -225,8 +225,7 @@ func (v *resourceView) markCmd(evt *tcell.EventKey) *tcell.EventKey {
|
||||||
return evt
|
return evt
|
||||||
}
|
}
|
||||||
|
|
||||||
sel := v.masterPage().GetSelectedItem()
|
v.masterPage().ToggleMark()
|
||||||
v.list.ToggleMark(sel)
|
|
||||||
v.refresh()
|
v.refresh()
|
||||||
v.app.Draw()
|
v.app.Draw()
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue