summaryrefslogtreecommitdiff
path: root/droplet.update.go
blob: 0c935f550fdb55bcf8e2852b57ac1b5b5d0f83f8 (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
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb 0.0.61 2025/02/23_0116_UTC
//     go install go.wit.com/apps/autogenpb@latest
//
// define which structs (messages) you want to use in the .proto file
// Then sort.pb.go and marshal.pb.go files are autogenerated
//
// autogenpb uses it and has an example .proto file with instructions
//

package virtpb

import (
	"github.com/google/uuid"
	"go.wit.com/lib/protobuf/guipb"
	"go.wit.com/log"
	"google.golang.org/protobuf/types/known/timestamppb"
)

func (mt *DropletsTable) NewUuid() {
	mt.pb.Uuid = uuid.New().String()
}

func (mt *HypervisorsTable) NewUuid() {
	mt.pb.Uuid = uuid.New().String()
}

func (mt *EventsTable) NewUuid() {
	mt.pb.Uuid = uuid.New().String()
}

func (mt *HypervisorsTable) Update() {
	log.Info("now what hyper?")
}

func (mt *DropletsTable) Update() {
	log.Info("now what?")
	for _, name := range mt.pb.Order {
		log.Info("virtpb: trying to update row()", name)
		if mt.updateStringFunc(name) {
			continue
		}
		if mt.updateTimeFunc(name) {
			continue
		}
		/*
			if mt.updateIntFunc(name) {
				continue
			}
		*/
	}
	mt.parent.ShowTable(mt.pb)
}

func (mt *DropletsTable) updateStringFunc(name string) bool {
	log.Info("LOOKING FOR STRING row", name)
	var found *guipb.StringRow
	for i, r := range mt.pb.StringRows {
		// log.Info("could use", i, r.Header.Name, "for name =", name)
		if r.Header.Name == name {
			log.Info("found row", i, r.Header.Name)
			found = r
			break
		}
	}
	if found == nil {
		log.Info("did not find string row", name)
		return false
	}
	for _, sf := range mt.stringFuncs {
		if sf.title != name {
			continue
		}
		log.Info("updateStringFunc() has row len =", len(mt.x.Droplets))
		log.Info("virtpb: starting", name, found.Vals)
		for i, _ := range found.Vals {
			found.Vals[i] = sf.f(mt.x.Droplets[i])
		}
		log.Info("virtpb: ending", name, found.Vals)
		return true
	}
	return false
}

func (mt *DropletsTable) updateTimeFunc(name string) bool {
	log.Info("LOOKING FOR TIME row", name)
	var found *guipb.TimeRow
	for i, r := range mt.pb.TimeRows {
		// log.Info("could use", i, r.Header.Name, "for name =", name)
		if r.Header.Name == name {
			log.Info("found row", i, r.Header.Name)
			found = r
			break
		}
	}
	if found == nil {
		log.Info("did not find time row", name)
		return false
	}
	for _, sf := range mt.timeFuncs {
		if sf.title != name {
			continue
		}
		log.Info("updateTimeFunc() has row len =", len(mt.x.Droplets))
		log.Info("virtpb: starting", name, found.Vals)
		for i, _ := range found.Vals {
			newt := sf.f(mt.x.Droplets[i])
			found.Vals[i] = timestamppb.New(newt) // convert to protobuf time
		}
		log.Info("virtpb: ending", name, found.Vals)
		return true
	}
	return false
}