summaryrefslogtreecommitdiff
path: root/windowDropletCreate.go
blob: f38f3939826c8d419f0d10eca5330dc3803fcced (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

// An app to submit patches for the 30 GO GUI repos

import (
	"fmt"
	"strconv"

	"go.wit.com/gui"
	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/protobuf/virtpb"
	"go.wit.com/log"
)

func (admin *adminT) createDropletWindow() *gadgets.GenericWindow {
	d := new(virtpb.Droplet)

	win := gadgets.NewGenericWindow("Create Droplet "+d.Hostname, "settings")
	win.Custom = func() {
		log.Warn("edit window close")
	}

	grid := win.Group.RawGrid()

	var save *gui.Node

	grid.NewLabel("name")
	name := grid.NewTextbox("new2.wit.com")
	d.Hostname = "new2.wit.com"
	name.SetText(d.Hostname)
	name.Custom = func() {
		if d.Hostname == name.String() {
			return
		}
		d.Hostname = name.String()
		log.Info("changed droplet name to", d.Hostname)
		save.Enable()
	}
	grid.NextRow()

	mem := gadgets.NewBasicEntry(grid, "memory (GB)")
	mem.SetText("16")
	d.Memory = int64(16 * 1024 * 2024 * 1024)
	grid.NextRow()
	mem.Custom = func() {
		newmem, err := strconv.Atoi(mem.String())
		if err != nil {
			log.Info("mem value error", mem.String(), err)
			mem.SetText(fmt.Sprintf("%d", d.Memory/(1024*1024*1024)))
			return
		}
		if newmem < 1 {
			log.Info("mem can not be < 1")
			mem.SetText(fmt.Sprintf("%d", d.Memory/(1024*1024*1024)))
			return
		}
		d.Memory = int64(newmem * (1024 * 2024 * 1024))
		log.Info("changed mem value. new val =", d.Memory)

		save.Enable()
	}
	grid.NextRow() // each entry is on it's own row

	cpus := gadgets.NewBasicEntry(grid, "cpus")
	cpus.SetText("4")
	d.Cpus = int64(4)
	cpus.Custom = func() {
		newcpu, err := strconv.Atoi(cpus.String())
		if err != nil {
			log.Info("cpus value error", cpus.String(), err)
			cpus.SetText(fmt.Sprintf("%d", d.Cpus))
			return
		}
		if newcpu < 1 {
			log.Info("cpus can not be < 1")
			cpus.SetText(fmt.Sprintf("%d", d.Cpus))
			return
		}
		d.Cpus = int64(newcpu)
		log.Info("changed cpus value. new val =", d.Cpus)

		save.Enable()
	}
	grid.NextRow() // each entry is on it's own row

	/*
		save = grid.NewButton("postEvent() EDIT", func() {
			log.Info("save droplet changes here")

			e := new(virtpb.Event)
			e.Etype = virtpb.EventType_EDIT
			e.Droplet = d

			if err := admin.postEvent(e); err != nil {
				log.Info("event edit err", err)
			} else {
				log.Info("admin.postEvent() worked (?)")
			}
		})
	*/

	save = grid.NewButton("Create", func() {
		log.Info("save droplet changes here")

		e := new(virtpb.Event)
		e.Etype = virtpb.EventType_ADD
		e.Droplet = d

		if err := admin.postEvent(e); err != nil {
			log.Info("event edit err", err)
		} else {
			log.Info("admin.postEvent() worked (?)")
		}
	})

	// save.Disable()
	return win
}