2019-06-01 23:15:36 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
import "fmt"
|
|
|
|
import "time"
|
2019-06-03 08:53:33 -05:00
|
|
|
// import "runtime"
|
|
|
|
// import "runtime/debug"
|
2019-06-01 23:15:36 -05:00
|
|
|
|
|
|
|
import "git.wit.com/wit/gui"
|
|
|
|
import pb "git.wit.com/wit/witProtobuf"
|
|
|
|
// import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
|
|
|
//
|
2019-06-02 17:19:36 -05:00
|
|
|
// This was the default handler for all mouse clicks (buttons, areas, etc))
|
|
|
|
//
|
|
|
|
// Most mouse clicks are now moved to custom functions
|
2019-06-01 23:15:36 -05:00
|
|
|
//
|
2019-06-02 17:19:36 -05:00
|
|
|
|
2019-06-03 08:53:33 -05:00
|
|
|
// stores the fields we want to map into our private structure 'values'
|
|
|
|
func makeGuiButtonValues(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM,
|
|
|
|
name string, action string, custom func(*gui.GuiButton)) *myButtonInfo {
|
|
|
|
val := &myButtonInfo{}
|
|
|
|
val.Account = a
|
|
|
|
val.Accounts = config.Accounts
|
|
|
|
val.VM = vm
|
|
|
|
val.Custom = custom
|
2019-06-05 12:01:56 -05:00
|
|
|
val.Name = name
|
|
|
|
// val.Action = action
|
2019-06-03 08:53:33 -05:00
|
|
|
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.CreateButton(box, custom, name, val)
|
|
|
|
}
|
|
|
|
|
2019-06-05 12:01:56 -05:00
|
|
|
func makeColorButton(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.CreateColorButton(box, custom, name, val)
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:15:36 -05:00
|
|
|
func mainMouseClick(b *gui.GuiButton) {
|
|
|
|
defer r() // a golang trick to try to not crash on certain errors
|
|
|
|
|
|
|
|
if (b == nil) {
|
|
|
|
log.Println("mainMouseClick() BACK IN MAIN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?")
|
2019-06-02 17:19:36 -05:00
|
|
|
log.Println("THIS IS PROBABLY A BUG IN git.wit.com/gui")
|
2019-06-01 23:15:36 -05:00
|
|
|
onExit(fmt.Errorf("mainMouseClick() got b = nil"))
|
|
|
|
}
|
2019-06-02 22:50:16 -05:00
|
|
|
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
|
2019-06-01 23:15:36 -05:00
|
|
|
|
2019-06-03 22:56:07 -05:00
|
|
|
gw := b.Box.Window
|
2019-06-01 23:15:36 -05:00
|
|
|
|
|
|
|
if (gw == nil) {
|
2019-06-02 22:50:16 -05:00
|
|
|
log.Println("\tTHIS BUTTON IS BROKEN gw = nil")
|
2019-06-01 23:15:36 -05:00
|
|
|
panic("something")
|
|
|
|
}
|
|
|
|
|
2019-06-02 22:50:16 -05:00
|
|
|
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)
|
|
|
|
|
2019-06-13 14:29:00 -05:00
|
|
|
/*
|
2019-06-02 22:50:16 -05:00
|
|
|
if (values.Action == "QUIT") {
|
2019-06-01 23:15:36 -05:00
|
|
|
onExit(nil)
|
2019-06-02 22:50:16 -05:00
|
|
|
} else if (values.Action == "CREATE") {
|
2019-06-01 23:15:36 -05:00
|
|
|
log.Println("\tTRY TO ADD A NEW VIRTUAL MACHINE")
|
2019-06-03 08:53:33 -05:00
|
|
|
createVmClick(b)
|
2019-06-02 22:50:16 -05:00
|
|
|
} else if (values.Action == "SHOW") {
|
2019-06-03 08:53:33 -05:00
|
|
|
showAccountClick(b)
|
2019-06-01 23:15:36 -05:00
|
|
|
}
|
2019-06-13 14:29:00 -05:00
|
|
|
*/
|
2019-06-02 17:19:36 -05:00
|
|
|
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
|
2019-06-02 22:50:16 -05:00
|
|
|
log.Println("mainMouseClick() FAILED TO FIND values.Action =", values.Action)
|
2019-06-02 17:19:36 -05:00
|
|
|
log.Println("mainMouseClick() END")
|
2019-06-01 23:15:36 -05:00
|
|
|
}
|
2019-06-02 21:56:14 -05:00
|
|
|
|
2019-06-03 08:53:33 -05:00
|
|
|
func showAccountClick(b *gui.GuiButton) {
|
|
|
|
log.Println("\tTRIGGER DISPLAY ACCOUNT")
|
|
|
|
State = "SEND WEBSOCKET"
|
|
|
|
|
|
|
|
var values *myButtonInfo
|
|
|
|
|
|
|
|
if tmp, ok := b.Values.(*myButtonInfo); ! ok {
|
2019-06-13 14:08:16 -05:00
|
|
|
log.Println("\tshowAccountClick() values.Accounts error =", ok)
|
|
|
|
log.Println("\tshowAccountClick() values.Accounts tmp =", tmp)
|
2019-06-03 08:53:33 -05:00
|
|
|
} else {
|
|
|
|
values = tmp
|
|
|
|
}
|
2019-06-13 14:08:16 -05:00
|
|
|
log.Println("\tshowAccountClick() values.Accounts =", values.Accounts)
|
|
|
|
log.Println("\tshowAccountClick() values.Name = ", values.Name)
|
2019-06-03 08:53:33 -05:00
|
|
|
|
2019-06-03 22:56:07 -05:00
|
|
|
gw := b.Box.Window
|
2019-06-03 08:53:33 -05:00
|
|
|
|
2019-06-13 18:37:17 -05:00
|
|
|
makeAccountWindow(gw, values.Account)
|
|
|
|
log.Println("\tshowAccountClick() END")
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeAccountWindow(gw *gui.GuiWindow, account *pb.Account) {
|
|
|
|
log.Println("\tmakeAccountWindow() START")
|
|
|
|
|
|
|
|
name := "Virtual Machines (" + account.Nick + ")"
|
|
|
|
|
2019-06-13 14:29:00 -05:00
|
|
|
// TODO: make this text i18n
|
|
|
|
box := gui.InitWindow(gw, name, gui.Yaxis)
|
|
|
|
if (box == nil) {
|
|
|
|
log.Println("gui.InitWindow() FAILED")
|
|
|
|
return
|
|
|
|
}
|
2019-06-13 15:09:24 -05:00
|
|
|
gw = box.Window
|
2019-06-13 14:29:00 -05:00
|
|
|
|
2019-06-03 08:53:33 -05:00
|
|
|
event := pb.MakeGetEvent()
|
2019-06-13 18:37:17 -05:00
|
|
|
event.Account = account
|
2019-06-03 08:53:33 -05:00
|
|
|
websocketSendProtobuf(event)
|
|
|
|
|
|
|
|
count := 0
|
|
|
|
for {
|
|
|
|
log.Println("\tSleep() in buttonClick() State =", State)
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
if (State == "NEW PROTOBUF") {
|
|
|
|
if (currentMessage == nil) {
|
|
|
|
gui.ErrorWindow(gw,
|
|
|
|
"There was a socket error",
|
|
|
|
"More detailed information can be shown here.")
|
|
|
|
State = "done"
|
|
|
|
} else {
|
|
|
|
count := countVMS(currentMessage)
|
|
|
|
log.Println("\tSHOW VMS currentMessage =", currentMessage)
|
|
|
|
log.Println("\tSHOW VMS count =", count)
|
|
|
|
// TODO: make sure login worked & the account really has zero VMs
|
|
|
|
// if (count != 0) {
|
2019-06-13 18:37:17 -05:00
|
|
|
mh := addVmsTab(box, name, count, account)
|
2019-06-13 14:29:00 -05:00
|
|
|
// ReadReceivedData(currentMessage, mh, b.Box)
|
|
|
|
ReadReceivedData(currentMessage, mh, box)
|
2019-06-03 08:53:33 -05:00
|
|
|
// }
|
|
|
|
currentMessage = nil
|
|
|
|
State = "done"
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
count += 1
|
|
|
|
if (count > 10) {
|
|
|
|
log.Println("\tERROR: waited too long for a resposne")
|
|
|
|
currentMessage = nil
|
|
|
|
State = "done"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2019-06-02 22:50:16 -05:00
|
|
|
}
|
|
|
|
|
2019-06-03 08:53:33 -05:00
|
|
|
func createVmClick(b *gui.GuiButton) {
|
|
|
|
log.Println("createVmClick()")
|
|
|
|
|
|
|
|
var values *myButtonInfo
|
|
|
|
|
|
|
|
if tmp, ok := b.Values.(*myButtonInfo); ! ok {
|
2019-06-13 14:08:16 -05:00
|
|
|
log.Println("\tcreateVmClick() values.Accounts error =", ok)
|
|
|
|
log.Println("\tcreateVmClick() values.Accounts tmp =", tmp)
|
2019-06-03 08:53:33 -05:00
|
|
|
} else {
|
|
|
|
values = tmp
|
|
|
|
}
|
2019-06-13 14:08:16 -05:00
|
|
|
log.Println("\tcreateVmClick() values.Accounts =", values.Accounts)
|
|
|
|
log.Println("\tcreateVmClick() values.Name = ", values.Name)
|
2019-06-03 08:53:33 -05:00
|
|
|
|
|
|
|
log.Println("\tTRIGGER CREATE VM")
|
|
|
|
State = "CREATE"
|
|
|
|
event := pb.MakeAddVmEvent()
|
|
|
|
for key, entry := range gui.Data.AllEntries {
|
|
|
|
log.Println("\tdefaultEntryChange() Data.AllEntries =", key, entry)
|
|
|
|
log.Println("\tdefaultEntryChange() Data.AllEntries[key].Name =", entry.Name)
|
|
|
|
if (entry.Name == "Hostname") {
|
|
|
|
event.Vms[0].Hostname = entry.UiEntry.Text()
|
|
|
|
}
|
|
|
|
if (entry.Name == "Memory") {
|
|
|
|
event.Vms[0].Memory = pint64(entry.UiEntry.Text())
|
|
|
|
}
|
|
|
|
log.Println("\tdefaultEntryChange() Data.AllEntries[key].E =", entry.UiEntry.Text())
|
|
|
|
log.Println("\tdefaultEntryChange() Data.AllEntries[key].B =", entry.B)
|
|
|
|
if entry.B == b {
|
|
|
|
log.Println("defaultEntryChange() FOUND. Entry assigned to Button", b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event.Account = values.Account
|
|
|
|
log.Println("\tTRIGGERING CREATE event=", event)
|
|
|
|
log.Println("\tTRIGGERING CREATE event.Account=", event.Account)
|
|
|
|
websocketSendProtobuf(event)
|
2019-06-02 21:56:14 -05:00
|
|
|
}
|