-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_field_to_form.go
213 lines (190 loc) · 6.11 KB
/
basic_field_to_form.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// generated code - do not edit
package probe
import (
"math"
"time"
form "github.com/fullstack-lang/gongtable/go/models"
"github.com/fullstack-lang/gongfly/go/models"
)
func BasicFieldtoForm[T models.PointerToGongstruct, TF models.GongtructBasicField](
fieldName string, field TF, instance T, formStage *form.StageStruct, formGroup *form.FormGroup,
isTextArea bool, isBespokeWidth bool, bespokeWidth int, isBespokeHeight bool, bespokeHeight int,
) {
switch fieldWithInterferedType := any(field).(type) {
case string:
formDiv := (&form.FormDiv{
Name: fieldName,
}).Stage(formStage)
formGroup.FormDivs = append(formGroup.FormDivs, formDiv)
formField := (&form.FormField{
Name: fieldName,
Label: fieldName,
Placeholder: "",
HasBespokeWidth: isBespokeWidth,
BespokeWidthPx: bespokeWidth,
HasBespokeHeight: isBespokeHeight,
BespokeHeightPx: bespokeHeight,
}).Stage(formStage)
formDiv.FormFields = append(formDiv.FormFields, formField)
formFieldString := (&form.FormFieldString{
Name: "string",
Value: fieldWithInterferedType,
IsTextArea: isTextArea,
}).Stage(formStage)
formField.FormFieldString = formFieldString
case time.Time:
formDiv := (&form.FormDiv{
Name: fieldName,
}).Stage(formStage)
formGroup.FormDivs = append(formGroup.FormDivs, formDiv)
{
formFieldPartDate := (&form.FormField{
Name: fieldName + "Date",
Label: fieldName + "Date",
Placeholder: "",
}).Stage(formStage)
formDiv.FormFields = append(formDiv.FormFields, formFieldPartDate)
formFieldDate := (&form.FormFieldDate{
Name: fieldName + "Date",
Value: fieldWithInterferedType,
}).Stage(formStage)
formFieldPartDate.FormFieldDate = formFieldDate
}
{
formFieldPartTime := (&form.FormField{
Name: fieldName + "Time",
Label: fieldName + "Time",
Placeholder: "",
}).Stage(formStage)
formDiv.FormFields = append(formDiv.FormFields, formFieldPartTime)
formFieldTime := (&form.FormFieldTime{
Name: fieldName + "Time",
Value: fieldWithInterferedType,
}).Stage(formStage)
formFieldPartTime.FormFieldTime = formFieldTime
}
case bool:
formDiv := (&form.FormDiv{
Name: fieldName,
}).Stage(formStage)
formGroup.FormDivs = append(formGroup.FormDivs, formDiv)
checkBox := (&form.CheckBox{
Name: fieldName,
Value: fieldWithInterferedType,
}).Stage(formStage)
formDiv.CheckBoxs = append(formDiv.CheckBoxs, checkBox)
case int:
formDiv := (&form.FormDiv{
Name: fieldName,
}).Stage(formStage)
formGroup.FormDivs = append(formGroup.FormDivs, formDiv)
formField := (&form.FormField{
Name: fieldName,
Label: fieldName,
}).Stage(formStage)
formDiv.FormFields = append(formDiv.FormFields, formField)
formFieldInt := (&form.FormFieldInt{
Name: fieldName,
Value: fieldWithInterferedType,
}).Stage(formStage)
formField.FormFieldInt = formFieldInt
case float64:
formDiv := (&form.FormDiv{
Name: fieldName,
}).Stage(formStage)
formGroup.FormDivs = append(formGroup.FormDivs, formDiv)
formField := (&form.FormField{
Name: fieldName,
Label: fieldName,
}).Stage(formStage)
formDiv.FormFields = append(formDiv.FormFields, formField)
formFieldFloat64 := (&form.FormFieldFloat64{
Name: fieldName,
Value: fieldWithInterferedType,
}).Stage(formStage)
formField.FormFieldFloat64 = formFieldFloat64
case time.Duration:
formDiv := (&form.FormDiv{
Name: fieldName,
}).Stage(formStage)
formGroup.FormDivs = append(formGroup.FormDivs, formDiv)
{
checkBox := (&form.CheckBox{
Name: "negative",
Value: fieldWithInterferedType < 0,
}).Stage(formStage)
formDiv.CheckBoxs = append(formDiv.CheckBoxs, checkBox)
}
{
formFieldDays := (&form.FormField{
Name: "Days",
Label: "Days",
}).Stage(formStage)
formFieldDays.HasBespokeWidth = true
formFieldDays.BespokeWidthPx = 90
formDiv.FormFields = append(formDiv.FormFields, formFieldDays)
value := int(math.Abs(fieldWithInterferedType.Hours() / 24))
formFieldIntDays := (&form.FormFieldInt{
Name: "Days",
Value: value,
}).Stage(formStage)
formFieldIntDays.HasMinValidator = true
formFieldIntDays.MinValue = 0
formFieldDays.FormFieldInt = formFieldIntDays
}
{
formFieldHours := (&form.FormField{
Name: "Hours",
Label: "Hours",
}).Stage(formStage)
formFieldHours.HasBespokeWidth = true
formFieldHours.BespokeWidthPx = 90
formDiv.FormFields = append(formDiv.FormFields, formFieldHours)
formFieldIntHours := (&form.FormFieldInt{
Name: "Hours",
Value: int(math.Abs(fieldWithInterferedType.Hours())) % 24,
}).Stage(formStage)
formFieldIntHours.HasMaxValidator = true
formFieldIntHours.MaxValue = 23
formFieldIntHours.HasMinValidator = true
formFieldIntHours.MinValue = 0
formFieldHours.FormFieldInt = formFieldIntHours
}
{
formFieldMinutes := (&form.FormField{
Name: "Minutes",
Label: "Minutes",
}).Stage(formStage)
formFieldMinutes.HasBespokeWidth = true
formFieldMinutes.BespokeWidthPx = 90
formDiv.FormFields = append(formDiv.FormFields, formFieldMinutes)
formFieldIntMinutes := (&form.FormFieldInt{
Name: "Minutes",
Value: int(math.Abs(fieldWithInterferedType.Minutes())) % 60,
}).Stage(formStage)
formFieldIntMinutes.HasMaxValidator = true
formFieldIntMinutes.MaxValue = 59
formFieldIntMinutes.HasMinValidator = true
formFieldIntMinutes.MinValue = 0
formFieldMinutes.FormFieldInt = formFieldIntMinutes
}
{
formFieldSeconds := (&form.FormField{
Name: "Seconds",
Label: "Seconds",
}).Stage(formStage)
formFieldSeconds.HasBespokeWidth = true
formFieldSeconds.BespokeWidthPx = 90
formDiv.FormFields = append(formDiv.FormFields, formFieldSeconds)
formFieldIntSeconds := (&form.FormFieldInt{
Name: "Seconds",
Value: int(math.Abs(fieldWithInterferedType.Seconds())) % 60,
}).Stage(formStage)
formFieldIntSeconds.HasMaxValidator = true
formFieldIntSeconds.MaxValue = 59
formFieldIntSeconds.HasMinValidator = true
formFieldIntSeconds.MinValue = 0
formFieldSeconds.FormFieldInt = formFieldIntSeconds
}
}
}