Add calendar color support (DAVx5 calendar-color)
Calendars can now have a color (hex, e.g. #3b82f6) that DAVx5 and other
CalDAV clients pick up via the Apple/dav4jvm calendar-color property.
- db: add calendars.color column with migration for existing DBs;
CreateCalendarWithColor, SetCalendarColor, GetCalendarColor;
ListCalendars now returns []Calendar{Name, Color} instead of []string
- caldav: since go-webdav's caldav.Backend interface has no extension
point for vendor properties, wrap the handler with a response-rewriting
middleware that injects <calendar-color xmlns="http://apple.com/ns/ical/">
into PROPFIND responses for calendars that have a color set
- web: color picker on the "New calendar" form and an inline color swatch/
picker on each calendar card (calendars only, not address books)
- nidusctl: `calendar create --color` flag and a new `calendar color`
subcommand; `calendar list` now also prints the color if set
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+56
-5
@@ -160,10 +160,24 @@ func (d *DB) UserCount() (int, error) {
|
||||
|
||||
// -------- calendars --------
|
||||
|
||||
// Calendar is a calendar registration, including its display color.
|
||||
type Calendar struct {
|
||||
Name string
|
||||
Color string
|
||||
}
|
||||
|
||||
// CreateCalendar registers a new calendar owned by owner. Returns
|
||||
// ErrResourceExists if it already exists.
|
||||
func (d *DB) CreateCalendar(owner, name string) error {
|
||||
_, err := d.conn.Exec(`INSERT INTO calendars (owner, name) VALUES (?, ?)`, owner, name)
|
||||
return d.CreateCalendarWithColor(owner, name, "")
|
||||
}
|
||||
|
||||
// CreateCalendarWithColor registers a new calendar owned by owner with the
|
||||
// given color (an empty string means no color is set, in which case the
|
||||
// client picks its own default). Returns ErrResourceExists if it already
|
||||
// exists.
|
||||
func (d *DB) CreateCalendarWithColor(owner, name, color string) error {
|
||||
_, err := d.conn.Exec(`INSERT INTO calendars (owner, name, color) VALUES (?, ?, ?)`, owner, name, color)
|
||||
if err != nil {
|
||||
if isUniqueConstraintErr(err) {
|
||||
return ErrResourceExists
|
||||
@@ -173,6 +187,30 @@ func (d *DB) CreateCalendar(owner, name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetCalendarColor updates a calendar's display color. Returns
|
||||
// ErrResourceNotFound if it doesn't exist.
|
||||
func (d *DB) SetCalendarColor(owner, name, color string) error {
|
||||
res, err := d.conn.Exec(`UPDATE calendars SET color = ? WHERE owner = ? AND name = ?`, color, owner, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("setting calendar color: %w", err)
|
||||
}
|
||||
return requireRowsAffected(res, ErrResourceNotFound)
|
||||
}
|
||||
|
||||
// GetCalendarColor returns a calendar's display color. Returns
|
||||
// ErrResourceNotFound if it doesn't exist.
|
||||
func (d *DB) GetCalendarColor(owner, name string) (string, error) {
|
||||
var color string
|
||||
err := d.conn.QueryRow(`SELECT color FROM calendars WHERE owner = ? AND name = ?`, owner, name).Scan(&color)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return "", ErrResourceNotFound
|
||||
}
|
||||
return "", fmt.Errorf("getting calendar color: %w", err)
|
||||
}
|
||||
return color, nil
|
||||
}
|
||||
|
||||
// DeleteCalendar removes a calendar registration (not the underlying
|
||||
// files/objects — callers are responsible for also removing those via
|
||||
// store.Store). Returns ErrResourceNotFound if it doesn't exist. Any
|
||||
@@ -197,10 +235,23 @@ func (d *DB) DeleteCalendar(owner, name string) error {
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// ListCalendars returns the names of all calendars owner has registered,
|
||||
// sorted.
|
||||
func (d *DB) ListCalendars(owner string) ([]string, error) {
|
||||
return listNames(d, `SELECT name FROM calendars WHERE owner = ? ORDER BY name`, owner)
|
||||
// ListCalendars returns all calendars owner has registered, sorted by name.
|
||||
func (d *DB) ListCalendars(owner string) ([]Calendar, error) {
|
||||
rows, err := d.conn.Query(`SELECT name, color FROM calendars WHERE owner = ? ORDER BY name`, owner)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("listing calendars: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var cals []Calendar
|
||||
for rows.Next() {
|
||||
var c Calendar
|
||||
if err := rows.Scan(&c.Name, &c.Color); err != nil {
|
||||
return nil, fmt.Errorf("scanning calendar: %w", err)
|
||||
}
|
||||
cals = append(cals, c)
|
||||
}
|
||||
return cals, rows.Err()
|
||||
}
|
||||
|
||||
// -------- address books --------
|
||||
|
||||
Reference in New Issue
Block a user