Reimplemented angeltypes about page

This commit is contained in:
Igor Scheller 2023-02-13 19:28:10 +01:00 committed by Michael Weimann
parent 0e033256f0
commit 98a0937b82
11 changed files with 231 additions and 142 deletions

View File

@ -57,6 +57,11 @@ $route->addGroup(
$route->get('/metrics', 'Metrics\\Controller@metrics');
$route->get('/stats', 'Metrics\\Controller@stats');
// Angeltypes
$route->addGroup('/angeltypes', function (RouteCollector $route): void {
$route->get('/about', 'AngelTypesController@about');
});
// News
$route->get('/meetings', 'NewsController@meetings');
$route->addGroup(

View File

@ -32,7 +32,6 @@ function angeltypes_controller()
'view' => angeltype_controller(),
'edit' => angeltype_edit_controller(),
'delete' => angeltype_delete_controller(),
'about' => angeltypes_about_controller(),
'list' => angeltypes_list_controller(),
default => angeltypes_list_controller(),
};
@ -51,27 +50,6 @@ function angeltype_link($angeltype_id, $params = [])
return page_link_to('angeltypes', $params);
}
/**
* Job description for all angeltypes (public to everyone)
*
* @return array
*/
function angeltypes_about_controller()
{
$user = auth()->user();
if ($user) {
$angeltypes = AngelTypes_with_user($user->id);
} else {
$angeltypes = AngelType::all();
}
return [
__('Teams/Job description'),
AngelTypes_about_view($angeltypes, (bool) $user),
];
}
/**
* Delete an Angeltype.
*

View File

@ -500,7 +500,7 @@ function guest_register()
'angel_types',
__('What do you want to do?') . sprintf(
' (<a href="%s">%s</a>)',
page_link_to('angeltypes', ['action' => 'about']),
url('/angeltypes/about'),
__('Description of job types')
),
$angel_types,

View File

@ -309,7 +309,7 @@ function view_user_shifts()
'task_notice' =>
'<sup>1</sup>'
. __('The tasks shown here are influenced by the angeltypes you joined already!')
. ' <a href="' . page_link_to('angeltypes', ['action' => 'about']) . '">'
. ' <a href="' . url('/angeltypes/about') . '">'
. __('Description of the jobs.')
. '</a>',
'shifts_table' => msg() . $shiftCalendarRenderer->render(),

View File

@ -7,7 +7,6 @@ use Engelsystem\Models\UserAngelType;
use Engelsystem\ShiftCalendarRenderer;
use Engelsystem\ShiftsFilterRenderer;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
/**
* AngelTypes
@ -532,7 +531,7 @@ function AngelTypes_list_view($angeltypes, bool $admin_angeltypes)
$admin_angeltypes
? button(page_link_to('angeltypes', ['action' => 'edit']), __('New angeltype'), 'add')
: '',
button(page_link_to('angeltypes', ['action' => 'about']), __('Teams/Job description')),
button(url('/angeltypes/about'), __('angeltypes.about')),
]),
table([
'name' => __('Name'),
@ -543,95 +542,3 @@ function AngelTypes_list_view($angeltypes, bool $admin_angeltypes)
], $angeltypes),
], true);
}
/**
* Renders the about-info for an angeltype.
*
* @param AngelType $angeltype
* @return string
*/
function AngelTypes_about_view_angeltype(AngelType $angeltype)
{
$parsedown = new Parsedown();
$html = '<h2>' . $angeltype->name . '</h2>';
if ($angeltype->hasContactInfo()) {
$html .= AngelTypes_render_contact_info($angeltype);
}
if (isset($angeltype->user_angel_type_id)) {
$buttons = [];
if (!empty($angeltype->user_angel_type_id)) {
$buttons[] = button(
page_link_to(
'user_angeltypes',
['action' => 'delete', 'user_angeltype_id' => $angeltype->user_angel_type_id]
),
icon('box-arrow-right') . __('leave')
);
} else {
$buttons[] = button(
page_link_to('user_angeltypes', ['action' => 'add', 'angeltype_id' => $angeltype->id]),
icon('box-arrow-in-right') . __('join'),
'add'
);
}
$html .= buttons($buttons);
}
if ($angeltype->restricted) {
$html .= info(
__('This angeltype requires the attendance at an introduction meeting. You might find additional information in the description.'),
true
);
}
if ($angeltype->description != '') {
$html .= $parsedown->parse($angeltype->description);
}
$html .= '<hr />';
return $html;
}
/**
* Renders a site that contains every angeltype and its description, basically as an overview of the needed help types.
*
* @param Collection|AngelType[] $angeltypes
* @param bool $user_logged_in
* @return string
*/
function AngelTypes_about_view($angeltypes, $user_logged_in)
{
$buttons = [];
if ($user_logged_in) {
$buttons[] = button(page_link_to('angeltypes'), angeltypes_title(), 'back');
} else {
if (auth()->can('register') && config('registration_enabled')) {
$buttons[] = button(page_link_to('register'), register_title());
}
$buttons[] = button(page_link_to('login'), __('login.login'));
}
$footerConfig = config('footer_items');
if (!empty($footerConfig['FAQ'])) {
$buttons[] = button(
Str::startsWith($footerConfig['FAQ'], '/') ? url($footerConfig['FAQ']) : $footerConfig['FAQ'],
__('FAQ'),
'btn-primary'
);
}
$content = [
buttons($buttons),
'<p>' . __('Here is the list of teams and their tasks. If you have questions, read the FAQ.') . '</p>',
'<hr />',
];
foreach ($angeltypes as $angeltype) {
$content[] = AngelTypes_about_view_angeltype($angeltype);
}
return page_with_title(__('Teams/Job description'), $content, true);
}

View File

@ -197,12 +197,6 @@ msgid "Please read about the jobs you can do to help us."
msgstr ""
"Bitte informiere Dich über die Tätigkeiten bei denen Du uns helfen kannst."
#: resources/views/pages/login.twig:99
#: includes/controller/angeltypes_controller.php:69
#: includes/view/AngelTypes_view.php:501 includes/view/AngelTypes_view.php:598
msgid "Teams/Job description"
msgstr "Team-/Aufgabenbeschreibung"
#: resources/views/pages/login.twig:105
msgid "Please note: You have to activate cookies!"
msgstr "Hinweis: Cookies müssen aktiviert sein!"
@ -2071,26 +2065,10 @@ msgstr "Selbst-Eintragen erlaubt"
msgid "Membership"
msgstr "Mitgliedschaft"
#: includes/view/AngelTypes_view.php:551
msgid ""
"This angeltype requires the attendance at an introduction meeting. "
"You might find additional information in the description."
msgstr ""
"Dieser Engeltyp benötigt eine Einweisung bei einem Einführungstreffen."
"Weitere Informationen findest du möglicherweise in der Beschreibung."
#: includes/view/AngelTypes_view.php:586
msgid "FAQ"
msgstr "FAQ"
#: includes/view/AngelTypes_view.php:591
msgid ""
"Here is the list of teams and their tasks. If you have questions, read the "
"FAQ."
msgstr ""
"Hier ist die Liste der Teams und ihrer Aufgaben. Wenn Du Fragen hast, schaue "
"im FAQ nach."
#: includes/view/EventConfig_view.php:91
msgid "Event Name"
msgstr "Event Name"
@ -3183,3 +3161,28 @@ msgstr "Arbeitseinsatz löschen"
msgid "worklog.delete.info"
msgstr "Möchtest du den Arbeitseinsatz von %s wirklich löschen?"
msgid "angeltypes.angeltypes"
msgstr "Engeltypen"
msgid "angeltypes.about"
msgstr "Teams-/Aufgabenbeschreibung"
msgid "angeltypes.about.text"
msgstr "Hier findest Du die Liste der Teams und ihrer Aufgaben. Wenn Du weitere Fragen hast, schaue in den FAQ nach."
msgid "angeltypes.restricted.hint"
msgstr "Dieser Engeltyp benötigt eine Einweisung bei einem Einführungstreffen. "
"Weitere Informationen findest du möglicherweise in der Beschreibung."
msgid "angeltypes.name"
msgstr "Name"
msgid "angeltypes.dect"
msgstr "DECT"
msgid "angeltypes.email"
msgstr "E-Mail"
msgid "registration.register"
msgstr "Registrieren"

View File

@ -427,3 +427,28 @@ msgstr "Delete work log"
msgid "worklog.delete.info"
msgstr "Do you really want to delete the work log for %s?"
msgid "angeltypes.angeltypes"
msgstr "Angeltypes"
msgid "angeltypes.about"
msgstr "Teams-/Job description"
msgid "angeltypes.about.text"
msgstr "Here you can find the list of teams and their tasks. If you have further questions, have a look at the FAQ."
msgid "angeltypes.restricted.hint"
msgstr "This angeltype requires the attendance at an introduction meeting. "
"You might find additional information in the description."
msgid "angeltypes.name"
msgstr "Name"
msgid "angeltypes.dect"
msgstr "DECT"
msgid "angeltypes.email"
msgstr "E-Mail"
msgid "registration.register"
msgstr "Register"

View File

@ -0,0 +1,114 @@
{% extends "layouts/app.twig" %}
{% import 'macros/base.twig' as m %}
{% block title %}{{ __('angeltypes.about') }}{% endblock %}
{% block content %}
<div class="container">
<h1>{{ block('title') }}</h1>
<div class="col-md-12">
<div class="btn-group mb-3" role="group">
{% if is_user() %}
<a href="{{ url('/angeltypes') }}" class="btn btn-secondary back">
{{ __('angeltypes.angeltypes') }}
</a>
{% else %}
{% if has_permission_to('register') and config('registration_enabled') %}
<a href="{{ url('/register') }}" class="btn btn-secondary back">
{{ __('registration.register') }}
</a>
{% endif %}
<a href="{{ url('/login') }}" class="btn btn-secondary back">
{{ __('login.login') }}
</a>
{% endif %}
{% set footerItems = config('footer_items') %}
{% if footerItems.FAQ is defined %}
{% set url = footerItems.FAQ %}
{% if footerItems.FAQ starts with '/' %}
{% set url = url(footerItems.FAQ) %}
{% endif %}
<a href="{{ url }}" class="btn btn-primary">{{ __('faq.faq') }}</a>
{% endif %}
</div>
</div>
<div class="col-md-12">
<p>{{ __('angeltypes.about.text') }}</p>
</div>
<div class="row">
{% for angeltype in angeltypes %}
<div class="col-md-6">
<div class="card border-info {{ m.type_bg_class() }} mb-3">
<h4 class="card-header bg-info">
{{ angeltype.name }}
{% if is_user() %}
<a href="{{ url('angeltypes', {'action': 'view', 'angeltype_id': angeltype.id}) }}"
class="btn btn-secondary float-end">
{{ m.icon('arrow-right') }}
</a>
{% endif %}
{% if angeltype.restricted %}
<button type="button" class="btn btn-info float-end"
data-bs-toggle="popover" data-bs-title="{{ angeltype.name | e('html_attr') }}"
data-bs-content="{{ __('angeltypes.restricted.hint') | e('html_attr') }}"
>
{{ m.icon('info-circle-fill') }}
</button>
{% endif %}
</h4>
<div class="card-body row">
<div class="card-text">
{{ angeltype.description | md }}
</div>
{% if angeltype.hasContactInfo() %}
<dl class="row card-text">
{% for type, info in {
'contact_name': {'name': __('angeltypes.name')},
'contact_dect': {'name': __('angeltypes.dect'), 'url': 'tel'},
'contact_email': {'name': __('angeltypes.email'), 'url': 'email'},
} %}
{% if angeltype[type] and (type != 'contact_dect' or config('enable_dect')) %}
<dt class="col-sm-3">{{ info.name }}</dt>
<dd class="col-sm-9">
{% if info.url is defined %}
<a href="{{ info['url'] }}:{{ angeltype[type] | e('html_attr') }}">
{{ angeltype[type] }}
</a>
{% else %}
{{ angeltype[type] }}
{% endif %}
</dd>
{% endif %}
{% endfor %}
</dl>
{% endif %}
</div>
</div>
</div>
{% if loop.index0 % 2 %}
</div>
<div class="row">
{% endif %}
{% endfor %}
</div>
</div>
{% endblock %}

View File

@ -118,8 +118,8 @@
<div class="col-sm-6 text-center">
<h2>{{ __('What can I do?') }}</h2>
<p>{{ __('Please read about the jobs you can do to help us.') }}</p>
<a href="{{ url('angeltypes', {'action': 'about'}) }}" class="btn btn-primary">
{{ __('Teams/Job description') }} &raquo;
<a href="{{ url('/angeltypes/about') }}" class="btn btn-primary">
{{ __('angeltypes.about') }} &raquo;
</a>
</div>

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Controllers;
use Engelsystem\Http\Response;
use Engelsystem\Models\AngelType;
class AngelTypesController extends BaseController
{
public function __construct(protected Response $response)
{
}
public function about(): Response
{
$angeltypes = AngelType::all();
return $this->response->withView(
'pages/angeltypes/about',
['angeltypes' => $angeltypes]
);
}
}

View File

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Test\Unit\Controllers;
use Engelsystem\Controllers\AngelTypesController;
use Engelsystem\Http\Response;
use Engelsystem\Test\Unit\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
class AngelTypesControllerTest extends TestCase
{
/**
* @covers \Engelsystem\Controllers\AngelTypesController::__construct
* @covers \Engelsystem\Controllers\AngelTypesController::about
*/
public function testIndex(): void
{
/** @var Response|MockObject $response */
$response = $this->createMock(Response::class);
$this->setExpects(
$response,
'withView',
['pages/angeltypes/about']
);
$controller = new AngelTypesController($response);
$controller->about();
}
}