2019-06-01 23:15:36 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
import "fmt"
|
|
|
|
import "time"
|
|
|
|
import "runtime"
|
|
|
|
import "runtime/debug"
|
|
|
|
|
|
|
|
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-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"))
|
|
|
|
}
|
|
|
|
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE b.Action =", b.Action)
|
|
|
|
|
|
|
|
var gw *gui.GuiWindow
|
|
|
|
gw = b.Box.Window
|
|
|
|
|
|
|
|
if (gw == nil) {
|
|
|
|
log.Println("THIS BUTTON IS BROKEN gw = nil")
|
|
|
|
panic("something")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b.Action == "QUIT") {
|
|
|
|
onExit(nil)
|
|
|
|
} else if (b.Action == "CREATE") {
|
|
|
|
log.Println("\tTRY TO ADD A NEW VIRTUAL MACHINE")
|
|
|
|
log.Println("\tTRIGGER CREATE VM")
|
|
|
|
gui.Data.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].Action =", entry.Action)
|
|
|
|
if (entry.Action == "Hostname") {
|
|
|
|
event.Vms[0].Hostname = entry.UiEntry.Text()
|
|
|
|
}
|
|
|
|
if (entry.Action == "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 = b.Account
|
|
|
|
log.Println("\tTRIGGERING CREATE event=", event)
|
|
|
|
log.Println("\tTRIGGERING CREATE event.Account=", event.Account)
|
2019-06-02 08:21:12 -05:00
|
|
|
websocketSendProtobuf(event)
|
2019-06-01 23:15:36 -05:00
|
|
|
} else if (b.Action == "CONFIG") {
|
|
|
|
newConfig := loadDefaultConfig()
|
|
|
|
config.Accounts = newConfig.Accounts
|
|
|
|
gui.Data.State = "done"
|
|
|
|
} else if (b.Action == "DEBUG") {
|
|
|
|
log.Println("\tdebug.PrintStack() (SHOULD BE JUST THIS goroutine)")
|
|
|
|
debug.PrintStack()
|
|
|
|
} else if (b.Action == "DEBUG FULL") {
|
|
|
|
log.Println("\tATTEMPT FULL STACK DUMP")
|
|
|
|
buf := make([]byte, 1<<16)
|
|
|
|
runtime.Stack(buf, true)
|
|
|
|
log.Printf("%s", buf)
|
|
|
|
log.Println("\tFINISHED FULL STACK DUMP")
|
2019-06-02 17:19:36 -05:00
|
|
|
/*
|
2019-06-01 23:15:36 -05:00
|
|
|
} else if (b.Action == "SHOW VM") {
|
|
|
|
if (gui.Data.Debug) {
|
|
|
|
log.Println("\tATTEMPTING TO SHOW VM TAB gw = ", gw)
|
|
|
|
createVmBox(gw, b.VM)
|
|
|
|
} else {
|
|
|
|
log.Println("\tATTEMPTING TO SHOW VM TAB gw = ", gw)
|
|
|
|
createVmBox(gw, b.VM)
|
|
|
|
}
|
2019-06-02 17:19:36 -05:00
|
|
|
*/
|
2019-06-01 23:15:36 -05:00
|
|
|
} else if (b.Action == "SHOW") {
|
|
|
|
log.Println("\tTRIGGER DISPLAY ACCOUNT")
|
|
|
|
gui.Data.State = "SEND WEBSOCKET"
|
|
|
|
|
|
|
|
event := pb.MakeGetEvent()
|
|
|
|
event.Account = b.Account
|
2019-06-02 08:21:12 -05:00
|
|
|
websocketSendProtobuf(event)
|
2019-06-01 23:15:36 -05:00
|
|
|
|
|
|
|
count := 0
|
|
|
|
for {
|
|
|
|
log.Println("\tSleep() in buttonClick() gui.Data.State =", gui.Data.State)
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
if (gui.Data.State == "NEW PROTOBUF") {
|
|
|
|
if (currentMessage == nil) {
|
|
|
|
gui.ErrorWindow(gw,
|
|
|
|
"There was a socket error",
|
|
|
|
"More detailed information can be shown here.")
|
|
|
|
gui.Data.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) {
|
|
|
|
name := "Virtual Machines (" + b.Account.Nick + ")"
|
|
|
|
mh := addVmsTab(gw, name, count, b.Account)
|
2019-06-02 17:19:36 -05:00
|
|
|
ReadReceivedData(currentMessage, mh, b.Box)
|
2019-06-01 23:15:36 -05:00
|
|
|
// }
|
|
|
|
currentMessage = nil
|
|
|
|
gui.Data.State = "done"
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
count += 1
|
|
|
|
if (count > 10) {
|
|
|
|
log.Println("\tERROR: waited too long for a resposne")
|
|
|
|
currentMessage = nil
|
|
|
|
gui.Data.State = "done"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-02 17:19:36 -05:00
|
|
|
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
|
|
|
|
log.Println("mainMouseClick() FAILED TO FIND b.Action =", b.Action)
|
|
|
|
log.Println("mainMouseClick() END")
|
2019-06-01 23:15:36 -05:00
|
|
|
}
|