Skip to content

Commit 5082ae6

Browse files
committed
feat(ui): simplify export workflow and refactor import fields
- Remove the manual "Plugin Save Path" entry and browse button from the Export tab. - Update "Generate Plugin" button to trigger a save dialog directly, streamlining the UX. - Refactor local variables in `createImportTab` (e.g., `hostEntry`, `sshUserEntry`) to be struct fields (e.g., `u.impHostEntry`, `u.impSSHUserEntry`) to ensure proper state access during form submission.
1 parent d84e5cd commit 5082ae6

3 files changed

Lines changed: 227 additions & 165 deletions

File tree

ui/export.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,21 @@ func (u *UI) createExportTab(w fyne.Window) fyne.CanvasObject {
6767
u.expWPKeyEntry = widget.NewEntry()
6868
u.expWPKeyEntry.SetPlaceHolder("API Key")
6969

70-
u.expWPPluginPathEntry = widget.NewEntry()
71-
u.expWPPluginPathEntry.SetText(u.getExecutableDir())
72-
pluginPathBtn := widget.NewButton("Browse", func() {
70+
generatePluginBtn := widget.NewButton("Generate Plugin", func() {
71+
// Ask for save location
7372
dialog.ShowFolderOpen(func(uri fyne.ListableURI, err error) {
74-
if err == nil && uri != nil {
75-
u.expWPPluginPathEntry.SetText(uri.Path())
73+
if err != nil || uri == nil {
74+
return
7675
}
77-
}, w)
78-
})
79-
pluginPathContainer := container.NewBorder(nil, nil, nil, pluginPathBtn, u.expWPPluginPathEntry)
8076

81-
generatePluginBtn := widget.NewButton("Generate Plugin", func() {
82-
destDir := u.expWPPluginPathEntry.Text
83-
key, path, err := wordpress.GeneratePlugin("plugin_template/dback-sync.php", destDir)
84-
if err != nil {
85-
dialog.ShowError(err, w)
86-
return
87-
}
88-
u.expWPKeyEntry.SetText(key)
89-
dialog.ShowInformation("Plugin Generated", fmt.Sprintf("Plugin saved to %s\nAPI Key has been set.", path), w)
77+
key, path, err := wordpress.GeneratePlugin("plugin_template/dback-sync.php", uri.Path())
78+
if err != nil {
79+
dialog.ShowError(err, w)
80+
return
81+
}
82+
u.expWPKeyEntry.SetText(key)
83+
dialog.ShowInformation("Plugin Generated", fmt.Sprintf("Plugin saved to %s\nAPI Key has been set.", path), w)
84+
}, w)
9085
})
9186

9287
// Containers
@@ -105,7 +100,6 @@ func (u *UI) createExportTab(w fyne.Window) fyne.CanvasObject {
105100
widget.NewForm(
106101
widget.NewFormItem("WordPress URL", u.expWPUrlEntry),
107102
widget.NewFormItem("API Key", u.expWPKeyEntry),
108-
widget.NewFormItem("Plugin Save Path", pluginPathContainer),
109103
),
110104
generatePluginBtn,
111105
)

ui/import.go

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -39,82 +39,82 @@ func (u *UI) createImportTab(w fyne.Window) fyne.CanvasObject {
3939
// --- Destination Server ---
4040
restoreLocalCheck := widget.NewCheck("Restore to Localhost?", nil)
4141

42-
connTypeSelect := widget.NewSelect([]string{string(models.ConnectionTypeSSH), string(models.ConnectionTypeWordPress)}, nil)
43-
connTypeSelect.SetSelected(string(models.ConnectionTypeSSH))
42+
u.impConnectionTypeSelect = widget.NewSelect([]string{string(models.ConnectionTypeSSH), string(models.ConnectionTypeWordPress)}, nil)
43+
u.impConnectionTypeSelect.SetSelected(string(models.ConnectionTypeSSH))
4444

4545
// SSH Fields
46-
hostEntry := widget.NewEntry()
47-
hostEntry.SetPlaceHolder("192.168.1.100")
48-
portEntry := widget.NewEntry()
49-
portEntry.SetText("22")
50-
sshUserEntry := widget.NewEntry()
51-
sshUserEntry.SetPlaceHolder("root")
46+
u.impHostEntry = widget.NewEntry()
47+
u.impHostEntry.SetPlaceHolder("192.168.1.100")
48+
u.impPortEntry = widget.NewEntry()
49+
u.impPortEntry.SetText("22")
50+
u.impSSHUserEntry = widget.NewEntry()
51+
u.impSSHUserEntry.SetPlaceHolder("root")
5252

53-
authTypeSelect := widget.NewSelect([]string{string(models.AuthTypePassword), string(models.AuthTypeKeyFile)}, nil)
54-
authTypeSelect.SetSelected(string(models.AuthTypePassword))
53+
u.impAuthTypeSelect = widget.NewSelect([]string{string(models.AuthTypePassword), string(models.AuthTypeKeyFile)}, nil)
54+
u.impAuthTypeSelect.SetSelected(string(models.AuthTypePassword))
5555

56-
sshPasswordEntry := widget.NewPasswordEntry()
57-
sshPasswordEntry.SetPlaceHolder("SSH Password")
56+
u.impSSHPassEntry = widget.NewPasswordEntry()
57+
u.impSSHPassEntry.SetPlaceHolder("SSH Password")
5858

59-
keyPathEntry := widget.NewEntry()
60-
keyPathEntry.SetPlaceHolder("/path/to/private/key")
59+
u.impKeyPathEntry = widget.NewEntry()
60+
u.impKeyPathEntry.SetPlaceHolder("/path/to/private/key")
6161
keyPathBtn := widget.NewButton("Select Key", func() {
6262
fd := dialog.NewFileOpen(func(reader fyne.URIReadCloser, err error) {
6363
if err == nil && reader != nil {
64-
keyPathEntry.SetText(reader.URI().Path())
64+
u.impKeyPathEntry.SetText(reader.URI().Path())
6565
}
6666
}, w)
6767
fd.Show()
6868
})
69-
keyAuthContainer := container.NewBorder(nil, nil, nil, keyPathBtn, keyPathEntry)
69+
keyAuthContainer := container.NewBorder(nil, nil, nil, keyPathBtn, u.impKeyPathEntry)
7070
keyAuthContainer.Hide()
7171

72-
authTypeSelect.OnChanged = func(s string) {
72+
u.impAuthTypeSelect.OnChanged = func(s string) {
7373
if s == string(models.AuthTypePassword) {
74-
sshPasswordEntry.Show()
74+
u.impSSHPassEntry.Show()
7575
keyAuthContainer.Hide()
7676
} else {
77-
sshPasswordEntry.Hide()
77+
u.impSSHPassEntry.Hide()
7878
keyAuthContainer.Show()
7979
}
8080
}
8181

8282
sshForm := widget.NewForm(
83-
widget.NewFormItem("Host", hostEntry),
84-
widget.NewFormItem("Port", portEntry),
85-
widget.NewFormItem("SSH User", sshUserEntry),
86-
widget.NewFormItem("Auth Type", authTypeSelect),
83+
widget.NewFormItem("Host", u.impHostEntry),
84+
widget.NewFormItem("Port", u.impPortEntry),
85+
widget.NewFormItem("SSH User", u.impSSHUserEntry),
86+
widget.NewFormItem("Auth Type", u.impAuthTypeSelect),
8787
)
88-
sshContainer := container.NewVBox(sshForm, sshPasswordEntry, keyAuthContainer)
88+
sshContainer := container.NewVBox(sshForm, u.impSSHPassEntry, keyAuthContainer)
8989

9090
// WP Fields
91-
wpUrlEntry := widget.NewEntry()
92-
wpUrlEntry.SetPlaceHolder("https://example.com")
93-
wpKeyEntry := widget.NewEntry()
94-
wpKeyEntry.SetPlaceHolder("API Key")
91+
u.impWPUrlEntry = widget.NewEntry()
92+
u.impWPUrlEntry.SetPlaceHolder("https://example.com")
93+
u.impWPKeyEntry = widget.NewEntry()
94+
u.impWPKeyEntry.SetPlaceHolder("API Key")
9595

9696
wpContainer := container.NewVBox(
9797
widget.NewForm(
98-
widget.NewFormItem("WordPress URL", wpUrlEntry),
99-
widget.NewFormItem("API Key", wpKeyEntry),
98+
widget.NewFormItem("WordPress URL", u.impWPUrlEntry),
99+
widget.NewFormItem("API Key", u.impWPKeyEntry),
100100
),
101101
)
102102
wpContainer.Hide()
103103

104104
// Toggle Logic
105105
restoreLocalCheck.OnChanged = func(b bool) {
106106
if b {
107-
connTypeSelect.Hide()
107+
u.impConnectionTypeSelect.Hide()
108108
sshContainer.Hide()
109109
wpContainer.Hide()
110110
} else {
111-
connTypeSelect.Show()
111+
u.impConnectionTypeSelect.Show()
112112
// Trigger conn type change
113-
connTypeSelect.OnChanged(connTypeSelect.Selected)
113+
u.impConnectionTypeSelect.OnChanged(u.impConnectionTypeSelect.Selected)
114114
}
115115
}
116116

117-
connTypeSelect.OnChanged = func(s string) {
117+
u.impConnectionTypeSelect.OnChanged = func(s string) {
118118
if restoreLocalCheck.Checked {
119119
return
120120
}
@@ -130,7 +130,7 @@ func (u *UI) createImportTab(w fyne.Window) fyne.CanvasObject {
130130

131131
// Test Server Connectivity (Import)
132132
testServerBtn := widget.NewButton("Test Connectivity", func() {
133-
connType := models.ConnectionType(connTypeSelect.Selected)
133+
connType := models.ConnectionType(u.impConnectionTypeSelect.Selected)
134134
if restoreLocalCheck.Checked {
135135
dialog.ShowInformation("Info", "Localhost selected. No connection test needed.", w)
136136
return
@@ -145,12 +145,12 @@ func (u *UI) createImportTab(w fyne.Window) fyne.CanvasObject {
145145
loading := u.showLoading("Testing Connection", "Connecting to server...")
146146
go func() {
147147
p := models.Profile{
148-
Host: strings.TrimSpace(hostEntry.Text),
149-
Port: strings.TrimSpace(portEntry.Text),
150-
SSHUser: strings.TrimSpace(sshUserEntry.Text),
151-
SSHPassword: strings.TrimSpace(sshPasswordEntry.Text),
152-
AuthType: models.AuthType(authTypeSelect.Selected),
153-
AuthKeyPath: strings.TrimSpace(keyPathEntry.Text),
148+
Host: strings.TrimSpace(u.impHostEntry.Text),
149+
Port: strings.TrimSpace(u.impPortEntry.Text),
150+
SSHUser: strings.TrimSpace(u.impSSHUserEntry.Text),
151+
SSHPassword: strings.TrimSpace(u.impSSHPassEntry.Text),
152+
AuthType: models.AuthType(u.impAuthTypeSelect.Selected),
153+
AuthKeyPath: strings.TrimSpace(u.impKeyPathEntry.Text),
154154
}
155155

156156
client, err := ssh.NewClient(p)
@@ -167,39 +167,39 @@ func (u *UI) createImportTab(w fyne.Window) fyne.CanvasObject {
167167

168168
serverGroup := widget.NewCard("Destination Server", "", container.NewVBox(
169169
restoreLocalCheck,
170-
widget.NewForm(widget.NewFormItem("Type", connTypeSelect)),
170+
widget.NewForm(widget.NewFormItem("Type", u.impConnectionTypeSelect)),
171171
sshContainer,
172172
wpContainer,
173173
widget.NewSeparator(),
174174
testServerBtn,
175175
))
176176

177177
// --- Destination Database ---
178-
isDockerCheck := widget.NewCheck("Is Docker Container?", nil)
179-
containerIDEntry := widget.NewEntry()
180-
containerIDEntry.SetPlaceHolder("mysql_container_name")
181-
containerIDEntry.Disable()
178+
u.impIsDockerCheck = widget.NewCheck("Is Docker Container?", nil)
179+
u.impContainerIDEntry = widget.NewEntry()
180+
u.impContainerIDEntry.SetPlaceHolder("mysql_container_name")
181+
u.impContainerIDEntry.Disable()
182182

183-
isDockerCheck.OnChanged = func(b bool) {
183+
u.impIsDockerCheck.OnChanged = func(b bool) {
184184
if b {
185-
containerIDEntry.Enable()
185+
u.impContainerIDEntry.Enable()
186186
} else {
187-
containerIDEntry.Disable()
187+
u.impContainerIDEntry.Disable()
188188
}
189189
}
190190

191-
dbTypeSelect := widget.NewSelect([]string{string(models.DBTypeMySQL), string(models.DBTypeMariaDB), string(models.DBTypePostgreSQL)}, nil)
192-
dbTypeSelect.SetSelected(string(models.DBTypeMySQL))
191+
u.impDBTypeSelect = widget.NewSelect([]string{string(models.DBTypeMySQL), string(models.DBTypeMariaDB), string(models.DBTypePostgreSQL)}, nil)
192+
u.impDBTypeSelect.SetSelected(string(models.DBTypeMySQL))
193193

194-
dbHostEntry := widget.NewEntry()
195-
dbHostEntry.SetText("127.0.0.1")
196-
dbPortEntry := widget.NewEntry()
197-
dbPortEntry.SetText("3306")
198-
dbUserEntry := widget.NewEntry()
199-
dbUserEntry.SetPlaceHolder("root")
200-
dbPasswordEntry := widget.NewPasswordEntry()
201-
targetDBEntry := widget.NewEntry()
202-
targetDBEntry.SetPlaceHolder("target_database")
194+
u.impDBHostEntry = widget.NewEntry()
195+
u.impDBHostEntry.SetText("127.0.0.1")
196+
u.impDBPortEntry = widget.NewEntry()
197+
u.impDBPortEntry.SetText("3306")
198+
u.impDBUserEntry = widget.NewEntry()
199+
u.impDBUserEntry.SetPlaceHolder("root")
200+
u.impDBPassEntry = widget.NewPasswordEntry()
201+
u.impTargetDBEntry = widget.NewEntry()
202+
u.impTargetDBEntry.SetPlaceHolder("target_database")
203203

204204
// Test DB Connectivity (Import)
205205
testDBBtn := widget.NewButton("Test DB Connectivity", func() {
@@ -215,19 +215,19 @@ func (u *UI) createImportTab(w fyne.Window) fyne.CanvasObject {
215215
loading := u.showLoading("Testing DB", "Connecting to Database...")
216216
go func() {
217217
p := models.Profile{
218-
Host: strings.TrimSpace(hostEntry.Text),
219-
Port: strings.TrimSpace(portEntry.Text),
220-
SSHUser: strings.TrimSpace(sshUserEntry.Text),
221-
SSHPassword: strings.TrimSpace(sshPasswordEntry.Text),
222-
AuthType: models.AuthType(authTypeSelect.Selected),
223-
AuthKeyPath: strings.TrimSpace(keyPathEntry.Text),
224-
DBHost: strings.TrimSpace(dbHostEntry.Text),
225-
DBPort: strings.TrimSpace(dbPortEntry.Text),
226-
DBUser: strings.TrimSpace(dbUserEntry.Text),
227-
DBPassword: strings.TrimSpace(dbPasswordEntry.Text),
228-
DBType: models.DBType(dbTypeSelect.Selected),
229-
IsDocker: isDockerCheck.Checked,
230-
ContainerID: strings.TrimSpace(containerIDEntry.Text),
218+
Host: strings.TrimSpace(u.impHostEntry.Text),
219+
Port: strings.TrimSpace(u.impPortEntry.Text),
220+
SSHUser: strings.TrimSpace(u.impSSHUserEntry.Text),
221+
SSHPassword: strings.TrimSpace(u.impSSHPassEntry.Text),
222+
AuthType: models.AuthType(u.impAuthTypeSelect.Selected),
223+
AuthKeyPath: strings.TrimSpace(u.impKeyPathEntry.Text),
224+
DBHost: strings.TrimSpace(u.impDBHostEntry.Text),
225+
DBPort: strings.TrimSpace(u.impDBPortEntry.Text),
226+
DBUser: strings.TrimSpace(u.impDBUserEntry.Text),
227+
DBPassword: strings.TrimSpace(u.impDBPassEntry.Text),
228+
DBType: models.DBType(u.impDBTypeSelect.Selected),
229+
IsDocker: u.impIsDockerCheck.Checked,
230+
ContainerID: strings.TrimSpace(u.impContainerIDEntry.Text),
231231
}
232232

233233
client, err := ssh.NewClient(p)
@@ -277,15 +277,15 @@ func (u *UI) createImportTab(w fyne.Window) fyne.CanvasObject {
277277
})
278278

279279
dbGroup := widget.NewCard("Destination Database", "", container.NewVBox(
280-
isDockerCheck,
280+
u.impIsDockerCheck,
281281
widget.NewForm(
282-
widget.NewFormItem("DB Type", dbTypeSelect),
283-
widget.NewFormItem("Container Name/ID", containerIDEntry),
284-
widget.NewFormItem("DB Host", dbHostEntry),
285-
widget.NewFormItem("DB Port", dbPortEntry),
286-
widget.NewFormItem("DB User", dbUserEntry),
287-
widget.NewFormItem("DB Password", dbPasswordEntry),
288-
widget.NewFormItem("Target DB Name", targetDBEntry),
282+
widget.NewFormItem("DB Type", u.impDBTypeSelect),
283+
widget.NewFormItem("Container Name/ID", u.impContainerIDEntry),
284+
widget.NewFormItem("DB Host", u.impDBHostEntry),
285+
widget.NewFormItem("DB Port", u.impDBPortEntry),
286+
widget.NewFormItem("DB User", u.impDBUserEntry),
287+
widget.NewFormItem("DB Password", u.impDBPassEntry),
288+
widget.NewFormItem("Target DB Name", u.impTargetDBEntry),
289289
),
290290
widget.NewSeparator(),
291291
testDBBtn,
@@ -301,13 +301,13 @@ func (u *UI) createImportTab(w fyne.Window) fyne.CanvasObject {
301301
return
302302
}
303303

304-
connType := models.ConnectionType(connTypeSelect.Selected)
304+
connType := models.ConnectionType(u.impConnectionTypeSelect.Selected)
305305
isLocal := restoreLocalCheck.Checked
306306

307307
if !isLocal && connType == models.ConnectionTypeWordPress {
308308
// WP Import
309-
wpUrl := wpUrlEntry.Text
310-
wpKey := wpKeyEntry.Text
309+
wpUrl := u.impWPUrlEntry.Text
310+
wpKey := u.impWPKeyEntry.Text
311311

312312
go func() {
313313
u.log("Import (WP)", "Starting import to WordPress", "", "In Progress", "")
@@ -345,20 +345,20 @@ func (u *UI) createImportTab(w fyne.Window) fyne.CanvasObject {
345345
}
346346

347347
p := models.Profile{
348-
Host: strings.TrimSpace(hostEntry.Text),
349-
Port: strings.TrimSpace(portEntry.Text),
350-
SSHUser: strings.TrimSpace(sshUserEntry.Text),
351-
SSHPassword: strings.TrimSpace(sshPasswordEntry.Text),
352-
AuthType: models.AuthType(authTypeSelect.Selected),
353-
AuthKeyPath: strings.TrimSpace(keyPathEntry.Text),
354-
DBHost: strings.TrimSpace(dbHostEntry.Text),
355-
DBPort: strings.TrimSpace(dbPortEntry.Text),
356-
DBUser: strings.TrimSpace(dbUserEntry.Text),
357-
DBPassword: strings.TrimSpace(dbPasswordEntry.Text),
358-
DBType: models.DBType(dbTypeSelect.Selected),
359-
IsDocker: isDockerCheck.Checked,
360-
ContainerID: strings.TrimSpace(containerIDEntry.Text),
361-
TargetDBName: strings.TrimSpace(targetDBEntry.Text),
348+
Host: strings.TrimSpace(u.impHostEntry.Text),
349+
Port: strings.TrimSpace(u.impPortEntry.Text),
350+
SSHUser: strings.TrimSpace(u.impSSHUserEntry.Text),
351+
SSHPassword: strings.TrimSpace(u.impSSHPassEntry.Text),
352+
AuthType: models.AuthType(u.impAuthTypeSelect.Selected),
353+
AuthKeyPath: strings.TrimSpace(u.impKeyPathEntry.Text),
354+
DBHost: strings.TrimSpace(u.impDBHostEntry.Text),
355+
DBPort: strings.TrimSpace(u.impDBPortEntry.Text),
356+
DBUser: strings.TrimSpace(u.impDBUserEntry.Text),
357+
DBPassword: strings.TrimSpace(u.impDBPassEntry.Text),
358+
DBType: models.DBType(u.impDBTypeSelect.Selected),
359+
IsDocker: u.impIsDockerCheck.Checked,
360+
ContainerID: strings.TrimSpace(u.impContainerIDEntry.Text),
361+
TargetDBName: strings.TrimSpace(u.impTargetDBEntry.Text),
362362
}
363363

364364
go func() {

0 commit comments

Comments
 (0)