From 7f0eb97f9b10b862f819a52e856a5932fbb8a109 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Sat, 9 Apr 2022 13:32:08 +0200 Subject: [PATCH] show apikey details in modal-overlay; todo: edit allowed_from and valid_until Signed-off-by: Michael Kaufmann --- api_keys.php | 1 - install/froxlor.sql | 2 +- lib/Froxlor/UI/Callbacks/Text.php | 19 +++++++ lib/Froxlor/UI/Listing.php | 5 ++ lib/formfields/formfield.api_key.php | 57 ++++++++++++++++++++ lib/tablelisting/tablelisting.apikeys.php | 7 +-- lng/english.lng.php | 3 +- lng/german.lng.php | 1 + templates/Froxlor/form/form.html.twig | 40 +++++++------- templates/Froxlor/table/macros.html.twig | 50 +++++++++++------ templates/Froxlor/user/inline-form.html.twig | 2 + 11 files changed, 143 insertions(+), 44 deletions(-) create mode 100644 lib/formfields/formfield.api_key.php create mode 100644 templates/Froxlor/user/inline-form.html.twig diff --git a/api_keys.php b/api_keys.php index 710a70c6..d57fa51b 100644 --- a/api_keys.php +++ b/api_keys.php @@ -30,7 +30,6 @@ use Froxlor\UI\Request; $del_stmt = Database::prepare("DELETE FROM `" . TABLE_API_KEYS . "` WHERE id = :id"); $success_message = ""; $id = (int) Request::get('id'); -$area = AREA; // do the delete and then just show a success-message and the apikeys list again if ($action == 'delete') { diff --git a/install/froxlor.sql b/install/froxlor.sql index 53a9673b..ef49e250 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -864,7 +864,7 @@ CREATE TABLE `panel_fpmdaemons` ( INSERT INTO `panel_fpmdaemons` (`id`, `description`, `reload_cmd`, `config_dir`) VALUES -(1, 'System default', 'service php7.3-fpm restart', '/etc/php/7.3/fpm/pool.d/'); +(1, 'System default', 'service php7.4-fpm restart', '/etc/php/7.4/fpm/pool.d/'); diff --git a/lib/Froxlor/UI/Callbacks/Text.php b/lib/Froxlor/UI/Callbacks/Text.php index 7e98fab1..12e6ead0 100644 --- a/lib/Froxlor/UI/Callbacks/Text.php +++ b/lib/Froxlor/UI/Callbacks/Text.php @@ -4,6 +4,7 @@ namespace Froxlor\UI\Callbacks; use Froxlor\PhpHelper; use Froxlor\UI\Panel\UI; +use Froxlor\Froxlor; use Froxlor\User; /** @@ -65,4 +66,22 @@ class Text { return wordwrap($attributes['data'], 100, '
', true); } + + public static function apikeyDetailModal(array $attributes): array + { + $linker = UI::getLinker(); + $result = $attributes['fields']; + $apikey_data = include Froxlor::getInstallDir() . '/lib/formfields/formfield.api_key.php'; + + $body = UI::twig()->render(UI::getTheme().'/user/inline-form.html.twig', [ + 'formaction' => $linker->getLink(array('section' => 'index', 'page' => 'apikeys')), + 'formdata' => $apikey_data['apikey'], + 'editid' => $attributes['fields']['id'] + ]); + return [ + 'id' => 'akModal' . $attributes['fields']['id'], + 'title' => 'API-key ' . ($attributes['fields']['loginname'] ?? $attributes['fields']['adminname']), + 'body' => $body + ]; + } } diff --git a/lib/Froxlor/UI/Listing.php b/lib/Froxlor/UI/Listing.php index 41cdab71..4d55dc3f 100644 --- a/lib/Froxlor/UI/Listing.php +++ b/lib/Froxlor/UI/Listing.php @@ -171,6 +171,11 @@ class Listing // Set actual link from linker $actions[$key]['href'] = $linker->getLink($action['href']); } + + // modal trigger - always require a valid callback + if (isset($action['modal']) && !empty($action['modal'])) { + $actions[$key]['modal'] = call_user_func($action['modal'], ['fields' => $item]); + } } return $actions; diff --git a/lib/formfields/formfield.api_key.php b/lib/formfields/formfield.api_key.php new file mode 100644 index 00000000..2bff23a4 --- /dev/null +++ b/lib/formfields/formfield.api_key.php @@ -0,0 +1,57 @@ + (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Formfields + * + */ +return [ + 'apikey' => [ + 'title' => UI::getLng('menue.main.apikeys'), + 'sections' => [ + 'section_a' => [ + 'fields' => [ + 'loginname' => [ + 'label' => UI::getLng('login.username'), + 'type' => 'label', + 'value' => $result['loginname'] ?? $result['adminname'] + ], + 'apikey' => [ + 'label' => 'API key', + 'type' => 'text', + 'readonly' => true, + 'value' => $result['apikey'] + ], + 'secret' => [ + 'label' => 'Secret', + 'type' => 'text', + 'readonly' => true, + 'value' => $result['secret'] + ], + 'allowed_from' => [ + 'label' => UI::getLng('apikeys.allowed_from'), + 'type' => 'text', + 'value' => $result['allowed_from'], + ], + 'valid_until' => [ + 'label' => UI::getLng('apikeys.valid_until'), + 'type' => 'text', + 'value' => $result['valid_until'], + 'format_callback' => [Text::class, 'timestampUntil'], + ] + ] + ] + ] + ] +]; diff --git a/lib/tablelisting/tablelisting.apikeys.php b/lib/tablelisting/tablelisting.apikeys.php index a87fd0ac..87698817 100644 --- a/lib/tablelisting/tablelisting.apikeys.php +++ b/lib/tablelisting/tablelisting.apikeys.php @@ -61,12 +61,7 @@ return [ 'show' => [ 'icon' => 'fa fa-eye', 'title' => $lng['apikeys']['clicktoview'], - 'href' => [ - 'section' => 'index', - 'page' => 'apikeys', - 'action' => '#', - 'id' => ':id' - ], + 'modal' => [Text::class, 'apikeyDetailModal'], ], 'delete' => [ 'icon' => 'fa fa-trash', diff --git a/lng/english.lng.php b/lng/english.lng.php index 228af112..6e36e933 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -2164,4 +2164,5 @@ $lng['panel']['backtooverview'] = 'Back to overview'; $lng['panel']['settingsmode'] = 'Mode'; $lng['panel']['settingsmodebasic'] = 'Basic'; $lng['panel']['settingsmodeadvanced'] = 'Advanced'; -$lng['panel']['settingsmodetoggle'] = 'Click to toggle mode'; \ No newline at end of file +$lng['panel']['settingsmodetoggle'] = 'Click to toggle mode'; +$lng['panel']['modalclose'] = 'Close'; diff --git a/lng/german.lng.php b/lng/german.lng.php index fb9961e9..bed2dfeb 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1803,3 +1803,4 @@ $lng['panel']['settingsmode'] = 'Modus'; $lng['panel']['settingsmodebasic'] = 'Einfach'; $lng['panel']['settingsmodeadvanced'] = 'Erweitert'; $lng['panel']['settingsmodetoggle'] = 'Modus umschalten'; +$lng['panel']['modalclose'] = 'Schließen'; diff --git a/templates/Froxlor/form/form.html.twig b/templates/Froxlor/form/form.html.twig index 46738174..629daff0 100644 --- a/templates/Froxlor/form/form.html.twig +++ b/templates/Froxlor/form/form.html.twig @@ -1,4 +1,4 @@ -{% macro form(form_data, formaction, title = "", hiddenid = "") %} +{% macro form(form_data, formaction, title = "", hiddenid = "", nosubmit = false) %} {% import "Froxlor/form/formfields.html.twig" as formfields %} @@ -21,25 +21,27 @@ {% endfor %} - -
- {% if hiddenid is not empty %} - - {% endif %} - - - - -
- {% if form_data.buttons is defined and form_data.buttons is iterable %} - {% for btn in form_data.buttons %} - - {% endfor %} - {% else %} - - + {% if nosubmit == false %} + +
+ {% if hiddenid is not empty %} + {% endif %} + + + + +
+ {% if form_data.buttons is defined and form_data.buttons is iterable %} + {% for btn in form_data.buttons %} + + {% endfor %} + {% else %} + + + {% endif %} +
-
+ {% endif %} {% endmacro %} diff --git a/templates/Froxlor/table/macros.html.twig b/templates/Froxlor/table/macros.html.twig index d82189f8..3944e548 100644 --- a/templates/Froxlor/table/macros.html.twig +++ b/templates/Froxlor/table/macros.html.twig @@ -31,27 +31,45 @@ {% macro link(data) %} {% apply spaceless %} - - {% if data.icon is defined %} - - {% endif %} - {% if data.text is defined %} - {{ data.text }} - {% endif %} - + + {% if data.icon is defined %} + + {% endif %} + {% if data.text is defined %} + {{ data.text }} + {% endif %} + {% endapply %} {% endmacro %} {% macro button(data) %} {% apply spaceless %} - - {% if data.icon is defined %} - - {% endif %} - {% if data.text is defined %} - {{ data.text }} - {% endif %} - + + {% if data.icon is defined %} + + {% endif %} + {% if data.text is defined %} + {{ data.text }} + {% endif %} + + {% if data.modal is defined and data.modal is iterable %} + + {% endif %} {% endapply %} {% endmacro %} diff --git a/templates/Froxlor/user/inline-form.html.twig b/templates/Froxlor/user/inline-form.html.twig new file mode 100644 index 00000000..1a391ccf --- /dev/null +++ b/templates/Froxlor/user/inline-form.html.twig @@ -0,0 +1,2 @@ +{% import "Froxlor/form/form.html.twig" as form %} +{{ form.form(formdata, formaction|default('#'), formdata.title, editid|default(''), true) }}