/
SetupAction.go
271 lines (186 loc) · 6.72 KB
/
SetupAction.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package action
import (
"fmt"
widgets2 "github.com/vit1251/golden/internal/site/widgets"
"github.com/vit1251/golden/pkg/config"
"net/http"
)
type SetupAction struct {
Action
}
func NewSetupAction() *SetupAction {
newSetupAction := new(SetupAction)
return newSetupAction
}
/* Setup sections */
type setupParam struct {
section string
name string
value string
summary string
}
type setupSection struct {
Name string
Params []setupParam
}
func (self *setupSection) Register(c *config.Config, section string, name string, summary string) {
paramValue := config.GetByPath(c, section, name)
newSetupParam := new(setupParam)
newSetupParam.section = section
newSetupParam.name = name
newSetupParam.summary = summary
newSetupParam.value = paramValue
self.Params = append(self.Params, *newSetupParam)
}
func (self SetupAction) makeFidoSection(c *config.Config) setupSection {
/* Section header */
netSetupSession := new(setupSection)
netSetupSession.Name = "Fidonet options"
/* Section options */
netSetupSession.Register(c, "main", "Address", "FidoNet point address (example: 2:5020/1024.11)")
netSetupSession.Register(c, "main", "Password", "FidoNet point password (example: pa$$w0rd)")
netSetupSession.Register(c, "main", "Link", "FidoNet uplink provide (example: 2:5020/1024)")
return *netSetupSession
}
func (self SetupAction) makeGatewaySection(c *config.Config) setupSection {
/* Section header */
gwSetupSession := new(setupSection)
gwSetupSession.Name = "Gateway options"
/* Section options */
gwSetupSession.Register(c, "main", "NetAddr", "Gateway IP address and port (example: f1024.n5020.z2.binkp.net:24554)")
return *gwSetupSession
}
func (self SetupAction) makeUserSection(c *config.Config) setupSection {
/* Section header */
userSetupSession := new(setupSection)
userSetupSession.Name = "User options"
/* Section options */
userSetupSession.Register(c, "main", "RealName", "Realname is you English version your real name (example: Dmitri Kamenski)")
userSetupSession.Register(c, "main", "Country", "Country where user is seat")
userSetupSession.Register(c, "main", "City", "City where user is seat")
userSetupSession.Register(c, "main", "Origin", "Origin was provide BBS station name and network address")
userSetupSession.Register(c, "main", "TearLine", "Tearline provide person sign in all their messages")
return *userSetupSession
}
func (self SetupAction) makeOtherSection(c *config.Config) setupSection {
/* Section header */
otherSetupSession := new(setupSection)
otherSetupSession.Name = "Other"
/* Section options */
otherSetupSession.Register(c, "main", "StationName", "Station name is your nickname")
otherSetupSession.Register(c, "mailer", "Interval", "Polling interval in minutes")
return *otherSetupSession
}
func (self SetupAction) makeDirectMessageSection(c *config.Config) setupSection {
/* Section header */
directMessageSetupSection := new(setupSection)
directMessageSetupSection.Name = "Netmail options"
/* Section options */
directMessageSetupSection.Register(c, "netmail", "Charset", "Netmail default charset")
return *directMessageSetupSection
}
func (self SetupAction) makeEchomailMessageSection(c *config.Config) setupSection {
/* Section header */
echoSetupSection := new(setupSection)
echoSetupSection.Name = "Echomail options"
/* Section options */
echoSetupSection.Register(c, "echomail", "Charset", "Echomail default charset")
return *echoSetupSection
}
func (self SetupAction) makeSections(c *config.Config) []setupSection {
var setupSections []setupSection
/* Fidonet section */
networkingSection := self.makeFidoSection(c)
setupSections = append(setupSections, networkingSection)
/* Gateway section */
gatewaySection := self.makeGatewaySection(c)
setupSections = append(setupSections, gatewaySection)
/* User section */
userSection := self.makeUserSection(c)
setupSections = append(setupSections, userSection)
/* Direct message section */
directMessageSection := self.makeDirectMessageSection(c)
setupSections = append(setupSections, directMessageSection)
/* Echomail message section */
echoSection := self.makeEchomailMessageSection(c)
setupSections = append(setupSections, echoSection)
/* Other section */
otherSection := self.makeOtherSection(c)
setupSections = append(setupSections, otherSection)
return setupSections
}
func (self SetupAction) ServeHTTP(w http.ResponseWriter, r *http.Request) {
configManager := config.RestoreConfigManager(self.GetRegistry())
/* Get params */
newConfig := configManager.GetConfig()
/* Make sections */
setupSections := self.makeSections(newConfig)
/* Render */
bw := widgets2.NewBaseWidget()
vBox := widgets2.NewVBoxWidget()
bw.SetWidget(vBox)
mmw := self.makeMenu()
vBox.Add(mmw)
container := widgets2.NewDivWidget()
container.SetClass("container")
containerVBox := widgets2.NewVBoxWidget()
container.AddWidget(containerVBox)
vBox.Add(container)
setupForm := widgets2.NewFormWidget().
SetMethod("POST").
SetAction("/setup/complete")
sections := widgets2.NewVBoxWidget()
sections.Add(widgets2.NewFormButtonWidget().
SetTitle("Save").
SetType("submit"))
sections.Add(widgets2.NewFormButtonWidget().
SetTitle("Discard").
SetType("reset"))
/* Make sections with settings */
sectionsWithSettings := self.makeSectionsWithSettings(setupSections)
sections.Add(sectionsWithSettings)
setupForm.SetWidget(sections)
containerVBox.Add(setupForm)
/* Render */
if err := bw.Render(w); err != nil {
status := fmt.Sprintf("%+v", err)
http.Error(w, status, http.StatusInternalServerError)
return
}
}
func (self *SetupAction) createInputField(box *widgets2.VBoxWidget, param setupParam) {
mainDiv := widgets2.NewDivWidget().
SetClass("form-group row")
mainDivBox := widgets2.NewVBoxWidget()
mainDiv.AddWidget(mainDivBox)
mainTitle := widgets2.NewDivWidget().
SetClass("").
SetContent(param.name)
mainDivBox.Add(mainTitle)
newInputName := fmt.Sprintf("%s.%s", param.section, param.name)
mainInput := widgets2.NewFormInputWidget().
SetTitle(param.summary).
SetName(newInputName).
SetValue(param.value)
mainDivBox.Add(mainInput)
box.Add(mainDiv)
}
func (self SetupAction) makeSectionWithSettings(s setupSection) widgets2.IWidget {
newSection := widgets2.NewSectionWidget()
newSection.SetTitle(s.Name)
sectionVBox := widgets2.NewVBoxWidget()
for _, param := range s.Params {
self.createInputField(sectionVBox, param)
}
newSection.SetWidget(sectionVBox)
return newSection
}
func (self SetupAction) makeSectionsWithSettings(setupSections []setupSection) widgets2.IWidget {
newSections := widgets2.NewVBoxWidget()
/* Draw sections */
for _, s := range setupSections {
newSection := self.makeSectionWithSettings(s)
newSections.Add(newSection)
}
return newSections
}