split out more of the functions
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
418b520835
commit
76dbbf952e
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import "log"
|
||||
|
||||
import "git.wit.com/wit/gui"
|
||||
|
||||
func makeCloudInfoBox(gw *gui.GuiWindow) {
|
||||
log.Println("makeCloudInfoBox() START gw =", gw)
|
||||
box := gui.AddMainTab(gw)
|
||||
gw = box.Window
|
||||
|
||||
log.Println("makeCloudInfoBox() START GW IS NOW: gw =", gw)
|
||||
log.Println("makeCloudInfoBox() box =", box)
|
||||
|
||||
gui.NewLabel(box, "Hostname:")
|
||||
|
||||
gui.HardHorizontalBreak(box)
|
||||
|
||||
tmp := gui.Data.Hostname + " (" + gui.Data.IPv6 + ")"
|
||||
gui.MakeEntryHbox(box, "hostname:", tmp, true, "Hostname")
|
||||
|
||||
for key, a := range config.Accounts {
|
||||
log.Println("account = ", key, a)
|
||||
log.Println("Accounts[key] = ", config.Accounts[key])
|
||||
log.Println("account.Nick = ", config.Accounts[key].Nick)
|
||||
log.Println("account.Username = ", config.Accounts[key].Username)
|
||||
log.Println("account.Token = ", config.Accounts[key].Token)
|
||||
|
||||
gui.NewLabel(box, config.Accounts[key].Domain)
|
||||
gui.NewLabel(box, config.Accounts[key].Email)
|
||||
|
||||
name := "Login " + config.Accounts[key].Nick
|
||||
login := gui.CreateButton(box, config.Accounts[key], nil, name, "LOGIN", login)
|
||||
gui.AddButtonToBox(box, login)
|
||||
|
||||
name = "Show " + config.Accounts[key].Nick
|
||||
show := gui.CreateButton(box, config.Accounts[key], nil, name, "SHOW", nil)
|
||||
gui.AddButtonToBox(box, show)
|
||||
}
|
||||
|
||||
add := gui.CreateButton(box, nil, nil, "Add Account", "ADD TAB", addSubdomainButton)
|
||||
gui.AddButtonToBox(box, add)
|
||||
|
||||
quit := gui.CreateButton(box, nil, nil, "Quit", "QUIT", nil)
|
||||
gui.AddButtonToBox(box, quit)
|
||||
|
||||
gui.ShowMainTabShowBox(gw, box)
|
||||
log.Println("makeCloudInfoBox() END")
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package main
|
||||
|
||||
import "log"
|
||||
import "fmt"
|
||||
import "time"
|
||||
|
||||
import "git.wit.com/wit/gui"
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
func login(b *gui.GuiButton) {
|
||||
log.Println("login() START")
|
||||
gui.Data.State = "SEND LOGIN"
|
||||
|
||||
// TODO: move this into a seperate goroutine
|
||||
event := pb.MakeLoginEvent()
|
||||
event.Account = b.Account
|
||||
prepareAndSend(event)
|
||||
|
||||
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(b.GW,
|
||||
"There was a socket error",
|
||||
"More detailed information can be shown here.")
|
||||
gui.Data.State = "done"
|
||||
} else {
|
||||
log.Println("LOGIN currentMessage =", currentMessage)
|
||||
if (currentMessage.Type == pb.Event_OK) {
|
||||
msg := "On account " + b.Account.Nick + "\n"
|
||||
log.Println("\tLOGIN WAS OK!", msg)
|
||||
log.Println("\tLOGIN WAS OK! old button.Account was =", b.Account)
|
||||
log.Println("\tLOGIN WAS OK! currentMessage.Account =", currentMessage.Account)
|
||||
if (b.Account.Id == currentMessage.Account.Id) {
|
||||
if (b.Account.Token != currentMessage.Account.Token) {
|
||||
log.Println("\tLOGIN SENT NEW TOKEN")
|
||||
b.Account.Token = currentMessage.Account.Token
|
||||
log.Println("\tLOGIN WAS OK! old button.Account is now =", b.Account)
|
||||
}
|
||||
}
|
||||
log.Println("\tLOGIN WAS OK!")
|
||||
gui.MessageWindow(b.GW, "Login OK", msg)
|
||||
} else if (currentMessage.Type == pb.Event_FAIL) {
|
||||
log.Println("\tLOGIN FAILED")
|
||||
log.Println("\tLOGIN FAILED")
|
||||
log.Println("\tLOGIN FAILED")
|
||||
msg := "On account " + b.Account.Nick + "\n"
|
||||
msg += "pb.Comment = " + currentMessage.Comment + "\n"
|
||||
msg += "pb.Id = " + fmt.Sprintf("%d", currentMessage.Id) + "\n"
|
||||
msg += "pb.Email = " + b.Account.Email + "\n"
|
||||
msg += "pb.Username = " + b.Account.Username + "\n"
|
||||
gui.ErrorWindow(b.GW, "Login Failed", msg)
|
||||
}
|
||||
currentMessage = nil
|
||||
gui.Data.State = "done"
|
||||
}
|
||||
return
|
||||
}
|
||||
// TODO: fix this with an actual timeout
|
||||
count += 1
|
||||
if (count > 10) {
|
||||
log.Println("\tERROR: waited too long for a resposne")
|
||||
currentMessage = nil
|
||||
gui.Data.State = "done"
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
79
main.go
79
main.go
|
@ -277,28 +277,8 @@ func mainMouseClick(b *gui.GuiButton) {
|
|||
runtime.Stack(buf, true)
|
||||
log.Printf("%s", buf)
|
||||
log.Println("\tFINISHED FULL STACK DUMP")
|
||||
} else if (b.Action == "ADD") {
|
||||
log.Println("\tSHOULD ADD ACCOUNT HERE")
|
||||
subdomain := gui.GetText(b.Box, "SUBDOMAIN")
|
||||
if (subdomain == "") {
|
||||
gui.ErrorWindow(gw, "Blank Name", "You must have a valid subdomain")
|
||||
return
|
||||
}
|
||||
log.Println("\tsubdomain =", subdomain)
|
||||
|
||||
acc := new(pb.Account)
|
||||
acc.Nick = subdomain
|
||||
acc.Domain = subdomain
|
||||
acc.Username = "jcarr@wit.com"
|
||||
acc.Email = "jcarr@wit.com"
|
||||
acc.Password = "badpass"
|
||||
acc.URL = "http://stackapi-api1.stackapi.customers.dev.wit.com:4000/"
|
||||
config.Accounts = append(config.Accounts, acc)
|
||||
|
||||
// gui.ShowMainTab(gw)
|
||||
makeCloudInfoBox(gw)
|
||||
gui.Data.State = "done"
|
||||
} else if (b.Action == "LOGIN") {
|
||||
/*
|
||||
log.Println("\tTRIGGER LOGIN ACCOUNT")
|
||||
gui.Data.State = "SEND LOGIN"
|
||||
|
||||
|
@ -358,6 +338,7 @@ func mainMouseClick(b *gui.GuiButton) {
|
|||
return
|
||||
}
|
||||
}
|
||||
*/
|
||||
} else if (b.Action == "SHOW VM") {
|
||||
// gui.Data.CurrentVM = b.VM
|
||||
if (gui.Data.Debug) {
|
||||
|
@ -455,10 +436,9 @@ func watchGUI() {
|
|||
if (count > 10) {
|
||||
log.Println("Sleep() in watchGUI() gui.Data.State =", gui.Data.State)
|
||||
for i, window := range gui.Data.Windows {
|
||||
log.Println("watchGUI() gui.Data.Windows i =", i)
|
||||
log.Println("\twatchGUI() gui.Data.Windows.Action =", window.Action)
|
||||
for name, box := range window.BoxMap {
|
||||
log.Println("\twatchGUI() name, box =", name, box)
|
||||
log.Println("watchGUI() gui.Data.Windows i =", i, "Action =", window.Action)
|
||||
for name, _ := range window.BoxMap {
|
||||
log.Println("\twatchGUI() name =", name)
|
||||
}
|
||||
}
|
||||
count = 0
|
||||
|
@ -483,52 +463,3 @@ func watchGUI() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func makeCloudInfoBox(gw *gui.GuiWindow) {
|
||||
log.Println("makeCloudInfoBox() START gw =", gw)
|
||||
box := gui.AddMainTab(gw)
|
||||
gw = box.Window
|
||||
|
||||
log.Println("makeCloudInfoBox() START GW IS NOW: gw =", gw)
|
||||
log.Println("makeCloudInfoBox() box =", box)
|
||||
|
||||
gui.NewLabel(box, "Hostname:")
|
||||
|
||||
gui.HardHorizontalBreak(box)
|
||||
// gui.VerticalBreak(box)
|
||||
|
||||
tmp := gui.Data.Hostname + " (" + gui.Data.IPv6 + ")"
|
||||
gui.MakeEntryHbox(box, "hostname:", tmp, true, "Hostname")
|
||||
|
||||
for key, a := range config.Accounts {
|
||||
log.Println("account = ", key, a)
|
||||
log.Println("Accounts[key] = ", config.Accounts[key])
|
||||
log.Println("account.Nick = ", config.Accounts[key].Nick)
|
||||
log.Println("account.Username = ", config.Accounts[key].Username)
|
||||
log.Println("account.Token = ", config.Accounts[key].Token)
|
||||
|
||||
gui.NewLabel(box, config.Accounts[key].Domain)
|
||||
gui.NewLabel(box, config.Accounts[key].Email)
|
||||
|
||||
name := "Login " + config.Accounts[key].Nick
|
||||
login := gui.CreateButton(box, config.Accounts[key], nil, name, "LOGIN", nil)
|
||||
gui.AddButtonToBox(box, login)
|
||||
|
||||
name = "Show " + config.Accounts[key].Nick
|
||||
show := gui.CreateButton(box, config.Accounts[key], nil, name, "SHOW", nil)
|
||||
gui.AddButtonToBox(box, show)
|
||||
}
|
||||
|
||||
// gui.HardHorizontalBreak(box)
|
||||
// gui.VerticalBreak(box)
|
||||
|
||||
|
||||
add := gui.CreateButton(box, nil, nil, "Add Account", "ADD TAB", nil)
|
||||
gui.AddButtonToBox(box, add)
|
||||
|
||||
quit := gui.CreateButton(box, nil, nil, "Quit", "QUIT", nil)
|
||||
gui.AddButtonToBox(box, quit)
|
||||
|
||||
gui.ShowMainTabShowBox(gw, box)
|
||||
log.Println("makeCloudInfoBox() END")
|
||||
}
|
||||
|
|
30
splash.go
30
splash.go
|
@ -8,6 +8,8 @@ import "git.wit.com/wit/gui"
|
|||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
func showSplashBox(gw *gui.GuiWindow) *gui.GuiBox {
|
||||
log.Println("ShowSplashBox() START")
|
||||
text := getNEWTEXT()
|
||||
|
@ -72,13 +74,39 @@ func addSubdomainQuestionBox(gw *gui.GuiWindow) *gui.GuiBox {
|
|||
|
||||
gui.HorizontalBreak(box)
|
||||
|
||||
button2 := gui.CreateButton(box, nil, nil, "Create Subdomain Account", "ADD", nil)
|
||||
button2 := gui.CreateButton(box, nil, nil, "Create Subdomain Account", "ADD", addSubdomainButton)
|
||||
gui.AddButtonToBox(box, button2)
|
||||
|
||||
log.Println("addSubdomainQuestionBox() END box =", box)
|
||||
return box
|
||||
}
|
||||
|
||||
// curl -vv -X POST -H "X-Wit-Auth: $TOKEN" 'http://stackapi-api1.stackapi.customers.wit.com:4000/vms/toby?count=1&cpu=2&ram=512&disk=25'
|
||||
|
||||
|
||||
func addSubdomainButton(b *gui.GuiButton) {
|
||||
log.Println("addSubdomainButton() START")
|
||||
subdomain := gui.GetText(b.Box, "SUBDOMAIN")
|
||||
if (subdomain == "") {
|
||||
gui.ErrorWindow(b.GW, "Blank Name", "You must have a valid subdomain")
|
||||
return
|
||||
}
|
||||
log.Println("\tsubdomain =", subdomain)
|
||||
|
||||
acc := new(pb.Account)
|
||||
acc.Nick = subdomain
|
||||
acc.Domain = subdomain
|
||||
acc.Username = "jcarr@wit.com"
|
||||
acc.Email = "jcarr@wit.com"
|
||||
acc.Password = "badpass"
|
||||
acc.URL = "http://stackapi-api1.stackapi.customers.dev.wit.com:4000/"
|
||||
config.Accounts = append(config.Accounts, acc)
|
||||
|
||||
makeCloudInfoBox(b.GW)
|
||||
gui.Data.State = "done"
|
||||
log.Println("addSubdomainButton() END")
|
||||
}
|
||||
|
||||
func generateSubdomain(b *gui.GuiButton) {
|
||||
log.Println("generateSubdomain START")
|
||||
if (b == nil) {
|
||||
|
|
Loading…
Reference in New Issue