rdv: available calendar ranges

This commit is contained in:
nobohan 2021-08-19 15:19:25 +02:00
parent 0457ee2b8d
commit 65bce1aacb
6 changed files with 59 additions and 7 deletions

View File

@ -0,0 +1,38 @@
<?php
namespace Chill\CalendarBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Chill\MainBundle\Pagination\PaginatorInterface;
use Chill\MainBundle\Serializer\Model\Collection;
class CalendarRangeAPIController extends ApiController
{
/**
* @Route("/api/1.0/calendar/calendar-range-available.{_format}", name="chill_api_single_calendar_range_available")
*/
public function availableRanges(Request $request, string $_format): JsonResponse
{
if ($request->query->has('user')) {
$user = $request->query->get('user');
}
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT c FROM ChillCalendarBundle:CalendarRange c
WHERE NOT EXISTS (SELECT cal.id FROM ChillCalendarBundle:Calendar cal WHERE cal.calendarRange = c.id)')
;
$results = $query->getResult();
return $this->json(['count' => count($results), 'results' => $results], Response::HTTP_OK, [], [ 'groups' => [ 'read' ]]);
//TODO use also the paginator, eg return $this->serializeCollection('get', $request, $_format, $paginator, $results);
}
}

View File

@ -57,6 +57,7 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf
$container->prependExtensionConfig('chill_main', [ $container->prependExtensionConfig('chill_main', [
'apis' => [ 'apis' => [
[ [
'controller' => \Chill\CalendarBundle\Controller\CalendarRangeAPIController::class,
'class' => \Chill\CalendarBundle\Entity\CalendarRange::class, 'class' => \Chill\CalendarBundle\Entity\CalendarRange::class,
'name' => 'calendar_range', 'name' => 'calendar_range',
'base_path' => '/api/1.0/calendar/calendar-range', 'base_path' => '/api/1.0/calendar/calendar-range',

View File

@ -116,7 +116,7 @@ class Calendar
private ?CancelReason $cancelReason = null; private ?CancelReason $cancelReason = null;
/** /**
* @ORM\ManyToOne(targetEntity="CalendarRange") * @ORM\ManyToOne(targetEntity="CalendarRange", inversedBy="calendars")
*/ */
private ?CalendarRange $calendarRange = null; private ?CalendarRange $calendarRange = null;

View File

@ -4,6 +4,8 @@ namespace Chill\CalendarBundle\Entity;
use Chill\CalendarBundle\Repository\CalendarRangeRepository; use Chill\CalendarBundle\Repository\CalendarRangeRepository;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
@ -23,7 +25,7 @@ class CalendarRange
/** /**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User") * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
* @groups({"read"}) * @Groups({"read"})
*/ */
private User $user; private User $user;
@ -39,8 +41,19 @@ class CalendarRange
*/ */
private \DateTimeImmutable $endDate; private \DateTimeImmutable $endDate;
/**
* @ORM\OneToMany(targetEntity=Calendar::class,
* mappedBy="calendarRange")
*/
private Collection $calendars;
//TODO Lieu //TODO Lieu
public function __construct()
{
$this->calendars = new ArrayCollection();
}
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;

View File

@ -19,9 +19,9 @@
:options="options"> :options="options">
</VueMultiselect> </VueMultiselect>
</div> </div>
<div> <div class="form-check">
<input type="checkbox" id="myCalendar" v-model="showMyCalendarWidget" /> <input type="checkbox" id="myCalendar" class="form-check-input" v-model="showMyCalendarWidget" />
<label for="checkbox">{{ $t('show_my_calendar') }}</label> <label class="form-check-label" for="myCalendar">{{ $t('show_my_calendar') }}</label>
</div> </div>
</template> </template>
<script> <script>
@ -151,7 +151,7 @@ export default {
transName(value) { transName(value) {
return `${value.username}`; return `${value.username}`;
}, },
coloriseSelectedValues() { //TODO cette function doit être exécutée au bon moment, après sélection (normalement avec @input) coloriseSelectedValues() {
let tags = document.querySelectorAll('div.multiselect__tags-wrap')[0]; let tags = document.querySelectorAll('div.multiselect__tags-wrap')[0];
if (tags.hasChildNodes()) { if (tags.hasChildNodes()) {

View File

@ -4,7 +4,7 @@
* @returns {Promise} a promise containing all Calendar ranges objects * @returns {Promise} a promise containing all Calendar ranges objects
*/ */
const fetchCalendarRanges = () => { const fetchCalendarRanges = () => {
const url = `/api/1.0/calendar/calendar-range.json?item_per_page=1000`; const url = `/api/1.0/calendar/calendar-range-available.json`;
return fetch(url) return fetch(url)
.then(response => { .then(response => {
if (response.ok) { return response.json(); } if (response.ok) { return response.json(); }