diff --git a/cmd/tracks/main.go b/cmd/tracks/main.go index 9d7d3d53..60780b55 100644 --- a/cmd/tracks/main.go +++ b/cmd/tracks/main.go @@ -103,6 +103,9 @@ func setupRoutes(router *gin.Engine, cfg *config.Config) { { webProtected.GET("/", webHandler.ShowDashboard) webProtected.GET("/dashboard", webHandler.ShowDashboard) + webProtected.GET("/todos", webHandler.ShowTodos) + webProtected.GET("/projects", webHandler.ShowProjects) + webProtected.GET("/contexts", webHandler.ShowContexts) // Admin web routes webAdmin := webProtected.Group("/admin") diff --git a/cmd/tracks/web/templates/contexts.html b/cmd/tracks/web/templates/contexts.html new file mode 100644 index 00000000..a50328a4 --- /dev/null +++ b/cmd/tracks/web/templates/contexts.html @@ -0,0 +1,83 @@ +{{define "content"}} + + + + +{{if .Contexts}} +
+ {{range .Contexts}} +
+
{{.Name}}
+ {{.State}} +
+ {{end}} +
+{{else}} +
+
+
🏷️
+

No contexts yet. Create contexts to categorize where or how you'll complete todos!

+
+
+{{end}} +{{end}} diff --git a/cmd/tracks/web/templates/projects.html b/cmd/tracks/web/templates/projects.html new file mode 100644 index 00000000..ce6b7d7a --- /dev/null +++ b/cmd/tracks/web/templates/projects.html @@ -0,0 +1,109 @@ +{{define "content"}} + + + + +{{if .Projects}} +
+ {{range .Projects}} +
+
+
{{.Name}}
+ {{.State}} +
+ {{if .Description}} +
{{.Description}}
+ {{end}} +
+ 📝 Todos + Created: {{.CreatedAt.Format "2006-01-02"}} +
+
+ {{end}} +
+{{else}} +
+
+
📁
+

No projects yet. Create your first one to organize your todos!

+
+
+{{end}} +{{end}} diff --git a/cmd/tracks/web/templates/todos.html b/cmd/tracks/web/templates/todos.html new file mode 100644 index 00000000..174a3f8f --- /dev/null +++ b/cmd/tracks/web/templates/todos.html @@ -0,0 +1,120 @@ +{{define "content"}} + + + + +
+ {{if .Todos}} +
+ {{range .Todos}} +
+
+
+ {{.State}} + {{.Description}} +
+
+ {{if .Context}}📁 {{.Context.Name}}{{end}} + {{if .Project}} • 🗂️ {{.Project.Name}}{{end}} + {{if .DueDate}} • 📅 Due: {{.DueDate.Format "2006-01-02"}}{{end}} +
+
+
+ {{if eq .State "active"}} + + {{end}} + +
+
+ {{end}} +
+ {{else}} +
+
📭
+

No todos yet. Create your first one to get started!

+
+ {{end}} +
+{{end}} diff --git a/internal/handlers/web_handler.go b/internal/handlers/web_handler.go index ee2daed3..f5719cb7 100644 --- a/internal/handlers/web_handler.go +++ b/internal/handlers/web_handler.go @@ -183,3 +183,68 @@ func (h *WebHandler) HandleCreateUser(c *gin.Context) { // Redirect back to users page with success message c.Redirect(http.StatusFound, "/admin/users?success=User created successfully") } + +// ShowTodos displays the todos page +func (h *WebHandler) ShowTodos(c *gin.Context) { + user, _ := middleware.GetCurrentUser(c) + + // Get user's todos + var todos []models.Todo + database.DB. + Preload("Context"). + Preload("Project"). + Where("user_id = ?", user.ID). + Order("created_at DESC"). + Find(&todos) + + data := gin.H{ + "Title": "Todos", + "User": user, + "Todos": todos, + } + + c.Header("Content-Type", "text/html; charset=utf-8") + h.templates.ExecuteTemplate(c.Writer, "base.html", data) +} + +// ShowProjects displays the projects page +func (h *WebHandler) ShowProjects(c *gin.Context) { + user, _ := middleware.GetCurrentUser(c) + + // Get user's projects + var projects []models.Project + database.DB. + Where("user_id = ?", user.ID). + Order("created_at DESC"). + Find(&projects) + + data := gin.H{ + "Title": "Projects", + "User": user, + "Projects": projects, + } + + c.Header("Content-Type", "text/html; charset=utf-8") + h.templates.ExecuteTemplate(c.Writer, "base.html", data) +} + +// ShowContexts displays the contexts page +func (h *WebHandler) ShowContexts(c *gin.Context) { + user, _ := middleware.GetCurrentUser(c) + + // Get user's contexts + var contexts []models.Context + database.DB. + Where("user_id = ?", user.ID). + Order("position ASC"). + Find(&contexts) + + data := gin.H{ + "Title": "Contexts", + "User": user, + "Contexts": contexts, + } + + c.Header("Content-Type", "text/html; charset=utf-8") + h.templates.ExecuteTemplate(c.Writer, "base.html", data) +}