fix(master): keep the scroll position when toggling auto mode on the overview (#34)
Docker Build / docker (push) Successful in 42s
Docker Build / docker (push) Successful in 42s
This commit was merged in pull request #34.
This commit is contained in:
@@ -628,6 +628,10 @@ func (s *Server) setMode(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
var nu *model.NotUpdatableError
|
||||
if err := s.jobs.AutoAllowed(svc); errors.As(err, &nu) {
|
||||
if isHTMX(r) {
|
||||
// htmx does not swap a 409; the service page shows the reason.
|
||||
w.Header().Set("HX-Redirect", "/services/"+strconv.FormatInt(id, 10))
|
||||
}
|
||||
s.renderServiceError(w, r, id, http.StatusConflict, "Cannot enable auto: "+nu.Reason+".")
|
||||
return
|
||||
} else if err != nil {
|
||||
@@ -641,6 +645,11 @@ func (s *Server) setMode(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
s.broker.Publish(events.Services)
|
||||
if r.PostFormValue("return") == "overview" {
|
||||
if isHTMX(r) {
|
||||
// Swap the list in place instead of redirecting, so the page keeps its scroll position.
|
||||
s.servicesFragment(w, r)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
@@ -881,6 +890,11 @@ func (s *Server) fail(w http.ResponseWriter, err error) {
|
||||
http.Error(w, "internal error", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// isHTMX reports whether r was sent by htmx rather than by a plain form submit.
|
||||
func isHTMX(r *http.Request) bool {
|
||||
return r.Header.Get("HX-Request") == "true"
|
||||
}
|
||||
|
||||
// agentSnippet is the compose file shown once when an agent is added.
|
||||
func agentSnippet(cfg Config, token string) string {
|
||||
return fmt.Sprintf(`services:
|
||||
|
||||
Reference in New Issue
Block a user