Issue 24: Added read-only mode (#27)
- Added settings to workspace, and added the read-only mode - Added the `-ro` field which will launch Dynamo-Browse in read-only mode - Added the `set ro` to enable read-only mode, and `set rw` to enable read-write mode
This commit is contained in:
parent
a1717572c5
commit
93ec519127
18 changed files with 623 additions and 315 deletions
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/lmika/audax/internal/dynamo-browse/ui/teamodels/layout"
|
||||
"github.com/lmika/audax/internal/dynamo-browse/ui/teamodels/styles"
|
||||
table "github.com/lmika/go-bubble-table"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -21,29 +22,38 @@ var (
|
|||
Background(lipgloss.Color("#4479ff"))
|
||||
)
|
||||
|
||||
type Setting interface {
|
||||
IsReadOnly() bool
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
frameTitle frame.FrameTitle
|
||||
table table.Model
|
||||
w, h int
|
||||
keyBinding *keybindings.TableKeyBinding
|
||||
setting Setting
|
||||
|
||||
// model state
|
||||
colOffset int
|
||||
rows []table.Row
|
||||
resultSet *models.ResultSet
|
||||
isReadOnly bool
|
||||
colOffset int
|
||||
rows []table.Row
|
||||
resultSet *models.ResultSet
|
||||
}
|
||||
|
||||
func New(keyBinding *keybindings.TableKeyBinding, uiStyles styles.Styles) *Model {
|
||||
func New(keyBinding *keybindings.TableKeyBinding, setting Setting, uiStyles styles.Styles) *Model {
|
||||
tbl := table.New(table.SimpleColumns([]string{"pk", "sk"}), 100, 100)
|
||||
rows := make([]table.Row, 0)
|
||||
tbl.SetRows(rows)
|
||||
|
||||
frameTitle := frame.NewFrameTitle("No table", true, uiStyles.Frames)
|
||||
isReadOnly := setting.IsReadOnly()
|
||||
|
||||
return &Model{
|
||||
isReadOnly: isReadOnly,
|
||||
frameTitle: frameTitle,
|
||||
table: tbl,
|
||||
keyBinding: keyBinding,
|
||||
setting: setting,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +67,9 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
m.resultSet = msg.ResultSet
|
||||
m.updateTable()
|
||||
return m, m.postSelectedItemChanged
|
||||
case controllers.SettingsUpdated:
|
||||
m.updateTableHeading()
|
||||
return m, nil
|
||||
case tea.KeyMsg:
|
||||
switch {
|
||||
// Table nav
|
||||
|
|
@ -113,10 +126,19 @@ func (m *Model) Resize(w, h int) layout.ResizingModel {
|
|||
return m
|
||||
}
|
||||
|
||||
func (m *Model) updateTable() {
|
||||
m.colOffset = 0
|
||||
func (m *Model) updateTableHeading() {
|
||||
tableName := new(strings.Builder)
|
||||
tableName.WriteString("Table: " + m.resultSet.TableInfo.Name)
|
||||
if m.setting.IsReadOnly() {
|
||||
tableName.WriteString(" [RO]")
|
||||
}
|
||||
|
||||
m.frameTitle.SetTitle("Table: " + m.resultSet.TableInfo.Name)
|
||||
m.frameTitle.SetTitle(tableName.String())
|
||||
}
|
||||
|
||||
func (m *Model) updateTable() {
|
||||
m.updateTableHeading()
|
||||
m.colOffset = 0
|
||||
m.rebuildTable()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue