Merge pull request #5294 from christianbeeznest/fixes-updates15

Calendar: Adapt event colors from settings and fix event updates
pull/5302/head
christianbeeznest 2 years ago committed by GitHub
commit d8d1790870
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      assets/vue/views/ccalendarevent/CCalendarEventList.vue
  2. 2
      src/CoreBundle/ApiResource/CalendarEvent.php
  3. 30
      src/CoreBundle/DataTransformer/CalendarEventTransformer.php
  4. 1
      src/CourseBundle/Entity/CCalendarEvent.php

@ -213,14 +213,7 @@ async function getCalendarEvents({ startStr, endStr }) {
const calendarEvents = await cCalendarEventService.findAll({ params }).then((response) => response.json()) const calendarEvents = await cCalendarEventService.findAll({ params }).then((response) => response.json())
return calendarEvents["hydra:member"].map((event) => { return calendarEvents["hydra:member"].map((event) => {
let color = '#007BFF' let color = event.color || '#007BFF'
if (event.type === 'global') {
color = '#FF0000'
} else if (event.type === 'course') {
color = '#28a745'
} else if (event.type === 'session') {
color = '#800080'
}
return { return {
...event, ...event,
@ -267,6 +260,7 @@ const calendarOptions = ref({
selectable: true, selectable: true,
eventClick(eventClickInfo) { eventClick(eventClickInfo) {
eventClickInfo.jsEvent.preventDefault() eventClickInfo.jsEvent.preventDefault()
currentEvent = eventClickInfo.event
let event = eventClickInfo.event.toPlainObject() let event = eventClickInfo.event.toPlainObject()
@ -277,8 +271,6 @@ const calendarOptions = ref({
return return
} }
currentEvent = event
item.value = { ...event.extendedProps } item.value = { ...event.extendedProps }
item.value["title"] = event.title item.value["title"] = event.title
@ -320,7 +312,7 @@ const currentContext = computed(() => {
} else { } else {
return 'personal' return 'personal'
} }
}); })
const allowAction = (eventType) => { const allowAction = (eventType) => {
const contextRules = { const contextRules = {
@ -328,13 +320,13 @@ const allowAction = (eventType) => {
course: ['course'], course: ['course'],
session: ['session'], session: ['session'],
personal: ['personal'] personal: ['personal']
}; }
return contextRules[currentContext.value].includes(eventType); return contextRules[currentContext.value].includes(eventType)
}; }
const showEditButton = computed(() => allowAction(item.value.type)); const showEditButton = computed(() => allowAction(item.value.type))
const showDeleteButton = computed(() => allowAction(item.value.type)); const showDeleteButton = computed(() => allowAction(item.value.type))
const cal = ref(null) const cal = ref(null)

@ -44,6 +44,8 @@ class CalendarEvent extends AbstractResource
public ?ResourceNode $resourceNode = null, public ?ResourceNode $resourceNode = null,
?array $resourceLinkListFromEntity = null, ?array $resourceLinkListFromEntity = null,
#[Groups(['calendar_event:read'])] #[Groups(['calendar_event:read'])]
public ?string $color = null,
#[Groups(['calendar_event:read'])]
public ?string $type = null, public ?string $type = null,
) { ) {
$this->resourceLinkListFromEntity = $resourceLinkListFromEntity; $this->resourceLinkListFromEntity = $resourceLinkListFromEntity;

@ -11,6 +11,7 @@ use Chamilo\CoreBundle\ApiResource\CalendarEvent;
use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\SessionRelCourse; use Chamilo\CoreBundle\Entity\SessionRelCourse;
use Chamilo\CoreBundle\Repository\Node\UsergroupRepository; use Chamilo\CoreBundle\Repository\Node\UsergroupRepository;
use Chamilo\CoreBundle\Settings\SettingsManager;
use Chamilo\CourseBundle\Entity\CCalendarEvent; use Chamilo\CourseBundle\Entity\CCalendarEvent;
use Chamilo\CourseBundle\Repository\CCalendarEventRepository; use Chamilo\CourseBundle\Repository\CCalendarEventRepository;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@ -21,7 +22,8 @@ class CalendarEventTransformer implements DataTransformerInterface
public function __construct( public function __construct(
private readonly RouterInterface $router, private readonly RouterInterface $router,
private readonly UsergroupRepository $usergroupRepository, private readonly UsergroupRepository $usergroupRepository,
private readonly CCalendarEventRepository $calendarEventRepository private readonly CCalendarEventRepository $calendarEventRepository,
private readonly SettingsManager $settingsManager
) {} ) {}
public function transform($object, string $to, array $context = []): object public function transform($object, string $to, array $context = []): object
@ -51,6 +53,8 @@ class CalendarEventTransformer implements DataTransformerInterface
} }
$eventType = $this->calendarEventRepository->determineEventType($object); $eventType = $this->calendarEventRepository->determineEventType($object);
$color = $this->determineEventColor($eventType);
$calendarEvent = new CalendarEvent( $calendarEvent = new CalendarEvent(
'calendar_event_'.$object->getIid(), 'calendar_event_'.$object->getIid(),
$object->getTitle(), $object->getTitle(),
@ -67,6 +71,7 @@ class CalendarEventTransformer implements DataTransformerInterface
$object->getMaxAttendees(), $object->getMaxAttendees(),
$object->getResourceNode(), $object->getResourceNode(),
$object->getResourceLinkListFromEntity(), $object->getResourceLinkListFromEntity(),
$color
); );
$calendarEvent->setType($eventType); $calendarEvent->setType($eventType);
@ -99,4 +104,27 @@ class CalendarEventTransformer implements DataTransformerInterface
$sessionUrl, $sessionUrl,
); );
} }
private function determineEventColor(string $eventType): string
{
$agendaColors = [
'platform' => 'red',
'course' => '#458B00',
'session' => '#00496D',
'personal' => 'steel blue',
];
$settingAgendaColors = $this->settingsManager->getSetting('agenda.agenda_colors');
if (is_array($settingAgendaColors)) {
$agendaColors = array_merge($agendaColors, $settingAgendaColors);
}
$colorKeyMap = [
'global' => 'platform',
];
$colorKey = $colorKeyMap[$eventType] ?? $eventType;
return $agendaColors[$colorKey] ?? $agendaColors['personal'];
}
} }

@ -132,6 +132,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface, Stri
#[ORM\Column(name: 'comment', type: 'text', nullable: true)] #[ORM\Column(name: 'comment', type: 'text', nullable: true)]
protected ?string $comment = null; protected ?string $comment = null;
#[Groups(['calendar_event:write', 'calendar_event:read'])]
#[ORM\Column(name: 'color', type: 'string', length: 20, nullable: true)] #[ORM\Column(name: 'color', type: 'string', length: 20, nullable: true)]
protected ?string $color = null; protected ?string $color = null;

Loading…
Cancel
Save