feat(web): add calendar event detail view
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"git.arnef.de/arnef/nidus/internal/birthdays"
|
||||
"git.arnef.de/arnef/nidus/internal/db"
|
||||
"git.arnef.de/arnef/nidus/internal/icalfix"
|
||||
"git.arnef.de/arnef/nidus/internal/store"
|
||||
"git.arnef.de/arnef/nidus/internal/web/templates"
|
||||
ical "github.com/emersion/go-ical"
|
||||
)
|
||||
@@ -636,6 +637,70 @@ func newEventFormDefaults(calRef, dateParam string) templates.EventFormData {
|
||||
}
|
||||
}
|
||||
|
||||
// handleEventView renders the read-only detail view for a single event. It
|
||||
// is the landing page when a user clicks an event in the month/week grid;
|
||||
// writable calendars link from here to the edit page.
|
||||
func (s *Server) handleEventView(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
w.Header().Set("Allow", "GET")
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
username := userFromContext(r.Context())
|
||||
ref := r.PathValue("ref")
|
||||
id := r.PathValue("id")
|
||||
|
||||
if !eventIDRe.MatchString(id) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
color, form, err := s.eventForDisplay(username, ref, id)
|
||||
if errors.Is(err, store.ErrNotFound) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
s.handleCalRefError(w, r, err)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
_ = templates.EventDetail(username, templates.EventDetailData{Form: form, Color: color}).Render(context.Background(), w)
|
||||
}
|
||||
|
||||
// eventForDisplay resolves a calendar reference for read access, loads and
|
||||
// decodes the event with the given id, populates the form's display fields
|
||||
// (CalRef, CalendarLabel, Writable), and returns the calendar's color for
|
||||
// the detail view's header dot.
|
||||
func (s *Server) eventForDisplay(username, ref, id string) (color string, form templates.EventFormData, err error) {
|
||||
owner, name, err := s.resolveCalRef(username, ref, false)
|
||||
if err != nil {
|
||||
return "", form, err
|
||||
}
|
||||
data, err := s.store.GetObject(owner, "cal-"+name, id)
|
||||
if err != nil {
|
||||
return "", form, err
|
||||
}
|
||||
form, err = eventFormFromICS(id, data)
|
||||
if err != nil {
|
||||
s.logger.Error("decoding event", "error", err)
|
||||
return "", form, err
|
||||
}
|
||||
form.CalRef = ref
|
||||
label := name
|
||||
if owner != username {
|
||||
label = name + " (" + s.dbase.DisplayName(owner) + ")"
|
||||
}
|
||||
form.CalendarLabel = label
|
||||
form.Writable = owner == username
|
||||
if !form.Writable {
|
||||
if share, err := s.dbase.CalendarShareFor(owner, name, username); err == nil {
|
||||
form.Writable = share.Permission == db.PermWrite
|
||||
}
|
||||
}
|
||||
color, _ = s.dbase.GetCalendarColor(owner, name)
|
||||
return color, form, nil
|
||||
}
|
||||
|
||||
func (s *Server) handleEventEdit(w http.ResponseWriter, r *http.Request) {
|
||||
username := userFromContext(r.Context())
|
||||
ref := r.PathValue("ref")
|
||||
|
||||
Reference in New Issue
Block a user