* Add schema management screen with list and editor * Implement table management screen with list and editor * Create data operations for schema and table management * Define UI rules and guidelines for consistency * Ensure circular tab navigation and keyboard shortcuts * Add forms for creating and editing schemas and tables * Implement confirmation dialogs for destructive actions
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
package ui
|
|
|
|
import (
|
|
"github.com/gdamore/tcell/v2"
|
|
"github.com/rivo/tview"
|
|
)
|
|
|
|
// showEditDatabaseForm displays a dialog to edit database properties
|
|
func (se *SchemaEditor) showEditDatabaseForm() {
|
|
form := tview.NewForm()
|
|
|
|
dbName := se.db.Name
|
|
dbDescription := se.db.Description
|
|
dbComment := se.db.Comment
|
|
dbType := string(se.db.DatabaseType)
|
|
dbVersion := se.db.DatabaseVersion
|
|
|
|
// Database type options
|
|
dbTypeOptions := []string{"pgsql", "mssql", "sqlite"}
|
|
selectedTypeIndex := 0
|
|
for i, opt := range dbTypeOptions {
|
|
if opt == dbType {
|
|
selectedTypeIndex = i
|
|
break
|
|
}
|
|
}
|
|
|
|
form.AddInputField("Database Name", dbName, 40, nil, func(value string) {
|
|
dbName = value
|
|
})
|
|
|
|
form.AddInputField("Description", dbDescription, 50, nil, func(value string) {
|
|
dbDescription = value
|
|
})
|
|
|
|
form.AddInputField("Comment", dbComment, 50, nil, func(value string) {
|
|
dbComment = value
|
|
})
|
|
|
|
form.AddDropDown("Database Type", dbTypeOptions, selectedTypeIndex, func(option string, index int) {
|
|
dbType = option
|
|
})
|
|
|
|
form.AddInputField("Database Version", dbVersion, 20, nil, func(value string) {
|
|
dbVersion = value
|
|
})
|
|
|
|
form.AddButton("Save", func() {
|
|
if dbName == "" {
|
|
return
|
|
}
|
|
se.updateDatabase(dbName, dbDescription, dbComment, dbType, dbVersion)
|
|
se.pages.RemovePage("edit-database")
|
|
se.pages.RemovePage("main")
|
|
se.pages.AddPage("main", se.createMainMenu(), true, true)
|
|
})
|
|
|
|
form.AddButton("Back", func() {
|
|
se.pages.RemovePage("edit-database")
|
|
})
|
|
|
|
form.SetBorder(true).SetTitle(" Edit Database ").SetTitleAlign(tview.AlignLeft)
|
|
form.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
|
if event.Key() == tcell.KeyEscape {
|
|
se.showExitConfirmation("edit-database", "main")
|
|
return nil
|
|
}
|
|
return event
|
|
})
|
|
|
|
se.pages.AddPage("edit-database", form, true, true)
|
|
}
|