start to simplify some of the UI code
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
0c7ed3bab4
commit
910107d044
71
main.go
71
main.go
|
@ -31,25 +31,6 @@ import "github.com/andlabs/ui"
|
||||||
|
|
||||||
var mainwin *ui.Window
|
var mainwin *ui.Window
|
||||||
|
|
||||||
func hostnameStuff() ui.Control {
|
|
||||||
tmpbox := ui.NewHorizontalBox()
|
|
||||||
tmpbox.SetPadded(true)
|
|
||||||
|
|
||||||
// start hostname button
|
|
||||||
// hostname := config.String("hostname")
|
|
||||||
// hostname, error := os.Hostname()
|
|
||||||
|
|
||||||
tmpButton := ui.NewButton(config.String("hostname"))
|
|
||||||
tmpbox.Append(tmpButton, false)
|
|
||||||
tmpButton.OnClicked(func(*ui.Button) {
|
|
||||||
log.Println("hostname =", config.String("hostname"))
|
|
||||||
config.Set("hostname", "librem15.lab.wit.com")
|
|
||||||
})
|
|
||||||
// tmpbox.Append(ui.NewLabel("hostname '" + hostname + "' is invalid"), false)
|
|
||||||
|
|
||||||
return tmpbox
|
|
||||||
}
|
|
||||||
|
|
||||||
func hostnameButton(hostname string) ui.Control {
|
func hostnameButton(hostname string) ui.Control {
|
||||||
tmpbox := ui.NewHorizontalBox()
|
tmpbox := ui.NewHorizontalBox()
|
||||||
tmpbox.SetPadded(true)
|
tmpbox.SetPadded(true)
|
||||||
|
@ -59,44 +40,30 @@ func hostnameButton(hostname string) ui.Control {
|
||||||
tmpButton.OnClicked(func(*ui.Button) {
|
tmpButton.OnClicked(func(*ui.Button) {
|
||||||
log.Println("hostname =", config.String("hostname"), tmpButton)
|
log.Println("hostname =", config.String("hostname"), tmpButton)
|
||||||
})
|
})
|
||||||
// tmpbox.Append(ui.NewLabel("hostname '" + hostname), false)
|
|
||||||
|
|
||||||
return tmpbox
|
return tmpbox
|
||||||
}
|
}
|
||||||
|
|
||||||
func listPhysicalMachines(vbox *ui.Box, machineType string) {
|
func getPhysicalMachines(machineType string) []string {
|
||||||
|
var machines []string
|
||||||
home, _ := homedir.Dir()
|
home, _ := homedir.Dir()
|
||||||
files, err := ioutil.ReadDir(home+"/wit/ansible/inventory-usw2/host_vars/")
|
files, err := ioutil.ReadDir(home+"/wit/ansible/inventory-usw2/host_vars/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return machines
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
s := strings.Split(f.Name(), ".")
|
s := strings.Split(f.Name(), ".")
|
||||||
if strings.HasPrefix(s[1], machineType) {
|
if strings.HasPrefix(s[1], machineType) {
|
||||||
fmt.Println(f.Name(), s)
|
fmt.Println(f.Name(), s)
|
||||||
vbox.Append(hostnameButton(f.Name()), false)
|
machines = append(machines, f.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return machines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func makeBasicControlsPage(machineType string) ui.Control {
|
|
||||||
vbox := ui.NewVerticalBox()
|
|
||||||
vbox.SetPadded(true)
|
|
||||||
|
|
||||||
hbox := ui.NewHorizontalBox()
|
|
||||||
hbox.SetPadded(true)
|
|
||||||
vbox.Append(hbox, false)
|
|
||||||
|
|
||||||
listPhysicalMachines(vbox, machineType)
|
|
||||||
|
|
||||||
vbox.Append(ui.NewHorizontalSeparator(), false)
|
|
||||||
|
|
||||||
return vbox
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPods(machineType string) []string {
|
func getPods(machineType string) []string {
|
||||||
var pods []string
|
var pods []string
|
||||||
home, _ := homedir.Dir()
|
home, _ := homedir.Dir()
|
||||||
|
@ -155,29 +122,6 @@ func makeGroupEntries() ui.Control {
|
||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeInterfaces() ui.Control {
|
|
||||||
group := ui.NewGroup("Interfaces")
|
|
||||||
group.SetMargined(true)
|
|
||||||
|
|
||||||
group.SetChild(ui.NewNonWrappingMultilineEntry())
|
|
||||||
|
|
||||||
entryForm := ui.NewForm()
|
|
||||||
entryForm.SetPadded(true)
|
|
||||||
group.SetChild(entryForm)
|
|
||||||
|
|
||||||
for _, addr := range config.Strings("arr1") {
|
|
||||||
log.Println("Adding entry for internface =", addr)
|
|
||||||
entryForm.Append(addr, ui.NewEntry(), false)
|
|
||||||
}
|
|
||||||
|
|
||||||
entryForm.Append("Password Entry", ui.NewPasswordEntry(), false)
|
|
||||||
entryForm.Append("Search Entry", ui.NewSearchEntry(), false)
|
|
||||||
entryForm.Append("Multiline Entry", ui.NewMultilineEntry(), true)
|
|
||||||
entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true)
|
|
||||||
|
|
||||||
return group
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeNumbersPage() ui.Control {
|
func makeNumbersPage() ui.Control {
|
||||||
hbox := ui.NewHorizontalBox()
|
hbox := ui.NewHorizontalBox()
|
||||||
hbox.SetPadded(true)
|
hbox.SetPadded(true)
|
||||||
|
@ -340,13 +284,12 @@ func setupUI() {
|
||||||
mainwin.SetChild(tab)
|
mainwin.SetChild(tab)
|
||||||
mainwin.SetMargined(true)
|
mainwin.SetMargined(true)
|
||||||
|
|
||||||
tab.Append("Hypervisors", makeBasicControlsPage("h"))
|
tab.Append("Hypervisors", makeButtonsPage(getPhysicalMachines("h")))
|
||||||
tab.SetMargined(0, true)
|
tab.SetMargined(0, true)
|
||||||
|
|
||||||
tab.Append("Ceph", makeBasicControlsPage("d"))
|
tab.Append("Ceph", makeButtonsPage(getPhysicalMachines("d")))
|
||||||
tab.SetMargined(0, true)
|
tab.SetMargined(0, true)
|
||||||
|
|
||||||
getPods("j")
|
|
||||||
tab.Append("k8s Pods", makeButtonsPage(getPods(".wit.com")))
|
tab.Append("k8s Pods", makeButtonsPage(getPods(".wit.com")))
|
||||||
tab.SetMargined(0, true)
|
tab.SetMargined(0, true)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue