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

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Widget\Renderer;
use App\Widget\WidgetRendererInterface;
use Twig\Environment;
abstract class AbstractTwigRenderer implements WidgetRendererInterface
{
/**
* @var Environment
*/
protected $twig;
/**
* @param Environment $twig
*/
public function __construct(Environment $twig)
{
$this->twig = $twig;
}
/**
* @param string $template
* @param array $data
* @return string
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
protected function renderTemplate(string $template, array $data): string
{
return $this->twig->render($template, $data);
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Widget\Renderer;
use App\Widget\Type\CompoundChart;
use App\Widget\WidgetInterface;
class CompoundChartRenderer extends AbstractTwigRenderer
{
public function supports(WidgetInterface $widget): bool
{
return ($widget instanceof CompoundChart);
}
public function render(WidgetInterface $widget, array $options = []): string
{
return $this->renderTemplate('widget/section-chart.html.twig', [
'title' => $widget->getTitle(),
'widgets' => $widget->getData(),
]);
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Widget\Renderer;
use App\Widget\Type\CompoundRow;
use App\Widget\WidgetInterface;
class CompoundRowRenderer extends AbstractTwigRenderer
{
public function supports(WidgetInterface $widget): bool
{
return ($widget instanceof CompoundRow);
}
public function render(WidgetInterface $widget, array $options = []): string
{
return $this->renderTemplate('widget/section-simple.html.twig', [
'title' => $widget->getTitle(),
'widgets' => $widget->getData(),
]);
}
}

View File

@@ -0,0 +1,33 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Widget\Renderer;
use App\Widget\Type\SimpleWidget;
use App\Widget\WidgetInterface;
use ReflectionClass;
class SimpleWidgetRenderer extends AbstractTwigRenderer
{
public function supports(WidgetInterface $widget): bool
{
return $widget instanceof SimpleWidget;
}
public function render(WidgetInterface $widget, array $options = []): string
{
$name = (new ReflectionClass($widget))->getShortName();
return $this->renderTemplate(sprintf('widget/widget-%s.html.twig', strtolower($name)), [
'data' => $widget->getData($options),
'options' => $widget->getOptions($options),
'title' => $widget->getTitle(),
]);
}
}