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:
+40
-1
@@ -64,6 +64,7 @@ CREATE TABLE IF NOT EXISTS users (
|
||||
CREATE TABLE IF NOT EXISTS calendars (
|
||||
owner TEXT NOT NULL REFERENCES users (username) ON DELETE CASCADE,
|
||||
name TEXT NOT NULL,
|
||||
color TEXT NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (owner, name)
|
||||
);
|
||||
@@ -106,5 +107,43 @@ CREATE TABLE IF NOT EXISTS web_sessions (
|
||||
CREATE INDEX IF NOT EXISTS idx_web_sessions_expires_at ON web_sessions (expires_at);
|
||||
`
|
||||
_, err := d.conn.Exec(schema)
|
||||
return err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return d.migrateAddColumns()
|
||||
}
|
||||
|
||||
// migrateAddColumns adds columns to already-existing tables that predate
|
||||
// their introduction. CREATE TABLE IF NOT EXISTS above only creates a
|
||||
// table's initial shape, so columns added later (like calendars.color)
|
||||
// need an explicit ALTER TABLE for databases created before this change.
|
||||
func (d *DB) migrateAddColumns() error {
|
||||
hasColumn := func(table, column string) (bool, error) {
|
||||
rows, err := d.conn.Query(`SELECT name FROM pragma_table_info(?)`, table)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var name string
|
||||
if err := rows.Scan(&name); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if name == column {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, rows.Err()
|
||||
}
|
||||
|
||||
ok, err := hasColumn("calendars", "color")
|
||||
if err != nil {
|
||||
return fmt.Errorf("checking calendars.color column: %w", err)
|
||||
}
|
||||
if !ok {
|
||||
if _, err := d.conn.Exec(`ALTER TABLE calendars ADD COLUMN color TEXT NOT NULL DEFAULT ''`); err != nil {
|
||||
return fmt.Errorf("adding calendars.color column: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user