join.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.API = accesstoken.ServerConfig.APIConnString
  31. err = functions.JoinNetwork(&cfg, "")
  32. if err != nil {
  33. ErrorNotify("Failed to join " + cfg.Network + "!")
  34. return
  35. }
  36. networks, err := ncutils.GetSystemNetworks()
  37. if err != nil {
  38. ErrorNotify("Failed to read local networks!")
  39. return
  40. }
  41. SuccessNotify("Joined " + cfg.Network + "!")
  42. input.Text = ""
  43. RefreshComponent(Networks, GetNetworksView(networks))
  44. ShowView(Networks)
  45. // TODO
  46. // - call join
  47. // - display loading
  48. // - on error display error notification
  49. // - on success notify success, refresh networks & networks view, display networks view
  50. }, components.Blue_color)
  51. return container.NewGridWithColumns(1,
  52. container.NewCenter(widget.NewLabel("Join new network with Access Token")),
  53. input,
  54. container.NewCenter(submitBtn),
  55. )
  56. }