2019-05-29 17:46:37 -05:00
package main
2019-06-01 03:19:51 -05:00
import "log"
import "runtime"
2019-05-29 17:46:37 -05:00
import "git.wit.com/wit/gui"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
2019-06-01 19:53:30 -05:00
import pb "git.wit.com/wit/witProtobuf"
2019-06-01 04:12:46 -05:00
func showSplashBox ( gw * gui . GuiWindow ) * gui . GuiBox {
log . Println ( "ShowSplashBox() START" )
text := getNEWTEXT ( )
2019-06-02 00:24:26 -05:00
box := gui . ShowTextBox ( gw , text , splashClick )
2019-06-01 04:12:46 -05:00
if runtime . GOOS == "linux" {
gui . NewLabel ( box , "OS: Linux" )
} else if runtime . GOOS == "windows" {
gui . NewLabel ( box , "OS: Windows" )
} else {
gui . NewLabel ( box , "OS: " + runtime . GOOS )
}
gui . NewLabel ( box , "Version: " + VERSION )
2019-06-02 17:50:11 -05:00
if ( gui . Config . Debug ) {
2019-06-01 04:12:46 -05:00
gui . NewLabel ( box , "git rev-list: " + GITCOMMIT )
gui . NewLabel ( box , "go build version: " + GOVERSION )
gui . NewLabel ( box , "build date: " + BUILDTIME )
}
2019-06-02 21:56:14 -05:00
makeButton ( box , nil , nil , "OK" , "AREA" , splashClick )
2019-06-01 04:12:46 -05:00
log . Println ( "ShowSplashBox() END box =" , box )
return box
2019-05-29 17:46:37 -05:00
}
func getNEWTEXT ( ) * ui . AttributedString {
var aText * ui . AttributedString
aText = ui . NewAttributedString ( "" )
gui . AreaAppendText ( aText , "Welcome to the Cloud Control Panel\n" , ui . TextSize ( 16 ) , ui . TextColor { 0.0 , 0.0 , 0.8 , .8 } )
gui . AreaAppendText ( aText , "(alpha)\n\n" , ui . TextSize ( 10 ) )
gui . AreaAppendText ( aText , "This control panel was designed to be an interface to your 'private' cloud. " , ui . TextWeightBold )
gui . AreaAppendText ( aText , "The concept of a private cloud means that you can use a providers system, or, seemlessly, use your own hardware in your own datacenter. " , ui . TextWeightBold )
aText . AppendUnattributed ( "\n" )
aText . AppendUnattributed ( "\n" )
gui . AreaAppendText ( aText , "This control panel requires:\n" )
aText . AppendUnattributed ( "\n" )
gui . AreaAppendText ( aText , "IPv6\n" )
gui . AreaAppendText ( aText , "Your hostname in DNS\n" )
aText . AppendUnattributed ( "\n\n\n\n\n" )
gui . AreaAppendText ( aText , "<click or press any key>\n" , ui . TextSize ( 10 ) )
return aText
}
2019-06-01 03:19:51 -05:00
2019-06-02 08:21:12 -05:00
func splashClick ( b * gui . GuiButton ) {
2019-06-02 21:56:14 -05:00
log . Println ( "splashClick() START" )
2019-06-02 08:21:12 -05:00
gw := b . Box . Window
// if there is already an account, skip straight to the main screen
for key , _ := range config . Accounts {
log . Println ( "gui.State = splash BUT THERE IS AN ACCOUNT Account = " , config . Accounts [ key ] )
makeCloudInfoBox ( gw )
return
}
// if there is not an account, then go to 'make account'
2019-06-02 17:50:11 -05:00
gw = gui . InitGuiWindow ( "splashClick() Box22" , gw )
2019-06-02 13:52:29 -05:00
gw . UiTab . Delete ( 0 )
2019-06-02 13:40:13 -05:00
2019-06-02 21:56:14 -05:00
log . Println ( "splashClick() AddGenericBox() START" )
2019-06-02 13:02:03 -05:00
box := gui . AddGenericBox ( gw , "addSubdomainQuestion" )
2019-06-02 21:56:14 -05:00
log . Println ( "splashClick() AddGenericBox() END box =" , box )
2019-06-01 03:19:51 -05:00
2019-06-01 04:12:46 -05:00
gui . NewLabel ( box , "Enter your Subdomain or" )
2019-06-01 03:19:51 -05:00
2019-06-02 21:56:14 -05:00
makeButton ( box , nil , nil , "Generate" , "SUBDOMAIN" , generateSubdomain )
2019-06-01 04:12:46 -05:00
gui . AddEntry ( box , "SUBDOMAIN" )
gui . HorizontalBreak ( box )
2019-06-02 21:56:14 -05:00
makeButton ( box , nil , nil , "Create Subdomain Account" , "ADD" , addSubdomainButton )
2019-06-01 04:12:46 -05:00
2019-06-02 21:56:14 -05:00
log . Println ( "splashClick() END box =" , box )
2019-06-01 03:19:51 -05:00
}
2019-06-01 04:12:46 -05:00
2019-06-01 19:53:30 -05:00
func addSubdomainButton ( b * gui . GuiButton ) {
log . Println ( "addSubdomainButton() START" )
subdomain := gui . GetText ( b . Box , "SUBDOMAIN" )
if ( subdomain == "" ) {
2019-06-02 17:19:36 -05:00
gui . ErrorWindow ( b . Box . Window , "Blank Name" , "You must have a valid subdomain" )
2019-06-01 19:53:30 -05:00
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 )
2019-06-02 17:19:36 -05:00
makeCloudInfoBox ( b . Box . Window )
2019-06-01 19:53:30 -05:00
gui . Data . State = "done"
log . Println ( "addSubdomainButton() END" )
}
2019-06-01 04:12:46 -05:00
func generateSubdomain ( b * gui . GuiButton ) {
log . Println ( "generateSubdomain START" )
2019-06-02 21:56:14 -05:00
if values , ok := b . Values . ( * myButtonInfo ) ; ! ok {
log . Println ( "\tvalues.Accounts error" )
} else {
log . Println ( "\tvalues.Accounts =" , values . Accounts )
log . Println ( "\tvalues.Name =" , values . Name )
}
// use this way?
// values, _ := b.Values.(*myButtonInfo)
2019-06-01 04:12:46 -05:00
if ( b == nil ) {
log . Println ( "generateSubdomain ERROR b == nil" )
return
}
// subdomain.SetText("cust00013.wit.dev")
2019-06-02 15:36:44 -05:00
// 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'
txt := gui . SetText ( b . Box , "SUBDOMAIN" , "http://stackapi-api1.stackapi.customers.wit.com:4000/vms/jcarr" )
2019-06-01 04:12:46 -05:00
log . Println ( "generateSubdomain subdomain = " , txt )
log . Println ( "generateSubdomain END" )
}