mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-12 09:40:46 +08:00
adding a connection button
This commit is contained in:
parent
db32887829
commit
7a2e95c7c0
1 changed files with 71 additions and 1 deletions
|
|
@ -21,11 +21,12 @@ func GetNetworksView(networks []string) fyne.CanvasObject {
|
||||||
if len(networks) == 0 {
|
if len(networks) == 0 {
|
||||||
return container.NewCenter(widget.NewLabel("No networks present"))
|
return container.NewCenter(widget.NewLabel("No networks present"))
|
||||||
}
|
}
|
||||||
grid := container.New(layout.NewGridLayout(4),
|
grid := container.New(layout.NewGridLayout(5),
|
||||||
container.NewCenter(widget.NewLabel("Network Name")),
|
container.NewCenter(widget.NewLabel("Network Name")),
|
||||||
container.NewCenter(widget.NewLabel("Node Info")),
|
container.NewCenter(widget.NewLabel("Node Info")),
|
||||||
container.NewCenter(widget.NewLabel("Pull Latest")),
|
container.NewCenter(widget.NewLabel("Pull Latest")),
|
||||||
container.NewCenter(widget.NewLabel("Leave network")),
|
container.NewCenter(widget.NewLabel("Leave network")),
|
||||||
|
container.NewCenter(widget.NewLabel("Connection status")),
|
||||||
)
|
)
|
||||||
for i := range networks {
|
for i := range networks {
|
||||||
network := &networks[i]
|
network := &networks[i]
|
||||||
|
|
@ -49,6 +50,24 @@ func GetNetworksView(networks []string) fyne.CanvasObject {
|
||||||
leave(*network)
|
leave(*network)
|
||||||
}, components.Danger_color),
|
}, components.Danger_color),
|
||||||
)
|
)
|
||||||
|
cfg, err := config.ReadConfig(*network)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
|
if cfg.Node.Connected == "yes" {
|
||||||
|
grid.Add(
|
||||||
|
components.ColoredIconButton("connection", theme.CheckButtonCheckedIcon(), func() {
|
||||||
|
disconnect(*network)
|
||||||
|
}, components.Gravitl_color),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
grid.Add(
|
||||||
|
components.ColoredIconButton("connection", theme.CheckButtonIcon(), func() {
|
||||||
|
connect(*network)
|
||||||
|
}, components.Danger_color),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// renders = append(renders, container.NewCenter(netToolbar))
|
// renders = append(renders, container.NewCenter(netToolbar))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,3 +183,54 @@ func leave(network string) {
|
||||||
RefreshComponent(Confirm, confirmView)
|
RefreshComponent(Confirm, confirmView)
|
||||||
ShowView(Confirm)
|
ShowView(Confirm)
|
||||||
}
|
}
|
||||||
|
func connect(network string) {
|
||||||
|
|
||||||
|
confirmView := GetConfirmation("Confirm connecting "+network+"?", func() {
|
||||||
|
ShowView(Networks)
|
||||||
|
}, func() {
|
||||||
|
LoadingNotify()
|
||||||
|
err := functions.Connect(network)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
ErrorNotify("Failed to connect " + network + " : " + err.Error())
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SuccessNotify("connected to " + network)
|
||||||
|
}
|
||||||
|
networks, err := ncutils.GetSystemNetworks()
|
||||||
|
if err != nil {
|
||||||
|
networks = []string{}
|
||||||
|
ErrorNotify("Failed to read local networks!")
|
||||||
|
}
|
||||||
|
RefreshComponent(Networks, GetNetworksView(networks))
|
||||||
|
ShowView(Networks)
|
||||||
|
})
|
||||||
|
RefreshComponent(Confirm, confirmView)
|
||||||
|
ShowView(Confirm)
|
||||||
|
}
|
||||||
|
func disconnect(network string) {
|
||||||
|
|
||||||
|
confirmView := GetConfirmation("Confirm disconnecting "+network+"?", func() {
|
||||||
|
ShowView(Networks)
|
||||||
|
}, func() {
|
||||||
|
LoadingNotify()
|
||||||
|
fmt.Println(network)
|
||||||
|
err := functions.Disconnect(network)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
ErrorNotify("Failed to disconnect " + network + " : " + err.Error())
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SuccessNotify("disconnected from " + network)
|
||||||
|
}
|
||||||
|
networks, err := ncutils.GetSystemNetworks()
|
||||||
|
if err != nil {
|
||||||
|
networks = []string{}
|
||||||
|
ErrorNotify("Failed to read local networks!")
|
||||||
|
}
|
||||||
|
RefreshComponent(Networks, GetNetworksView(networks))
|
||||||
|
ShowView(Networks)
|
||||||
|
})
|
||||||
|
RefreshComponent(Confirm, confirmView)
|
||||||
|
ShowView(Confirm)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue