From 98a0937b82cff1c7a806c0edb3c471d13d0c2e0f Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 13 Feb 2023 19:28:10 +0100 Subject: [PATCH] Reimplemented angeltypes about page --- config/routes.php | 5 + includes/controller/angeltypes_controller.php | 22 ---- includes/pages/guest_login.php | 2 +- includes/pages/user_shifts.php | 2 +- includes/view/AngelTypes_view.php | 95 +-------------- resources/lang/de_DE/default.po | 47 ++++---- resources/lang/en_US/default.po | 25 ++++ resources/views/pages/angeltypes/about.twig | 114 ++++++++++++++++++ resources/views/pages/login.twig | 4 +- src/Controllers/AngelTypesController.php | 25 ++++ .../Controllers/AngelTypesControllerTest.php | 32 +++++ 11 files changed, 231 insertions(+), 142 deletions(-) create mode 100644 resources/views/pages/angeltypes/about.twig create mode 100644 src/Controllers/AngelTypesController.php create mode 100644 tests/Unit/Controllers/AngelTypesControllerTest.php diff --git a/config/routes.php b/config/routes.php index 51991f71..a28e697d 100644 --- a/config/routes.php +++ b/config/routes.php @@ -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( diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index c2a54774..28c82fe1 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -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. * diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 9a2b4e77..4498c17f 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -500,7 +500,7 @@ function guest_register() 'angel_types', __('What do you want to do?') . sprintf( ' (%s)', - page_link_to('angeltypes', ['action' => 'about']), + url('/angeltypes/about'), __('Description of job types') ), $angel_types, diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 0e5ca35b..c32c9d75 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -309,7 +309,7 @@ function view_user_shifts() 'task_notice' => '1' . __('The tasks shown here are influenced by the angeltypes you joined already!') - . ' ' + . ' ' . __('Description of the jobs.') . '', 'shifts_table' => msg() . $shiftCalendarRenderer->render(), diff --git a/includes/view/AngelTypes_view.php b/includes/view/AngelTypes_view.php index 6292ec09..a9b4797b 100644 --- a/includes/view/AngelTypes_view.php +++ b/includes/view/AngelTypes_view.php @@ -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 = '

' . $angeltype->name . '

'; - - 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 .= '
'; - - 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), - '

' . __('Here is the list of teams and their tasks. If you have questions, read the FAQ.') . '

', - '
', - ]; - foreach ($angeltypes as $angeltype) { - $content[] = AngelTypes_about_view_angeltype($angeltype); - } - - return page_with_title(__('Teams/Job description'), $content, true); -} diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 11360467..16f1423b 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -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" diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index 07663f04..aaa353e5 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -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" diff --git a/resources/views/pages/angeltypes/about.twig b/resources/views/pages/angeltypes/about.twig new file mode 100644 index 00000000..749479f8 --- /dev/null +++ b/resources/views/pages/angeltypes/about.twig @@ -0,0 +1,114 @@ +{% extends "layouts/app.twig" %} +{% import 'macros/base.twig' as m %} + +{% block title %}{{ __('angeltypes.about') }}{% endblock %} + +{% block content %} +
+

{{ block('title') }}

+ +
+
+ {% if is_user() %} + + {{ __('angeltypes.angeltypes') }} + + {% else %} + {% if has_permission_to('register') and config('registration_enabled') %} + + {{ __('registration.register') }} + + {% endif %} + + {{ __('login.login') }} + + {% 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 %} + {{ __('faq.faq') }} + {% endif %} +
+
+ +
+

{{ __('angeltypes.about.text') }}

+
+ +
+ {% for angeltype in angeltypes %} + +
+
+ +

+ {{ angeltype.name }} + + {% if is_user() %} + + {{ m.icon('arrow-right') }} + + {% endif %} + + {% if angeltype.restricted %} + + {% endif %} +

+ +
+ +
+ {{ angeltype.description | md }} +
+ + {% if angeltype.hasContactInfo() %} +
+ {% 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')) %} + +
{{ info.name }}
+ +
+ {% if info.url is defined %} + + {{ angeltype[type] }} + + {% else %} + {{ angeltype[type] }} + {% endif %} +
+ + {% endif %} + {% endfor %} +
+ {% endif %} + +
+ +
+
+ + {% if loop.index0 % 2 %} +
+
+ {% endif %} + + {% endfor %} +
+ +
+{% endblock %} diff --git a/resources/views/pages/login.twig b/resources/views/pages/login.twig index 59ffd1dc..27400ffc 100644 --- a/resources/views/pages/login.twig +++ b/resources/views/pages/login.twig @@ -118,8 +118,8 @@

{{ __('What can I do?') }}

{{ __('Please read about the jobs you can do to help us.') }}

- - {{ __('Teams/Job description') }} » + + {{ __('angeltypes.about') }} »
diff --git a/src/Controllers/AngelTypesController.php b/src/Controllers/AngelTypesController.php new file mode 100644 index 00000000..24f4e120 --- /dev/null +++ b/src/Controllers/AngelTypesController.php @@ -0,0 +1,25 @@ +response->withView( + 'pages/angeltypes/about', + ['angeltypes' => $angeltypes] + ); + } +} diff --git a/tests/Unit/Controllers/AngelTypesControllerTest.php b/tests/Unit/Controllers/AngelTypesControllerTest.php new file mode 100644 index 00000000..5c89bd5e --- /dev/null +++ b/tests/Unit/Controllers/AngelTypesControllerTest.php @@ -0,0 +1,32 @@ +createMock(Response::class); + + $this->setExpects( + $response, + 'withView', + ['pages/angeltypes/about'] + ); + + $controller = new AngelTypesController($response); + $controller->about(); + } +}