join.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package views
  2. import (
  3. "fyne.io/fyne/v2"
  4. "fyne.io/fyne/v2/container"
  5. "fyne.io/fyne/v2/theme"
  6. "fyne.io/fyne/v2/widget"
  7. "github.com/gravitl/netmaker/netclient/config"
  8. "github.com/gravitl/netmaker/netclient/functions"
  9. "github.com/gravitl/netmaker/netclient/gui/components"
  10. "github.com/gravitl/netmaker/netclient/ncutils"
  11. )
  12. // GetJoinView - get's the join screen where a user inputs an access token
  13. func GetJoinView() fyne.CanvasObject {
  14. input := widget.NewMultiLineEntry()
  15. input.SetPlaceHolder("access token here...")
  16. submitBtn := components.ColoredIconButton("Submit", theme.UploadIcon(), func() {
  17. // ErrorNotify("Could not process token")
  18. LoadingNotify()
  19. var cfg config.ClientConfig
  20. accesstoken, err := config.ParseAccessToken(input.Text)
  21. if err != nil {
  22. ErrorNotify("Failed to parse access token!")
  23. return
  24. }
  25. cfg.Network = accesstoken.ClientConfig.Network
  26. cfg.Node.Network = accesstoken.ClientConfig.Network
  27. cfg.Node.Name = ncutils.GetHostname()
  28. cfg.Server.AccessKey = accesstoken.ClientConfig.Key
  29. cfg.Node.LocalRange = accesstoken.ClientConfig.LocalRange
  30. cfg.Server.Server = accesstoken.ServerConfig.Server
  31. cfg.Server.API = accesstoken.ServerConfig.APIConnString
  32. err = functions.JoinNetwork(&cfg, "")
  33. if err != nil {
  34. ErrorNotify("Failed to join " + cfg.Network + "!")
  35. return
  36. }
  37. networks, err := ncutils.GetSystemNetworks()
  38. if err != nil {
  39. ErrorNotify("Failed to read local networks!")
  40. return
  41. }
  42. SuccessNotify("Joined " + cfg.Network + "!")
  43. input.Text = ""
  44. RefreshComponent(Networks, GetNetworksView(networks))
  45. ShowView(Networks)
  46. // TODO
  47. // - call join
  48. // - display loading
  49. // - on error display error notification
  50. // - on success notify success, refresh networks & networks view, display networks view
  51. }, components.Blue_color)
  52. return container.NewGridWithColumns(1,
  53. container.NewCenter(widget.NewLabel("Join new network with Access Token")),
  54. input,
  55. container.NewCenter(submitBtn),
  56. )
  57. }