Add colors for caldav (#738)
Add colors for caldav Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/738 Co-Authored-By: konrad <konrad@kola-entertainments.de> Co-Committed-By: konrad <konrad@kola-entertainments.de>
This commit is contained in:
parent
5281ca548b
commit
969e467f48
2 changed files with 40 additions and 4 deletions
|
@ -37,6 +37,7 @@ type Event struct {
|
||||||
Description string
|
Description string
|
||||||
UID string
|
UID string
|
||||||
Alarms []Alarm
|
Alarms []Alarm
|
||||||
|
Color string
|
||||||
|
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
Start time.Time
|
Start time.Time
|
||||||
|
@ -56,6 +57,7 @@ type Todo struct {
|
||||||
Organizer *user.User
|
Organizer *user.User
|
||||||
Priority int64 // 0-9, 1 is highest
|
Priority int64 // 0-9, 1 is highest
|
||||||
RelatedToUID string
|
RelatedToUID string
|
||||||
|
Color string
|
||||||
|
|
||||||
Start time.Time
|
Start time.Time
|
||||||
End time.Time
|
End time.Time
|
||||||
|
@ -76,6 +78,24 @@ type Alarm struct {
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string
|
Name string
|
||||||
ProdID string
|
ProdID string
|
||||||
|
Color string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCaldavColor(color string) (caldavcolor string) {
|
||||||
|
if color == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(color, "#") {
|
||||||
|
color = "#" + color
|
||||||
|
}
|
||||||
|
|
||||||
|
color += "FF"
|
||||||
|
|
||||||
|
return `
|
||||||
|
X-APPLE-CALENDAR-COLOR:` + color + `
|
||||||
|
X-OUTLOOK-COLOR:` + color + `
|
||||||
|
X-FUNAMBOL-COLOR:` + color
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseEvents parses an array of caldav events and gives them back as string
|
// ParseEvents parses an array of caldav events and gives them back as string
|
||||||
|
@ -85,7 +105,7 @@ VERSION:2.0
|
||||||
METHOD:PUBLISH
|
METHOD:PUBLISH
|
||||||
X-PUBLISHED-TTL:PT4H
|
X-PUBLISHED-TTL:PT4H
|
||||||
X-WR-CALNAME:` + config.Name + `
|
X-WR-CALNAME:` + config.Name + `
|
||||||
PRODID:-//` + config.ProdID + `//EN`
|
PRODID:-//` + config.ProdID + `//EN` + getCaldavColor(config.Color)
|
||||||
|
|
||||||
for _, e := range events {
|
for _, e := range events {
|
||||||
|
|
||||||
|
@ -102,7 +122,7 @@ PRODID:-//` + config.ProdID + `//EN`
|
||||||
caldavevents += `
|
caldavevents += `
|
||||||
BEGIN:VEVENT
|
BEGIN:VEVENT
|
||||||
UID:` + e.UID + `
|
UID:` + e.UID + `
|
||||||
SUMMARY:` + e.Summary + `
|
SUMMARY:` + e.Summary + getCaldavColor(e.Color) + `
|
||||||
DESCRIPTION:` + formattedDescription + `
|
DESCRIPTION:` + formattedDescription + `
|
||||||
DTSTAMP:` + makeCalDavTimeFromTimeStamp(e.Timestamp) + `
|
DTSTAMP:` + makeCalDavTimeFromTimeStamp(e.Timestamp) + `
|
||||||
DTSTART:` + makeCalDavTimeFromTimeStamp(e.Start) + `
|
DTSTART:` + makeCalDavTimeFromTimeStamp(e.Start) + `
|
||||||
|
@ -137,7 +157,7 @@ VERSION:2.0
|
||||||
METHOD:PUBLISH
|
METHOD:PUBLISH
|
||||||
X-PUBLISHED-TTL:PT4H
|
X-PUBLISHED-TTL:PT4H
|
||||||
X-WR-CALNAME:` + config.Name + `
|
X-WR-CALNAME:` + config.Name + `
|
||||||
PRODID:-//` + config.ProdID + `//EN`
|
PRODID:-//` + config.ProdID + `//EN` + getCaldavColor(config.Color)
|
||||||
|
|
||||||
for _, t := range todos {
|
for _, t := range todos {
|
||||||
if t.UID == "" {
|
if t.UID == "" {
|
||||||
|
@ -148,7 +168,7 @@ PRODID:-//` + config.ProdID + `//EN`
|
||||||
BEGIN:VTODO
|
BEGIN:VTODO
|
||||||
UID:` + t.UID + `
|
UID:` + t.UID + `
|
||||||
DTSTAMP:` + makeCalDavTimeFromTimeStamp(t.Timestamp) + `
|
DTSTAMP:` + makeCalDavTimeFromTimeStamp(t.Timestamp) + `
|
||||||
SUMMARY:` + t.Summary
|
SUMMARY:` + t.Summary + getCaldavColor(t.Color)
|
||||||
|
|
||||||
if t.Start.Unix() > 0 {
|
if t.Start.Unix() > 0 {
|
||||||
caldavtodos += `
|
caldavtodos += `
|
||||||
|
|
|
@ -40,6 +40,7 @@ func TestParseEvents(t *testing.T) {
|
||||||
config: &Config{
|
config: &Config{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
ProdID: "RandomProdID which is not random",
|
ProdID: "RandomProdID which is not random",
|
||||||
|
Color: "ffffff",
|
||||||
},
|
},
|
||||||
events: []*Event{
|
events: []*Event{
|
||||||
{
|
{
|
||||||
|
@ -49,6 +50,7 @@ func TestParseEvents(t *testing.T) {
|
||||||
Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()),
|
Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()),
|
||||||
Start: time.Unix(1543626724, 0).In(config.GetTimeZone()),
|
Start: time.Unix(1543626724, 0).In(config.GetTimeZone()),
|
||||||
End: time.Unix(1543627824, 0).In(config.GetTimeZone()),
|
End: time.Unix(1543627824, 0).In(config.GetTimeZone()),
|
||||||
|
Color: "affffe",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Summary: "Event #2",
|
Summary: "Event #2",
|
||||||
|
@ -72,9 +74,15 @@ METHOD:PUBLISH
|
||||||
X-PUBLISHED-TTL:PT4H
|
X-PUBLISHED-TTL:PT4H
|
||||||
X-WR-CALNAME:test
|
X-WR-CALNAME:test
|
||||||
PRODID:-//RandomProdID which is not random//EN
|
PRODID:-//RandomProdID which is not random//EN
|
||||||
|
X-APPLE-CALENDAR-COLOR:#ffffffFF
|
||||||
|
X-OUTLOOK-COLOR:#ffffffFF
|
||||||
|
X-FUNAMBOL-COLOR:#ffffffFF
|
||||||
BEGIN:VEVENT
|
BEGIN:VEVENT
|
||||||
UID:randommduid
|
UID:randommduid
|
||||||
SUMMARY:Event #1
|
SUMMARY:Event #1
|
||||||
|
X-APPLE-CALENDAR-COLOR:#affffeFF
|
||||||
|
X-OUTLOOK-COLOR:#affffeFF
|
||||||
|
X-FUNAMBOL-COLOR:#affffeFF
|
||||||
DESCRIPTION:Lorem Ipsum
|
DESCRIPTION:Lorem Ipsum
|
||||||
DTSTAMP:20181201T011204
|
DTSTAMP:20181201T011204
|
||||||
DTSTART:20181201T011204
|
DTSTART:20181201T011204
|
||||||
|
@ -301,6 +309,7 @@ func TestParseTodos(t *testing.T) {
|
||||||
config: &Config{
|
config: &Config{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
ProdID: "RandomProdID which is not random",
|
ProdID: "RandomProdID which is not random",
|
||||||
|
Color: "ffffff",
|
||||||
},
|
},
|
||||||
todos: []*Todo{
|
todos: []*Todo{
|
||||||
{
|
{
|
||||||
|
@ -309,6 +318,7 @@ func TestParseTodos(t *testing.T) {
|
||||||
Dolor sit amet`,
|
Dolor sit amet`,
|
||||||
UID: "randommduid",
|
UID: "randommduid",
|
||||||
Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()),
|
Timestamp: time.Unix(1543626724, 0).In(config.GetTimeZone()),
|
||||||
|
Color: "affffe",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -318,10 +328,16 @@ METHOD:PUBLISH
|
||||||
X-PUBLISHED-TTL:PT4H
|
X-PUBLISHED-TTL:PT4H
|
||||||
X-WR-CALNAME:test
|
X-WR-CALNAME:test
|
||||||
PRODID:-//RandomProdID which is not random//EN
|
PRODID:-//RandomProdID which is not random//EN
|
||||||
|
X-APPLE-CALENDAR-COLOR:#ffffffFF
|
||||||
|
X-OUTLOOK-COLOR:#ffffffFF
|
||||||
|
X-FUNAMBOL-COLOR:#ffffffFF
|
||||||
BEGIN:VTODO
|
BEGIN:VTODO
|
||||||
UID:randommduid
|
UID:randommduid
|
||||||
DTSTAMP:20181201T011204
|
DTSTAMP:20181201T011204
|
||||||
SUMMARY:Todo #1
|
SUMMARY:Todo #1
|
||||||
|
X-APPLE-CALENDAR-COLOR:#affffeFF
|
||||||
|
X-OUTLOOK-COLOR:#affffeFF
|
||||||
|
X-FUNAMBOL-COLOR:#affffeFF
|
||||||
DESCRIPTION:Lorem Ipsum\nDolor sit amet
|
DESCRIPTION:Lorem Ipsum\nDolor sit amet
|
||||||
LAST-MODIFIED:00010101T000000
|
LAST-MODIFIED:00010101T000000
|
||||||
END:VTODO
|
END:VTODO
|
||||||
|
|
Loading…
Reference in a new issue