added configurable view after login (#523)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\Type\InitialViewType;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
@@ -30,8 +31,9 @@ class HomepageController extends AbstractController
|
||||
*/
|
||||
public function indexAction(Request $request)
|
||||
{
|
||||
// make me configurable via UserPreference
|
||||
$route = 'timesheet';
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$route = $user->getPreferenceValue('login.initial_view', InitialViewType::DEFAULT_VIEW);
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
@@ -55,6 +55,7 @@ class ProfileController extends AbstractController
|
||||
|
||||
/**
|
||||
* @Route(path="/", name="fos_user_profile_show", methods={"GET"})
|
||||
* @Route(path="/", name="my_profile", methods={"GET"})
|
||||
*/
|
||||
public function profileAction()
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@ use App\Entity\UserPreference;
|
||||
use App\Event\PrepareUserEvent;
|
||||
use App\Event\UserPreferenceEvent;
|
||||
use App\Form\Type\CalendarViewType;
|
||||
use App\Form\Type\InitialViewType;
|
||||
use App\Form\Type\LanguageType;
|
||||
use App\Form\Type\SkinType;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
@@ -124,6 +125,11 @@ class UserPreferenceSubscriber implements EventSubscriberInterface
|
||||
->setName('calendar.initial_view')
|
||||
->setValue(CalendarViewType::DEFAULT_VIEW)
|
||||
->setType(CalendarViewType::class),
|
||||
|
||||
(new UserPreference())
|
||||
->setName('login.initial_view')
|
||||
->setValue(InitialViewType::DEFAULT_VIEW)
|
||||
->setType(InitialViewType::class),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
89
src/Form/Type/InitialViewType.php
Normal file
89
src/Form/Type/InitialViewType.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
|
||||
/**
|
||||
* Custom form field type to select the initial view, where the user should be redirected to after login.
|
||||
*/
|
||||
class InitialViewType extends AbstractType
|
||||
{
|
||||
public const DEFAULT_VIEW = 'timesheet';
|
||||
|
||||
public const ALLOWED_VIEWS = [
|
||||
'dashboard' => 'menu.homepage',
|
||||
'timesheet' => 'menu.timesheet',
|
||||
'calendar' => 'calendar.title',
|
||||
'my_profile' => 'profile.title',
|
||||
'admin_timesheet' => 'menu.admin_timesheet',
|
||||
'invoice' => 'menu.invoice',
|
||||
'admin_user' => 'menu.admin_user',
|
||||
'admin_customer' => 'menu.admin_customer',
|
||||
'admin_project' => 'menu.admin_project',
|
||||
'admin_activity' => 'menu.admin_activity',
|
||||
];
|
||||
|
||||
protected const ROUTE_PERMISSION = [
|
||||
'dashboard' => 'menu.homepage',
|
||||
'timesheet' => 'view_own_timesheet',
|
||||
'calendar' => 'view_own_timesheet',
|
||||
'my_profile' => 'view_own_profile',
|
||||
'admin_timesheet' => 'view_other_timesheet',
|
||||
'invoice' => 'view_invoice',
|
||||
'admin_user' => 'view_user',
|
||||
'admin_customer' => 'view_customer',
|
||||
'admin_project' => 'view_project',
|
||||
'admin_activity' => 'view_activity',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var AuthorizationCheckerInterface
|
||||
*/
|
||||
protected $voter;
|
||||
|
||||
/**
|
||||
* @param AuthorizationCheckerInterface $voter
|
||||
*/
|
||||
public function __construct(AuthorizationCheckerInterface $voter)
|
||||
{
|
||||
$this->voter = $voter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$choices = [];
|
||||
foreach (self::ROUTE_PERMISSION as $route => $permission) {
|
||||
if ($this->voter->isGranted($permission)) {
|
||||
$name = self::ALLOWED_VIEWS[$route];
|
||||
$choices[$name] = $route;
|
||||
}
|
||||
}
|
||||
|
||||
$resolver->setDefaults([
|
||||
'required' => true,
|
||||
'choices' => $choices,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
{% import "macros/datatables.html.twig" as tables %}
|
||||
{% import "macros/toolbar.html.twig" as toolbar %}
|
||||
|
||||
{% block page_title %}{{ 'timesheet.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'timesheet.subtitle'|trans }}{% endblock %}
|
||||
{% block page_title %}{{ 'calendar.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'calendar.subtitle'|trans }}{% endblock %}
|
||||
{% block page_actions %}{{ widgets.page_actions({'list': path('timesheet'), 'create': path('timesheet_create')}) }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserPreference;
|
||||
use App\Form\Type\InitialViewType;
|
||||
use App\Form\Type\LanguageType;
|
||||
|
||||
/**
|
||||
@@ -31,13 +32,20 @@ class HomepageControllerTest extends ControllerBaseTest
|
||||
$this->assertIsRedirect($client, '/en/timesheet/');
|
||||
}
|
||||
|
||||
public function testIndexActionWithChangedLanguage()
|
||||
public function testIndexActionWithChangedPreferences()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$user = $this->getUserByRole($em, User::ROLE_USER);
|
||||
|
||||
$pref = (new UserPreference())
|
||||
->setName('login.initial_view')
|
||||
->setValue('my_profile')
|
||||
->setType(InitialViewType::class);
|
||||
|
||||
$user->addPreference($pref);
|
||||
|
||||
$pref = (new UserPreference())
|
||||
->setName('language')
|
||||
->setValue('ar')
|
||||
@@ -48,6 +56,6 @@ class HomepageControllerTest extends ControllerBaseTest
|
||||
$em->persist($pref);
|
||||
|
||||
$this->request($client, '/homepage');
|
||||
$this->assertIsRedirect($client, '/ar/timesheet/');
|
||||
$this->assertIsRedirect($client, '/ar/profile/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,6 +387,10 @@
|
||||
<source>label.calendar.initial_view</source>
|
||||
<target>Initiale Darstellung des Kalenders</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="label.login.initial_view">
|
||||
<source>label.login.initial_view</source>
|
||||
<target>Initiale Ansicht nach Anmeldung</target>
|
||||
</trans-unit>
|
||||
<!-- Options for user-preference label.calendar.initial_view -->
|
||||
<trans-unit id="month">
|
||||
<source>month</source>
|
||||
@@ -401,6 +405,18 @@
|
||||
<target>Tag</target>
|
||||
</trans-unit>
|
||||
|
||||
<!--
|
||||
User timesheet calendar
|
||||
-->
|
||||
<trans-unit id="calendar.title">
|
||||
<source>calendar.title</source>
|
||||
<target>Kalender</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="calendar.subtitle">
|
||||
<source>calendar.subtitle</source>
|
||||
<target>Ansicht und Verwaltung ihrer gebuchten Zeiteinträge anhand eines Kalenders</target>
|
||||
</trans-unit>
|
||||
|
||||
<!--
|
||||
Help - Manual
|
||||
-->
|
||||
|
||||
@@ -387,6 +387,10 @@
|
||||
<source>label.calendar.initial_view</source>
|
||||
<target>Initial calendar view</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="label.login.initial_view">
|
||||
<source>label.login.initial_view</source>
|
||||
<target>Initial view after login</target>
|
||||
</trans-unit>
|
||||
<!-- Options for user-preference label.calendar.initial_view -->
|
||||
<trans-unit id="month">
|
||||
<source>month</source>
|
||||
@@ -401,6 +405,18 @@
|
||||
<target>Day</target>
|
||||
</trans-unit>
|
||||
|
||||
<!--
|
||||
User timesheet calendar
|
||||
-->
|
||||
<trans-unit id="calendar.title">
|
||||
<source>calendar.title</source>
|
||||
<target>Calendar</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="calendar.subtitle">
|
||||
<source>calendar.subtitle</source>
|
||||
<target>View and manage your timesheet data within a calendar</target>
|
||||
</trans-unit>
|
||||
|
||||
<!--
|
||||
Help - Manual
|
||||
-->
|
||||
|
||||
Reference in New Issue
Block a user