Merge remote-tracking branch 'origin/main' into LPM-48

This commit is contained in:
Robin Olsen
2026-03-08 10:58:24 +01:00
31 changed files with 527 additions and 228 deletions

View File

@@ -2,6 +2,7 @@ package handler
import (
"context"
"html"
"net/http"
"strings"
@@ -250,6 +251,49 @@ func DeleteIssue(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
}
func CloseIssue(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
issueVal := r.Context().Value(issueKey)
issue, ok := issueVal.(*models.Issue)
if !ok || issue == nil {
http.Error(w, "Issue not found in context", http.StatusInternalServerError)
return
}
closeReason := r.FormValue("close_reason")
if closeReason == "" {
if HTMX(r).IsHxRequest() {
w.WriteHeader(http.StatusBadRequest)
HTMX(r).WriteString("<div class=\"alert alert-error\">Closing reason is required</div>")
} else {
http.Error(w, "Closing reason is required", http.StatusBadRequest)
}
return
}
if err := App(r).Issues.CloseIssue(r.Context(), issue.ID, closeReason, "web", ""); err != nil {
if HTMX(r).IsHxRequest() {
w.WriteHeader(http.StatusInternalServerError)
HTMX(r).WriteString("<div class=\"alert alert-error\">Failed to close issue: " + html.EscapeString(err.Error()) + "</div>")
} else {
http.Error(w, "Failed to close issue: "+err.Error(), http.StatusInternalServerError)
}
return
}
if HTMX(r).IsHxRequest() {
w.Header().Set("HX-Refresh", "true")
return
}
w.WriteHeader(http.StatusNoContent)
}
func (f *IssueForm) toIssue() *models.Issue {
return &models.Issue{
Title: f.Title,

View File

@@ -36,9 +36,9 @@ func CreateIssueFormModal(w http.ResponseWriter, r *http.Request) {
}
func EditIssueFormModal(w http.ResponseWriter, r *http.Request) {
issue := r.Context().Value(issueKey).(*models.Issue)
if issue == nil {
issueVal := r.Context().Value(issueKey)
issue, ok := issueVal.(*models.Issue)
if !ok || issue == nil {
http.Error(w, "Issue not found in context", http.StatusInternalServerError)
return
}
@@ -76,9 +76,9 @@ func EditIssueFormModal(w http.ResponseWriter, r *http.Request) {
}
func AssigneeFormModal(w http.ResponseWriter, r *http.Request) {
issue := r.Context().Value(issueKey).(*models.Issue)
if issue == nil {
issueVal := r.Context().Value(issueKey)
issue, ok := issueVal.(*models.Issue)
if !ok || issue == nil {
http.Error(w, "Issue not found in context", http.StatusInternalServerError)
return
}
@@ -126,3 +126,29 @@ func DeleteIssueConfirmModal(w http.ResponseWriter, r *http.Request) {
confirmModal.Render(r.Context(), w)
}
func CloseIssueFormModal(w http.ResponseWriter, r *http.Request) {
issueVal := r.Context().Value(issueKey)
issue, ok := issueVal.(*models.Issue)
if !ok || issue == nil {
http.Error(w, "Issue not found in context", http.StatusInternalServerError)
return
}
if issue.Status == models.StatusClosed {
http.Error(w, "Issue is already closed", http.StatusBadRequest)
return
}
modalContent := components.CloseIssueForm(components.CloseIssueFormProps{
PostAction: "/issues/" + issue.ID + "/close",
})
modal := components.Modal(components.ModalProps{
ID: "close-issue-modal",
Title: "Close Issue",
Content: modalContent,
Open: true,
})
modal.Render(r.Context(), w)
}