re-style error pages (#1210)

This commit is contained in:
Kevin Papst
2019-10-31 14:20:53 +01:00
committed by GitHub
parent 8eec97deb5
commit cd88901868
7 changed files with 143 additions and 73 deletions

View File

@@ -14,10 +14,11 @@ use KevinPapst\AdminLTEBundle\Event\SidebarMenuEvent;
use KevinPapst\AdminLTEBundle\Model\MenuItemModel; use KevinPapst\AdminLTEBundle\Model\MenuItemModel;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
/** /**
* Class MenuBuilder configures the main navigation. * Class MenuBuilder configures the main navigation.
* @internal
*/ */
class MenuBuilderSubscriber implements EventSubscriberInterface class MenuBuilderSubscriber implements EventSubscriberInterface
{ {
@@ -26,19 +27,14 @@ class MenuBuilderSubscriber implements EventSubscriberInterface
*/ */
private $eventDispatcher; private $eventDispatcher;
/** /**
* @var AuthorizationCheckerInterface * @var TokenStorageInterface
*/ */
private $security; private $tokenStorage;
/** public function __construct(EventDispatcherInterface $dispatcher, TokenStorageInterface $storage)
* MenuBuilderSubscriber constructor.
* @param EventDispatcherInterface $dispatcher
* @param AuthorizationCheckerInterface $security
*/
public function __construct(EventDispatcherInterface $dispatcher, AuthorizationCheckerInterface $security)
{ {
$this->eventDispatcher = $dispatcher; $this->eventDispatcher = $dispatcher;
$this->security = $security; $this->tokenStorage = $storage;
} }
/** /**
@@ -72,7 +68,7 @@ class MenuBuilderSubscriber implements EventSubscriberInterface
); );
// error pages don't have a user and will fail when is_granted() is called // error pages don't have a user and will fail when is_granted() is called
if (null !== $event->getRequest()->getUser()) { if (null !== $this->tokenStorage->getToken()) {
$this->eventDispatcher->dispatch($menuEvent); $this->eventDispatcher->dispatch($menuEvent);
} }

View File

@@ -1 +1,5 @@
{% extends 'error.html.twig' %} {% extends 'error.html.twig' %}
{% block error_icon %}
<i class="far fa-frown"></i>
{% endblock %}

View File

@@ -1,33 +1,51 @@
{% extends 'base.html.twig' %} {% extends '@AdminLTE/layout/security-layout.html.twig' %}
{% block page_title %}{{ 'http_error.title'|trans({}, 'exceptions') }}{% endblock %} {% set errorTitleKey = "http_error_#{status_code}.description" %}
{% block page_subtitle %}{{ status_code }}{% endblock %} {% set errorTitleTrans = errorTitleKey|trans({ '%status_code%': status_code }, 'exceptions') %}
{% if errorTitleKey == errorTitleTrans %}
{% block main %} {% set errorTitleKey = 'http_error.description' %}
{% set errorTitleKey = "http_error_#{status_code}.description" %}
{% set errorTitleTrans = errorTitleKey|trans({ '%status_code%': status_code }, 'exceptions') %} {% set errorTitleTrans = errorTitleKey|trans({ '%status_code%': status_code }, 'exceptions') %}
{% if errorTitleKey == errorTitleTrans %} {% endif %}
{% set errorTitleKey = 'http_error.description' %}
{% set errorTitleTrans = errorTitleKey|trans({ '%status_code%': status_code }, 'exceptions') %}
{% endif %}
{% set errorMessageKey = "http_error_#{status_code}.suggestion" %} {% set errorMessageKey = "http_error_#{status_code}.suggestion" %}
{% set errorMessageTrans = errorMessageKey|trans({ '%status_code%': status_code }, 'exceptions') %}
{% if errorMessageKey == errorMessageTrans %}
{% set errorMessageKey = 'http_error.suggestion' %}
{% set errorMessageTrans = errorMessageKey|trans({ '%status_code%': status_code }, 'exceptions') %} {% set errorMessageTrans = errorMessageKey|trans({ '%status_code%': status_code }, 'exceptions') %}
{% if errorMessageKey == errorMessageTrans %} {% endif %}
{% set errorMessageKey = 'http_error.suggestion' %}
{% set errorMessageTrans = errorMessageKey|trans({ '%status_code%': status_code }, 'exceptions') %}
{% endif %}
<div class="error-page"> {% block logo_login %}{% include 'partials/logo_login.html.twig' %}{% endblock %}
<h2 class="headline {% block error_class %}text-yellow{% endblock %}"> {{ status_code }}</h2> {% block title %}{{ status_code }} - {{ 'http_error.title'|trans({}, 'exceptions') }}{% endblock %}
{% block error_content %} {% block head %}
<div class="error-content"> {{ parent() }}
<h3>{% block error_icon %}{% endblock %} {{ errorTitleTrans }}</h3> {% include 'partials/head.html.twig' %}
<p>{{ errorMessageTrans }}</p>
<a class="btn btn-primary" href="javascript:window.history.back();">{{ 'action.back'|trans }}</a>
</div>
{% endblock %}
</div>
{% endblock %} {% endblock %}
{% block stylesheets %}
{{ encore_entry_link_tags('app') }}
{% endblock %}
{% block javascripts %}
{{ encore_entry_script_tags('app') }}
{% endblock %}
{% block login_box_icon %}{% block error_icon %}{% endblock %}{% endblock %}
{% block login_box_msg %}
{{ errorTitleTrans }}
{% endblock %}
{% block login_form %}
{% block error_content %}
<p>
{{ errorMessageTrans }}
</p>
<p>
<a class="btn btn-primary" href="{{ path('dashboard') }}">{{ 'dashboard.title'|trans }}</a>
</p>
{% endblock %}
{% endblock %}
{% block login_social_auth %}{% endblock %}
{% block login_actions %}{% endblock %}

View File

@@ -50,25 +50,4 @@ class DashboardControllerTest extends ControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful()); $this->assertTrue($client->getResponse()->isSuccessful());
$this->assertMainContentClass($client, 'dashboard'); $this->assertMainContentClass($client, 'dashboard');
} }
/**
* This is not a test for the dashbaord, but for the general layout
*/
public function testUserMenuIsAvailable()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$user = $this->getUserByRole($em, User::ROLE_USER);
$this->request($client, '/dashboard/');
$this->assertTrue($client->getResponse()->isSuccessful());
$content = $client->getResponse()->getContent();
$this->assertStringContainsString('<li class="dropdown user-menu">', $content);
$this->assertStringContainsString('<a href="/en/profile/' . $user->getUsername() . '">', $content);
$this->assertStringContainsString('<a href="/en/profile/' . $user->getUsername() . '/prefs">', $content);
$this->assertStringContainsString('<a href="/en/logout">', $content);
}
} }

View File

@@ -0,0 +1,75 @@
<?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\Tests\Controller;
use App\Entity\User;
use Symfony\Component\HttpKernel\HttpKernelBrowser;
/**
* @group integration
*/
class LayoutTest extends ControllerBaseTest
{
public function testNavigationMenus()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$user = $this->getUserByRole($em, User::ROLE_USER);
$this->request($client, '/dashboard/');
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertHasMainHeader($client, $user);
$this->assertHasSidebar($client, $user);
}
protected function assertHasMainHeader(HttpKernelBrowser $client, User $user)
{
// TODO improve me
// main-header > a.logo
// # href = homepage
// && > span.logo-mini
// && > span.logo-lg
// && > nav.navbar.navbar-static-top
// && div.navbar-custom-menu
$content = $client->getResponse()->getContent();
$this->assertStringContainsString('<li class="dropdown user-menu">', $content);
$this->assertStringContainsString('<a href="/en/profile/' . $user->getUsername() . '">', $content);
$this->assertStringContainsString('<a href="/en/profile/' . $user->getUsername() . '/prefs">', $content);
$this->assertStringContainsString('<a href="/en/logout">', $content);
}
protected function assertHasSidebar(HttpKernelBrowser $client, User $user)
{
// TODO improve me
// aside.main-sidebar
// && section.sidebar
// && ul.sidebar-menu tree
// && li#dashboard > a href=dashboard
// && li#... with links
$content = $client->getResponse()->getContent();
$this->assertStringContainsString('<li id="dashboard"', $content);
$this->assertStringContainsString('<a href="/en/dashboard/">', $content);
$this->assertStringContainsString('<span>Dashboard</span>', $content);
$this->assertStringContainsString('<li id="timesheet"', $content);
$this->assertStringContainsString('<a href="/en/timesheet/">', $content);
$this->assertStringContainsString('<span>My times</span>', $content);
$this->assertStringContainsString('<li id="calendar"', $content);
$this->assertStringContainsString('<a href="/en/calendar/">', $content);
$this->assertStringContainsString('<span>Calendar</span>', $content);
}
}

View File

@@ -16,30 +16,29 @@
</trans-unit> </trans-unit>
<trans-unit id="http_error.description"> <trans-unit id="http_error.description">
<source>http_error.description</source> <source>http_error.description</source>
<target>Oops! Ein Fehler ist aufgetreten.</target> <target>Etwas läuft falsch</target>
</trans-unit> </trans-unit>
<trans-unit id="http_error.suggestion"> <trans-unit id="http_error.suggestion">
<source>http_error.suggestion</source> <source>http_error.suggestion</source>
<target> <target>
Ein unerwarteter Fehler ist aufgetreten. Ein kritischer Fehler ist aufgetreten.
Möglicherweise haben Sie einen Bug gefunden, daher kontaktieren Sie bitte ihren Administrator Möglicherweise haben Sie einen Software Fehler gefunden, kontaktieren Sie bitte ihren Administrator wenn der Fehler bestehen bleibt.
wenn der Fehler nach einem erneuten Versuch immer noch vorhanden sein sollte.
</target> </target>
</trans-unit> </trans-unit>
<trans-unit id="http_error_404.description"> <trans-unit id="http_error_404.description">
<source>http_error_404.description</source> <source>http_error_404.description</source>
<target>Oops! Seite wurde nicht gefunden.</target> <target>Seite wurde nicht gefunden</target>
</trans-unit> </trans-unit>
<trans-unit id="http_error_404.suggestion"> <trans-unit id="http_error_404.suggestion">
<source>http_error_404.suggestion</source> <source>http_error_404.suggestion</source>
<target> <target>
Wir konnten die angeforderte Seite leider nicht finden. Wir konnten die angeforderte Seite leider nicht finden.
Bitte wechseln Sie zurück zu ihrem Dashboard und starten von vorne. Bitte wechseln Sie zu ihrem Dashboard und starten von vorne.
</target> </target>
</trans-unit> </trans-unit>
<trans-unit id="http_error_403.description"> <trans-unit id="http_error_403.description">
<source>http_error_403.description</source> <source>http_error_403.description</source>
<target>Diese Seite ist geschützt.</target> <target>Seite ist geschützt</target>
</trans-unit> </trans-unit>
<trans-unit id="http_error_403.suggestion"> <trans-unit id="http_error_403.suggestion">
<source>http_error_403.suggestion</source> <source>http_error_403.suggestion</source>

View File

@@ -16,35 +16,34 @@
</trans-unit> </trans-unit>
<trans-unit id="http_error.description"> <trans-unit id="http_error.description">
<source>http_error.description</source> <source>http_error.description</source>
<target>Oops! An error occured.</target> <target>Something is wrong</target>
</trans-unit> </trans-unit>
<trans-unit id="http_error.suggestion"> <trans-unit id="http_error.suggestion">
<source>http_error.suggestion</source> <source>http_error.suggestion</source>
<target> <target>
An unexpected error occured, please try again. A critical error occurred, please try again.
You may have found a bug, so please contact your administrator if the problem You may have found a software problem, please contact your administrator if the problem persists.
doesn't go away after you tried it again.
</target> </target>
</trans-unit> </trans-unit>
<trans-unit id="http_error_404.description"> <trans-unit id="http_error_404.description">
<source>http_error_404.description</source> <source>http_error_404.description</source>
<target>Oops! Page not found.</target> <target>Page not found</target>
</trans-unit> </trans-unit>
<trans-unit id="http_error_404.suggestion"> <trans-unit id="http_error_404.suggestion">
<source>http_error_404.suggestion</source> <source>http_error_404.suggestion</source>
<target> <target>
We could not find the page you were looking for. We could not find the page you were looking for.
Meanwhile, you may return to your dashboard and start over. Please return to your dashboard and start over.
</target> </target>
</trans-unit> </trans-unit>
<trans-unit id="http_error_403.description"> <trans-unit id="http_error_403.description">
<source>http_error_403.description</source> <source>http_error_403.description</source>
<target>This page is restricted.</target> <target>Page is restricted</target>
</trans-unit> </trans-unit>
<trans-unit id="http_error_403.suggestion"> <trans-unit id="http_error_403.suggestion">
<source>http_error_403.suggestion</source> <source>http_error_403.suggestion</source>
<target> <target>
Sorry, but you do not have sufficient permissions to see this page. Sorry, but you don't have sufficient permissions to see this page.
Please talk to your administrator if you think this is an error. Please talk to your administrator if you think this is an error.
</target> </target>
</trans-unit> </trans-unit>