diff --git a/internal/handlers/connections.go b/internal/handlers/connections.go index 2c8dd09..f1e55a4 100644 --- a/internal/handlers/connections.go +++ b/internal/handlers/connections.go @@ -144,7 +144,7 @@ func (h *Handlers) ConnectionCreate(w http.ResponseWriter, r *http.Request) { if err := h.Store.ConnectionCreate(conn); err != nil { if returnPortID != "" { - h.renderConnectionModal(w, returnPortID) + h.renderConnectionModalError(w, returnPortID, err.Error()) return } h.redirect(w, r, "/") @@ -159,6 +159,14 @@ func (h *Handlers) ConnectionCreate(w http.ResponseWriter, r *http.Request) { } func (h *Handlers) renderConnectionModal(w http.ResponseWriter, returnPortID string) { + h.renderConnectionModalWithError(w, returnPortID, "") +} + +func (h *Handlers) renderConnectionModalError(w http.ResponseWriter, returnPortID string, errMsg string) { + h.renderConnectionModalWithError(w, returnPortID, errMsg) +} + +func (h *Handlers) renderConnectionModalWithError(w http.ResponseWriter, returnPortID string, errMsg string) { portID, err := strconv.ParseInt(returnPortID, 10, 64) if err != nil { http.Error(w, "invalid port id", http.StatusBadRequest) @@ -180,6 +188,7 @@ func (h *Handlers) renderConnectionModal(w http.ResponseWriter, returnPortID str Trace *services.TraceResult ConnectionTypes []models.ConnectionType PortGroups []PortGroup + Error string } allDevices, _ := h.Store.DeviceGetAllUnracked() @@ -225,13 +234,24 @@ func (h *Handlers) renderConnectionModal(w http.ResponseWriter, returnPortID str var groups []PortGroup for _, id := range groupOrder { - groups = append(groups, *groupMap[id]) + grp := *groupMap[id] + filtered := grp.Ports[:0] + for _, fp := range grp.Ports { + if fp.ID != portID { + filtered = append(filtered, fp) + } + } + if len(filtered) > 0 { + grp.Ports = filtered + groups = append(groups, grp) + } } h.render(w, "connection_modal.html", ConnectionModalData{ Trace: trace, ConnectionTypes: connTypes, PortGroups: groups, + Error: errMsg, }) } diff --git a/templates/connection_modal.html b/templates/connection_modal.html index d8a4d45..d564a31 100644 --- a/templates/connection_modal.html +++ b/templates/connection_modal.html @@ -1,10 +1,9 @@