Skip to content

Add rfc7986 color support for VEVENT objects #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add basic read support for COLOR prop
  • Loading branch information
ghsioux committed Feb 19, 2025
commit f99fd6e096f6d525d1e5f3a35303d105816a9fa5
6 changes: 6 additions & 0 deletions assets/js/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,12 @@ var event_render_callback = function event_render_callback(event, element) {
// Icons
var icons = [];

// Set the background and text colors of the event
if (event.color) {
element.css('background-color', event.color);
element.css('color', fg_for_bg(event.color));
}

if (event.rrule !== undefined) {
icons.push('fa-repeat');
}
Expand Down
2 changes: 1 addition & 1 deletion assets/templates/templates.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/AgenDAV/Event/VObjectEventInstanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class VObjectEventInstanceTest extends TestCase
'TRANSP' => 'OPAQUE',
'RRULE' => 'FREQ=MONTHLY',
'RECURRENCE-ID' => '20150109T123456Z',
'COLOR' => 'peachpuff',
'SEQUENCE' => '2',
];

Expand Down Expand Up @@ -184,10 +185,12 @@ public function testOneSet()
$vevent = $this->vcalendar->add('VEVENT', [
'SUMMARY' => 'Test summary',
'LOCATION' => 'Test location',
'COLOR' => 'peachpuff',
]);
$instance = new VObjectEventInstance($vevent);
$instance->setSummary('New summary');
$instance->setLocation('');
$instance->setColor('navajowhite');
$this->assertEquals(
'New summary',
$instance->getSummary()
Expand All @@ -196,6 +199,10 @@ public function testOneSet()
'',
$instance->getLocation()
);
$this->assertEquals(
'navajowhite',
$instance->getColor()
);
}

public function testSetStart()
Expand Down Expand Up @@ -512,6 +519,7 @@ protected function checkSomeProperties(VObjectEventInstance $instance, $recurren
} else {
$this->assertEquals('FREQ=MONTHLY', $instance->getRepeatRule());
}
$this->assertEquals('peachpuff', $instance->getColor());
}

protected function setSomeVAlarms(VEvent $vevent)
Expand Down
3 changes: 3 additions & 0 deletions tests/AgenDAV/Event/VObjectEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function setUp()
$this->vevent = $this->vcalendar->add('VEVENT', [
'UID' => '123456',
'SUMMARY' => 'Initial event instance',
'COLOR' => 'peachpuff',
'MYPROPERTY' => 'Check',
]);
}
Expand Down Expand Up @@ -272,6 +273,7 @@ public function testSetBaseInstanceWithBase()
$instance->setStart($now, true);
$instance->setSummary('New test summary');
$instance->setRecurrenceId(RecurrenceId::buildFromString('20150110T100500Z'));
$instance->setColor('navajowhite');

$event->storeInstance($instance);

Expand All @@ -280,6 +282,7 @@ public function testSetBaseInstanceWithBase()
$this->assertEmpty($vevent->{'RECURRENCE-ID'});
$this->assertEquals('Check', $vevent->MYPROPERTY);
$this->assertEquals('New test summary', $vevent->SUMMARY);
$this->assertEquals('navajowhite', $vevent->COLOR);
}


Expand Down
1 change: 1 addition & 0 deletions web/src/Data/Transformer/FullCalendarEventTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function transform(FullCalendarEvent $fc_event)
'etag' => $fc_event->getEtag(),
'uid' => $event->getUid(),
'title' => $event->getSummary(),
'color' => $event->getColor(),
'start' => $start->format('c'),
'end' => $end->format('c'),
'allDay' => $event->isAllDay(),
Expand Down
10 changes: 10 additions & 0 deletions web/src/Event/VObjectEventInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public function getSummary()
return (string) $this->vevent->SUMMARY;
}

public function getColor()
{
return (string) $this->vevent->COLOR;
}

/**
* Get the LOCATION property of this event
*
Expand Down Expand Up @@ -265,6 +270,10 @@ public function setSummary($summary)
{
$this->setProperty('SUMMARY', $summary);
}
public function setColor($color)
{
$this->setProperty('COLOR', $color);
}

/**
* Set the LOCATION property for this event
Expand Down Expand Up @@ -443,6 +452,7 @@ public function touch()
public function copyPropertiesFrom(EventInstance $source)
{
$this->setSummary($source->getSummary());
$this->setColor($source->getColor());
$this->setLocation($source->getLocation());
$this->setDescription($source->getDescription());
$this->setClass($source->getClass());
Expand Down
15 changes: 14 additions & 1 deletion web/src/EventInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ public function getRepeatRule();
*/
public function getRecurrenceId();

/**
* Get the COLOR property of this event
*
* @return string
*/
public function getColor();

/**
* Returns all recognized reminders for this instance
*
Expand Down Expand Up @@ -198,6 +205,13 @@ public function setRepeatRule($rrule);
*/
public function setRecurrenceId(RecurrenceId $recurrence_id = null);

/**
* Set the COLOR property for this event
*
* @param string $color
*/
public function setColor($color);

/**
* Sets the exception status for this instance. This is useful on
* recurrent events which have exceptions (with their own RECURRENCE-ID)
Expand Down Expand Up @@ -243,4 +257,3 @@ public function touch();
*/
public function copyPropertiesFrom(EventInstance $source);
}