allow to customize dashboard permissions for latest row (#2806)
This commit is contained in:
@@ -24,7 +24,6 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->systemConfiguration = $systemConfiguration;
|
||||
$this->setId('PaginatedWorkingTimeChart');
|
||||
$this->setTitle('stats.yourWorkingHours');
|
||||
}
|
||||
|
||||
|
||||
65
src/Widget/Type/TotalsActivity.php
Normal file
65
src/Widget/Type/TotalsActivity.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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\Type;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\Query\ActivityQuery;
|
||||
|
||||
final class TotalsActivity extends SimpleWidget implements UserWidget, AuthorizedWidget
|
||||
{
|
||||
use UserWidgetTrait;
|
||||
|
||||
private $activity;
|
||||
|
||||
public function __construct(ActivityRepository $activity)
|
||||
{
|
||||
$this->activity = $activity;
|
||||
$this->setTitle('stats.activityTotal');
|
||||
}
|
||||
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge([
|
||||
'route' => 'admin_activity',
|
||||
'icon' => 'activity',
|
||||
'color' => 'primary',
|
||||
'dataType' => 'int',
|
||||
], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$options = $this->getOptions($options);
|
||||
|
||||
$user = $options['user'];
|
||||
if (null === $user || !($user instanceof User)) {
|
||||
throw new \InvalidArgumentException('Widget option "user" must be an instance of ' . User::class);
|
||||
}
|
||||
|
||||
$query = new ActivityQuery();
|
||||
$query->setCurrentUser($user);
|
||||
|
||||
return $this->activity->countActivitiesForQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPermissions(): array
|
||||
{
|
||||
return ['view_activity', 'view_teamlead_activity', 'view_team_activity'];
|
||||
}
|
||||
|
||||
public function getTemplateName(): string
|
||||
{
|
||||
return 'widget/widget-more.html.twig';
|
||||
}
|
||||
}
|
||||
65
src/Widget/Type/TotalsCustomer.php
Normal file
65
src/Widget/Type/TotalsCustomer.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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\Type;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\Query\CustomerQuery;
|
||||
|
||||
final class TotalsCustomer extends SimpleWidget implements UserWidget, AuthorizedWidget
|
||||
{
|
||||
use UserWidgetTrait;
|
||||
|
||||
private $customer;
|
||||
|
||||
public function __construct(CustomerRepository $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
$this->setTitle('stats.customerTotal');
|
||||
}
|
||||
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge([
|
||||
'route' => 'admin_customer',
|
||||
'icon' => 'customer',
|
||||
'color' => 'primary',
|
||||
'dataType' => 'int',
|
||||
], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$options = $this->getOptions($options);
|
||||
|
||||
$user = $options['user'];
|
||||
if (null === $user || !($user instanceof User)) {
|
||||
throw new \InvalidArgumentException('Widget option "user" must be an instance of ' . User::class);
|
||||
}
|
||||
|
||||
$query = new CustomerQuery();
|
||||
$query->setCurrentUser($user);
|
||||
|
||||
return $this->customer->countCustomersForQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPermissions(): array
|
||||
{
|
||||
return ['view_customer', 'view_teamlead_customer', 'view_team_customer'];
|
||||
}
|
||||
|
||||
public function getTemplateName(): string
|
||||
{
|
||||
return 'widget/widget-more.html.twig';
|
||||
}
|
||||
}
|
||||
65
src/Widget/Type/TotalsProject.php
Normal file
65
src/Widget/Type/TotalsProject.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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\Type;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\Query\ProjectQuery;
|
||||
|
||||
final class TotalsProject extends SimpleWidget implements UserWidget, AuthorizedWidget
|
||||
{
|
||||
use UserWidgetTrait;
|
||||
|
||||
private $project;
|
||||
|
||||
public function __construct(ProjectRepository $project)
|
||||
{
|
||||
$this->project = $project;
|
||||
$this->setTitle('stats.projectTotal');
|
||||
}
|
||||
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge([
|
||||
'route' => 'admin_project',
|
||||
'icon' => 'project',
|
||||
'color' => 'primary',
|
||||
'dataType' => 'int',
|
||||
], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$options = $this->getOptions($options);
|
||||
|
||||
$user = $options['user'];
|
||||
if (null === $user || !($user instanceof User)) {
|
||||
throw new \InvalidArgumentException('Widget option "user" must be an instance of ' . User::class);
|
||||
}
|
||||
|
||||
$query = new ProjectQuery();
|
||||
$query->setCurrentUser($user);
|
||||
|
||||
return $this->project->countProjectsForQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPermissions(): array
|
||||
{
|
||||
return ['view_project', 'view_teamlead_project', 'view_team_project'];
|
||||
}
|
||||
|
||||
public function getTemplateName(): string
|
||||
{
|
||||
return 'widget/widget-more.html.twig';
|
||||
}
|
||||
}
|
||||
65
src/Widget/Type/TotalsUser.php
Normal file
65
src/Widget/Type/TotalsUser.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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\Type;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Repository\Query\UserQuery;
|
||||
use App\Repository\UserRepository;
|
||||
|
||||
final class TotalsUser extends SimpleWidget implements UserWidget, AuthorizedWidget
|
||||
{
|
||||
use UserWidgetTrait;
|
||||
|
||||
private $user;
|
||||
|
||||
public function __construct(UserRepository $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->setTitle('stats.userTotal');
|
||||
}
|
||||
|
||||
public function getOptions(array $options = []): array
|
||||
{
|
||||
return array_merge([
|
||||
'route' => 'admin_user',
|
||||
'icon' => 'user',
|
||||
'color' => 'primary',
|
||||
'dataType' => 'int',
|
||||
], parent::getOptions($options));
|
||||
}
|
||||
|
||||
public function getData(array $options = [])
|
||||
{
|
||||
$options = $this->getOptions($options);
|
||||
|
||||
$user = $options['user'];
|
||||
if (null === $user || !($user instanceof User)) {
|
||||
throw new \InvalidArgumentException('Widget option "user" must be an instance of ' . User::class);
|
||||
}
|
||||
|
||||
$query = new UserQuery();
|
||||
$query->setCurrentUser($user);
|
||||
|
||||
return $this->user->countUsersForQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPermissions(): array
|
||||
{
|
||||
return ['view_user'];
|
||||
}
|
||||
|
||||
public function getTemplateName(): string
|
||||
{
|
||||
return 'widget/widget-more.html.twig';
|
||||
}
|
||||
}
|
||||
24
src/Widget/Type/UserWidgetTrait.php
Normal file
24
src/Widget/Type/UserWidgetTrait.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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\Type;
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
/**
|
||||
* Needs to be used on a SimpleWidget
|
||||
* @internal
|
||||
*/
|
||||
trait UserWidgetTrait
|
||||
{
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->setOption('user', $user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user