This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
schema_group.go
111 lines (97 loc) · 2.16 KB
/
schema_group.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
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
package property
import (
"github.com/reearth/reearth-backend/pkg/i18n"
)
// SchemaGroup represents a group of property that has some fields
type SchemaGroup struct {
id SchemaGroupID
fields []*SchemaField
list bool
isAvailableIf *Condition
title i18n.String
representativeField *FieldID
}
// ID returns id
func (s *SchemaGroup) ID() SchemaGroupID {
if s == nil {
return SchemaGroupID("")
}
return s.id
}
func (s *SchemaGroup) IDRef() *SchemaGroupID {
if s == nil {
return nil
}
return s.id.Ref()
}
// Fields returns a slice of fields
func (s *SchemaGroup) Fields() []*SchemaField {
if s == nil {
return nil
}
return append([]*SchemaField{}, s.fields...)
}
// Field returns a field whose id is specified
func (s *SchemaGroup) Field(fid FieldID) *SchemaField {
if s == nil {
return nil
}
for _, f := range s.fields {
if f.ID() == fid {
return f
}
}
return nil
}
// FieldByPointer returns a field whose id is specified
func (s *SchemaGroup) FieldByPointer(ptr *Pointer) *SchemaField {
if s == nil {
return nil
}
fid, ok := ptr.Field()
if !ok {
return nil
}
return s.Field(fid)
}
func (s *SchemaGroup) HasField(i FieldID) bool {
return s.Field(i) != nil
}
// IsList returns true if this group is list
func (s *SchemaGroup) IsList() bool {
if s == nil {
return false
}
return s.list
}
// IsAvailableIf returns condition of availability
func (s *SchemaGroup) IsAvailableIf() *Condition {
if s == nil {
return nil
}
return s.isAvailableIf.Clone()
}
// Title returns a title of the group
func (s *SchemaGroup) Title() i18n.String {
if s == nil {
return nil
}
return s.title.Clone()
}
// RepresentativeFieldID returns the representative field ID of the group
func (s *SchemaGroup) RepresentativeFieldID() *FieldID {
if s == nil {
return nil
}
return s.representativeField
}
// RepresentativeField returns the representative field of the group
func (s *SchemaGroup) RepresentativeField() *SchemaField {
if s == nil || s.representativeField == nil {
return nil
}
return s.Field(*s.representativeField)
}
func (s *SchemaGroup) SetTitle(t i18n.String) {
s.title = t.Clone()
}