The git.wit.com/gui code is in much better shape now

so I can move the focus to here.

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-02 20:50:16 -07:00
parent 468842e572
commit 1f23138db8
6 changed files with 73 additions and 59 deletions

View File

@ -72,28 +72,16 @@ func ReadReceivedData(data *pb.Event, mh *gui.TableData, box *gui.GuiBox) {
// create entries for the mouse clicks within tables // create entries for the mouse clicks within tables
var newGuiButton gui.GuiButton var newGuiButton gui.GuiButton
newGuiButton.Action = "SHOW VM WAS HERE"
newGuiButton.Custom = showVmMouseClick newGuiButton.Custom = showVmMouseClick
newGuiButton.VM = vm // set the button to this VM
// newGuiButton.GW = box
if (box.Window == nil) { if (box.Window == nil) {
newGuiButton.Action = "SHOW VM WAS HERE NIL"
panic("ReadReceivedData() box == nil") panic("ReadReceivedData() box == nil")
} }
newGuiButton.Account = data.Account
newGuiButton.Box = mh.Box newGuiButton.Box = mh.Box
newGuiButton.Values = makeGuiButtonValues(box, data.Account, vm, "JWC", "SHOW VM 33", showVmMouseClick)
gui.Data.AllButtons = append(gui.Data.AllButtons, &newGuiButton) gui.Data.AllButtons = append(gui.Data.AllButtons, &newGuiButton)
mh.Rows[row].HumanData[6].Button = &newGuiButton mh.Rows[row].HumanData[6].Button = &newGuiButton
// mh.Rows[row].HumanData[6].VM = vm
// mh.Rows[row].VM = vm log.Println("\tvm.Name=", vm.Name, mh.Rows[row].Name)
log.Println("\tvm=", vm)
log.Println("\tvm.Name=", vm.Name)
log.Println("\tRows[row]=", mh.Rows[row])
log.Println("\tRows[row]=", row)
log.Println("\tRows[row].Name=", mh.Rows[row].Name)
log.Println(vm)
row += 1 row += 1
} }
} }

View File

@ -30,13 +30,13 @@ func makeCloudInfoBox(gw *gui.GuiWindow) {
gui.NewLabel(box, config.Accounts[key].Email) gui.NewLabel(box, config.Accounts[key].Email)
name := "Login " + config.Accounts[key].Nick name := "Login " + config.Accounts[key].Nick
gui.CreateButton(box, config.Accounts[key], nil, name, "LOGIN", login) makeButton(box, config.Accounts[key], nil, name, "LOGIN", login)
name = "Show " + config.Accounts[key].Nick name = "Show " + config.Accounts[key].Nick
gui.CreateButton(box, config.Accounts[key], nil, name, "SHOW", nil) makeButton(box, config.Accounts[key], nil, name, "SHOW", nil)
} }
gui.CreateButton(box, nil, nil, "Add Account", "ADD TAB", addSubdomainButton) makeButton(box, nil, nil, "Add Account", "ADD TAB", addSubdomainButton)
gui.CreateButton(box, nil, nil, "Quit", "QUIT", nil) makeButton(box, nil, nil, "Quit", "QUIT", nil)
log.Println("makeCloudInfoBox() END") log.Println("makeCloudInfoBox() END")
} }

View File

@ -24,19 +24,30 @@ func mainMouseClick(b *gui.GuiButton) {
log.Println("THIS IS PROBABLY A BUG IN git.wit.com/gui") log.Println("THIS IS PROBABLY A BUG IN git.wit.com/gui")
onExit(fmt.Errorf("mainMouseClick() got b = nil")) onExit(fmt.Errorf("mainMouseClick() got b = nil"))
} }
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE b.Action =", b.Action) log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
var gw *gui.GuiWindow var gw *gui.GuiWindow
gw = b.Box.Window gw = b.Box.Window
if (gw == nil) { if (gw == nil) {
log.Println("THIS BUTTON IS BROKEN gw = nil") log.Println("\tTHIS BUTTON IS BROKEN gw = nil")
panic("something") panic("something")
} }
if (b.Action == "QUIT") { var values *myButtonInfo
if tmp, ok := b.Values.(*myButtonInfo); ! ok {
log.Println("\tmainMouseClick() values.Accounts error =", ok)
log.Println("\tmainMouseClick() values.Accounts tmp =", tmp)
} else {
values = tmp
}
log.Println("\tmainMouseClick() values.Accounts =", values.Accounts)
log.Println("\tmainMouseClick() values.Name = ", values.Name)
if (values.Action == "QUIT") {
onExit(nil) onExit(nil)
} else if (b.Action == "CREATE") { } else if (values.Action == "CREATE") {
log.Println("\tTRY TO ADD A NEW VIRTUAL MACHINE") log.Println("\tTRY TO ADD A NEW VIRTUAL MACHINE")
log.Println("\tTRIGGER CREATE VM") log.Println("\tTRIGGER CREATE VM")
gui.Data.State = "CREATE" gui.Data.State = "CREATE"
@ -56,25 +67,25 @@ func mainMouseClick(b *gui.GuiButton) {
log.Println("defaultEntryChange() FOUND. Entry assigned to Button", b) log.Println("defaultEntryChange() FOUND. Entry assigned to Button", b)
} }
} }
event.Account = b.Account event.Account = values.Account
log.Println("\tTRIGGERING CREATE event=", event) log.Println("\tTRIGGERING CREATE event=", event)
log.Println("\tTRIGGERING CREATE event.Account=", event.Account) log.Println("\tTRIGGERING CREATE event.Account=", event.Account)
websocketSendProtobuf(event) websocketSendProtobuf(event)
} else if (b.Action == "CONFIG") { } else if (values.Action == "CONFIG") {
newConfig := loadDefaultConfig() newConfig := loadDefaultConfig()
config.Accounts = newConfig.Accounts config.Accounts = newConfig.Accounts
gui.Data.State = "done" gui.Data.State = "done"
} else if (b.Action == "DEBUG") { } else if (values.Action == "DEBUG") {
log.Println("\tdebug.PrintStack() (SHOULD BE JUST THIS goroutine)") log.Println("\tdebug.PrintStack() (SHOULD BE JUST THIS goroutine)")
debug.PrintStack() debug.PrintStack()
} else if (b.Action == "DEBUG FULL") { } else if (values.Action == "DEBUG FULL") {
log.Println("\tATTEMPT FULL STACK DUMP") log.Println("\tATTEMPT FULL STACK DUMP")
buf := make([]byte, 1<<16) buf := make([]byte, 1<<16)
runtime.Stack(buf, true) runtime.Stack(buf, true)
log.Printf("%s", buf) log.Printf("%s", buf)
log.Println("\tFINISHED FULL STACK DUMP") log.Println("\tFINISHED FULL STACK DUMP")
/* /*
} else if (b.Action == "SHOW VM") { } else if (values.Action == "SHOW VM") {
if (gui.Data.Debug) { if (gui.Data.Debug) {
log.Println("\tATTEMPTING TO SHOW VM TAB gw = ", gw) log.Println("\tATTEMPTING TO SHOW VM TAB gw = ", gw)
createVmBox(gw, b.VM) createVmBox(gw, b.VM)
@ -83,12 +94,12 @@ func mainMouseClick(b *gui.GuiButton) {
createVmBox(gw, b.VM) createVmBox(gw, b.VM)
} }
*/ */
} else if (b.Action == "SHOW") { } else if (values.Action == "SHOW") {
log.Println("\tTRIGGER DISPLAY ACCOUNT") log.Println("\tTRIGGER DISPLAY ACCOUNT")
gui.Data.State = "SEND WEBSOCKET" gui.Data.State = "SEND WEBSOCKET"
event := pb.MakeGetEvent() event := pb.MakeGetEvent()
event.Account = b.Account event.Account = values.Account
websocketSendProtobuf(event) websocketSendProtobuf(event)
count := 0 count := 0
@ -107,8 +118,8 @@ func mainMouseClick(b *gui.GuiButton) {
log.Println("\tSHOW VMS count =", count) log.Println("\tSHOW VMS count =", count)
// TODO: make sure login worked & the account really has zero VMs // TODO: make sure login worked & the account really has zero VMs
// if (count != 0) { // if (count != 0) {
name := "Virtual Machines (" + b.Account.Nick + ")" name := "Virtual Machines (" + values.Account.Nick + ")"
mh := addVmsTab(gw, name, count, b.Account) mh := addVmsTab(gw, name, count, values.Account)
ReadReceivedData(currentMessage, mh, b.Box) ReadReceivedData(currentMessage, mh, b.Box)
// } // }
currentMessage = nil currentMessage = nil
@ -126,17 +137,25 @@ func mainMouseClick(b *gui.GuiButton) {
} }
} }
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE") log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
log.Println("mainMouseClick() FAILED TO FIND b.Action =", b.Action) log.Println("mainMouseClick() FAILED TO FIND values.Action =", values.Action)
log.Println("mainMouseClick() END") log.Println("mainMouseClick() END")
} }
func makeButton(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM, // stores the fields we want to map into our private structure 'values'
name string, action string, custom func(*gui.GuiButton)) *gui.GuiButton { func makeGuiButtonValues(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM,
name string, action string, custom func(*gui.GuiButton)) *myButtonInfo {
val := &myButtonInfo{} val := &myButtonInfo{}
val.Account = a val.Account = a
val.Accounts = config.Accounts val.Accounts = config.Accounts
val.VM = vm val.VM = vm
val.Custom = custom val.Custom = custom
val.Name = "jcarr" val.Name = "jcarr"
val.Action = action
return val
}
func makeButton(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM,
name string, action string, custom func(*gui.GuiButton)) *gui.GuiButton {
val := makeGuiButtonValues(box, a, vm, name, action, custom)
return gui.NewCreateButton(box, custom, name, val) return gui.NewCreateButton(box, custom, name, val)
} }

View File

@ -75,7 +75,7 @@ func addVmsTab(gw *gui.GuiWindow, name string, count int, a *pb.Account) *gui.Ta
human += 1 human += 1
mh := gui.AddTableTab(gw, name, count, parts) mh := gui.AddTableTab(gw, name, count, parts)
gui.CreateButton(mh.Box, a, nil, "Add Virtual Machine", "JUNK", createAddVmBox) makeButton(mh.Box, a, nil, "Add Virtual Machine", "JUNK", createAddVmBox)
return mh return mh
} }
@ -83,7 +83,8 @@ func createAddVmBox(b *gui.GuiButton) {
log.Println("createAddVmBox() START") log.Println("createAddVmBox() START")
gw := b.Box.Window gw := b.Box.Window
log.Println("createAddVmBox() gw =", gw) log.Println("createAddVmBox() gw =", gw)
name := "(" + b.Account.Nick + ")" values, _ := b.Values.(*myButtonInfo)
name := "(" + values.Account.Nick + ")"
// gw.BoxMap["ADD VM" + name] = box // gw.BoxMap["ADD VM" + name] = box
@ -100,13 +101,14 @@ func createAddVmBox(b *gui.GuiButton) {
gui.HorizontalBreak(box) gui.HorizontalBreak(box)
gui.CreateButton(box, b.Account, nil, "Add Virtual Machine", "CREATE", nil) makeButton(box, values.Account, nil, "Add Virtual Machine", "CREATE", nil)
gui.CreateButton(box, b.Account, nil, "Cancel", "CLOSE", nil) makeButton(box, values.Account, nil, "Cancel", "CLOSE", nil)
} }
func showVmMouseClick(b *gui.GuiButton) { func showVmMouseClick(b *gui.GuiButton) {
log.Println("showVmMouseClick() START b.Box.Window =", b.Box.Window) log.Println("showVmMouseClick() START b.Box.Window =", b.Box.Window)
createVmBox(b.Box.Window, b.VM) values, _ := b.Values.(*myButtonInfo)
createVmBox(b.Box.Window, values.VM)
log.Println("showVmMouseClick() END") log.Println("showVmMouseClick() END")
} }
@ -129,13 +131,13 @@ func createVmBox(gw *gui.GuiWindow, vm *pb.Event_VM) {
gui.HorizontalBreak(box) gui.HorizontalBreak(box)
gui.CreateButton(box, nil, vm, "Power On", "POWERON", nil) makeButton(box, nil, vm, "Power On", "POWERON", nil)
gui.CreateButton(box, nil, vm, "Power Off", "POWEROFF", nil) makeButton(box, nil, vm, "Power Off", "POWEROFF", nil)
gui.CreateButton(box, nil, vm, "Destroy", "DESTROY", nil) makeButton(box, nil, vm, "Destroy", "DESTROY", nil)
gui.CreateButton(box, nil, vm, "ping", "PING", runPingClick) makeButton(box, nil, vm, "ping", "PING", runPingClick)
gui.CreateButton(box, nil, vm, "Console", "XTERM", runTestExecClick) makeButton(box, nil, vm, "Console", "XTERM", runTestExecClick)
gui.CreateButton(box, nil, vm, "Save", "SAVE", nil) makeButton(box, nil, vm, "Save", "SAVE", nil)
gui.CreateButton(box, nil, vm, "Done", "DONE", nil) makeButton(box, nil, vm, "Done", "DONE", nil)
} }
func runTestHide(b *gui.GuiButton) { func runTestHide(b *gui.GuiButton) {
@ -151,10 +153,11 @@ func runTestHide(b *gui.GuiButton) {
func runPingClick(b *gui.GuiButton) { func runPingClick(b *gui.GuiButton) {
log.Println("runPingClick START") log.Println("runPingClick START")
log.Println("runTestExecClick b.VM", b.VM) values, _ := b.Values.(*myButtonInfo)
log.Println("runTestExecClick values.VM", values.VM)
hostname := "localhost" hostname := "localhost"
if (b.VM != nil) { if (values.VM != nil) {
hostname = b.VM.Hostname hostname = values.VM.Hostname
} }
spew.Dump(b) spew.Dump(b)
var tmp []string var tmp []string

View File

@ -19,10 +19,13 @@ func login(b *gui.GuiButton) {
// note: this may never be possible because of cross platform // note: this may never be possible because of cross platform
// andlabs/ui requirements. windows and macos seem to freak out // andlabs/ui requirements. windows and macos seem to freak out
// when you try to trigger the UI in seperate threads // when you try to trigger the UI in seperate threads
values, _ := b.Values.(*myButtonInfo)
event := pb.MakeLoginEvent() event := pb.MakeLoginEvent()
event.Account = b.Account event.Account = values.Account
websocketSendProtobuf(event) websocketSendProtobuf(event)
count := 0 count := 0
for { for {
log.Println("\tSleep() in buttonClick() gui.Data.State =", gui.Data.State) log.Println("\tSleep() in buttonClick() gui.Data.State =", gui.Data.State)
@ -36,15 +39,15 @@ func login(b *gui.GuiButton) {
} else { } else {
log.Println("LOGIN currentMessage =", currentMessage) log.Println("LOGIN currentMessage =", currentMessage)
if (currentMessage.Type == pb.Event_OK) { if (currentMessage.Type == pb.Event_OK) {
msg := "On account " + b.Account.Nick + "\n" msg := "On account " + values.Account.Nick + "\n"
log.Println("\tLOGIN WAS OK!", msg) log.Println("\tLOGIN WAS OK!", msg)
log.Println("\tLOGIN WAS OK! old button.Account was =", b.Account) log.Println("\tLOGIN WAS OK! old button.Account was =", values.Account)
log.Println("\tLOGIN WAS OK! currentMessage.Account =", currentMessage.Account) log.Println("\tLOGIN WAS OK! currentMessage.Account =", currentMessage.Account)
if (b.Account.Id == currentMessage.Account.Id) { if (values.Account.Id == currentMessage.Account.Id) {
if (b.Account.Token != currentMessage.Account.Token) { if (values.Account.Token != currentMessage.Account.Token) {
log.Println("\tLOGIN SENT NEW TOKEN") log.Println("\tLOGIN SENT NEW TOKEN")
b.Account.Token = currentMessage.Account.Token values.Account.Token = currentMessage.Account.Token
log.Println("\tLOGIN WAS OK! old button.Account is now =", b.Account) log.Println("\tLOGIN WAS OK! old button.Account is now =", values.Account)
} }
} }
log.Println("\tLOGIN WAS OK!") log.Println("\tLOGIN WAS OK!")
@ -53,11 +56,11 @@ func login(b *gui.GuiButton) {
log.Println("\tLOGIN FAILED") log.Println("\tLOGIN FAILED")
log.Println("\tLOGIN FAILED") log.Println("\tLOGIN FAILED")
log.Println("\tLOGIN FAILED") log.Println("\tLOGIN FAILED")
msg := "On account " + b.Account.Nick + "\n" msg := "On account " + values.Account.Nick + "\n"
msg += "pb.Comment = " + currentMessage.Comment + "\n" msg += "pb.Comment = " + currentMessage.Comment + "\n"
msg += "pb.Id = " + fmt.Sprintf("%d", currentMessage.Id) + "\n" msg += "pb.Id = " + fmt.Sprintf("%d", currentMessage.Id) + "\n"
msg += "pb.Email = " + b.Account.Email + "\n" msg += "pb.Email = " + values.Account.Email + "\n"
msg += "pb.Username = " + b.Account.Username + "\n" msg += "pb.Username = " + values.Account.Username + "\n"
gui.ErrorWindow(b.Box.Window, "Login Failed", msg) gui.ErrorWindow(b.Box.Window, "Login Failed", msg)
} }
currentMessage = nil currentMessage = nil

View File

@ -27,6 +27,7 @@ type myButtonInfo struct {
Custom func (*gui.GuiButton) Custom func (*gui.GuiButton)
ADD func (*gui.GuiButton) ADD func (*gui.GuiButton)
Name string Name string
Action string
} }