users weekly stats as bar-chart in dashboard (#847)

This commit is contained in:
Kevin Papst
2019-06-13 18:38:49 +02:00
committed by GitHub
parent e1f862507e
commit 3311f17bbb
96 changed files with 2754 additions and 846 deletions

View File

@@ -10,8 +10,10 @@
namespace App\Controller;
use App\Event\DashboardEvent;
use App\Model\DashboardSection;
use App\Repository\WidgetRepository;
use App\Widget\Type\CompoundChart;
use App\Widget\Type\CompoundRow;
use App\Widget\WidgetContainerInterface;
use App\Widget\WidgetService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Routing\Annotation\Route;
@@ -29,9 +31,9 @@ class DashboardController extends AbstractController
*/
protected $eventDispatcher;
/**
* @var WidgetRepository
* @var WidgetService
*/
protected $repository;
protected $widgets;
/**
* @var array
*/
@@ -39,13 +41,13 @@ class DashboardController extends AbstractController
/**
* @param EventDispatcherInterface $dispatcher
* @param WidgetRepository $repository
* @param WidgetService $service
* @param array $dashboard
*/
public function __construct(EventDispatcherInterface $dispatcher, WidgetRepository $repository, array $dashboard)
public function __construct(EventDispatcherInterface $dispatcher, WidgetService $service, array $dashboard)
{
$this->eventDispatcher = $dispatcher;
$this->repository = $repository;
$this->widgets = $service;
$this->dashboard = $dashboard;
}
@@ -61,22 +63,26 @@ class DashboardController extends AbstractController
continue;
}
if (!$this->isGranted($widgetRow['permission'])) {
if (null !== $widgetRow['permission'] && !$this->isGranted($widgetRow['permission'])) {
continue;
}
$row = new DashboardSection($widgetRow['title'] ?? null);
$row
->setOrder($widgetRow['order'])
->setType($widgetRow['type'])
;
// TODO this should be dynamic
if ($widgetRow['type'] === 'compoundChart') {
$row = new CompoundChart();
} else {
$row = new CompoundRow();
}
$row->setTitle($widgetRow['title'] ?? '');
$row->setOrder($widgetRow['order']);
foreach ($widgetRow['widgets'] as $widgetName) {
if (!$this->repository->has($widgetName)) {
throw new \Exception('Unknwon widget: ' . $widgetName);
if (!$this->widgets->hasWidget($widgetName)) {
throw new \Exception(sprintf('Unknown widget "%s"', $widgetName));
}
$row->addWidget($this->repository->get($widgetName, $event->getUser()));
$row->addWidget($this->widgets->getWidget($widgetName));
}
$event->addSection($row);
@@ -91,7 +97,7 @@ class DashboardController extends AbstractController
uasort(
$sections,
function (DashboardSection $a, DashboardSection $b) {
function (WidgetContainerInterface $a, WidgetContainerInterface $b) {
if ($a->getOrder() == $b->getOrder()) {
return 0;
}
@@ -101,7 +107,7 @@ class DashboardController extends AbstractController
);
return $this->render('dashboard/index.html.twig', [
'widget_rows' => $sections
'widgets' => $sections
]);
}
}