-
Notifications
You must be signed in to change notification settings - Fork 4
/
status.go
64 lines (53 loc) · 1.44 KB
/
status.go
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
package diff
import (
"github.com/samber/lo"
"projectforge.dev/projectforge/app/util"
)
type Status struct {
Key string
Title string
}
var (
StatusDifferent = &Status{Key: "different", Title: "The files are different"}
StatusIdentical = &Status{Key: "identical", Title: "The files are identical"}
StatusMissing = &Status{Key: "missing", Title: "File is not present in the source"}
StatusNew = &Status{Key: "new", Title: "File is not present in the target"}
StatusSkipped = &Status{Key: "skipped", Title: "File was ignored"}
)
var AllStatuses = []*Status{StatusDifferent, StatusIdentical, StatusMissing, StatusNew, StatusSkipped}
func StatusFromString(s string) *Status {
return lo.FindOrElse(AllStatuses, nil, func(t *Status) bool {
return t.Key == s
})
}
func (s *Status) String() string {
return s.Key
}
func (s *Status) Matches(x *Status) bool {
return s.Key == x.Key
}
func (s *Status) StringFor(act string) string {
if act == "audit" {
switch s.Key {
case StatusDifferent.Key:
return "Invalid Header"
case StatusMissing.Key:
return "Empty Folder"
default:
return util.StringToTitle(s.Key)
}
}
return util.StringToTitle(s.Key)
}
func (s *Status) MarshalJSON() ([]byte, error) {
return util.ToJSONBytes(s.Key, false), nil
}
func (s *Status) UnmarshalJSON(data []byte) error {
var str string
if err := util.FromJSON(data, &s); err != nil {
return err
}
x := StatusFromString(str)
*s = *x
return nil
}