Skip to content

Commit 4608189

Browse files
committed
webui: configure toolbar — add Apply & Save button
Copies candidate → running then running → startup in one step, so users can commit changes to the running configuration and persist them across reboots without two separate button clicks. The existing Apply button confirm text is updated to remind the user that changes will be lost on reboot unless saved. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent faca79f commit 4608189

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/webui/internal/handlers/configure.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,20 @@ func (h *ConfigureHandler) Abort(w http.ResponseWriter, r *http.Request) {
4848
w.Header().Set("HX-Redirect", "/")
4949
w.WriteHeader(http.StatusNoContent)
5050
}
51+
52+
// ApplyAndSave copies candidate → running then running → startup in one step.
53+
// POST /configure/apply-and-save
54+
func (h *ConfigureHandler) ApplyAndSave(w http.ResponseWriter, r *http.Request) {
55+
if err := h.RC.CopyDatastore(r.Context(), "candidate", "running"); err != nil {
56+
log.Printf("configure apply-and-save: %v", err)
57+
http.Error(w, "Could not apply configuration: "+err.Error(), http.StatusBadGateway)
58+
return
59+
}
60+
if err := h.RC.CopyDatastore(r.Context(), "running", "startup"); err != nil {
61+
log.Printf("configure apply-and-save (save): %v", err)
62+
http.Error(w, "Could not save configuration: "+err.Error(), http.StatusBadGateway)
63+
return
64+
}
65+
w.Header().Set("HX-Redirect", "/")
66+
w.WriteHeader(http.StatusNoContent)
67+
}

src/webui/internal/server/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func New(
187187
// Configure routes.
188188
mux.HandleFunc("POST /configure/enter", cfg.Enter)
189189
mux.HandleFunc("POST /configure/apply", cfg.Apply)
190+
mux.HandleFunc("POST /configure/apply-and-save", cfg.ApplyAndSave)
190191
mux.HandleFunc("POST /configure/abort", cfg.Abort)
191192
mux.HandleFunc("GET /configure/system", cfgSys.Overview)
192193
mux.HandleFunc("POST /configure/system/identity", cfgSys.SaveIdentity)

src/webui/static/css/style.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,13 @@ details.fw-hint[open] summary::before { transform: rotate(90deg); }
19921992
}
19931993
.btn-danger-outline:hover { background: rgba(220, 38, 38, 0.08); }
19941994

1995+
.btn-accept {
1996+
background: var(--success);
1997+
color: #fff;
1998+
border: 1px solid transparent;
1999+
}
2000+
.btn-accept:hover { background: var(--green-600); }
2001+
19952002
/* ─── Configure toolbar ───────────────────────────────────────────────────── */
19962003
.configure-toolbar {
19972004
position: fixed;

src/webui/templates/fragments/configure-toolbar.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
<button type="button" class="btn btn-primary cfg-apply-btn"
55
hx-post="/configure/apply"
66
hx-swap="none"
7-
hx-confirm="Apply all staged changes to the running configuration?">
7+
hx-confirm="Apply staged changes to running configuration? Changes will be lost on reboot unless saved.">
88
Apply
99
</button>
10+
<button type="button" class="btn btn-accept cfg-apply-save-btn"
11+
hx-post="/configure/apply-and-save"
12+
hx-swap="none"
13+
hx-confirm="Apply staged changes and save to startup configuration?">
14+
Apply &amp; Save
15+
</button>
1016
<button type="button" class="btn btn-danger-outline cfg-abort-btn"
1117
hx-post="/configure/abort"
1218
hx-swap="none"

0 commit comments

Comments
 (0)