TASK BACKLOG REFINEMENT ISSUE
This commit is contained in:
@@ -213,6 +213,41 @@ 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
|
||||
}
|
||||
|
||||
issue := r.Context().Value(issueKey).(*models.Issue)
|
||||
closeReason := r.FormValue("close_reason")
|
||||
|
||||
if closeReason == "" {
|
||||
if HTMX(r).IsHxRequest() {
|
||||
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() {
|
||||
HTMX(r).WriteString("<div class=\"alert alert-error\">Failed to close issue: " + 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,
|
||||
|
||||
@@ -72,3 +72,29 @@ func AssigneeFormModal(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
modal.Render(r.Context(), w)
|
||||
}
|
||||
|
||||
func CloseIssueFormModal(w http.ResponseWriter, r *http.Request) {
|
||||
issue := r.Context().Value(issueKey).(*models.Issue)
|
||||
|
||||
if 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user