Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
82 lines
2.3 KiB
Go
82 lines
2.3 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"sort"
|
|
"time"
|
|
|
|
cal "pageswiki/internal/calendar"
|
|
"pageswiki/internal/store"
|
|
)
|
|
|
|
func (s *Server) handleTaskToday(w http.ResponseWriter, r *http.Request, actor string) {
|
|
if r.Method != "GET" {
|
|
w.WriteHeader(405)
|
|
return
|
|
}
|
|
domain := s.domainUUIDForRequest(r)
|
|
now := time.Now()
|
|
loc := s.getLocation(domain)
|
|
local := now.In(loc)
|
|
start := time.Date(local.Year(), local.Month(), local.Day(), 0, 0, 0, 0, loc)
|
|
end := start.AddDate(0, 0, 1)
|
|
summary, err := s.store.TaskDaySummary(r.Context(), domain, actor, start, end, now)
|
|
if err != nil {
|
|
taskError(w, err)
|
|
return
|
|
}
|
|
blocks := []store.TaskDayBlock{}
|
|
partial, unavailable := false, 0
|
|
enabled := s.systemExtensionEnabled(domain, "organizer.calendar")
|
|
if enabled {
|
|
ids, more, err := s.store.TaskBlockCalendars(r.Context(), domain, actor)
|
|
if err != nil {
|
|
taskError(w, err)
|
|
return
|
|
}
|
|
partial = more
|
|
repo, err := s.calendars()
|
|
if err != nil {
|
|
taskError(w, err)
|
|
return
|
|
}
|
|
for _, id := range ids {
|
|
err = repo.ReadPersonalLocalIndex(r.Context(), domain, id, actor, func(c cal.Calendar) error {
|
|
items, more, e := s.store.TaskDayBlocks(r.Context(), domain, actor, id, start, end)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
partial = partial || more
|
|
for _, b := range items {
|
|
b.Href = "/v/plan/event/" + url.PathEscape(b.EventUID) + "?calendar=" + url.QueryEscape(c.PrettyName)
|
|
blocks = append(blocks, b)
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
unavailable++
|
|
}
|
|
}
|
|
}
|
|
sort.Slice(blocks, func(i, j int) bool {
|
|
if blocks[i].Start == blocks[j].Start {
|
|
return blocks[i].UUID < blocks[j].UUID
|
|
}
|
|
return blocks[i].Start < blocks[j].Start
|
|
})
|
|
if len(blocks) > 100 {
|
|
blocks = blocks[:100]
|
|
partial = true
|
|
}
|
|
var allocated, busy int64
|
|
var lastEnd int64
|
|
for _, b := range blocks {
|
|
a, z := max(b.Start, start.UnixMilli()), min(b.End, end.UnixMilli())
|
|
allocated += max(int64(0), z-a)
|
|
busy += max(int64(0), z-max(a, lastEnd))
|
|
lastEnd = max(lastEnd, z)
|
|
}
|
|
writeEventJSON(w, 200, map[string]any{"date": start.Format("2006-01-02"), "timezone": loc.String(), "summary": summary, "blocks": blocks, "allocated_ms": allocated, "occupied_ms": busy, "overlap_ms": allocated - busy, "blocks_partial": partial, "unavailable_calendars": unavailable, "calendar_enabled": enabled})
|
|
}
|