lots of changes and reducing dependency imports
This commit is contained in:
@@ -68,7 +68,7 @@ func ListIssues(w http.ResponseWriter, r *http.Request) {
|
||||
app := App(r)
|
||||
hx := HTMX(r)
|
||||
|
||||
issues, err := app.Issues.AllIssues(r.Context())
|
||||
issues, err := app.Issues.SearchIssues(r.Context(), "", models.IssueFilter{})
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to retrieve issues", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -1,29 +1,55 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/components"
|
||||
"github.com/a-h/templ"
|
||||
"github.com/donseba/go-htmx"
|
||||
)
|
||||
|
||||
var taskFeedback task.ValidationFeedback
|
||||
type ValidationFeedback = models.ValidationFeedback
|
||||
|
||||
func SetTaskFeedback(feedback task.ValidationFeedback) {
|
||||
var taskFeedback ValidationFeedback
|
||||
|
||||
func SetTaskFeedback(feedback 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>")
|
||||
}
|
||||
hx.WriteString(`<a hx-get="/status/modal" hx-target="#modal-container" hx-swap="innerHTML">` + taskFeedback.Message + `</a>`)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
hx.WriteJSON(taskFeedback)
|
||||
}
|
||||
|
||||
func HandleTaskStatusModal(w http.ResponseWriter, r *http.Request) {
|
||||
err := components.Modal(components.ModalProps{
|
||||
ID: "task-status-modal",
|
||||
Title: "Task Status",
|
||||
Content: feedbackList(HTMX(r), taskFeedback),
|
||||
Open: true,
|
||||
}).Render(r.Context(), w)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func feedbackList(hx *htmx.Handler, feedback ValidationFeedback) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) error {
|
||||
for _, check := range feedback.Checks {
|
||||
if !check.Valid {
|
||||
hx.WriteString(`<p class="my-2 text-red-500">` + check.Message + `</p>`)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ func (s *Server) RegisterRoutes(assets embed.FS) http.Handler {
|
||||
|
||||
r.Get("/", handler.DashboardHandler)
|
||||
r.Get("/status", handler.HandleTaskStatus)
|
||||
r.Get("/status/modal", handler.HandleTaskStatusModal)
|
||||
|
||||
r.Route("/issues", func(r chi.Router) {
|
||||
r.Get("/", handler.ListIssues)
|
||||
|
||||
@@ -9,17 +9,18 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/internal/utils"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/handler"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/server"
|
||||
)
|
||||
|
||||
type Config = service.Config
|
||||
type Config = models.Config
|
||||
type ValidationFeedback = models.ValidationFeedback
|
||||
|
||||
type Web struct {
|
||||
feedbackChan chan task.ValidationFeedback
|
||||
feedbackChan chan ValidationFeedback
|
||||
quitChan chan bool
|
||||
}
|
||||
|
||||
@@ -31,7 +32,7 @@ func NewWeb() *Web {
|
||||
var assets embed.FS
|
||||
|
||||
func (w *Web) Run(ctx context.Context, config Config) error {
|
||||
app, cleanup, err := service.NewServices(ctx, config)
|
||||
app, cleanup, err := service.NewApp(ctx, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -84,7 +85,7 @@ func (w *Web) Run(ctx context.Context, config Config) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Web) SetChannels(feedbackChan chan task.ValidationFeedback, quitChan chan bool) {
|
||||
func (w *Web) SetChannels(feedbackChan chan ValidationFeedback, quitChan chan bool) {
|
||||
w.feedbackChan = feedbackChan
|
||||
w.quitChan = quitChan
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user