Add Fullcalendar using vue, add filters with api platformpull/3924/head
parent
8f9852a1a5
commit
5f77c651c3
@ -0,0 +1,114 @@ |
||||
<template> |
||||
<div> |
||||
<Toolbar |
||||
v-if="item" |
||||
:handle-edit="editHandler" |
||||
:handle-delete="del" |
||||
> |
||||
</Toolbar> |
||||
|
||||
|
||||
<FullCalendar :options="calendarOptions" /> |
||||
|
||||
<Loading :visible="isLoading" /> |
||||
</div> |
||||
</template> |
||||
|
||||
<script> |
||||
import { mapActions, mapGetters } from 'vuex'; |
||||
import { mapFields } from 'vuex-map-fields'; |
||||
import Loading from '../../components/Loading.vue'; |
||||
import Toolbar from '../../components/Toolbar.vue'; |
||||
import {ref} from "vue"; |
||||
|
||||
//import '@fullcalendar/core/vdom' // solve problem with Vite |
||||
import FullCalendar from '@fullcalendar/vue3'; |
||||
import dayGridPlugin from '@fullcalendar/daygrid'; |
||||
import interactionPlugin from '@fullcalendar/interaction'; |
||||
import timeGridPlugin from '@fullcalendar/timegrid'; |
||||
import axios from "axios"; |
||||
|
||||
const servicePrefix = 'CCalendarEvent'; |
||||
|
||||
export default { |
||||
name: 'CCalendarEventIndex', |
||||
components: { |
||||
Loading, |
||||
Toolbar, |
||||
FullCalendar |
||||
}, |
||||
//mixins: [ShowMixin], |
||||
setup() { |
||||
const calendarOptions = ref([]); |
||||
|
||||
const events = []; |
||||
|
||||
calendarOptions.value = { |
||||
plugins: [ |
||||
dayGridPlugin, |
||||
timeGridPlugin, |
||||
interactionPlugin |
||||
], |
||||
headerToolbar: { |
||||
left: 'prev,next today', |
||||
center: 'title', |
||||
right: 'dayGridMonth,timeGridWeek,timeGridDay' |
||||
}, |
||||
nowIndicator: true, |
||||
initialView: 'dayGridMonth', |
||||
//events: '/api/c_calendar_events', |
||||
startParam: "startDate[after]", |
||||
endParam: 'endDate[before]', |
||||
events: function(info, successCallback, failureCallback) { |
||||
axios.get('/api/c_calendar_events',{ |
||||
params: { |
||||
'startDate[after]': info.start.valueOf(), |
||||
'endDate[after]': info.end.valueOf() |
||||
} |
||||
}).then(response => { |
||||
let data = response.data; |
||||
let events = data['hydra:member']; |
||||
successCallback( |
||||
Array.prototype.slice.call( // convert to array |
||||
events |
||||
).map(function(event) { |
||||
return { |
||||
title: event['title'], |
||||
start: event['startDate'], |
||||
end: event['endDate'], |
||||
} |
||||
}) |
||||
) |
||||
}) |
||||
}, |
||||
/*eventSourceSuccess: function(content, xhr) { |
||||
console.log('aaa'); |
||||
console.log(content['hydra:member']); |
||||
|
||||
return content['hydra:member']; |
||||
}*/ |
||||
} |
||||
|
||||
return {calendarOptions}; |
||||
}, |
||||
computed: { |
||||
...mapFields('ccalendarevent', { |
||||
isLoading: 'isLoading' |
||||
}), |
||||
...mapGetters('ccalendarevent', ['find']), |
||||
...mapGetters({ |
||||
'isAuthenticated': 'security/isAuthenticated', |
||||
'isAdmin': 'security/isAdmin', |
||||
'isCurrentTeacher': 'security/isCurrentTeacher', |
||||
}), |
||||
}, |
||||
methods: { |
||||
...mapActions('ccalendarevent', { |
||||
deleteItem: 'del', |
||||
reset: 'resetShow', |
||||
retrieve: 'loadWithQuery' |
||||
}), |
||||
}, |
||||
servicePrefix |
||||
}; |
||||
</script> |
@ -0,0 +1,99 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace Chamilo\CoreBundle\DataProvider\Extension; |
||||
|
||||
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface; |
||||
//use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface; |
||||
//use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface; |
||||
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface; |
||||
use Chamilo\CoreBundle\Entity\Message; |
||||
use Chamilo\CoreBundle\Entity\User; |
||||
use Chamilo\CourseBundle\Entity\CCalendarEvent; |
||||
use Doctrine\ORM\Query\Expr\Join; |
||||
use Doctrine\ORM\QueryBuilder; |
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
||||
use Symfony\Component\Security\Core\Security; |
||||
|
||||
final class CCalendarEventExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface |
||||
{ |
||||
private Security $security; |
||||
|
||||
public function __construct(Security $security) |
||||
{ |
||||
$this->security = $security; |
||||
} |
||||
|
||||
public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null): void |
||||
{ |
||||
/*if ($this->security->isGranted('ROLE_ADMIN')) { |
||||
return; |
||||
}*/ |
||||
/* |
||||
if ('collection_query' === $operationName) { |
||||
if (null === $user = $this->security->getUser()) { |
||||
throw new AccessDeniedException('Access Denied.'); |
||||
} |
||||
|
||||
$rootAlias = $queryBuilder->getRootAliases()[0]; |
||||
$queryBuilder->andWhere(sprintf('%s.user = :current_user', $rootAlias)); |
||||
$queryBuilder->setParameter('current_user', $user); |
||||
}*/ |
||||
|
||||
$this->addWhere($queryBuilder, $resourceClass); |
||||
} |
||||
|
||||
public function applyToItem(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, array $identifiers, string $operationName = null, array $context = []): void |
||||
{ |
||||
//error_log('applyToItem1'); |
||||
//$this->addWhere($queryBuilder, $resourceClass); |
||||
} |
||||
|
||||
private function addWhere(QueryBuilder $qb, string $resourceClass): void |
||||
{ |
||||
if (CCalendarEvent::class !== $resourceClass) { |
||||
return; |
||||
} |
||||
|
||||
/*if ($this->security->isGranted('ROLE_ADMIN')) { |
||||
return; |
||||
}*/ |
||||
|
||||
/** @var User $user */ |
||||
$user = $this->security->getUser(); |
||||
$alias = $qb->getRootAliases()[0]; |
||||
|
||||
$qb |
||||
->innerJoin("$alias.resourceNode", 'node') |
||||
->leftJoin('node.resourceLinks', 'links') |
||||
; |
||||
|
||||
$qb |
||||
->andWhere( |
||||
' |
||||
links.user = :user OR node.creator = :user |
||||
' |
||||
) |
||||
->setParameter('user', $user) |
||||
; |
||||
|
||||
//$qb->leftJoin("$alias.receivers", 'r'); |
||||
//$qb->leftJoin("$alias.receivers", 'r', Join::WITH, "r.receiver = :current OR $alias.sender = :current "); |
||||
//$qb->leftJoin("$alias.receivers", 'r'); |
||||
/*$qb->andWhere( |
||||
$qb->expr()->orX( |
||||
$qb->andWhere( |
||||
$qb->expr()->eq("$alias.sender", $user->getId()), |
||||
$qb->expr()->eq("$alias.msgType", Message::MESSAGE_TYPE_OUTBOX) |
||||
), |
||||
$qb->andWhere( |
||||
$qb->expr()->in("r", $user->getId()), |
||||
$qb->expr()->eq("$alias.msgType", Message::MESSAGE_TYPE_INBOX) |
||||
) |
||||
), |
||||
);*/ |
||||
} |
||||
} |
Loading…
Reference in new issue