mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fixes for editing calendar
This commit is contained in:
parent
a025883a5d
commit
7dcd5be735
@ -18,7 +18,7 @@
|
|||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% set blocks = [] %}
|
{% set blocks = [] %}
|
||||||
{% if entity.activityType.personsVisible %}
|
{% if context == 'calendar_accompanyingCourse' or entity.activityType.personsVisible %}
|
||||||
{% if context == 'person' %}
|
{% if context == 'person' %}
|
||||||
{% set blocks = blocks|merge([{
|
{% set blocks = blocks|merge([{
|
||||||
'title': 'Others persons'|trans,
|
'title': 'Others persons'|trans,
|
||||||
@ -43,7 +43,7 @@
|
|||||||
}]) %}
|
}]) %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if entity.activityType.thirdPartiesVisible %}
|
{% if context == 'calendar_accompanyingCourse' or entity.activityType.thirdPartiesVisible %}
|
||||||
{% set blocks = blocks|merge([{
|
{% set blocks = blocks|merge([{
|
||||||
'title': 'Third parties'|trans,
|
'title': 'Third parties'|trans,
|
||||||
'items': entity.thirdParties,
|
'items': entity.thirdParties,
|
||||||
@ -52,7 +52,7 @@
|
|||||||
'key' : 'id',
|
'key' : 'id',
|
||||||
}]) %}
|
}]) %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if entity.activityType.usersVisible %}
|
{% if context == 'calendar_accompanyingCourse' or entity.activityType.usersVisible %}
|
||||||
{% set blocks = blocks|merge([{
|
{% set blocks = blocks|merge([{
|
||||||
'title': 'Users concerned'|trans,
|
'title': 'Users concerned'|trans,
|
||||||
'items': entity.users,
|
'items': entity.users,
|
||||||
|
@ -137,7 +137,7 @@ class CalendarController extends AbstractController
|
|||||||
*
|
*
|
||||||
* @Route("/{_locale}/calendar/calendar/{id}/edit", name="chill_calendar_calendar_edit")
|
* @Route("/{_locale}/calendar/calendar/{id}/edit", name="chill_calendar_calendar_edit")
|
||||||
*/
|
*/
|
||||||
public function editAction(int $id, Request $request): Response
|
public function editAction(Calendar $entity, Request $request): Response
|
||||||
{
|
{
|
||||||
$view = null;
|
$view = null;
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
@ -147,21 +147,14 @@ class CalendarController extends AbstractController
|
|||||||
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||||
$view = '@ChillCalendar/Calendar/editByAccompanyingCourse.html.twig';
|
$view = '@ChillCalendar/Calendar/editByAccompanyingCourse.html.twig';
|
||||||
} elseif ($user instanceof User) {
|
} elseif ($user instanceof User) {
|
||||||
|
throw new Exception('to analyze');
|
||||||
$view = '@ChillCalendar/Calendar/editByUser.html.twig';
|
$view = '@ChillCalendar/Calendar/editByUser.html.twig';
|
||||||
}
|
}
|
||||||
|
|
||||||
$entity = $em->getRepository(\Chill\CalendarBundle\Entity\Calendar::class)->find($id);
|
$form = $this->createForm(CalendarType::class, $entity);
|
||||||
|
$form->handleRequest($request);
|
||||||
if (!$entity) {
|
|
||||||
throw $this->createNotFoundException('Unable to find Calendar entity.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$form = $this->createForm(CalendarType::class, $entity, [
|
|
||||||
'accompanyingPeriod' => $accompanyingPeriod,
|
|
||||||
])->handleRequest($request);
|
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$em->persist($entity);
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$this->addFlash('success', $this->get('translator')->trans('Success : calendar item updated!'));
|
$this->addFlash('success', $this->get('translator')->trans('Success : calendar item updated!'));
|
||||||
@ -175,7 +168,7 @@ class CalendarController extends AbstractController
|
|||||||
$this->addFlash('error', $this->get('translator')->trans('This form contains errors'));
|
$this->addFlash('error', $this->get('translator')->trans('This form contains errors'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$deleteForm = $this->createDeleteForm($id, $user, $accompanyingPeriod);
|
$deleteForm = $this->createDeleteForm($entity->getId(), $user, $accompanyingPeriod);
|
||||||
|
|
||||||
if (null === $view) {
|
if (null === $view) {
|
||||||
throw $this->createNotFoundException('Template not found');
|
throw $this->createNotFoundException('Template not found');
|
||||||
@ -188,7 +181,7 @@ class CalendarController extends AbstractController
|
|||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'delete_form' => $deleteForm->createView(),
|
'delete_form' => $deleteForm->createView(),
|
||||||
'accompanyingCourse' => $accompanyingPeriod,
|
'accompanyingCourse' => $accompanyingPeriod,
|
||||||
'user' => $user,
|
// 'user' => $user,
|
||||||
'entity_json' => $entity_array,
|
'entity_json' => $entity_array,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ use Chill\MainBundle\Entity\User;
|
|||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
|
use DateInterval;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
@ -30,8 +31,8 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
use LogicException;
|
use LogicException;
|
||||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
use Symfony\Component\Validator\Constraints\Range;
|
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraints\Range;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||||
use function in_array;
|
use function in_array;
|
||||||
|
|
||||||
@ -219,6 +220,15 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
return $this->comment;
|
return $this->comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDuration(): ?DateInterval
|
||||||
|
{
|
||||||
|
if ($this->getStartDate() === null || $this->getEndDate() === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getStartDate()->diff($this->getEndDate());
|
||||||
|
}
|
||||||
|
|
||||||
public function getEndDate(): ?DateTimeImmutable
|
public function getEndDate(): ?DateTimeImmutable
|
||||||
{
|
{
|
||||||
return $this->endDate;
|
return $this->endDate;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import {COLORS} from '../const';
|
import {COLORS} from '../const';
|
||||||
|
import {ISOToDatetime} from 'ChillMainAssets/chill/js/date';
|
||||||
|
|
||||||
const addIdToValue = (string, id) => {
|
const addIdToValue = (string, id) => {
|
||||||
let array = string ? string.split(',') : [];
|
let array = string ? string.split(',') : [];
|
||||||
@ -18,8 +19,25 @@ const removeIdFromValue = (string, id) => {
|
|||||||
* Assign missing keys for the ConcernedGroups component
|
* Assign missing keys for the ConcernedGroups component
|
||||||
*/
|
*/
|
||||||
const mapEntity = (entity) => {
|
const mapEntity = (entity) => {
|
||||||
Object.assign(entity, {thirdParties: entity.professionals, users: entity.invites});
|
console.log('mapEntity', entity);
|
||||||
return entity;
|
let calendar = { ...entity};
|
||||||
|
Object.assign(calendar, {thirdParties: entity.professionals, users: entity.invites});
|
||||||
|
|
||||||
|
if (entity.startDate !== null ) {
|
||||||
|
calendar.startDate = ISOToDatetime(entity.startDate.datetime);
|
||||||
|
}
|
||||||
|
if (entity.endDate !== null) {
|
||||||
|
calendar.endDate = ISOToDatetime(entity.endDate.datetime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.calendarRange !== null) {
|
||||||
|
calendar.calendarRange.calendarRangeId = entity.calendarRange.id;
|
||||||
|
calendar.calendarRange.id = `range_${entity.calendarRange.id}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('new calendar object ', calendar);
|
||||||
|
|
||||||
|
return calendar;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createUserData = (user, colorIndex) => {
|
const createUserData = (user, colorIndex) => {
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
<div class="duration">
|
<div class="duration">
|
||||||
<p>
|
<p>
|
||||||
<i class="fa fa-fw fa-hourglass-end"></i>
|
<i class="fa fa-fw fa-hourglass-end"></i>
|
||||||
{{ calendar.endDate.diff(calendar.startDate)|date("%H:%M")}}
|
{{ calendar.duration|date('%H:%I')}}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -47,12 +47,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="item-col">
|
<div class="item-col">
|
||||||
<ul class="list-content">
|
<ul class="list-content">
|
||||||
{% if calendar.user %}
|
|
||||||
<li>
|
|
||||||
<b>{{ 'by'|trans }}{{ calendar.user.usernameCanonical }}</b>
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if calendar.mainUser is not empty %}
|
{% if calendar.mainUser is not empty %}
|
||||||
<li>
|
<li>
|
||||||
<b>{{ 'main user concerned'|trans }}: {{ calendar.mainUser.usernameCanonical }}</b>
|
<b>{{ 'main user concerned'|trans }}: {{ calendar.mainUser.usernameCanonical }}</b>
|
||||||
@ -93,7 +87,7 @@
|
|||||||
<div class="item-row details">
|
<div class="item-row details">
|
||||||
<div class="item-col">
|
<div class="item-col">
|
||||||
{% include 'ChillActivityBundle:Activity:concernedGroups.html.twig' with {
|
{% include 'ChillActivityBundle:Activity:concernedGroups.html.twig' with {
|
||||||
'context': accompanyingCourse,
|
'context': 'calendar_accompanyingCourse',
|
||||||
'render': 'row',
|
'render': 'row',
|
||||||
'entity': calendar
|
'entity': calendar
|
||||||
} %}
|
} %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user