2019-05-22 22:49:28 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
2019-05-24 23:07:40 -05:00
|
|
|
import "time"
|
2019-05-27 19:23:19 -05:00
|
|
|
import "regexp"
|
2019-05-22 22:49:28 -05:00
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
import pb "git.wit.com/wit/witProtobuf"
|
2019-05-24 23:07:40 -05:00
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
// import "github.com/davecgh/go-spew/spew"
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-26 14:10:48 -05:00
|
|
|
func makeCloudInfoBox() *ui.Box {
|
2019-05-22 22:49:28 -05:00
|
|
|
hbox := ui.NewHorizontalBox()
|
|
|
|
hbox.SetPadded(true)
|
|
|
|
|
2019-05-24 20:17:05 -05:00
|
|
|
if (Data.Debug) {
|
2019-05-24 02:40:52 -05:00
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
|
|
|
hbox.Append(vbox, false)
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-26 14:40:07 -05:00
|
|
|
addDebuggingButtons(vbox)
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-24 02:40:52 -05:00
|
|
|
hbox.Append(ui.NewVerticalSeparator(), false)
|
|
|
|
}
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-24 02:40:52 -05:00
|
|
|
vbox := ui.NewVerticalBox()
|
2019-05-22 22:49:28 -05:00
|
|
|
vbox.SetPadded(true)
|
|
|
|
hbox.Append(vbox, true)
|
|
|
|
|
2019-05-24 02:04:14 -05:00
|
|
|
hostnamebox := ui.NewHorizontalBox()
|
|
|
|
hostnamebox.SetPadded(true)
|
|
|
|
vbox.Append(hostnamebox, false)
|
|
|
|
|
2019-05-22 22:49:28 -05:00
|
|
|
entryForm := ui.NewForm()
|
|
|
|
entryForm.SetPadded(true)
|
2019-05-24 02:04:14 -05:00
|
|
|
hostnamebox.Append(entryForm, true)
|
2019-05-22 22:49:28 -05:00
|
|
|
|
|
|
|
hostnameEntry := ui.NewEntry()
|
|
|
|
entryForm.Append("hostname:", hostnameEntry, false)
|
2019-05-24 02:04:14 -05:00
|
|
|
tmp := Data.Hostname + " (" + Data.IPv6 + ")"
|
|
|
|
hostnameEntry.SetText(tmp)
|
|
|
|
hostnameEntry.SetReadOnly(true)
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-26 14:40:07 -05:00
|
|
|
hostnamebox.Append(CreateButton(nil, nil, "Edit", "EDIT", nil), false)
|
2019-05-22 22:49:28 -05:00
|
|
|
|
2019-05-23 11:48:12 -05:00
|
|
|
vbox.Append(ui.NewHorizontalSeparator(), false)
|
|
|
|
|
|
|
|
agrid := ui.NewGrid()
|
|
|
|
agrid.SetPadded(true)
|
|
|
|
|
2019-05-23 17:07:10 -05:00
|
|
|
agrid.Append(ui.NewLabel("Accounts:"), 0, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
agrid.Append(ui.NewLabel("Nickname"), 1, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
agrid.Append(ui.NewLabel("Username"), 2, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
agrid.Append(ui.NewLabel("Domain Name"), 3, 0, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
|
|
|
|
row := 1
|
|
|
|
|
2019-05-27 23:29:30 -05:00
|
|
|
for key, a := range Data.Config.Accounts {
|
|
|
|
log.Println("account = ", key, a)
|
2019-05-26 04:19:09 -05:00
|
|
|
log.Println("Accounts[key] = ", Data.Config.Accounts[key])
|
|
|
|
log.Println("account.Nick = ", Data.Config.Accounts[key].Nick)
|
2019-05-24 20:17:05 -05:00
|
|
|
log.Println("account.Username = ", Data.Config.Accounts[key].Username)
|
2019-05-26 04:19:09 -05:00
|
|
|
log.Println("account.Token = ", Data.Config.Accounts[key].Token)
|
2019-05-23 17:07:10 -05:00
|
|
|
|
2019-05-26 04:19:09 -05:00
|
|
|
agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Nick), 1, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Username), 2, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
agrid.Append(ui.NewLabel(Data.Config.Accounts[key].Domain), 3, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
2019-05-23 19:44:00 -05:00
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
name := "Login " + Data.Config.Accounts[key].Nick
|
2019-05-26 14:40:07 -05:00
|
|
|
l := CreateButton(Data.Config.Accounts[key], nil, name, "LOGIN", nil)
|
2019-05-24 02:04:14 -05:00
|
|
|
agrid.Append(l, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
name = "Show " + Data.Config.Accounts[key].Nick
|
2019-05-26 14:40:07 -05:00
|
|
|
b := CreateButton(Data.Config.Accounts[key], nil, name, "SHOW", nil)
|
2019-05-24 02:04:14 -05:00
|
|
|
agrid.Append(b, 5, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
2019-05-23 17:07:10 -05:00
|
|
|
|
|
|
|
row += 1
|
2019-05-23 11:48:12 -05:00
|
|
|
}
|
2019-05-24 20:17:05 -05:00
|
|
|
|
2019-05-24 02:40:52 -05:00
|
|
|
row += 1
|
|
|
|
agrid.Append(ui.NewLabel(""), 1, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
|
|
|
row += 1
|
2019-05-27 17:25:30 -05:00
|
|
|
a := CreateButton(nil, nil, "Add Account", "ADD TAB", nil)
|
2019-05-24 02:40:52 -05:00
|
|
|
agrid.Append(a, 4, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
2019-05-26 14:40:07 -05:00
|
|
|
q := CreateButton(nil, nil, "Quit", "QUIT", nil)
|
2019-05-24 02:40:52 -05:00
|
|
|
agrid.Append(q, 5, row, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
|
2019-05-23 17:07:10 -05:00
|
|
|
|
|
|
|
vbox.Append(agrid, false)
|
2019-05-22 22:49:28 -05:00
|
|
|
return hbox
|
|
|
|
}
|
|
|
|
|
2019-05-24 23:07:40 -05:00
|
|
|
//
|
|
|
|
// THIS IS THE STANDARD VM DISPLAY TABLE
|
|
|
|
// This maps the 'human' indexed cells in the table
|
|
|
|
// to the machine's andlabs/libui values. That way
|
|
|
|
// if you want to work against column 4, then you
|
|
|
|
// can just reference 4 instead of the internal number
|
|
|
|
// which could be anything since TEXTCOLOR, TEXT, BG, etc
|
|
|
|
// fields use between 1 and 3 values internally
|
|
|
|
//
|
2019-05-25 04:50:43 -05:00
|
|
|
func AddVmsTab(name string, count int, a *pb.Account) *TableData {
|
2019-05-22 22:49:28 -05:00
|
|
|
var parts []TableColumnData
|
|
|
|
|
|
|
|
human := 0
|
|
|
|
|
|
|
|
tmp := TableColumnData{}
|
|
|
|
tmp.CellType = "BG"
|
|
|
|
tmp.Heading = "background"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "name"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "hostname"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "IPv6"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "cpus"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "memory"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "BUTTON"
|
2019-05-24 23:07:40 -05:00
|
|
|
tmp.Heading = "Details"
|
2019-05-22 22:49:28 -05:00
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
2019-05-24 22:54:09 -05:00
|
|
|
mh := AddTableTab(Data.cloudTab, 1, name, count, parts, a)
|
2019-05-22 22:49:28 -05:00
|
|
|
return mh
|
|
|
|
}
|
2019-05-24 23:07:40 -05:00
|
|
|
|
|
|
|
func ShowAccountQuestionTab() {
|
|
|
|
Data.cloudTab.Delete(0)
|
|
|
|
|
|
|
|
log.Println("Sleep(200)")
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
|
2019-05-26 14:40:07 -05:00
|
|
|
Data.smallBox = AddAccountQuestionBox()
|
2019-05-24 23:07:40 -05:00
|
|
|
Data.cloudTab.InsertAt("New Account?", 0, Data.smallBox)
|
|
|
|
Data.cloudTab.SetMargined(0, true)
|
|
|
|
}
|
|
|
|
|
2019-05-27 12:55:10 -05:00
|
|
|
func ShowAccountTab(i int) {
|
2019-05-27 17:25:30 -05:00
|
|
|
log.Println("ShowAccountTab() START")
|
2019-05-24 23:07:40 -05:00
|
|
|
|
|
|
|
log.Println("Sleep(200)")
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
|
2019-05-25 03:36:36 -05:00
|
|
|
// Create the things for the Account Tab
|
2019-05-27 12:55:10 -05:00
|
|
|
abox := AddAccountBox()
|
2019-05-25 03:36:36 -05:00
|
|
|
|
|
|
|
// Set the parents and data structure links
|
2019-05-27 12:55:10 -05:00
|
|
|
// aTab.me = Data.cloudTab
|
2019-05-27 17:25:30 -05:00
|
|
|
// aTab.parentWindow = Data.cloudWindow
|
|
|
|
// aTab.tabOffset = 0
|
2019-05-27 12:55:10 -05:00
|
|
|
|
|
|
|
if (i >= 0) {
|
2019-05-27 17:25:30 -05:00
|
|
|
log.Println("ShowAccountTab() InsertAt i=", i)
|
|
|
|
Data.cloudTab.Delete(0)
|
|
|
|
Data.cloudTab.InsertAt("Add Account", i, abox)
|
|
|
|
Data.cloudTab.SetMargined(0, true)
|
2019-05-27 12:55:10 -05:00
|
|
|
} else {
|
2019-05-27 17:25:30 -05:00
|
|
|
// TODO: After append try to discover the tab index #
|
|
|
|
log.Println("ShowAccountTab() Append")
|
|
|
|
AddBoxToTab("Create New Account", Data.cloudTab, abox)
|
2019-05-27 12:55:10 -05:00
|
|
|
}
|
2019-05-24 23:07:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func ShowMainTab() {
|
|
|
|
Data.cloudTab.Delete(0)
|
|
|
|
|
|
|
|
log.Println("Sleep(200)")
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
|
2019-05-26 14:10:48 -05:00
|
|
|
Data.smallBox = makeCloudInfoBox()
|
2019-05-24 23:07:40 -05:00
|
|
|
Data.cloudTab.InsertAt("Main", 0, Data.smallBox)
|
|
|
|
Data.cloudTab.SetMargined(0, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GoMainWindow() {
|
|
|
|
ui.Main(makeCloudWindow)
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeCloudWindow() {
|
|
|
|
Data.cloudWindow = ui.NewWindow("", Data.Width, Data.Height, true)
|
|
|
|
// cloudWindow.SetBorderless(true)
|
2019-05-26 13:54:33 -05:00
|
|
|
|
|
|
|
// create a 'fake' button entry for the mouse clicks
|
|
|
|
var newButtonMap ButtonMap
|
|
|
|
newButtonMap.Action = "QUIT"
|
|
|
|
Data.AllButtons = append(Data.AllButtons, newButtonMap)
|
|
|
|
|
2019-05-24 23:07:40 -05:00
|
|
|
Data.cloudWindow.OnClosing(func(*ui.Window) bool {
|
2019-05-26 13:54:33 -05:00
|
|
|
mouseClick(&newButtonMap)
|
2019-05-24 23:07:40 -05:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
ui.OnShouldQuit(func() bool {
|
2019-05-26 13:54:33 -05:00
|
|
|
mouseClick(&newButtonMap)
|
2019-05-24 23:07:40 -05:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
Data.cloudTab = ui.NewTab()
|
|
|
|
Data.cloudWindow.SetChild(Data.cloudTab)
|
|
|
|
Data.cloudWindow.SetMargined(true)
|
|
|
|
|
2019-05-26 14:05:23 -05:00
|
|
|
Data.cloudBox = ShowSplashBox()
|
2019-05-24 23:07:40 -05:00
|
|
|
|
|
|
|
Data.cloudTab.Append("WIT Splash", Data.cloudBox)
|
|
|
|
Data.cloudTab.SetMargined(0, true)
|
|
|
|
|
|
|
|
Data.cloudWindow.Show()
|
|
|
|
Data.State = "splash"
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
/*
|
2019-05-24 23:07:40 -05:00
|
|
|
func AddVmConfigureTab(name string, pbVM *pb.Event_VM) {
|
2019-05-26 19:28:34 -05:00
|
|
|
CreateVmBox(Data.cloudTab, Data.CurrentVM)
|
2019-05-24 23:07:40 -05:00
|
|
|
}
|
2019-05-29 09:24:40 -05:00
|
|
|
*/
|
2019-05-24 23:07:40 -05:00
|
|
|
|
|
|
|
// makeEntryBox(box, "hostname:", "blah.foo.org") {
|
2019-05-27 23:29:30 -05:00
|
|
|
func makeEntryVbox(hbox *ui.Box, a string, startValue string, edit bool, action string) *EntryMap {
|
2019-05-24 23:07:40 -05:00
|
|
|
// Start 'Nickname' vertical box
|
|
|
|
vboxN := ui.NewVerticalBox()
|
|
|
|
vboxN.SetPadded(true)
|
|
|
|
vboxN.Append(ui.NewLabel(a), false)
|
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
e := defaultMakeEntry(startValue, edit, action)
|
2019-05-24 23:07:40 -05:00
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
vboxN.Append(e.E, false)
|
2019-05-24 23:07:40 -05:00
|
|
|
hbox.Append(vboxN, false)
|
|
|
|
// End 'Nickname' vertical box
|
2019-05-27 23:29:30 -05:00
|
|
|
|
|
|
|
return e
|
2019-05-24 23:07:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
/*
|
|
|
|
// string handling examples that might be helpful for normalizeInt()
|
|
|
|
isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString
|
|
|
|
|
|
|
|
for _, username := range []string{"userone", "user2", "user-three"} {
|
|
|
|
if !isAlpha(username) {
|
|
|
|
fmt.Printf("%q is not valid\n", username)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const alpha = "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
|
|
|
|
func alphaOnly(s string) bool {
|
|
|
|
for _, char := range s {
|
|
|
|
if !strings.Contains(alpha, strings.ToLower(string(char))) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
func normalizeInt(s string) string {
|
|
|
|
// reg, err := regexp.Compile("[^a-zA-Z0-9]+")
|
|
|
|
reg, err := regexp.Compile("[^0-9]+")
|
|
|
|
if err != nil {
|
|
|
|
log.Println("normalizeInt() regexp.Compile() ERROR =", err)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
clean := reg.ReplaceAllString(s, "")
|
|
|
|
log.Println("normalizeInt() s =", clean)
|
|
|
|
return clean
|
|
|
|
}
|
|
|
|
|
2019-05-27 18:27:43 -05:00
|
|
|
func defaultEntryChange(e *ui.Entry) {
|
2019-05-27 23:29:30 -05:00
|
|
|
for key, em := range Data.AllEntries {
|
2019-05-27 18:27:43 -05:00
|
|
|
if (Data.Debug) {
|
2019-05-27 23:29:30 -05:00
|
|
|
log.Println("\tdefaultEntryChange() Data.AllEntries =", key, em)
|
2019-05-27 18:27:43 -05:00
|
|
|
}
|
|
|
|
if Data.AllEntries[key].E == e {
|
2019-05-27 19:23:19 -05:00
|
|
|
log.Println("defaultEntryChange() FOUND",
|
|
|
|
"action =", Data.AllEntries[key].Action,
|
|
|
|
"Last =", Data.AllEntries[key].Last,
|
|
|
|
"e.Text() =", e.Text())
|
|
|
|
Data.AllEntries[key].Last = e.Text()
|
|
|
|
if Data.AllEntries[key].Normalize != nil {
|
|
|
|
fixed := Data.AllEntries[key].Normalize(e.Text())
|
|
|
|
e.SetText(fixed)
|
|
|
|
}
|
2019-05-27 18:27:43 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Println("defaultEntryChange() ERROR. MISSING ENTRY MAP. e.Text() =", e.Text())
|
|
|
|
}
|
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
func defaultMakeEntry(startValue string, edit bool, action string) *EntryMap {
|
2019-05-27 18:27:43 -05:00
|
|
|
e := ui.NewEntry()
|
|
|
|
e.SetText(startValue)
|
|
|
|
if (edit == false) {
|
|
|
|
e.SetReadOnly(true)
|
|
|
|
}
|
|
|
|
e.OnChanged(defaultEntryChange)
|
|
|
|
|
|
|
|
// add the entry field to the global map
|
|
|
|
var newEntryMap EntryMap
|
|
|
|
newEntryMap.E = e
|
|
|
|
newEntryMap.Edit = edit
|
|
|
|
newEntryMap.Action = action
|
2019-05-27 19:23:19 -05:00
|
|
|
if (action == "Memory") {
|
|
|
|
newEntryMap.Normalize = normalizeInt
|
|
|
|
}
|
2019-05-27 18:27:43 -05:00
|
|
|
Data.AllEntries = append(Data.AllEntries, newEntryMap)
|
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
return &newEntryMap
|
2019-05-27 18:27:43 -05:00
|
|
|
}
|
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
func makeEntryHbox(hbox *ui.Box, a string, startValue string, edit bool, action string) *EntryMap {
|
2019-05-24 23:07:40 -05:00
|
|
|
// Start 'Nickname' vertical box
|
|
|
|
hboxN := ui.NewHorizontalBox()
|
|
|
|
hboxN.SetPadded(true)
|
|
|
|
hboxN.Append(ui.NewLabel(a), false)
|
|
|
|
|
2019-05-27 19:23:19 -05:00
|
|
|
e := defaultMakeEntry(startValue, edit, action)
|
|
|
|
hboxN.Append(e.E, false)
|
2019-05-24 23:07:40 -05:00
|
|
|
|
|
|
|
hbox.Append(hboxN, false)
|
|
|
|
// End 'Nickname' vertical box
|
2019-05-27 19:23:19 -05:00
|
|
|
|
|
|
|
return e
|
2019-05-24 23:07:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-27 17:25:30 -05:00
|
|
|
func AddBoxToTab(name string, tab *ui.Tab, box *ui.Box) {
|
|
|
|
tab.Append(name, box)
|
|
|
|
tab.SetMargined(0, true)
|
|
|
|
}
|