summaryrefslogtreecommitdiff
path: root/internal/handlers/widget.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers/widget.go')
-rw-r--r--internal/handlers/widget.go37
1 files changed, 28 insertions, 9 deletions
diff --git a/internal/handlers/widget.go b/internal/handlers/widget.go
index 5e515c3..5880314 100644
--- a/internal/handlers/widget.go
+++ b/internal/handlers/widget.go
@@ -612,15 +612,17 @@ func (h *Handler) HandleWidgetLabelsColorSet(w http.ResponseWriter, r *http.Requ
}
type taskDetailResponse struct {
- ID string `json:"id"`
- Title string `json:"title"`
- Description string `json:"description"`
- DueDate *time.Time `json:"due_date,omitempty"`
- Completed bool `json:"completed"`
- Recurrence *recurrenceResponse `json:"recurrence,omitempty"`
- NextDate *time.Time `json:"next_date,omitempty"`
- Project *projectResponse `json:"project,omitempty"`
- Labels []string `json:"labels,omitempty"`
+ ID string `json:"id"`
+ Title string `json:"title"`
+ Description string `json:"description"`
+ DueDate *time.Time `json:"due_date,omitempty"`
+ Completed bool `json:"completed"`
+ Recurrence *recurrenceResponse `json:"recurrence,omitempty"`
+ NextDate *time.Time `json:"next_date,omitempty"`
+ Project *projectResponse `json:"project,omitempty"`
+ Labels []string `json:"labels,omitempty"`
+ EstimatedMinutes int `json:"estimated_minutes,omitempty"`
+ SuggestedEstimateMinutes *int `json:"suggested_estimate_minutes,omitempty"`
}
// HandleWidgetTaskDetail returns full detail for a single doot-native task,
@@ -670,6 +672,23 @@ func (h *Handler) HandleWidgetTaskDetail(w http.ResponseWriter, r *http.Request)
}
}
+ resp.EstimatedMinutes = task.EstimatedMinutes
+ if task.EstimatedMinutes == 0 {
+ if task.ProjectID != "" {
+ if avg, ok, err := h.store.AverageEstimateForProject(task.ProjectID); err == nil && ok {
+ resp.SuggestedEstimateMinutes = &avg
+ }
+ }
+ if resp.SuggestedEstimateMinutes == nil {
+ for _, label := range task.Labels {
+ if avg, ok, err := h.store.AverageEstimateForLabel(label); err == nil && ok {
+ resp.SuggestedEstimateMinutes = &avg
+ break
+ }
+ }
+ }
+ }
+
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(resp)
}