modified: web/assets/css/styles.css
modified: web/components/base/input.templ modified: web/components/base/input_templ.go modified: web/components/base/range.templ modified: web/components/base/range_templ.go modified: web/components/base/select.templ modified: web/components/base/select_templ.go modified: web/components/base/textarea.templ modified: web/components/base/textarea_templ.go modified: web/components/icons.templ modified: web/components/icons_templ.go modified: web/components/issue.templ modified: web/components/issue_templ.go modified: web/components/layout.templ modified: web/components/layout_templ.go new file: web/components/sidebar.templ new file: web/components/sidebar_templ.go new file: web/components/status.templ new file: web/components/status_templ.go modified: web/handler/issues.go new file: web/handler/task.go modified: web/input.css deleted: web/package-lock.json deleted: web/package.json modified: web/routes/layout.templ modified: web/routes/layout_templ.go modified: web/server/routes.go modified: web/server/server.go modified: web/web.go
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
const issueKey = "issue"
|
||||
|
||||
type IssueForm struct {
|
||||
Title string `form:"title" validate:"required,max=255"`
|
||||
Description string `form:"description" validate:"required,max=2000"`
|
||||
@@ -16,14 +18,12 @@ type IssueForm struct {
|
||||
Priority int `form:"priority" validate:"gte=0,lte=4"`
|
||||
}
|
||||
|
||||
func (f *IssueForm) ToIssue() models.Issue {
|
||||
return models.Issue{
|
||||
Title: f.Title,
|
||||
Description: f.Description,
|
||||
Status: f.Status,
|
||||
IssueType: f.IssueType,
|
||||
Priority: f.Priority,
|
||||
}
|
||||
type UpdateIssueForm struct {
|
||||
Title *string `form:"title" validate:"omitempty,max=255"`
|
||||
Description *string `form:"description" validate:"omitempty,max=2000"`
|
||||
Status *models.Status `form:"status" validate:"omitempty,oneof=open in_progress closed"`
|
||||
IssueType *models.IssueType `form:"issue_type" validate:"omitempty,oneof=task bug feature chore"`
|
||||
Priority *int `form:"priority" validate:"omitempty,gte=0,lte=4"`
|
||||
}
|
||||
|
||||
func CreateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -37,16 +37,15 @@ func CreateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err := ValidateForm(form); err != nil {
|
||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||
if hx.IsHxRequest() {
|
||||
hx.WriteString("<div class='alert alert-error'>Please fix the form errors</div>")
|
||||
hx.WriteString("<div>Please fix the form errors</div>")
|
||||
} else {
|
||||
hx.WriteJSON(map[string]interface{}{"error": err.Error()})
|
||||
http.Error(w, "Validation error: "+err.Error(), http.StatusUnprocessableEntity)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
issue := form.ToIssue()
|
||||
issue := form.toIssue()
|
||||
if err := svc.Beads.CreateIssue(r.Context(), &issue, ""); err != nil {
|
||||
http.Error(w, "Failed to create issue: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -57,10 +56,8 @@ func CreateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
hx.WriteJSON(map[string]any{
|
||||
"title": issue.Title,
|
||||
"status": issue.Status,
|
||||
})
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
hx.WriteJSON(issue)
|
||||
}
|
||||
|
||||
func ListIssues(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -73,6 +70,7 @@ func ListIssues(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
hx.WriteJSON(issues)
|
||||
}
|
||||
|
||||
@@ -83,46 +81,66 @@ func IssueCtx(next http.Handler) http.Handler {
|
||||
id := chi.URLParam(r, "id")
|
||||
issue, err := svc.Beads.GetIssue(r.Context(), id)
|
||||
if err != nil {
|
||||
http.Error(w, "Error getting issue: "+err.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if issue == nil {
|
||||
http.Error(w, "Issue not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "issue", issue)
|
||||
ctx := context.WithValue(r.Context(), issueKey, issue)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func GetIssue(w http.ResponseWriter, r *http.Request) {
|
||||
issue := r.Context().Value("issue").(*models.Issue)
|
||||
issue := r.Context().Value(issueKey).(*models.Issue)
|
||||
hx := HTMX(r)
|
||||
|
||||
hx.WriteJSON(issue)
|
||||
}
|
||||
|
||||
func UpdateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
issue := r.Context().Value("issue").(*models.Issue)
|
||||
issue := r.Context().Value(issueKey).(*models.Issue)
|
||||
svc := Services(r)
|
||||
hx := HTMX(r)
|
||||
|
||||
changes := make(map[string]any)
|
||||
form, err := ParseForm[UpdateIssueForm](r)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to parse form", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := ValidateForm(form); err != nil {
|
||||
if hx.IsHxRequest() {
|
||||
hx.WriteString("<div>Please fix the form errors</div>")
|
||||
} else {
|
||||
http.Error(w, "Validation error: "+err.Error(), http.StatusUnprocessableEntity)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
changes := form.toChanges()
|
||||
|
||||
if err := svc.Beads.UpdateIssue(r.Context(), issue.ID, changes, ""); err != nil {
|
||||
http.Error(w, "Failed to update issue", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
issue, err := svc.Beads.GetIssue(r.Context(), issue.ID)
|
||||
issue, err = svc.Beads.GetIssue(r.Context(), issue.ID)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to retrieve updated issue", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
hx.WriteJSON(issue)
|
||||
}
|
||||
|
||||
func DeleteIssue(w http.ResponseWriter, r *http.Request) {
|
||||
issue := r.Context().Value("issue").(*models.Issue)
|
||||
issue := r.Context().Value(issueKey).(*models.Issue)
|
||||
|
||||
svc := Services(r)
|
||||
if err := svc.Beads.DeleteIssue(r.Context(), issue.ID); err != nil {
|
||||
@@ -130,5 +148,36 @@ func DeleteIssue(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (f *IssueForm) toIssue() models.Issue {
|
||||
return models.Issue{
|
||||
Title: f.Title,
|
||||
Description: f.Description,
|
||||
Status: f.Status,
|
||||
IssueType: f.IssueType,
|
||||
Priority: f.Priority,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *UpdateIssueForm) toChanges() map[string]any {
|
||||
changes := make(map[string]any)
|
||||
if f.Title != nil {
|
||||
changes["title"] = *f.Title
|
||||
}
|
||||
if f.Description != nil {
|
||||
changes["description"] = *f.Description
|
||||
}
|
||||
if f.Status != nil {
|
||||
changes["status"] = *f.Status
|
||||
}
|
||||
if f.IssueType != nil {
|
||||
changes["issue_type"] = *f.IssueType
|
||||
}
|
||||
if f.Priority != nil {
|
||||
changes["priority"] = *f.Priority
|
||||
}
|
||||
return changes
|
||||
}
|
||||
|
||||
29
pkg/web/handler/task.go
Normal file
29
pkg/web/handler/task.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
)
|
||||
|
||||
var taskFeedback task.ValidationFeedback
|
||||
|
||||
func SetTaskFeedback(feedback task.ValidationFeedback) {
|
||||
taskFeedback = feedback
|
||||
}
|
||||
|
||||
func HandleTaskStatus(w http.ResponseWriter, r *http.Request) {
|
||||
hx := HTMX(r)
|
||||
|
||||
if hx.IsHxRequest() {
|
||||
if taskFeedback.Success {
|
||||
hx.WriteString("<div>Task completed successfully!</div>")
|
||||
} else {
|
||||
hx.WriteString("<div>" + taskFeedback.Message + "</div>")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
hx.WriteJSON(taskFeedback)
|
||||
}
|
||||
Reference in New Issue
Block a user